Skip to content

Commit ad78718

Browse files
committed
Fix test code.
1 parent 3fac53d commit ad78718

File tree

2 files changed

+52
-40
lines changed

2 files changed

+52
-40
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/BytecodeDSLCompilationTest.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.junit.Assert.fail;
3232
import static org.junit.Assume.assumeTrue;
3333

34+
import java.util.ArrayList;
3435
import java.util.List;
3536

3637
import org.graalvm.polyglot.Context;
@@ -51,6 +52,7 @@
5152
import com.oracle.truffle.api.bytecode.ContinuationResult;
5253
import com.oracle.truffle.api.bytecode.test.BytecodeDSLTestLanguage;
5354
import com.oracle.truffle.api.bytecode.test.basic_interpreter.AbstractBasicInterpreterTest;
55+
import com.oracle.truffle.api.bytecode.test.basic_interpreter.AbstractBasicInterpreterTest.TestRun;
5456
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreter;
5557
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreterBuilder;
5658
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreterBuilder.BytecodeVariant;
@@ -70,14 +72,18 @@
7072
public class BytecodeDSLCompilationTest extends TestWithSynchronousCompiling {
7173

7274
@Parameters(name = "{0}")
73-
public static List<BytecodeVariant> getBytecodeVariants() {
74-
return AbstractBasicInterpreterTest.allVariants();
75+
public static List<TestRun> getParameters() {
76+
List<TestRun> result = new ArrayList<>();
77+
for (BytecodeVariant bc : AbstractBasicInterpreterTest.allVariants()) {
78+
result.add(new TestRun(bc, false, false));
79+
}
80+
return result;
7581
}
7682

77-
@Parameter(0) public BytecodeVariant bytecode;
83+
@Parameter(0) public TestRun run;
7884

7985
private boolean hasBoxingElimination() {
80-
return new AbstractBasicInterpreterTest.TestRun(bytecode, false).hasBoxingElimination();
86+
return run.hasBoxingElimination();
8187
}
8288

8389
Context context;
@@ -124,7 +130,7 @@ public static void beforeClass() {
124130
*/
125131
@Test
126132
public void testOSR1() {
127-
BasicInterpreter root = parseNode(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, "osrRoot", b -> {
133+
BasicInterpreter root = parseNode(run, BytecodeDSLTestLanguage.REF.get(null), "osrRoot", b -> {
128134
b.beginRoot();
129135

130136
BytecodeLocal iLoc = b.createLocal();
@@ -224,7 +230,7 @@ public void testOSR1() {
224230
*/
225231
@Test
226232
public void testOSR2() {
227-
BasicInterpreter root = parseNode(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, "osrRoot", b -> {
233+
BasicInterpreter root = parseNode(run, BytecodeDSLTestLanguage.REF.get(null), "osrRoot", b -> {
228234
b.beginRoot();
229235

230236
BytecodeLocal iLoc = b.createLocal();
@@ -342,7 +348,7 @@ public void testOSR2() {
342348

343349
@Test
344350
public void testCompiles() {
345-
BasicInterpreter root = parseNodeForCompilation(bytecode, "addTwoConstants", b -> {
351+
BasicInterpreter root = parseNodeForCompilation(run, "addTwoConstants", b -> {
346352
b.beginRoot();
347353

348354
b.beginReturn();
@@ -366,7 +372,7 @@ public void testCompiles() {
366372
@Test
367373
public void testMultipleReturns() {
368374
// return 30 + (arg0 ? 12 : (return 123; 0))
369-
BasicInterpreter root = parseNodeForCompilation(bytecode, "multipleReturns", b -> {
375+
BasicInterpreter root = parseNodeForCompilation(run, "multipleReturns", b -> {
370376
b.beginRoot();
371377

372378
b.beginReturn();
@@ -404,7 +410,7 @@ public void testMultipleReturns() {
404410
@Test
405411
public void testStoreInvalidatesCode() {
406412
assumeTrue(hasBoxingElimination());
407-
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, BytecodeConfig.DEFAULT, b -> {
413+
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(run, BytecodeDSLTestLanguage.REF.get(null), BytecodeConfig.DEFAULT, b -> {
408414
b.beginRoot();
409415
BytecodeLocal x = b.createLocal("x", null);
410416
b.beginStoreLocal(x);
@@ -464,7 +470,7 @@ public void testStoreInvalidatesCode() {
464470
@Test
465471
public void testBytecodeNodeStoreInvalidatesCode() {
466472
assumeTrue(hasBoxingElimination());
467-
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, BytecodeConfig.DEFAULT, b -> {
473+
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(run, BytecodeDSLTestLanguage.REF.get(null), BytecodeConfig.DEFAULT, b -> {
468474
b.beginRoot();
469475
BytecodeLocal x = b.createLocal("x", null);
470476
b.beginStoreLocal(x);
@@ -538,7 +544,7 @@ public void testBytecodeNodeStoreInvalidatesCode() {
538544
@Test
539545
public void testMaterializedStoreInvalidatesCode() {
540546
assumeTrue(hasBoxingElimination());
541-
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, BytecodeConfig.DEFAULT, b -> {
547+
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(run, BytecodeDSLTestLanguage.REF.get(null), BytecodeConfig.DEFAULT, b -> {
542548
b.beginRoot();
543549
BytecodeLocal x = b.createLocal("x", null);
544550
b.beginStoreLocal(x);
@@ -616,7 +622,7 @@ public void testMaterializedStoreInvalidatesCode() {
616622
@Test
617623
public void testMaterializedAccessorStoreInvalidatesCode() {
618624
assumeTrue(hasBoxingElimination());
619-
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, BytecodeConfig.DEFAULT, b -> {
625+
BytecodeRootNodes<BasicInterpreter> rootNodes = createNodes(run, BytecodeDSLTestLanguage.REF.get(null), BytecodeConfig.DEFAULT, b -> {
620626
b.beginRoot();
621627
BytecodeLocal x = b.createLocal("x", null);
622628
b.beginStoreLocal(x);
@@ -689,7 +695,7 @@ public void testMaterializedAccessorStoreInvalidatesCode() {
689695

690696
@Test
691697
public void testInstrumentation() {
692-
BasicInterpreter root = parseNodeForCompilation(bytecode, "addTwoConstantsInstrumented", b -> {
698+
BasicInterpreter root = parseNodeForCompilation(run, "addTwoConstantsInstrumented", b -> {
693699
b.beginRoot();
694700

695701
b.beginReturn();
@@ -711,7 +717,7 @@ public void testInstrumentation() {
711717

712718
// Instrumentation should invalidate the compiled code.
713719
root.getRootNodes().update(
714-
bytecode.newConfigBuilder().addInstrumentation(BasicInterpreter.IncrementValue.class).build());
720+
run.bytecode().newConfigBuilder().addInstrumentation(BasicInterpreter.IncrementValue.class).build());
715721
assertNotCompiled(target);
716722

717723
// The instrumented interpreter should be recompiled.
@@ -724,7 +730,7 @@ public void testInstrumentation() {
724730

725731
@Test
726732
public void testYield() {
727-
BasicInterpreter root = parseNodeForCompilation(bytecode, "addYield", b -> {
733+
BasicInterpreter root = parseNodeForCompilation(run, "addYield", b -> {
728734
b.beginRoot();
729735

730736
b.beginReturn();
@@ -764,7 +770,7 @@ public void testYield() {
764770

765771
@Test
766772
public void testYieldInstrumentation() {
767-
BasicInterpreter root = parseNodeForCompilation(bytecode, "addYieldInstrumented", b -> {
773+
BasicInterpreter root = parseNodeForCompilation(run, "addYieldInstrumented", b -> {
768774
b.beginRoot();
769775

770776
b.beginReturn();
@@ -798,7 +804,7 @@ public void testYieldInstrumentation() {
798804

799805
// Instrumentation should invalidate the compiled code.
800806
root.getRootNodes().update(
801-
bytecode.newConfigBuilder().addInstrumentation(BasicInterpreter.IncrementValue.class).build());
807+
run.bytecode().newConfigBuilder().addInstrumentation(BasicInterpreter.IncrementValue.class).build());
802808
assertNotCompiled(target);
803809
assertNotCompiled(continuationCallTarget);
804810

@@ -816,7 +822,7 @@ public void testYieldInstrumentation() {
816822
@Test
817823
public void testCompiledSourceInfo() {
818824
Source s = Source.newBuilder("test", "return sourcePosition", "compiledSourceInfo").build();
819-
BasicInterpreter root = parseNodeForCompilation(bytecode, "compiledSourceInfo", b -> {
825+
BasicInterpreter root = parseNodeForCompilation(run, "compiledSourceInfo", b -> {
820826
b.beginSource(s);
821827
b.beginSourceSection(0, 21);
822828
b.beginRoot();
@@ -864,7 +870,7 @@ public void testCompiledSourceInfo() {
864870

865871
@Test
866872
public void testTagInstrumentation() {
867-
BasicInterpreter root = parseNodeForCompilation(bytecode, "tagInstrumentation", b -> {
873+
BasicInterpreter root = parseNodeForCompilation(run, "tagInstrumentation", b -> {
868874
b.beginRoot();
869875

870876
// i = 0
@@ -991,9 +997,9 @@ public void onEnter(VirtualFrame f) {
991997
return c;
992998
}
993999

994-
private static BasicInterpreter parseNodeForCompilation(BytecodeVariant bytecode,
1000+
private static BasicInterpreter parseNodeForCompilation(TestRun run,
9951001
String rootName, BytecodeParser<BasicInterpreterBuilder> builder) {
996-
BasicInterpreter result = parseNode(bytecode, BytecodeDSLTestLanguage.REF.get(null), false, rootName, builder);
1002+
BasicInterpreter result = parseNode(run, BytecodeDSLTestLanguage.REF.get(null), rootName, builder);
9971003
result.getBytecodeNode().setUncachedThreshold(0); // force interpreter to skip tier 0
9981004
return result;
9991005
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/BytecodeDSLPartialEvaluationTest.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import static com.oracle.truffle.api.bytecode.test.basic_interpreter.AbstractBasicInterpreterTest.parseNode;
2828

29+
import java.util.ArrayList;
2930
import java.util.List;
3031
import java.util.function.Supplier;
3132

@@ -43,6 +44,7 @@
4344
import com.oracle.truffle.api.bytecode.test.basic_interpreter.AbstractBasicInterpreterTest;
4445
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreter;
4546
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreterBuilder;
47+
import com.oracle.truffle.api.bytecode.test.basic_interpreter.AbstractBasicInterpreterTest.TestRun;
4648
import com.oracle.truffle.api.bytecode.test.basic_interpreter.BasicInterpreterBuilder.BytecodeVariant;
4749
import com.oracle.truffle.api.frame.VirtualFrame;
4850
import com.oracle.truffle.api.instrumentation.EventContext;
@@ -59,17 +61,21 @@ public class BytecodeDSLPartialEvaluationTest extends PartialEvaluationTest {
5961
protected static final BytecodeDSLTestLanguage LANGUAGE = null;
6062

6163
@Parameters(name = "{0}")
62-
public static List<BytecodeVariant> getInterpreterClasses() {
63-
return AbstractBasicInterpreterTest.allVariants();
64+
public static List<TestRun> getParameters() {
65+
List<TestRun> result = new ArrayList<>();
66+
for (BytecodeVariant bc : AbstractBasicInterpreterTest.allVariants()) {
67+
result.add(new TestRun(bc, false, false));
68+
}
69+
return result;
6470
}
6571

66-
@Parameter(0) public BytecodeVariant bytecode;
72+
@Parameter(0) public TestRun run;
6773

6874
@Test
6975
public void testAddTwoConstants() {
7076
// return 20 + 22;
7177

72-
BasicInterpreter root = parseNodeForPE(bytecode, "addTwoConstants", b -> {
78+
BasicInterpreter root = parseNodeForPE(run, "addTwoConstants", b -> {
7379
b.beginRoot();
7480

7581
b.beginReturn();
@@ -89,7 +95,7 @@ public void testAddTwoConstants() {
8995
public void testAddThreeConstants() {
9096
// return 40 + 22 + - 20;
9197

92-
BasicInterpreter root = parseNodeForPE(bytecode, "addThreeConstants", b -> {
98+
BasicInterpreter root = parseNodeForPE(run, "addThreeConstants", b -> {
9399
b.beginRoot();
94100

95101
b.beginReturn();
@@ -116,7 +122,7 @@ public void testAddThreeConstants() {
116122
public void testAddThreeConstantsWithConstantOperands() {
117123
// return 40 + 22 + - 20;
118124

119-
BasicInterpreter root = parseNodeForPE(bytecode, "addThreeConstantsWithConstantOperands", b -> {
125+
BasicInterpreter root = parseNodeForPE(run, "addThreeConstantsWithConstantOperands", b -> {
120126
b.beginRoot();
121127

122128
b.beginReturn();
@@ -148,7 +154,7 @@ public void testSum() {
148154

149155
long endValue = 10L;
150156

151-
BasicInterpreter root = parseNodeForPE(bytecode, "sum", b -> {
157+
BasicInterpreter root = parseNodeForPE(run, "sum", b -> {
152158
b.beginRoot();
153159

154160
BytecodeLocal i = b.createLocal();
@@ -209,7 +215,7 @@ public void testTryCatch() {
209215
// return 3;
210216
// @formatter:on
211217

212-
BasicInterpreter root = parseNodeForPE(bytecode, "sum", b -> {
218+
BasicInterpreter root = parseNodeForPE(run, "sum", b -> {
213219
b.beginRoot();
214220

215221
b.beginTryCatch();
@@ -257,7 +263,7 @@ public void testTryCatch2() {
257263
// return 42;
258264
// @formatter:on
259265

260-
BasicInterpreter root = parseNodeForPE(bytecode, "sum", b -> {
266+
BasicInterpreter root = parseNodeForPE(run, "sum", b -> {
261267
b.beginRoot();
262268

263269
b.beginTryCatch();
@@ -307,7 +313,7 @@ public void testTryCatch2() {
307313
public void testConditionalTrue() {
308314
// return true ? 42 : 21;
309315

310-
BasicInterpreter root = parseNodeForPE(bytecode, "conditionalTrue", b -> {
316+
BasicInterpreter root = parseNodeForPE(run, "conditionalTrue", b -> {
311317
b.beginRoot();
312318
b.beginReturn();
313319
b.beginConditional();
@@ -329,7 +335,7 @@ public void testConditionalTrue() {
329335
public void testConditionalFalse() {
330336
// return false ? 21 : 42;
331337

332-
BasicInterpreter root = parseNodeForPE(bytecode, "conditionalFalse", b -> {
338+
BasicInterpreter root = parseNodeForPE(run, "conditionalFalse", b -> {
333339
b.beginRoot();
334340

335341
b.beginReturn();
@@ -355,7 +361,7 @@ public void testEarlyReturn() {
355361
// earlyReturn(42) // throws exception caught by intercept hook
356362
// return 123
357363
// @formatter:on
358-
BasicInterpreter root = parseNodeForPE(bytecode, "earlyReturn", b -> {
364+
BasicInterpreter root = parseNodeForPE(run, "earlyReturn", b -> {
359365
b.beginRoot();
360366
b.beginBlock();
361367

@@ -380,7 +386,7 @@ public void testVariadicLength() {
380386

381387
// Note: the variadic array length is not PE constant beyond 8 arguments.
382388
final int numVariadic = 8;
383-
BasicInterpreter root = parseNodeForPE(bytecode, "variadicLength", b -> {
389+
BasicInterpreter root = parseNodeForPE(run, "variadicLength", b -> {
384390
b.beginRoot();
385391
b.beginBlock();
386392

@@ -406,7 +412,7 @@ public void testEmptyTagInstrumentation() {
406412
try (Context c = Context.create()) {
407413
c.enter();
408414

409-
BasicInterpreter root = parseNodeForPE(bytecode, "testEmptyTagInstrumentation", b -> {
415+
BasicInterpreter root = parseNodeForPE(run, "testEmptyTagInstrumentation", b -> {
410416
b.beginRoot();
411417

412418
b.beginTag(ExpressionTag.class);
@@ -441,7 +447,7 @@ public void testUnwindTagInstrumentation() {
441447

442448
String text = "return 20 + 22";
443449
Source s = Source.newBuilder("test", text, "testUnwindTagInstrumentation").build();
444-
BasicInterpreter root = parseNodeForPE(BytecodeDSLTestLanguage.REF.get(null), bytecode, "testUnwindTagInstrumentation", b -> {
450+
BasicInterpreter root = parseNodeForPE(BytecodeDSLTestLanguage.REF.get(null), run, "testUnwindTagInstrumentation", b -> {
445451
b.beginSource(s);
446452
b.beginSourceSection(0, text.length());
447453
b.beginRoot();
@@ -508,15 +514,15 @@ private static Supplier<Object> supplier(Object result) {
508514
return () -> result;
509515
}
510516

511-
private static BasicInterpreter parseNodeForPE(BytecodeVariant bytecode,
517+
private static BasicInterpreter parseNodeForPE(TestRun run,
512518
String rootName, BytecodeParser<BasicInterpreterBuilder> builder) {
513-
return parseNodeForPE(LANGUAGE, bytecode, rootName, builder);
519+
return parseNodeForPE(LANGUAGE, run, rootName, builder);
514520
}
515521

516522
private static <T extends BasicInterpreterBuilder> BasicInterpreter parseNodeForPE(BytecodeDSLTestLanguage language,
517-
BytecodeVariant bytecode, String rootName,
523+
TestRun run, String rootName,
518524
BytecodeParser<BasicInterpreterBuilder> builder) {
519-
BasicInterpreter result = parseNode(bytecode, language, false, rootName, builder);
525+
BasicInterpreter result = parseNode(run, language, rootName, builder);
520526
result.getBytecodeNode().setUncachedThreshold(0); // force interpreter to skip tier 0
521527
return result;
522528
}

0 commit comments

Comments
 (0)