2405 }
2406
2407 @DontCompile
2408 public void test86_verifier(boolean warmup) throws Throwable {
2409 int i = test86();
2410 Asserts.assertEQ(i, test86_vt.x);
2411 }
2412
2413 static {
2414 try {
2415 MethodHandles.Lookup lookup = MethodHandles.lookup();
2416
2417 MethodType test85_mt1 = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2418 MethodType test85_mt2 = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue1;", ValueTypeTestBench.class.getClassLoader());
2419 MethodHandle test85_mh1 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper1", test85_mt1);
2420 MethodHandle test85_mh2 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper2", test85_mt2);
2421 test85_mh = MethodHandles.filterReturnValue(test85_mh2, test85_mh1);
2422
2423 MethodType test86_mt = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2424 test86_mh = lookup.findVirtual(ValueTypeTestBench.class, "test86_target", test86_mt);
2425 } catch (NoSuchMethodException|IllegalAccessException e) {
2426 throw new RuntimeException("method handle lookup fails");
2427 }
2428 }
2429
2430 static MyValue3 staticVal3;
2431 static MyValue3 staticVal3_copy;
2432
2433 // Check elimination of redundant value type allocations
2434 @Test(match = {ALLOC}, matchCount = {1})
2435 public MyValue3 test87(MyValue3[] va) {
2436 // Create value type and force allocation
2437 MyValue3 vt = MyValue3.create();
2438 va[0] = vt;
2439 staticVal3 = vt;
2440 vt.verify(staticVal3);
2441
2442 // Value type is now allocated, make a copy and force allocation.
2443 // Because copy is equal to vt, C2 should remove this redundant allocation.
2444 MyValue3 copy = MyValue3.setC(vt, vt.c);
2588 vload(0).
2589 vbox(ValueCapableClass1.class).
2590 areturn();
2591 });
2592 long result = 0;
2593 for (int i = 0; i < 10_000; ++i) {
2594 // Merge __Value (ValueCapableClass1) from the two GWT branches, box to the VCC and access field
2595 MethodHandle gwt = MethodHandles.guardWithTest(MethodHandles.constant(boolean.class, i % 2 == 0), dvt, dvt);
2596 ValueCapableClass1 vcc = (ValueCapableClass1) MethodHandles.filterReturnValue(gwt, box).invokeExact();
2597 result += vcc.t;
2598 }
2599 return result;
2600 }
2601
2602 @DontCompile
2603 public void test93_verifier(boolean warmup) throws Throwable {
2604 long result = test93();
2605 Asserts.assertEQ(result, 0L);
2606 }
2607
2608 // ========== Test infrastructure ==========
2609
2610 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
2611 private static final int ValueTypePassFieldsAsArgsOn = 0x1;
2612 private static final int ValueTypePassFieldsAsArgsOff = 0x2;
2613 private static final int ValueTypeArrayFlattenOn = 0x4;
2614 private static final int ValueTypeArrayFlattenOff = 0x8;
2615 private static final int ValueTypeReturnedAsFieldsOn = 0x10;
2616 private static final int ValueTypeReturnedAsFieldsOff = 0x20;
2617 static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
2618 private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
2619 private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
2620 private static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
2621 private static final int COMP_LEVEL_ANY = -1;
2622 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
2623 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
2624 private static final int WARMUP = 251;
2625 private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
2626 private static boolean PRINT_IDEAL = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
2627 private static boolean XCOMP = Platform.isComp();
2662 all_args.add(ValueTypeTestBench.class.getName());
2663 all_args.add("run");
2664 // Spawn process with default JVM options from the test's run command
2665 String[] vmInputArgs = InputArguments.getVmInputArgs();
2666 String[] cmds = Arrays.copyOf(vmInputArgs, vmInputArgs.length + all_args.size());
2667 System.arraycopy(all_args.toArray(), 0, cmds, vmInputArgs.length, all_args.size());
2668 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
2669 // If ideal graph printing is enabled/supported, verify output
2670 String output = oa.getOutput();
2671 oa.shouldHaveExitValue(0);
2672 boolean verifyIR = output.contains("PrintIdeal enabled") &&
2673 !output.contains("ValueTypePassFieldsAsArgs is not supported on this platform");
2674 if (verifyIR) {
2675 parseOutput(output);
2676 } else {
2677 System.out.println("WARNING: IR verification disabled! Running with -Xint, -Xcomp or release build?");
2678 }
2679 }
2680
2681 public static void main(String[] args) throws Throwable {
2682 //tests.values().removeIf(p -> !p.getName().equals("test85")); // Run single test
2683 if (args.length == 0) {
2684 execute_vm("-XX:+IgnoreUnrecognizedVMOptions", "-XX:-BackgroundCompilation",
2685 "-XX:+PrintCompilation", "-XX:+PrintInlining", "-XX:+PrintIdeal", "-XX:+PrintOptoAssembly",
2686 "-XX:CICompilerCount=1",
2687 "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.ValueTypeTestBench::*",
2688 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue1::*",
2689 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue2::*",
2690 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue3::*",
2691 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue4::*",
2692 "-XX:CompileCommand=compileonly,java.lang.Object::<init>",
2693 "-XX:CompileCommand=inline,java.lang.__Value::hashCode",
2694 "-XX:CompileCommand=compileonly,java.lang.invoke.*::*");
2695 } else {
2696 // Execute tests
2697 ValueTypeTestBench bench = new ValueTypeTestBench();
2698 bench.run();
2699 }
2700 }
2701
2702 public static void parseOutput(String output) throws Exception {
|
2405 }
2406
2407 @DontCompile
2408 public void test86_verifier(boolean warmup) throws Throwable {
2409 int i = test86();
2410 Asserts.assertEQ(i, test86_vt.x);
2411 }
2412
2413 static {
2414 try {
2415 MethodHandles.Lookup lookup = MethodHandles.lookup();
2416
2417 MethodType test85_mt1 = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2418 MethodType test85_mt2 = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue1;", ValueTypeTestBench.class.getClassLoader());
2419 MethodHandle test85_mh1 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper1", test85_mt1);
2420 MethodHandle test85_mh2 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper2", test85_mt2);
2421 test85_mh = MethodHandles.filterReturnValue(test85_mh2, test85_mh1);
2422
2423 MethodType test86_mt = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2424 test86_mh = lookup.findVirtual(ValueTypeTestBench.class, "test86_target", test86_mt);
2425
2426 MethodType test94_mt = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue3;", ValueTypeTestBench.class.getClassLoader());
2427 MethodHandle test94_mh1 = lookup.findVirtual(ValueTypeTestBench.class, "test94_target1", test94_mt);
2428 MethodHandle test94_mh2 = lookup.findVirtual(ValueTypeTestBench.class, "test94_target2", test94_mt);
2429 MethodType test94_mt2 = MethodType.methodType(boolean.class);
2430 MethodHandle test94_mh_test = lookup.findVirtual(ValueTypeTestBench.class, "test94_test", test94_mt2);
2431 test94_mh = MethodHandles.guardWithTest(test94_mh_test, test94_mh1, test94_mh2);
2432
2433 } catch (NoSuchMethodException|IllegalAccessException e) {
2434 throw new RuntimeException("method handle lookup fails");
2435 }
2436 }
2437
2438 static MyValue3 staticVal3;
2439 static MyValue3 staticVal3_copy;
2440
2441 // Check elimination of redundant value type allocations
2442 @Test(match = {ALLOC}, matchCount = {1})
2443 public MyValue3 test87(MyValue3[] va) {
2444 // Create value type and force allocation
2445 MyValue3 vt = MyValue3.create();
2446 va[0] = vt;
2447 staticVal3 = vt;
2448 vt.verify(staticVal3);
2449
2450 // Value type is now allocated, make a copy and force allocation.
2451 // Because copy is equal to vt, C2 should remove this redundant allocation.
2452 MyValue3 copy = MyValue3.setC(vt, vt.c);
2596 vload(0).
2597 vbox(ValueCapableClass1.class).
2598 areturn();
2599 });
2600 long result = 0;
2601 for (int i = 0; i < 10_000; ++i) {
2602 // Merge __Value (ValueCapableClass1) from the two GWT branches, box to the VCC and access field
2603 MethodHandle gwt = MethodHandles.guardWithTest(MethodHandles.constant(boolean.class, i % 2 == 0), dvt, dvt);
2604 ValueCapableClass1 vcc = (ValueCapableClass1) MethodHandles.filterReturnValue(gwt, box).invokeExact();
2605 result += vcc.t;
2606 }
2607 return result;
2608 }
2609
2610 @DontCompile
2611 public void test93_verifier(boolean warmup) throws Throwable {
2612 long result = test93();
2613 Asserts.assertEQ(result, 0L);
2614 }
2615
2616 // method handle combinators
2617 final MyValue3 test94_vt1 = MyValue3.create();
2618 @ForceInline
2619 MyValue3 test94_target1() {
2620 return test94_vt1;
2621 }
2622
2623 final MyValue3 test94_vt2 = MyValue3.create();
2624 @ForceInline
2625 MyValue3 test94_target2() {
2626 return test94_vt2;
2627 }
2628
2629 boolean test94_bool = true;
2630 @ForceInline
2631 boolean test94_test() {
2632 return test94_bool;
2633 }
2634
2635 static final MethodHandle test94_mh;
2636
2637 // @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE)
2638 // @Test(valid = ValueTypeReturnedAsFieldsOff)
2639 @Test()
2640 MyValue3 test94() throws Throwable {
2641 return (MyValue3)test94_mh.invokeExact(this);
2642 }
2643
2644 @DontCompile
2645 public void test94_verifier(boolean warmup) throws Throwable {
2646 test94_bool = !test94_bool;
2647 MyValue3 vt = test94();
2648 //vt.verify(test94_bool ? test94_vt1 : test94_vt2);
2649 }
2650
2651
2652 // ========== Test infrastructure ==========
2653
2654 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
2655 private static final int ValueTypePassFieldsAsArgsOn = 0x1;
2656 private static final int ValueTypePassFieldsAsArgsOff = 0x2;
2657 private static final int ValueTypeArrayFlattenOn = 0x4;
2658 private static final int ValueTypeArrayFlattenOff = 0x8;
2659 private static final int ValueTypeReturnedAsFieldsOn = 0x10;
2660 private static final int ValueTypeReturnedAsFieldsOff = 0x20;
2661 static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
2662 private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
2663 private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
2664 private static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
2665 private static final int COMP_LEVEL_ANY = -1;
2666 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
2667 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
2668 private static final int WARMUP = 251;
2669 private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
2670 private static boolean PRINT_IDEAL = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
2671 private static boolean XCOMP = Platform.isComp();
2706 all_args.add(ValueTypeTestBench.class.getName());
2707 all_args.add("run");
2708 // Spawn process with default JVM options from the test's run command
2709 String[] vmInputArgs = InputArguments.getVmInputArgs();
2710 String[] cmds = Arrays.copyOf(vmInputArgs, vmInputArgs.length + all_args.size());
2711 System.arraycopy(all_args.toArray(), 0, cmds, vmInputArgs.length, all_args.size());
2712 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
2713 // If ideal graph printing is enabled/supported, verify output
2714 String output = oa.getOutput();
2715 oa.shouldHaveExitValue(0);
2716 boolean verifyIR = output.contains("PrintIdeal enabled") &&
2717 !output.contains("ValueTypePassFieldsAsArgs is not supported on this platform");
2718 if (verifyIR) {
2719 parseOutput(output);
2720 } else {
2721 System.out.println("WARNING: IR verification disabled! Running with -Xint, -Xcomp or release build?");
2722 }
2723 }
2724
2725 public static void main(String[] args) throws Throwable {
2726 //tests.values().removeIf(p -> !p.getName().equals("test94")); // Run single test
2727 if (args.length == 0) {
2728 execute_vm("-XX:+IgnoreUnrecognizedVMOptions", "-XX:-BackgroundCompilation",
2729 "-XX:+PrintCompilation", "-XX:+PrintInlining", "-XX:+PrintIdeal", "-XX:+PrintOptoAssembly",
2730 "-XX:CICompilerCount=1",
2731 "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.ValueTypeTestBench::*",
2732 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue1::*",
2733 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue2::*",
2734 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue3::*",
2735 "-XX:CompileCommand=compileonly,compiler.valhalla.valuetypes.MyValue4::*",
2736 "-XX:CompileCommand=compileonly,java.lang.Object::<init>",
2737 "-XX:CompileCommand=inline,java.lang.__Value::hashCode",
2738 "-XX:CompileCommand=compileonly,java.lang.invoke.*::*");
2739 } else {
2740 // Execute tests
2741 ValueTypeTestBench bench = new ValueTypeTestBench();
2742 bench.run();
2743 }
2744 }
2745
2746 public static void parseOutput(String output) throws Exception {
|