< prev index next >

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

Print this page
@@ -92,39 +92,38 @@
  
          @ForceInline
          static $type$ get(VarHandle ob, Object holder) {
              FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
              return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getVolatile(VarHandle ob, Object holder) {
              FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
              return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getOpaque(VarHandle ob, Object holder) {
              FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
              return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getAcquire(VarHandle ob, Object holder) {
              FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
              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}) {
              this(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
          }
  
          private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},

@@ -144,137 +143,146 @@
              return !hasInvokeExactBehavior()
                  ? this
                  : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
          }
  
+ #if[Object]
+         @ForceInline
+         static Object checkCast(FieldInstanceReadWrite handle, $type$ value) {
+             if (handle.fieldType.isValueType())
+                 Objects.requireNonNull(value);
+             return handle.fieldType.cast(value);
+         }
+ #end[Object]
+ 
          @ForceInline
          static void set(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ expected, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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(VarHandle ob, Object holder, $type$ value) {
              FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
              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

@@ -438,39 +446,38 @@
  
          @ForceInline
          static $type$ get(VarHandle ob) {
              FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
              return UNSAFE.get$Type$(handle.base,
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getVolatile(VarHandle ob) {
              FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
              return UNSAFE.get$Type$Volatile(handle.base,
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getOpaque(VarHandle ob) {
              FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
              return UNSAFE.get$Type$Opaque(handle.base,
-                                  handle.fieldOffset);
+                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
          }
  
          @ForceInline
          static $type$ getAcquire(VarHandle ob) {
              FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
              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}) {
              this(base, fieldOffset{#if[Object]?, fieldType}, false);
          }
  
          private FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},

@@ -490,138 +497,146 @@
              return !hasInvokeExactBehavior()
                  ? this
                  : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, false);
          }
  
+ #if[Object]
+         static Object checkCast(FieldStaticReadWrite handle, $type$ value) {
+             if (handle.fieldType.isValueType())
+                 Objects.requireNonNull(value);
+             return handle.fieldType.cast(value);
+         }
+ #end[Object]
+ 
          @ForceInline
          static void set(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ expected, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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(VarHandle ob, $type$ value) {
              FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
              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

@@ -724,10 +739,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.isValueType() && 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]

@@ -778,10 +801,13 @@
          }
  
  #if[Object]
          @ForceInline
          static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
+             if (handle.componentType.isValueType())
+                  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

@@ -816,35 +842,58 @@
  #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(VarHandle ob, Object oarray, int index) {
              Array handle = (Array)ob;
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
          }
  
          @ForceInline
          static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
              Array handle = (Array)ob;
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline
          static $type$ getOpaque(VarHandle ob, Object oarray, int index) {

@@ -852,24 +901,39 @@
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
          }
  
          @ForceInline
          static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
              Array handle = (Array)ob;
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline
          static $type$ getAcquire(VarHandle ob, Object oarray, int index) {

@@ -877,24 +941,39 @@
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
          }
  
          @ForceInline
          static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
              Array handle = (Array)ob;
  #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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  #if[CAS]
  
          @ForceInline

@@ -903,12 +982,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -917,12 +1003,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -931,12 +1024,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -945,12 +1045,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -959,12 +1066,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -973,12 +1087,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -987,12 +1108,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -1001,12 +1129,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, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
                      {#if[Object]?handle.componentType.cast(expected):expected},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline

@@ -1015,12 +1150,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.getAndSet(oarray, index, reflectiveTypeCheck(array, value));
+             }
+ #end[Reference]
              return UNSAFE.getAndSet$Type$(array,
-                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline
          static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {

@@ -1028,12 +1170,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.getAndSetAcquire(oarray, index, reflectiveTypeCheck(array, value));
+             }
+ #end[Reference]
              return UNSAFE.getAndSet$Type$Acquire(array,
-                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  
          @ForceInline
          static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {

@@ -1041,12 +1190,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.getAndSetRelease(oarray, index, reflectiveTypeCheck(array, value));
+             }
+ #end[Reference]
              return UNSAFE.getAndSet$Type$Release(array,
-                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
+                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
                      {#if[Object]?runtimeTypeCheck(handle, array, value):value});
          }
  #end[CAS]
  #if[AtomicAdd]
  
< prev index next >