< prev index next >

test/compiler/valhalla/valuetypes/ValueTypeTestBench.java

Print this page




  71 import java.util.List;
  72 import java.util.Map;
  73 import java.util.regex.Matcher;
  74 import java.util.regex.Pattern;
  75 import jdk.experimental.value.*;
  76 
  77 // Test value types
  78 __ByValue final class MyValue1 {
  79     static int s;
  80     static final long sf = ValueTypeTestBench.rL;
  81     final int x;
  82     final long y;
  83     final short z;
  84     final Integer o;
  85     final int[] oa;
  86     final MyValue2 v1;
  87     final MyValue2 v2;
  88     static final MyValue2 v3 = MyValue2.createWithFieldsInline(ValueTypeTestBench.rI, true);
  89     final int c;
  90 
  91     private MyValue1(int x, long y, short z, Integer o, int[] oa, MyValue2 v1, MyValue2 v2, int c) {
  92         s = x;
  93         this.x = x;
  94         this.y = y;
  95         this.z = z;
  96         this.o = o;
  97         this.oa = oa;
  98         this.v1 = v1;
  99         this.v2 = v2;
 100         this.c = c;
 101     }
 102 
 103     private MyValue1() {
 104         s = 0;
 105         this.x = 0;
 106         this.y = 0;
 107         this.z = 0;
 108         this.o = null;
 109         this.oa = null;
 110         this.v1 = MyValue2.createDefaultInline();
 111         this.v2 = MyValue2.createDefaultInline();
 112         this.c = 0;
 113     }
 114 
 115     @DontInline
 116     __ValueFactory static MyValue1 createDefaultDontInline() {
 117         return __MakeDefault MyValue1();
 118     }
 119 
 120     @ForceInline
 121     __ValueFactory static MyValue1 createDefaultInline() {
 122         return __MakeDefault MyValue1();
 123     }
 124 
 125     @DontInline
 126     static MyValue1 createWithFieldsDontInline(int x, long y) {
 127         MyValue1 v = createDefaultInline();
 128         v = setX(v, x);
 129         v = setY(v, y);
 130         v = setZ(v, (short)x);
 131         v = setO(v, new Integer(x));
 132         int[] oa = {x};
 133         v = setOA(v, oa);
 134         v = setV1(v, MyValue2.createWithFieldsInline(x, x < y));
 135         v = setV2(v, MyValue2.createWithFieldsInline(x, x > y));
 136         v = setC(v, ValueTypeTestBench.rI);
 137         return v;
 138     }
 139 
 140     @ForceInline
 141     static MyValue1 createWithFieldsInline(int x, long y) {
 142         MyValue1 v = createDefaultInline();
 143         v = setX(v, x);
 144         v = setY(v, y);
 145         v = setZ(v, (short)x);
 146         v = setO(v, new Integer(x));
 147         int[] oa = {x};
 148         v = setOA(v, oa);
 149         v = setV1(v, MyValue2.createWithFieldsInline(x, x < y));
 150         v = setV2(v, MyValue2.createWithFieldsInline(x, x > y));
 151         v = setC(v, ValueTypeTestBench.rI);
 152         return v;
 153     }
 154 
 155     // Hash only primitive and value type fields to avoid NullPointerException
 156     @ForceInline
 157     public long hashPrimitive() {


 217 
 218     @ForceInline
 219     __ValueFactory static MyValue1 setV1(MyValue1 v, MyValue2 v1) {
 220         v.v1 = v1;
 221         return v;
 222     }
 223 
 224     @ForceInline
 225     __ValueFactory static MyValue1 setV2(MyValue1 v, MyValue2 v2) {
 226         v.v2 = v2;
 227         return v;
 228     }
 229 }
 230 
 231 __ByValue final class MyValue2 {
 232     final int x;
 233     final byte y;
 234     final boolean b;
 235     final long c;
 236 
 237     private MyValue2(int x, byte y, boolean b, long c) {
 238         this.x = x;
 239         this.y = y;
 240         this.b = b;
 241         this.c = c;
 242     }
 243 
 244     private MyValue2() {
 245         this.x = 0;
 246         this.y = 0;
 247         this.b = false;
 248         this.c = 0;
 249     }
 250 
 251     @ForceInline
 252     __ValueFactory public static MyValue2 createDefaultInline() {
 253         return __MakeDefault MyValue2();
 254     }
 255 
 256     @ForceInline
 257     public static MyValue2 createWithFieldsInline(int x, boolean b) {
 258         MyValue2 v = createDefaultInline();
 259         v = setX(v, x);
 260         v = setY(v, (byte)x);
 261         v = setB(v, b);
 262         v = setC(v, ValueTypeTestBench.rL);
 263         return v;


 461     public static MyValue3 create() {
 462         java.util.Random r = Utils.getRandomInstance();
 463         MyValue3 v = createDefault();
 464         v = setC(v, (char)r.nextInt());
 465         v = setBB(v, (byte)r.nextInt());
 466         v = setS(v, (short)r.nextInt());
 467         v = setI(v, r.nextInt());
 468         v = setL(v, r.nextLong());
 469         v = setO(v, new Object());
 470         v = setF1(v, r.nextFloat());
 471         v = setF2(v, r.nextDouble());
 472         v = setF3(v, r.nextFloat());
 473         v = setF4(v, r.nextDouble());
 474         v = setF5(v, r.nextFloat());
 475         v = setF6(v, r.nextDouble());
 476         v = setF7(v, r.nextFloat());
 477         v = setF8(v, r.nextDouble());
 478         return v;
 479     }
 480 


























 481     public void verify(MyValue3 other) {
 482         Asserts.assertEQ(c, other.c);
 483         Asserts.assertEQ(bb, other.bb);
 484         Asserts.assertEQ(s, other.s);
 485         Asserts.assertEQ(i, other.i);
 486         Asserts.assertEQ(l, other.l);
 487         Asserts.assertEQ(o, other.o);
 488         Asserts.assertEQ(f1, other.f1);
 489         Asserts.assertEQ(f2, other.f2);
 490         Asserts.assertEQ(f3, other.f3);
 491         Asserts.assertEQ(f4, other.f4);
 492         Asserts.assertEQ(f5, other.f5);
 493         Asserts.assertEQ(f6, other.f6);
 494         Asserts.assertEQ(f7, other.f7);
 495         Asserts.assertEQ(f8, other.f8);
 496     }
 497 }
 498 
 499 // Value type definition with too many fields to return in registers
 500 __ByValue final class MyValue4 {


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     // ========== Test infrastructure ==========
2430 
2431     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
2432     private static final int ValueTypePassFieldsAsArgsOn = 0x1;
2433     private static final int ValueTypePassFieldsAsArgsOff = 0x2;
2434     private static final int ValueTypeArrayFlattenOn = 0x4;
2435     private static final int ValueTypeArrayFlattenOff = 0x8;
2436     private static final int ValueTypeReturnedAsFieldsOn = 0x10;
2437     private static final int ValueTypeReturnedAsFieldsOff = 0x20;
2438     static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
2439     private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
2440     private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
2441     private static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
2442     private static final int COMP_LEVEL_ANY = -1;
2443     private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
2444     private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
2445     private static final int WARMUP = 251;
2446     private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
2447     private static boolean PRINT_IDEAL  = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
2448     private static boolean XCOMP = Platform.isComp();


2632                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, true);
2633                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, false);
2634                 WHITE_BOX.testSetDontInlineMethod(m, true);
2635             }
2636             if (m.isAnnotationPresent(ForceInline.class)) {
2637                 WHITE_BOX.testSetForceInlineMethod(m, true);
2638             } else if (m.isAnnotationPresent(DontInline.class)) {
2639                 WHITE_BOX.testSetDontInlineMethod(m, true);
2640             }
2641         }
2642     }
2643 
2644     public void run() throws Exception {
2645         if (USE_COMPILER && PRINT_IDEAL && !XCOMP) {
2646             System.out.println("PrintIdeal enabled");
2647         }
2648         System.out.format("rI = %d, rL = %d\n", rI, rL);
2649         setup(this.getClass().getDeclaredMethods());
2650         setup(MyValue1.class.getDeclaredMethods());
2651         setup(MyValue2.class.getDeclaredMethods());


2652 
2653         // Compile class initializers
2654         WHITE_BOX.enqueueInitializerForCompilation(this.getClass(), COMP_LEVEL_FULL_OPTIMIZATION);
2655         WHITE_BOX.enqueueInitializerForCompilation(MyValue1.class, COMP_LEVEL_FULL_OPTIMIZATION);
2656         WHITE_BOX.enqueueInitializerForCompilation(MyValue2.class, COMP_LEVEL_FULL_OPTIMIZATION);


2657 
2658         // Execute tests
2659         for (Method test : tests.values()) {
2660             Method verifier = getClass().getDeclaredMethod(test.getName() + "_verifier", boolean.class);
2661             // Warmup using verifier method
2662             for (int i = 0; i < WARMUP; ++i) {
2663                 verifier.invoke(this, true);
2664             }
2665             // Trigger compilation
2666             WHITE_BOX.enqueueMethodForCompilation(test, COMP_LEVEL_FULL_OPTIMIZATION);
2667             Asserts.assertTrue(!USE_COMPILER || WHITE_BOX.isMethodCompiled(test, false), test + " not compiled");
2668             // Check result
2669             verifier.invoke(this, false);
2670         }
2671     }
2672 }
2673 
2674 // Mark method as test
2675 @Retention(RetentionPolicy.RUNTIME)
2676 @Repeatable(Tests.class)




  71 import java.util.List;
  72 import java.util.Map;
  73 import java.util.regex.Matcher;
  74 import java.util.regex.Pattern;
  75 import jdk.experimental.value.*;
  76 
  77 // Test value types
  78 __ByValue final class MyValue1 {
  79     static int s;
  80     static final long sf = ValueTypeTestBench.rL;
  81     final int x;
  82     final long y;
  83     final short z;
  84     final Integer o;
  85     final int[] oa;
  86     final MyValue2 v1;
  87     final MyValue2 v2;
  88     static final MyValue2 v3 = MyValue2.createWithFieldsInline(ValueTypeTestBench.rI, true);
  89     final int c;
  90 












  91     private MyValue1() {
  92         s = 0;
  93         this.x = 0;
  94         this.y = 0;
  95         this.z = 0;
  96         this.o = null;
  97         this.oa = null;
  98         this.v1 = MyValue2.createDefaultInline();
  99         this.v2 = MyValue2.createDefaultInline();
 100         this.c = 0;
 101     }
 102 
 103     @DontInline
 104     __ValueFactory static MyValue1 createDefaultDontInline() {
 105         return createDefaultInline();
 106     }
 107 
 108     @ForceInline
 109     __ValueFactory static MyValue1 createDefaultInline() {
 110         return __MakeDefault MyValue1();
 111     }
 112 
 113     @DontInline
 114     static MyValue1 createWithFieldsDontInline(int x, long y) {
 115         return createWithFieldsInline(x, y);










 116     }
 117 
 118     @ForceInline
 119     static MyValue1 createWithFieldsInline(int x, long y) {
 120         MyValue1 v = createDefaultInline();
 121         v = setX(v, x);
 122         v = setY(v, y);
 123         v = setZ(v, (short)x);
 124         v = setO(v, new Integer(x));
 125         int[] oa = {x};
 126         v = setOA(v, oa);
 127         v = setV1(v, MyValue2.createWithFieldsInline(x, x < y));
 128         v = setV2(v, MyValue2.createWithFieldsInline(x, x > y));
 129         v = setC(v, ValueTypeTestBench.rI);
 130         return v;
 131     }
 132 
 133     // Hash only primitive and value type fields to avoid NullPointerException
 134     @ForceInline
 135     public long hashPrimitive() {


 195 
 196     @ForceInline
 197     __ValueFactory static MyValue1 setV1(MyValue1 v, MyValue2 v1) {
 198         v.v1 = v1;
 199         return v;
 200     }
 201 
 202     @ForceInline
 203     __ValueFactory static MyValue1 setV2(MyValue1 v, MyValue2 v2) {
 204         v.v2 = v2;
 205         return v;
 206     }
 207 }
 208 
 209 __ByValue final class MyValue2 {
 210     final int x;
 211     final byte y;
 212     final boolean b;
 213     final long c;
 214 







 215     private MyValue2() {
 216         this.x = 0;
 217         this.y = 0;
 218         this.b = false;
 219         this.c = 0;
 220     }
 221 
 222     @ForceInline
 223     __ValueFactory public static MyValue2 createDefaultInline() {
 224         return __MakeDefault MyValue2();
 225     }
 226 
 227     @ForceInline
 228     public static MyValue2 createWithFieldsInline(int x, boolean b) {
 229         MyValue2 v = createDefaultInline();
 230         v = setX(v, x);
 231         v = setY(v, (byte)x);
 232         v = setB(v, b);
 233         v = setC(v, ValueTypeTestBench.rL);
 234         return v;


 432     public static MyValue3 create() {
 433         java.util.Random r = Utils.getRandomInstance();
 434         MyValue3 v = createDefault();
 435         v = setC(v, (char)r.nextInt());
 436         v = setBB(v, (byte)r.nextInt());
 437         v = setS(v, (short)r.nextInt());
 438         v = setI(v, r.nextInt());
 439         v = setL(v, r.nextLong());
 440         v = setO(v, new Object());
 441         v = setF1(v, r.nextFloat());
 442         v = setF2(v, r.nextDouble());
 443         v = setF3(v, r.nextFloat());
 444         v = setF4(v, r.nextDouble());
 445         v = setF5(v, r.nextFloat());
 446         v = setF6(v, r.nextDouble());
 447         v = setF7(v, r.nextFloat());
 448         v = setF8(v, r.nextDouble());
 449         return v;
 450     }
 451 
 452     @DontInline
 453     public static MyValue3 createDontInline() {
 454         return create();
 455     }
 456 
 457     @ForceInline
 458     public static MyValue3 copy(MyValue3 other) {
 459         MyValue3 v = createDefault();
 460         v = setC(v, other.c);
 461         v = setBB(v, other.bb);
 462         v = setS(v, other.s);
 463         v = setI(v, other.i);
 464         v = setL(v, other.l);
 465         v = setO(v, other.o);
 466         v = setF1(v, other.f1);
 467         v = setF2(v, other.f2);
 468         v = setF3(v, other.f3);
 469         v = setF4(v, other.f4);
 470         v = setF5(v, other.f5);
 471         v = setF6(v, other.f6);
 472         v = setF7(v, other.f7);
 473         v = setF8(v, other.f8);
 474         return v;
 475     }
 476 
 477     @DontInline
 478     public void verify(MyValue3 other) {
 479         Asserts.assertEQ(c, other.c);
 480         Asserts.assertEQ(bb, other.bb);
 481         Asserts.assertEQ(s, other.s);
 482         Asserts.assertEQ(i, other.i);
 483         Asserts.assertEQ(l, other.l);
 484         Asserts.assertEQ(o, other.o);
 485         Asserts.assertEQ(f1, other.f1);
 486         Asserts.assertEQ(f2, other.f2);
 487         Asserts.assertEQ(f3, other.f3);
 488         Asserts.assertEQ(f4, other.f4);
 489         Asserts.assertEQ(f5, other.f5);
 490         Asserts.assertEQ(f6, other.f6);
 491         Asserts.assertEQ(f7, other.f7);
 492         Asserts.assertEQ(f8, other.f8);
 493     }
 494 }
 495 
 496 // Value type definition with too many fields to return in registers
 497 __ByValue final class MyValue4 {


2406         int i = test86();
2407         Asserts.assertEQ(i, test86_vt.x);
2408     }
2409 
2410     static {
2411         try {
2412             MethodHandles.Lookup lookup = MethodHandles.lookup();
2413 
2414             MethodType test85_mt1 = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2415             MethodType test85_mt2 = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue1;", ValueTypeTestBench.class.getClassLoader());
2416             MethodHandle test85_mh1 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper1", test85_mt1);
2417             MethodHandle test85_mh2 = lookup.findStatic(ValueTypeTestBench.class, "test85_helper2", test85_mt2);
2418             test85_mh = MethodHandles.filterReturnValue(test85_mh2, test85_mh1);
2419 
2420             MethodType test86_mt = MethodType.fromMethodDescriptorString("(Qcompiler/valhalla/valuetypes/MyValue1;)I", ValueTypeTestBench.class.getClassLoader());
2421             test86_mh = lookup.findVirtual(ValueTypeTestBench.class, "test86_target", test86_mt);
2422         } catch (NoSuchMethodException|IllegalAccessException e) {
2423             throw new RuntimeException("method handle lookup fails");
2424         }
2425     }
2426 
2427     static MyValue3 staticVal3;
2428     static MyValue3 staticVal3_copy;
2429 
2430     // Check elimination of redundant value type allocations
2431     @Test(match = {ALLOC}, matchCount = {1})
2432     public MyValue3 test87(MyValue3[] va) {
2433         // Create value type and force allocation
2434         MyValue3 vt = MyValue3.create();
2435         va[0] = vt;
2436         staticVal3 = vt;
2437         vt.verify(staticVal3);
2438 
2439         // Value type is now allocated, make a copy and force allocation.
2440         // Because copy is equal to vt, C2 should remove this redundant allocation.
2441         MyValue3 copy = MyValue3.setC(vt, vt.c);
2442         va[0] = copy;
2443         staticVal3_copy = copy;
2444         copy.verify(staticVal3_copy);
2445         return copy;
2446     }
2447 
2448     @DontCompile
2449     public void test87_verifier(boolean warmup) {
2450         MyValue3[] va = new MyValue3[1];
2451         MyValue3 vt = test87(va);
2452         staticVal3.verify(vt);
2453         staticVal3.verify(va[0]);
2454         staticVal3_copy.verify(vt);
2455         staticVal3_copy.verify(va[0]);
2456     }
2457 
2458     // Verify that only dominating allocations are re-used
2459     @Test()
2460     public MyValue3 test88(boolean warmup) {
2461         MyValue3 vt = MyValue3.create();
2462         if (warmup) {
2463             staticVal3 = vt; // Force allocation
2464         }
2465         // Force allocation to verify that above
2466         // non-dominating allocation is not re-used
2467         MyValue3 copy = MyValue3.setC(vt, vt.c);
2468         staticVal3_copy = copy;
2469         copy.verify(vt);
2470         return copy;
2471     }
2472 
2473     @DontCompile
2474     public void test88_verifier(boolean warmup) {
2475         MyValue3 vt = test88(warmup);
2476         if (warmup) {
2477             staticVal3.verify(vt);
2478         }
2479     }
2480 
2481     // Verify that C2 recognizes value type loads and re-uses the oop to avoid allocations
2482     @Test(failOn = ALLOC + ALLOCA + STORE)
2483     public MyValue3 test89(MyValue3[] va) {
2484         // C2 can re-use the oop of staticVal3 because staticVal3 is equal to copy
2485         MyValue3 copy = MyValue3.copy(staticVal3);
2486         va[0] = copy;
2487         staticVal3 = copy;
2488         copy.verify(staticVal3);
2489         return copy;
2490     }
2491 
2492     @DontCompile
2493     public void test89_verifier(boolean warmup) {
2494         staticVal3 = MyValue3.create();
2495         MyValue3[] va = new MyValue3[1];
2496         MyValue3 vt = test89(va);
2497         staticVal3.verify(vt);
2498         staticVal3.verify(va[0]);
2499     }
2500 
2501     // Verify that C2 recognizes value type loads and re-uses the oop to avoid allocations
2502     @Test(valid = ValueTypeReturnedAsFieldsOff, failOn = ALLOC + ALLOCA + STORE)
2503     @Test(valid = ValueTypeReturnedAsFieldsOn)
2504     public MyValue3 test90(MyValue3[] va) {
2505         // C2 can re-use the oop returned by createDontInline()
2506         // because the corresponding value type is equal to 'copy'.
2507         MyValue3 copy = MyValue3.copy(MyValue3.createDontInline());
2508         va[0] = copy;
2509         staticVal3 = copy;
2510         copy.verify(staticVal3);
2511         return copy;
2512     }
2513 
2514     @DontCompile
2515     public void test90_verifier(boolean warmup) {
2516         MyValue3[] va = new MyValue3[1];
2517         MyValue3 vt = test90(va);
2518         staticVal3.verify(vt);
2519         staticVal3.verify(va[0]);
2520     }
2521 
2522     // Verify that C2 recognizes value type loads and re-uses the oop to avoid allocations
2523     @Test(valid = ValueTypePassFieldsAsArgsOff, failOn = ALLOC + ALLOCA + STORE)
2524     @Test(valid = ValueTypePassFieldsAsArgsOn)
2525     public MyValue3 test91(MyValue3 vt, MyValue3[] va) {
2526         // C2 can re-use the oop of vt because vt is equal to 'copy'.
2527         MyValue3 copy = MyValue3.copy(vt);
2528         va[0] = copy;
2529         staticVal3 = copy;
2530         copy.verify(staticVal3);
2531         return copy;
2532     }
2533 
2534     @DontCompile
2535     public void test91_verifier(boolean warmup) {
2536         MyValue3 vt = MyValue3.create();
2537         MyValue3[] va = new MyValue3[1];
2538         MyValue3 result = test91(vt, va);
2539         staticVal3.verify(vt);
2540         va[0].verify(vt);
2541         result.verify(vt);
2542     }
2543 
2544     // Test correct identification of value type copies
2545     @Test()
2546     public MyValue3 test92(MyValue3[] va) {
2547         MyValue3 vt = MyValue3.copy(staticVal3);
2548         vt = MyValue3.setI(vt, (int)vt.c);
2549         // vt is not equal to staticVal3, so C2 should not re-use the oop
2550         va[0] = vt;
2551         staticVal3 = vt;
2552         vt.verify(staticVal3);
2553         return vt;
2554     }
2555 
2556     @DontCompile
2557     public void test92_verifier(boolean warmup) {
2558         staticVal3 = MyValue3.create();
2559         MyValue3[] va = new MyValue3[1];
2560         MyValue3 vt = test92(va);
2561         Asserts.assertEQ(staticVal3.i, (int)staticVal3.c);
2562         Asserts.assertEQ(va[0].i, (int)staticVal3.c);
2563         Asserts.assertEQ(vt.i, (int)staticVal3.c);
2564     }
2565 
2566     // ========== Test infrastructure ==========
2567 
2568     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
2569     private static final int ValueTypePassFieldsAsArgsOn = 0x1;
2570     private static final int ValueTypePassFieldsAsArgsOff = 0x2;
2571     private static final int ValueTypeArrayFlattenOn = 0x4;
2572     private static final int ValueTypeArrayFlattenOff = 0x8;
2573     private static final int ValueTypeReturnedAsFieldsOn = 0x10;
2574     private static final int ValueTypeReturnedAsFieldsOff = 0x20;
2575     static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
2576     private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
2577     private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
2578     private static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
2579     private static final int COMP_LEVEL_ANY = -1;
2580     private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
2581     private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
2582     private static final int WARMUP = 251;
2583     private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
2584     private static boolean PRINT_IDEAL  = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
2585     private static boolean XCOMP = Platform.isComp();


2769                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, true);
2770                 WHITE_BOX.makeMethodNotCompilable(m, COMP_LEVEL_ANY, false);
2771                 WHITE_BOX.testSetDontInlineMethod(m, true);
2772             }
2773             if (m.isAnnotationPresent(ForceInline.class)) {
2774                 WHITE_BOX.testSetForceInlineMethod(m, true);
2775             } else if (m.isAnnotationPresent(DontInline.class)) {
2776                 WHITE_BOX.testSetDontInlineMethod(m, true);
2777             }
2778         }
2779     }
2780 
2781     public void run() throws Exception {
2782         if (USE_COMPILER && PRINT_IDEAL && !XCOMP) {
2783             System.out.println("PrintIdeal enabled");
2784         }
2785         System.out.format("rI = %d, rL = %d\n", rI, rL);
2786         setup(this.getClass().getDeclaredMethods());
2787         setup(MyValue1.class.getDeclaredMethods());
2788         setup(MyValue2.class.getDeclaredMethods());
2789         setup(MyValue3.class.getDeclaredMethods());
2790         setup(MyValue4.class.getDeclaredMethods());
2791 
2792         // Compile class initializers
2793         WHITE_BOX.enqueueInitializerForCompilation(this.getClass(), COMP_LEVEL_FULL_OPTIMIZATION);
2794         WHITE_BOX.enqueueInitializerForCompilation(MyValue1.class, COMP_LEVEL_FULL_OPTIMIZATION);
2795         WHITE_BOX.enqueueInitializerForCompilation(MyValue2.class, COMP_LEVEL_FULL_OPTIMIZATION);
2796         WHITE_BOX.enqueueInitializerForCompilation(MyValue3.class, COMP_LEVEL_FULL_OPTIMIZATION);
2797         WHITE_BOX.enqueueInitializerForCompilation(MyValue4.class, COMP_LEVEL_FULL_OPTIMIZATION);
2798 
2799         // Execute tests
2800         for (Method test : tests.values()) {
2801             Method verifier = getClass().getDeclaredMethod(test.getName() + "_verifier", boolean.class);
2802             // Warmup using verifier method
2803             for (int i = 0; i < WARMUP; ++i) {
2804                 verifier.invoke(this, true);
2805             }
2806             // Trigger compilation
2807             WHITE_BOX.enqueueMethodForCompilation(test, COMP_LEVEL_FULL_OPTIMIZATION);
2808             Asserts.assertTrue(!USE_COMPILER || WHITE_BOX.isMethodCompiled(test, false), test + " not compiled");
2809             // Check result
2810             verifier.invoke(this, false);
2811         }
2812     }
2813 }
2814 
2815 // Mark method as test
2816 @Retention(RetentionPolicy.RUNTIME)
2817 @Repeatable(Tests.class)


< prev index next >