< prev index next >

src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template

Print this page

        

@@ -77,152 +77,160 @@
         }
 
         @ForceInline
         static $type$ get(FieldInstanceReadOnly handle, Object holder) {
             return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getVolatile(FieldInstanceReadOnly handle, Object holder) {
             return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getOpaque(FieldInstanceReadOnly handle, Object holder) {
             return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getAcquire(FieldInstanceReadOnly handle, Object holder) {
             return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
     }
 
     static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
-
         FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
             super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM);
         }
 
+#if[Object]
+        @ForceInline
+        static Object checkCast(FieldInstanceReadWrite handle, $type$ value) {
+            if (!handle.fieldType.isNullableType())
+                Objects.requireNonNull(value);
+            return handle.fieldType.cast(value);
+        }
+#end[Object]
+
         @ForceInline
         static void set(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                             handle.fieldOffset,
-                             {#if[Object]?handle.fieldType.cast(value):value});
+                             handle.fieldOffset{#if[Value]?, handle.fieldType},
+                             {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setVolatile(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                     handle.fieldOffset,
-                                     {#if[Object]?handle.fieldType.cast(value):value});
+                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                     {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setOpaque(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                   handle.fieldOffset,
-                                   {#if[Object]?handle.fieldType.cast(value):value});
+                                   handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                   {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                    handle.fieldOffset,
-                                    {#if[Object]?handle.fieldType.cast(value):value});
+                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                    {#if[Object]?checkCast(handle, value):value});
         }
 #if[CAS]
 
         @ForceInline
         static boolean compareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ compareAndExchange(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ compareAndExchangeAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ compareAndExchangeRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetPlain(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSet(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
             return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 #end[CAS]
 #if[AtomicAdd]
 
         @ForceInline

@@ -359,153 +367,160 @@
         }
 
         @ForceInline
         static $type$ get(FieldStaticReadOnly handle) {
             return UNSAFE.get$Type$(handle.base,
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getVolatile(FieldStaticReadOnly handle) {
             return UNSAFE.get$Type$Volatile(handle.base,
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getOpaque(FieldStaticReadOnly handle) {
             return UNSAFE.get$Type$Opaque(handle.base,
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         @ForceInline
         static $type$ getAcquire(FieldStaticReadOnly handle) {
             return UNSAFE.get$Type$Acquire(handle.base,
-                                 handle.fieldOffset);
+                                 handle.fieldOffset{#if[Value]?, handle.fieldType});
         }
 
         static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
     }
 
     static final class FieldStaticReadWrite extends FieldStaticReadOnly {
-
         FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
             super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM);
         }
 
+#if[Object]
+        static Object checkCast(FieldStaticReadWrite handle, $type$ value) {
+            if (!handle.fieldType.isNullableType())
+                Objects.requireNonNull(value);
+            return handle.fieldType.cast(value);
+        }
+#end[Object]
+
         @ForceInline
         static void set(FieldStaticReadWrite handle, $type$ value) {
             UNSAFE.put$Type$(handle.base,
-                             handle.fieldOffset,
-                             {#if[Object]?handle.fieldType.cast(value):value});
+                             handle.fieldOffset{#if[Value]?, handle.fieldType},
+                             {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setVolatile(FieldStaticReadWrite handle, $type$ value) {
             UNSAFE.put$Type$Volatile(handle.base,
-                                     handle.fieldOffset,
-                                     {#if[Object]?handle.fieldType.cast(value):value});
+                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                     {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setOpaque(FieldStaticReadWrite handle, $type$ value) {
             UNSAFE.put$Type$Opaque(handle.base,
-                                   handle.fieldOffset,
-                                   {#if[Object]?handle.fieldType.cast(value):value});
+                                   handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                   {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static void setRelease(FieldStaticReadWrite handle, $type$ value) {
             UNSAFE.put$Type$Release(handle.base,
-                                    handle.fieldOffset,
-                                    {#if[Object]?handle.fieldType.cast(value):value});
+                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                    {#if[Object]?checkCast(handle, value):value});
         }
 #if[CAS]
 
         @ForceInline
         static boolean compareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.compareAndSet$Type$(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
 
         @ForceInline
         static $type$ compareAndExchange(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ compareAndExchangeAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ compareAndExchangeRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.compareAndExchange$Type$Release(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetPlain(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static boolean weakCompareAndSetRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
             return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
-                                               handle.fieldOffset,
-                                               {#if[Object]?handle.fieldType.cast(expected):expected},
-                                               {#if[Object]?handle.fieldType.cast(value):value});
+                                               handle.fieldOffset{#if[Object]?, handle.fieldType},
+                                               {#if[Object]?checkCast(handle, expected):expected},
+                                               {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSet(FieldStaticReadWrite handle, $type$ value) {
             return UNSAFE.getAndSet$Type$(handle.base,
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetAcquire(FieldStaticReadWrite handle, $type$ value) {
             return UNSAFE.getAndSet$Type$Acquire(handle.base,
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetRelease(FieldStaticReadWrite handle, $type$ value) {
             return UNSAFE.getAndSet$Type$Release(handle.base,
-                                          handle.fieldOffset,
-                                          {#if[Object]?handle.fieldType.cast(value):value});
+                                          handle.fieldOffset{#if[Value]?, handle.fieldType},
+                                          {#if[Object]?checkCast(handle, value):value});
         }
 #end[CAS]
 #if[AtomicAdd]
 
         @ForceInline

@@ -596,10 +611,18 @@
 #end[Bitwise]
 
         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
     }
 
+#if[Reference]
+    static VarHandle makeVarHandleValuesArray(Class<?> arrayClass) {
+        Class<?> componentType = arrayClass.getComponentType();
+        assert componentType.isInlineClass() && UNSAFE.isFlattenedArray(arrayClass);
+        // should cache these VarHandle for performance
+        return VarHandles.makeArrayElementHandle(arrayClass);
+    }
+#end[Reference]
 
     static final class Array extends VarHandle {
         final int abase;
         final int ashift;
 #if[Object]

@@ -632,10 +655,13 @@
         }
 
 #if[Object]
         @ForceInline
         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
+            if (!handle.componentType.isNullableType())
+                 Objects.requireNonNull(value);
+
             if (handle.arrayType == oarray.getClass()) {
                 // Fast path: static array type same as argument array type
                 return handle.componentType.cast(value);
             } else {
                 // Slow path: check value against argument array component type

@@ -668,79 +694,132 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
-            array[index] = {#if[Object]?handle.componentType.cast(value):value};
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                vh.set(oarray, index, reflectiveTypeCheck(array, value));
+                return;
+            }
+#end[Reference]
+            array[index] = {#if[Object]?runtimeTypeCheck(handle, array, value):value};
         }
 
         @ForceInline
         static $type$ getVolatile(Array handle, Object oarray, int index) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getVolatile(oarray, index);
+            }
+#end[Reference]
             return UNSAFE.get$Type$Volatile(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
         }
 
         @ForceInline
         static void setVolatile(Array handle, Object oarray, int index, $type$ value) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                vh.setVolatile(oarray, index, reflectiveTypeCheck(array, value));
+                return;
+            }
+#end[Reference]
             UNSAFE.put$Type$Volatile(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline
         static $type$ getOpaque(Array handle, Object oarray, int index) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getOpaque(oarray, index);
+            }
+#end[Reference]
             return UNSAFE.get$Type$Opaque(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
         }
 
         @ForceInline
         static void setOpaque(Array handle, Object oarray, int index, $type$ value) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                vh.setOpaque(oarray, index, reflectiveTypeCheck(array, value));
+                return;
+            }
+#end[Reference]
             UNSAFE.put$Type$Opaque(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline
         static $type$ getAcquire(Array handle, Object oarray, int index) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getAcquire(oarray, index);
+            }
+#end[Reference]
             return UNSAFE.get$Type$Acquire(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
         }
 
         @ForceInline
         static void setRelease(Array handle, Object oarray, int index, $type$ value) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                vh.setRelease(oarray, index, reflectiveTypeCheck(array, value));
+                return;
+            }
+#end[Reference]
             UNSAFE.put$Type$Release(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 #if[CAS]
 
         @ForceInline

@@ -748,12 +827,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.compareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.compareAndSet$Type$(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -761,12 +847,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.compareAndExchange(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.compareAndExchange$Type$(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -774,12 +867,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.compareAndExchangeAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.compareAndExchange$Type$Acquire(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -787,12 +887,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.compareAndExchangeRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.compareAndExchange$Type$Release(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -800,12 +907,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.weakCompareAndSetPlain(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.weakCompareAndSet$Type$Plain(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -813,12 +927,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.weakCompareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.weakCompareAndSet$Type$(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -826,12 +947,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.weakCompareAndSetAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -839,12 +967,19 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.weakCompareAndSetRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.weakCompareAndSet$Type$Release(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                     {#if[Object]?handle.componentType.cast(expected):expected},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline

@@ -852,36 +987,57 @@
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getAndSet(oarray, index, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.getAndSet$Type$(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetAcquire(Array handle, Object oarray, int index, $type$ value) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getAndSetAcquire(oarray, index, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.getAndSet$Type$Acquire(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 
         @ForceInline
         static $type$ getAndSetRelease(Array handle, Object oarray, int index, $type$ value) {
 #if[Object]
             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 #else[Object]
             $type$[] array = ($type$[]) oarray;
 #end[Object]
+#if[Reference]
+            if (UNSAFE.isFlattenedArray(oarray.getClass())) {
+                // for flattened array, delegate to VarHandle of the inline type array
+                VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
+                return vh.getAndSetRelease(oarray, index, reflectiveTypeCheck(array, value));
+            }
+#end[Reference]
             return UNSAFE.getAndSet$Type$Release(array,
-                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
+                    (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
         }
 #end[CAS]
 #if[AtomicAdd]
 
< prev index next >