Skip to content

Commit 2dbbcbb

Browse files
committed
Refactor instruction instrumentation; Cleanup API methods. (breaking)
1 parent 2be95b0 commit 2dbbcbb

File tree

16 files changed

+596
-369
lines changed

16 files changed

+596
-369
lines changed

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/AbstractInstructionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class AbstractInstructionTest {
5555
public static void printInstructions(BytecodeRootNode root) {
5656
System.out.print("[\n");
5757
String sep = "";
58-
for (Instruction s : root.getIntrospectionData().getInstructions()) {
58+
for (Instruction s : root.getBytecodeNode().getInstructionsAsList()) {
5959
System.out.print(sep);
6060
System.out.print("\"");
6161
System.out.print(s.getName());
@@ -79,7 +79,7 @@ public static QuickeningCounts assertQuickenings(DebugBytecodeRootNode node, int
7979
}
8080

8181
public static void assertInstructions(BytecodeRootNode node, String... expectedInstructions) {
82-
List<Instruction> actualInstructions = node.getIntrospectionData().getInstructions();
82+
List<Instruction> actualInstructions = node.getBytecodeNode().getInstructionsAsList();
8383
if (actualInstructions.size() != expectedInstructions.length) {
8484
throw throwBytecodeNodeAssertion(node, expectedInstructions, String.format("Invalid instruction size. Expected %s got %s.", expectedInstructions.length, actualInstructions.size()));
8585
}

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/DeadCodeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ public void testUnreachableBranchIsNotPatched() {
620620
"throw",
621621
"load.constant",
622622
"return");
623-
node.getIntrospectionData().getInstructions().stream() //
623+
node.getBytecodeNode().getInstructionsAsList().stream() //
624624
.filter(insn -> insn.getName().equals("load.argument")) //
625-
.forEach(insn -> assertEquals(0, insn.getArgumentValues().get(0).getInteger()));
625+
.forEach(insn -> assertEquals(0, insn.getArguments().get(0).asInteger()));
626626
try {
627627
node.getCallTarget().call(42);
628628
fail("exception expected");

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/ExceptionInterceptionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void testInterceptTruffleExceptionSimple() {
109109
} catch (MyException ex) {
110110
BytecodeLocation location = ex.getBytecodeLocation();
111111
assertNotNull(location);
112-
assertTrue(location.findInstruction().getName().contains("Throw"));
112+
assertTrue(location.getInstruction().getName().contains("Throw"));
113113
}
114114
}
115115

@@ -131,7 +131,7 @@ public void testInterceptTruffleExceptionFromInternal() {
131131
} catch (MyException ex) {
132132
BytecodeLocation location = ex.getBytecodeLocation();
133133
assertNotNull(location);
134-
assertTrue(location.findInstruction().getName().contains("ThrowStackOverflow"));
134+
assertTrue(location.getInstruction().getName().contains("ThrowStackOverflow"));
135135
}
136136
}
137137

@@ -167,7 +167,7 @@ public void testInterceptTruffleExceptionPropagated() {
167167
} catch (MyException ex) {
168168
childThrowLocation = ex.getBytecodeLocation();
169169
assertNotNull(childThrowLocation);
170-
assertTrue(childThrowLocation.findInstruction().getName().contains("Throw"));
170+
assertTrue(childThrowLocation.getInstruction().getName().contains("Throw"));
171171
}
172172

173173
BytecodeLocation rootThrowLocation = null;
@@ -177,7 +177,7 @@ public void testInterceptTruffleExceptionPropagated() {
177177
} catch (MyException ex) {
178178
rootThrowLocation = ex.getBytecodeLocation();
179179
assertNotNull(rootThrowLocation);
180-
assertTrue(rootThrowLocation.findInstruction().getName().contains("Invoke"));
180+
assertTrue(rootThrowLocation.getInstruction().getName().contains("Invoke"));
181181
}
182182

183183
assertNotEquals(childThrowLocation, rootThrowLocation);
@@ -246,7 +246,7 @@ public void testControlFlowInternalError() {
246246
assertEquals("internal error", ex.result);
247247
BytecodeLocation location = ex.getBytecodeLocation();
248248
assertNotNull(location);
249-
assertTrue(location.findInstruction().getName().contains("ThrowControlFlowInternalError"));
249+
assertTrue(location.getInstruction().getName().contains("ThrowControlFlowInternalError"));
250250
}
251251
}
252252

@@ -273,7 +273,7 @@ public void testControlFlowTruffleException() {
273273
assertEquals(42, ex.result);
274274
BytecodeLocation location = ex.getBytecodeLocation();
275275
assertNotNull(location);
276-
assertTrue(location.findInstruction().getName().contains("ThrowControlFlowTruffleException"));
276+
assertTrue(location.getInstruction().getName().contains("ThrowControlFlowTruffleException"));
277277
}
278278
}
279279

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/basic_interpreter/BasicInterpreter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public static final class AppendInstructionIndex {
403403
@Specialization
404404
@TruffleBoundary
405405
public static void doAppend(List<?> indices, @Bind("$location") BytecodeLocation location) {
406-
((List<Integer>) indices).add(location.findInstructionIndex());
406+
((List<Integer>) indices).add(location.getInstructionIndex());
407407
}
408408
}
409409

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/basic_interpreter/BasicInterpreterTest.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class BasicInterpreterTest extends AbstractBasicInterpreterTest {
7373
// @formatter:off
7474

7575
private static void assertInstructionEquals(Instruction instr, int bci, String name) {
76-
assertEquals(bci, instr.getBci());
76+
assertEquals(bci, instr.getBytecodeIndex());
7777
assertEquals(name, instr.getName());
7878
}
7979

@@ -999,15 +999,15 @@ public void testIntrospectionDataInstructions() {
999999
b.endRoot();
10001000
});
10011001

1002-
BytecodeIntrospection data = node.getIntrospectionData();
1002+
List<Instruction> instructions = node.getBytecodeNode().getInstructionsAsList();
10031003

1004-
assertEquals(4, data.getInstructions().size());
1005-
assertInstructionEquals(data.getInstructions().get(0), 0, "load.argument");
1006-
assertInstructionEquals(data.getInstructions().get(1), 2, "load.argument");
1007-
assertInstructionEquals(data.getInstructions().get(2), 4, "c.AddOperation");
1004+
assertEquals(4, instructions.size());
1005+
assertInstructionEquals(instructions.get(0), 0, "load.argument");
1006+
assertInstructionEquals(instructions.get(1), 2, "load.argument");
1007+
assertInstructionEquals(instructions.get(2), 4, "c.AddOperation");
10081008
// With BE, the add instruction's encoding includes its child indices.
10091009
int beOffset = hasBE(interpreterClass) ? 2 : 0;
1010-
assertInstructionEquals(data.getInstructions().get(3), 6 + beOffset, "return");
1010+
assertInstructionEquals(instructions.get(3), 6 + beOffset, "return");
10111011

10121012
}
10131013

@@ -1118,19 +1118,19 @@ public void testIntrospectionDataSourceInformation() {
11181118
assertEquals("1 + 2", s3.getSourceSection().getCharacters().toString());
11191119
assertEquals("return 1 + 2", s4.getSourceSection().getCharacters().toString());
11201120

1121-
List<Instruction> instructions = data.getInstructions();
1121+
List<Instruction> instructions = node.getBytecodeNode().getInstructionsAsList();
11221122

11231123
assertEquals(0, s1.getBeginBci());
1124-
assertEquals(instructions.get(1).getBci(), s1.getEndBci());
1124+
assertEquals(instructions.get(1).getBytecodeIndex(), s1.getEndBci());
11251125

1126-
assertEquals(2, instructions.get(1).getBci());
1127-
assertEquals(instructions.get(2).getBci(), s2.getEndBci());
1126+
assertEquals(2, instructions.get(1).getBytecodeIndex());
1127+
assertEquals(instructions.get(2).getBytecodeIndex(), s2.getEndBci());
11281128

11291129
assertEquals(0, s3.getBeginBci());
1130-
assertEquals(instructions.get(3).getBci(), s3.getEndBci());
1130+
assertEquals(instructions.get(3).getBytecodeIndex(), s3.getEndBci());
11311131

11321132
assertEquals(0, s4.getBeginBci());
1133-
assertEquals(instructions.get(3).getBci() + 1, s4.getEndBci());
1133+
assertEquals(instructions.get(3).getBytecodeIndex() + 1, s4.getEndBci());
11341134
}
11351135

11361136
@Test
@@ -1227,15 +1227,17 @@ public void testDecisionQuicken() {
12271227

12281228
// todo these tests do not pass, since quickening is not implemented yet properly
12291229

1230-
assertInstructionEquals(node.getIntrospectionData().getInstructions().get(2), 2, "c.AddOperation");
1230+
List<Instruction> instructions = node.getBytecodeNode().getInstructionsAsList();
1231+
1232+
assertInstructionEquals(instructions.get(2), 2, "c.AddOperation");
12311233

12321234
assertEquals(3L, node.getCallTarget().call(1L, 2L));
12331235

1234-
assertInstructionEquals(node.getIntrospectionData().getInstructions().get(2), 2, "c.AddOperation.q.AddLongs");
1236+
assertInstructionEquals(instructions.get(2), 2, "c.AddOperation.q.AddLongs");
12351237

12361238
assertEquals("foobar", node.getCallTarget().call("foo", "bar"));
12371239

1238-
assertInstructionEquals(node.getIntrospectionData().getInstructions().get(2), 2, "c.AddOperation");
1240+
assertInstructionEquals(instructions.get(2), 2, "c.AddOperation");
12391241
}
12401242

12411243
@Test
@@ -1256,6 +1258,8 @@ public void testDecisionSuperInstruction() {
12561258

12571259
// todo these tests do not pass, since quickening is not implemented yet properly
12581260

1259-
assertInstructionEquals(node.getIntrospectionData().getInstructions().get(1), 1, "si.load.argument.c.LessThanOperation");
1261+
List<Instruction> instructions = node.getBytecodeNode().getInstructionsAsList();
1262+
1263+
assertInstructionEquals(instructions.get(1), 1, "si.load.argument.c.LessThanOperation");
12601264
}
12611265
}

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/basic_interpreter/BytecodeLocationTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ public void testStacktrace() {
184184
assert baz.getName().equals("baz");
185185

186186
// Check that the start locations map to the first instruction.
187-
assertEquals(0, foo.getStartLocation().findInstructionIndex());
188-
assertEquals(0, bar.getStartLocation().findInstructionIndex());
189-
assertEquals(0, baz.getStartLocation().findInstructionIndex());
187+
assertEquals(0, foo.getStartLocation().getInstructionIndex());
188+
assertEquals(0, bar.getStartLocation().getInstructionIndex());
189+
assertEquals(0, baz.getStartLocation().getInstructionIndex());
190190

191191
for (boolean fooArgument : List.of(true, false)) {
192192
Object result = foo.getCallTarget().call(fooArgument);
@@ -202,7 +202,7 @@ public void testStacktrace() {
202202
// baz
203203
BytecodeLocation bazLocation = bytecodeLocations.get(1);
204204
assertNotNull(bazLocation);
205-
SourceSection bazSourceSection = bazLocation.findSourceLocation();
205+
SourceSection bazSourceSection = bazLocation.getSourceLocation();
206206
assertEquals(bazSource, bazSourceSection.getSource());
207207
if (fooArgument) {
208208
assertEquals("<trace1>", bazSourceSection.getCharacters());
@@ -213,14 +213,14 @@ public void testStacktrace() {
213213
// bar
214214
BytecodeLocation barLocation = bytecodeLocations.get(2);
215215
assertNotNull(barLocation);
216-
SourceSection barSourceSection = barLocation.findSourceLocation();
216+
SourceSection barSourceSection = barLocation.getSourceLocation();
217217
assertEquals(barSource, barSourceSection.getSource());
218218
assertEquals("baz(arg0)", barSourceSection.getCharacters());
219219

220220
// foo
221221
BytecodeLocation fooLocation = bytecodeLocations.get(3);
222222
assertNotNull(fooLocation);
223-
SourceSection fooSourceSection = fooLocation.findSourceLocation();
223+
SourceSection fooSourceSection = fooLocation.getSourceLocation();
224224
assertEquals(fooSource, fooSourceSection.getSource());
225225
assertEquals("bar(arg0)", fooSourceSection.getCharacters());
226226
}
@@ -368,7 +368,7 @@ public void testStacktraceWithContinuation() {
368368
BytecodeLocation bazLocation = locations.get(1);
369369
assertNotNull(bazLocation);
370370
assertNotEquals(-1, bazLocation);
371-
SourceSection bazSourceSection = bazLocation.findSourceLocation();
371+
SourceSection bazSourceSection = bazLocation.getSourceLocation();
372372
assertEquals(bazSource, bazSourceSection.getSource());
373373
if (continuationArgument) {
374374
assertEquals("<trace1>", bazSourceSection.getCharacters());
@@ -379,14 +379,14 @@ public void testStacktraceWithContinuation() {
379379
// bar
380380
BytecodeLocation barLocation = locations.get(2);
381381
assertNotNull(barLocation);
382-
SourceSection barSourceSection = barLocation.findSourceLocation();
382+
SourceSection barSourceSection = barLocation.getSourceLocation();
383383
assertEquals(barSource, barSourceSection.getSource());
384384
assertEquals("baz(x)", barSourceSection.getCharacters());
385385

386386
// foo
387387
BytecodeLocation fooLocation = locations.get(3);
388388
assertNotNull(fooLocation);
389-
SourceSection fooSourceSection = fooLocation.findSourceLocation();
389+
SourceSection fooSourceSection = fooLocation.getSourceLocation();
390390
assertEquals(fooSource, fooSourceSection.getSource());
391391
assertEquals("continue(c, arg0)", fooSourceSection.getCharacters());
392392
}
@@ -436,8 +436,8 @@ public void testInstructionIndex() {
436436
// Check that mapping between instruction index and bci produces the same result.
437437
BytecodeNode bytecodeNode = rootNode.getBytecodeNode();
438438
for (int expectedIndex : indices) {
439-
int bci = bytecodeNode.findBciFromInstructionIndex(expectedIndex);
440-
int actualIndex = bytecodeNode.findInstructionIndex(bci);
439+
BytecodeLocation location = bytecodeNode.getBytecodeLocationFromInstructionIndex(expectedIndex);
440+
int actualIndex = location.getInstructionIndex();
441441
assertEquals(expectedIndex, actualIndex);
442442
}
443443
}

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/basic_interpreter/SourcesTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ public void testSource() {
8888
assertEquals(node.getSourceSection().getCharLength(), 8);
8989

9090
BytecodeNode bytecode = node.getBytecodeNode();
91-
List<Instruction> instructions = bytecode.getIntrospectionData().getInstructions();
91+
List<Instruction> instructions = bytecode.getInstructionsAsList();
9292
BytecodeLocation location1 = instructions.get(0).getLocation();
9393
BytecodeLocation location2 = instructions.get(1).getLocation();
9494

95-
assertEquals(location1.findSourceLocation().getSource(), source);
96-
assertEquals(location1.findSourceLocation().getCharIndex(), 7);
97-
assertEquals(location1.findSourceLocation().getCharLength(), 1);
95+
assertEquals(location1.getSourceLocation().getSource(), source);
96+
assertEquals(location1.getSourceLocation().getCharIndex(), 7);
97+
assertEquals(location1.getSourceLocation().getCharLength(), 1);
9898

9999
// return
100-
assertEquals(location2.findSourceLocation().getSource(), source);
101-
assertEquals(location2.findSourceLocation().getCharIndex(), 0);
102-
assertEquals(location2.findSourceLocation().getCharLength(), 8);
100+
assertEquals(location2.getSourceLocation().getSource(), source);
101+
assertEquals(location2.getSourceLocation().getCharIndex(), 0);
102+
assertEquals(location2.getSourceLocation().getCharLength(), 8);
103103
}
104104

105105
@Test
@@ -113,12 +113,12 @@ public void testWithoutSource() {
113113
});
114114

115115
BytecodeNode bytecode = node.getBytecodeNode();
116-
List<Instruction> instructions = bytecode.getIntrospectionData().getInstructions();
116+
List<Instruction> instructions = bytecode.getInstructionsAsList();
117117
BytecodeLocation location1 = instructions.get(0).getLocation();
118118
BytecodeLocation location2 = instructions.get(1).getLocation();
119119

120-
assertNull(location1.findSourceLocation());
121-
assertNull(location2.findSourceLocation());
120+
assertNull(location1.getSourceLocation());
121+
assertNull(location2.getSourceLocation());
122122
}
123123

124124
@Test
@@ -201,7 +201,7 @@ public void testSourceMultipleSources() {
201201

202202
assertSourceSection(source1, 0, source1.getLength(), root.getSourceSection());
203203

204-
List<Instruction> instructions = root.getBytecodeNode().getIntrospectionData().getInstructions();
204+
List<Instruction> instructions = root.getBytecodeNode().getInstructionsAsList();
205205
assertInstructionSourceSection(source1, 0, source1.getLength(), instructions.get(0));
206206
assertInstructionSourceSection(source1, 0, source1.getLength(), instructions.get(1));
207207
assertInstructionSourceSection(source1, 1, 2, instructions.get(2));
@@ -216,7 +216,7 @@ public void testSourceMultipleSources() {
216216
}
217217

218218
private static void assertInstructionSourceSection(Source source, int startIndex, int length, Instruction i) {
219-
assertSourceSection(source, startIndex, length, i.getLocation().findSourceLocation());
219+
assertSourceSection(source, startIndex, length, i.getLocation().getSourceLocation());
220220
}
221221

222222
private static void assertSourceSection(Source source, int startIndex, int length, SourceSection section) {
@@ -364,9 +364,9 @@ public void testSourceReparse() {
364364
assertEquals(node.getSourceSection().getCharIndex(), 0);
365365
assertEquals(node.getSourceSection().getCharLength(), 8);
366366

367-
List<Instruction> instructions = node.getBytecodeNode().getIntrospectionData().getInstructions();
368-
SourceSection sourceSection0 = instructions.get(0).getLocation().findSourceLocation();
369-
SourceSection sourceSection1 = instructions.get(1).getLocation().findSourceLocation();
367+
List<Instruction> instructions = node.getBytecodeNode().getInstructionsAsList();
368+
SourceSection sourceSection0 = instructions.get(0).getLocation().getSourceLocation();
369+
SourceSection sourceSection1 = instructions.get(1).getLocation().getSourceLocation();
370370

371371
// load constant
372372
assertEquals(sourceSection0.getSource(), source);

truffle/src/com.oracle.truffle.api.bytecode/src/com/oracle/truffle/api/bytecode/AbstractBytecodeTruffleException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ public SourceSection getEncapsulatingSourceSection() {
133133
if (bci == INVALID_BCI) {
134134
return super.getEncapsulatingSourceSection();
135135
}
136-
return BytecodeLocation.get(getLocation(), bci).findSourceLocation();
136+
return BytecodeLocation.get(getLocation(), bci).getSourceLocation();
137137
}
138138
}

truffle/src/com.oracle.truffle.api.bytecode/src/com/oracle/truffle/api/bytecode/BytecodeIntrospection.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ public BytecodeIntrospection(Object[] data) {
7575
this.data = data;
7676
}
7777

78-
public List<Instruction> getInstructions() {
79-
Object[] instructions = (Object[]) data[1];
80-
List<Instruction> result = new ArrayList<>(instructions.length);
81-
for (int i = 0; i < instructions.length; i++) {
82-
result.add(new Instruction((Object[]) instructions[i]));
83-
}
84-
return Collections.unmodifiableList(result);
85-
}
86-
8778
public List<ExceptionHandler> getExceptionHandlers() {
8879
Object[] handlers = (Object[]) data[2];
8980
List<ExceptionHandler> result = new ArrayList<>(handlers.length);
@@ -117,18 +108,14 @@ public TagTree getTagTree() {
117108

118109
@Override
119110
public String toString() {
120-
List<Instruction> instructions = getInstructions();
121111
List<ExceptionHandler> exceptions = getExceptionHandlers();
122112
List<SourceInformation> sourceInformation = getSourceInformation();
123113
return String.format("""
124114
BytecodeIntrospection[
125-
instructions(%s) = %s
126115
exceptionHandlers(%s) = %s
127116
sourceInformation(%s) = %s
128117
tagTree = %s
129118
]""",
130-
instructions.size(),
131-
formatList(instructions),
132119
exceptions.size(),
133120
formatList(exceptions),
134121
sourceInformation != null ? sourceInformation.size() : "-",

0 commit comments

Comments
 (0)