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