Skip to content

Commit 847008c

Browse files
committed
OSR loop highlighting
1 parent 43658fe commit 847008c

File tree

19 files changed

+525
-104
lines changed

19 files changed

+525
-104
lines changed

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.2.2
1+
version=1.2.3

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.chrisnewland</groupId>
66
<artifactId>jitwatch-parent</artifactId>
7-
<version>1.2.2</version>
7+
<version>1.2.3</version>
88
</parent>
99

1010
<artifactId>jitwatch-core</artifactId>

core/src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private JITWatchConstants()
136136
public static final String ATTR_STAMP_COMPLETED = "stamp_completed";
137137
public static final String ATTR_NAME = "name";
138138
public static final String ATTR_BCI = "bci";
139+
public static final String ATTR_OSR_BCI = "osr_bci";
139140
public static final String ATTR_CODE = "code";
140141
public static final String ATTR_COMPILER = "compiler";
141142
public static final String ATTR_LEVEL = "level";

core/src/main/java/org/adoptopenjdk/jitwatch/model/Compilation.java

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
*/
66
package org.adoptopenjdk.jitwatch.model;
77

8-
import java.util.HashMap;
9-
import java.util.Map;
10-
11-
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod;
12-
import org.adoptopenjdk.jitwatch.util.ParseUtil;
13-
14-
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID;
158
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ADDRESS;
16-
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ENTRY;
179
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILER;
18-
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NMSIZE;
19-
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2;
10+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_ID;
2011
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_COMPILE_KIND;
12+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_ENTRY;
2113
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_LEVEL;
14+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_NMSIZE;
15+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_OSR_BCI;
16+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2;
2217
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.C2N;
18+
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.OSR;
2319
import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_FAILURE;
2420

21+
import java.util.HashMap;
22+
import java.util.Map;
23+
24+
import org.adoptopenjdk.jitwatch.model.assembly.AssemblyMethod;
25+
import org.adoptopenjdk.jitwatch.util.ParseUtil;
26+
2527
public class Compilation
2628
{
2729
private Tag tagTaskQueued;
@@ -43,6 +45,10 @@ public class Compilation
4345
private long compiledStamp;
4446

4547
private boolean isC2N;
48+
49+
private boolean isOSR;
50+
51+
private int osrBCI;
4652

4753
private String nativeAddress;
4854

@@ -136,9 +142,29 @@ public void setTagTaskQueued(Tag tagTaskQueued)
136142
{
137143
this.tagTaskQueued = tagTaskQueued;
138144

139-
this.compileID = tagTaskQueued.getAttributes().get(ATTR_COMPILE_ID);
145+
Map<String, String> attrs = tagTaskQueued.getAttributes();
146+
147+
this.compileID = attrs.get(ATTR_COMPILE_ID);
148+
149+
queuedStamp = ParseUtil.getStamp(attrs);
150+
151+
String compileKind = attrs.get(ATTR_COMPILE_KIND);
152+
String osrBCIString = attrs.get(ATTR_OSR_BCI);
140153

141-
queuedStamp = ParseUtil.getStamp(tagTaskQueued.getAttributes());
154+
if (OSR.equalsIgnoreCase(compileKind))
155+
{
156+
isOSR =true;
157+
osrBCI = -1;
158+
159+
try
160+
{
161+
osrBCI = Integer.parseInt(osrBCIString);
162+
}
163+
catch (NumberFormatException nfe)
164+
{
165+
//logger.error("Could not parse {} '{}'", ATTR_OSR_BCI, osrBCIString);
166+
}
167+
}
142168
}
143169

144170
public void setTagNMethod(Tag tagNMethod)
@@ -393,4 +419,16 @@ public boolean isFailedTask()
393419
{
394420
return failedTask;
395421
}
422+
423+
public boolean isOSR()
424+
{
425+
return isOSR;
426+
}
427+
428+
public int getOSRBCI()
429+
{
430+
return osrBCI;
431+
}
432+
433+
396434
}

