1 /*
   2  * Copyright (c) 2015, 2016, 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 
  93         FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
  94             super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM);
  95         }
  96 
  97         @ForceInline
  98         static void set(FieldInstanceReadWrite handle, Object holder, $type$ value) {
  99             UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 100                              handle.fieldOffset,
 101                              {#if[Object]?handle.fieldType.cast(value):value});
 102         }
 103 
 104         @ForceInline
 105         static void setVolatile(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 106             UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 107                                      handle.fieldOffset,
 108                                      {#if[Object]?handle.fieldType.cast(value):value});
 109         }
 110 
 111         @ForceInline
 112         static void setOpaque(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 113             UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 114                                    handle.fieldOffset,
 115                                    {#if[Object]?handle.fieldType.cast(value):value});
 116         }
 117 
 118         @ForceInline
 119         static void setRelease(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 120             UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 121                                     handle.fieldOffset,
 122                                     {#if[Object]?handle.fieldType.cast(value):value});
 123         }
 124 #if[CAS]
 125 
 126         @ForceInline
 127         static boolean compareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 128             return UNSAFE.compareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 129                                                handle.fieldOffset,
 130                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 131                                                {#if[Object]?handle.fieldType.cast(value):value});
 132         }
 133 
 134         @ForceInline
 135         static $type$ compareAndExchangeVolatile(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 136             return UNSAFE.compareAndExchange$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 137                                                handle.fieldOffset,
 138                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 139                                                {#if[Object]?handle.fieldType.cast(value):value});
 140         }
 141 
 142         @ForceInline
 143         static $type$ compareAndExchangeAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 144             return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 145                                                handle.fieldOffset,
 146                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 147                                                {#if[Object]?handle.fieldType.cast(value):value});
 148         }
 149 
 150         @ForceInline
 151         static $type$ compareAndExchangeRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 152             return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 153                                                handle.fieldOffset,
 154                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 155                                                {#if[Object]?handle.fieldType.cast(value):value});
 156         }
 157 
 158         @ForceInline
 159         static boolean weakCompareAndSet(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 160             return UNSAFE.weakCompareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 161                                                handle.fieldOffset,
 162                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 163                                                {#if[Object]?handle.fieldType.cast(value):value});
 164         }
 165 
 166         @ForceInline
 167         static boolean weakCompareAndSetVolatile(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 168             // TODO defer to strong form until new Unsafe method is added
 169             return UNSAFE.compareAndSwap$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 170                                                handle.fieldOffset,
 171                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 172                                                {#if[Object]?handle.fieldType.cast(value):value});
 173         }
 174 
 175         @ForceInline
 176         static boolean weakCompareAndSetAcquire(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 177             return UNSAFE.weakCompareAndSwap$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 178                                                handle.fieldOffset,
 179                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 180                                                {#if[Object]?handle.fieldType.cast(value):value});
 181         }
 182 
 183         @ForceInline
 184         static boolean weakCompareAndSetRelease(FieldInstanceReadWrite handle, Object holder, $type$ expected, $type$ value) {
 185             return UNSAFE.weakCompareAndSwap$Type$Release(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$ getAndSet(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 193             return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 194                                           handle.fieldOffset,
 195                                           {#if[Object]?handle.fieldType.cast(value):value});
 196         }
 197 #end[CAS]
 198 #if[AtomicAdd]
 199 
 200         @ForceInline
 201         static $type$ getAndAdd(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 202             return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 203                                        handle.fieldOffset,
 204                                        value);
 205         }
 206 
 207         @ForceInline
 208         static $type$ addAndGet(FieldInstanceReadWrite handle, Object holder, $type$ value) {
 209             return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 210                                        handle.fieldOffset,
 211                                        value) + value;
 212         }
 213 #end[AtomicAdd]
 214 
 215         static final VarForm FORM = new VarForm(FieldInstanceReadWrite.class, Object.class, $type$.class);
 216     }
 217 
 218 
 219     static class FieldStaticReadOnly extends VarHandle {
 220         final Object base;
 221         final long fieldOffset;
 222 #if[Object]
 223         final Class<?> fieldType;
 224 #end[Object]
 225 
 226         FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 227             this(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadOnly.FORM);
 228         }
 229 
 230         protected FieldStaticReadOnly(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
 231                                       VarForm form) {
 232             super(form);
 233             this.base = base;
 234             this.fieldOffset = fieldOffset;
 235 #if[Object]
 236             this.fieldType = fieldType;
 237 #end[Object]
 238         }
 239 
 240         @Override
 241         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 242             return accessMode.at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 243         }
 244 
 245         @ForceInline
 246         static $type$ get(FieldStaticReadOnly handle) {
 247             return UNSAFE.get$Type$(handle.base,
 248                                  handle.fieldOffset);
 249         }
 250 
 251         @ForceInline
 252         static $type$ getVolatile(FieldStaticReadOnly handle) {
 253             return UNSAFE.get$Type$Volatile(handle.base,
 254                                  handle.fieldOffset);
 255         }
 256 
 257         @ForceInline
 258         static $type$ getOpaque(FieldStaticReadOnly handle) {
 259             return UNSAFE.get$Type$Opaque(handle.base,
 260                                  handle.fieldOffset);
 261         }
 262 
 263         @ForceInline
 264         static $type$ getAcquire(FieldStaticReadOnly handle) {
 265             return UNSAFE.get$Type$Acquire(handle.base,
 266                                  handle.fieldOffset);
 267         }
 268 
 269         static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
 270     }
 271 
 272     static final class FieldStaticReadWrite extends FieldStaticReadOnly {
 273 
 274         FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 275             super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM);
 276         }
 277 
 278         @ForceInline
 279         static void set(FieldStaticReadWrite handle, $type$ value) {
 280             UNSAFE.put$Type$(handle.base,
 281                              handle.fieldOffset,
 282                              {#if[Object]?handle.fieldType.cast(value):value});
 283         }
 284 
 285         @ForceInline
 286         static void setVolatile(FieldStaticReadWrite handle, $type$ value) {
 287             UNSAFE.put$Type$Volatile(handle.base,
 288                                      handle.fieldOffset,
 289                                      {#if[Object]?handle.fieldType.cast(value):value});
 290         }
 291 
 292         @ForceInline
 293         static void setOpaque(FieldStaticReadWrite handle, $type$ value) {
 294             UNSAFE.put$Type$Opaque(handle.base,
 295                                    handle.fieldOffset,
 296                                    {#if[Object]?handle.fieldType.cast(value):value});
 297         }
 298 
 299         @ForceInline
 300         static void setRelease(FieldStaticReadWrite handle, $type$ value) {
 301             UNSAFE.put$Type$Release(handle.base,
 302                                     handle.fieldOffset,
 303                                     {#if[Object]?handle.fieldType.cast(value):value});
 304         }
 305 #if[CAS]
 306 
 307         @ForceInline
 308         static boolean compareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 309             return UNSAFE.compareAndSwap$Type$(handle.base,
 310                                                handle.fieldOffset,
 311                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 312                                                {#if[Object]?handle.fieldType.cast(value):value});
 313         }
 314 
 315 
 316         @ForceInline
 317         static $type$ compareAndExchangeVolatile(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 318             return UNSAFE.compareAndExchange$Type$Volatile(handle.base,
 319                                                handle.fieldOffset,
 320                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 321                                                {#if[Object]?handle.fieldType.cast(value):value});
 322         }
 323 
 324         @ForceInline
 325         static $type$ compareAndExchangeAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 326             return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
 327                                                handle.fieldOffset,
 328                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 329                                                {#if[Object]?handle.fieldType.cast(value):value});
 330         }
 331 
 332         @ForceInline
 333         static $type$ compareAndExchangeRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 334             return UNSAFE.compareAndExchange$Type$Release(handle.base,
 335                                                handle.fieldOffset,
 336                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 337                                                {#if[Object]?handle.fieldType.cast(value):value});
 338         }
 339 
 340         @ForceInline
 341         static boolean weakCompareAndSet(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 342             return UNSAFE.weakCompareAndSwap$Type$(handle.base,
 343                                                handle.fieldOffset,
 344                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 345                                                {#if[Object]?handle.fieldType.cast(value):value});
 346         }
 347 
 348         @ForceInline
 349         static boolean weakCompareAndSetVolatile(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 350             // TODO defer to strong form until new Unsafe method is added
 351             return UNSAFE.compareAndSwap$Type$(handle.base,
 352                                                handle.fieldOffset,
 353                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 354                                                {#if[Object]?handle.fieldType.cast(value):value});
 355         }
 356 
 357         @ForceInline
 358         static boolean weakCompareAndSetAcquire(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 359             return UNSAFE.weakCompareAndSwap$Type$Acquire(handle.base,
 360                                                handle.fieldOffset,
 361                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 362                                                {#if[Object]?handle.fieldType.cast(value):value});
 363         }
 364 
 365         @ForceInline
 366         static boolean weakCompareAndSetRelease(FieldStaticReadWrite handle, $type$ expected, $type$ value) {
 367             return UNSAFE.weakCompareAndSwap$Type$Release(handle.base,
 368                                                handle.fieldOffset,
 369                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 370                                                {#if[Object]?handle.fieldType.cast(value):value});
 371         }
 372 
 373         @ForceInline
 374         static $type$ getAndSet(FieldStaticReadWrite handle, $type$ value) {
 375             return UNSAFE.getAndSet$Type$(handle.base,
 376                                           handle.fieldOffset,
 377                                           {#if[Object]?handle.fieldType.cast(value):value});
 378         }
 379 #end[CAS]
 380 #if[AtomicAdd]
 381 
 382         @ForceInline
 383         static $type$ getAndAdd(FieldStaticReadWrite handle, $type$ value) {
 384             return UNSAFE.getAndAdd$Type$(handle.base,
 385                                        handle.fieldOffset,
 386                                        value);
 387         }
 388 
 389         @ForceInline
 390         static $type$ addAndGet(FieldStaticReadWrite handle, $type$ value) {
 391             return UNSAFE.getAndAdd$Type$(handle.base,
 392                                        handle.fieldOffset,
 393                                        value) + value;
 394         }
 395 #end[AtomicAdd]
 396 
 397         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 398     }
 399 
 400 
 401     static final class Array extends VarHandle {
 402         final int abase;
 403         final int ashift;
 404 #if[Object]
 405         final Class<{#if[Object]??:$type$[]}> arrayType;
 406         final Class<?> componentType;
 407 #end[Object]
 408 
 409         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 410             super(Array.FORM);
 411             this.abase = abase;
 412             this.ashift = ashift;
 413 #if[Object]
 414             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 415             this.componentType = arrayType.getComponentType();
 416 #end[Object]
 417         }
 418 
 419         @Override
 420         final MethodType accessModeTypeUncached(AccessMode accessMode) {
 421             return accessMode.at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 422         }
 423 
 424         @ForceInline
 425         static $type$ get(Array handle, Object oarray, int index) {
 426 #if[Object]
 427             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 428 #else[Object]
 429             $type$[] array = ($type$[]) oarray;
 430 #end[Object]
 431             return array[index];
 432         }
 433 
 434         @ForceInline
 435         static void set(Array handle, Object oarray, int index, $type$ value) {
 436 #if[Object]
 437             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 438 #else[Object]
 439             $type$[] array = ($type$[]) oarray;
 440 #end[Object]
 441             array[index] = {#if[Object]?handle.componentType.cast(value):value};
 442         }
 443 
 444         @ForceInline
 445         static $type$ getVolatile(Array handle, Object oarray, int index) {
 446 #if[Object]
 447             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 448 #else[Object]
 449             $type$[] array = ($type$[]) oarray;
 450 #end[Object]
 451             return UNSAFE.get$Type$Volatile(array,
 452                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
 453         }
 454 
 455         @ForceInline
 456         static void setVolatile(Array handle, Object oarray, int index, $type$ value) {
 457 #if[Object]
 458             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 459 #else[Object]
 460             $type$[] array = ($type$[]) oarray;
 461 #end[Object]
 462             UNSAFE.put$Type$Volatile(array,
 463                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 464                     {#if[Object]?handle.componentType.cast(value):value});
 465         }
 466 
 467         @ForceInline
 468         static $type$ getOpaque(Array handle, Object oarray, int index) {
 469 #if[Object]
 470             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 471 #else[Object]
 472             $type$[] array = ($type$[]) oarray;
 473 #end[Object]
 474             return UNSAFE.get$Type$Opaque(array,
 475                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
 476         }
 477 
 478         @ForceInline
 479         static void setOpaque(Array handle, Object oarray, int index, $type$ value) {
 480 #if[Object]
 481             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 482 #else[Object]
 483             $type$[] array = ($type$[]) oarray;
 484 #end[Object]
 485             UNSAFE.put$Type$Opaque(array,
 486                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 487                     {#if[Object]?handle.componentType.cast(value):value});
 488         }
 489 
 490         @ForceInline
 491         static $type$ getAcquire(Array handle, Object oarray, int index) {
 492 #if[Object]
 493             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 494 #else[Object]
 495             $type$[] array = ($type$[]) oarray;
 496 #end[Object]
 497             return UNSAFE.get$Type$Acquire(array,
 498                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase);
 499         }
 500 
 501         @ForceInline
 502         static void setRelease(Array handle, Object oarray, int index, $type$ value) {
 503 #if[Object]
 504             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 505 #else[Object]
 506             $type$[] array = ($type$[]) oarray;
 507 #end[Object]
 508             UNSAFE.put$Type$Release(array,
 509                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 510                     {#if[Object]?handle.componentType.cast(value):value});
 511         }
 512 #if[CAS]
 513 
 514         @ForceInline
 515         static boolean compareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 516 #if[Object]
 517             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 518 #else[Object]
 519             $type$[] array = ($type$[]) oarray;
 520 #end[Object]
 521             return UNSAFE.compareAndSwap$Type$(array,
 522                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 523                     {#if[Object]?handle.componentType.cast(expected):expected},
 524                     {#if[Object]?handle.componentType.cast(value):value});
 525         }
 526 
 527         @ForceInline
 528         static $type$ compareAndExchangeVolatile(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 529 #if[Object]
 530             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 531 #else[Object]
 532             $type$[] array = ($type$[]) oarray;
 533 #end[Object]
 534             return UNSAFE.compareAndExchange$Type$Volatile(array,
 535                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 536                     {#if[Object]?handle.componentType.cast(expected):expected},
 537                     {#if[Object]?handle.componentType.cast(value):value});
 538         }
 539 
 540         @ForceInline
 541         static $type$ compareAndExchangeAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 542 #if[Object]
 543             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 544 #else[Object]
 545             $type$[] array = ($type$[]) oarray;
 546 #end[Object]
 547             return UNSAFE.compareAndExchange$Type$Acquire(array,
 548                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 549                     {#if[Object]?handle.componentType.cast(expected):expected},
 550                     {#if[Object]?handle.componentType.cast(value):value});
 551         }
 552 
 553         @ForceInline
 554         static $type$ compareAndExchangeRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 555 #if[Object]
 556             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 557 #else[Object]
 558             $type$[] array = ($type$[]) oarray;
 559 #end[Object]
 560             return UNSAFE.compareAndExchange$Type$Release(array,
 561                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 562                     {#if[Object]?handle.componentType.cast(expected):expected},
 563                     {#if[Object]?handle.componentType.cast(value):value});
 564         }
 565 
 566         @ForceInline
 567         static boolean weakCompareAndSet(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 568 #if[Object]
 569             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 570 #else[Object]
 571             $type$[] array = ($type$[]) oarray;
 572 #end[Object]
 573             return UNSAFE.weakCompareAndSwap$Type$(array,
 574                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 575                     {#if[Object]?handle.componentType.cast(expected):expected},
 576                     {#if[Object]?handle.componentType.cast(value):value});
 577         }
 578 
 579         @ForceInline
 580         static boolean weakCompareAndSetVolatile(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 581 #if[Object]
 582             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 583 #else[Object]
 584             $type$[] array = ($type$[]) oarray;
 585 #end[Object]
 586             // TODO defer to strong form until new Unsafe method is added
 587             return UNSAFE.compareAndSwap$Type$(array,
 588                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 589                     {#if[Object]?handle.componentType.cast(expected):expected},
 590                     {#if[Object]?handle.componentType.cast(value):value});
 591         }
 592 
 593         @ForceInline
 594         static boolean weakCompareAndSetAcquire(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 595 #if[Object]
 596             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 597 #else[Object]
 598             $type$[] array = ($type$[]) oarray;
 599 #end[Object]
 600             return UNSAFE.weakCompareAndSwap$Type$Acquire(array,
 601                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 602                     {#if[Object]?handle.componentType.cast(expected):expected},
 603                     {#if[Object]?handle.componentType.cast(value):value});
 604         }
 605 
 606         @ForceInline
 607         static boolean weakCompareAndSetRelease(Array handle, Object oarray, int index, $type$ expected, $type$ value) {
 608 #if[Object]
 609             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 610 #else[Object]
 611             $type$[] array = ($type$[]) oarray;
 612 #end[Object]
 613             return UNSAFE.weakCompareAndSwap$Type$Release(array,
 614                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 615                     {#if[Object]?handle.componentType.cast(expected):expected},
 616                     {#if[Object]?handle.componentType.cast(value):value});
 617         }
 618 
 619         @ForceInline
 620         static $type$ getAndSet(Array handle, Object oarray, int index, $type$ value) {
 621 #if[Object]
 622             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 623 #else[Object]
 624             $type$[] array = ($type$[]) oarray;
 625 #end[Object]
 626             return UNSAFE.getAndSet$Type$(array,
 627                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 628                     {#if[Object]?handle.componentType.cast(value):value});
 629         }
 630 #end[CAS]
 631 #if[AtomicAdd]
 632 
 633         @ForceInline
 634         static $type$ getAndAdd(Array handle, Object oarray, int index, $type$ value) {
 635 #if[Object]
 636             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 637 #else[Object]
 638             $type$[] array = ($type$[]) oarray;
 639 #end[Object]
 640             return UNSAFE.getAndAdd$Type$(array,
 641                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 642                     value);
 643         }
 644 
 645         @ForceInline
 646         static $type$ addAndGet(Array handle, Object oarray, int index, $type$ value) {
 647 #if[Object]
 648             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 649 #else[Object]
 650             $type$[] array = ($type$[]) oarray;
 651 #end[Object]
 652             return UNSAFE.getAndAdd$Type$(array,
 653                     (((long) Preconditions.checkIndex(index, array.length, AIOOBE_SUPPLIER)) << handle.ashift) + handle.abase,
 654                     value) + value;
 655         }
 656 #end[AtomicAdd]
 657 
 658         static final VarForm FORM = new VarForm(Array.class, {#if[Object]?Object[].class:$type$[].class}, {#if[Object]?Object.class:$type$.class}, int.class);
 659     }
 660 }