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