1 /*
   2  * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.invoke;
  26 
  27 #if[Reference]
  28 import jdk.internal.value.ValueClass;
  29 #end[Reference]
  30 import jdk.internal.util.Preconditions;
  31 import jdk.internal.vm.annotation.ForceInline;
  32 
  33 import java.lang.invoke.VarHandle.VarHandleDesc;
  34 import java.util.Objects;
  35 import java.util.Optional;
  36 
  37 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  38 
  39 #warn
  40 
  41 final class VarHandle$Type$s {
  42 
  43     static sealed class FieldInstanceReadOnly extends VarHandle {
  44         final long fieldOffset;
  45         final Class<?> receiverType;
  46 #if[Object]
  47         final Class<?> fieldType;
  48 #end[Object]
  49 #if[Reference]
  50         final boolean nullRestricted;
  51 #end[Reference]
  52 
  53         FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted}) {
  54             this(receiverType, fieldOffset{#if[Object]?, fieldType, nullRestricted}, FieldInstanceReadOnly.FORM, false);
  55         }
  56 
  57         protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted},
  58                                         VarForm form, boolean exact) {
  59             super(form, exact);
  60             this.fieldOffset = fieldOffset;
  61             this.receiverType = receiverType;
  62 #if[Object]
  63             this.fieldType = fieldType;
  64 #end[Object]
  65 #if[Reference]
  66             this.nullRestricted = nullRestricted;
  67 #end[Reference]
  68         }
  69 
  70         @Override
  71         public FieldInstanceReadOnly withInvokeExactBehavior() {
  72             return hasInvokeExactBehavior()
  73                 ? this
  74                 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Reference]?, fieldType, nullRestricted}{#if[Value]?, fieldType, true}, vform, true);
  75         }
  76 
  77         @Override
  78         public FieldInstanceReadOnly withInvokeBehavior() {
  79             return !hasInvokeExactBehavior()
  80                 ? this
  81                 : new FieldInstanceReadOnly(receiverType, fieldOffset{#if[Reference]?, fieldType, nullRestricted}{#if[Value]?, fieldType, true}, vform, false);
  82         }
  83 
  84         @Override
  85         final MethodType accessModeTypeUncached(AccessType at) {
  86             return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
  87         }
  88 
  89         @Override
  90         public Optional<VarHandleDesc> describeConstable() {
  91             var receiverTypeRef = receiverType.describeConstable();
  92             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
  93             if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
  94                 return Optional.empty();
  95 
  96             // Reflect on this VarHandle to extract the field name
  97             String name = VarHandles.getFieldFromReceiverAndOffset(
  98                 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
  99             return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
 100         }
 101 
 102         @ForceInline
 103         static $type$ get(VarHandle ob, Object holder) {
 104             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 105             $type$ value = UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 106                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 107 #if[Reference]
 108             if (handle.nullRestricted && value == null) {
 109                 return ValueClass.zeroInstance(handle.fieldType);
 110             }
 111 #end[Reference]
 112             return value;
 113         }
 114 
 115         @ForceInline
 116         static $type$ getVolatile(VarHandle ob, Object holder) {
 117             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 118             $type$ value = UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 119                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 120 #if[Reference]
 121             if (handle.nullRestricted && value == null) {
 122                 return ValueClass.zeroInstance(handle.fieldType);
 123             }
 124 #end[Reference]
 125             return value;
 126         }
 127 
 128         @ForceInline
 129         static $type$ getOpaque(VarHandle ob, Object holder) {
 130             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 131             $type$ value = UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 132                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 133 #if[Reference]
 134             if (handle.nullRestricted && value == null) {
 135                 return ValueClass.zeroInstance(handle.fieldType);
 136             }
 137 #end[Reference]
 138             return value;
 139         }
 140 
 141         @ForceInline
 142         static $type$ getAcquire(VarHandle ob, Object holder) {
 143             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 144             $type$ value = UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 145                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 146 #if[Reference]
 147             if (handle.nullRestricted && value == null) {
 148                 return ValueClass.zeroInstance(handle.fieldType);
 149             }
 150 #end[Reference]
 151             return value;
 152         }
 153 
 154         static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
 155     }
 156 
 157     static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
 158         FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted}) {
 159             this(receiverType, fieldOffset{#if[Object]?, fieldType, nullRestricted}, false);
 160         }
 161 
 162         private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted},
 163                                        boolean exact) {
 164             super(receiverType, fieldOffset{#if[Object]?, fieldType, nullRestricted}, FieldInstanceReadWrite.FORM, exact);
 165         }
 166 
 167         @Override
 168         public FieldInstanceReadWrite withInvokeExactBehavior() {
 169             return hasInvokeExactBehavior()
 170                 ? this
 171                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Reference]?, fieldType, nullRestricted}{#if[Value]?, fieldType, true}, true);
 172         }
 173 
 174         @Override
 175         public FieldInstanceReadWrite withInvokeBehavior() {
 176             return !hasInvokeExactBehavior()
 177                 ? this
 178                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Reference]?, fieldType, nullRestricted}{#if[Value]?, fieldType, true}, false);
 179         }
 180 
 181 #if[Object]
 182         @ForceInline
 183         static Object checkCast(FieldInstanceReadWrite handle, $type$ value) {
 184 #if[Reference]
 185             if (value == null && handle.nullRestricted)
 186                 throw new NullPointerException("null-restricted field");
 187 #end[Reference]
 188             return handle.fieldType.cast(value);
 189         }
 190 #end[Object]
 191 
 192         @ForceInline
 193         static void set(VarHandle ob, Object holder, $type$ value) {
 194             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 195             UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 196                              handle.fieldOffset{#if[Value]?, handle.fieldType},
 197                              {#if[Object]?checkCast(handle, value):value});
 198         }
 199 
 200         @ForceInline
 201         static void setVolatile(VarHandle ob, Object holder, $type$ value) {
 202             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 203             UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 204                                      handle.fieldOffset{#if[Value]?, handle.fieldType},
 205                                      {#if[Object]?checkCast(handle, value):value});
 206         }
 207 
 208         @ForceInline
 209         static void setOpaque(VarHandle ob, Object holder, $type$ value) {
 210             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 211             UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 212                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
 213                                    {#if[Object]?checkCast(handle, value):value});
 214         }
 215 
 216         @ForceInline
 217         static void setRelease(VarHandle ob, Object holder, $type$ value) {
 218             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 219             UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 220                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
 221                                     {#if[Object]?checkCast(handle, value):value});
 222         }
 223 #if[CAS]
 224 
 225         @ForceInline
 226         static boolean compareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 227             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 228             return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 229                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 230                                                {#if[Object]?checkCast(handle, expected):expected},
 231                                                {#if[Object]?checkCast(handle, value):value});
 232         }
 233 
 234         @ForceInline
 235         static $type$ compareAndExchange(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 236             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 237             return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 238                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 239                                                {#if[Object]?checkCast(handle, expected):expected},
 240                                                {#if[Object]?checkCast(handle, value):value});
 241         }
 242 
 243         @ForceInline
 244         static $type$ compareAndExchangeAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 245             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 246             return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 247                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 248                                                {#if[Object]?checkCast(handle, expected):expected},
 249                                                {#if[Object]?checkCast(handle, value):value});
 250         }
 251 
 252         @ForceInline
 253         static $type$ compareAndExchangeRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 254             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 255             return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 256                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 257                                                {#if[Object]?checkCast(handle, expected):expected},
 258                                                {#if[Object]?checkCast(handle, value):value});
 259         }
 260 
 261         @ForceInline
 262         static boolean weakCompareAndSetPlain(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 263             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 264             return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
 265                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 266                                                {#if[Object]?checkCast(handle, expected):expected},
 267                                                {#if[Object]?checkCast(handle, value):value});
 268         }
 269 
 270         @ForceInline
 271         static boolean weakCompareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 272             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 273             return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 274                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 275                                                {#if[Object]?checkCast(handle, expected):expected},
 276                                                {#if[Object]?checkCast(handle, value):value});
 277         }
 278 
 279         @ForceInline
 280         static boolean weakCompareAndSetAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 281             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 282             return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 283                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 284                                                {#if[Object]?checkCast(handle, expected):expected},
 285                                                {#if[Object]?checkCast(handle, value):value});
 286         }
 287 
 288         @ForceInline
 289         static boolean weakCompareAndSetRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 290             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 291             return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 292                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 293                                                {#if[Object]?checkCast(handle, expected):expected},
 294                                                {#if[Object]?checkCast(handle, value):value});
 295         }
 296 
 297         @ForceInline
 298         static $type$ getAndSet(VarHandle ob, Object holder, $type$ value) {
 299             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 300             return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 301                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 302                                           {#if[Object]?checkCast(handle, value):value});
 303         }
 304 
 305         @ForceInline
 306         static $type$ getAndSetAcquire(VarHandle ob, Object holder, $type$ value) {
 307             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 308             return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 309                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 310                                           {#if[Object]?checkCast(handle, value):value});
 311         }
 312 
 313         @ForceInline
 314         static $type$ getAndSetRelease(VarHandle ob, Object holder, $type$ value) {
 315             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 316             return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 317                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 318                                           {#if[Object]?checkCast(handle, value):value});
 319         }
 320 #end[CAS]
 321 #if[AtomicAdd]
 322 
 323         @ForceInline
 324         static $type$ getAndAdd(VarHandle ob, Object holder, $type$ value) {
 325             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 326             return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 327                                        handle.fieldOffset,
 328                                        value);
 329         }
 330 
 331         @ForceInline
 332         static $type$ getAndAddAcquire(VarHandle ob, Object holder, $type$ value) {
 333             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 334             return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 335                                        handle.fieldOffset,
 336                                        value);
 337         }
 338 
 339         @ForceInline
 340         static $type$ getAndAddRelease(VarHandle ob, Object holder, $type$ value) {
 341             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 342             return UNSAFE.getAndAdd$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 343                                        handle.fieldOffset,
 344                                        value);
 345         }
 346 
 347 #end[AtomicAdd]
 348 #if[Bitwise]
 349 
 350         @ForceInline
 351         static $type$ getAndBitwiseOr(VarHandle ob, Object holder, $type$ value) {
 352             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 353             return UNSAFE.getAndBitwiseOr$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 354                                        handle.fieldOffset,
 355                                        value);
 356         }
 357 
 358         @ForceInline
 359         static $type$ getAndBitwiseOrRelease(VarHandle ob, Object holder, $type$ value) {
 360             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 361             return UNSAFE.getAndBitwiseOr$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 362                                        handle.fieldOffset,
 363                                        value);
 364         }
 365 
 366         @ForceInline
 367         static $type$ getAndBitwiseOrAcquire(VarHandle ob, Object holder, $type$ value) {
 368             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 369             return UNSAFE.getAndBitwiseOr$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 370                                        handle.fieldOffset,
 371                                        value);
 372         }
 373 
 374         @ForceInline
 375         static $type$ getAndBitwiseAnd(VarHandle ob, Object holder, $type$ value) {
 376             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 377             return UNSAFE.getAndBitwiseAnd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 378                                        handle.fieldOffset,
 379                                        value);
 380         }
 381 
 382         @ForceInline
 383         static $type$ getAndBitwiseAndRelease(VarHandle ob, Object holder, $type$ value) {
 384             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 385             return UNSAFE.getAndBitwiseAnd$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 386                                        handle.fieldOffset,
 387                                        value);
 388         }
 389 
 390         @ForceInline
 391         static $type$ getAndBitwiseAndAcquire(VarHandle ob, Object holder, $type$ value) {
 392             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 393             return UNSAFE.getAndBitwiseAnd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 394                                        handle.fieldOffset,
 395                                        value);
 396         }
 397 
 398         @ForceInline
 399         static $type$ getAndBitwiseXor(VarHandle ob, Object holder, $type$ value) {
 400             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 401             return UNSAFE.getAndBitwiseXor$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 402                                        handle.fieldOffset,
 403                                        value);
 404         }
 405 
 406         @ForceInline
 407         static $type$ getAndBitwiseXorRelease(VarHandle ob, Object holder, $type$ value) {
 408             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 409             return UNSAFE.getAndBitwiseXor$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 410                                        handle.fieldOffset,
 411                                        value);
 412         }
 413 
 414         @ForceInline
 415         static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object holder, $type$ value) {
 416             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 417             return UNSAFE.getAndBitwiseXor$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 418                                        handle.fieldOffset,
 419                                        value);
 420         }
 421 #end[Bitwise]
 422 
 423         static final VarForm FORM = new VarForm(FieldInstanceReadWrite.class, Object.class, $type$.class);
 424     }
 425 
 426 
 427     static sealed class FieldStaticReadOnly extends VarHandle {
 428         final Class<?> declaringClass;
 429         final Object base;
 430         final long fieldOffset;
 431 #if[Object]
 432         final Class<?> fieldType;
 433         final boolean nullRestricted;
 434 #end[Object]
 435 
 436         FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted}) {
 437             this(declaringClass, base, fieldOffset{#if[Object]?, fieldType, nullRestricted}, FieldStaticReadOnly.FORM, false);
 438         }
 439 
 440         protected FieldStaticReadOnly(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted},
 441                                       VarForm form, boolean exact) {
 442             super(form, exact);
 443             this.declaringClass = declaringClass;
 444             this.base = base;
 445             this.fieldOffset = fieldOffset;
 446 #if[Object]
 447             this.fieldType = fieldType;
 448             this.nullRestricted = nullRestricted;
 449 #end[Object]
 450         }
 451 
 452         @Override
 453         public FieldStaticReadOnly withInvokeExactBehavior() {
 454             return hasInvokeExactBehavior()
 455                 ? this
 456                 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType, nullRestricted}, vform, true);
 457         }
 458 
 459         @Override
 460         public FieldStaticReadOnly withInvokeBehavior() {
 461             return !hasInvokeExactBehavior()
 462                 ? this
 463                 : new FieldStaticReadOnly(declaringClass, base, fieldOffset{#if[Object]?, fieldType, nullRestricted}, vform, false);
 464         }
 465 
 466         @Override
 467         public Optional<VarHandleDesc> describeConstable() {
 468             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
 469             if (!fieldTypeRef.isPresent())
 470                 return Optional.empty();
 471 
 472             // Reflect on this VarHandle to extract the field name
 473             var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
 474                 declaringClass, fieldOffset, {#if[Object]?fieldType:$type$.class});
 475             var declaringTypeRef = declaringClass.describeConstable();
 476             if (!declaringTypeRef.isPresent())
 477                 return Optional.empty();
 478             return Optional.of(VarHandleDesc.ofStaticField(declaringTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
 479         }
 480 
 481         @Override
 482         final MethodType accessModeTypeUncached(AccessType at) {
 483             return at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 484         }
 485 
 486         @ForceInline
 487         static $type$ get(VarHandle ob) {
 488             FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
 489             $type$ value = UNSAFE.get$Type$(handle.base,
 490                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 491 #if[Reference]
 492             if (handle.nullRestricted && value == null) {
 493                 return ValueClass.zeroInstance(handle.fieldType);
 494             }
 495 #end[Reference]
 496             return value;
 497         }
 498 
 499         @ForceInline
 500         static $type$ getVolatile(VarHandle ob) {
 501             FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
 502             $type$ value = UNSAFE.get$Type$Volatile(handle.base,
 503                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 504 #if[Reference]
 505             if (handle.nullRestricted && value == null) {
 506                 return ValueClass.zeroInstance(handle.fieldType);
 507             }
 508 #end[Reference]
 509             return value;
 510         }
 511 
 512         @ForceInline
 513         static $type$ getOpaque(VarHandle ob) {
 514             FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
 515             $type$ value = UNSAFE.get$Type$Opaque(handle.base,
 516                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 517 #if[Reference]
 518             if (handle.nullRestricted && value == null) {
 519                 return ValueClass.zeroInstance(handle.fieldType);
 520             }
 521 #end[Reference]
 522             return value;
 523         }
 524 
 525         @ForceInline
 526         static $type$ getAcquire(VarHandle ob) {
 527             FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
 528             $type$ value = UNSAFE.get$Type$Acquire(handle.base,
 529                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 530 #if[Reference]
 531             if (handle.nullRestricted && value == null) {
 532                 return ValueClass.zeroInstance(handle.fieldType);
 533             }
 534 #end[Reference]
 535             return value;
 536         }
 537 
 538         static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
 539     }
 540 
 541     static final class FieldStaticReadWrite extends FieldStaticReadOnly {
 542 
 543         FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted}) {
 544             this(declaringClass, base, fieldOffset{#if[Object]?, fieldType, nullRestricted}, false);
 545         }
 546 
 547         private FieldStaticReadWrite(Class<?> declaringClass, Object base, long fieldOffset{#if[Object]?, Class<?> fieldType, boolean nullRestricted},
 548                                      boolean exact) {
 549             super(declaringClass, base, fieldOffset{#if[Object]?, fieldType, nullRestricted}, FieldStaticReadWrite.FORM, exact);
 550         }
 551 
 552         @Override
 553         public FieldStaticReadWrite withInvokeExactBehavior() {
 554             return hasInvokeExactBehavior()
 555                 ? this
 556                 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType}{#if[Reference]?, nullRestricted}, true);
 557         }
 558 
 559         @Override
 560         public FieldStaticReadWrite withInvokeBehavior() {
 561             return !hasInvokeExactBehavior()
 562                 ? this
 563                 : new FieldStaticReadWrite(declaringClass, base, fieldOffset{#if[Object]?, fieldType}{#if[Reference]?, nullRestricted}, false);
 564         }
 565 
 566 #if[Object]
 567         static Object checkCast(FieldStaticReadWrite handle, $type$ value) {
 568             return handle.fieldType.cast(value);
 569         }
 570 #end[Object]
 571 
 572         @ForceInline
 573         static void set(VarHandle ob, $type$ value) {
 574             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 575             UNSAFE.put$Type$(handle.base,
 576                              handle.fieldOffset{#if[Value]?, handle.fieldType},
 577                              {#if[Object]?checkCast(handle, value):value});
 578         }
 579 
 580         @ForceInline
 581         static void setVolatile(VarHandle ob, $type$ value) {
 582             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 583             UNSAFE.put$Type$Volatile(handle.base,
 584                                      handle.fieldOffset{#if[Value]?, handle.fieldType},
 585                                      {#if[Object]?checkCast(handle, value):value});
 586         }
 587 
 588         @ForceInline
 589         static void setOpaque(VarHandle ob, $type$ value) {
 590             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 591             UNSAFE.put$Type$Opaque(handle.base,
 592                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
 593                                    {#if[Object]?checkCast(handle, value):value});
 594         }
 595 
 596         @ForceInline
 597         static void setRelease(VarHandle ob, $type$ value) {
 598             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 599             UNSAFE.put$Type$Release(handle.base,
 600                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
 601                                     {#if[Object]?checkCast(handle, value):value});
 602         }
 603 #if[CAS]
 604 
 605         @ForceInline
 606         static boolean compareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 607             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 608             return UNSAFE.compareAndSet$Type$(handle.base,
 609                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 610                                                {#if[Object]?checkCast(handle, expected):expected},
 611                                                {#if[Object]?checkCast(handle, value):value});
 612         }
 613 
 614 
 615         @ForceInline
 616         static $type$ compareAndExchange(VarHandle ob, $type$ expected, $type$ value) {
 617             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 618             return UNSAFE.compareAndExchange$Type$(handle.base,
 619                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 620                                                {#if[Object]?checkCast(handle, expected):expected},
 621                                                {#if[Object]?checkCast(handle, value):value});
 622         }
 623 
 624         @ForceInline
 625         static $type$ compareAndExchangeAcquire(VarHandle ob, $type$ expected, $type$ value) {
 626             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 627             return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
 628                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 629                                                {#if[Object]?checkCast(handle, expected):expected},
 630                                                {#if[Object]?checkCast(handle, value):value});
 631         }
 632 
 633         @ForceInline
 634         static $type$ compareAndExchangeRelease(VarHandle ob, $type$ expected, $type$ value) {
 635             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 636             return UNSAFE.compareAndExchange$Type$Release(handle.base,
 637                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 638                                                {#if[Object]?checkCast(handle, expected):expected},
 639                                                {#if[Object]?checkCast(handle, value):value});
 640         }
 641 
 642         @ForceInline
 643         static boolean weakCompareAndSetPlain(VarHandle ob, $type$ expected, $type$ value) {
 644             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 645             return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
 646                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 647                                                {#if[Object]?checkCast(handle, expected):expected},
 648                                                {#if[Object]?checkCast(handle, value):value});
 649         }
 650 
 651         @ForceInline
 652         static boolean weakCompareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 653             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 654             return UNSAFE.weakCompareAndSet$Type$(handle.base,
 655                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 656                                                {#if[Object]?checkCast(handle, expected):expected},
 657                                                {#if[Object]?checkCast(handle, value):value});
 658         }
 659 
 660         @ForceInline
 661         static boolean weakCompareAndSetAcquire(VarHandle ob, $type$ expected, $type$ value) {
 662             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 663             return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
 664                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 665                                                {#if[Object]?checkCast(handle, expected):expected},
 666                                                {#if[Object]?checkCast(handle, value):value});
 667         }
 668 
 669         @ForceInline
 670         static boolean weakCompareAndSetRelease(VarHandle ob, $type$ expected, $type$ value) {
 671             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 672             return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
 673                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 674                                                {#if[Object]?checkCast(handle, expected):expected},
 675                                                {#if[Object]?checkCast(handle, value):value});
 676         }
 677 
 678         @ForceInline
 679         static $type$ getAndSet(VarHandle ob, $type$ value) {
 680             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 681             return UNSAFE.getAndSet$Type$(handle.base,
 682                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 683                                           {#if[Object]?checkCast(handle, value):value});
 684         }
 685 
 686         @ForceInline
 687         static $type$ getAndSetAcquire(VarHandle ob, $type$ value) {
 688             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 689             return UNSAFE.getAndSet$Type$Acquire(handle.base,
 690                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 691                                           {#if[Object]?checkCast(handle, value):value});
 692         }
 693 
 694         @ForceInline
 695         static $type$ getAndSetRelease(VarHandle ob, $type$ value) {
 696             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 697             return UNSAFE.getAndSet$Type$Release(handle.base,
 698                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 699                                           {#if[Object]?checkCast(handle, value):value});
 700         }
 701 #end[CAS]
 702 #if[AtomicAdd]
 703 
 704         @ForceInline
 705         static $type$ getAndAdd(VarHandle ob, $type$ value) {
 706             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 707             return UNSAFE.getAndAdd$Type$(handle.base,
 708                                        handle.fieldOffset,
 709                                        value);
 710         }
 711 
 712         @ForceInline
 713         static $type$ getAndAddAcquire(VarHandle ob, $type$ value) {
 714             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 715             return UNSAFE.getAndAdd$Type$Acquire(handle.base,
 716                                        handle.fieldOffset,
 717                                        value);
 718         }
 719 
 720         @ForceInline
 721         static $type$ getAndAddRelease(VarHandle ob, $type$ value) {
 722             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 723             return UNSAFE.getAndAdd$Type$Release(handle.base,
 724                                        handle.fieldOffset,
 725                                        value);
 726         }
 727 #end[AtomicAdd]
 728 #if[Bitwise]
 729 
 730         @ForceInline
 731         static $type$ getAndBitwiseOr(VarHandle ob, $type$ value) {
 732             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 733             return UNSAFE.getAndBitwiseOr$Type$(handle.base,
 734                                        handle.fieldOffset,
 735                                        value);
 736         }
 737 
 738         @ForceInline
 739         static $type$ getAndBitwiseOrRelease(VarHandle ob, $type$ value) {
 740             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 741             return UNSAFE.getAndBitwiseOr$Type$Release(handle.base,
 742                                        handle.fieldOffset,
 743                                        value);
 744         }
 745 
 746         @ForceInline
 747         static $type$ getAndBitwiseOrAcquire(VarHandle ob, $type$ value) {
 748             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 749             return UNSAFE.getAndBitwiseOr$Type$Acquire(handle.base,
 750                                        handle.fieldOffset,
 751                                        value);
 752         }
 753 
 754         @ForceInline
 755         static $type$ getAndBitwiseAnd(VarHandle ob, $type$ value) {
 756             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 757             return UNSAFE.getAndBitwiseAnd$Type$(handle.base,
 758                                        handle.fieldOffset,
 759                                        value);
 760         }
 761 
 762         @ForceInline
 763         static $type$ getAndBitwiseAndRelease(VarHandle ob, $type$ value) {
 764             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 765             return UNSAFE.getAndBitwiseAnd$Type$Release(handle.base,
 766                                        handle.fieldOffset,
 767                                        value);
 768         }
 769 
 770         @ForceInline
 771         static $type$ getAndBitwiseAndAcquire(VarHandle ob, $type$ value) {
 772             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 773             return UNSAFE.getAndBitwiseAnd$Type$Acquire(handle.base,
 774                                        handle.fieldOffset,
 775                                        value);
 776         }
 777 
 778         @ForceInline
 779         static $type$ getAndBitwiseXor(VarHandle ob, $type$ value) {
 780             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 781             return UNSAFE.getAndBitwiseXor$Type$(handle.base,
 782                                        handle.fieldOffset,
 783                                        value);
 784         }
 785 
 786         @ForceInline
 787         static $type$ getAndBitwiseXorRelease(VarHandle ob, $type$ value) {
 788             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 789             return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
 790                                        handle.fieldOffset,
 791                                        value);
 792         }
 793 
 794         @ForceInline
 795         static $type$ getAndBitwiseXorAcquire(VarHandle ob, $type$ value) {
 796             FieldStaticReadWrite handle = (FieldStaticReadWrite) ob.target();
 797             return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
 798                                        handle.fieldOffset,
 799                                        value);
 800         }
 801 #end[Bitwise]
 802 
 803         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 804     }
 805 
 806 #if[Reference]
 807     static VarHandle makeVarHandleValuesArray(Class<?> arrayClass) {
 808         Class<?> componentType = arrayClass.getComponentType();
 809         assert UNSAFE.isFlattenedArray(arrayClass);
 810         // should cache these VarHandle for performance
 811         return VarHandles.makeArrayElementHandle(arrayClass);
 812     }
 813 #end[Reference]
 814 
 815     static final class Array extends VarHandle {
 816         final int abase;
 817         final int ashift;
 818 #if[Object]
 819         final Class<{#if[Object]??:$type$[]}> arrayType;
 820         final Class<?> componentType;
 821 #end[Object]
 822 
 823         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 824             this(abase, ashift{#if[Object]?, arrayType}, false);
 825         }
 826 
 827         private Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}, boolean exact) {
 828             super(Array.FORM, exact);
 829             this.abase = abase;
 830             this.ashift = ashift;
 831 #if[Object]
 832             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 833             this.componentType = arrayType.getComponentType();
 834 #end[Object]
 835         }
 836 
 837         @Override
 838         public Array withInvokeExactBehavior() {
 839             return hasInvokeExactBehavior()
 840                 ? this
 841                 : new Array(abase, ashift{#if[Object]?, arrayType}, true);
 842         }
 843 
 844         @Override
 845         public Array withInvokeBehavior() {
 846             return !hasInvokeExactBehavior()
 847                 ? this
 848                 : new Array(abase, ashift{#if[Object]?, arrayType}, false);
 849         }
 850 
 851         @Override
 852         public Optional<VarHandleDesc> describeConstable() {
 853             var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
 854             if (!arrayTypeRef.isPresent())
 855                 return Optional.empty();
 856 
 857             return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
 858         }
 859 
 860         @Override
 861         final MethodType accessModeTypeUncached(AccessType at) {
 862             return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 863         }
 864 
 865 #if[Object]
 866         @ForceInline
 867         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
 868             if (handle.arrayType == oarray.getClass()) {
 869                 // Fast path: static array type same as argument array type
 870                 return handle.componentType.cast(value);
 871             } else {
 872                 // Slow path: check value against argument array component type
 873                 return reflectiveTypeCheck(oarray, value);
 874             }
 875         }
 876 
 877         @ForceInline
 878         static Object reflectiveTypeCheck(Object[] oarray, Object value) {
 879             try {
 880                 return oarray.getClass().getComponentType().cast(value);
 881             } catch (ClassCastException e) {
 882                 throw new ArrayStoreException();
 883             }
 884         }
 885 #end[Object]
 886 
 887         @ForceInline
 888         static $type$ get(VarHandle ob, Object oarray, int index) {
 889             Array handle = (Array)ob;
 890 #if[Object]
 891             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 892 #else[Object]
 893             $type$[] array = ($type$[]) oarray;
 894 #end[Object]
 895             return array[index];
 896         }
 897 
 898         @ForceInline
 899         static void set(VarHandle ob, Object oarray, int index, $type$ value) {
 900             Array handle = (Array)ob;
 901 #if[Object]
 902             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 903 #else[Object]
 904             $type$[] array = ($type$[]) oarray;
 905 #end[Object]
 906 #if[Reference]
 907             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 908                 // for flattened array, delegate to VarHandle of the inline type array
 909                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 910                 vh.set(oarray, index, reflectiveTypeCheck(array, value));
 911                 return;
 912             }
 913 #end[Reference]
 914             array[index] = {#if[Object]?runtimeTypeCheck(handle, array, value):value};
 915         }
 916 
 917         @ForceInline
 918         static $type$ getVolatile(VarHandle ob, Object oarray, int index) {
 919             Array handle = (Array)ob;
 920 #if[Object]
 921             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 922 #else[Object]
 923             $type$[] array = ($type$[]) oarray;
 924 #end[Object]
 925 #if[Reference]
 926             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 927                 // for flattened array, delegate to VarHandle of the inline type array
 928                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 929                 return vh.getVolatile(oarray, index);
 930             }
 931 #end[Reference]
 932             return UNSAFE.get$Type$Volatile(array,
 933                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
 934         }
 935 
 936         @ForceInline
 937         static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
 938             Array handle = (Array)ob;
 939 #if[Object]
 940             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 941 #else[Object]
 942             $type$[] array = ($type$[]) oarray;
 943 #end[Object]
 944 #if[Reference]
 945             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 946                 // for flattened array, delegate to VarHandle of the inline type array
 947                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 948                 vh.setVolatile(oarray, index, reflectiveTypeCheck(array, value));
 949                 return;
 950             }
 951 #end[Reference]
 952             UNSAFE.put$Type$Volatile(array,
 953                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
 954                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 955         }
 956 
 957         @ForceInline
 958         static $type$ getOpaque(VarHandle ob, Object oarray, int index) {
 959             Array handle = (Array)ob;
 960 #if[Object]
 961             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 962 #else[Object]
 963             $type$[] array = ($type$[]) oarray;
 964 #end[Object]
 965 #if[Reference]
 966             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 967                 // for flattened array, delegate to VarHandle of the inline type array
 968                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 969                 return vh.getOpaque(oarray, index);
 970             }
 971 #end[Reference]
 972             return UNSAFE.get$Type$Opaque(array,
 973                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
 974         }
 975 
 976         @ForceInline
 977         static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
 978             Array handle = (Array)ob;
 979 #if[Object]
 980             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 981 #else[Object]
 982             $type$[] array = ($type$[]) oarray;
 983 #end[Object]
 984 #if[Reference]
 985             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 986                 // for flattened array, delegate to VarHandle of the inline type array
 987                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 988                 vh.setOpaque(oarray, index, reflectiveTypeCheck(array, value));
 989                 return;
 990             }
 991 #end[Reference]
 992             UNSAFE.put$Type$Opaque(array,
 993                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
 994                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 995         }
 996 
 997         @ForceInline
 998         static $type$ getAcquire(VarHandle ob, Object oarray, int index) {
 999             Array handle = (Array)ob;
1000 #if[Object]
1001             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1002 #else[Object]
1003             $type$[] array = ($type$[]) oarray;
1004 #end[Object]
1005 #if[Reference]
1006             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1007                 // for flattened array, delegate to VarHandle of the inline type array
1008                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1009                 return vh.getAcquire(oarray, index);
1010             }
1011 #end[Reference]
1012             return UNSAFE.get$Type$Acquire(array,
1013                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
1014         }
1015 
1016         @ForceInline
1017         static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1018             Array handle = (Array)ob;
1019 #if[Object]
1020             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1021 #else[Object]
1022             $type$[] array = ($type$[]) oarray;
1023 #end[Object]
1024 #if[Reference]
1025             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1026                 // for flattened array, delegate to VarHandle of the inline type array
1027                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1028                 vh.setRelease(oarray, index, reflectiveTypeCheck(array, value));
1029                 return;
1030             }
1031 #end[Reference]
1032             UNSAFE.put$Type$Release(array,
1033                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1034                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1035         }
1036 #if[CAS]
1037 
1038         @ForceInline
1039         static boolean compareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1040             Array handle = (Array)ob;
1041 #if[Object]
1042             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1043 #else[Object]
1044             $type$[] array = ($type$[]) oarray;
1045 #end[Object]
1046 #if[Reference]
1047             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1048                 // for flattened array, delegate to VarHandle of the inline type array
1049                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1050                 return vh.compareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
1051             }
1052 #end[Reference]
1053             return UNSAFE.compareAndSet$Type$(array,
1054                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1055                     {#if[Object]?handle.componentType.cast(expected):expected},
1056                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1057         }
1058 
1059         @ForceInline
1060         static $type$ compareAndExchange(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1061             Array handle = (Array)ob;
1062 #if[Object]
1063             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1064 #else[Object]
1065             $type$[] array = ($type$[]) oarray;
1066 #end[Object]
1067 #if[Reference]
1068             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1069                 // for flattened array, delegate to VarHandle of the inline type array
1070                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1071                 return vh.compareAndExchange(oarray, index, expected, reflectiveTypeCheck(array, value));
1072             }
1073 #end[Reference]
1074             return UNSAFE.compareAndExchange$Type$(array,
1075                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1076                     {#if[Object]?handle.componentType.cast(expected):expected},
1077                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1078         }
1079 
1080         @ForceInline
1081         static $type$ compareAndExchangeAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1082             Array handle = (Array)ob;
1083 #if[Object]
1084             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1085 #else[Object]
1086             $type$[] array = ($type$[]) oarray;
1087 #end[Object]
1088 #if[Reference]
1089             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1090                 // for flattened array, delegate to VarHandle of the inline type array
1091                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1092                 return vh.compareAndExchangeAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
1093             }
1094 #end[Reference]
1095             return UNSAFE.compareAndExchange$Type$Acquire(array,
1096                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1097                     {#if[Object]?handle.componentType.cast(expected):expected},
1098                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1099         }
1100 
1101         @ForceInline
1102         static $type$ compareAndExchangeRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1103             Array handle = (Array)ob;
1104 #if[Object]
1105             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1106 #else[Object]
1107             $type$[] array = ($type$[]) oarray;
1108 #end[Object]
1109 #if[Reference]
1110             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1111                 // for flattened array, delegate to VarHandle of the inline type array
1112                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1113                 return vh.compareAndExchangeRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
1114             }
1115 #end[Reference]
1116             return UNSAFE.compareAndExchange$Type$Release(array,
1117                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1118                     {#if[Object]?handle.componentType.cast(expected):expected},
1119                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1120         }
1121 
1122         @ForceInline
1123         static boolean weakCompareAndSetPlain(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1124             Array handle = (Array)ob;
1125 #if[Object]
1126             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1127 #else[Object]
1128             $type$[] array = ($type$[]) oarray;
1129 #end[Object]
1130 #if[Reference]
1131             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1132                 // for flattened array, delegate to VarHandle of the inline type array
1133                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1134                 return vh.weakCompareAndSetPlain(oarray, index, expected, reflectiveTypeCheck(array, value));
1135             }
1136 #end[Reference]
1137             return UNSAFE.weakCompareAndSet$Type$Plain(array,
1138                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1139                     {#if[Object]?handle.componentType.cast(expected):expected},
1140                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1141         }
1142 
1143         @ForceInline
1144         static boolean weakCompareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1145             Array handle = (Array)ob;
1146 #if[Object]
1147             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1148 #else[Object]
1149             $type$[] array = ($type$[]) oarray;
1150 #end[Object]
1151 #if[Reference]
1152             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1153                 // for flattened array, delegate to VarHandle of the inline type array
1154                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1155                 return vh.weakCompareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
1156             }
1157 #end[Reference]
1158             return UNSAFE.weakCompareAndSet$Type$(array,
1159                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1160                     {#if[Object]?handle.componentType.cast(expected):expected},
1161                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1162         }
1163 
1164         @ForceInline
1165         static boolean weakCompareAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1166             Array handle = (Array)ob;
1167 #if[Object]
1168             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1169 #else[Object]
1170             $type$[] array = ($type$[]) oarray;
1171 #end[Object]
1172 #if[Reference]
1173             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1174                 // for flattened array, delegate to VarHandle of the inline type array
1175                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1176                 return vh.weakCompareAndSetAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
1177             }
1178 #end[Reference]
1179             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
1180                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1181                     {#if[Object]?handle.componentType.cast(expected):expected},
1182                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1183         }
1184 
1185         @ForceInline
1186         static boolean weakCompareAndSetRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1187             Array handle = (Array)ob;
1188 #if[Object]
1189             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1190 #else[Object]
1191             $type$[] array = ($type$[]) oarray;
1192 #end[Object]
1193 #if[Reference]
1194             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1195                 // for flattened array, delegate to VarHandle of the inline type array
1196                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1197                 return vh.weakCompareAndSetRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
1198             }
1199 #end[Reference]
1200             return UNSAFE.weakCompareAndSet$Type$Release(array,
1201                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1202                     {#if[Object]?handle.componentType.cast(expected):expected},
1203                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1204         }
1205 
1206         @ForceInline
1207         static $type$ getAndSet(VarHandle ob, Object oarray, int index, $type$ value) {
1208             Array handle = (Array)ob;
1209 #if[Object]
1210             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1211 #else[Object]
1212             $type$[] array = ($type$[]) oarray;
1213 #end[Object]
1214 #if[Reference]
1215             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1216                 // for flattened array, delegate to VarHandle of the inline type array
1217                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1218                 return vh.getAndSet(oarray, index, reflectiveTypeCheck(array, value));
1219             }
1220 #end[Reference]
1221             return UNSAFE.getAndSet$Type$(array,
1222                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1223                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1224         }
1225 
1226         @ForceInline
1227         static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1228             Array handle = (Array)ob;
1229 #if[Object]
1230             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1231 #else[Object]
1232             $type$[] array = ($type$[]) oarray;
1233 #end[Object]
1234 #if[Reference]
1235             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1236                 // for flattened array, delegate to VarHandle of the inline type array
1237                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1238                 return vh.getAndSetAcquire(oarray, index, reflectiveTypeCheck(array, value));
1239             }
1240 #end[Reference]
1241             return UNSAFE.getAndSet$Type$Acquire(array,
1242                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1243                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1244         }
1245 
1246         @ForceInline
1247         static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1248             Array handle = (Array)ob;
1249 #if[Object]
1250             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1251 #else[Object]
1252             $type$[] array = ($type$[]) oarray;
1253 #end[Object]
1254 #if[Reference]
1255             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1256                 // for flattened array, delegate to VarHandle of the inline type array
1257                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1258                 return vh.getAndSetRelease(oarray, index, reflectiveTypeCheck(array, value));
1259             }
1260 #end[Reference]
1261             return UNSAFE.getAndSet$Type$Release(array,
1262                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1263                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1264         }
1265 #end[CAS]
1266 #if[AtomicAdd]
1267 
1268         @ForceInline
1269         static $type$ getAndAdd(VarHandle ob, Object oarray, int index, $type$ value) {
1270             Array handle = (Array)ob;
1271             $type$[] array = ($type$[]) oarray;
1272             return UNSAFE.getAndAdd$Type$(array,
1273                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1274                     value);
1275         }
1276 
1277         @ForceInline
1278         static $type$ getAndAddAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1279             Array handle = (Array)ob;
1280             $type$[] array = ($type$[]) oarray;
1281             return UNSAFE.getAndAdd$Type$Acquire(array,
1282                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1283                     value);
1284         }
1285 
1286         @ForceInline
1287         static $type$ getAndAddRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1288             Array handle = (Array)ob;
1289             $type$[] array = ($type$[]) oarray;
1290             return UNSAFE.getAndAdd$Type$Release(array,
1291                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1292                     value);
1293         }
1294 #end[AtomicAdd]
1295 #if[Bitwise]
1296 
1297         @ForceInline
1298         static $type$ getAndBitwiseOr(VarHandle ob, Object oarray, int index, $type$ value) {
1299             Array handle = (Array)ob;
1300             $type$[] array = ($type$[]) oarray;
1301             return UNSAFE.getAndBitwiseOr$Type$(array,
1302                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1303                                        value);
1304         }
1305 
1306         @ForceInline
1307         static $type$ getAndBitwiseOrRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1308             Array handle = (Array)ob;
1309             $type$[] array = ($type$[]) oarray;
1310             return UNSAFE.getAndBitwiseOr$Type$Release(array,
1311                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1312                                        value);
1313         }
1314 
1315         @ForceInline
1316         static $type$ getAndBitwiseOrAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1317             Array handle = (Array)ob;
1318             $type$[] array = ($type$[]) oarray;
1319             return UNSAFE.getAndBitwiseOr$Type$Acquire(array,
1320                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1321                                        value);
1322         }
1323 
1324         @ForceInline
1325         static $type$ getAndBitwiseAnd(VarHandle ob, Object oarray, int index, $type$ value) {
1326             Array handle = (Array)ob;
1327             $type$[] array = ($type$[]) oarray;
1328             return UNSAFE.getAndBitwiseAnd$Type$(array,
1329                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1330                                        value);
1331         }
1332 
1333         @ForceInline
1334         static $type$ getAndBitwiseAndRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1335             Array handle = (Array)ob;
1336             $type$[] array = ($type$[]) oarray;
1337             return UNSAFE.getAndBitwiseAnd$Type$Release(array,
1338                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1339                                        value);
1340         }
1341 
1342         @ForceInline
1343         static $type$ getAndBitwiseAndAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1344             Array handle = (Array)ob;
1345             $type$[] array = ($type$[]) oarray;
1346             return UNSAFE.getAndBitwiseAnd$Type$Acquire(array,
1347                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1348                                        value);
1349         }
1350 
1351         @ForceInline
1352         static $type$ getAndBitwiseXor(VarHandle ob, Object oarray, int index, $type$ value) {
1353             Array handle = (Array)ob;
1354             $type$[] array = ($type$[]) oarray;
1355             return UNSAFE.getAndBitwiseXor$Type$(array,
1356                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1357                                        value);
1358         }
1359 
1360         @ForceInline
1361         static $type$ getAndBitwiseXorRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1362             Array handle = (Array)ob;
1363             $type$[] array = ($type$[]) oarray;
1364             return UNSAFE.getAndBitwiseXor$Type$Release(array,
1365                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1366                                        value);
1367         }
1368 
1369         @ForceInline
1370         static $type$ getAndBitwiseXorAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1371             Array handle = (Array)ob;
1372             $type$[] array = ($type$[]) oarray;
1373             return UNSAFE.getAndBitwiseXor$Type$Acquire(array,
1374                                        (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1375                                        value);
1376         }
1377 #end[Bitwise]
1378 
1379         static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
1380     }
1381 }