1 /*
   2  * Copyright (c) 2017, 2019, 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.reflect.Array;
  27 import java.lang.reflect.Field;
  28 import java.util.Arrays;
  29 
  30 import jdk.test.lib.Asserts;
  31 import jdk.internal.misc.Unsafe;
  32 
  33 /*
  34  * @test
  35  * @summary Test intrinsic support for value types
  36  * @library /testlibrary /test/lib /compiler/whitebox /
  37  * @modules java.base/jdk.internal.misc
  38  * @requires os.simpleArch == "x64"
  39  * @compile -XDallowWithFieldOperator TestIntrinsics.java
  40  * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
  41  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  42  *                               -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  43  *                               compiler.valhalla.valuetypes.ValueTypeTest
  44  *                               compiler.valhalla.valuetypes.TestIntrinsics
  45  */
  46 public class TestIntrinsics extends ValueTypeTest {
  47     // Extra VM parameters for some test scenarios. See ValueTypeTest.getVMParameters()
  48     @Override
  49     public String[] getExtraVMParameters(int scenario) {
  50         switch (scenario) {
  51         case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:+ValueArrayFlatten"};
  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(Object.class, MyValue1.class), "test1_1 failed");
  70         Asserts.assertTrue(test1(MyValue1.class, MyValue1.class), "test1_2 failed");
  71         Asserts.assertTrue(test1(Object.class, java.util.ArrayList.class), "test1_3 failed");
  72         Asserts.assertTrue(test1(java.util.ArrayList.class, java.util.ArrayList.class), "test1_4 failed");
  73     }
  74 
  75     // Verify that Class::isAssignableFrom checks with statically known classes are folded
  76     @Test(failOn = LOADK)
  77     public boolean test2() {
  78         boolean check1 = java.util.AbstractList.class.isAssignableFrom(java.util.ArrayList.class);
  79         boolean check2 = MyValue1.class.isAssignableFrom(MyValue1.class);
  80         boolean check3 = Object.class.isAssignableFrom(java.util.ArrayList.class);
  81         boolean check4 = Object.class.isAssignableFrom(MyValue1.class);
  82         boolean check5 = !MyValue1.class.isAssignableFrom(Object.class);
  83         return check1 && check2 && check3 && check4 && check5;
  84     }
  85 
  86     public void test2_verifier(boolean warmup) {
  87         Asserts.assertTrue(test2(), "test2 failed");
  88     }
  89 
  90     // Test correctness of the Class::getSuperclass intrinsic
  91     @Test()
  92     public Class<?> test3(Class<?> cls) {
  93         return cls.getSuperclass();
  94     }
  95 
  96     public void test3_verifier(boolean warmup) {
  97         Asserts.assertTrue(test3(Object.class) == null, "test3_1 failed");
  98         Asserts.assertTrue(test3(MyValue1.class) == Object.class, "test3_2 failed");
  99         Asserts.assertTrue(test3(Class.class) == Object.class, "test3_3 failed");
 100     }
 101 
 102     // Verify that Class::getSuperclass checks with statically known classes are folded
 103     @Test(failOn = LOADK)
 104     public boolean test4() {
 105         boolean check1 = Object.class.getSuperclass() == null;
 106         boolean check2 = MyValue1.class.getSuperclass() == Object.class;
 107         boolean check3 = Class.class.getSuperclass() == Object.class;
 108         return check1 && check2 && check3;
 109     }
 110 
 111     public void test4_verifier(boolean warmup) {
 112         Asserts.assertTrue(test4(), "test4 failed");
 113     }
 114 
 115     // Test toString() method
 116     @Test()
 117     public String test5(MyValue1 v) {
 118         return v.toString();
 119     }
 120 
 121     @DontCompile
 122     public void test5_verifier(boolean warmup) {
 123         MyValue1 v = MyValue1.createDefaultInline();
 124         test5(v);
 125     }
 126 
 127     // Test hashCode() method
 128     @Test()
 129     public int test6(MyValue1 v) {
 130         return v.hashCode();
 131     }
 132 
 133     @DontCompile
 134     public void test6_verifier(boolean warmup) {
 135         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 136         int res = test6(v);
 137         Asserts.assertEQ(res, v.hashCode());
 138     }
 139 
 140     // Test default value type array creation via reflection
 141     @Test()
 142     public Object[] test7(Class<?> componentType, int len) {
 143         Object[] va = (Object[])Array.newInstance(componentType, len);
 144         return va;
 145     }
 146 
 147     @DontCompile
 148     public void test7_verifier(boolean warmup) {
 149         int len = Math.abs(rI) % 42;
 150         long hash = MyValue1.createDefaultDontInline().hashPrimitive();
 151         Object[] va = test7(MyValue1.class, len);
 152         for (int i = 0; i < len; ++i) {
 153             Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
 154         }
 155     }
 156 
 157     // Class.isInstance
 158     @Test()
 159     public boolean test8(Class c, MyValue1 vt) {
 160         return c.isInstance(vt);
 161     }
 162 
 163     @DontCompile
 164     public void test8_verifier(boolean warmup) {
 165         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 166         boolean result = test8(MyValue1.class, vt);
 167         Asserts.assertTrue(result);
 168     }
 169 
 170     @Test()
 171     public boolean test9(Class c, MyValue1 vt) {
 172         return c.isInstance(vt);
 173     }
 174 
 175     @DontCompile
 176     public void test9_verifier(boolean warmup) {
 177         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 178         boolean result = test9(MyValue2.class, vt);
 179         Asserts.assertFalse(result);
 180     }
 181 
 182     // Class.cast
 183     @Test()
 184     public Object test10(Class c, MyValue1 vt) {
 185         return c.cast(vt);
 186     }
 187 
 188     @DontCompile
 189     public void test10_verifier(boolean warmup) {
 190         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 191         Object result = test10(MyValue1.class, vt);
 192         Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
 193     }
 194 
 195     @Test()
 196     public Object test11(Class c, MyValue1 vt) {
 197         return c.cast(vt);
 198     }
 199 
 200     @DontCompile
 201     public void test11_verifier(boolean warmup) {
 202         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 203         try {
 204             test11(MyValue2.class, vt);
 205             throw new RuntimeException("should have thrown");
 206         } catch(ClassCastException cce) {
 207         }
 208     }
 209 
 210     @Test()
 211     public Object test12(MyValue1 vt) {
 212         return MyValue1.class.cast(vt);
 213     }
 214 
 215     @DontCompile
 216     public void test12_verifier(boolean warmup) {
 217         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 218         Object result = test12(vt);
 219         Asserts.assertEQ(((MyValue1)result).hash(), vt.hash());
 220     }
 221 
 222     @Test()
 223     public Object test13(MyValue1 vt) {
 224         return MyValue2.class.cast(vt);
 225     }
 226 
 227     @DontCompile
 228     public void test13_verifier(boolean warmup) {
 229         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 230         try {
 231             test13(vt);
 232             throw new RuntimeException("should have thrown");
 233         } catch(ClassCastException cce) {
 234         }
 235     }
 236 
 237     // value type array creation via reflection
 238     @Test()
 239     public void test14(int len, long hash) {
 240         Object[] va = (Object[])Array.newInstance(MyValue1.class, len);
 241         for (int i = 0; i < len; ++i) {
 242             Asserts.assertEQ(((MyValue1)va[i]).hashPrimitive(), hash);
 243         }
 244     }
 245 
 246     @DontCompile
 247     public void test14_verifier(boolean warmup) {
 248         int len = Math.abs(rI) % 42;
 249         long hash = MyValue1.createDefaultDontInline().hashPrimitive();
 250         test14(len, hash);
 251     }
 252 
 253     // Test hashCode() method
 254     @Test()
 255     public int test15(Object v) {
 256         return v.hashCode();
 257     }
 258 
 259     @DontCompile
 260     public void test15_verifier(boolean warmup) {
 261         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 262         int res = test15(v);
 263         Asserts.assertEQ(res, v.hashCode());
 264     }
 265 
 266     @Test()
 267     public int test16(Object v) {
 268         return System.identityHashCode(v);
 269     }
 270 
 271     @DontCompile
 272     public void test16_verifier(boolean warmup) {
 273         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 274         int res = test16(v);
 275         Asserts.assertEQ(res, System.identityHashCode((Object)v));
 276     }
 277 
 278     @Test()
 279     public int test17(Object v) {
 280         return System.identityHashCode(v);
 281     }
 282 
 283     @DontCompile
 284     public void test17_verifier(boolean warmup) {
 285         Integer v = new Integer(rI);
 286         int res = test17(v);
 287         Asserts.assertEQ(res, System.identityHashCode(v));
 288     }
 289 
 290     @Test()
 291     public int test18(Object v) {
 292         return System.identityHashCode(v);
 293     }
 294 
 295     @DontCompile
 296     public void test18_verifier(boolean warmup) {
 297         Object v = null;
 298         int res = test18(v);
 299         Asserts.assertEQ(res, System.identityHashCode(v));
 300     }
 301 
 302     // hashCode() and toString() with different value types
 303     @Test()
 304     public int test19(MyValue1 vt1, MyValue1 vt2, boolean b) {
 305         MyValue1 res = b ? vt1 : vt2;
 306         return res.hashCode();
 307     }
 308 
 309     @DontCompile
 310     public void test19_verifier(boolean warmup) {
 311         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 312         int res = test19(vt, vt, true);
 313         Asserts.assertEQ(res, vt.hashCode());
 314         res = test19(vt, vt, false);
 315         Asserts.assertEQ(res, vt.hashCode());
 316     }
 317 
 318     @Test()
 319     public String test20(MyValue1 vt1, MyValue1 vt2, boolean b) {
 320         MyValue1 res = b ? vt1 : vt2;
 321         return res.toString();
 322     }
 323 
 324     @DontCompile
 325     public void test20_verifier(boolean warmup) {
 326         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 327         String res = test20(vt, vt, true);
 328         Asserts.assertEQ(res, vt.toString());
 329         res = test20(vt, vt, false);
 330         Asserts.assertEQ(res, vt.toString());
 331     }
 332 
 333     private static final Unsafe U = Unsafe.getUnsafe();
 334     private static final long X_OFFSET;
 335     private static final long Y_OFFSET;
 336     private static final long V1_OFFSET;
 337     private static final boolean V1_FLATTENED;
 338     static {
 339         try {
 340             Field xField = MyValue1.class.getDeclaredField("x");
 341             X_OFFSET = U.objectFieldOffset(xField);
 342             Field yField = MyValue1.class.getDeclaredField("y");
 343             Y_OFFSET = U.objectFieldOffset(yField);
 344             Field v1Field = MyValue1.class.getDeclaredField("v1");
 345             V1_OFFSET = U.objectFieldOffset(v1Field);
 346             V1_FLATTENED = U.isFlattened(v1Field);
 347         } catch (Exception e) {
 348             throw new RuntimeException(e);
 349         }
 350     }
 351 
 352     protected static final String CALL_Unsafe = START + "CallStaticJava" + MID + "# Static  jdk.internal.misc.Unsafe::" + END;
 353 
 354     @Test(failOn=CALL_Unsafe)
 355     public int test21(MyValue1 v) {
 356        return U.getInt(v, X_OFFSET);
 357     }
 358 
 359     @DontCompile
 360     public void test21_verifier(boolean warmup) {
 361         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 362         int res = test21(v);
 363         Asserts.assertEQ(res, v.x);
 364     }
 365 
 366     MyValue1.val test22_vt;
 367     @Test(failOn=CALL_Unsafe + ALLOC)
 368     public void test22(MyValue1 v) {
 369         v = U.makePrivateBuffer(v);
 370         U.putInt(v, X_OFFSET, rI);
 371         v = U.finishPrivateBuffer(v);
 372         test22_vt = v;
 373     }
 374 
 375     @DontCompile
 376     public void test22_verifier(boolean warmup) {
 377         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 378         test22(v.setX(v, 0));
 379         Asserts.assertEQ(test22_vt.hash(), v.hash());
 380     }
 381 
 382     @Test(failOn=CALL_Unsafe)
 383     public int test23(MyValue1 v, long offset) {
 384         return U.getInt(v, offset);
 385     }
 386 
 387     @DontCompile
 388     public void test23_verifier(boolean warmup) {
 389         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 390         int res = test23(v, X_OFFSET);
 391         Asserts.assertEQ(res, v.x);
 392     }
 393 
 394     MyValue1.val test24_vt = MyValue1.createWithFieldsInline(rI, rL);
 395 
 396     @Test(failOn=CALL_Unsafe)
 397     public int test24(long offset) {
 398         return U.getInt(test24_vt, offset);
 399     }
 400 
 401     @DontCompile
 402     public void test24_verifier(boolean warmup) {
 403         int res = test24(X_OFFSET);
 404         Asserts.assertEQ(res, test24_vt.x);
 405     }
 406 
 407     // Test copyOf intrinsic with allocated value type in it's debug information
 408     value final class Test25Value {
 409         final int x;
 410         public Test25Value() {
 411             this.x = 42;
 412         }
 413     }
 414 
 415     final Test25Value[] test25Array = new Test25Value[10];
 416 
 417     @Test
 418     public Test25Value[] test25(Test25Value element) {
 419         Test25Value[] newArray = Arrays.copyOf(test25Array, test25Array.length + 1);
 420         newArray[test25Array.length] = element;
 421         return newArray;
 422     }
 423 
 424     @DontCompile
 425     public void test25_verifier(boolean warmup) {
 426         Test25Value vt = new Test25Value();
 427         test25(vt);
 428     }
 429 
 430     @Test
 431     public Object test26() {
 432         Class<?>[] ca = new Class<?>[1];
 433         for (int i = 0; i < 1; ++i) {
 434           // Folds during loop opts
 435           ca[i] = MyValue1.class;
 436         }
 437         return Array.newInstance(ca[0], 1);
 438     }
 439 
 440     @DontCompile
 441     public void test26_verifier(boolean warmup) {
 442         Object[] res = (Object[])test26();
 443         Asserts.assertEQ(((MyValue1)res[0]).hashPrimitive(), MyValue1.createDefaultInline().hashPrimitive());
 444     }
 445 
 446     // Load non-flattenable value type field with unsafe
 447     MyValue1.box test27_vt = MyValue1.createWithFieldsInline(rI, rL);
 448     private static final long TEST27_OFFSET;
 449     static {
 450         try {
 451             Field field = TestIntrinsics.class.getDeclaredField("test27_vt");
 452             TEST27_OFFSET = U.objectFieldOffset(field);
 453         } catch (Exception e) {
 454             throw new RuntimeException(e);
 455         }
 456     }
 457 
 458     @Test(failOn=CALL_Unsafe)
 459     public MyValue1 test27() {
 460         return (MyValue1)U.getReference(this, TEST27_OFFSET);
 461     }
 462 
 463     @DontCompile
 464     public void test27_verifier(boolean warmup) {
 465         MyValue1 res = test27();
 466         Asserts.assertEQ(res.hash(), test24_vt.hash());
 467     }
 468 
 469     // Mismatched type
 470     @Test(failOn=CALL_Unsafe)
 471     public int test28(MyValue1 v) {
 472         return U.getByte(v, X_OFFSET);
 473     }
 474 
 475     @DontCompile
 476     public void test28_verifier(boolean warmup) {
 477         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 478         int res = test28(v);
 479         if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
 480             Asserts.assertEQ(res, (int)((byte)v.x));
 481         } else {
 482             Asserts.assertEQ(res, (int)((byte)Integer.reverseBytes(v.x)));
 483         }
 484     }
 485 
 486     // Wrong alignment
 487     @Test(failOn=CALL_Unsafe)
 488     public long test29(MyValue1 v) {
 489         // Read the field that's guaranteed to not be last in the
 490         // value so we don't read out of the value
 491         if (X_OFFSET < Y_OFFSET) {
 492             return U.getInt(v, X_OFFSET+1);
 493         }
 494         return U.getLong(v, Y_OFFSET+1);
 495     }
 496 
 497     @DontCompile
 498     public void test29_verifier(boolean warmup) {
 499         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 500         long res = test29(v);
 501         if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
 502             if (X_OFFSET < Y_OFFSET) {
 503                 Asserts.assertEQ(((int)res) << 8, (v.x >> 8) << 8);
 504             } else {
 505                 Asserts.assertEQ(res << 8, (v.y >> 8) << 8);
 506             }
 507         } else {
 508             if (X_OFFSET < Y_OFFSET) {
 509                 Asserts.assertEQ(((int)res), v.x >>> 8);
 510             } else {
 511                 Asserts.assertEQ(res, v.y >>> 8);
 512             }
 513         }
 514     }
 515 
 516     // getValue to retrieve flattened field from value
 517     @Test(failOn=CALL_Unsafe)
 518     public MyValue2 test30(MyValue1 v) {
 519         if (V1_FLATTENED) {
 520             return U.getValue(v, V1_OFFSET, MyValue2.class);
 521         }
 522         return (MyValue2)U.getReference(v, V1_OFFSET);
 523     }
 524 
 525     @DontCompile
 526     public void test30_verifier(boolean warmup) {
 527         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 528         MyValue2 res = test30(v);
 529         Asserts.assertEQ(res.hash(), v.v1.hash());
 530     }
 531 
 532     MyValue1.val test31_vt;
 533     private static final long TEST31_VT_OFFSET;
 534     private static final boolean TEST31_VT_FLATTENED;
 535     static {
 536         try {
 537             Field test31_vt_Field = TestIntrinsics.class.getDeclaredField("test31_vt");
 538             TEST31_VT_OFFSET = U.objectFieldOffset(test31_vt_Field);
 539             TEST31_VT_FLATTENED = U.isFlattened(test31_vt_Field);
 540         } catch (Exception e) {
 541             throw new RuntimeException(e);
 542         }
 543     }
 544 
 545     // getValue to retrieve flattened field from object
 546     @Test(failOn=CALL_Unsafe)
 547     public MyValue1 test31() {
 548         if (TEST31_VT_FLATTENED) {
 549             return U.getValue(this, TEST31_VT_OFFSET, MyValue1.class);
 550         }
 551         return (MyValue1)U.getReference(this, TEST31_VT_OFFSET);
 552     }
 553 
 554     @DontCompile
 555     public void test31_verifier(boolean warmup) {
 556         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 557         MyValue1 res = test31();
 558         Asserts.assertEQ(res.hash(), test31_vt.hash());
 559     }
 560 
 561     // putValue to set flattened field in object
 562     @Test(failOn=CALL_Unsafe)
 563     public void test32(MyValue1 vt) {
 564         if (TEST31_VT_FLATTENED) {
 565             U.putValue(this, TEST31_VT_OFFSET, MyValue1.class, vt);
 566         } else {
 567             U.putReference(this, TEST31_VT_OFFSET, vt);
 568         }
 569     }
 570 
 571     @DontCompile
 572     public void test32_verifier(boolean warmup) {
 573         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 574         test31_vt = MyValue1.createDefaultInline();
 575         test32(vt);
 576         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 577     }
 578 
 579     private static final int TEST33_BASE_OFFSET;
 580     private static final int TEST33_INDEX_SCALE;
 581     private static final boolean TEST33_FLATTENED_ARRAY;
 582     static {
 583         try {
 584             TEST33_BASE_OFFSET = U.arrayBaseOffset(MyValue1[].class);
 585             TEST33_INDEX_SCALE = U.arrayIndexScale(MyValue1[].class);
 586             TEST33_FLATTENED_ARRAY = U.isFlattenedArray(MyValue1[].class);
 587         } catch (Exception e) {
 588             throw new RuntimeException(e);
 589         }
 590     }
 591     // getValue to retrieve flattened field from array
 592     @Test(failOn=CALL_Unsafe)
 593     public MyValue1 test33(MyValue1[] arr) {
 594         if (TEST33_FLATTENED_ARRAY) {
 595             return U.getValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class);
 596         }
 597         return (MyValue1)U.getReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE);
 598     }
 599 
 600     @DontCompile
 601     public void test33_verifier(boolean warmup) {
 602         MyValue1[] arr = new MyValue1[2];
 603         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 604         arr[1] = vt;
 605         MyValue1 res = test33(arr);
 606         Asserts.assertEQ(res.hash(), vt.hash());
 607     }
 608 
 609     // putValue to set flattened field in array
 610     @Test(failOn=CALL_Unsafe)
 611     public void test34(MyValue1[] arr, MyValue1 vt) {
 612         if (TEST33_FLATTENED_ARRAY) {
 613             U.putValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class, vt);
 614         } else {
 615             U.putReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, vt);
 616         }
 617     }
 618 
 619     @DontCompile
 620     public void test34_verifier(boolean warmup) {
 621         MyValue1[] arr = new MyValue1[2];
 622         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 623         test34(arr, vt);
 624         Asserts.assertEQ(arr[1].hash(), vt.hash());
 625     }
 626 
 627     // getValue to retrieve flattened field from object with unknown
 628     // container type
 629     @Test(failOn=CALL_Unsafe)
 630     public MyValue1 test35(Object o) {
 631         if (TEST31_VT_FLATTENED) {
 632             return U.getValue(o, TEST31_VT_OFFSET, MyValue1.class);
 633         }
 634         return (MyValue1)U.getReference(o, TEST31_VT_OFFSET);
 635     }
 636 
 637     @DontCompile
 638     public void test35_verifier(boolean warmup) {
 639         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 640         MyValue1 res = test35(this);
 641         Asserts.assertEQ(res.hash(), test31_vt.hash());
 642     }
 643 
 644     // getValue to retrieve flattened field from object at unknown
 645     // offset
 646     @Test(failOn=CALL_Unsafe)
 647     public MyValue1 test36(long offset) {
 648         if (TEST31_VT_FLATTENED) {
 649             return U.getValue(this, offset, MyValue1.class);
 650         }
 651         return (MyValue1)U.getReference(this, offset);
 652     }
 653 
 654     @DontCompile
 655     public void test36_verifier(boolean warmup) {
 656         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 657         MyValue1 res = test36(TEST31_VT_OFFSET);
 658         Asserts.assertEQ(res.hash(), test31_vt.hash());
 659     }
 660 
 661     // putValue to set flattened field in object with unknown
 662     // container
 663     @Test(failOn=CALL_Unsafe)
 664     public void test37(Object o, MyValue1 vt) {
 665         if (TEST31_VT_FLATTENED) {
 666             U.putValue(o, TEST31_VT_OFFSET, MyValue1.class, vt);
 667         } else {
 668             U.putReference(o, TEST31_VT_OFFSET, vt);
 669         }
 670     }
 671 
 672     @DontCompile
 673     public void test37_verifier(boolean warmup) {
 674         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 675         test31_vt = MyValue1.createDefaultInline();
 676         test37(this, vt);
 677         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 678     }
 679 
 680     // putValue to set flattened field in object, non value argument
 681     // to store
 682     @Test(match = { CALL_Unsafe }, matchCount = { 1 })
 683     public void test38(Object o) {
 684         if (TEST31_VT_FLATTENED) {
 685             U.putValue(this, TEST31_VT_OFFSET, MyValue1.class, o);
 686         } else {
 687             U.putReference(this, TEST31_VT_OFFSET, o);
 688         }
 689     }
 690 
 691     @DontCompile
 692     public void test38_verifier(boolean warmup) {
 693         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 694         test31_vt = MyValue1.createDefaultInline();
 695         test38(vt);
 696         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 697     }
 698 
 699     @Test(failOn=CALL_Unsafe)
 700     public MyValue1 test39(MyValue1 v) {
 701         v = U.makePrivateBuffer(v);
 702         U.putInt(v, X_OFFSET, rI);
 703         v = U.finishPrivateBuffer(v);
 704         return v;
 705     }
 706 
 707     @DontCompile
 708     public void test39_verifier(boolean warmup) {
 709         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 710         MyValue1 res = test39(v.setX(v, 0));
 711         Asserts.assertEQ(res.hash(), v.hash());
 712     }
 713 }