1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package compiler.valhalla.valuetypes;
  25 
  26 import java.lang.invoke.*;
  27 
  28 import jdk.experimental.value.MethodHandleBuilder;
  29 import jdk.experimental.bytecode.MacroCodeBuilder;
  30 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
  31 import jdk.experimental.bytecode.TypeTag;
  32 import jdk.test.lib.Asserts;
  33 
  34 /*
  35  * @test
  36  * @summary Test value types in LWorld.
  37  * @modules java.base/jdk.experimental.bytecode
  38  *          java.base/jdk.experimental.value
  39  * @library /testlibrary /test/lib /compiler/whitebox /
  40  * @requires os.simpleArch == "x64"
  41  * @compile -XDenableValueTypes -XDallowFlattenabilityModifiers TestLWorld.java
  42  * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
  43  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  44  *                               -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  45  *                               compiler.valhalla.valuetypes.ValueTypeTest
  46  *                               compiler.valhalla.valuetypes.TestLWorld
  47  */
  48 public class TestLWorld extends ValueTypeTest {
  49     // Extra VM parameters for some test scenarios. See ValueTypeTest.getVMParameters()
  50     @Override
  51     public String[] getExtraVMParameters(int scenario) {
  52         switch (scenario) {
  53         case 1: return new String[] {"-XX:-UseOptoBiasInlining"};
  54         case 2: return new String[] {"-XX:-UseBiasedLocking"};
  55         case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:-UseBiasedLocking", "-XX:+ValueArrayFlatten"};
  56         case 4: return new String[] {"-XX:-MonomorphicArrayCheck"};
  57         }
  58         return null;
  59     }
  60 
  61     public static void main(String[] args) throws Throwable {
  62         TestLWorld test = new TestLWorld();
  63         test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, MyValue3.class, MyValue3Inline.class, Test65Value.class);
  64     }
  65 
  66     // Helper methods
  67 
  68     private static final MyValue1 testValue1 = MyValue1.createWithFieldsInline(rI, rL);
  69     private static final MyValue2 testValue2 = MyValue2.createWithFieldsInline(rI, true);
  70 
  71     protected long hash() {
  72         return testValue1.hash();
  73     }
  74 
  75     // Test passing a value type as an Object
  76     @DontInline
  77     public Object test1_dontinline1(Object o) {
  78         return o;
  79     }
  80 
  81     @DontInline
  82     public MyValue1 test1_dontinline2(Object o) {
  83         return (MyValue1)o;
  84     }
  85 
  86     @ForceInline
  87     public Object test1_inline1(Object o) {
  88         return o;
  89     }
  90 
  91     @ForceInline
  92     public MyValue1 test1_inline2(Object o) {
  93         return (MyValue1)o;
  94     }
  95 
  96     @Test()
  97     public MyValue1 test1() {
  98         MyValue1 vt = testValue1;
  99         vt = (MyValue1)test1_dontinline1(vt);
 100         vt =           test1_dontinline2(vt);
 101         vt = (MyValue1)test1_inline1(vt);
 102         vt =           test1_inline2(vt);
 103         return vt;
 104     }
 105 
 106     @DontCompile
 107     public void test1_verifier(boolean warmup) {
 108         Asserts.assertEQ(test1().hash(), hash());
 109     }
 110 
 111     // Test storing/loading value types to/from Object and value type fields
 112     Object objectField1 = null;
 113     Object objectField2 = null;
 114     Object objectField3 = null;
 115     Object objectField4 = null;
 116     Object objectField5 = null;
 117     Object objectField6 = null;
 118 
 119     __Flattenable  MyValue1 valueField1 = testValue1;
 120     __Flattenable  MyValue1 valueField2 = testValue1;
 121     __NotFlattened MyValue1 valueField3 = testValue1;
 122     __Flattenable  MyValue1 valueField4;
 123     __NotFlattened MyValue1 valueField5;
 124 
 125     static __NotFlattened MyValue1 staticValueField1 = testValue1;
 126     static __Flattenable  MyValue1 staticValueField2 = testValue1;
 127     static __Flattenable  MyValue1 staticValueField3;
 128     static __NotFlattened MyValue1 staticValueField4;
 129 
 130     @DontInline
 131     public Object readValueField5() {
 132         return (Object)valueField5;
 133     }
 134 
 135     @DontInline
 136     public Object readStaticValueField4() {
 137         return (Object)staticValueField4;
 138     }
 139 
 140     @Test()
 141     public long test2(MyValue1 vt1, Object vt2) {
 142         objectField1 = vt1;
 143         objectField2 = (MyValue1)vt2;
 144         objectField3 = testValue1;
 145         objectField4 = MyValue1.createWithFieldsDontInline(rI, rL);
 146         objectField5 = valueField1;
 147         objectField6 = valueField3;
 148         valueField1 = (MyValue1)objectField1;
 149         valueField2 = (MyValue1)vt2;
 150         valueField3 = (MyValue1)vt2;
 151         staticValueField1 = (MyValue1)objectField1;
 152         staticValueField2 = (MyValue1)vt1;
 153         // Don't inline these methods because reading NULL will trigger a deoptimization
 154         if (readValueField5() != null || readStaticValueField4() != null) {
 155             throw new RuntimeException("Should be null");
 156         }
 157         return ((MyValue1)objectField1).hash() + ((MyValue1)objectField2).hash() +
 158                ((MyValue1)objectField3).hash() + ((MyValue1)objectField4).hash() +
 159                ((MyValue1)objectField5).hash() + ((MyValue1)objectField6).hash() +
 160                 valueField1.hash() + valueField2.hash() + valueField3.hash() + valueField4.hashPrimitive() +
 161                 staticValueField1.hash() + staticValueField2.hash() + staticValueField3.hashPrimitive();
 162     }
 163 
 164     @DontCompile
 165     public void test2_verifier(boolean warmup) {
 166         MyValue1 vt = testValue1;
 167         MyValue1 def = MyValue1.createDefaultDontInline();
 168         long result = test2(vt, vt);
 169         Asserts.assertEQ(result, 11*vt.hash() + 2*def.hashPrimitive());
 170     }
 171 
 172     // Test merging value types and objects
 173     @Test()
 174     public Object test3(int state) {
 175         Object res = null;
 176         if (state == 0) {
 177             res = new Integer(rI);
 178         } else if (state == 1) {
 179             res = MyValue1.createWithFieldsInline(rI, rL);
 180         } else if (state == 2) {
 181             res = MyValue1.createWithFieldsDontInline(rI, rL);
 182         } else if (state == 3) {
 183             res = (MyValue1)objectField1;
 184         } else if (state == 4) {
 185             res = valueField1;
 186         } else if (state == 5) {
 187             res = null;
 188         } else if (state == 6) {
 189             res = MyValue2.createWithFieldsInline(rI, true);
 190         } else if (state == 7) {
 191             res = testValue2;
 192         }
 193         return res;
 194     }
 195 
 196     @DontCompile
 197     public void test3_verifier(boolean warmup) {
 198         objectField1 = valueField1;
 199         Object result = null;
 200         result = test3(0);
 201         Asserts.assertEQ((Integer)result, rI);
 202         result = test3(1);
 203         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 204         result = test3(2);
 205         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 206         result = test3(3);
 207         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 208         result = test3(4);
 209         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 210         result = test3(5);
 211         Asserts.assertEQ(result, null);
 212         result = test3(6);
 213         Asserts.assertEQ(((MyValue2)result).hash(), testValue2.hash());
 214         result = test3(7);
 215         Asserts.assertEQ(((MyValue2)result).hash(), testValue2.hash());
 216     }
 217 
 218     // Test merging value types and objects in loops
 219     @Test()
 220     public Object test4(int iters) {
 221         Object res = new Integer(rI);
 222         for (int i = 0; i < iters; ++i) {
 223             if (res instanceof Integer) {
 224                 res = MyValue1.createWithFieldsInline(rI, rL);
 225             } else {
 226                 res = MyValue1.createWithFieldsInline(((MyValue1)res).x + 1, rL);
 227             }
 228         }
 229         return res;
 230     }
 231 
 232     @DontCompile
 233     public void test4_verifier(boolean warmup) {
 234         Integer result1 = (Integer)test4(0);
 235         Asserts.assertEQ(result1, rI);
 236         int iters = (Math.abs(rI) % 10) + 1;
 237         MyValue1 result2 = (MyValue1)test4(iters);
 238         MyValue1 vt = MyValue1.createWithFieldsInline(rI + iters - 1, rL);
 239         Asserts.assertEQ(result2.hash(), vt.hash());
 240     }
 241 
 242     // Test value types in object variables that are live at safepoint
 243     @Test(failOn = ALLOC + STORE + LOOP)
 244     public long test5(MyValue1 arg, boolean deopt) {
 245         Object vt1 = MyValue1.createWithFieldsInline(rI, rL);
 246         Object vt2 = MyValue1.createWithFieldsDontInline(rI, rL);
 247         Object vt3 = arg;
 248         Object vt4 = valueField1;
 249         if (deopt) {
 250             // uncommon trap
 251             WHITE_BOX.deoptimizeMethod(tests.get(getClass().getSimpleName() + "::test5"));
 252         }
 253         return ((MyValue1)vt1).hash() + ((MyValue1)vt2).hash() +
 254                ((MyValue1)vt3).hash() + ((MyValue1)vt4).hash();
 255     }
 256 
 257     @DontCompile
 258     public void test5_verifier(boolean warmup) {
 259         long result = test5(valueField1, !warmup);
 260         Asserts.assertEQ(result, 4*hash());
 261     }
 262 
 263     // Test comparing value types with objects
 264     @Test(failOn = ALLOC + LOAD + STORE + LOOP)
 265     public boolean test6(Object arg) {
 266         Object vt = MyValue1.createWithFieldsInline(rI, rL);
 267         if (vt == arg || vt == (Object)valueField1 || vt == objectField1 || vt == null ||
 268             arg == vt || (Object)valueField1 == vt || objectField1 == vt || null == vt) {
 269             return true;
 270         }
 271         return false;
 272     }
 273 
 274     @DontCompile
 275     public void test6_verifier(boolean warmup) {
 276         boolean result = test6(null);
 277         Asserts.assertFalse(result);
 278     }
 279 
 280     // Test correct handling of null-ness of value types
 281 
 282     __NotFlattened MyValue1 nullField;
 283 
 284     @Test
 285     @Warmup(10000) // Warmup to make sure 'callTest7WithNull' is compiled
 286     public long test7(MyValue1 vt) {
 287         long result = 0;
 288         try {
 289             result = vt.hash();
 290             throw new RuntimeException("NullPointerException expected");
 291         } catch (NullPointerException e) {
 292             // Expected
 293         }
 294         return result;
 295     }
 296 
 297     private static final MethodHandle callTest7WithNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 298         "callTest7WithNull",
 299         MethodType.methodType(void.class, TestLWorld.class),
 300         CODE -> {
 301             CODE.
 302             aload_0().
 303             aconst_null().
 304             invokevirtual(TestLWorld.class, "test7", "(Lcompiler/valhalla/valuetypes/MyValue1;)J", false).
 305             return_();
 306         },
 307         MyValue1.class);
 308 
 309     @DontCompile
 310     public void test7_verifier(boolean warmup) throws Throwable {
 311         long result = (long)callTest7WithNull.invoke(this);
 312         Asserts.assertEquals(result, 0L);
 313     }
 314 
 315     @Test
 316     public long test8(MyValue1 vt) {
 317         long result = 0;
 318         try {
 319             result = vt.hashInterpreted();
 320             throw new RuntimeException("NullPointerException expected");
 321         } catch (NullPointerException e) {
 322             // Expected
 323         }
 324         return result;
 325     }
 326 
 327     @DontCompile
 328     public void test8_verifier(boolean warmup) {
 329         long result = test8(nullField);
 330         Asserts.assertEquals(result, 0L);
 331     }
 332 
 333     @Test
 334     public long test9() {
 335         long result = 0;
 336         try {
 337             if ((Object)nullField != null) {
 338                 throw new RuntimeException("nullField should be null");
 339             }
 340             result = nullField.hash();
 341             throw new RuntimeException("NullPointerException expected");
 342         } catch (NullPointerException e) {
 343             // Expected
 344         }
 345         return result;
 346     }
 347 
 348     @DontCompile
 349     public void test9_verifier(boolean warmup) {
 350         long result = test9();
 351         Asserts.assertEquals(result, 0L);
 352     }
 353 
 354     @Test
 355     public void test10() {
 356         try {
 357             valueField1 = nullField;
 358             throw new RuntimeException("NullPointerException expected");
 359         } catch (NullPointerException e) {
 360             // Expected
 361         }
 362     }
 363 
 364     @DontCompile
 365     public void test10_verifier(boolean warmup) {
 366         test10();
 367     }
 368 
 369     @Test
 370     public MyValue1 test11(MyValue1 vt) {
 371         try {
 372             Object o = vt;
 373             vt = (MyValue1)o;
 374             throw new RuntimeException("NullPointerException expected");
 375         } catch (NullPointerException e) {
 376             // Expected
 377         }
 378 
 379         // Should not throw
 380         vt = test11_dontinline(vt);
 381         vt = test11_inline(vt);
 382         return vt;
 383     }
 384 
 385     @DontCompile
 386     public void test11_verifier(boolean warmup) {
 387         MyValue1 vt = test11(nullField);
 388         Asserts.assertEquals((Object)vt, null);
 389     }
 390 
 391     @DontInline
 392     public MyValue1 test11_dontinline(MyValue1 vt) {
 393         return vt;
 394     }
 395 
 396     @ForceInline
 397     public MyValue1 test11_inline(MyValue1 vt) {
 398         return vt;
 399     }
 400 
 401     @Test
 402     public MyValue1 test12(Object obj) {
 403         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 404         try {
 405             vt = (MyValue1)obj;
 406             throw new RuntimeException("NullPointerException expected");
 407         } catch (NullPointerException e) {
 408             // Expected
 409         }
 410         return vt;
 411     }
 412 
 413     @DontCompile
 414     public void test12_verifier(boolean warmup) {
 415         MyValue1 vt = test12(null);
 416         Asserts.assertEquals(vt.hash(), hash());
 417     }
 418 
 419     private static final MethodHandle getNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 420         "getNull",
 421         MethodType.methodType(MyValue1.class),
 422         CODE -> {
 423             CODE.
 424             aconst_null().
 425             areturn();
 426         },
 427         MyValue1.class);
 428 
 429     @Test
 430     public void test13() throws Throwable {
 431         try {
 432             valueField1 = (MyValue1)getNull.invoke();
 433             throw new RuntimeException("NullPointerException expected");
 434         } catch (NullPointerException e) {
 435             // Expected
 436         }
 437         nullField = (MyValue1)getNull.invoke(); // Should not throw
 438     }
 439 
 440     @DontCompile
 441     public void test13_verifier(boolean warmup) throws Throwable {
 442         test13();
 443     }
 444 
 445     // null constant
 446     private static final MethodHandle setNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 447         "setNull",
 448         MethodType.methodType(void.class, TestLWorld.class),
 449         CODE -> {
 450             CODE.
 451             aload_0().
 452             aconst_null().
 453             putfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
 454             return_();
 455         },
 456         MyValue1.class);
 457 
 458     @Test
 459     public void test14() throws Throwable {
 460         try {
 461             setNull.invoke(this);
 462             throw new RuntimeException("NullPointerException expected");
 463         } catch (NullPointerException e) {
 464             // Expected
 465         }
 466     }
 467 
 468     @DontCompile
 469     public void test14_verifier(boolean warmup) throws Throwable {
 470         test14();
 471     }
 472 
 473     // merge of 2 values, one being null
 474     @Test
 475     public void test15(boolean flag1) {
 476         MyValue1 v;
 477         if (flag1) {
 478             v = valueField1;
 479         } else {
 480             v = valueField5;
 481         }
 482         valueField1 = v;
 483     }
 484 
 485     @DontCompile
 486     public void test15_verifier(boolean warmup) {
 487         test15(true);
 488         try {
 489             test15(false);
 490             throw new RuntimeException("NullPointerException expected");
 491         } catch (NullPointerException e) {
 492             // Expected
 493         }
 494     }
 495 
 496     // null constant
 497     private static final MethodHandle mergeNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 498         "mergeNull",
 499         MethodType.methodType(void.class, TestLWorld.class, boolean.class),
 500         CODE -> {
 501             CODE.
 502             iload_1().
 503             iconst_0().
 504             ifcmp(TypeTag.I, CondKind.EQ, "null").
 505             aload_0().
 506             getfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
 507             goto_("continue").
 508             label("null").
 509             aconst_null().
 510             label("continue").
 511             aload_0().
 512             swap().
 513             putfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
 514             return_();
 515         },
 516         MyValue1.class);
 517 
 518     @Test
 519     public void test16(boolean flag) throws Throwable {
 520         mergeNull.invoke(this, flag);
 521     }
 522 
 523     @DontCompile
 524     public void test16_verifier(boolean warmup) throws Throwable {
 525         test16(true);
 526         try {
 527             test16(false);
 528             throw new RuntimeException("NullPointerException expected");
 529         } catch (NullPointerException e) {
 530             // Expected
 531         }
 532     }
 533 
 534     // merge of value and non value
 535     @Test
 536     public Object test17(boolean flag) {
 537         Object res = null;
 538         if (flag) {
 539             res = valueField1;
 540         } else {
 541             res = objectField1;
 542         }
 543         return res;
 544     }
 545 
 546     @DontCompile
 547     public void test17_verifier(boolean warmup) {
 548         test17(true);
 549         test17(false);
 550     }
 551 
 552     @Test
 553     public Object test18(boolean flag) {
 554         Object res = null;
 555         if (flag) {
 556             res = objectField1;
 557         } else {
 558             res = valueField1;
 559         }
 560         return res;
 561     }
 562 
 563     @DontCompile
 564     public void test18_verifier(boolean warmup) {
 565         test18(true);
 566         test18(false);
 567     }
 568 
 569     // null constant
 570     private static final MethodHandle mergeNull2 = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 571         "mergeNull2",
 572         MethodType.methodType(void.class, TestLWorld.class, boolean.class),
 573         CODE -> {
 574             CODE.
 575             iload_1().
 576             iconst_0().
 577             ifcmp(TypeTag.I, CondKind.EQ, "not_null").
 578             aconst_null().
 579             goto_("continue").
 580             label("not_null").
 581             aload_0().
 582             getfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
 583             label("continue").
 584             aload_0().
 585             swap().
 586             putfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
 587             return_();
 588         },
 589         MyValue1.class);
 590 
 591     @Test
 592     public void test19(boolean flag) throws Throwable {
 593         mergeNull2.invoke(this, flag);
 594     }
 595 
 596     @DontCompile
 597     public void test19_verifier(boolean warmup) throws Throwable {
 598         test19(false);
 599         try {
 600             test19(true);
 601             throw new RuntimeException("NullPointerException expected");
 602         } catch (NullPointerException e) {
 603             // Expected
 604         }
 605     }
 606 
 607     // merge of values in a loop, stored in an object local
 608     @Test
 609     public Object test20() {
 610         Object o = valueField1;
 611         for (int i = 1; i < 100; i *= 2) {
 612             MyValue1 v = (MyValue1)o;
 613             o = MyValue1.setX(v, v.x + 1);
 614         }
 615         return o;
 616     }
 617 
 618     @DontCompile
 619     public void test20_verifier(boolean warmup) {
 620         test20();
 621     }
 622 
 623     // merge of values in an object local
 624     public Object test21_helper() {
 625         return valueField1;
 626     }
 627 
 628     @Test(failOn = ALLOC + LOAD + STORE)
 629     public void test21(boolean flag) {
 630         Object o = null;
 631         if (flag) {
 632             o = valueField1;
 633         } else {
 634             o = test21_helper();
 635         }
 636         valueField1 = (MyValue1)o;
 637     }
 638 
 639     @DontCompile
 640     public void test21_verifier(boolean warmup) {
 641         test21(true);
 642         test21(false);
 643     }
 644 
 645     // null return
 646     int test_22_cnt;
 647 
 648     @DontInline
 649     public MyValue1 test22_helper() {
 650         test_22_cnt++;
 651         return valueField5;
 652     }
 653 
 654     @Test
 655     public void test22() {
 656         valueField1 = test22_helper();
 657     }
 658 
 659     @DontCompile
 660     public void test22_verifier(boolean warmup) {
 661         try {
 662             test_22_cnt = 0;
 663             test22();
 664             throw new RuntimeException("NullPointerException expected");
 665         } catch (NullPointerException e) {
 666             // Expected
 667         }
 668         if (test_22_cnt != 1) {
 669             throw new RuntimeException("call executed twice");
 670         }
 671     }
 672 
 673     // null return at virtual call
 674     class A {
 675         public MyValue1 test23_helper() {
 676             return valueField5;
 677         }
 678     }
 679 
 680     class B extends A {
 681         public MyValue1 test23_helper() {
 682             return valueField5;
 683         }
 684     }
 685 
 686     class C extends A {
 687         public MyValue1 test23_helper() {
 688             return valueField5;
 689         }
 690     }
 691 
 692     class D extends A {
 693         public MyValue1 test23_helper() {
 694             return valueField5;
 695         }
 696     }
 697 
 698     @Test
 699     public void test23(A a) {
 700         valueField1 = a.test23_helper();
 701     }
 702 
 703     @DontCompile
 704     public void test23_verifier(boolean warmup) {
 705         A b = new B();
 706         A c = new C();
 707         A d = new D();
 708         try {
 709             test23(b);
 710             throw new RuntimeException("NullPointerException expected");
 711         } catch (NullPointerException e) {
 712             // Expected
 713         }
 714         try {
 715             test23(c);
 716             throw new RuntimeException("NullPointerException expected");
 717         } catch (NullPointerException e) {
 718             // Expected
 719         }
 720         try {
 721             test23(d);
 722             throw new RuntimeException("NullPointerException expected");
 723         } catch (NullPointerException e) {
 724             // Expected
 725         }
 726     }
 727 
 728 
 729     // Interface tests
 730 
 731     @DontInline
 732     public MyInterface test24_dontinline1(MyInterface o) {
 733         return o;
 734     }
 735 
 736     @DontInline
 737     public MyValue1 test24_dontinline2(MyInterface o) {
 738         return (MyValue1)o;
 739     }
 740 
 741     @ForceInline
 742     public MyInterface test24_inline1(MyInterface o) {
 743         return o;
 744     }
 745 
 746     @ForceInline
 747     public MyValue1 test24_inline2(MyInterface o) {
 748         return (MyValue1)o;
 749     }
 750 
 751     @Test()
 752     public MyValue1 test24() {
 753         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 754         vt = (MyValue1)test24_dontinline1(vt);
 755         vt =           test24_dontinline2(vt);
 756         vt = (MyValue1)test24_inline1(vt);
 757         vt =           test24_inline2(vt);
 758         return vt;
 759     }
 760 
 761     @DontCompile
 762     public void test24_verifier(boolean warmup) {
 763         Asserts.assertEQ(test24().hash(), hash());
 764     }
 765 
 766     // Test storing/loading value types to/from interface and value type fields
 767     MyInterface interfaceField1 = null;
 768     MyInterface interfaceField2 = null;
 769     MyInterface interfaceField3 = null;
 770     MyInterface interfaceField4 = null;
 771     MyInterface interfaceField5 = null;
 772     MyInterface interfaceField6 = null;
 773 
 774     @DontInline
 775     public MyInterface readValueField5AsInterface() {
 776         return (MyInterface)valueField5;
 777     }
 778 
 779     @DontInline
 780     public MyInterface readStaticValueField4AsInterface() {
 781         return (MyInterface)staticValueField4;
 782     }
 783 
 784     @Test()
 785     public long test25(MyValue1 vt1, MyInterface vt2) {
 786         interfaceField1 = vt1;
 787         interfaceField2 = (MyValue1)vt2;
 788         interfaceField3 = MyValue1.createWithFieldsInline(rI, rL);
 789         interfaceField4 = MyValue1.createWithFieldsDontInline(rI, rL);
 790         interfaceField5 = valueField1;
 791         interfaceField6 = valueField3;
 792         valueField1 = (MyValue1)interfaceField1;
 793         valueField2 = (MyValue1)vt2;
 794         valueField3 = (MyValue1)vt2;
 795         staticValueField1 = (MyValue1)interfaceField1;
 796         staticValueField2 = (MyValue1)vt1;
 797         // Don't inline these methods because reading NULL will trigger a deoptimization
 798         if (readValueField5AsInterface() != null || readStaticValueField4AsInterface() != null) {
 799             throw new RuntimeException("Should be null");
 800         }
 801         return ((MyValue1)interfaceField1).hash() + ((MyValue1)interfaceField2).hash() +
 802                ((MyValue1)interfaceField3).hash() + ((MyValue1)interfaceField4).hash() +
 803                ((MyValue1)interfaceField5).hash() + ((MyValue1)interfaceField6).hash() +
 804                 valueField1.hash() + valueField2.hash() + valueField3.hash() + valueField4.hashPrimitive() +
 805                 staticValueField1.hash() + staticValueField2.hash() + staticValueField3.hashPrimitive();
 806     }
 807 
 808     @DontCompile
 809     public void test25_verifier(boolean warmup) {
 810         MyValue1 vt = testValue1;
 811         MyValue1 def = MyValue1.createDefaultDontInline();
 812         long result = test25(vt, vt);
 813         Asserts.assertEQ(result, 11*vt.hash() + 2*def.hashPrimitive());
 814     }
 815 
 816     class MyObject implements MyInterface {
 817         public int x;
 818 
 819         public MyObject(int x) {
 820             this.x = x;
 821         }
 822 
 823         @ForceInline
 824         public long hash() {
 825             return x;
 826         }
 827     }
 828 
 829     // Test merging value types and interfaces
 830     @Test()
 831     public MyInterface test26(int state) {
 832         MyInterface res = null;
 833         if (state == 0) {
 834             res = new MyObject(rI);
 835         } else if (state == 1) {
 836             res = MyValue1.createWithFieldsInline(rI, rL);
 837         } else if (state == 2) {
 838             res = MyValue1.createWithFieldsDontInline(rI, rL);
 839         } else if (state == 3) {
 840             res = (MyValue1)objectField1;
 841         } else if (state == 4) {
 842             res = valueField1;
 843         } else if (state == 5) {
 844             res = null;
 845         }
 846         return res;
 847     }
 848 
 849     @DontCompile
 850     public void test26_verifier(boolean warmup) {
 851         objectField1 = valueField1;
 852         MyInterface result = null;
 853         result = test26(0);
 854         Asserts.assertEQ(((MyObject)result).x, rI);
 855         result = test26(1);
 856         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 857         result = test26(2);
 858         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 859         result = test26(3);
 860         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 861         result = test26(4);
 862         Asserts.assertEQ(((MyValue1)result).hash(), hash());
 863         result = test26(5);
 864         Asserts.assertEQ(result, null);
 865     }
 866 
 867     // Test merging value types and interfaces in loops
 868     @Test()
 869     public MyInterface test27(int iters) {
 870         MyInterface res = new MyObject(rI);
 871         for (int i = 0; i < iters; ++i) {
 872             if (res instanceof MyObject) {
 873                 res = MyValue1.createWithFieldsInline(rI, rL);
 874             } else {
 875                 res = MyValue1.createWithFieldsInline(((MyValue1)res).x + 1, rL);
 876             }
 877         }
 878         return res;
 879     }
 880 
 881     @DontCompile
 882     public void test27_verifier(boolean warmup) {
 883         MyObject result1 = (MyObject)test27(0);
 884         Asserts.assertEQ(result1.x, rI);
 885         int iters = (Math.abs(rI) % 10) + 1;
 886         MyValue1 result2 = (MyValue1)test27(iters);
 887         MyValue1 vt = MyValue1.createWithFieldsInline(rI + iters - 1, rL);
 888         Asserts.assertEQ(result2.hash(), vt.hash());
 889     }
 890 
 891     // Test value types in interface variables that are live at safepoint
 892     @Test(failOn = ALLOC + STORE + LOOP)
 893     public long test28(MyValue1 arg, boolean deopt) {
 894         MyInterface vt1 = MyValue1.createWithFieldsInline(rI, rL);
 895         MyInterface vt2 = MyValue1.createWithFieldsDontInline(rI, rL);
 896         MyInterface vt3 = arg;
 897         MyInterface vt4 = valueField1;
 898         if (deopt) {
 899             // uncommon trap
 900             WHITE_BOX.deoptimizeMethod(tests.get(getClass().getSimpleName() + "::test5"));
 901         }
 902         return ((MyValue1)vt1).hash() + ((MyValue1)vt2).hash() +
 903                ((MyValue1)vt3).hash() + ((MyValue1)vt4).hash();
 904     }
 905 
 906     @DontCompile
 907     public void test28_verifier(boolean warmup) {
 908         long result = test28(valueField1, !warmup);
 909         Asserts.assertEQ(result, 4*hash());
 910     }
 911 
 912     // Test comparing value types with interfaces
 913     @Test(failOn = ALLOC + LOAD + STORE + LOOP)
 914     public boolean test29(Object arg) {
 915         MyInterface vt = MyValue1.createWithFieldsInline(rI, rL);
 916         if (vt == arg || vt == (MyInterface)valueField1 || vt == interfaceField1 || vt == null ||
 917             arg == vt || (MyInterface)valueField1 == vt || interfaceField1 == vt || null == vt) {
 918             return true;
 919         }
 920         return false;
 921     }
 922 
 923     @DontCompile
 924     public void test29_verifier(boolean warmup) {
 925         boolean result = test29(null);
 926         Asserts.assertFalse(result);
 927     }
 928 
 929     // Test subtype check when casting to value type
 930     @Test
 931     public MyValue1 test30(MyValue1 vt, Object obj) {
 932         try {
 933             vt = (MyValue1)obj;
 934             throw new RuntimeException("ClassCastException expected");
 935         } catch (ClassCastException e) {
 936             // Expected
 937         }
 938         return vt;
 939     }
 940 
 941     @DontCompile
 942     public void test30_verifier(boolean warmup) {
 943         MyValue1 vt = testValue1;
 944         MyValue1 result = test30(vt, new Integer(rI));
 945         Asserts.assertEquals(result.hash(), vt.hash());
 946     }
 947 
 948     @Test
 949     public MyValue1 test31(MyValue1 vt) {
 950         Object obj = vt;
 951         vt = (MyValue1)obj;
 952         return vt;
 953     }
 954 
 955     @DontCompile
 956     public void test31_verifier(boolean warmup) {
 957         MyValue1 vt = testValue1;
 958         MyValue1 result = test31(vt);
 959         Asserts.assertEquals(result.hash(), vt.hash());
 960     }
 961 
 962     @Test
 963     public void test32(MyValue1 vt) {
 964         Object obj = vt;
 965         try {
 966             MyValue2 vt2 = (MyValue2)obj;
 967             throw new RuntimeException("ClassCastException expected");
 968         } catch (ClassCastException e) {
 969             // Expected
 970         }
 971     }
 972 
 973     @DontCompile
 974     public void test32_verifier(boolean warmup) {
 975         test32(valueField1);
 976     }
 977 
 978     @Test
 979     public void test33(MyValue1 vt) {
 980         Object obj = vt;
 981         try {
 982             Integer i = (Integer)obj;
 983             throw new RuntimeException("ClassCastException expected");
 984         } catch (ClassCastException e) {
 985             // Expected
 986         }
 987     }
 988 
 989     @DontCompile
 990     public void test33_verifier(boolean warmup) {
 991         test33(valueField1);
 992     }
 993 
 994 
 995     // Array tests
 996 
 997     private static final MyValue1[] testValue1Array = new MyValue1[] {testValue1,
 998                                                                       testValue1,
 999                                                                       testValue1};
