50 switch (scenario) {
51 case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:ValueArrayElemMaxFlatSize=-1"};
52 case 4: return new String[] {"-XX:-MonomorphicArrayCheck"};
53 }
54 return null;
55 }
56
57 public static void main(String[] args) throws Throwable {
58 TestIntrinsics test = new TestIntrinsics();
59 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class);
60 }
61
62 // Test correctness of the Class::isAssignableFrom intrinsic
63 @Test()
64 public boolean test1(Class<?> supercls, Class<?> subcls) {
65 return supercls.isAssignableFrom(subcls);
66 }
67
68 public void test1_verifier(boolean warmup) {
69 Asserts.assertTrue(test1(java.util.AbstractList.class, java.util.ArrayList.class), "test1_1 failed");
70 Asserts.assertTrue(test1(MyValue1.class.asBoxType(), MyValue1.class.asBoxType()), "test1_2 failed");
71 Asserts.assertTrue(test1(MyValue1.class.asValueType(), MyValue1.class.asValueType()), "test1_3 failed");
72 Asserts.assertTrue(test1(MyValue1.class.asBoxType(), MyValue1.class.asValueType()), "test1_4 failed");
73 Asserts.assertTrue(test1(MyValue1.class.asValueType(), MyValue1.class.asBoxType()), "test1_5 failed");
74 Asserts.assertTrue(test1(Object.class, java.util.ArrayList.class), "test1_6 failed");
75 Asserts.assertTrue(test1(Object.class, MyValue1.class.asBoxType()), "test1_7 failed");
76 Asserts.assertTrue(test1(Object.class, MyValue1.class.asValueType()), "test1_8 failed");
77 Asserts.assertTrue(!test1(MyValue1.class.asBoxType(), Object.class), "test1_9 failed");
78 Asserts.assertTrue(!test1(MyValue1.class.asValueType(), Object.class), "test1_10 failed");
79 }
80
81 // Verify that Class::isAssignableFrom checks with statically known classes are folded
82 @Test(failOn = LOADK)
83 public boolean test2() {
84 boolean check1 = java.util.AbstractList.class.isAssignableFrom(java.util.ArrayList.class);
85 boolean check2 = MyValue1.class.asBoxType().isAssignableFrom(MyValue1.class.asBoxType());
86 boolean check3 = MyValue1.class.asValueType().isAssignableFrom(MyValue1.class.asValueType());
87 boolean check4 = MyValue1.class.asBoxType().isAssignableFrom(MyValue1.class.asValueType());
88 boolean check5 = MyValue1.class.asValueType().isAssignableFrom(MyValue1.class.asBoxType());
89 boolean check6 = Object.class.isAssignableFrom(java.util.ArrayList.class);
90 boolean check7 = Object.class.isAssignableFrom(MyValue1.class.asBoxType());
91 boolean check8 = Object.class.isAssignableFrom(MyValue1.class.asValueType());
92 boolean check9 = !MyValue1.class.asBoxType().isAssignableFrom(Object.class);
93 boolean check10 = !MyValue1.class.asValueType().isAssignableFrom(Object.class);
94 return check1 && check2 && check3 && check4 && check5 && check6 && check7 && check8 && check9 && check10;
95 }
96
97 public void test2_verifier(boolean warmup) {
98 Asserts.assertTrue(test2(), "test2 failed");
99 }
100
101 // Test correctness of the Class::getSuperclass intrinsic
102 @Test()
103 public Class<?> test3(Class<?> cls) {
104 return cls.getSuperclass();
105 }
106
107 public void test3_verifier(boolean warmup) {
108 Asserts.assertTrue(test3(Object.class) == null, "test3_1 failed");
109 Asserts.assertTrue(test3(MyValue1.class.asBoxType()) == Object.class, "test3_2 failed");
110 Asserts.assertTrue(test3(MyValue1.class.asValueType()) == Object.class, "test3_3 failed");
111 Asserts.assertTrue(test3(Class.class) == Object.class, "test3_4 failed");
112 }
113
114 // Verify that Class::getSuperclass checks with statically known classes are folded
115 @Test(failOn = LOADK)
116 public boolean test4() {
117 boolean check1 = Object.class.getSuperclass() == null;
118 boolean check2 = MyValue1.class.asBoxType().getSuperclass() == Object.class;
119 boolean check3 = MyValue1.class.asValueType().getSuperclass() == Object.class;
120 boolean check4 = Class.class.getSuperclass() == Object.class;
121 return check1 && check2 && check3 && check4;
122 }
123
124 public void test4_verifier(boolean warmup) {
125 Asserts.assertTrue(test4(), "test4 failed");
126 }
127
128 // Test toString() method
129 @Test()
130 public String test5(MyValue1 v) {
131 return v.toString();
132 }
133
134 @DontCompile
135 public void test5_verifier(boolean warmup) {
136 MyValue1 v = MyValue1.createDefaultInline();
137 test5(v);
138 }
139
144 }
145
146 @DontCompile
147 public void test6_verifier(boolean warmup) {
148 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
149 int res = test6(v);
150 Asserts.assertEQ(res, v.hashCode());
151 }
152
153 // Test default value type array creation via reflection
154 @Test()
155 public Object[] test7(Class<?> componentType, int len) {
156 Object[] va = (Object[])Array.newInstance(componentType, len);
157 return va;
158 }
159
160 @DontCompile
161 public void test7_verifier(boolean warmup) {
162 int len = Math.abs(rI) % 42;
163 long hash = MyValue1.createDefaultDontInline().hashPrimitive();
164 Object[] va = test7(MyValue1.class.asValueType(), len);
165 for (int i = 0; i < len; ++i) {
166 Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
167 }
168 }
169
170 // Class.isInstance
171 @Test()
172 public boolean test8(Class c, MyValue1 vt) {
173 return c.isInstance(vt);
174 }
175
176 @DontCompile
177 public void test8_verifier(boolean warmup) {
178 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
179 boolean result = test8(MyValue1.class.asValueType(), vt);
180 Asserts.assertTrue(result);
181 result = test8(MyValue1.class.asBoxType(), vt);
182 Asserts.assertTrue(result);
183 }
184
185 @Test()
186 public boolean test9(Class c, MyValue1 vt) {
187 return c.isInstance(vt);
188 }
189
190 @DontCompile
191 public void test9_verifier(boolean warmup) {
192 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
193 boolean result = test9(MyValue2.class.asValueType(), vt);
194 Asserts.assertFalse(result);
195 result = test9(MyValue2.class.asBoxType(), vt);
196 Asserts.assertFalse(result);
197 }
198
199 // Class.cast
200 @Test()
201 public Object test10(Class c, MyValue1 vt) {
202 return c.cast(vt);
203 }
204
205 @DontCompile
206 public void test10_verifier(boolean warmup) {
207 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
208 Object result = test10(MyValue1.class.asValueType(), vt);
209 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
210 }
211
212 @Test()
213 public Object test11(Class c, MyValue1 vt) {
214 return c.cast(vt);
215 }
216
217 @DontCompile
218 public void test11_verifier(boolean warmup) {
219 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
220 try {
221 test11(MyValue2.class.asValueType(), vt);
222 throw new RuntimeException("should have thrown");
223 } catch (ClassCastException cce) {
224 }
225 }
226
227 @Test()
228 public Object test12(MyValue1 vt) {
229 return MyValue1.class.asValueType().cast(vt);
230 }
231
232 @DontCompile
233 public void test12_verifier(boolean warmup) {
234 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
235 Object result = test12(vt);
236 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
237 }
238
239 @Test()
240 public Object test13(MyValue1 vt) {
241 return MyValue2.class.asValueType().cast(vt);
242 }
243
244 @DontCompile
245 public void test13_verifier(boolean warmup) {
246 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
247 try {
248 test13(vt);
249 throw new RuntimeException("should have thrown");
250 } catch (ClassCastException cce) {
251 }
252 }
253
254 // value type array creation via reflection
255 @Test()
256 public void test14(int len, long hash) {
257 Object[] va = (Object[])Array.newInstance(MyValue1.class.asValueType().asBoxType().asValueType(), len);
258 for (int i = 0; i < len; ++i) {
259 Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
260 }
261 }
262
263 @DontCompile
264 public void test14_verifier(boolean warmup) {
265 int len = Math.abs(rI) % 42;
266 long hash = MyValue1.createDefaultDontInline().hashPrimitive();
267 test14(len, hash);
268 }
269
270 // Test hashCode() method
271 @Test()
272 public int test15(Object v) {
273 return v.hashCode();
274 }
275
276 @DontCompile
277 public void test15_verifier(boolean warmup) {
337 MyValue1 res = b ? vt1 : vt2;
338 return res.toString();
339 }
340
341 @DontCompile
342 public void test20_verifier(boolean warmup) {
343 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
344 String res = test20(vt, vt, true);
345 Asserts.assertEQ(res, vt.toString());
346 res = test20(vt, vt, false);
347 Asserts.assertEQ(res, vt.toString());
348 }
349
350 private static final Unsafe U = Unsafe.getUnsafe();
351 private static final long X_OFFSET;
352 private static final long Y_OFFSET;
353 private static final long V1_OFFSET;
354 private static final boolean V1_FLATTENED;
355 static {
356 try {
357 Field xField = MyValue1.class.asValueType().getDeclaredField("x");
358 X_OFFSET = U.objectFieldOffset(xField);
359 Field yField = MyValue1.class.asValueType().getDeclaredField("y");
360 Y_OFFSET = U.objectFieldOffset(yField);
361 Field v1Field = MyValue1.class.asValueType().getDeclaredField("v1");
362 V1_OFFSET = U.objectFieldOffset(v1Field);
363 V1_FLATTENED = U.isFlattened(v1Field);
364 } catch (Exception e) {
365 throw new RuntimeException(e);
366 }
367 }
368
369 protected static final String CALL_Unsafe = START + "CallStaticJava" + MID + "# Static jdk.internal.misc.Unsafe::" + END;
370
371 @Test(failOn=CALL_Unsafe)
372 public int test21(MyValue1 v) {
373 return U.getInt(v, X_OFFSET);
374 }
375
376 @DontCompile
377 public void test21_verifier(boolean warmup) {
378 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
379 int res = test21(v);
380 Asserts.assertEQ(res, v.x);
381 }
432 final Test25Value[] test25Array = new Test25Value[10];
433
434 @Test
435 public Test25Value[] test25(Test25Value element) {
436 Test25Value[] newArray = Arrays.copyOf(test25Array, test25Array.length + 1);
437 newArray[test25Array.length] = element;
438 return newArray;
439 }
440
441 @DontCompile
442 public void test25_verifier(boolean warmup) {
443 Test25Value vt = new Test25Value();
444 test25(vt);
445 }
446
447 @Test
448 public Object test26() {
449 Class<?>[] ca = new Class<?>[1];
450 for (int i = 0; i < 1; ++i) {
451 // Folds during loop opts
452 ca[i] = MyValue1.class.asValueType();
453 }
454 return Array.newInstance(ca[0], 1);
455 }
456
457 @DontCompile
458 public void test26_verifier(boolean warmup) {
459 Object[] res = (Object[])test26();
460 Asserts.assertEQ(((MyValue1)res[0]).hashPrimitive(), MyValue1.createDefaultInline().hashPrimitive());
461 }
462
463 // Load non-flattenable value type field with unsafe
464 MyValue1? test27_vt = MyValue1.createWithFieldsInline(rI, rL);
465 private static final long TEST27_OFFSET;
466 static {
467 try {
468 Field field = TestIntrinsics.class.getDeclaredField("test27_vt");
469 TEST27_OFFSET = U.objectFieldOffset(field);
470 } catch (Exception e) {
471 throw new RuntimeException(e);
472 }
517 long res = test29(v);
518 if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
519 if (X_OFFSET < Y_OFFSET) {
520 Asserts.assertEQ(((int)res) << 8, (v.x >> 8) << 8);
521 } else {
522 Asserts.assertEQ(res << 8, (v.y >> 8) << 8);
523 }
524 } else {
525 if (X_OFFSET < Y_OFFSET) {
526 Asserts.assertEQ(((int)res), v.x >>> 8);
527 } else {
528 Asserts.assertEQ(res, v.y >>> 8);
529 }
530 }
531 }
532
533 // getValue to retrieve flattened field from value
534 @Test(failOn=CALL_Unsafe)
535 public MyValue2 test30(MyValue1 v) {
536 if (V1_FLATTENED) {
537 return U.getValue(v, V1_OFFSET, MyValue2.class.asValueType().asBoxType().asValueType());
538 }
539 return (MyValue2)U.getReference(v, V1_OFFSET);
540 }
541
542 @DontCompile
543 public void test30_verifier(boolean warmup) {
544 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
545 MyValue2 res = test30(v);
546 Asserts.assertEQ(res.hash(), v.v1.hash());
547 }
548
549 MyValue1 test31_vt;
550 private static final long TEST31_VT_OFFSET;
551 private static final boolean TEST31_VT_FLATTENED;
552 static {
553 try {
554 Field test31_vt_Field = TestIntrinsics.class.getDeclaredField("test31_vt");
555 TEST31_VT_OFFSET = U.objectFieldOffset(test31_vt_Field);
556 TEST31_VT_FLATTENED = U.isFlattened(test31_vt_Field);
557 } catch (Exception e) {
558 throw new RuntimeException(e);
559 }
560 }
561
562 // getValue to retrieve flattened field from object
563 @Test(failOn=CALL_Unsafe)
564 public MyValue1 test31() {
565 if (TEST31_VT_FLATTENED) {
566 return U.getValue(this, TEST31_VT_OFFSET, MyValue1.class.asValueType().asBoxType().asValueType());
567 }
568 return (MyValue1)U.getReference(this, TEST31_VT_OFFSET);
569 }
570
571 @DontCompile
572 public void test31_verifier(boolean warmup) {
573 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
574 MyValue1 res = test31();
575 Asserts.assertEQ(res.hash(), test31_vt.hash());
576 }
577
578 // putValue to set flattened field in object
579 @Test(failOn=CALL_Unsafe)
580 public void test32(MyValue1 vt) {
581 if (TEST31_VT_FLATTENED) {
582 U.putValue(this, TEST31_VT_OFFSET, MyValue1.class.asValueType().asBoxType().asValueType(), vt);
583 } else {
584 U.putReference(this, TEST31_VT_OFFSET, vt);
585 }
586 }
587
588 @DontCompile
589 public void test32_verifier(boolean warmup) {
590 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
591 test31_vt = MyValue1.createDefaultInline();
592 test32(vt);
593 Asserts.assertEQ(vt.hash(), test31_vt.hash());
594 }
595
596 private static final int TEST33_BASE_OFFSET;
597 private static final int TEST33_INDEX_SCALE;
598 private static final boolean TEST33_FLATTENED_ARRAY;
599 static {
600 try {
601 TEST33_BASE_OFFSET = U.arrayBaseOffset(MyValue1[].class);
602 TEST33_INDEX_SCALE = U.arrayIndexScale(MyValue1[].class);
603 TEST33_FLATTENED_ARRAY = U.isFlattenedArray(MyValue1[].class);
604 } catch (Exception e) {
605 throw new RuntimeException(e);
606 }
607 }
608 // getValue to retrieve flattened field from array
609 @Test(failOn=CALL_Unsafe)
610 public MyValue1 test33(MyValue1[] arr) {
611 if (TEST33_FLATTENED_ARRAY) {
612 return U.getValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class.asValueType().asBoxType().asValueType());
613 }
614 return (MyValue1)U.getReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE);
615 }
616
617 @DontCompile
618 public void test33_verifier(boolean warmup) {
619 MyValue1[] arr = new MyValue1[2];
620 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
621 arr[1] = vt;
622 MyValue1 res = test33(arr);
623 Asserts.assertEQ(res.hash(), vt.hash());
624 }
625
626 // putValue to set flattened field in array
627 @Test(failOn=CALL_Unsafe)
628 public void test34(MyValue1[] arr, MyValue1 vt) {
629 if (TEST33_FLATTENED_ARRAY) {
630 U.putValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class.asValueType().asBoxType().asValueType(), vt);
631 } else {
632 U.putReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, vt);
633 }
634 }
635
636 @DontCompile
637 public void test34_verifier(boolean warmup) {
638 MyValue1[] arr = new MyValue1[2];
639 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
640 test34(arr, vt);
641 Asserts.assertEQ(arr[1].hash(), vt.hash());
642 }
643
644 // getValue to retrieve flattened field from object with unknown
645 // container type
646 @Test(failOn=CALL_Unsafe)
647 public MyValue1 test35(Object o) {
648 if (TEST31_VT_FLATTENED) {
649 return U.getValue(o, TEST31_VT_OFFSET, MyValue1.class.asValueType().asBoxType().asValueType());
650 }
651 return (MyValue1)U.getReference(o, TEST31_VT_OFFSET);
652 }
653
654 @DontCompile
655 public void test35_verifier(boolean warmup) {
656 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
657 MyValue1 res = test35(this);
658 Asserts.assertEQ(res.hash(), test31_vt.hash());
659 }
660
661 // getValue to retrieve flattened field from object at unknown
662 // offset
663 @Test(failOn=CALL_Unsafe)
664 public MyValue1 test36(long offset) {
665 if (TEST31_VT_FLATTENED) {
666 return U.getValue(this, offset, MyValue1.class.asValueType().asBoxType().asValueType());
667 }
668 return (MyValue1)U.getReference(this, offset);
669 }
670
671 @DontCompile
672 public void test36_verifier(boolean warmup) {
673 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
674 MyValue1 res = test36(TEST31_VT_OFFSET);
675 Asserts.assertEQ(res.hash(), test31_vt.hash());
676 }
677
678 // putValue to set flattened field in object with unknown
679 // container
680 @Test(failOn=CALL_Unsafe)
681 public void test37(Object o, MyValue1 vt) {
682 if (TEST31_VT_FLATTENED) {
683 U.putValue(o, TEST31_VT_OFFSET, MyValue1.class.asValueType().asBoxType().asValueType(), vt);
684 } else {
685 U.putReference(o, TEST31_VT_OFFSET, vt);
686 }
687 }
688
689 @DontCompile
690 public void test37_verifier(boolean warmup) {
691 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
692 test31_vt = MyValue1.createDefaultInline();
693 test37(this, vt);
694 Asserts.assertEQ(vt.hash(), test31_vt.hash());
695 }
696
697 // putValue to set flattened field in object, non value argument
698 // to store
699 @Test(match = { CALL_Unsafe }, matchCount = { 1 })
700 public void test38(Object o) {
701 if (TEST31_VT_FLATTENED) {
702 U.putValue(this, TEST31_VT_OFFSET, MyValue1.class.asValueType().asBoxType().asValueType(), o);
703 } else {
704 U.putReference(this, TEST31_VT_OFFSET, o);
705 }
706 }
707
708 @DontCompile
709 public void test38_verifier(boolean warmup) {
710 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
711 test31_vt = MyValue1.createDefaultInline();
712 test38(vt);
713 Asserts.assertEQ(vt.hash(), test31_vt.hash());
714 }
715
716 @Test(failOn=CALL_Unsafe)
717 public MyValue1 test39(MyValue1 v) {
718 v = U.makePrivateBuffer(v);
719 U.putInt(v, X_OFFSET, rI);
720 v = U.finishPrivateBuffer(v);
721 return v;
722 }
723
724 @DontCompile
725 public void test39_verifier(boolean warmup) {
726 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
727 MyValue1 res = test39(v.setX(v, 0));
728 Asserts.assertEQ(res.hash(), v.hash());
729 }
730
731 // Test default value type array creation via reflection
732 @Test()
733 public Object[] test40(Class<?> componentType, int len) {
734 Object[] va = (Object[])Array.newInstance(componentType, len);
735 return va;
736 }
737
738 @DontCompile
739 public void test40_verifier(boolean warmup) {
740 int len = Math.abs(rI) % 42;
741 Object[] va = test40(MyValue1.class.asBoxType(), len);
742 for (int i = 0; i < len; ++i) {
743 Asserts.assertEQ(va[i], null);
744 }
745 }
746
747 // Class.isInstance
748 @Test()
749 public boolean test41(Class c, MyValue1? vt) {
750 return c.isInstance(vt);
751 }
752
753 @DontCompile
754 public void test41_verifier(boolean warmup) {
755 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
756 boolean result = test41(MyValue1.class.asBoxType(), vt);
757 Asserts.assertTrue(result);
758 result = test41(MyValue1.class.asValueType(), vt);
759 Asserts.assertTrue(result);
760 }
761
762 @Test()
763 public boolean test42(Class c, MyValue1? vt) {
764 return c.isInstance(vt);
765 }
766
767 @DontCompile
768 public void test42_verifier(boolean warmup) {
769 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
770 boolean result = test42(MyValue2.class.asBoxType(), vt);
771 Asserts.assertFalse(result);
772 result = test42(MyValue2.class.asValueType(), vt);
773 Asserts.assertFalse(result);
774 }
775
776 // Class.cast
777 @Test()
778 public Object test43(Class c, MyValue1? vt) {
779 return c.cast(vt);
780 }
781
782 @DontCompile
783 public void test43_verifier(boolean warmup) {
784 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
785 Object result = test43(MyValue1.class.asBoxType(), vt);
786 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
787 result = test43(MyValue1.class.asBoxType(), null);
788 Asserts.assertEQ(result, null);
789 }
790
791 @Test()
792 public Object test44(Class c, MyValue1? vt) {
793 return c.cast(vt);
794 }
795
796 @DontCompile
797 public void test44_verifier(boolean warmup) {
798 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
799 try {
800 test44(MyValue2.class.asBoxType(), vt);
801 throw new RuntimeException("should have thrown");
802 } catch (ClassCastException cce) {
803 }
804 }
805
806 @Test()
807 public Object test45(MyValue1? vt) {
808 return MyValue1.class.asBoxType().cast(vt);
809 }
810
811 @DontCompile
812 public void test45_verifier(boolean warmup) {
813 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
814 Object result = test45(vt);
815 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
816 result = test45(null);
817 Asserts.assertEQ(result, null);
818 }
819
820 @Test()
821 public Object test46(MyValue1? vt) {
822 return MyValue2.class.asBoxType().cast(vt);
823 }
824
825 @DontCompile
826 public void test46_verifier(boolean warmup) {
827 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
828 test46(null);
829 try {
830 test46(vt);
831 throw new RuntimeException("should have thrown");
832 } catch (ClassCastException cce) {
833 }
834 }
835
836 @Test()
837 public Object test47(MyValue1? vt) {
838 return MyValue1.class.asValueType().cast(vt);
839 }
840
841 @DontCompile
842 public void test47_verifier(boolean warmup) {
843 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
844 Object result = test47(vt);
845 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
846 try {
847 test47(null);
848 throw new RuntimeException("should have thrown");
849 } catch (NullPointerException npe) {
850 }
851 }
852
853 @Test()
854 public Object test48(Class c, MyValue1? vt) {
855 return c.cast(vt);
856 }
857
858 @DontCompile
859 public void test48_verifier(boolean warmup) {
860 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
861 Object result = test48(MyValue1.class.asValueType(), vt);
862 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
863 try {
864 test48(MyValue1.class.asValueType(), null);
865 throw new RuntimeException("should have thrown");
866 } catch (NullPointerException npe) {
867 }
868 }
869
870 @Test()
871 public Object test49(MyValue1 vt) {
872 return MyValue1.class.asBoxType().cast(vt);
873 }
874
875 @DontCompile
876 public void test49_verifier(boolean warmup) {
877 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
878 Object result = test49(vt);
879 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
880 }
881
882 @Test()
883 public Object test50(Class c, Object obj) {
884 return c.cast(obj);
885 }
886
887 @DontCompile
888 public void test50_verifier(boolean warmup) {
889 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
890 MyValue1[] va = new MyValue1[42];
891 MyValue1?[] vba = new MyValue1?[42];
892 Object result = test50(MyValue1.class.asValueType(), vt);
893 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
894 result = test50(MyValue1.class.asBoxType(), vt);
895 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
896 result = test50(MyValue1[].class, va);
897 Asserts.assertEQ(result, va);
898 result = test50(MyValue1?[].class, vba);
899 Asserts.assertEQ(result, vba);
900 result = test50(MyValue1?[].class, va);
901 Asserts.assertEQ(result, va);
902 try {
903 test50(MyValue1.class.asValueType(), null);
904 throw new RuntimeException("should have thrown");
905 } catch (NullPointerException npe) {
906 }
907 try {
908 test50(MyValue1[].class, vba);
909 throw new RuntimeException("should have thrown");
910 } catch (ClassCastException cce) {
911 }
912 }
913
914 // value type array creation via reflection
915 @Test()
916 public void test51(int len) {
917 Object[] va = (Object[])Array.newInstance(MyValue1.class.asBoxType().asValueType().asBoxType(), len);
918 for (int i = 0; i < len; ++i) {
919 Asserts.assertEQ(va[i], null);
920 }
921 }
922
923 @DontCompile
924 public void test51_verifier(boolean warmup) {
925 int len = Math.abs(rI) % 42;
926 test51(len);
927 }
928
929 // multidimensional value type array creation via reflection
930 @Test()
931 public Object[][] test52(int len, int val) {
932 MyValue1[][] va1 = (MyValue1[][])Array.newInstance(MyValue1[].class, len);
933 MyValue1?[][] va2 = (MyValue1?[][])Array.newInstance(MyValue1?[].class, len);
934 Object[][] result;
935 if (val == 1) {
936 va1[0] = new MyValue1[1];
937 result = va1;
|
50 switch (scenario) {
51 case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:ValueArrayElemMaxFlatSize=-1"};
52 case 4: return new String[] {"-XX:-MonomorphicArrayCheck"};
53 }
54 return null;
55 }
56
57 public static void main(String[] args) throws Throwable {
58 TestIntrinsics test = new TestIntrinsics();
59 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class);
60 }
61
62 // Test correctness of the Class::isAssignableFrom intrinsic
63 @Test()
64 public boolean test1(Class<?> supercls, Class<?> subcls) {
65 return supercls.isAssignableFrom(subcls);
66 }
67
68 public void test1_verifier(boolean warmup) {
69 Asserts.assertTrue(test1(java.util.AbstractList.class, java.util.ArrayList.class), "test1_1 failed");
70 Asserts.assertTrue(test1(MyValue1.class.asNullableType(), MyValue1.class.asNullableType()), "test1_2 failed");
71 Asserts.assertTrue(test1(MyValue1.class.asPrimaryType(), MyValue1.class.asPrimaryType()), "test1_3 failed");
72 Asserts.assertTrue(test1(MyValue1.class.asNullableType(), MyValue1.class.asPrimaryType()), "test1_4 failed");
73 Asserts.assertTrue(test1(MyValue1.class.asPrimaryType(), MyValue1.class.asNullableType()), "test1_5 failed");
74 Asserts.assertTrue(test1(Object.class, java.util.ArrayList.class), "test1_6 failed");
75 Asserts.assertTrue(test1(Object.class, MyValue1.class.asNullableType()), "test1_7 failed");
76 Asserts.assertTrue(test1(Object.class, MyValue1.class.asPrimaryType()), "test1_8 failed");
77 Asserts.assertTrue(!test1(MyValue1.class.asNullableType(), Object.class), "test1_9 failed");
78 Asserts.assertTrue(!test1(MyValue1.class.asPrimaryType(), Object.class), "test1_10 failed");
79 }
80
81 // Verify that Class::isAssignableFrom checks with statically known classes are folded
82 @Test(failOn = LOADK)
83 public boolean test2() {
84 boolean check1 = java.util.AbstractList.class.isAssignableFrom(java.util.ArrayList.class);
85 boolean check2 = MyValue1.class.asNullableType().isAssignableFrom(MyValue1.class.asNullableType());
86 boolean check3 = MyValue1.class.asPrimaryType().isAssignableFrom(MyValue1.class.asPrimaryType());
87 boolean check4 = MyValue1.class.asNullableType().isAssignableFrom(MyValue1.class.asPrimaryType());
88 boolean check5 = MyValue1.class.asPrimaryType().isAssignableFrom(MyValue1.class.asNullableType());
89 boolean check6 = Object.class.isAssignableFrom(java.util.ArrayList.class);
90 boolean check7 = Object.class.isAssignableFrom(MyValue1.class.asNullableType());
91 boolean check8 = Object.class.isAssignableFrom(MyValue1.class.asPrimaryType());
92 boolean check9 = !MyValue1.class.asNullableType().isAssignableFrom(Object.class);
93 boolean check10 = !MyValue1.class.asPrimaryType().isAssignableFrom(Object.class);
94 return check1 && check2 && check3 && check4 && check5 && check6 && check7 && check8 && check9 && check10;
95 }
96
97 public void test2_verifier(boolean warmup) {
98 Asserts.assertTrue(test2(), "test2 failed");
99 }
100
101 // Test correctness of the Class::getSuperclass intrinsic
102 @Test()
103 public Class<?> test3(Class<?> cls) {
104 return cls.getSuperclass();
105 }
106
107 public void test3_verifier(boolean warmup) {
108 Asserts.assertTrue(test3(Object.class) == null, "test3_1 failed");
109 Asserts.assertTrue(test3(MyValue1.class.asNullableType()) == Object.class, "test3_2 failed");
110 Asserts.assertTrue(test3(MyValue1.class.asPrimaryType()) == Object.class, "test3_3 failed");
111 Asserts.assertTrue(test3(Class.class) == Object.class, "test3_4 failed");
112 }
113
114 // Verify that Class::getSuperclass checks with statically known classes are folded
115 @Test(failOn = LOADK)
116 public boolean test4() {
117 boolean check1 = Object.class.getSuperclass() == null;
118 boolean check2 = MyValue1.class.asNullableType().getSuperclass() == Object.class;
119 boolean check3 = MyValue1.class.asPrimaryType().getSuperclass() == Object.class;
120 boolean check4 = Class.class.getSuperclass() == Object.class;
121 return check1 && check2 && check3 && check4;
122 }
123
124 public void test4_verifier(boolean warmup) {
125 Asserts.assertTrue(test4(), "test4 failed");
126 }
127
128 // Test toString() method
129 @Test()
130 public String test5(MyValue1 v) {
131 return v.toString();
132 }
133
134 @DontCompile
135 public void test5_verifier(boolean warmup) {
136 MyValue1 v = MyValue1.createDefaultInline();
137 test5(v);
138 }
139
144 }
145
146 @DontCompile
147 public void test6_verifier(boolean warmup) {
148 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
149 int res = test6(v);
150 Asserts.assertEQ(res, v.hashCode());
151 }
152
153 // Test default value type array creation via reflection
154 @Test()
155 public Object[] test7(Class<?> componentType, int len) {
156 Object[] va = (Object[])Array.newInstance(componentType, len);
157 return va;
158 }
159
160 @DontCompile
161 public void test7_verifier(boolean warmup) {
162 int len = Math.abs(rI) % 42;
163 long hash = MyValue1.createDefaultDontInline().hashPrimitive();
164 Object[] va = test7(MyValue1.class.asPrimaryType(), len);
165 for (int i = 0; i < len; ++i) {
166 Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
167 }
168 }
169
170 // Class.isInstance
171 @Test()
172 public boolean test8(Class c, MyValue1 vt) {
173 return c.isInstance(vt);
174 }
175
176 @DontCompile
177 public void test8_verifier(boolean warmup) {
178 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
179 boolean result = test8(MyValue1.class.asPrimaryType(), vt);
180 Asserts.assertTrue(result);
181 result = test8(MyValue1.class.asNullableType(), vt);
182 Asserts.assertTrue(result);
183 }
184
185 @Test()
186 public boolean test9(Class c, MyValue1 vt) {
187 return c.isInstance(vt);
188 }
189
190 @DontCompile
191 public void test9_verifier(boolean warmup) {
192 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
193 boolean result = test9(MyValue2.class.asPrimaryType(), vt);
194 Asserts.assertFalse(result);
195 result = test9(MyValue2.class.asNullableType(), vt);
196 Asserts.assertFalse(result);
197 }
198
199 // Class.cast
200 @Test()
201 public Object test10(Class c, MyValue1 vt) {
202 return c.cast(vt);
203 }
204
205 @DontCompile
206 public void test10_verifier(boolean warmup) {
207 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
208 Object result = test10(MyValue1.class.asPrimaryType(), vt);
209 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
210 }
211
212 @Test()
213 public Object test11(Class c, MyValue1 vt) {
214 return c.cast(vt);
215 }
216
217 @DontCompile
218 public void test11_verifier(boolean warmup) {
219 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
220 try {
221 test11(MyValue2.class.asPrimaryType(), vt);
222 throw new RuntimeException("should have thrown");
223 } catch (ClassCastException cce) {
224 }
225 }
226
227 @Test()
228 public Object test12(MyValue1 vt) {
229 return MyValue1.class.asPrimaryType().cast(vt);
230 }
231
232 @DontCompile
233 public void test12_verifier(boolean warmup) {
234 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
235 Object result = test12(vt);
236 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
237 }
238
239 @Test()
240 public Object test13(MyValue1 vt) {
241 return MyValue2.class.asPrimaryType().cast(vt);
242 }
243
244 @DontCompile
245 public void test13_verifier(boolean warmup) {
246 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
247 try {
248 test13(vt);
249 throw new RuntimeException("should have thrown");
250 } catch (ClassCastException cce) {
251 }
252 }
253
254 // value type array creation via reflection
255 @Test()
256 public void test14(int len, long hash) {
257 Object[] va = (Object[])Array.newInstance(MyValue1.class.asPrimaryType().asNullableType().asPrimaryType(), len);
258 for (int i = 0; i < len; ++i) {
259 Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
260 }
261 }
262
263 @DontCompile
264 public void test14_verifier(boolean warmup) {
265 int len = Math.abs(rI) % 42;
266 long hash = MyValue1.createDefaultDontInline().hashPrimitive();
267 test14(len, hash);
268 }
269
270 // Test hashCode() method
271 @Test()
272 public int test15(Object v) {
273 return v.hashCode();
274 }
275
276 @DontCompile
277 public void test15_verifier(boolean warmup) {
337 MyValue1 res = b ? vt1 : vt2;
338 return res.toString();
339 }
340
341 @DontCompile
342 public void test20_verifier(boolean warmup) {
343 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
344 String res = test20(vt, vt, true);
345 Asserts.assertEQ(res, vt.toString());
346 res = test20(vt, vt, false);
347 Asserts.assertEQ(res, vt.toString());
348 }
349
350 private static final Unsafe U = Unsafe.getUnsafe();
351 private static final long X_OFFSET;
352 private static final long Y_OFFSET;
353 private static final long V1_OFFSET;
354 private static final boolean V1_FLATTENED;
355 static {
356 try {
357 Field xField = MyValue1.class.asPrimaryType().getDeclaredField("x");
358 X_OFFSET = U.objectFieldOffset(xField);
359 Field yField = MyValue1.class.asPrimaryType().getDeclaredField("y");
360 Y_OFFSET = U.objectFieldOffset(yField);
361 Field v1Field = MyValue1.class.asPrimaryType().getDeclaredField("v1");
362 V1_OFFSET = U.objectFieldOffset(v1Field);
363 V1_FLATTENED = U.isFlattened(v1Field);
364 } catch (Exception e) {
365 throw new RuntimeException(e);
366 }
367 }
368
369 protected static final String CALL_Unsafe = START + "CallStaticJava" + MID + "# Static jdk.internal.misc.Unsafe::" + END;
370
371 @Test(failOn=CALL_Unsafe)
372 public int test21(MyValue1 v) {
373 return U.getInt(v, X_OFFSET);
374 }
375
376 @DontCompile
377 public void test21_verifier(boolean warmup) {
378 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
379 int res = test21(v);
380 Asserts.assertEQ(res, v.x);
381 }
432 final Test25Value[] test25Array = new Test25Value[10];
433
434 @Test
435 public Test25Value[] test25(Test25Value element) {
436 Test25Value[] newArray = Arrays.copyOf(test25Array, test25Array.length + 1);
437 newArray[test25Array.length] = element;
438 return newArray;
439 }
440
441 @DontCompile
442 public void test25_verifier(boolean warmup) {
443 Test25Value vt = new Test25Value();
444 test25(vt);
445 }
446
447 @Test
448 public Object test26() {
449 Class<?>[] ca = new Class<?>[1];
450 for (int i = 0; i < 1; ++i) {
451 // Folds during loop opts
452 ca[i] = MyValue1.class.asPrimaryType();
453 }
454 return Array.newInstance(ca[0], 1);
455 }
456
457 @DontCompile
458 public void test26_verifier(boolean warmup) {
459 Object[] res = (Object[])test26();
460 Asserts.assertEQ(((MyValue1)res[0]).hashPrimitive(), MyValue1.createDefaultInline().hashPrimitive());
461 }
462
463 // Load non-flattenable value type field with unsafe
464 MyValue1? test27_vt = MyValue1.createWithFieldsInline(rI, rL);
465 private static final long TEST27_OFFSET;
466 static {
467 try {
468 Field field = TestIntrinsics.class.getDeclaredField("test27_vt");
469 TEST27_OFFSET = U.objectFieldOffset(field);
470 } catch (Exception e) {
471 throw new RuntimeException(e);
472 }
517 long res = test29(v);
518 if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
519 if (X_OFFSET < Y_OFFSET) {
520 Asserts.assertEQ(((int)res) << 8, (v.x >> 8) << 8);
521 } else {
522 Asserts.assertEQ(res << 8, (v.y >> 8) << 8);
523 }
524 } else {
525 if (X_OFFSET < Y_OFFSET) {
526 Asserts.assertEQ(((int)res), v.x >>> 8);
527 } else {
528 Asserts.assertEQ(res, v.y >>> 8);
529 }
530 }
531 }
532
533 // getValue to retrieve flattened field from value
534 @Test(failOn=CALL_Unsafe)
535 public MyValue2 test30(MyValue1 v) {
536 if (V1_FLATTENED) {
537 return U.getValue(v, V1_OFFSET, MyValue2.class.asPrimaryType().asNullableType().asPrimaryType());
538 }
539 return (MyValue2)U.getReference(v, V1_OFFSET);
540 }
541
542 @DontCompile
543 public void test30_verifier(boolean warmup) {
544 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
545 MyValue2 res = test30(v);
546 Asserts.assertEQ(res.hash(), v.v1.hash());
547 }
548
549 MyValue1 test31_vt;
550 private static final long TEST31_VT_OFFSET;
551 private static final boolean TEST31_VT_FLATTENED;
552 static {
553 try {
554 Field test31_vt_Field = TestIntrinsics.class.getDeclaredField("test31_vt");
555 TEST31_VT_OFFSET = U.objectFieldOffset(test31_vt_Field);
556 TEST31_VT_FLATTENED = U.isFlattened(test31_vt_Field);
557 } catch (Exception e) {
558 throw new RuntimeException(e);
559 }
560 }
561
562 // getValue to retrieve flattened field from object
563 @Test(failOn=CALL_Unsafe)
564 public MyValue1 test31() {
565 if (TEST31_VT_FLATTENED) {
566 return U.getValue(this, TEST31_VT_OFFSET, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType());
567 }
568 return (MyValue1)U.getReference(this, TEST31_VT_OFFSET);
569 }
570
571 @DontCompile
572 public void test31_verifier(boolean warmup) {
573 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
574 MyValue1 res = test31();
575 Asserts.assertEQ(res.hash(), test31_vt.hash());
576 }
577
578 // putValue to set flattened field in object
579 @Test(failOn=CALL_Unsafe)
580 public void test32(MyValue1 vt) {
581 if (TEST31_VT_FLATTENED) {
582 U.putValue(this, TEST31_VT_OFFSET, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType(), vt);
583 } else {
584 U.putReference(this, TEST31_VT_OFFSET, vt);
585 }
586 }
587
588 @DontCompile
589 public void test32_verifier(boolean warmup) {
590 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
591 test31_vt = MyValue1.createDefaultInline();
592 test32(vt);
593 Asserts.assertEQ(vt.hash(), test31_vt.hash());
594 }
595
596 private static final int TEST33_BASE_OFFSET;
597 private static final int TEST33_INDEX_SCALE;
598 private static final boolean TEST33_FLATTENED_ARRAY;
599 static {
600 try {
601 TEST33_BASE_OFFSET = U.arrayBaseOffset(MyValue1[].class);
602 TEST33_INDEX_SCALE = U.arrayIndexScale(MyValue1[].class);
603 TEST33_FLATTENED_ARRAY = U.isFlattenedArray(MyValue1[].class);
604 } catch (Exception e) {
605 throw new RuntimeException(e);
606 }
607 }
608 // getValue to retrieve flattened field from array
609 @Test(failOn=CALL_Unsafe)
610 public MyValue1 test33(MyValue1[] arr) {
611 if (TEST33_FLATTENED_ARRAY) {
612 return U.getValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType());
613 }
614 return (MyValue1)U.getReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE);
615 }
616
617 @DontCompile
618 public void test33_verifier(boolean warmup) {
619 MyValue1[] arr = new MyValue1[2];
620 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
621 arr[1] = vt;
622 MyValue1 res = test33(arr);
623 Asserts.assertEQ(res.hash(), vt.hash());
624 }
625
626 // putValue to set flattened field in array
627 @Test(failOn=CALL_Unsafe)
628 public void test34(MyValue1[] arr, MyValue1 vt) {
629 if (TEST33_FLATTENED_ARRAY) {
630 U.putValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType(), vt);
631 } else {
632 U.putReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, vt);
633 }
634 }
635
636 @DontCompile
637 public void test34_verifier(boolean warmup) {
638 MyValue1[] arr = new MyValue1[2];
639 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
640 test34(arr, vt);
641 Asserts.assertEQ(arr[1].hash(), vt.hash());
642 }
643
644 // getValue to retrieve flattened field from object with unknown
645 // container type
646 @Test(failOn=CALL_Unsafe)
647 public MyValue1 test35(Object o) {
648 if (TEST31_VT_FLATTENED) {
649 return U.getValue(o, TEST31_VT_OFFSET, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType());
650 }
651 return (MyValue1)U.getReference(o, TEST31_VT_OFFSET);
652 }
653
654 @DontCompile
655 public void test35_verifier(boolean warmup) {
656 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
657 MyValue1 res = test35(this);
658 Asserts.assertEQ(res.hash(), test31_vt.hash());
659 }
660
661 // getValue to retrieve flattened field from object at unknown
662 // offset
663 @Test(failOn=CALL_Unsafe)
664 public MyValue1 test36(long offset) {
665 if (TEST31_VT_FLATTENED) {
666 return U.getValue(this, offset, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType());
667 }
668 return (MyValue1)U.getReference(this, offset);
669 }
670
671 @DontCompile
672 public void test36_verifier(boolean warmup) {
673 test31_vt = MyValue1.createWithFieldsInline(rI, rL);
674 MyValue1 res = test36(TEST31_VT_OFFSET);
675 Asserts.assertEQ(res.hash(), test31_vt.hash());
676 }
677
678 // putValue to set flattened field in object with unknown
679 // container
680 @Test(failOn=CALL_Unsafe)
681 public void test37(Object o, MyValue1 vt) {
682 if (TEST31_VT_FLATTENED) {
683 U.putValue(o, TEST31_VT_OFFSET, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType(), vt);
684 } else {
685 U.putReference(o, TEST31_VT_OFFSET, vt);
686 }
687 }
688
689 @DontCompile
690 public void test37_verifier(boolean warmup) {
691 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
692 test31_vt = MyValue1.createDefaultInline();
693 test37(this, vt);
694 Asserts.assertEQ(vt.hash(), test31_vt.hash());
695 }
696
697 // putValue to set flattened field in object, non value argument
698 // to store
699 @Test(match = { CALL_Unsafe }, matchCount = { 1 })
700 public void test38(Object o) {
701 if (TEST31_VT_FLATTENED) {
702 U.putValue(this, TEST31_VT_OFFSET, MyValue1.class.asPrimaryType().asNullableType().asPrimaryType(), o);
703 } else {
704 U.putReference(this, TEST31_VT_OFFSET, o);
705 }
706 }
707
708 @DontCompile
709 public void test38_verifier(boolean warmup) {
710 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
711 test31_vt = MyValue1.createDefaultInline();
712 test38(vt);
713 Asserts.assertEQ(vt.hash(), test31_vt.hash());
714 }
715
716 @Test(failOn=CALL_Unsafe)
717 public MyValue1 test39(MyValue1 v) {
718 v = U.makePrivateBuffer(v);
719 U.putInt(v, X_OFFSET, rI);
720 v = U.finishPrivateBuffer(v);
721 return v;
722 }
723
724 @DontCompile
725 public void test39_verifier(boolean warmup) {
726 MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
727 MyValue1 res = test39(v.setX(v, 0));
728 Asserts.assertEQ(res.hash(), v.hash());
729 }
730
731 // Test default value type array creation via reflection
732 @Test()
733 public Object[] test40(Class<?> componentType, int len) {
734 Object[] va = (Object[])Array.newInstance(componentType, len);
735 return va;
736 }
737
738 @DontCompile
739 public void test40_verifier(boolean warmup) {
740 int len = Math.abs(rI) % 42;
741 Object[] va = test40(MyValue1.class.asNullableType(), len);
742 for (int i = 0; i < len; ++i) {
743 Asserts.assertEQ(va[i], null);
744 }
745 }
746
747 // Class.isInstance
748 @Test()
749 public boolean test41(Class c, MyValue1? vt) {
750 return c.isInstance(vt);
751 }
752
753 @DontCompile
754 public void test41_verifier(boolean warmup) {
755 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
756 boolean result = test41(MyValue1.class.asNullableType(), vt);
757 Asserts.assertTrue(result);
758 result = test41(MyValue1.class.asPrimaryType(), vt);
759 Asserts.assertTrue(result);
760 }
761
762 @Test()
763 public boolean test42(Class c, MyValue1? vt) {
764 return c.isInstance(vt);
765 }
766
767 @DontCompile
768 public void test42_verifier(boolean warmup) {
769 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
770 boolean result = test42(MyValue2.class.asNullableType(), vt);
771 Asserts.assertFalse(result);
772 result = test42(MyValue2.class.asPrimaryType(), vt);
773 Asserts.assertFalse(result);
774 }
775
776 // Class.cast
777 @Test()
778 public Object test43(Class c, MyValue1? vt) {
779 return c.cast(vt);
780 }
781
782 @DontCompile
783 public void test43_verifier(boolean warmup) {
784 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
785 Object result = test43(MyValue1.class.asNullableType(), vt);
786 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
787 result = test43(MyValue1.class.asNullableType(), null);
788 Asserts.assertEQ(result, null);
789 }
790
791 @Test()
792 public Object test44(Class c, MyValue1? vt) {
793 return c.cast(vt);
794 }
795
796 @DontCompile
797 public void test44_verifier(boolean warmup) {
798 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
799 try {
800 test44(MyValue2.class.asNullableType(), vt);
801 throw new RuntimeException("should have thrown");
802 } catch (ClassCastException cce) {
803 }
804 }
805
806 @Test()
807 public Object test45(MyValue1? vt) {
808 return MyValue1.class.asNullableType().cast(vt);
809 }
810
811 @DontCompile
812 public void test45_verifier(boolean warmup) {
813 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
814 Object result = test45(vt);
815 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
816 result = test45(null);
817 Asserts.assertEQ(result, null);
818 }
819
820 @Test()
821 public Object test46(MyValue1? vt) {
822 return MyValue2.class.asNullableType().cast(vt);
823 }
824
825 @DontCompile
826 public void test46_verifier(boolean warmup) {
827 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
828 test46(null);
829 try {
830 test46(vt);
831 throw new RuntimeException("should have thrown");
832 } catch (ClassCastException cce) {
833 }
834 }
835
836 @Test()
837 public Object test47(MyValue1? vt) {
838 return MyValue1.class.asPrimaryType().cast(vt);
839 }
840
841 @DontCompile
842 public void test47_verifier(boolean warmup) {
843 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
844 Object result = test47(vt);
845 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
846 try {
847 test47(null);
848 throw new RuntimeException("should have thrown");
849 } catch (NullPointerException npe) {
850 }
851 }
852
853 @Test()
854 public Object test48(Class c, MyValue1? vt) {
855 return c.cast(vt);
856 }
857
858 @DontCompile
859 public void test48_verifier(boolean warmup) {
860 MyValue1? vt = MyValue1.createWithFieldsInline(rI, rL);
861 Object result = test48(MyValue1.class.asPrimaryType(), vt);
862 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
863 try {
864 test48(MyValue1.class.asPrimaryType(), null);
865 throw new RuntimeException("should have thrown");
866 } catch (NullPointerException npe) {
867 }
868 }
869
870 @Test()
871 public Object test49(MyValue1 vt) {
872 return MyValue1.class.asNullableType().cast(vt);
873 }
874
875 @DontCompile
876 public void test49_verifier(boolean warmup) {
877 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
878 Object result = test49(vt);
879 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
880 }
881
882 @Test()
883 public Object test50(Class c, Object obj) {
884 return c.cast(obj);
885 }
886
887 @DontCompile
888 public void test50_verifier(boolean warmup) {
889 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
890 MyValue1[] va = new MyValue1[42];
891 MyValue1?[] vba = new MyValue1?[42];
892 Object result = test50(MyValue1.class.asPrimaryType(), vt);
893 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
894 result = test50(MyValue1.class.asNullableType(), vt);
895 Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
896 result = test50(MyValue1[].class, va);
897 Asserts.assertEQ(result, va);
898 result = test50(MyValue1?[].class, vba);
899 Asserts.assertEQ(result, vba);
900 result = test50(MyValue1?[].class, va);
901 Asserts.assertEQ(result, va);
902 try {
903 test50(MyValue1.class.asPrimaryType(), null);
904 throw new RuntimeException("should have thrown");
905 } catch (NullPointerException npe) {
906 }
907 try {
908 test50(MyValue1[].class, vba);
909 throw new RuntimeException("should have thrown");
910 } catch (ClassCastException cce) {
911 }
912 }
913
914 // value type array creation via reflection
915 @Test()
916 public void test51(int len) {
917 Object[] va = (Object[])Array.newInstance(MyValue1.class.asNullableType().asPrimaryType().asNullableType(), len);
918 for (int i = 0; i < len; ++i) {
919 Asserts.assertEQ(va[i], null);
920 }
921 }
922
923 @DontCompile
924 public void test51_verifier(boolean warmup) {
925 int len = Math.abs(rI) % 42;
926 test51(len);
927 }
928
929 // multidimensional value type array creation via reflection
930 @Test()
931 public Object[][] test52(int len, int val) {
932 MyValue1[][] va1 = (MyValue1[][])Array.newInstance(MyValue1[].class, len);
933 MyValue1?[][] va2 = (MyValue1?[][])Array.newInstance(MyValue1?[].class, len);
934 Object[][] result;
935 if (val == 1) {
936 va1[0] = new MyValue1[1];
937 result = va1;
|