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