core/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/LineTable.java

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013-2015 Chris Newland.
2+
* Copyright (c) 2013-2017 Chris Newland.
33
* Licensed under https://github.com/AdoptOpenJDK/jitwatch/blob/master/LICENSE-BSD
44
* Instructions: https://github.com/AdoptOpenJDK/jitwatch/wiki
55
*/
@@ -51,28 +51,83 @@ public void add(LineTable lineTable)
5151

5252
public int getLastSourceLine()
5353
{
54-
return lineTableEntries.get(lineTableEntries.size() - 1).getSourceOffset();
54+
return getSourceRange()[1];
5555
}
5656

57-
public boolean sourceLineInRange(int sourceLine)
57+
public int[] getSourceRange(int startBCI, int endBCI)
5858
{
59-
boolean result = false;
59+
boolean first = true;
60+
61+
int minSourceLine = 0;
62+
int maxSourceLine = 0;
6063

61-
if (lineTableEntries.size() > 0)
64+
for (LineTableEntry entry : lineTableEntries)
6265
{
63-
int maxIndex = lineTableEntries.size() - 1;
66+
int entryBCI = entry.getBytecodeOffset();
67+
int entrySourceLine = entry.getSourceOffset();
6468

65-
int minSourceLine = lineTableEntries.get(0).getSourceOffset();
66-
int maxSourceLine = lineTableEntries.get(maxIndex).getSourceOffset();
69+
if (entryBCI >= startBCI && entryBCI <= endBCI)
70+
{
71+
if (first)
72+
{
73+
minSourceLine = entrySourceLine;
74+
maxSourceLine = entrySourceLine;
75+
first = false;
76+
}
77+
else
78+
{
79+
minSourceLine = Math.min(entrySourceLine, minSourceLine);
80+
maxSourceLine = Math.max(entrySourceLine, maxSourceLine);
81+
}
82+
}
83+
}
84+
85+
return new int[] { minSourceLine, maxSourceLine };
86+
}
87+
88+
public int[] getSourceRange()
89+
{
90+
boolean first = true;
6791

68-
result = (sourceLine >= minSourceLine) && (sourceLine <= maxSourceLine);
92+
int minSourceLine = 0;
93+
int maxSourceLine = 0;
6994

70-
if (DEBUG_LOGGING_BYTECODE)
95+
for (LineTableEntry entry : lineTableEntries)
96+
{
97+
int entrySourceLine = entry.getSourceOffset();
98+
99+
if (first)
100+
{
101+
minSourceLine = entrySourceLine;
102+
maxSourceLine = entrySourceLine;
103+
first = false;
104+
}
105+
else
71106
{
72-
logger.debug("{} in range {}-{} : {}", sourceLine, minSourceLine, maxSourceLine, result);
107+
minSourceLine = Math.min(entrySourceLine, minSourceLine);
108+
maxSourceLine = Math.max(entrySourceLine, maxSourceLine);
73109
}
74110
}
75111

112+
return new int[] { minSourceLine, maxSourceLine };
113+
}
114+
115+
public boolean sourceLineInRange(int sourceLine)
116+
{
117+
boolean result = false;
118+
119+
int[] sourceRange = getSourceRange();
120+
121+
int minSourceLine = sourceRange[0];
122+
int maxSourceLine = sourceRange[1];
123+
124+
result = (sourceLine >= minSourceLine) && (sourceLine <= maxSourceLine);
125+
126+
if (DEBUG_LOGGING_BYTECODE)
127+
{
128+
logger.debug("{} in range {}-{} : {}", sourceLine, minSourceLine, maxSourceLine, result);
129+
}
130+
76131
return result;
77132
}
78133

@@ -83,7 +138,7 @@ private void sort()
83138
@Override
84139
public int compare(LineTableEntry o1, LineTableEntry o2)
85140
{
86-
return Integer.compare(o1.getSourceOffset(), o2.getSourceOffset());
141+
return Integer.compare(o1.getBytecodeOffset(), o2.getBytecodeOffset());
87142
}
88143
});
89144
}

core/src/main/java/org/adoptopenjdk/jitwatch/model/bytecode/MemberBytecode.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public class MemberBytecode
2020
private List<BytecodeInstruction> bytecodeInstructions = new ArrayList<>();
2121

2222
private LineTable lineTable;
23-
23+
2424
private ExceptionTable exceptionTable;
2525

