1 /*
   2  * Copyright (c) 2017, 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 runtime.valhalla.valuetypes;
  25 
  26 import java.lang.invoke.*;
  27 import java.lang.ref.*;
  28 import java.util.concurrent.*;
  29 
  30 import static jdk.test.lib.Asserts.*;
  31 import jdk.test.lib.Utils;
  32 import sun.hotspot.WhiteBox;
  33 
  34 import jdk.experimental.value.MethodHandleBuilder;
  35 
  36 /**
  37  * @test ValueOops
  38  * @summary Test embedding oops into Value types
  39  * @modules java.base/jdk.experimental.bytecode
  40  *          java.base/jdk.experimental.value
  41  * @library /test/lib
  42  * @compile -XDenableValueTypes Person.java
  43  * @compile -XDenableValueTypes ValueOops.java
  44  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  45  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  46  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  47  * @run main/othervm -Xint -XX:+UseSerialGC -Xmx128m -XX:+EnableValhalla
  48  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  49  *                   runtime.valhalla.valuetypes.ValueOops
  50  * @run main/othervm -Xint  -XX:+UseG1GC -Xmx128m -XX:+EnableValhalla
  51  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  52  *                   runtime.valhalla.valuetypes.ValueOops 100
  53  * @run main/othervm -Xint -XX:+UseParallelGC -Xmx128m -XX:+EnableValhalla
  54  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  55  *                   runtime.valhalla.valuetypes.ValueOops
  56  * @run main/othervm -Xcomp -XX:+UseSerialGC -Xmx128m -XX:+EnableValhalla
  57  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  58  *                   runtime.valhalla.valuetypes.ValueOops
  59  * @run main/othervm -Xcomp -XX:+UseG1GC -Xmx128m -XX:+EnableValhalla
  60  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  61  *                   runtime.valhalla.valuetypes.ValueOops 100
  62  * @run main/othervm -Xcomp -XX:+UseParallelGC -Xmx128m -XX:+EnableValhalla
  63  *                   -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  64  *                   runtime.valhalla.valuetypes.ValueOops
  65  */
  66 public class ValueOops {
  67 
  68     // Note: -noverify can not be eliminated. Javac Class_Info not using ";Q"
  69 
  70     // Extra debug: -XX:+VerifyOops -XX:+VerifyStack -XX:+VerifyLastFrame -XX:+VerifyBeforeGC -XX:+VerifyAfterGC -XX:+VerifyDuringGC -XX:VerifySubSet=threads,heap
  71     // Even more debugging: -XX:+TraceNewOopMapGeneration -Xlog:gc*=info
  72 
  73     static final int NOF_PEOPLE = 1000; // Exercise arrays of this size
  74 
  75     static int MIN_ACTIVE_GC_COUNT = 10; // Run active workload for this number of GC passes
  76 
  77     static int MED_ACTIVE_GC_COUNT = 4;  // Medium life span in terms of GC passes
  78 
  79     static final String TEST_STRING1 = "Test String 1";
  80     static final String TEST_STRING2 = "Test String 2";
  81 
  82     static boolean USE_COMPILER = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompiler");
  83 
  84     static MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
  85 
  86     public static void main(String[] args) {
  87         if (args.length > 0) {
  88             MIN_ACTIVE_GC_COUNT = Integer.parseInt(args[0]);
  89         }
  90         testClassLoad();
  91         testVvt();
  92 
  93         if (!USE_COMPILER) {
  94             testOopMaps();
  95         }
  96 
  97         // Check we survive GC...
  98         testOverGc();   // Exercise root scan / oopMap
  99         testActiveGc(); // Brute force
 100     }
 101 
 102     /**
 103      * Test ClassFileParser can load values with reference fields
 104      */
 105     public static void testClassLoad() {
 106         String s = Person.class.toString();
 107         new Bar();
 108         new BarWithValue();
 109         s = BarValue.class.toString();
 110         s = ObjectWithObjectValue.class.toString();
 111         s = ObjectWithObjectValues.class.toString();
 112     }
 113 
 114 
 115     static class Couple {
 116         public Person onePerson;
 117         public Person otherPerson;
 118     }
 119 
 120     static final __ByValue class Composition {
 121         public final Person onePerson;
 122         public final Person otherPerson;
 123 
 124         private Composition() {
 125             this.onePerson   = Person.create(0, null, null);
 126             this.otherPerson = Person.create(0, null, null);
 127         }
 128 
 129         __ValueFactory public static Composition create(Person onePerson, Person otherPerson) {
 130             Composition comp = __MakeDefault Composition();
 131             comp.onePerson   = onePerson;
 132             comp.otherPerson = otherPerson;
 133             return comp;
 134         }
 135     }
 136 
 137     /**
 138      * Check value type operations with "Valhalla Value Types" (VVT)
 139      */
 140     public static void testVvt() {
 141         // Exercise creation, getfield, vreturn with null refs
 142         validateDefaultPerson(createDefaultPerson());
 143 
 144         // anewarray, vaload, vastore
 145         int index = 7;
 146         Person[] array =  new Person[NOF_PEOPLE];
 147         validateDefaultPerson(array[index]);
 148 
 149         // Now with refs...
 150         validateIndexedPerson(createIndexedPerson(index), index);
 151         array[index] = createIndexedPerson(index);
 152         validateIndexedPerson(array[index], index);
 153 
 154         // Check the neighbours
 155         validateDefaultPerson(array[index - 1]);
 156         validateDefaultPerson(array[index + 1]);
 157 
 158         // getfield/putfield
 159         Couple couple = new Couple();
 160         validateDefaultPerson(couple.onePerson);
 161         validateDefaultPerson(couple.otherPerson);
 162 
 163         couple.onePerson = createIndexedPerson(index);
 164         validateIndexedPerson(couple.onePerson, index);
 165 
 166         Composition composition = Composition.create(couple.onePerson, couple.onePerson);
 167         validateIndexedPerson(composition.onePerson, index);
 168         validateIndexedPerson(composition.otherPerson, index);
 169     }
 170 
 171     /**
 172      * Check oop map generation for klass layout and frame...
 173      */
 174     public static void testOopMaps() {
 175         Object[] objects = WhiteBox.getWhiteBox().getObjectsViaKlassOopMaps(new Couple());
 176         assertTrue(objects.length == 4, "Expected 4 oops");
 177         for (int i = 0; i < objects.length; i++) {
 178             assertTrue(objects[i] == null, "not-null");
 179         }
 180 
 181         String fn1 = "Sam";
 182         String ln1 = "Smith";
 183         String fn2 = "Jane";
 184         String ln2 = "Jones";
 185         Couple couple = new Couple();
 186         couple.onePerson = Person.create(0, fn1, ln1);
 187         couple.otherPerson = Person.create(1, fn2, ln2);
 188         objects = WhiteBox.getWhiteBox().getObjectsViaKlassOopMaps(couple);
 189         assertTrue(objects.length == 4, "Expected 4 oops");
 190         assertTrue(objects[0] == fn1, "Bad oop fn1");
 191         assertTrue(objects[1] == ln1, "Bad oop ln1");
 192         assertTrue(objects[2] == fn2, "Bad oop fn2");
 193         assertTrue(objects[3] == ln2, "Bad oop ln2");
 194 
 195         objects = WhiteBox.getWhiteBox().getObjectsViaOopIterator(couple);
 196         assertTrue(objects.length == 4, "Expected 4 oops");
 197         assertTrue(objects[0] == fn1, "Bad oop fn1");
 198         assertTrue(objects[1] == ln1, "Bad oop ln1");
 199         assertTrue(objects[2] == fn2, "Bad oop fn2");
 200         assertTrue(objects[3] == ln2, "Bad oop ln2");
 201 
 202         // Array..
 203         objects = WhiteBox.getWhiteBox().getObjectsViaOopIterator(createPeople());
 204         assertTrue(objects.length == NOF_PEOPLE * 2, "Unexpected length: " + objects.length);
 205         int o = 0;
 206         for (int i = 0; i < NOF_PEOPLE; i++) {
 207             assertTrue(objects[o++].equals(firstName(i)), "Bad firstName");
 208             assertTrue(objects[o++].equals(lastName(i)), "Bad lastName");
 209         }
 210 
 211         // Sanity check, FixMe need more test cases
 212         objects = testFrameOops(couple);
 213         assertTrue(objects.length == 5, "Number of frame oops incorrect = " + objects.length);
 214         assertTrue(objects[0] == couple, "Bad oop 0");
 215         assertTrue(objects[1] == fn1, "Bad oop 1");
 216         assertTrue(objects[2] == ln1, "Bad oop 2");
 217         assertTrue(objects[3] == TEST_STRING1, "Bad oop 3");
 218         assertTrue(objects[4] == TEST_STRING2, "Bad oop 4");
 219 
 220         testFrameOopsVBytecodes();
 221     }
 222 
 223     static final String GET_OOP_MAP_NAME = "getOopMap";
 224     static final String GET_OOP_MAP_DESC = "()[Ljava/lang/Object;";
 225 
 226     public static Object[] getOopMap() {
 227         Object[] oopMap = WhiteBox.getWhiteBox().getObjectsViaFrameOopIterator(2);
 228         /* Remove this frame (class mirror for this method), and above class mirror */
 229         Object[] trimmedOopMap = new Object[oopMap.length - 2];
 230         System.arraycopy(oopMap, 2, trimmedOopMap, 0, trimmedOopMap.length);
 231         return trimmedOopMap;
 232     }
 233 
 234     // Expecting Couple couple, Person couple.onePerson, and Person (created here)
 235     public static Object[] testFrameOops(Couple couple) {
 236         int someId = 89898;
 237         Person person = couple.onePerson;
 238         assertTrue(person.getId() == 0, "Bad Person");
 239         Person anotherPerson = Person.create(someId, TEST_STRING1, TEST_STRING2);
 240         assertTrue(anotherPerson.getId() == someId, "Bad Person");
 241         return getOopMap();
 242     }
 243 
 244     // Debug...
 245     static void dumpOopMap(Object[] oopMap) {
 246         System.out.println("Oop Map len: " + oopMap.length);
 247         for (int i = 0; i < oopMap.length; i++) {
 248             System.out.println("[" + i + "] = " + oopMap[i]);
 249         }
 250     }
 251 
 252     /**
 253      * Just some check sanity checks with vdefault, vwithfield, vstore and vload
 254      *
 255      * Changes to javac slot usage may well break this test
 256      */
 257     public static void testFrameOopsVBytecodes() {
 258         int nofOopMaps = 4;
 259         Object[][] oopMaps = new Object[nofOopMaps][];
 260         String[] inputArgs = new String[] { "aName", "aDescription", "someNotes" };
 261 
 262         FooValue.testFrameOopsDefault(oopMaps);
 263 
 264         // Test-D0 Slots=R Stack=Q(RRR)RV
 265         assertTrue(oopMaps[0].length == 5 &&
 266                    oopMaps[0][1] == null &&
 267                    oopMaps[0][2] == null &&
 268                    oopMaps[0][3] == null, "Test-D0 incorrect");
 269 
 270         // Test-D1 Slots=R Stack=RV
 271         assertTrue(oopMaps[1].length == 2, "Test-D1 incorrect");
 272 
 273         // Test-D2 Slots=RQ(RRR) Stack=RV
 274         assertTrue(oopMaps[2].length == 5 &&
 275                    oopMaps[2][1] == null &&
 276                    oopMaps[2][2] == null &&
 277                    oopMaps[2][3] == null, "Test-D2 incorrect");
 278 
 279         // Test-D3 Slots=R Stack=Q(RRR)RV
 280         assertTrue(oopMaps[3].length == 6 &&
 281                    oopMaps[3][1] == null &&
 282                    oopMaps[3][2] == null &&
 283                    oopMaps[3][3] == null &&
 284                    oopMaps[3][4] == null, "Test-D3 incorrect");
 285 
 286         // With ref fields...
 287         String name = "TestName";
 288         String desc = "TestDesc";
 289         String note = "TestNotes";
 290         FooValue.testFrameOopsRefs(name, desc, note, oopMaps);
 291 
 292         // Test-R0 Slots=RR Stack=Q(RRR)RV
 293         assertTrue(oopMaps[0].length == 6 &&
 294                    oopMaps[0][2] == name &&
 295                    oopMaps[0][3] == desc &&
 296                    oopMaps[0][4] == note, "Test-R0 incorrect");
 297 
 298         /**
 299          * TODO: vwithfield from method handle cooked from anonymous class within the value class
 300          *       even with "MethodHandles.privateLookupIn()" will fail final putfield rules
 301          */
 302     }
 303 
 304     /**
 305      * Check forcing GC for combination of VT on stack/LVT etc works
 306      */
 307     public static void testOverGc() {
 308         try {
 309             Class<?> vtClass = Person.class;
 310 
 311             doGc();
 312 
 313             // VT on stack and lvt, null refs, see if GC flies
 314             MethodHandle moveValueThroughStackAndLvt = MethodHandleBuilder.loadCode(
 315                 LOOKUP,
 316                 "gcOverPerson",
 317                 MethodType.methodType(vtClass, vtClass),
 318                 CODE->{
 319                 CODE
 320                 .vload(0)
 321                 .invokestatic(ValueOops.class, "doGc", "()V", false) // Stack
 322                 .vstore(0)
 323                 .invokestatic(ValueOops.class, "doGc", "()V", false) // LVT
 324                 .vload(0)
 325                 .iconst_1()  // push a litte further down
 326                 .invokestatic(ValueOops.class, "doGc", "()V", false) // Stack,LVT
 327                 .pop()
 328                 .vreturn();
 329             });
 330             Person person = (Person) moveValueThroughStackAndLvt.invokeExact(createDefaultPerson());
 331             validateDefaultPerson(person);
 332             doGc();
 333 
 334             int index = 4711;
 335             person = (Person) moveValueThroughStackAndLvt.invokeExact(createIndexedPerson(index));
 336             validateIndexedPerson(person, index);
 337             doGc();
 338             person = createDefaultPerson();
 339             doGc();
 340         }
 341         catch (Throwable t) { fail("testOverGc", t); }
 342     }
 343 
 344     static void submitNewWork(ForkJoinPool fjPool, int size) {
 345         for (int i = 0; i < size; i++) {
 346             for (int j = 0; j < 100; j++) {
 347                 fjPool.execute(ValueOops::testVvt);
 348             }
 349         }
 350     }
 351 
 352     static void sleepNoThrow(long ms) {
 353         try {
 354             Thread.sleep(ms);
 355         }
 356         catch (Throwable t) {}
 357     }
 358 
 359     /**
 360      * Run some workloads with different object/value life times...
 361      */
 362     public static void testActiveGc() {
 363         try {
 364             int nofThreads = 7;
 365             int workSize = nofThreads * 10;
 366 
 367             Object longLivedObjects = createLongLived();
 368             Object longLivedPeople = createPeople();
 369 
 370             Object medLivedObjects = createLongLived();
 371             Object medLivedPeople = createPeople();
 372 
 373             doGc();
 374 
 375             ForkJoinPool fjPool = new ForkJoinPool(nofThreads, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
 376 
 377             // submit work until we see some GC
 378             Reference ref = createRef();
 379             submitNewWork(fjPool, workSize);
 380             while (ref.get() != null) {
 381                 if (fjPool.hasQueuedSubmissions()) {
 382                     sleepNoThrow(1L);
 383                 }
 384                 else {
 385                     workSize *= 2; // Grow the submission size
 386                     submitNewWork(fjPool, workSize);
 387                 }
 388             }
 389 
 390             // Keep working and actively GC, until MIN_ACTIVE_GC_COUNT
 391             int nofActiveGc = 1;
 392             ref = createRef();
 393             while (nofActiveGc < MIN_ACTIVE_GC_COUNT) {
 394                 if (ref.get() == null) {
 395                     nofActiveGc++;
 396                     ref = createRef();
 397                     if (nofActiveGc % MED_ACTIVE_GC_COUNT == 0) {
 398                         validateLongLived(medLivedObjects);
 399                         validatePeople(medLivedPeople);
 400 
 401                         medLivedObjects = createLongLived();
 402                         medLivedPeople = createPeople();
 403                     }
 404                 }
 405                 else if (fjPool.hasQueuedSubmissions()) {
 406                     sleepNoThrow((long) Utils.getRandomInstance().nextInt(1000));
 407                     doGc();
 408                 }
 409                 else {
 410                     submitNewWork(fjPool, workSize);
 411                 }
 412             }
 413             fjPool.shutdown();
 414 
 415             validateLongLived(medLivedObjects);
 416             validatePeople(medLivedPeople);
 417             medLivedObjects = null;
 418             medLivedPeople = null;
 419 
 420             validateLongLived(longLivedObjects);
 421             validatePeople(longLivedPeople);
 422 
 423             longLivedObjects = null;
 424             longLivedPeople = null;
 425 
 426             doGc();
 427         }
 428         catch (Throwable t) { fail("testActiveGc", t); }
 429     }
 430 
 431     static final ReferenceQueue<Object> REFQ = new ReferenceQueue<>();
 432 
 433     public static void doGc() {
 434         // Create Reference, wait until it clears...
 435         Reference ref = createRef();
 436         while (ref.get() != null) {
 437             System.gc();
 438         }
 439     }
 440 
 441     static Reference createRef() {
 442         return new WeakReference<Object>(new Object(), REFQ);
 443     }
 444 
 445     static void validatePerson(Person person, int id, String fn, String ln, boolean equals) {
 446         assertTrue(person.id == id);
 447         if (equals) {
 448             assertTrue(fn.equals(person.getFirstName()), "Invalid field firstName");
 449             assertTrue(ln.equals(person.getLastName()), "Invalid  field lastName");
 450         }
 451         else {
 452             assertTrue(person.getFirstName() == fn, "Invalid field firstName");
 453             assertTrue(person.getLastName() == ln, "Invalid  field lastName");
 454         }
 455     }
 456 
 457     static Person createIndexedPerson(int i) {
 458         return Person.create(i, firstName(i), lastName(i));
 459     }
 460 
 461     static void validateIndexedPerson(Person person, int i) {
 462         validatePerson(person, i, firstName(i), lastName(i), true);
 463     }
 464 
 465     static Person createDefaultPerson() {
 466         return Person.create(0, null, null);
 467     }
 468 
 469     static void validateDefaultPerson(Person person) {
 470         validatePerson(person, 0, null, null, false);
 471     }
 472 
 473     static String firstName(int i) {
 474         return "FirstName-" + i;
 475     }
 476 
 477     static String lastName(int i) {
 478         return "LastName-" + i;
 479     }
 480 
 481     static Object createLongLived()  throws Throwable {
 482         Object[] population = new Object[1];
 483         population[0] = createPeople();
 484         return population;
 485     }
 486 
 487     static void validateLongLived(Object pop) throws Throwable {
 488         Object[] population = (Object[]) pop;
 489         validatePeople(population[0]);
 490     }
 491 
 492     static Object createPeople() {
 493         int arrayLength = NOF_PEOPLE;
 494         Person[] people = new Person[arrayLength];
 495         for (int i = 0; i < arrayLength; i++) {
 496             people[i] = createIndexedPerson(i);
 497         }
 498         return people;
 499     }
 500 
 501     static void validatePeople(Object array) {
 502         Person[] people = (Person[]) array;
 503         int arrayLength = people.length;
 504         assertTrue(arrayLength == NOF_PEOPLE);
 505         for (int i = 0; i < arrayLength; i++) {
 506             validateIndexedPerson(people[i], i);
 507         }
 508     }
 509 
 510     // Various field layouts...sanity testing, see MVTCombo testing for full-set
 511 
 512     static final __ByValue class ObjectValue {
 513         final Object object;
 514 
 515         private ObjectValue(Object object) {
 516             this.object = object;
 517         }
 518     }
 519 
 520     static class ObjectWithObjectValue {
 521         ObjectValue value1;
 522         Object      ref1;
 523     }
 524 
 525     static class ObjectWithObjectValues {
 526         ObjectValue value1;
 527         ObjectValue value2;
 528         Object      ref1;
 529     }
 530 
 531     static class Foo {
 532         int id;
 533         String name;
 534         String description;
 535         long timestamp;
 536         String notes;
 537     }
 538 
 539     static class Bar extends Foo {
 540         long extendedId;
 541         String moreNotes;
 542         int count;
 543         String otherStuff;
 544     }
 545 
 546     public static final __ByValue class FooValue {
 547         public final int id;
 548         public final String name;
 549         public final String description;
 550         public final long timestamp;
 551         public final String notes;
 552 
 553         private FooValue() {
 554             this.id          = 0;
 555             this.name        = null;
 556             this.description = null;
 557             this.timestamp   = 0L;
 558             this.notes       = null;
 559         }
 560 
 561         __ValueFactory public static FooValue create(int id, String name, String description, long timestamp, String notes) {
 562             FooValue f = __MakeDefault FooValue();
 563             f.id          = id;
 564             f.name        = name;
 565             f.description = description;
 566             f.timestamp   = timestamp;
 567             f.notes       = notes;
 568             return f;
 569         }
 570 
 571         public static void testFrameOopsDefault(Object[][] oopMaps) {
 572             MethodType mt = MethodType.methodType(Void.TYPE, oopMaps.getClass());
 573             int oopMapsSlot   = 0;
 574             int vtSlot        = 1;
 575 
 576             // Slots 1=oopMaps
 577             // OopMap Q=RRR (.name .description .someNotes)
 578             try {
 579                 MethodHandleBuilder.loadCode(
 580                               LOOKUP, "exerciseVBytecodeExprStackWithDefault", mt,
 581                               CODE->{
 582                                   CODE
 583                                       .vdefault(FooValue.class)
 584                                       .aload(oopMapsSlot)
 585                                       .iconst_0()  // Test-D0 Slots=R Stack=Q(RRR)RV
 586                                       .invokestatic(ValueOops.class, GET_OOP_MAP_NAME, GET_OOP_MAP_DESC, false)
 587                                       .aastore()
 588                                       .pop()
 589                                       .aload(oopMapsSlot)
 590                                       .iconst_1()  // Test-D1 Slots=R Stack=RV
 591                                       .invokestatic(ValueOops.class, GET_OOP_MAP_NAME, GET_OOP_MAP_DESC, false)
 592                                       .aastore()
 593                                       .vdefault(FooValue.class)
 594                                       .vstore(vtSlot)
 595                                       .aload(oopMapsSlot)
 596                                       .iconst_2()  // Test-D2 Slots=RQ(RRR) Stack=RV
 597                                       .invokestatic(ValueOops.class, GET_OOP_MAP_NAME, GET_OOP_MAP_DESC, false)
 598                                       .aastore()
 599                                       .vload(vtSlot)
 600                                       .aconst_null()
 601                                       .astore(vtSlot) // Storing null over the Q slot won't remove the ref, but should be single null ref
 602                                       .aload(oopMapsSlot)
 603                                       .iconst_3()  // Test-D3 Slots=R Stack=Q(RRR)RV
 604                                       .invokestatic(ValueOops.class, GET_OOP_MAP_NAME, GET_OOP_MAP_DESC, false)
 605                                       .aastore()
 606                                       .pop()
 607                                       .return_();
 608                               }).invoke(oopMaps);
 609             } catch (Throwable t) { fail("exerciseVBytecodeExprStackWithDefault", t); }
 610         }
 611 
 612         public static void testFrameOopsRefs(String name, String description, String notes, Object[][] oopMaps) {
 613             FooValue f = create(4711, name, description, 9876543231L, notes);
 614             FooValue[] fa = new FooValue[] { f };
 615             MethodType mt = MethodType.methodType(Void.TYPE, fa.getClass(), oopMaps.getClass());
 616             int fooArraySlot  = 0;
 617             int oopMapsSlot   = 1;
 618             try {
 619                 MethodHandleBuilder.loadCode(LOOKUP, "exerciseVBytecodeExprStackWithRefs", mt,
 620                               CODE->{
 621                                   CODE
 622                                       .aload(fooArraySlot)
 623                                       .iconst_0()
 624                                       .vaload()
 625                                       .aload(oopMapsSlot)
 626                                       .iconst_0()  // Test-R0 Slots=RR Stack=Q(RRR)RV
 627                                       .invokestatic(ValueOops.class, GET_OOP_MAP_NAME, GET_OOP_MAP_DESC, false)
 628                                       .aastore()
 629                                       .pop()
 630                                       .return_();
 631                               }).invoke(fa, oopMaps);
 632             } catch (Throwable t) { fail("exerciseVBytecodeExprStackWithRefs", t); }
 633         }
 634     }
 635 
 636     static class BarWithValue {
 637         FooValue foo;
 638         long extendedId;
 639         String moreNotes;
 640         int count;
 641         String otherStuff;
 642     }
 643 
 644     static final __ByValue class BarValue {
 645         final FooValue foo;
 646         final long extendedId;
 647         final String moreNotes;
 648         final int count;
 649         final String otherStuff;
 650 
 651         private BarValue(FooValue foo, long extendedId, String moreNotes, int count, String otherStuff) {
 652             this.foo = foo;
 653             this.extendedId = extendedId;
 654             this.moreNotes = moreNotes;
 655             this.count = count;
 656             this.otherStuff = otherStuff;
 657         }
 658     }
 659 
 660 }
 661