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