Skip to content

Commit

Permalink
OSR loop highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Oct 22, 2017
1 parent 43658fe commit 847008c
Show file tree
Hide file tree
Showing 19 changed files with 525 additions and 104 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.2.2
version=1.2.3
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.chrisnewland</groupId>
<artifactId>jitwatch-parent</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
</parent>

<artifactId>jitwatch-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private JITWatchConstants()
public static final String ATTR_STAMP_COMPLETED = "stamp_completed";
public static final String ATTR_NAME = "name";
public static final String ATTR_BCI = "bci";
public static final String ATTR_OSR_BCI = "osr_bci";
public static final String ATTR_CODE = "code";
public static final String ATTR_COMPILER = "compiler";
public static final String ATTR_LEVEL = "level";
Expand Down
62 changes: 50 additions & 12 deletions core/src/main/java/org/adoptopenjdk/jitwatch/model/Compilation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
*/
package org.adoptopenjdk.jitwatch.model;

import java.util.HashMap;
import java.util.Map;

import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod;
import org.adoptopenjdk.jitwatch.util.ParseUtil;

import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ADDRESS;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ENTRY;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILER;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NMSIZE;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_KIND;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ENTRY;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_LEVEL;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NMSIZE;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_OSR_BCI;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2N;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.OSR;
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_FAILURE;

import java.util.HashMap;
import java.util.Map;

import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod;
import org.adoptopenjdk.jitwatch.util.ParseUtil;