1000 
1001     private static final MyValue1[][] testValue1Array2 = new MyValue1[][] {testValue1Array,
1002                                                                            testValue1Array,
1003                                                                            testValue1Array};
1004 
1005     private static final MyValue2[] testValue2Array = new MyValue2[] {testValue2,
1006                                                                       testValue2,
1007                                                                       testValue2};
1008 
1009     private static final Integer[] testIntegerArray = new Integer[42];
1010 
1011     // Test load from (flattened) value type array disguised as object array
1012     @Test()
1013     public Object test34(Object[] oa, int index) {
1014         return oa[index];
1015     }
1016 
1017     @DontCompile
1018     public void test34_verifier(boolean warmup) {
1019         MyValue1 result = (MyValue1)test34(testValue1Array, Math.abs(rI) % 3);
1020         Asserts.assertEQ(result.hash(), hash());
1021     }
1022 
1023     // Test load from (flattened) value type array disguised as interface array
1024     @Test()
1025     public Object test35(MyInterface[] ia, int index) {
1026         return ia[index];
1027     }
1028 
1029     @DontCompile
1030     public void test35_verifier(boolean warmup) {
1031         MyValue1 result = (MyValue1)test35(testValue1Array, Math.abs(rI) % 3);
1032         Asserts.assertEQ(result.hash(), hash());
1033     }
1034 
1035     // Test value store to (flattened) value type array disguised as object array
1036 
1037     @ForceInline
1038     public void test36_inline(Object[] oa, Object o, int index) {
1039         oa[index] = o;
1040     }
1041 
1042     @Test()
1043     public void test36(Object[] oa, MyValue1 vt, int index) {
1044         test36_inline(oa, vt, index);
1045     }
1046 
1047     @DontCompile
1048     public void test36_verifier(boolean warmup) {
1049         int index = Math.abs(rI) % 3;
1050         MyValue1 vt = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1051         test36(testValue1Array, vt, index);
1052         Asserts.assertEQ(testValue1Array[index].hash(), vt.hash());
1053         testValue1Array[index] = testValue1;
1054         try {
1055             test36(testValue2Array, vt, index);
1056             throw new RuntimeException("No ArrayStoreException thrown");
1057         } catch (ArrayStoreException e) {
1058             // Expected
1059         }
1060         Asserts.assertEQ(testValue2Array[index].hash(), testValue2.hash());
1061     }
1062 
1063     @ForceInline
1064     public void test37_inline(Object[] oa, Object o, int index) {
1065         oa[index] = o;
1066     }
1067 
1068     @Test()
1069     public void test37(Object[] oa, MyValue1 vt, int index) {
1070         test37_inline(oa, vt, index);
1071     }
1072 
1073     @DontCompile
1074     public void test37_verifier(boolean warmup) {
1075         int index = Math.abs(rI) % 3;
1076         try {
1077             test37(testIntegerArray, testValue1, index);
1078             throw new RuntimeException("No ArrayStoreException thrown");
1079         } catch (ArrayStoreException e) {
1080             // Expected
1081         }
1082     }
1083 
1084     @ForceInline
1085     public void test38_inline(Object[] oa, Object o, int index) {
1086         oa[index] = o;
1087     }
1088 
1089     @Test()
1090     public void test38(Object[] oa, MyValue1 vt, int index) {
1091         test38_inline(oa, vt, index);
1092     }
1093 
1094     @DontCompile
1095     public void test38_verifier(boolean warmup) {
1096         int index = Math.abs(rI) % 3;
1097         try {
1098             test38(null, testValue1, index);
1099             throw new RuntimeException("No NPE thrown");
1100         } catch (NullPointerException e) {
1101             // Expected
1102         }
1103     }
1104 
1105     // Test value store to (flattened) value type array disguised as interface array
1106 
1107     @ForceInline
1108     public void test39_inline(MyInterface[] ia, MyInterface i, int index) {
1109         ia[index] = i;
1110     }
1111 
1112     @Test()
1113     public void test39(MyInterface[] ia, MyValue1 vt, int index) {
1114       test39_inline(ia, vt, index);
1115     }
1116 
1117     @DontCompile
1118     public void test39_verifier(boolean warmup) {
1119         int index = Math.abs(rI) % 3;
1120         MyValue1 vt = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1121         test39(testValue1Array, vt, index);
1122         Asserts.assertEQ(testValue1Array[index].hash(), vt.hash());
1123         testValue1Array[index] = testValue1;
1124         try {
1125             test39(testValue2Array, vt, index);
1126             throw new RuntimeException("No ArrayStoreException thrown");
1127         } catch (ArrayStoreException e) {
1128             // Expected
1129         }
1130         Asserts.assertEQ(testValue2Array[index].hash(), testValue2.hash());
1131     }
1132 
1133     @ForceInline
1134     public void test40_inline(MyInterface[] ia, MyInterface i, int index) {
1135         ia[index] = i;
1136     }
1137 
1138     @Test()
1139     public void test40(MyInterface[] ia, MyValue1 vt, int index) {
1140         test40_inline(ia, vt, index);
1141     }
1142 
1143     @DontCompile
1144     public void test40_verifier(boolean warmup) {
1145         int index = Math.abs(rI) % 3;
1146         try {
1147             test40(null, testValue1, index);
1148             throw new RuntimeException("No NPE thrown");
1149         } catch (NullPointerException e) {
1150             // Expected
1151         }
1152     }
1153 
1154     // Test object store to (flattened) value type array disguised as object array
1155 
1156     @ForceInline
1157     public void test41_inline(Object[] oa, Object o, int index) {
1158         oa[index] = o;
1159     }
1160 
1161     @Test()
1162     public void test41(Object[] oa, Object o, int index) {
1163         test41_inline(oa, o, index);
1164     }
1165 
1166     @DontCompile
1167     public void test41_verifier(boolean warmup) {
1168         int index = Math.abs(rI) % 3;
1169         MyValue1 vt1 = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1170         test41(testValue1Array, vt1, index);
1171         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1172         try {
1173             test41(testValue1Array, testValue2, index);
1174             throw new RuntimeException("No ArrayStoreException thrown");
1175         } catch (ArrayStoreException e) {
1176             // Expected
1177         }
1178         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1179         testValue1Array[index] = testValue1;
1180     }
1181 
1182     @ForceInline
1183     public void test42_inline(Object[] oa, Object o, int index) {
1184         oa[index] = o;
1185     }
1186 
1187     @Test()
1188     public void test42(Object[] oa, Object o, int index) {
1189         test42_inline(oa, o, index);
1190     }
1191 
1192     @DontCompile
1193     public void test42_verifier(boolean warmup) {
1194         int index = Math.abs(rI) % 3;
1195         try {
1196             test42(testValue2Array, testValue1, index);
1197             throw new RuntimeException("No ArrayStoreException thrown");
1198         } catch (ArrayStoreException e) {
1199             // Expected
1200         }
1201         Asserts.assertEQ(testValue2Array[index].hash(), testValue2.hash());
1202     }
1203 
1204     @ForceInline
1205     public void test43_inline(Object[] oa, Object o, int index) {
1206         oa[index] = o;
1207     }
1208 
1209     @Test()
1210     public void test43(Object[] oa, Object o, int index) {
1211         test43_inline(oa, o, index);
1212     }
1213 
1214     @DontCompile
1215     public void test43_verifier(boolean warmup) {
1216         int index = Math.abs(rI) % 3;
1217         try {
1218             test43(testIntegerArray, testValue1, index);
1219             throw new RuntimeException("No ArrayStoreException thrown");
1220         } catch (ArrayStoreException e) {
1221             // Expected
1222         }
1223     }
1224 
1225     // Test value store to (flattened) value type array disguised as interface array
1226 
1227     @ForceInline
1228     public void test43_inline(MyInterface[] ia, MyInterface i, int index) {
1229         ia[index] = i;
1230     }
1231 
1232     @Test()
1233     public void test44(MyInterface[] ia, MyInterface i, int index) {
1234         test43_inline(ia, i, index);
1235     }
1236 
1237     @DontCompile
1238     public void test44_verifier(boolean warmup) {
1239         int index = Math.abs(rI) % 3;
1240         MyValue1 vt1 = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1241         test44(testValue1Array, vt1, index);
1242         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1243         try {
1244             test44(testValue1Array, testValue2, index);
1245             throw new RuntimeException("No ArrayStoreException thrown");
1246         } catch (ArrayStoreException e) {
1247             // Expected
1248         }
1249         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1250         testValue1Array[index] = testValue1;
1251     }
1252 
1253     @ForceInline
1254     public void test45_inline(MyInterface[] ia, MyInterface i, int index) {
1255         ia[index] = i;
1256     }
1257 
1258     @Test()
1259     public void test45(MyInterface[] ia, MyInterface i, int index) {
1260         test45_inline(ia, i, index);
1261     }
1262 
1263     @DontCompile
1264     public void test45_verifier(boolean warmup) {
1265         int index = Math.abs(rI) % 3;
1266         try {
1267             test45(testValue2Array, testValue1, index);
1268             throw new RuntimeException("No ArrayStoreException thrown");
1269         } catch (ArrayStoreException e) {
1270             // Expected
1271         }
1272     }
1273 
1274     // Test writing null to a (flattened) value type array disguised as object array
1275 
1276     @ForceInline
1277     public void test46_inline(Object[] oa, Object o, int index) {
1278         oa[index] = o;
1279     }
1280 
1281     @Test()
1282     public void test46(Object[] oa, Object o, int index) {
1283         test46_inline(oa, o, index);
1284     }
1285 
1286     @DontCompile
1287     public void test46_verifier(boolean warmup) {
1288         int index = Math.abs(rI) % 3;
1289         try {
1290             test46(testValue1Array, null, index);
1291             throw new RuntimeException("No NPE thrown");
1292         } catch (NullPointerException e) {
1293             // Expected
1294         }
1295         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1296     }
1297 
1298     // Test writing constant null to a (flattened) value type array disguised as object array
1299 
1300     @ForceInline
1301     public void test47_inline(Object[] oa, Object o, int index) {
1302         oa[index] = o;
1303     }
1304 
1305     @Test()
1306     public void test47(Object[] oa, int index) {
1307         test47_inline(oa, null, index);
1308     }
1309 
1310     @DontCompile
1311     public void test47_verifier(boolean warmup) {
1312         int index = Math.abs(rI) % 3;
1313         try {
1314             test47(testValue1Array, index);
1315             throw new RuntimeException("No NPE thrown");
1316         } catch (NullPointerException e) {
1317             // Expected
1318         }
1319         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1320     }
1321 
1322     // Test writing null to a (flattened) value type array
1323 
1324     @ForceInline
1325     public void test48_inline(Object[] oa, Object o, int index) {
1326         oa[index] = o;
1327     }
1328 
1329     @Test()
1330     public void test48(MyValue1[] va, int index) {
1331         test48_inline(va, nullField, index);
1332     }
1333 
1334     @DontCompile
1335     public void test48_verifier(boolean warmup) {
1336         int index = Math.abs(rI) % 3;
1337         try {
1338             test48(testValue1Array, index);
1339             throw new RuntimeException("No NPE thrown");
1340         } catch (NullPointerException e) {
1341             // Expected
1342         }
1343         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1344     }
1345 
1346     // Test writing constant null to a (flattened) value type array
1347 
1348     private static final MethodHandle setArrayElementNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1349         "setArrayElementNull",
1350         MethodType.methodType(void.class, TestLWorld.class, MyValue1[].class, int.class),
1351         CODE -> {
1352             CODE.
1353             aload_1().
1354             iload_2().
1355             aconst_null().
1356             aastore().
1357             return_();
1358         },
1359         MyValue1.class);
1360 
1361     @Test()
1362     public void test49(MyValue1[] va, int index) throws Throwable {
1363         setArrayElementNull.invoke(this, va, index);
1364     }
1365 
1366     @DontCompile
1367     public void test49_verifier(boolean warmup) throws Throwable {
1368         int index = Math.abs(rI) % 3;
1369         try {
1370             test49(testValue1Array, index);
1371             throw new RuntimeException("No NPE thrown");
1372         } catch (NullPointerException e) {
1373             // Expected
1374         }
1375         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1376     }
1377 
1378     // Test writing a value type to a null value type array
1379     @Test()
1380     public void test50(MyValue1[] va, MyValue1 vt, int index) {
1381         va[index] = vt;
1382     }
1383 
1384     @DontCompile
1385     public void test50_verifier(boolean warmup) {
1386         int index = Math.abs(rI) % 3;
1387         try {
1388             test50(null, testValue1Array[index], index);
1389             throw new RuntimeException("No NPE thrown");
1390         } catch (NullPointerException e) {
1391             // Expected
1392         }
1393     }
1394 
1395     // Test incremental inlining
1396 
1397     @ForceInline
1398     public void test51_inline(Object[] oa, Object o, int index) {
1399         oa[index] = o;
1400     }
1401 
1402     @Test()
1403     public void test51(MyValue1[] va, Object o, int index) {
1404         test51_inline(va, o, index);
1405     }
1406 
1407     @DontCompile
1408     public void test51_verifier(boolean warmup) {
1409         int index = Math.abs(rI) % 3;
1410         MyValue1 vt1 = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1411         test51(testValue1Array, vt1, index);
1412         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1413         try {
1414             test51(testValue1Array, testValue2, index);
1415             throw new RuntimeException("No ArrayStoreException thrown");
1416         } catch (ArrayStoreException e) {
1417             // Expected
1418         }
1419         Asserts.assertEQ(testValue1Array[index].hash(), vt1.hash());
1420         testValue1Array[index] = testValue1;
1421     }
1422 
1423     // Test merging of value type arrays
1424 
1425     @ForceInline
1426     public Object[] test52_inline() {
1427         return new MyValue1[42];
1428     }
1429 
1430     @Test()
1431     public Object[] test52(Object[] oa, Object o, int i1, int i2, int num) {
1432         Object[] result = null;
1433         switch (num) {
1434         case 0:
1435             result = test52_inline();
1436             break;
1437         case 1:
1438             result = oa;
1439             break;
1440         case 2:
1441             result = testValue1Array;
1442             break;
1443         case 3:
1444             result = testValue2Array;
1445             break;
1446         case 4:
1447             result = testIntegerArray;
1448             break;
1449         case 5:
1450             result = null;
1451             break;
1452         case 6:
1453             result = testValue1Array2;
1454             break;
1455         }
1456         result[i1] = result[i2];
1457         result[i2] = o;
1458         return result;
1459     }
1460 
1461     @DontCompile
1462     public void test52_verifier(boolean warmup) {
1463         int index = Math.abs(rI) % 3;
1464         MyValue1[] va = new MyValue1[42];
1465         Object[] result = test52(null, testValue1, index, index, 0);
1466         Asserts.assertEQ(((MyValue1)result[index]).hash(), testValue1.hash());
1467         result = test52(testValue1Array, testValue1, index, index, 1);
1468         Asserts.assertEQ(((MyValue1)result[index]).hash(), testValue1.hash());
1469         result = test52(null, testValue1, index, index, 2);
1470         Asserts.assertEQ(((MyValue1)result[index]).hash(), testValue1.hash());
1471         result = test52(null, testValue2, index, index, 3);
1472         Asserts.assertEQ(((MyValue2)result[index]).hash(), testValue2.hash());
1473         try {
1474             result = test52(null, null, index, index, 3);
1475             throw new RuntimeException("No NPE thrown");
1476         } catch (NullPointerException e) {
1477             // Expected
1478         }
1479         result = test52(null, null, index, index, 4);
1480         try {
1481             result = test52(null, testValue1, index, index, 4);
1482             throw new RuntimeException("No ArrayStoreException thrown");
1483         } catch (ArrayStoreException e) {
1484             // Expected
1485         }
1486         try {
1487             result = test52(null, testValue1, index, index, 5);
1488             throw new RuntimeException("No NPE thrown");
1489         } catch (NullPointerException e) {
1490             // Expected
1491         }
1492         result = test52(null, testValue1Array, index, index, 6);
1493         Asserts.assertEQ(((MyValue1[][])result)[index][index].hash(), testValue1.hash());
1494     }
1495 
1496     // Same as above but merging into Object instead of Object[]
1497     @Test()
1498     public Object test53(Object oa, Object o, int i1, int i2, int num) {
1499         Object result = null;
1500         switch (num) {
1501         case 0:
1502             result = test52_inline();
1503             break;
1504         case 1:
1505             result = oa;
1506             break;
1507         case 2:
1508             result = testValue1Array;
1509             break;
1510         case 3:
1511             result = testValue2Array;
1512             break;
1513         case 4:
1514             result = testIntegerArray;
1515             break;
1516         case 5:
1517             result = null;
1518             break;
1519         case 6:
1520             result = testValue1;
1521             break;
1522         case 7:
1523             result = testValue2;
1524             break;
1525         case 8:
1526             result = MyValue1.createWithFieldsInline(rI, rL);
1527             break;
1528         case 9:
1529             result = new Integer(42);
1530             break;
1531         case 10:
1532             result = testValue1Array2;
1533             break;
1534         }
1535         if (result instanceof Object[]) {
1536             ((Object[])result)[i1] = ((Object[])result)[i2];
1537             ((Object[])result)[i2] = o;
1538         }
1539         return result;
1540     }
1541 
1542     @DontCompile
1543     public void test53_verifier(boolean warmup) {
1544         int index = Math.abs(rI) % 3;
1545         MyValue1[] va = new MyValue1[42];
1546         Object result = test53(null, testValue1, index, index, 0);
1547         Asserts.assertEQ(((MyValue1[])result)[index].hash(), testValue1.hash());
1548         result = test53(testValue1Array, testValue1, index, index, 1);
1549         Asserts.assertEQ(((MyValue1[])result)[index].hash(), testValue1.hash());
1550         result = test53(null, testValue1, index, index, 2);
1551         Asserts.assertEQ(((MyValue1[])result)[index].hash(), testValue1.hash());
1552         result = test53(null, testValue2, index, index, 3);
1553         Asserts.assertEQ(((MyValue2[])result)[index].hash(), testValue2.hash());
1554         try {
1555             result = test53(null, null, index, index, 3);
1556             throw new RuntimeException("No NPE thrown");
1557         } catch (NullPointerException e) {
1558             // Expected
1559         }
1560         result = test53(null, null, index, index, 4);
1561         try {
1562             result = test53(null, testValue1, index, index, 4);
1563             throw new RuntimeException("No ArrayStoreException thrown");
1564         } catch (ArrayStoreException e) {
1565             // Expected
1566         }
1567         result = test53(null, testValue1, index, index, 5);
1568         Asserts.assertEQ(result, null);
1569         result = test53(null, testValue1, index, index, 6);
1570         Asserts.assertEQ(((MyValue1)result).hash(), testValue1.hash());
1571         result = test53(null, testValue1, index, index, 7);
1572         Asserts.assertEQ(((MyValue2)result).hash(), testValue2.hash());
1573         result = test53(null, testValue1, index, index, 8);
1574         Asserts.assertEQ(((MyValue1)result).hash(), testValue1.hash());
1575         result = test53(null, testValue1, index, index, 9);
1576         Asserts.assertEQ(((Integer)result), 42);
1577         result = test53(null, testValue1Array, index, index, 10);
1578         Asserts.assertEQ(((MyValue1[][])result)[index][index].hash(), testValue1.hash());
1579     }
1580 
1581     // Test instanceof with value types and arrays
1582     @Test()
1583     public long test54(Object o, int index) {
1584         if (o instanceof MyValue1) {
1585           return ((MyValue1)o).hashInterpreted();
1586         } else if (o instanceof MyValue1[]) {
1587           return ((MyValue1[])o)[index].hashInterpreted();
1588         } else if (o instanceof MyValue2) {
1589           return ((MyValue2)o).hash();
1590         } else if (o instanceof MyValue2[]) {
1591           return ((MyValue2[])o)[index].hash();
1592         } else if (o instanceof MyValue1[][]) {
1593           return ((MyValue1[][])o)[index][index].hash();
1594         } else if (o instanceof Long) {
1595           return (long)o;
1596         }
1597         return 0;
1598     }
1599 
1600     @DontCompile
1601     public void test54_verifier(boolean warmup) {
1602         int index = Math.abs(rI) % 3;
1603         long result = test54(testValue1, 0);
1604         Asserts.assertEQ(result, testValue1.hash());
1605         result = test54(testValue1Array, index);
1606         Asserts.assertEQ(result, testValue1.hash());
1607         result = test54(testValue2, index);
1608         Asserts.assertEQ(result, testValue2.hash());
1609         result = test54(testValue2Array, index);
1610         Asserts.assertEQ(result, testValue2.hash());
1611         result = test54(testValue1Array2, index);
1612         Asserts.assertEQ(result, testValue1.hash());
1613         result = test54(new Long(42), index);
1614         Asserts.assertEQ(result, 42L);
1615     }
1616 
1617     // Test for bug in Escape Analysis
1618     @DontInline
1619     public void test55_dontinline(Object o) {
1620         Asserts.assertEQ(o, rI);
1621     }
1622 
1623     @Test()
1624     public void test55() {
1625         MyValue1[] vals = new MyValue1[] {testValue1};
1626         test55_dontinline(vals[0].oa[0]);
1627         test55_dontinline(vals[0].oa[0]);
1628     }
1629 
1630     @DontCompile
1631     public void test55_verifier(boolean warmup) {
1632         test55();
1633     }
1634 
1635     // Test for bug in Escape Analysis
1636     private static __NotFlattened final MyValue1 test56VT1 = MyValue1.createWithFieldsInline(rI, rL);
1637     private static __NotFlattened final MyValue1 test56VT2 = MyValue1.createWithFieldsInline(rI + 1, rL + 1);
1638 
1639     @Test()
1640     public void test56() {
1641         MyValue1[] vals = new MyValue1[] {test56VT1, test56VT2};
1642         Asserts.assertEQ(vals[0].hash(), test56VT1.hash());
1643         Asserts.assertEQ(vals[1].hash(), test56VT2.hash());
1644     }
1645 
1646     @DontCompile
1647     public void test56_verifier(boolean warmup) {
1648         if (!warmup) test56(); // We need -Xcomp behavior
1649     }
1650 
1651     // Test for bug in Escape Analysis
1652     @Test()
1653     public long test57(boolean deopt) {
1654         MyValue1[] vals = new MyValue1[] {test56VT1, test56VT2};
1655 
1656         if (deopt) {
1657             // uncommon trap
1658             WHITE_BOX.deoptimizeMethod(tests.get(getClass().getSimpleName() + "::test57"));
1659             Asserts.assertEQ(vals[0].hash(), test56VT1.hash());
1660             Asserts.assertEQ(vals[1].hash(), test56VT2.hash());
1661         }
1662 
1663         return vals[0].hash();
1664     }
1665 
1666     @DontCompile
1667     public void test57_verifier(boolean warmup) {
1668         test57(!warmup);
1669     }
1670 
1671     // Tests writing an array element with a (statically known) incompatible type
1672     private static final MethodHandle setArrayElementIncompatible = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1673         "setArrayElementIncompatible",
1674         MethodType.methodType(void.class, TestLWorld.class, MyValue1[].class, int.class, MyValue2.class),
1675         CODE -> {
1676             CODE.
1677             aload_1().
1678             iload_2().
1679             aload_3().
1680             aastore().
1681             return_();
1682         },
1683         MyValue1.class, MyValue2.class);
1684 
1685     @Test()
1686     public void test58(MyValue1[] va, int index, MyValue2 v) throws Throwable {
1687         setArrayElementIncompatible.invoke(this, va, index, v);
1688     }
1689 
1690     @DontCompile
1691     public void test58_verifier(boolean warmup) throws Throwable {
1692         int index = Math.abs(rI) % 3;
1693         try {
1694             test58(testValue1Array, index, testValue2);
1695             throw new RuntimeException("No ArrayStoreException thrown");
1696         } catch (ArrayStoreException e) {
1697             // Expected
1698         }
1699         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1700     }
1701 
1702     // Tests writing an array element with a (statically known) incompatible type
1703     @ForceInline
1704     public void test59_inline(Object[] oa, Object o, int index) {
1705         oa[index] = o;
1706     }
1707 
1708     @Test()
1709     public void test59(MyValue1[] va, int index, MyValue2 v) throws Throwable {
1710         test59_inline(va, v, index);
1711     }
1712 
1713     @DontCompile
1714     public void test59_verifier(boolean warmup) throws Throwable {
1715         int index = Math.abs(rI) % 3;
1716         try {
1717             test59(testValue1Array, index, testValue2);
1718             throw new RuntimeException("No ArrayStoreException thrown");
1719         } catch (ArrayStoreException e) {
1720             // Expected
1721         }
1722         Asserts.assertEQ(testValue1Array[index].hash(), hash());
1723     }
1724 
1725     // instanceof tests with values
1726     @Test
1727     public boolean test60(MyValue1 vt) {
1728         Object obj = vt;
1729         return obj instanceof MyValue1;
1730     }
1731 
1732     @DontCompile
1733     public void test60_verifier(boolean warmup) {
1734         MyValue1 vt = testValue1;
1735         boolean result = test60(vt);
1736         Asserts.assertTrue(result);
1737     }
1738 
1739     @Test
1740     public boolean test61(MyValue1 vt) {
1741         Object obj = vt;
1742         return obj instanceof MyValue2;
1743     }
1744 
1745     @DontCompile
1746     public void test61_verifier(boolean warmup) {
1747         MyValue1 vt = testValue1;
1748         boolean result = test61(vt);
1749         Asserts.assertFalse(result);
1750     }
1751 
1752     @Test
1753     public boolean test62(Object obj) {
1754         return obj instanceof MyValue1;
1755     }
1756 
1757     @DontCompile
1758     public void test62_verifier(boolean warmup) {
1759         MyValue1 vt = testValue1;
1760         boolean result = test62(vt);
1761         Asserts.assertTrue(result);
1762     }
1763 
1764     @Test
1765     public boolean test63(Object obj) {
1766         return obj instanceof MyValue2;
1767     }
1768 
1769     @DontCompile
1770     public void test63_verifier(boolean warmup) {
1771         MyValue1 vt = testValue1;
1772         boolean result = test63(vt);
1773         Asserts.assertFalse(result);
1774     }
1775 
1776     @Test
1777     public boolean test64(Object obj) {
1778         return obj instanceof MyValue1;
1779     }
1780 
1781     @DontCompile
1782     public void test64_verifier(boolean warmup) {
1783         boolean result = test63(new Integer(42));
1784         Asserts.assertFalse(result);
1785     }
1786 
1787     // Value type with some non-flattened fields
1788     __ByValue final class Test65Value {
1789         final Object objectField1 = null;
1790         final Object objectField2 = null;
1791         final Object objectField3 = null;
1792         final Object objectField4 = null;
1793         final Object objectField5 = null;
1794         final Object objectField6 = null;
1795 
1796         final __Flattenable  MyValue1 valueField1;
1797         final __Flattenable  MyValue1 valueField2;
1798         final __NotFlattened MyValue1 valueField3;
1799         final __Flattenable  MyValue1 valueField4;
1800         final __NotFlattened MyValue1 valueField5;
1801 
1802         private Test65Value() {
1803             valueField1 = testValue1;
1804             valueField2 = testValue1;
1805             valueField3 = testValue1;
1806             valueField4 = MyValue1.createDefaultDontInline();
1807             valueField5 = MyValue1.createDefaultDontInline();
1808         }
1809 
1810         public Test65Value init() {
1811             Test65Value vt = __WithField(this.valueField1, testValue1);
1812             vt = __WithField(vt.valueField2, testValue1);
1813             vt = __WithField(vt.valueField3, testValue1);
1814             return vt;
1815         }
1816 
1817         @ForceInline
1818         public long test(Test65Value holder, MyValue1 vt1, Object vt2) {
1819             holder = __WithField(holder.objectField1, vt1);
1820             holder = __WithField(holder.objectField2, (MyValue1)vt2);
1821             holder = __WithField(holder.objectField3, testValue1);
1822             holder = __WithField(holder.objectField4, MyValue1.createWithFieldsDontInline(rI, rL));
1823             holder = __WithField(holder.objectField5, holder.valueField1);
1824             holder = __WithField(holder.objectField6, holder.valueField3);
1825             holder = __WithField(holder.valueField1, (MyValue1)holder.objectField1);
1826             holder = __WithField(holder.valueField2, (MyValue1)vt2);
1827             holder = __WithField(holder.valueField3, (MyValue1)vt2);
1828 
1829             return ((MyValue1)holder.objectField1).hash() +
1830                    ((MyValue1)holder.objectField2).hash() +
1831                    ((MyValue1)holder.objectField3).hash() +
1832                    ((MyValue1)holder.objectField4).hash() +
1833                    ((MyValue1)holder.objectField5).hash() +
1834                    ((MyValue1)holder.objectField6).hash() +
1835                    holder.valueField1.hash() +
1836                    holder.valueField2.hash() +
1837                    holder.valueField3.hash() +
1838                    holder.valueField4.hashPrimitive();
1839         }
1840     }
1841 
1842     // Same as test2 but with field holder being a value type
1843     @Test()
1844     public long test65(Test65Value holder, MyValue1 vt1, Object vt2) {
1845         return holder.test(holder, vt1, vt2);
1846     }
1847 
1848     @DontCompile
1849     public void test65_verifier(boolean warmup) {
1850         MyValue1 vt = testValue1;
1851         MyValue1 def = MyValue1.createDefaultDontInline();
1852         Test65Value holder = __MakeDefault Test65Value();
1853         Asserts.assertEQ(testValue1.hash(), vt.hash());
1854         holder = holder.init();
1855         Asserts.assertEQ(holder.valueField1.hash(), vt.hash());
1856         long result = test65(holder, vt, vt);
1857         Asserts.assertEQ(result, 9*vt.hash() + def.hashPrimitive());
1858     }
1859 
1860     // Access non-flattened, uninitialized value type field with value type holder
1861     @Test()
1862     public void test66(Test65Value holder) {
1863         if ((Object)holder.valueField5 != null) {
1864             throw new RuntimeException("Should be null");
1865         }
1866     }
1867 
1868     @DontCompile
1869     public void test66_verifier(boolean warmup) {
1870         Test65Value vt = __MakeDefault Test65Value();
1871         test66(vt);
1872     }
1873 
1874     // Merging value types of different types
1875     @Test()
1876     public Object test67(Object o, boolean b) {
1877         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1878         return b ? vt : o;
1879     }
1880 
1881     @DontCompile
1882     public void test67_verifier(boolean warmup) {
1883         test67(new Object(), false);
1884         MyValue1 result = (MyValue1)test67(new Object(), true);
1885         Asserts.assertEQ(result.hash(), hash());
1886     }
1887 
1888     @Test()
1889     public Object test68(boolean b) {
1890         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1891         return b ? vt : testValue2;
1892     }
1893 
1894     @DontCompile
1895     public void test68_verifier(boolean warmup) {
1896         MyValue1 result1 = (MyValue1)test68(true);
1897         Asserts.assertEQ(result1.hash(), hash());
1898         MyValue2 result2 = (MyValue2)test68(false);
1899         Asserts.assertEQ(result2.hash(), testValue2.hash());
1900     }
1901 
1902     @Test()
1903     public Object test69(boolean b) {
1904         MyValue1 vt1 = MyValue1.createWithFieldsInline(rI, rL);
1905         MyValue2 vt2 = MyValue2.createWithFieldsInline(rI, true);
1906         return b ? vt1 : vt2;
1907     }
1908 
1909     @DontCompile
1910     public void test69_verifier(boolean warmup) {
1911         MyValue1 result1 = (MyValue1)test69(true);
1912         Asserts.assertEQ(result1.hash(), hash());
1913         MyValue2 result2 = (MyValue2)test69(false);
1914         Asserts.assertEQ(result2.hash(), testValue2.hash());
1915     }
1916 
1917     // Test synchronization on value types
1918     @Test()
1919     public void test70(Object vt) {
1920         synchronized (vt) {
1921             throw new RuntimeException("test70 failed: synchronization on value type should not succeed");
1922         }
1923     }
1924 
1925     @DontCompile
1926     public void test70_verifier(boolean warmup) {
1927         try {
1928             test70(testValue1);
1929             throw new RuntimeException("test70 failed: no exception thrown");
1930         } catch (IllegalMonitorStateException ex) {
1931             // Expected
1932         }
1933     }
1934 
1935     @ForceInline
1936     public void test71_inline(Object vt) {
1937         synchronized (vt) {
1938             throw new RuntimeException("test71 failed: synchronization on value type should not succeed");
1939         }
1940     }
1941 
1942     @Test()
1943     public void test71(MyValue1 vt) {
1944         test71_inline(vt);
1945     }
1946 
1947     @DontCompile
1948     public void test71_verifier(boolean warmup) {
1949         try {
1950             test71(testValue1);
1951             throw new RuntimeException("test71 failed: no exception thrown");
1952         } catch (IllegalMonitorStateException ex) {
1953             // Expected
1954         }
1955     }
1956 
1957     @ForceInline
1958     public void test72_inline(Object vt) {
1959         synchronized (vt) {
1960             throw new RuntimeException("test72 failed: synchronization on value type should not succeed");
1961         }
1962     }
1963 
1964     @Test()
1965     public void test72() {
1966         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1967         test72_inline(vt);
1968     }
1969 
1970     @DontCompile
1971     public void test72_verifier(boolean warmup) {
1972         try {
1973             test72();
1974             throw new RuntimeException("test72 failed: no exception thrown");
1975         } catch (IllegalMonitorStateException ex) {
1976             // Expected
1977         }
1978     }
1979 
1980     @Test()
1981     public void test73(Object o, boolean b) {
1982         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1983         Object sync = b ? vt : o;
1984         synchronized (sync) {
1985             if (b) {
1986                 throw new RuntimeException("test73 failed: synchronization on value type should not succeed");
1987             }
1988         }
1989     }
1990 
1991     @DontCompile
1992     public void test73_verifier(boolean warmup) {
1993         test73(new Object(), false);
1994         try {
1995             test73(new Object(), true);
1996             throw new RuntimeException("test73 failed: no exception thrown");
1997         } catch (IllegalMonitorStateException ex) {
1998             // Expected
1999         }
2000     }
2001 
2002     @Test()
2003     public void test74(boolean b) {
2004         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
2005         Object sync = b ? vt : testValue2;
2006         synchronized (sync) {
2007             throw new RuntimeException("test74 failed: synchronization on value type should not succeed");
2008         }
2009     }
2010 
2011     @DontCompile
2012     public void test74_verifier(boolean warmup) {
2013         try {
2014             test74(false);
2015             throw new RuntimeException("test74 failed: no exception thrown");
2016         } catch (IllegalMonitorStateException ex) {
2017             // Expected
2018         }
2019         try {
2020             test74(true);
2021             throw new RuntimeException("test74 failed: no exception thrown");
2022         } catch (IllegalMonitorStateException ex) {
2023             // Expected
2024         }
2025     }
2026 
2027     // Test catching the IllegalMonitorStateException in compiled code
2028     @Test()
2029     public void test75(Object vt) {
2030         boolean thrown = false;
2031         try {
2032             synchronized (vt) {
2033                 throw new RuntimeException("test75 failed: no exception thrown");
2034             }
2035         } catch (IllegalMonitorStateException ex) {
2036             thrown = true;
2037         }
2038         if (!thrown) {
2039             throw new RuntimeException("test75 failed: no exception thrown");
2040         }
2041     }
2042 
2043     @DontCompile
2044     public void test75_verifier(boolean warmup) {
2045         test75(testValue1);
2046     }
2047 
2048     @Test()
2049     public void test76(Object o) {
2050         try {
2051             synchronized (o) { }
2052         } catch (IllegalMonitorStateException ex) {
2053             // Expected
2054             return;
2055         }
2056         throw new RuntimeException("test76 failed: no exception thrown");
2057     }
2058 
2059     @DontCompile
2060     public void test76_verifier(boolean warmup) {
2061         test76(testValue1);
2062     }
2063 
2064     // Test synchronization without any instructions in the synchronized block
2065     @Test()
2066     public void test77(Object o) {
2067         synchronized (o) { }
2068     }
2069 
2070     @DontCompile
2071     public void test77_verifier(boolean warmup) {
2072         try {
2073             test77(testValue1);
2074         } catch (IllegalMonitorStateException ex) {
2075             // Expected
2076             return;
2077         }
2078         throw new RuntimeException("test77 failed: no exception thrown");
2079     }
2080 
2081     // type system test with interface and value type
2082     @ForceInline
2083     public MyInterface test78_helper(MyValue1 vt) {
2084         return vt;
2085     }
2086 
2087     @Test()
2088     public MyInterface test78(MyValue1 vt) {
2089         return test78_helper(vt);
2090     }
2091 
2092     @DontCompile
2093     public void test78_verifier(boolean warmup) {
2094         test78(testValue1);
2095     }
2096 
2097     // Array store tests
2098     @Test()
2099     public void test79(Object[] array, MyValue1 vt) {
2100         array[0] = vt;
2101     }
2102 
2103     @DontCompile
2104     public void test79_verifier(boolean warmup) {
2105         Object[] array = new Object[1];
2106         test79(array, testValue1);
2107         Asserts.assertEQ(((MyValue1)array[0]).hash(), testValue1.hash());
2108     }
2109 
2110     @Test()
2111     public void test80(Object[] array, MyValue1 vt) {
2112         array[0] = vt;
2113     }
2114 
2115     @DontCompile
2116     public void test80_verifier(boolean warmup) {
2117         MyValue1[] array = new MyValue1[1];
2118         test80(array, testValue1);
2119         Asserts.assertEQ(array[0].hash(), testValue1.hash());
2120     }
2121 
2122     @Test()
2123     public void test81(Object[] array, Object vt) {
2124         array[0] = vt;
2125     }
2126 
2127     @DontCompile
2128     public void test81_verifier(boolean warmup) {
2129         MyValue1[] array = new MyValue1[1];
2130         test81(array, testValue1);
2131         Asserts.assertEQ(array[0].hash(), testValue1.hash());
2132     }
2133 
2134     @Test()
2135     public void test82(Object[] array, Integer o) {
2136         array[0] = o;
2137     }
2138 
2139     @DontCompile
2140     public void test82_verifier(boolean warmup) {
2141         Integer[] array = new Integer[1];
2142         test82(array, 1);
2143         Asserts.assertEQ(array[0], Integer.valueOf(1));
2144     }
2145 
2146     // Test convertion between a value type and java.lang.Object without an allocation
2147     @ForceInline
2148     public Object test83_sum(Object a, Object b) {
2149         int sum = ((MyValue1)a).x + ((MyValue1)b).x;
2150         return MyValue1.setX(((MyValue1)a), sum);
2151     }
2152 
2153     @Test(failOn = ALLOC + STORE)
2154     public int test83(Object[] array) {
2155         MyValue1 result = MyValue1.createDefaultInline();
2156         for (int i = 0; i < array.length; ++i) {
2157             result = (MyValue1)test83_sum(result, (MyValue1)array[i]);
2158         }
2159         return result.x;
2160     }
2161 
2162     @DontCompile
2163     public void test83_verifier(boolean warmup) {
2164         int result = test83(testValue1Array);
2165         Asserts.assertEQ(result, rI * testValue1Array.length);
2166     }
2167 
2168     // Same as test84 but with an Interface
2169     @ForceInline
2170     public MyInterface test84_sum(MyInterface a, MyInterface b) {
2171         int sum = ((MyValue1)a).x + ((MyValue1)b).x;
2172         return MyValue1.setX(((MyValue1)a), sum);
2173     }
2174 
2175     @Test(failOn = ALLOC + STORE)
2176     public int test84(MyInterface[] array) {
2177         MyValue1 result = MyValue1.createDefaultInline();
2178         for (int i = 0; i < array.length; ++i) {
2179             result = (MyValue1)test84_sum(result, (MyValue1)array[i]);
2180         }
2181         return result.x;
2182     }
2183 
2184     @DontCompile
2185     public void test84_verifier(boolean warmup) {
2186         int result = test84(testValue1Array);
2187         Asserts.assertEQ(result, rI * testValue1Array.length);
2188     }
2189 
2190     // Test that allocated value type is not used in non-dominated path
2191     public MyValue1 test85_inline(Object obj) {
2192         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
2193         try {
2194             vt = (MyValue1)obj;
2195             throw new RuntimeException("NullPointerException expected");
2196         } catch (NullPointerException e) {
2197             // Expected
2198         }
2199         return vt;
2200     }
2201 
2202     @Test
2203     public MyValue1 test85() {
2204         return test85_inline(null);
2205     }
2206 
2207     @DontCompile
2208     public void test85_verifier(boolean warmup) {
2209         MyValue1 vt = test85();
2210         Asserts.assertEquals(vt.hash(), hash());
2211     }
2212 
2213     // Test calling a method on an uninitialized value type
2214     __ByValue final class Test86Value {
2215         final int x = 42;
2216         public int get() {
2217             return x;
2218         }
2219     }
2220 
2221     // Make sure Test86Value is loaded but not initialized
2222     public void unused(Test86Value vt) { }
2223 
2224     @Test
2225     @Warmup(0)
2226     public int test86() {
2227         Test86Value vt = __MakeDefault Test86Value();
2228         return vt.get();
2229     }
2230 
2231     @DontCompile
2232     public void test86_verifier(boolean warmup) {
2233         int result = test86();
2234         Asserts.assertEquals(result, 0);
2235     }
2236 }