2129 MyValue3 vt = test75();
2130 test75_vt.verify(vt);
2131 }
2132
2133 // Test no result from inlined method for incremental inlining
2134 final MyValue3 test76_vt = MyValue3.create();
2135 public MyValue3 test76_inlined() {
2136 throw new RuntimeException();
2137 }
2138
2139 @Test
2140 public MyValue3 test76() {
2141 try {
2142 return test76_inlined();
2143 } catch (RuntimeException ex) {
2144 return test76_vt;
2145 }
2146 }
2147
2148 @DontCompile
2149 public void test76_verifier(boolean warmup) throws Exception {
2150 MyValue3 vt = test76();
2151 test76_vt.verify(vt);
2152 }
2153
2154 static {
2155 try {
2156 MethodHandles.Lookup lookup = MethodHandles.lookup();
2157 MethodType mt = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue3;", ValueTypeTestBench.class.getClassLoader());
2158 test73_mh = lookup.findVirtual(ValueTypeTestBench.class, "test73_target", mt);
2159 test74_mh = lookup.findVirtual(ValueTypeTestBench.class, "test74_target", mt);
2160 test75_mh = lookup.findVirtual(ValueTypeTestBench.class, "test75_target", mt);
2161 } catch (NoSuchMethodException|IllegalAccessException e) {
2162 throw new RuntimeException("method handle lookup fails");
2163 }
2164 }
2165
2166 /* Array load out of bounds (upper bound) at compile time.*/
2167 @Test
2168 public int test77() {
2169 int arraySize = Math.abs(rI) % 10;;
2348 Asserts.assertTrue(exceptionThrown, "ArrayStoreException must be thrown");
2349 }
2350
2351 private static MethodHandle generateInvalidVastore() {
2352 return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
2353 "Vastore",
2354 MethodType.methodType(void.class, ValueCapableClass2.class),
2355 CODE -> {
2356 CODE.
2357 iconst_1().
2358 anewarray(ValueType.forClass(ValueCapableClass1.class).valueClass()).
2359 iconst_0().
2360 aload_0().
2361 vunbox(ValueType.forClass(ValueCapableClass2.class).valueClass()).
2362 vastore().
2363 return_();
2364 }
2365 );
2366 }
2367
2368 // ========== Test infrastructure ==========
2369
2370 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
2371 private static final int ValueTypePassFieldsAsArgsOn = 0x1;
2372 private static final int ValueTypePassFieldsAsArgsOff = 0x2;
2373 private static final int ValueTypeArrayFlattenOn = 0x4;
2374 private static final int ValueTypeArrayFlattenOff = 0x8;
2375 private static final int ValueTypeReturnedAsFieldsOn = 0x10;
2376 private static final int ValueTypeReturnedAsFieldsOff = 0x20;
2377 static final int AllFlags = ValueTypePassFieldsAsArgsOn | ValueTypePassFieldsAsArgsOff | ValueTypeArrayFlattenOn | ValueTypeArrayFlattenOff | ValueTypeReturnedAsFieldsOn;
2378 private static final boolean ValueTypePassFieldsAsArgs = (Boolean)WHITE_BOX.getVMFlag("ValueTypePassFieldsAsArgs");
2379 private static final boolean ValueTypeArrayFlatten = (Boolean)WHITE_BOX.getVMFlag("ValueArrayFlatten");
2380 private static final boolean ValueTypeReturnedAsFields = (Boolean)WHITE_BOX.getVMFlag("ValueTypeReturnedAsFields");
2381 private static final int COMP_LEVEL_ANY = -1;
2382 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
2383 private static final Hashtable<String, Method> tests = new Hashtable<String, Method>();
2384 private static final int WARMUP = 251;
2385 private static boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler");
2386 private static boolean PRINT_IDEAL = WHITE_BOX.getBooleanVMFlag("PrintIdeal");
2387 private static boolean XCOMP = Platform.isComp();
|
2129 MyValue3 vt = test75();
2130 test75_vt.verify(vt);
2131 }
2132
2133 // Test no result from inlined method for incremental inlining
2134 final MyValue3 test76_vt = MyValue3.create();
2135 public MyValue3 test76_inlined() {
2136 throw new RuntimeException();
2137 }
2138
2139 @Test
2140 public MyValue3 test76() {
2141 try {
2142 return test76_inlined();
2143 } catch (RuntimeException ex) {
2144 return test76_vt;
2145 }
2146 }
2147
2148 @DontCompile
2149 public void test76_verifier(boolean warmup) {
2150 MyValue3 vt = test76();
2151 test76_vt.verify(vt);
2152 }
2153
2154 static {
2155 try {
2156 MethodHandles.Lookup lookup = MethodHandles.lookup();
2157 MethodType mt = MethodType.fromMethodDescriptorString("()Qcompiler/valhalla/valuetypes/MyValue3;", ValueTypeTestBench.class.getClassLoader());
2158 test73_mh = lookup.findVirtual(ValueTypeTestBench.class, "test73_target", mt);
2159 test74_mh = lookup.findVirtual(ValueTypeTestBench.class, "test74_target", mt);
2160 test75_mh = lookup.findVirtual(ValueTypeTestBench.class, "test75_target", mt);
2161 } catch (NoSuchMethodException|IllegalAccessException e) {
2162 throw new RuntimeException("method handle lookup fails");
2163 }
2164 }
2165
2166 /* Array load out of bounds (upper bound) at compile time.*/
2167 @Test
2168 public int test77() {
2169 int arraySize = Math.abs(rI) % 10;;
2348 Asserts.assertTrue(exceptionThrown, "ArrayStoreException must be thrown");
2349 }
2350
2351 private static MethodHandle generateInvalidVastore() {
2352 return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
2353 "Vastore",
2354 MethodType.methodType(void.class, ValueCapableClass2.class),
2355 CODE -> {
2356 CODE.
2357 iconst_1().
2358 anewarray(ValueType.forClass(ValueCapableClass1.class).valueClass()).
2359 iconst_0().
2360 aload_0().
2361 vunbox(ValueType.forClass(ValueCapableClass2.class).valueClass()).
2362 vastore().
2363 return_();
2364 }
2365 );
2366 }
2367
2368 // When test85_helper1 is inlined in test85, the method handle
2369 // linker that called it is passed a pointer to a copy of vt
2370 // stored in memory. The method handle linker needs to load the
2371 // fields from memory before it inlines test85_helper1.
2372 static public int test85_helper1(MyValue1 vt) {
2373 return vt.x;
2374 }
2375
2376 static MyValue1 test85_vt = MyValue1.createWithFieldsInline(rI, rL);
2377 static public MyValue1 test85_helper2() {
2378 return test85_vt;
2379 }
2380
2381 static final MethodHandle test85_mh;
2382
2383 @Test
2384 public int test85() throws Throwable {
2385 return (int)test85_mh.invokeExact();
2386 }
2387
2388 @DontCompile
2389 public void test85_verifier(boolean warmup) throws Throwable {
2390 int i = test85();
2391 Asserts.assertEQ(i, test85_vt.x);
2392 }
2393
2394 // Test method handle call with value type argument
2395 public int test86_target(MyValue1 vt) {
2396 return vt.x;
2397 }
2398
2399 static final MethodHandle test86_mh;
2400 MyValue1 test86_vt = MyValue1.createWithFieldsInline(rI, rL);
2401
2402 @Test
2403 public int test86() throws Throwable {
2404 return (int)test86_mh.invokeExact(this, test86_vt);
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 // ========== 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();
|