public class Compilation
{
private Tag tagTaskQueued;
Expand All @@ -43,6 +45,10 @@ public class Compilation
private long compiledStamp;

private boolean isC2N;

private boolean isOSR;

private int osrBCI;

private String nativeAddress;

Expand Down Expand Up @@ -136,9 +142,29 @@ public void setTagTaskQueued(Tag tagTaskQueued)
{
this.tagTaskQueued = tagTaskQueued;

this.compileID = tagTaskQueued.getAttributes().get(ATTR_COMPILE_ID);
Map<String, String> attrs = tagTaskQueued.getAttributes();

this.compileID = attrs.get(ATTR_COMPILE_ID);

queuedStamp = ParseUtil.getStamp(attrs);

String compileKind = attrs.get(ATTR_COMPILE_KIND);
String osrBCIString = attrs.get(ATTR_OSR_BCI);

queuedStamp = ParseUtil.getStamp(tagTaskQueued.getAttributes());
if (OSR.equalsIgnoreCase(compileKind))
{
isOSR =true;
osrBCI = -1;

try
{
osrBCI = Integer.parseInt(osrBCIString);
}
catch (NumberFormatException nfe)
{
//logger.error("Could not parse {} '{}'", ATTR_OSR_BCI, osrBCIString);
}
}
}

public void setTagNMethod(Tag tagNMethod)
Expand Down Expand Up @@ -393,4 +419,16 @@ public boolean isFailedTask()
{
return failedTask;
}

public boolean isOSR()
{
return isOSR;
}

public int getOSRBCI()
{
return osrBCI;
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2015 Chris Newland.
* Copyright (c) 2013-2017 Chris Newland.
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
*/
Expand Down Expand Up @@ -51,28 +51,83 @@ public void add(LineTable lineTable)

public int getLastSourceLine()
{
return lineTableEntries.get(lineTableEntries.size() - 1).getSourceOffset();
return getSourceRange()[1];
}

public boolean sourceLineInRange(int sourceLine)
public int[] getSourceRange(int startBCI, int endBCI)
{
boolean result = false;
boolean first = true;

int minSourceLine = 0;
int maxSourceLine = 0;

if (lineTableEntries.size() > 0)
for (LineTableEntry entry : lineTableEntries)
{
int maxIndex = lineTableEntries.size() - 1;
int entryBCI = entry.getBytecodeOffset();
int entrySourceLine = entry.getSourceOffset();

int minSourceLine = lineTableEntries.get(0).getSourceOffset();
int maxSourceLine = lineTableEntries.get(maxIndex).getSourceOffset();
if (entryBCI >= startBCI && entryBCI <= endBCI)
{
if (first)
{
minSourceLine = entrySourceLine;
maxSourceLine = entrySourceLine;
first = false;
}
else
{
minSourceLine = Math.min(entrySourceLine, minSourceLine);
maxSourceLine = Math.max(entrySourceLine, maxSourceLine);
}
}
}

return new int[] { minSourceLine, maxSourceLine };
}

public int[] getSourceRange()
{
boolean first = true;

result = (sourceLine >= minSourceLine) && (sourceLine <= maxSourceLine);
int minSourceLine = 0;
int maxSourceLine = 0;

if (DEBUG_LOGGING_BYTECODE)
for (LineTableEntry entry : lineTableEntries)
{
int entrySourceLine = entry.getSourceOffset();

if (first)
{
minSourceLine = entrySourceLine;
maxSourceLine = entrySourceLine;
first = false;
}
else
{
logger.debug("{} in range {}-{} : {}", sourceLine, minSourceLine, maxSourceLine, result);
minSourceLine = Math.min(entrySourceLine, minSourceLine);
maxSourceLine = Math.max(entrySourceLine, maxSourceLine);
}
}

return new int[] { minSourceLine, maxSourceLine };
}

public boolean sourceLineInRange(int sourceLine)
{
boolean result = false;

int[] sourceRange = getSourceRange();

int minSourceLine = sourceRange[0];
int maxSourceLine = sourceRange[1];

result = (sourceLine >= minSourceLine) && (sourceLine <= maxSourceLine);

if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("{} in range {}-{} : {}", sourceLine, minSourceLine, maxSourceLine, result);
}

return result;
}

Expand All @@ -83,7 +138,7 @@ private void sort()
@Override
public int compare(LineTableEntry o1, LineTableEntry o2)
{
return Integer.compare(o1.getSourceOffset(), o2.getSourceOffset());
return Integer.compare(o1.getBytecodeOffset(), o2.getBytecodeOffset());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public class MemberBytecode
private List<BytecodeInstruction> bytecodeInstructions = new ArrayList<>();

private LineTable lineTable;

private ExceptionTable exceptionTable;

private MemberSignatureParts msp;

private ClassBC classBytecode;

private int size = 0;

private static final Logger logger = LoggerFactory.getLogger(MemberBytecode.class);

private BytecodeAnnotations bytecodeAnnotations = new BytecodeAnnotations();

public MemberBytecode(ClassBC classBytecode, MemberSignatureParts msp)
Expand All @@ -45,7 +45,7 @@ public ClassBC getClassBytecode()
{
return classBytecode;
}

public BytecodeAnnotations getBytecodeAnnotations()
{
return bytecodeAnnotations;
Expand All @@ -59,15 +59,15 @@ public MemberSignatureParts getMemberSignatureParts()
public void setInstructions(List<BytecodeInstruction> bytecodeInstructions)
{
this.bytecodeInstructions = bytecodeInstructions;

if (!bytecodeInstructions.isEmpty())
{
BytecodeInstruction instruction = bytecodeInstructions.get(bytecodeInstructions.size() -1);
BytecodeInstruction instruction = bytecodeInstructions.get(bytecodeInstructions.size() - 1);

if (instruction != null)
{
int bci = instruction.getOffset();

size = bci + 1;
}
}
Expand All @@ -77,17 +77,17 @@ public int size()
{
return size;
}

public List<BytecodeInstruction> getInstructions()
{
return bytecodeInstructions;
}

public BytecodeInstruction getBytecodeAtOffset(int bci)
public BytecodeInstruction getInstructionAtBCI(int bci)
{
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("getBytecodeAtOffset({})", bci);
logger.debug("getInstructionAtBCI({})", bci);
}

BytecodeInstruction result = null;
Expand All @@ -113,6 +113,59 @@ public BytecodeInstruction getBytecodeAtOffset(int bci)
return result;
}

public int findLastBackBranchToBCI(int bci)
{
if (DEBUG_LOGGING_BYTECODE)
{
logger.debug("findLastBackBranchToBCI({})", bci);
}

int lastBackBranchBCI = -1;

boolean inLoop = false;

for (BytecodeInstruction instruction : bytecodeInstructions)
{
if (instruction.getOffset() == bci)
{
inLoop = true;
}

if (inLoop)
{
Opcode opCode = instruction.getOpcode();

if (opCode == Opcode.GOTO || opCode == Opcode.GOTO_W)
{
List<IBytecodeParam> gotoParams = instruction.getParameters();

int paramCount = gotoParams.size();

if (paramCount == 1)
{
IBytecodeParam param = gotoParams.get(0);

if (param instanceof BCParamNumeric)
{
int gotoTarget = ((BCParamNumeric) param).getValue();

if (gotoTarget == bci)
{
lastBackBranchBCI = instruction.getOffset();
}
}
}
else
{
logger.error("Unexpected param count for {} {}", opCode, paramCount);
}
}
}
}

return lastBackBranchBCI;
}

public void addLineTableEntry(LineTableEntry entry)
{
lineTable.add(entry);
Expand All @@ -122,7 +175,7 @@ public LineTable getLineTable()
{
return lineTable;
}

public void addExceptionTableEntry(ExceptionTableEntry entry)
{
exceptionTable.add(entry);
Expand Down
Loading

0 comments on commit 847008c

Please sign in to comment.