2626
private MemberSignatureParts msp;
2727

2828
private ClassBC classBytecode;
29-
29+
3030
private int size = 0;
3131

3232
private static final Logger logger = LoggerFactory.getLogger(MemberBytecode.class);
33-
33+
3434
private BytecodeAnnotations bytecodeAnnotations = new BytecodeAnnotations();
3535

3636
public MemberBytecode(ClassBC classBytecode, MemberSignatureParts msp)
@@ -45,7 +45,7 @@ public ClassBC getClassBytecode()
4545
{
4646
return classBytecode;
4747
}
48-
48+
4949
public BytecodeAnnotations getBytecodeAnnotations()
5050
{
5151
return bytecodeAnnotations;
@@ -59,15 +59,15 @@ public MemberSignatureParts getMemberSignatureParts()
5959
public void setInstructions(List<BytecodeInstruction> bytecodeInstructions)
6060
{
6161
this.bytecodeInstructions = bytecodeInstructions;
62-
62+
6363
if (!bytecodeInstructions.isEmpty())
6464
{
65-
BytecodeInstruction instruction = bytecodeInstructions.get(bytecodeInstructions.size() -1);
66-
65+
BytecodeInstruction instruction = bytecodeInstructions.get(bytecodeInstructions.size() - 1);
66+
6767
if (instruction != null)
6868
{
6969
int bci = instruction.getOffset();
70-
70+
7171
size = bci + 1;
7272
}
7373
}
@@ -77,17 +77,17 @@ public int size()
7777
{
7878
return size;
7979
}
80-
80+
8181
public List<BytecodeInstruction> getInstructions()
8282
{
8383
return bytecodeInstructions;
8484
}
8585

86-
public BytecodeInstruction getBytecodeAtOffset(int bci)
86+
public BytecodeInstruction getInstructionAtBCI(int bci)
8787
{
8888
if (DEBUG_LOGGING_BYTECODE)
8989
{
90-
logger.debug("getBytecodeAtOffset({})", bci);
90+
logger.debug("getInstructionAtBCI({})", bci);
9191
}
9292

9393
BytecodeInstruction result = null;
@@ -113,6 +113,59 @@ public BytecodeInstruction getBytecodeAtOffset(int bci)
113113
return result;
114114
}
115115

116+
public int findLastBackBranchToBCI(int bci)
117+
{
118+
if (DEBUG_LOGGING_BYTECODE)
119+
{
120+
logger.debug("findLastBackBranchToBCI({})", bci);
121+
}
122+
123+
int lastBackBranchBCI = -1;
124+
125+
boolean inLoop = false;
126+
127+
for (BytecodeInstruction instruction : bytecodeInstructions)
128+
{
129+
if (instruction.getOffset() == bci)
130+
{
131+
inLoop = true;
132+
}
133+
134+
if (inLoop)
135+
{
136+
Opcode opCode = instruction.getOpcode();
137+
138+
if (opCode == Opcode.GOTO || opCode == Opcode.GOTO_W)
139+
{
140+
List<IBytecodeParam> gotoParams = instruction.getParameters();
141+
142+
int paramCount = gotoParams.size();
143+
144+
if (paramCount == 1)
145+
{
146+
IBytecodeParam param = gotoParams.get(0);
147+
148+
if (param instanceof BCParamNumeric)
149+
{
150+
int gotoTarget = ((BCParamNumeric) param).getValue();
151+
152+
if (gotoTarget == bci)
153+
{
154+
lastBackBranchBCI = instruction.getOffset();
155+
}
156+
}
157+
}
158+
else
159+
{
160+
logger.error("Unexpected param count for {} {}", opCode, paramCount);
161+
}
162+
}
163+
}
164+
}
165+
166+
return lastBackBranchBCI;
167+
}
168+
116169
public void addLineTableEntry(LineTableEntry entry)
117170
{
118171
lineTable.add(entry);
@@ -122,7 +175,7 @@ public LineTable getLineTable()
122175
{
123176
return lineTable;
124177
}
125-
178+
126179
public void addExceptionTableEntry(ExceptionTableEntry entry)
127180
{
128181
exceptionTable.add(entry);

0 commit comments

Comments
 (0)