129 MethodHandle test11_mh_test = lookup.findStatic(clazz, "test11_test", boolean_mt);
130 test11_mh = MethodHandles.guardWithTest(test11_mh_test,
131 MethodHandles.dropArguments(test11_mh1, 0, MethodHandle.class),
132 MethodHandles.invoker(myvalue2_mt));
133
134 MethodType test12_mt = MethodType.methodType(void.class, MyValue1.class);
135 test12_mh1 = lookup.findStatic(clazz, "test12_target1", test12_mt);
136 test12_mh2 = lookup.findStatic(clazz, "test12_target2", test12_mt);
137
138 MethodType test13_mt = MethodType.methodType(void.class, MyValue1.class);
139 test13_mh1 = lookup.findStatic(clazz, "test13_target1", test13_mt);
140 test13_mh2 = lookup.findStatic(clazz, "test13_target2", test13_mt);
141 } catch (NoSuchMethodException | IllegalAccessException e) {
142 e.printStackTrace();
143 throw new RuntimeException("Method handle lookup failed");
144 }
145 }
146
147 public static void main(String[] args) throws Throwable {
148 TestMethodHandles test = new TestMethodHandles();
149 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class);
150 }
151
152 // Everything inlined
153 final MyValue3 test1_vt = MyValue3.create();
154
155 @ForceInline
156 MyValue3 test1_target() {
157 return test1_vt;
158 }
159
160 static final MethodHandle test1_mh;
161
162 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + STORE + CALL)
163 @Test(valid = ValueTypeReturnedAsFieldsOff, match = { ALLOC, STORE }, matchCount = { 1, 11 })
164 MyValue3 test1() throws Throwable {
165 return (MyValue3)test1_mh.invokeExact(this);
166 }
167
168 @DontCompile
169 public void test1_verifier(boolean warmup) throws Throwable {
170 MyValue3 vt = test1();
171 test1_vt.verify(vt);
172 }
173
174 // Leaf method not inlined but returned type is known
175 final MyValue3 test2_vt = MyValue3.create();
176 @DontInline
177 MyValue3 test2_target() {
178 return test2_vt;
179 }
180
181 static final MethodHandle test2_mh;
182
183 @Test
184 MyValue3 test2() throws Throwable {
185 return (MyValue3)test2_mh.invokeExact(this);
186 }
187
188 @DontCompile
189 public void test2_verifier(boolean warmup) throws Throwable {
190 Method helper_m = getClass().getDeclaredMethod("test2_target");
191 if (!warmup && USE_COMPILER && !WHITE_BOX.isMethodCompiled(helper_m, false)) {
192 WHITE_BOX.enqueueMethodForCompilation(helper_m, COMP_LEVEL_FULL_OPTIMIZATION);
193 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(helper_m, false), "test2_target not compiled");
194 }
195 MyValue3 vt = test2();
196 test2_vt.verify(vt);
197 }
198
199 // Leaf method not inlined and returned type not known
200 final MyValue3 test3_vt = MyValue3.create();
201 @DontInline
202 MyValue3 test3_target() {
203 return test3_vt;
204 }
205
206 static final MethodHandle test3_mh;
207
208 @Test
209 MyValue3 test3() throws Throwable {
210 return (MyValue3)test3_mh.invokeExact(this);
211 }
212
213 @DontCompile
214 public void test3_verifier(boolean warmup) throws Throwable {
215 // hack so C2 doesn't know the target of the invoke call
216 Class c = Class.forName("java.lang.invoke.DirectMethodHandle");
217 Method m = c.getDeclaredMethod("internalMemberName", Object.class);
218 WHITE_BOX.testSetDontInlineMethod(m, warmup);
219 MyValue3 vt = test3();
220 test3_vt.verify(vt);
221 }
222
223 // When test75_helper1 is inlined in test75, the method handle
224 // linker that called it is passed a pointer to a copy of vt
225 // stored in memory. The method handle linker needs to load the
226 // fields from memory before it inlines test75_helper1.
227 static public int test4_helper1(MyValue1 vt) {
228 return vt.x;
229 }
272 MyValue3 test6_target1() {
273 return test6_vt1;
274 }
275
276 final MyValue3 test6_vt2 = MyValue3.create();
277 @ForceInline
278 MyValue3 test6_target2() {
279 return test6_vt2;
280 }
281
282 boolean test6_bool = true;
283 @ForceInline
284 boolean test6_test() {
285 return test6_bool;
286 }
287
288 static final MethodHandle test6_mh;
289
290 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
291 @Test(valid = ValueTypeReturnedAsFieldsOff)
292 MyValue3 test6() throws Throwable {
293 return (MyValue3)test6_mh.invokeExact(this);
294 }
295
296 @DontCompile
297 public void test6_verifier(boolean warmup) throws Throwable {
298 test6_bool = !test6_bool;
299 MyValue3 vt = test6();
300 vt.verify(test6_bool ? test6_vt1 : test6_vt2);
301 }
302
303 // Similar as above but with the method handle for target1 not
304 // constant. Shouldn't cause any allocation.
305 @ForceInline
306 static MyValue2 test7_target1() {
307 return MyValue2.createWithFieldsInline(rI, true);
308 }
309
310 @ForceInline
311 static MyValue2 test7_target2() {
312 return MyValue2.createWithFieldsInline(rI+1, false);
313 }
314
315 static boolean test7_bool = true;
316 @ForceInline
317 static boolean test7_test() {
318 return test7_bool;
319 }
320
321 static final MethodHandle test7_mh;
322 static MethodHandle test7_mh1;
323
324 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
325 @Test(valid = ValueTypeReturnedAsFieldsOff)
326 long test7() throws Throwable {
327 return ((MyValue2)test7_mh.invokeExact(test7_mh1)).hash();
328 }
329
330 @DontCompile
331 public void test7_verifier(boolean warmup) throws Throwable {
332 test7_bool = !test7_bool;
333 long hash = test7();
334 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+(test7_bool ? 0 : 1), test7_bool).hash());
335 }
336
337 // Same as above but with the method handle for target2 not
338 // constant. Shouldn't cause any allocation.
339 @ForceInline
340 static MyValue2 test8_target1() {
341 return MyValue2.createWithFieldsInline(rI, true);
342 }
343
344 @ForceInline
345 static MyValue2 test8_target2() {
346 return MyValue2.createWithFieldsInline(rI+1, false);
347 }
348
349 static boolean test8_bool = true;
350 @ForceInline
351 static boolean test8_test() {
352 return test8_bool;
353 }
354
355 static final MethodHandle test8_mh;
356 static MethodHandle test8_mh2;
357
358 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
359 @Test(valid = ValueTypeReturnedAsFieldsOff)
360 long test8() throws Throwable {
361 return ((MyValue2)test8_mh.invokeExact(test8_mh2)).hash();
362 }
363
364 @DontCompile
365 public void test8_verifier(boolean warmup) throws Throwable {
366 test8_bool = !test8_bool;
367 long hash = test8();
368 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+(test8_bool ? 0 : 1), test8_bool).hash());
369 }
370
371 // Return of target1, target2 and target3 merged in Lambda Forms
372 // as an Object. Shouldn't cause any allocation
373 final MyValue3 test9_vt1 = MyValue3.create();
374 @ForceInline
375 MyValue3 test9_target1() {
376 return test9_vt1;
377 }
378
379 final MyValue3 test9_vt2 = MyValue3.create();
380 @ForceInline
387 MyValue3 test9_target3() {
388 return test9_vt3;
389 }
390
391 boolean test9_bool1 = true;
392 @ForceInline
393 boolean test9_test1() {
394 return test9_bool1;
395 }
396
397 boolean test9_bool2 = true;
398 @ForceInline
399 boolean test9_test2() {
400 return test9_bool2;
401 }
402
403 static final MethodHandle test9_mh;
404
405 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
406 @Test(valid = ValueTypeReturnedAsFieldsOff)
407 MyValue3 test9() throws Throwable {
408 return (MyValue3)test9_mh.invokeExact(this);
409 }
410
411 static int test9_i = 0;
412 @DontCompile
413 public void test9_verifier(boolean warmup) throws Throwable {
414 test9_i++;
415 test9_bool1 = (test9_i % 2) == 0;
416 test9_bool2 = (test9_i % 3) == 0;
417 MyValue3 vt = test9();
418 vt.verify(test9_bool1 ? test9_vt1 : (test9_bool2 ? test9_vt2 : test9_vt3));
419 }
420
421 // Same as above but with non constant target2 and target3
422 @ForceInline
423 static MyValue2 test10_target1() {
424 return MyValue2.createWithFieldsInline(rI, true);
425 }
426
427 @ForceInline
435 }
436
437 static boolean test10_bool1 = true;
438 @ForceInline
439 static boolean test10_test1() {
440 return test10_bool1;
441 }
442
443 static boolean test10_bool2 = true;
444 @ForceInline
445 static boolean test10_test2() {
446 return test10_bool2;
447 }
448
449 static final MethodHandle test10_mh;
450 static MethodHandle test10_mh2;
451 static MethodHandle test10_mh3;
452
453 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
454 @Test(valid = ValueTypeReturnedAsFieldsOff)
455 long test10() throws Throwable {
456 return ((MyValue2)test10_mh.invokeExact(test10_mh2, test10_mh3)).hash();
457 }
458
459 static int test10_i = 0;
460
461 @DontCompile
462 public void test10_verifier(boolean warmup) throws Throwable {
463 test10_i++;
464 test10_bool1 = (test10_i % 2) == 0;
465 test10_bool2 = (test10_i % 3) == 0;
466 long hash = test10();
467 int i = rI+(test10_bool1 ? 0 : (test10_bool2 ? 1 : 2));
468 boolean b = test10_bool1 ? true : (test10_bool2 ? false : true);
469 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(i, b).hash());
470 }
471
472 static int test11_i = 0;
473
474 @ForceInline
475 static MyValue2 test11_target1() {
477 }
478
479 @ForceInline
480 static MyValue2 test11_target2() {
481 return MyValue2.createWithFieldsInline(rI-test11_i, false);
482 }
483
484 @ForceInline
485 static boolean test11_test() {
486 return (test11_i % 100) == 0;
487 }
488
489 static final MethodHandle test11_mh;
490 static MethodHandle test11_mh2;
491
492 // Check that a buffered value returned by a compiled lambda form
493 // is properly handled by the caller.
494 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
495 @Test(valid = ValueTypeReturnedAsFieldsOff)
496 @Warmup(11000)
497 long test11() throws Throwable {
498 return ((MyValue2)test11_mh.invokeExact(test11_mh2)).hash();
499 }
500
501 @DontCompile
502 public void test11_verifier(boolean warmup) throws Throwable {
503 test11_i++;
504 long hash = test11();
505 boolean b = (test11_i % 100) == 0;
506 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+test11_i * (b ? 1 : -1), b).hash());
507 }
508
509 static final MethodHandle test12_mh1;
510 static final MethodHandle test12_mh2;
511
512 __NotFlattened static MyValue1 nullValue;
513
514 @DontInline
515 static void test12_target1(MyValue1 vt) {
516 nullValue = vt;
517 }
518
519 @ForceInline
520 static void test12_target2(MyValue1 vt) {
521 nullValue = vt;
522 }
523
524 // Test passing null for a value type
525 @Test
526 @Warmup(11000) // Make sure lambda forms get compiled
527 public void test12() throws Throwable {
528 test12_mh1.invokeExact(nullValue);
529 test12_mh2.invokeExact(nullValue);
530 }
531
532 public void test12_verifier(boolean warmup) {
533 try {
534 test12();
535 } catch (Throwable t) {
536 throw new RuntimeException("test12 failed", t);
537 }
538 }
539
540 static MethodHandle test13_mh1;
541 static MethodHandle test13_mh2;
542
543 @DontInline
544 static void test13_target1(MyValue1 vt) {
545 nullValue = vt;
546 }
547
548 @ForceInline
549 static void test13_target2(MyValue1 vt) {
550 nullValue = vt;
551 }
552
553 // Same as test12 but with non-final mh
554 @Test
555 @Warmup(11000) // Make sure lambda forms get compiled
556 public void test13() throws Throwable {
557 test13_mh1.invokeExact(nullValue);
558 test13_mh2.invokeExact(nullValue);
559 }
560
561 public void test13_verifier(boolean warmup) {
562 try {
563 test13();
564 } catch (Throwable t) {
565 throw new RuntimeException("test13 failed", t);
566 }
567 }
568
569 // Same as test12/13 but with constant null
570 @Test
571 @Warmup(11000) // Make sure lambda forms get compiled
572 public void test14(MethodHandle mh) throws Throwable {
573 mh.invoke(null);
574 }
575
576 public void test14_verifier(boolean warmup) {
577 try {
578 test14(test12_mh1);
579 test14(test12_mh2);
580 test14(test13_mh1);
581 test14(test13_mh2);
582 } catch (Throwable t) {
583 throw new RuntimeException("test14 failed", t);
584 }
585 }
586 }
|
129 MethodHandle test11_mh_test = lookup.findStatic(clazz, "test11_test", boolean_mt);
130 test11_mh = MethodHandles.guardWithTest(test11_mh_test,
131 MethodHandles.dropArguments(test11_mh1, 0, MethodHandle.class),
132 MethodHandles.invoker(myvalue2_mt));
133
134 MethodType test12_mt = MethodType.methodType(void.class, MyValue1.class);
135 test12_mh1 = lookup.findStatic(clazz, "test12_target1", test12_mt);
136 test12_mh2 = lookup.findStatic(clazz, "test12_target2", test12_mt);
137
138 MethodType test13_mt = MethodType.methodType(void.class, MyValue1.class);
139 test13_mh1 = lookup.findStatic(clazz, "test13_target1", test13_mt);
140 test13_mh2 = lookup.findStatic(clazz, "test13_target2", test13_mt);
141 } catch (NoSuchMethodException | IllegalAccessException e) {
142 e.printStackTrace();
143 throw new RuntimeException("Method handle lookup failed");
144 }
145 }
146
147 public static void main(String[] args) throws Throwable {
148 TestMethodHandles test = new TestMethodHandles();
149 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, MyValue3.class, MyValue3Inline.class);
150 }
151
152 // Everything inlined
153 final MyValue3 test1_vt = MyValue3.create();
154
155 @ForceInline
156 MyValue3 test1_target() {
157 return test1_vt;
158 }
159
160 static final MethodHandle test1_mh;
161
162 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + STORE + CALL)
163 @Test(valid = ValueTypeReturnedAsFieldsOff, match = { ALLOC, STORE }, matchCount = { 1, 12 })
164 public MyValue3 test1() throws Throwable {
165 return (MyValue3)test1_mh.invokeExact(this);
166 }
167
168 @DontCompile
169 public void test1_verifier(boolean warmup) throws Throwable {
170 MyValue3 vt = test1();
171 test1_vt.verify(vt);
172 }
173
174 // Leaf method not inlined but returned type is known
175 final MyValue3 test2_vt = MyValue3.create();
176 @DontInline
177 MyValue3 test2_target() {
178 return test2_vt;
179 }
180
181 static final MethodHandle test2_mh;
182
183 @Test
184 public MyValue3 test2() throws Throwable {
185 return (MyValue3)test2_mh.invokeExact(this);
186 }
187
188 @DontCompile
189 public void test2_verifier(boolean warmup) throws Throwable {
190 Method helper_m = getClass().getDeclaredMethod("test2_target");
191 if (!warmup && USE_COMPILER && !WHITE_BOX.isMethodCompiled(helper_m, false)) {
192 WHITE_BOX.enqueueMethodForCompilation(helper_m, COMP_LEVEL_FULL_OPTIMIZATION);
193 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(helper_m, false), "test2_target not compiled");
194 }
195 MyValue3 vt = test2();
196 test2_vt.verify(vt);
197 }
198
199 // Leaf method not inlined and returned type not known
200 final MyValue3 test3_vt = MyValue3.create();
201 @DontInline
202 MyValue3 test3_target() {
203 return test3_vt;
204 }
205
206 static final MethodHandle test3_mh;
207
208 @Test
209 public MyValue3 test3() throws Throwable {
210 return (MyValue3)test3_mh.invokeExact(this);
211 }
212
213 @DontCompile
214 public void test3_verifier(boolean warmup) throws Throwable {
215 // hack so C2 doesn't know the target of the invoke call
216 Class c = Class.forName("java.lang.invoke.DirectMethodHandle");
217 Method m = c.getDeclaredMethod("internalMemberName", Object.class);
218 WHITE_BOX.testSetDontInlineMethod(m, warmup);
219 MyValue3 vt = test3();
220 test3_vt.verify(vt);
221 }
222
223 // When test75_helper1 is inlined in test75, the method handle
224 // linker that called it is passed a pointer to a copy of vt
225 // stored in memory. The method handle linker needs to load the
226 // fields from memory before it inlines test75_helper1.
227 static public int test4_helper1(MyValue1 vt) {
228 return vt.x;
229 }
272 MyValue3 test6_target1() {
273 return test6_vt1;
274 }
275
276 final MyValue3 test6_vt2 = MyValue3.create();
277 @ForceInline
278 MyValue3 test6_target2() {
279 return test6_vt2;
280 }
281
282 boolean test6_bool = true;
283 @ForceInline
284 boolean test6_test() {
285 return test6_bool;
286 }
287
288 static final MethodHandle test6_mh;
289
290 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
291 @Test(valid = ValueTypeReturnedAsFieldsOff)
292 public MyValue3 test6() throws Throwable {
293 return (MyValue3)test6_mh.invokeExact(this);
294 }
295
296 @DontCompile
297 public void test6_verifier(boolean warmup) throws Throwable {
298 test6_bool = !test6_bool;
299 MyValue3 vt = test6();
300 vt.verify(test6_bool ? test6_vt1 : test6_vt2);
301 }
302
303 // Similar as above but with the method handle for target1 not
304 // constant. Shouldn't cause any allocation.
305 @ForceInline
306 static MyValue2 test7_target1() {
307 return MyValue2.createWithFieldsInline(rI, true);
308 }
309
310 @ForceInline
311 static MyValue2 test7_target2() {
312 return MyValue2.createWithFieldsInline(rI+1, false);
313 }
314
315 static boolean test7_bool = true;
316 @ForceInline
317 static boolean test7_test() {
318 return test7_bool;
319 }
320
321 static final MethodHandle test7_mh;
322 static MethodHandle test7_mh1;
323
324 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
325 @Test(valid = ValueTypeReturnedAsFieldsOff)
326 public long test7() throws Throwable {
327 return ((MyValue2)test7_mh.invokeExact(test7_mh1)).hash();
328 }
329
330 @DontCompile
331 public void test7_verifier(boolean warmup) throws Throwable {
332 test7_bool = !test7_bool;
333 long hash = test7();
334 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+(test7_bool ? 0 : 1), test7_bool).hash());
335 }
336
337 // Same as above but with the method handle for target2 not
338 // constant. Shouldn't cause any allocation.
339 @ForceInline
340 static MyValue2 test8_target1() {
341 return MyValue2.createWithFieldsInline(rI, true);
342 }
343
344 @ForceInline
345 static MyValue2 test8_target2() {
346 return MyValue2.createWithFieldsInline(rI+1, false);
347 }
348
349 static boolean test8_bool = true;
350 @ForceInline
351 static boolean test8_test() {
352 return test8_bool;
353 }
354
355 static final MethodHandle test8_mh;
356 static MethodHandle test8_mh2;
357
358 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
359 @Test(valid = ValueTypeReturnedAsFieldsOff)
360 public long test8() throws Throwable {
361 return ((MyValue2)test8_mh.invokeExact(test8_mh2)).hash();
362 }
363
364 @DontCompile
365 public void test8_verifier(boolean warmup) throws Throwable {
366 test8_bool = !test8_bool;
367 long hash = test8();
368 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+(test8_bool ? 0 : 1), test8_bool).hash());
369 }
370
371 // Return of target1, target2 and target3 merged in Lambda Forms
372 // as an Object. Shouldn't cause any allocation
373 final MyValue3 test9_vt1 = MyValue3.create();
374 @ForceInline
375 MyValue3 test9_target1() {
376 return test9_vt1;
377 }
378
379 final MyValue3 test9_vt2 = MyValue3.create();
380 @ForceInline
387 MyValue3 test9_target3() {
388 return test9_vt3;
389 }
390
391 boolean test9_bool1 = true;
392 @ForceInline
393 boolean test9_test1() {
394 return test9_bool1;
395 }
396
397 boolean test9_bool2 = true;
398 @ForceInline
399 boolean test9_test2() {
400 return test9_bool2;
401 }
402
403 static final MethodHandle test9_mh;
404
405 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
406 @Test(valid = ValueTypeReturnedAsFieldsOff)
407 public MyValue3 test9() throws Throwable {
408 return (MyValue3)test9_mh.invokeExact(this);
409 }
410
411 static int test9_i = 0;
412 @DontCompile
413 public void test9_verifier(boolean warmup) throws Throwable {
414 test9_i++;
415 test9_bool1 = (test9_i % 2) == 0;
416 test9_bool2 = (test9_i % 3) == 0;
417 MyValue3 vt = test9();
418 vt.verify(test9_bool1 ? test9_vt1 : (test9_bool2 ? test9_vt2 : test9_vt3));
419 }
420
421 // Same as above but with non constant target2 and target3
422 @ForceInline
423 static MyValue2 test10_target1() {
424 return MyValue2.createWithFieldsInline(rI, true);
425 }
426
427 @ForceInline
435 }
436
437 static boolean test10_bool1 = true;
438 @ForceInline
439 static boolean test10_test1() {
440 return test10_bool1;
441 }
442
443 static boolean test10_bool2 = true;
444 @ForceInline
445 static boolean test10_test2() {
446 return test10_bool2;
447 }
448
449 static final MethodHandle test10_mh;
450 static MethodHandle test10_mh2;
451 static MethodHandle test10_mh3;
452
453 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
454 @Test(valid = ValueTypeReturnedAsFieldsOff)
455 public long test10() throws Throwable {
456 return ((MyValue2)test10_mh.invokeExact(test10_mh2, test10_mh3)).hash();
457 }
458
459 static int test10_i = 0;
460
461 @DontCompile
462 public void test10_verifier(boolean warmup) throws Throwable {
463 test10_i++;
464 test10_bool1 = (test10_i % 2) == 0;
465 test10_bool2 = (test10_i % 3) == 0;
466 long hash = test10();
467 int i = rI+(test10_bool1 ? 0 : (test10_bool2 ? 1 : 2));
468 boolean b = test10_bool1 ? true : (test10_bool2 ? false : true);
469 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(i, b).hash());
470 }
471
472 static int test11_i = 0;
473
474 @ForceInline
475 static MyValue2 test11_target1() {
477 }
478
479 @ForceInline
480 static MyValue2 test11_target2() {
481 return MyValue2.createWithFieldsInline(rI-test11_i, false);
482 }
483
484 @ForceInline
485 static boolean test11_test() {
486 return (test11_i % 100) == 0;
487 }
488
489 static final MethodHandle test11_mh;
490 static MethodHandle test11_mh2;
491
492 // Check that a buffered value returned by a compiled lambda form
493 // is properly handled by the caller.
494 @Test(valid = ValueTypeReturnedAsFieldsOn, failOn = ALLOC + ALLOCA + STORE + STOREVALUETYPEFIELDS)
495 @Test(valid = ValueTypeReturnedAsFieldsOff)
496 @Warmup(11000)
497 public long test11() throws Throwable {
498 return ((MyValue2)test11_mh.invokeExact(test11_mh2)).hash();
499 }
500
501 @DontCompile
502 public void test11_verifier(boolean warmup) throws Throwable {
503 test11_i++;
504 long hash = test11();
505 boolean b = (test11_i % 100) == 0;
506 Asserts.assertEQ(hash, MyValue2.createWithFieldsInline(rI+test11_i * (b ? 1 : -1), b).hash());
507 }
508
509 static final MethodHandle test12_mh1;
510 static final MethodHandle test12_mh2;
511
512 __NotFlattened static MyValue1 nullValue;
513
514 @DontInline
515 static void test12_target1(MyValue1 vt) {
516 nullValue = vt;
517 }
518
519 @ForceInline
520 static void test12_target2(MyValue1 vt) {
521 nullValue = vt;
522 }
523
524 // Test passing null for a value type
525 @Test
526 @Warmup(11000) // Make sure lambda forms get compiled
527 public void test12() throws Throwable {
528 test12_mh1.invokeExact(nullValue);
529 test12_mh2.invokeExact(nullValue);
530 }
531
532 @DontCompile
533 public void test12_verifier(boolean warmup) {
534 try {
535 test12();
536 } catch (Throwable t) {
537 throw new RuntimeException("test12 failed", t);
538 }
539 }
540
541 static MethodHandle test13_mh1;
542 static MethodHandle test13_mh2;
543
544 @DontInline
545 static void test13_target1(MyValue1 vt) {
546 nullValue = vt;
547 }
548
549 @ForceInline
550 static void test13_target2(MyValue1 vt) {
551 nullValue = vt;
552 }
553
554 // Same as test12 but with non-final mh
555 @Test
556 @Warmup(11000) // Make sure lambda forms get compiled
557 public void test13() throws Throwable {
558 test13_mh1.invokeExact(nullValue);
559 test13_mh2.invokeExact(nullValue);
560 }
561
562 @DontCompile
563 public void test13_verifier(boolean warmup) {
564 try {
565 test13();
566 } catch (Throwable t) {
567 throw new RuntimeException("test13 failed", t);
568 }
569 }
570
571 // Same as test12/13 but with constant null
572 @Test
573 @Warmup(11000) // Make sure lambda forms get compiled
574 public void test14(MethodHandle mh) throws Throwable {
575 mh.invoke(null);
576 }
577
578 @DontCompile
579 public void test14_verifier(boolean warmup) {
580 try {
581 test14(test12_mh1);
582 test14(test12_mh2);
583 test14(test13_mh1);
584 test14(test13_mh2);
585 } catch (Throwable t) {
586 throw new RuntimeException("test14 failed", t);
587 }
588 }
589 }
|