1402 @Test()
1403 public void test58() {
1404 MyValue1 v1 = MyValue1.createInline(0, 0);
1405 MyValue1 v2 = MyValue1.createInline(1, 1);
1406 // Trigger OSR compilation and loop peeling
1407 for (int i = 0; i < 100_000; ++i) {
1408 if (v1.x != 2*i || v2.x != i+1 || v2.y != i+1) {
1409 // Uncommon trap
1410 throw new RuntimeException("test58 failed");
1411 }
1412 v1 = MyValue1.createInline(2*(i+1), 0);
1413 v2 = MyValue1.createInline(i+2, i+2);
1414 }
1415 }
1416
1417 @DontCompile
1418 public void test58_verifier(boolean warmup) {
1419 test58();
1420 }
1421
1422
1423 // ========== Test infrastructure ==========
1424
1425 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1426 private static final int ValueTypePassFieldsAsArgsOn = 0x1;
1427 private static final int ValueTypePassFieldsAsArgsOff = 0x2;
1428 private static final int ValueTypeArrayFlattenOn = 0x4;
1429 private static final int ValueTypeArrayFlattenOff = 0x8;
1430 static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff;
1431 private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
1432 private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
1433 private static final int COMP_LEVEL_ANY = -1;
1434 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
1435 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
1436 private static final int WARMUP = 250;
1437 private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
1438 private static boolean PRINT_IDEAL = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
1439 // TODO use Platform.isComp() after merge with JDK 9
1440 private static boolean XCOMP = System.getProperty("java.vm.info").startsWith("compiled ");
1441
1475 // If ideal graph printing is enabled/supported, verify output
1476 String output = oa.getOutput();
1477 oa.shouldHaveExitValue(0);
1478 boolean verifyIR = output.contains("PrintIdeal enabled") &&
1479 !output.contains("ValueTypePassFieldsAsArgs is not supported on this platform");
1480 if (verifyIR) {
1481 parseOutput(output);
1482 } else {
1483 System.out.println("WARNING: IR verification disabled! Running with -Xint, -Xcomp or release build?");
1484 }
1485 }
1486
1487 public static void main(String[] args) throws Throwable {
1488 //tests.values().removeIf(p -> !p.getName().equals("test58")); // Run single test
1489 if (args.length == 0) {
1490 execute_vm("-XX:+IgnoreUnrecognizedVMOptions", "-XX:-BackgroundCompilation",
1491 "-XX:+PrintCompilation", "-XX:+PrintIdeal", "-XX:+PrintOptoAssembly",
1492 "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.ValueTypeTestBench::*",
1493 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue1::*",
1494 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue2::*",
1495 "-XX:CompileCommand=compileonly,java.lang.Object::<init>");
1496 } else {
1497 // Execute tests
1498 ValueTypeTestBench bench = new ValueTypeTestBench();
1499 bench.run();
1500 }
1501 }
1502
1503 public static void parseOutput(String output) throws Exception {
1504 String split = "b compiler.valhalla.valuetypes.";
1505 String[] compilations = output.split(split);
1506 // Print header
1507 System.out.println(compilations[0]);
1508 // Iterate over compilation output
1509 for (String graph : compilations) {
1510 String[] lines = graph.split("\\n");
1511 if (lines[0].contains("@")) {
1512 continue; // Ignore OSR compilations
1513 }
1514 String testName = lines[0].split(" ")[0];
1515 Method test = tests.get(testName);
|
1402 @Test()
1403 public void test58() {
1404 MyValue1 v1 = MyValue1.createInline(0, 0);
1405 MyValue1 v2 = MyValue1.createInline(1, 1);
1406 // Trigger OSR compilation and loop peeling
1407 for (int i = 0; i < 100_000; ++i) {
1408 if (v1.x != 2*i || v2.x != i+1 || v2.y != i+1) {
1409 // Uncommon trap
1410 throw new RuntimeException("test58 failed");
1411 }
1412 v1 = MyValue1.createInline(2*(i+1), 0);
1413 v2 = MyValue1.createInline(i+2, i+2);
1414 }
1415 }
1416
1417 @DontCompile
1418 public void test58_verifier(boolean warmup) {
1419 test58();
1420 }
1421
1422 // When calling a method on __Value, passing fields as arguments is impossible
1423 @Test(valid = ValueTypePassFieldsAsArgsOn, match = {ALLOC, STORE}, matchCount={1, 9})
1424 @Test(valid = ValueTypePassFieldsAsArgsOff, failOn = ALLOC + STORE + LOAD)
1425 public String test59(MyValue1 v) {
1426 return v.toString();
1427 }
1428
1429 @DontCompile
1430 public void test59_verifier(boolean warmup) {
1431 boolean failed = false;
1432 try {
1433 test59(val1);
1434 failed = true;
1435 } catch (UnsupportedOperationException uoe) {
1436 }
1437 Asserts.assertFalse(failed);
1438 }
1439
1440 // Same as above, but the method on __Value is inlined
1441 // hashCode allocates an exception so can't really check the graph shape
1442 @Test()
1443 public int test60(MyValue1 v) {
1444 return v.hashCode();
1445 }
1446
1447 @DontCompile
1448 public void test60_verifier(boolean warmup) {
1449 boolean failed = false;
1450 try {
1451 test60(val1);
1452 failed = true;
1453 } catch (UnsupportedOperationException uoe) {
1454 }
1455 Asserts.assertFalse(failed);
1456 }
1457
1458 // ========== Test infrastructure ==========
1459
1460 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1461 private static final int ValueTypePassFieldsAsArgsOn = 0x1;
1462 private static final int ValueTypePassFieldsAsArgsOff = 0x2;
1463 private static final int ValueTypeArrayFlattenOn = 0x4;
1464 private static final int ValueTypeArrayFlattenOff = 0x8;
1465 static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff;
1466 private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
1467 private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
1468 private static final int COMP_LEVEL_ANY = -1;
1469 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
1470 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
1471 private static final int WARMUP = 250;
1472 private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
1473 private static boolean PRINT_IDEAL = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
1474 // TODO use Platform.isComp() after merge with JDK 9
1475 private static boolean XCOMP = System.getProperty("java.vm.info").startsWith("compiled ");
1476
1510 // If ideal graph printing is enabled/supported, verify output
1511 String output = oa.getOutput();
1512 oa.shouldHaveExitValue(0);
1513 boolean verifyIR = output.contains("PrintIdeal enabled") &&
1514 !output.contains("ValueTypePassFieldsAsArgs is not supported on this platform");
1515 if (verifyIR) {
1516 parseOutput(output);
1517 } else {
1518 System.out.println("WARNING: IR verification disabled! Running with -Xint, -Xcomp or release build?");
1519 }
1520 }
1521
1522 public static void main(String[] args) throws Throwable {
1523 //tests.values().removeIf(p -> !p.getName().equals("test58")); // Run single test
1524 if (args.length == 0) {
1525 execute_vm("-XX:+IgnoreUnrecognizedVMOptions", "-XX:-BackgroundCompilation",
1526 "-XX:+PrintCompilation", "-XX:+PrintIdeal", "-XX:+PrintOptoAssembly",
1527 "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.ValueTypeTestBench::*",
1528 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue1::*",
1529 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue2::*",
1530 "-XX:CompileCommand=compileonly,java.lang.Object::<init>",
1531 "-XX:CompileCommand=inline,java.lang.__Value::hashCode");
1532 } else {
1533 // Execute tests
1534 ValueTypeTestBench bench = new ValueTypeTestBench();
1535 bench.run();
1536 }
1537 }
1538
1539 public static void parseOutput(String output) throws Exception {
1540 String split = "b compiler.valhalla.valuetypes.";
1541 String[] compilations = output.split(split);
1542 // Print header
1543 System.out.println(compilations[0]);
1544 // Iterate over compilation output
1545 for (String graph : compilations) {
1546 String[] lines = graph.split("\\n");
1547 if (lines[0].contains("@")) {
1548 continue; // Ignore OSR compilations
1549 }
1550 String testName = lines[0].split(" ")[0];
1551 Method test = tests.get(testName);
|