< prev index next >

src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template

Print this page

  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.invoke;
  26 
  27 import jdk.internal.util.Preconditions;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 
  30 import java.lang.invoke.VarHandle.VarHandleDesc;
  31 import java.util.Objects;
  32 import java.util.Optional;
  33 


  34 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  35 
  36 #warn
  37 
  38 final class VarHandle$Type$s {
  39 
  40     static sealed class FieldInstanceReadOnly extends VarHandle {
  41         final long fieldOffset;
  42         final Class<?> receiverType;
  43 #if[Object]
  44         final Class<?> fieldType;
  45 #end[Object]
  46 
  47         FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
  48             this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM, false);
  49         }
  50 
  51         protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
  52                                         VarForm form, boolean exact) {
  53             super(form, exact);

  77             return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
  78         }
  79 
  80         @Override
  81         public Optional<VarHandleDesc> describeConstable() {
  82             var receiverTypeRef = receiverType.describeConstable();
  83             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
  84             if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
  85                 return Optional.empty();
  86 
  87             // Reflect on this VarHandle to extract the field name
  88             String name = VarHandles.getFieldFromReceiverAndOffset(
  89                 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
  90             return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
  91         }
  92 
  93         @ForceInline
  94         static $type$ get(VarHandle ob, Object holder) {
  95             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
  96             return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
  97                                  handle.fieldOffset);
  98         }
  99 
 100         @ForceInline
 101         static $type$ getVolatile(VarHandle ob, Object holder) {
 102             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 103             return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 104                                  handle.fieldOffset);
 105         }
 106 
 107         @ForceInline
 108         static $type$ getOpaque(VarHandle ob, Object holder) {
 109             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 110             return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 111                                  handle.fieldOffset);
 112         }
 113 
 114         @ForceInline
 115         static $type$ getAcquire(VarHandle ob, Object holder) {
 116             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 117             return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 118                                  handle.fieldOffset);
 119         }
 120 
 121         static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
 122     }
 123 
 124     static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {
 125 
 126         FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 127             this(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
 128         }
 129 
 130         private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
 131                                        boolean exact) {
 132             super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM, exact);
 133         }
 134 
 135         @Override
 136         public FieldInstanceReadWrite withInvokeExactBehavior() {
 137             return hasInvokeExactBehavior()
 138                 ? this
 139                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, true);
 140         }
 141 
 142         @Override
 143         public FieldInstanceReadWrite withInvokeBehavior() {
 144             return !hasInvokeExactBehavior()
 145                 ? this
 146                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
 147         }
 148 









 149         @ForceInline
 150         static void set(VarHandle ob, Object holder, $type$ value) {
 151             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 152             UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 153                              handle.fieldOffset,
 154                              {#if[Object]?handle.fieldType.cast(value):value});
 155         }
 156 
 157         @ForceInline
 158         static void setVolatile(VarHandle ob, Object holder, $type$ value) {
 159             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 160             UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 161                                      handle.fieldOffset,
 162                                      {#if[Object]?handle.fieldType.cast(value):value});
 163         }
 164 
 165         @ForceInline
 166         static void setOpaque(VarHandle ob, Object holder, $type$ value) {
 167             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 168             UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 169                                    handle.fieldOffset,
 170                                    {#if[Object]?handle.fieldType.cast(value):value});
 171         }
 172 
 173         @ForceInline
 174         static void setRelease(VarHandle ob, Object holder, $type$ value) {
 175             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 176             UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 177                                     handle.fieldOffset,
 178                                     {#if[Object]?handle.fieldType.cast(value):value});
 179         }
 180 #if[CAS]
 181 
 182         @ForceInline
 183         static boolean compareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 184             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 185             return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 186                                                handle.fieldOffset,
 187                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 188                                                {#if[Object]?handle.fieldType.cast(value):value});
 189         }
 190 
 191         @ForceInline
 192         static $type$ compareAndExchange(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 193             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 194             return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 195                                                handle.fieldOffset,
 196                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 197                                                {#if[Object]?handle.fieldType.cast(value):value});
 198         }
 199 
 200         @ForceInline
 201         static $type$ compareAndExchangeAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 202             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 203             return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 204                                                handle.fieldOffset,
 205                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 206                                                {#if[Object]?handle.fieldType.cast(value):value});
 207         }
 208 
 209         @ForceInline
 210         static $type$ compareAndExchangeRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 211             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 212             return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 213                                                handle.fieldOffset,
 214                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 215                                                {#if[Object]?handle.fieldType.cast(value):value});
 216         }
 217 
 218         @ForceInline
 219         static boolean weakCompareAndSetPlain(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 220             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 221             return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
 222                                                handle.fieldOffset,
 223                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 224                                                {#if[Object]?handle.fieldType.cast(value):value});
 225         }
 226 
 227         @ForceInline
 228         static boolean weakCompareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 229             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 230             return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 231                                                handle.fieldOffset,
 232                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 233                                                {#if[Object]?handle.fieldType.cast(value):value});
 234         }
 235 
 236         @ForceInline
 237         static boolean weakCompareAndSetAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 238             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 239             return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 240                                                handle.fieldOffset,
 241                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 242                                                {#if[Object]?handle.fieldType.cast(value):value});
 243         }
 244 
 245         @ForceInline
 246         static boolean weakCompareAndSetRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 247             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 248             return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 249                                                handle.fieldOffset,
 250                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 251                                                {#if[Object]?handle.fieldType.cast(value):value});
 252         }
 253 
 254         @ForceInline
 255         static $type$ getAndSet(VarHandle ob, Object holder, $type$ value) {
 256             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 257             return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 258                                           handle.fieldOffset,
 259                                           {#if[Object]?handle.fieldType.cast(value):value});
 260         }
 261 
 262         @ForceInline
 263         static $type$ getAndSetAcquire(VarHandle ob, Object holder, $type$ value) {
 264             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 265             return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 266                                           handle.fieldOffset,
 267                                           {#if[Object]?handle.fieldType.cast(value):value});
 268         }
 269 
 270         @ForceInline
 271         static $type$ getAndSetRelease(VarHandle ob, Object holder, $type$ value) {
 272             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 273             return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 274                                           handle.fieldOffset,
 275                                           {#if[Object]?handle.fieldType.cast(value):value});
 276         }
 277 #end[CAS]
 278 #if[AtomicAdd]
 279 
 280         @ForceInline
 281         static $type$ getAndAdd(VarHandle ob, Object holder, $type$ value) {
 282             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 283             return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 284                                        handle.fieldOffset,
 285                                        value);
 286         }
 287 
 288         @ForceInline
 289         static $type$ getAndAddAcquire(VarHandle ob, Object holder, $type$ value) {
 290             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 291             return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 292                                        handle.fieldOffset,
 293                                        value);
 294         }
 295 

 423                 return Optional.empty();
 424 
 425             // Reflect on this VarHandle to extract the field name
 426             var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
 427                 base, fieldOffset, {#if[Object]?fieldType:$type$.class});
 428             var receiverTypeRef = staticField.getDeclaringClass().describeConstable();
 429             if (!receiverTypeRef.isPresent())
 430                 return Optional.empty();
 431             return Optional.of(VarHandleDesc.ofStaticField(receiverTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
 432         }
 433 
 434         @Override
 435         final MethodType accessModeTypeUncached(AccessType at) {
 436             return at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 437         }
 438 
 439         @ForceInline
 440         static $type$ get(VarHandle ob) {
 441             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 442             return UNSAFE.get$Type$(handle.base,
 443                                  handle.fieldOffset);
 444         }
 445 
 446         @ForceInline
 447         static $type$ getVolatile(VarHandle ob) {
 448             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 449             return UNSAFE.get$Type$Volatile(handle.base,
 450                                  handle.fieldOffset);
 451         }
 452 
 453         @ForceInline
 454         static $type$ getOpaque(VarHandle ob) {
 455             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 456             return UNSAFE.get$Type$Opaque(handle.base,
 457                                  handle.fieldOffset);
 458         }
 459 
 460         @ForceInline
 461         static $type$ getAcquire(VarHandle ob) {
 462             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 463             return UNSAFE.get$Type$Acquire(handle.base,
 464                                  handle.fieldOffset);
 465         }
 466 
 467         static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
 468     }
 469 
 470     static final class FieldStaticReadWrite extends FieldStaticReadOnly {
 471 
 472         FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 473             this(base, fieldOffset{#if[Object]?, fieldType}, false);
 474         }
 475 
 476         private FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
 477                                      boolean exact) {
 478             super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM, exact);
 479         }
 480 
 481         @Override
 482         public FieldStaticReadWrite withInvokeExactBehavior() {
 483             return hasInvokeExactBehavior()
 484                 ? this
 485                 : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, true);
 486         }
 487 
 488         @Override
 489         public FieldStaticReadWrite withInvokeBehavior() {
 490             return !hasInvokeExactBehavior()
 491                 ? this
 492                 : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, false);
 493         }
 494 








 495         @ForceInline
 496         static void set(VarHandle ob, $type$ value) {
 497             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 498             UNSAFE.put$Type$(handle.base,
 499                              handle.fieldOffset,
 500                              {#if[Object]?handle.fieldType.cast(value):value});
 501         }
 502 
 503         @ForceInline
 504         static void setVolatile(VarHandle ob, $type$ value) {
 505             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 506             UNSAFE.put$Type$Volatile(handle.base,
 507                                      handle.fieldOffset,
 508                                      {#if[Object]?handle.fieldType.cast(value):value});
 509         }
 510 
 511         @ForceInline
 512         static void setOpaque(VarHandle ob, $type$ value) {
 513             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 514             UNSAFE.put$Type$Opaque(handle.base,
 515                                    handle.fieldOffset,
 516                                    {#if[Object]?handle.fieldType.cast(value):value});
 517         }
 518 
 519         @ForceInline
 520         static void setRelease(VarHandle ob, $type$ value) {
 521             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 522             UNSAFE.put$Type$Release(handle.base,
 523                                     handle.fieldOffset,
 524                                     {#if[Object]?handle.fieldType.cast(value):value});
 525         }
 526 #if[CAS]
 527 
 528         @ForceInline
 529         static boolean compareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 530             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 531             return UNSAFE.compareAndSet$Type$(handle.base,
 532                                                handle.fieldOffset,
 533                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 534                                                {#if[Object]?handle.fieldType.cast(value):value});
 535         }
 536 
 537 
 538         @ForceInline
 539         static $type$ compareAndExchange(VarHandle ob, $type$ expected, $type$ value) {
 540             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 541             return UNSAFE.compareAndExchange$Type$(handle.base,
 542                                                handle.fieldOffset,
 543                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 544                                                {#if[Object]?handle.fieldType.cast(value):value});
 545         }
 546 
 547         @ForceInline
 548         static $type$ compareAndExchangeAcquire(VarHandle ob, $type$ expected, $type$ value) {
 549             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 550             return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
 551                                                handle.fieldOffset,
 552                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 553                                                {#if[Object]?handle.fieldType.cast(value):value});
 554         }
 555 
 556         @ForceInline
 557         static $type$ compareAndExchangeRelease(VarHandle ob, $type$ expected, $type$ value) {
 558             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 559             return UNSAFE.compareAndExchange$Type$Release(handle.base,
 560                                                handle.fieldOffset,
 561                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 562                                                {#if[Object]?handle.fieldType.cast(value):value});
 563         }
 564 
 565         @ForceInline
 566         static boolean weakCompareAndSetPlain(VarHandle ob, $type$ expected, $type$ value) {
 567             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 568             return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
 569                                                handle.fieldOffset,
 570                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 571                                                {#if[Object]?handle.fieldType.cast(value):value});
 572         }
 573 
 574         @ForceInline
 575         static boolean weakCompareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 576             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 577             return UNSAFE.weakCompareAndSet$Type$(handle.base,
 578                                                handle.fieldOffset,
 579                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 580                                                {#if[Object]?handle.fieldType.cast(value):value});
 581         }
 582 
 583         @ForceInline
 584         static boolean weakCompareAndSetAcquire(VarHandle ob, $type$ expected, $type$ value) {
 585             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 586             return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
 587                                                handle.fieldOffset,
 588                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 589                                                {#if[Object]?handle.fieldType.cast(value):value});
 590         }
 591 
 592         @ForceInline
 593         static boolean weakCompareAndSetRelease(VarHandle ob, $type$ expected, $type$ value) {
 594             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 595             return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
 596                                                handle.fieldOffset,
 597                                                {#if[Object]?handle.fieldType.cast(expected):expected},
 598                                                {#if[Object]?handle.fieldType.cast(value):value});
 599         }
 600 
 601         @ForceInline
 602         static $type$ getAndSet(VarHandle ob, $type$ value) {
 603             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 604             return UNSAFE.getAndSet$Type$(handle.base,
 605                                           handle.fieldOffset,
 606                                           {#if[Object]?handle.fieldType.cast(value):value});
 607         }
 608 
 609         @ForceInline
 610         static $type$ getAndSetAcquire(VarHandle ob, $type$ value) {
 611             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 612             return UNSAFE.getAndSet$Type$Acquire(handle.base,
 613                                           handle.fieldOffset,
 614                                           {#if[Object]?handle.fieldType.cast(value):value});
 615         }
 616 
 617         @ForceInline
 618         static $type$ getAndSetRelease(VarHandle ob, $type$ value) {
 619             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 620             return UNSAFE.getAndSet$Type$Release(handle.base,
 621                                           handle.fieldOffset,
 622                                           {#if[Object]?handle.fieldType.cast(value):value});
 623         }
 624 #end[CAS]
 625 #if[AtomicAdd]
 626 
 627         @ForceInline
 628         static $type$ getAndAdd(VarHandle ob, $type$ value) {
 629             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 630             return UNSAFE.getAndAdd$Type$(handle.base,
 631                                        handle.fieldOffset,
 632                                        value);
 633         }
 634 
 635         @ForceInline
 636         static $type$ getAndAddAcquire(VarHandle ob, $type$ value) {
 637             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 638             return UNSAFE.getAndAdd$Type$Acquire(handle.base,
 639                                        handle.fieldOffset,
 640                                        value);
 641         }
 642 

 709         @ForceInline
 710         static $type$ getAndBitwiseXorRelease(VarHandle ob, $type$ value) {
 711             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 712             return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
 713                                        handle.fieldOffset,
 714                                        value);
 715         }
 716 
 717         @ForceInline
 718         static $type$ getAndBitwiseXorAcquire(VarHandle ob, $type$ value) {
 719             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 720             return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
 721                                        handle.fieldOffset,
 722                                        value);
 723         }
 724 #end[Bitwise]
 725 
 726         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 727     }
 728 








 729 
 730     static final class Array extends VarHandle {
 731         final int abase;
 732         final int ashift;
 733 #if[Object]
 734         final Class<{#if[Object]??:$type$[]}> arrayType;
 735         final Class<?> componentType;
 736 #end[Object]
 737 
 738         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 739             this(abase, ashift{#if[Object]?, arrayType}, false);
 740         }
 741 
 742         private Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}, boolean exact) {
 743             super(Array.FORM, exact);
 744             this.abase = abase;
 745             this.ashift = ashift;
 746 #if[Object]
 747             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 748             this.componentType = arrayType.getComponentType();

 763                 : new Array(abase, ashift{#if[Object]?, arrayType}, false);
 764         }
 765 
 766         @Override
 767         public Optional<VarHandleDesc> describeConstable() {
 768             var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
 769             if (!arrayTypeRef.isPresent())
 770                 return Optional.empty();
 771 
 772             return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
 773         }
 774 
 775         @Override
 776         final MethodType accessModeTypeUncached(AccessType at) {
 777             return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 778         }
 779 
 780 #if[Object]
 781         @ForceInline
 782         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {



 783             if (handle.arrayType == oarray.getClass()) {
 784                 // Fast path: static array type same as argument array type
 785                 return handle.componentType.cast(value);
 786             } else {
 787                 // Slow path: check value against argument array component type
 788                 return reflectiveTypeCheck(oarray, value);
 789             }
 790         }
 791 
 792         @ForceInline
 793         static Object reflectiveTypeCheck(Object[] oarray, Object value) {
 794             try {
 795                 return oarray.getClass().getComponentType().cast(value);
 796             } catch (ClassCastException e) {
 797                 throw new ArrayStoreException();
 798             }
 799         }
 800 #end[Object]
 801 
 802         @ForceInline
 803         static $type$ get(VarHandle ob, Object oarray, int index) {
 804             Array handle = (Array)ob;
 805 #if[Object]
 806             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 807 #else[Object]
 808             $type$[] array = ($type$[]) oarray;
 809 #end[Object]
 810             return array[index];
 811         }
 812 
 813         @ForceInline
 814         static void set(VarHandle ob, Object oarray, int index, $type$ value) {
 815             Array handle = (Array)ob;
 816 #if[Object]
 817             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 818 #else[Object]
 819             $type$[] array = ($type$[]) oarray;
 820 #end[Object]
 821             array[index] = {#if[Object]?handle.componentType.cast(value):value};








 822         }
 823 
 824         @ForceInline
 825         static $type$ getVolatile(VarHandle ob, Object oarray, int index) {
 826             Array handle = (Array)ob;
 827 #if[Object]
 828             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 829 #else[Object]
 830             $type$[] array = ($type$[]) oarray;
 831 #end[Object]







 832             return UNSAFE.get$Type$Volatile(array,
 833                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
 834         }
 835 
 836         @ForceInline
 837         static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
 838             Array handle = (Array)ob;
 839 #if[Object]
 840             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 841 #else[Object]
 842             $type$[] array = ($type$[]) oarray;
 843 #end[Object]








 844             UNSAFE.put$Type$Volatile(array,
 845                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 846                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 847         }
 848 
 849         @ForceInline
 850         static $type$ getOpaque(VarHandle ob, Object oarray, int index) {
 851             Array handle = (Array)ob;
 852 #if[Object]
 853             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 854 #else[Object]
 855             $type$[] array = ($type$[]) oarray;
 856 #end[Object]







 857             return UNSAFE.get$Type$Opaque(array,
 858                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
 859         }
 860 
 861         @ForceInline
 862         static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
 863             Array handle = (Array)ob;
 864 #if[Object]
 865             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 866 #else[Object]
 867             $type$[] array = ($type$[]) oarray;
 868 #end[Object]








 869             UNSAFE.put$Type$Opaque(array,
 870                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 871                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 872         }
 873 
 874         @ForceInline
 875         static $type$ getAcquire(VarHandle ob, Object oarray, int index) {
 876             Array handle = (Array)ob;
 877 #if[Object]
 878             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 879 #else[Object]
 880             $type$[] array = ($type$[]) oarray;
 881 #end[Object]







 882             return UNSAFE.get$Type$Acquire(array,
 883                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase);
 884         }
 885 
 886         @ForceInline
 887         static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
 888             Array handle = (Array)ob;
 889 #if[Object]
 890             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 891 #else[Object]
 892             $type$[] array = ($type$[]) oarray;
 893 #end[Object]








 894             UNSAFE.put$Type$Release(array,
 895                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 896                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 897         }
 898 #if[CAS]
 899 
 900         @ForceInline
 901         static boolean compareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 902             Array handle = (Array)ob;
 903 #if[Object]
 904             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 905 #else[Object]
 906             $type$[] array = ($type$[]) oarray;
 907 #end[Object]







 908             return UNSAFE.compareAndSet$Type$(array,
 909                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 910                     {#if[Object]?handle.componentType.cast(expected):expected},
 911                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 912         }
 913 
 914         @ForceInline
 915         static $type$ compareAndExchange(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 916             Array handle = (Array)ob;
 917 #if[Object]
 918             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 919 #else[Object]
 920             $type$[] array = ($type$[]) oarray;
 921 #end[Object]







 922             return UNSAFE.compareAndExchange$Type$(array,
 923                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 924                     {#if[Object]?handle.componentType.cast(expected):expected},
 925                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 926         }
 927 
 928         @ForceInline
 929         static $type$ compareAndExchangeAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 930             Array handle = (Array)ob;
 931 #if[Object]
 932             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 933 #else[Object]
 934             $type$[] array = ($type$[]) oarray;
 935 #end[Object]







 936             return UNSAFE.compareAndExchange$Type$Acquire(array,
 937                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 938                     {#if[Object]?handle.componentType.cast(expected):expected},
 939                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 940         }
 941 
 942         @ForceInline
 943         static $type$ compareAndExchangeRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 944             Array handle = (Array)ob;
 945 #if[Object]
 946             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 947 #else[Object]
 948             $type$[] array = ($type$[]) oarray;
 949 #end[Object]







 950             return UNSAFE.compareAndExchange$Type$Release(array,
 951                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 952                     {#if[Object]?handle.componentType.cast(expected):expected},
 953                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 954         }
 955 
 956         @ForceInline
 957         static boolean weakCompareAndSetPlain(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 958             Array handle = (Array)ob;
 959 #if[Object]
 960             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 961 #else[Object]
 962             $type$[] array = ($type$[]) oarray;
 963 #end[Object]







 964             return UNSAFE.weakCompareAndSet$Type$Plain(array,
 965                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 966                     {#if[Object]?handle.componentType.cast(expected):expected},
 967                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 968         }
 969 
 970         @ForceInline
 971         static boolean weakCompareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 972             Array handle = (Array)ob;
 973 #if[Object]
 974             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 975 #else[Object]
 976             $type$[] array = ($type$[]) oarray;
 977 #end[Object]







 978             return UNSAFE.weakCompareAndSet$Type$(array,
 979                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 980                     {#if[Object]?handle.componentType.cast(expected):expected},
 981                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 982         }
 983 
 984         @ForceInline
 985         static boolean weakCompareAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 986             Array handle = (Array)ob;
 987 #if[Object]
 988             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 989 #else[Object]
 990             $type$[] array = ($type$[]) oarray;
 991 #end[Object]







 992             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
 993                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
 994                     {#if[Object]?handle.componentType.cast(expected):expected},
 995                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 996         }
 997 
 998         @ForceInline
 999         static boolean weakCompareAndSetRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1000             Array handle = (Array)ob;
1001 #if[Object]
1002             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1003 #else[Object]
1004             $type$[] array = ($type$[]) oarray;
1005 #end[Object]







1006             return UNSAFE.weakCompareAndSet$Type$Release(array,
1007                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1008                     {#if[Object]?handle.componentType.cast(expected):expected},
1009                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1010         }
1011 
1012         @ForceInline
1013         static $type$ getAndSet(VarHandle ob, Object oarray, int index, $type$ value) {
1014             Array handle = (Array)ob;
1015 #if[Object]
1016             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1017 #else[Object]
1018             $type$[] array = ($type$[]) oarray;
1019 #end[Object]







1020             return UNSAFE.getAndSet$Type$(array,
1021                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1022                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1023         }
1024 
1025         @ForceInline
1026         static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1027             Array handle = (Array)ob;
1028 #if[Object]
1029             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1030 #else[Object]
1031             $type$[] array = ($type$[]) oarray;
1032 #end[Object]







1033             return UNSAFE.getAndSet$Type$Acquire(array,
1034                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1035                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1036         }
1037 
1038         @ForceInline
1039         static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1040             Array handle = (Array)ob;
1041 #if[Object]
1042             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1043 #else[Object]
1044             $type$[] array = ($type$[]) oarray;
1045 #end[Object]







1046             return UNSAFE.getAndSet$Type$Release(array,
1047                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1048                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1049         }
1050 #end[CAS]
1051 #if[AtomicAdd]
1052 
1053         @ForceInline
1054         static $type$ getAndAdd(VarHandle ob, Object oarray, int index, $type$ value) {
1055             Array handle = (Array)ob;
1056             $type$[] array = ($type$[]) oarray;
1057             return UNSAFE.getAndAdd$Type$(array,
1058                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1059                     value);
1060         }
1061 
1062         @ForceInline
1063         static $type$ getAndAddAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1064             Array handle = (Array)ob;
1065             $type$[] array = ($type$[]) oarray;
1066             return UNSAFE.getAndAdd$Type$Acquire(array,
1067                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,

  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.invoke;
  26 
  27 import jdk.internal.util.Preconditions;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 
  30 import java.lang.invoke.VarHandle.VarHandleDesc;
  31 import java.util.Objects;
  32 import java.util.Optional;
  33 
  34 import jdk.internal.value.PrimitiveClass;
  35 
  36 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  37 
  38 #warn
  39 
  40 final class VarHandle$Type$s {
  41 
  42     static sealed class FieldInstanceReadOnly extends VarHandle {
  43         final long fieldOffset;
  44         final Class<?> receiverType;
  45 #if[Object]
  46         final Class<?> fieldType;
  47 #end[Object]
  48 
  49         FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
  50             this(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadOnly.FORM, false);
  51         }
  52 
  53         protected FieldInstanceReadOnly(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
  54                                         VarForm form, boolean exact) {
  55             super(form, exact);

  79             return at.accessModeType(receiverType, {#if[Object]?fieldType:$type$.class});
  80         }
  81 
  82         @Override
  83         public Optional<VarHandleDesc> describeConstable() {
  84             var receiverTypeRef = receiverType.describeConstable();
  85             var fieldTypeRef = {#if[Object]?fieldType:$type$.class}.describeConstable();
  86             if (!receiverTypeRef.isPresent() || !fieldTypeRef.isPresent())
  87                 return Optional.empty();
  88 
  89             // Reflect on this VarHandle to extract the field name
  90             String name = VarHandles.getFieldFromReceiverAndOffset(
  91                 receiverType, fieldOffset, {#if[Object]?fieldType:$type$.class}).getName();
  92             return Optional.of(VarHandleDesc.ofField(receiverTypeRef.get(), name, fieldTypeRef.get()));
  93         }
  94 
  95         @ForceInline
  96         static $type$ get(VarHandle ob, Object holder) {
  97             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
  98             return UNSAFE.get$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
  99                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 100         }
 101 
 102         @ForceInline
 103         static $type$ getVolatile(VarHandle ob, Object holder) {
 104             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 105             return UNSAFE.get$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 106                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 107         }
 108 
 109         @ForceInline
 110         static $type$ getOpaque(VarHandle ob, Object holder) {
 111             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 112             return UNSAFE.get$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 113                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 114         }
 115 
 116         @ForceInline
 117         static $type$ getAcquire(VarHandle ob, Object holder) {
 118             FieldInstanceReadOnly handle = (FieldInstanceReadOnly)ob;
 119             return UNSAFE.get$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 120                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 121         }
 122 
 123         static final VarForm FORM = new VarForm(FieldInstanceReadOnly.class, Object.class, $type$.class);
 124     }
 125 
 126     static final class FieldInstanceReadWrite extends FieldInstanceReadOnly {

 127         FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 128             this(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
 129         }
 130 
 131         private FieldInstanceReadWrite(Class<?> receiverType, long fieldOffset{#if[Object]?, Class<?> fieldType},
 132                                        boolean exact) {
 133             super(receiverType, fieldOffset{#if[Object]?, fieldType}, FieldInstanceReadWrite.FORM, exact);
 134         }
 135 
 136         @Override
 137         public FieldInstanceReadWrite withInvokeExactBehavior() {
 138             return hasInvokeExactBehavior()
 139                 ? this
 140                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, true);
 141         }
 142 
 143         @Override
 144         public FieldInstanceReadWrite withInvokeBehavior() {
 145             return !hasInvokeExactBehavior()
 146                 ? this
 147                 : new FieldInstanceReadWrite(receiverType, fieldOffset{#if[Object]?, fieldType}, false);
 148         }
 149 
 150 #if[Object]
 151         @ForceInline
 152         static Object checkCast(FieldInstanceReadWrite handle, $type$ value) {
 153             if (PrimitiveClass.isPrimitiveValueType(handle.fieldType))
 154                 Objects.requireNonNull(value);
 155             return handle.fieldType.cast(value);
 156         }
 157 #end[Object]
 158 
 159         @ForceInline
 160         static void set(VarHandle ob, Object holder, $type$ value) {
 161             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 162             UNSAFE.put$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 163                              handle.fieldOffset{#if[Value]?, handle.fieldType},
 164                              {#if[Object]?checkCast(handle, value):value});
 165         }
 166 
 167         @ForceInline
 168         static void setVolatile(VarHandle ob, Object holder, $type$ value) {
 169             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 170             UNSAFE.put$Type$Volatile(Objects.requireNonNull(handle.receiverType.cast(holder)),
 171                                      handle.fieldOffset{#if[Value]?, handle.fieldType},
 172                                      {#if[Object]?checkCast(handle, value):value});
 173         }
 174 
 175         @ForceInline
 176         static void setOpaque(VarHandle ob, Object holder, $type$ value) {
 177             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 178             UNSAFE.put$Type$Opaque(Objects.requireNonNull(handle.receiverType.cast(holder)),
 179                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
 180                                    {#if[Object]?checkCast(handle, value):value});
 181         }
 182 
 183         @ForceInline
 184         static void setRelease(VarHandle ob, Object holder, $type$ value) {
 185             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 186             UNSAFE.put$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 187                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
 188                                     {#if[Object]?checkCast(handle, value):value});
 189         }
 190 #if[CAS]
 191 
 192         @ForceInline
 193         static boolean compareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 194             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 195             return UNSAFE.compareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 196                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 197                                                {#if[Object]?checkCast(handle, expected):expected},
 198                                                {#if[Object]?checkCast(handle, value):value});
 199         }
 200 
 201         @ForceInline
 202         static $type$ compareAndExchange(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 203             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 204             return UNSAFE.compareAndExchange$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 205                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 206                                                {#if[Object]?checkCast(handle, expected):expected},
 207                                                {#if[Object]?checkCast(handle, value):value});
 208         }
 209 
 210         @ForceInline
 211         static $type$ compareAndExchangeAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 212             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 213             return UNSAFE.compareAndExchange$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 214                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 215                                                {#if[Object]?checkCast(handle, expected):expected},
 216                                                {#if[Object]?checkCast(handle, value):value});
 217         }
 218 
 219         @ForceInline
 220         static $type$ compareAndExchangeRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 221             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 222             return UNSAFE.compareAndExchange$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 223                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 224                                                {#if[Object]?checkCast(handle, expected):expected},
 225                                                {#if[Object]?checkCast(handle, value):value});
 226         }
 227 
 228         @ForceInline
 229         static boolean weakCompareAndSetPlain(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 230             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 231             return UNSAFE.weakCompareAndSet$Type$Plain(Objects.requireNonNull(handle.receiverType.cast(holder)),
 232                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 233                                                {#if[Object]?checkCast(handle, expected):expected},
 234                                                {#if[Object]?checkCast(handle, value):value});
 235         }
 236 
 237         @ForceInline
 238         static boolean weakCompareAndSet(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 239             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 240             return UNSAFE.weakCompareAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 241                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 242                                                {#if[Object]?checkCast(handle, expected):expected},
 243                                                {#if[Object]?checkCast(handle, value):value});
 244         }
 245 
 246         @ForceInline
 247         static boolean weakCompareAndSetAcquire(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 248             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 249             return UNSAFE.weakCompareAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 250                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 251                                                {#if[Object]?checkCast(handle, expected):expected},
 252                                                {#if[Object]?checkCast(handle, value):value});
 253         }
 254 
 255         @ForceInline
 256         static boolean weakCompareAndSetRelease(VarHandle ob, Object holder, $type$ expected, $type$ value) {
 257             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 258             return UNSAFE.weakCompareAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 259                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 260                                                {#if[Object]?checkCast(handle, expected):expected},
 261                                                {#if[Object]?checkCast(handle, value):value});
 262         }
 263 
 264         @ForceInline
 265         static $type$ getAndSet(VarHandle ob, Object holder, $type$ value) {
 266             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 267             return UNSAFE.getAndSet$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 268                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 269                                           {#if[Object]?checkCast(handle, value):value});
 270         }
 271 
 272         @ForceInline
 273         static $type$ getAndSetAcquire(VarHandle ob, Object holder, $type$ value) {
 274             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 275             return UNSAFE.getAndSet$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 276                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 277                                           {#if[Object]?checkCast(handle, value):value});
 278         }
 279 
 280         @ForceInline
 281         static $type$ getAndSetRelease(VarHandle ob, Object holder, $type$ value) {
 282             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 283             return UNSAFE.getAndSet$Type$Release(Objects.requireNonNull(handle.receiverType.cast(holder)),
 284                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 285                                           {#if[Object]?checkCast(handle, value):value});
 286         }
 287 #end[CAS]
 288 #if[AtomicAdd]
 289 
 290         @ForceInline
 291         static $type$ getAndAdd(VarHandle ob, Object holder, $type$ value) {
 292             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 293             return UNSAFE.getAndAdd$Type$(Objects.requireNonNull(handle.receiverType.cast(holder)),
 294                                        handle.fieldOffset,
 295                                        value);
 296         }
 297 
 298         @ForceInline
 299         static $type$ getAndAddAcquire(VarHandle ob, Object holder, $type$ value) {
 300             FieldInstanceReadWrite handle = (FieldInstanceReadWrite)ob;
 301             return UNSAFE.getAndAdd$Type$Acquire(Objects.requireNonNull(handle.receiverType.cast(holder)),
 302                                        handle.fieldOffset,
 303                                        value);
 304         }
 305 

 433                 return Optional.empty();
 434 
 435             // Reflect on this VarHandle to extract the field name
 436             var staticField = VarHandles.getStaticFieldFromBaseAndOffset(
 437                 base, fieldOffset, {#if[Object]?fieldType:$type$.class});
 438             var receiverTypeRef = staticField.getDeclaringClass().describeConstable();
 439             if (!receiverTypeRef.isPresent())
 440                 return Optional.empty();
 441             return Optional.of(VarHandleDesc.ofStaticField(receiverTypeRef.get(), staticField.getName(), fieldTypeRef.get()));
 442         }
 443 
 444         @Override
 445         final MethodType accessModeTypeUncached(AccessType at) {
 446             return at.accessModeType(null, {#if[Object]?fieldType:$type$.class});
 447         }
 448 
 449         @ForceInline
 450         static $type$ get(VarHandle ob) {
 451             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 452             return UNSAFE.get$Type$(handle.base,
 453                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 454         }
 455 
 456         @ForceInline
 457         static $type$ getVolatile(VarHandle ob) {
 458             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 459             return UNSAFE.get$Type$Volatile(handle.base,
 460                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 461         }
 462 
 463         @ForceInline
 464         static $type$ getOpaque(VarHandle ob) {
 465             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 466             return UNSAFE.get$Type$Opaque(handle.base,
 467                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 468         }
 469 
 470         @ForceInline
 471         static $type$ getAcquire(VarHandle ob) {
 472             FieldStaticReadOnly handle = (FieldStaticReadOnly)ob;
 473             return UNSAFE.get$Type$Acquire(handle.base,
 474                                  handle.fieldOffset{#if[Value]?, handle.fieldType});
 475         }
 476 
 477         static final VarForm FORM = new VarForm(FieldStaticReadOnly.class, null, $type$.class);
 478     }
 479 
 480     static final class FieldStaticReadWrite extends FieldStaticReadOnly {

 481         FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType}) {
 482             this(base, fieldOffset{#if[Object]?, fieldType}, false);
 483         }
 484 
 485         private FieldStaticReadWrite(Object base, long fieldOffset{#if[Object]?, Class<?> fieldType},
 486                                      boolean exact) {
 487             super(base, fieldOffset{#if[Object]?, fieldType}, FieldStaticReadWrite.FORM, exact);
 488         }
 489 
 490         @Override
 491         public FieldStaticReadWrite withInvokeExactBehavior() {
 492             return hasInvokeExactBehavior()
 493                 ? this
 494                 : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, true);
 495         }
 496 
 497         @Override
 498         public FieldStaticReadWrite withInvokeBehavior() {
 499             return !hasInvokeExactBehavior()
 500                 ? this
 501                 : new FieldStaticReadWrite(base, fieldOffset{#if[Object]?, fieldType}, false);
 502         }
 503 
 504 #if[Object]
 505         static Object checkCast(FieldStaticReadWrite handle, $type$ value) {
 506             if (PrimitiveClass.isPrimitiveValueType(handle.fieldType))
 507                 Objects.requireNonNull(value);
 508             return handle.fieldType.cast(value);
 509         }
 510 #end[Object]
 511 
 512         @ForceInline
 513         static void set(VarHandle ob, $type$ value) {
 514             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 515             UNSAFE.put$Type$(handle.base,
 516                              handle.fieldOffset{#if[Value]?, handle.fieldType},
 517                              {#if[Object]?checkCast(handle, value):value});
 518         }
 519 
 520         @ForceInline
 521         static void setVolatile(VarHandle ob, $type$ value) {
 522             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 523             UNSAFE.put$Type$Volatile(handle.base,
 524                                      handle.fieldOffset{#if[Value]?, handle.fieldType},
 525                                      {#if[Object]?checkCast(handle, value):value});
 526         }
 527 
 528         @ForceInline
 529         static void setOpaque(VarHandle ob, $type$ value) {
 530             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 531             UNSAFE.put$Type$Opaque(handle.base,
 532                                    handle.fieldOffset{#if[Value]?, handle.fieldType},
 533                                    {#if[Object]?checkCast(handle, value):value});
 534         }
 535 
 536         @ForceInline
 537         static void setRelease(VarHandle ob, $type$ value) {
 538             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 539             UNSAFE.put$Type$Release(handle.base,
 540                                     handle.fieldOffset{#if[Value]?, handle.fieldType},
 541                                     {#if[Object]?checkCast(handle, value):value});
 542         }
 543 #if[CAS]
 544 
 545         @ForceInline
 546         static boolean compareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 547             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 548             return UNSAFE.compareAndSet$Type$(handle.base,
 549                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 550                                                {#if[Object]?checkCast(handle, expected):expected},
 551                                                {#if[Object]?checkCast(handle, value):value});
 552         }
 553 
 554 
 555         @ForceInline
 556         static $type$ compareAndExchange(VarHandle ob, $type$ expected, $type$ value) {
 557             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 558             return UNSAFE.compareAndExchange$Type$(handle.base,
 559                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 560                                                {#if[Object]?checkCast(handle, expected):expected},
 561                                                {#if[Object]?checkCast(handle, value):value});
 562         }
 563 
 564         @ForceInline
 565         static $type$ compareAndExchangeAcquire(VarHandle ob, $type$ expected, $type$ value) {
 566             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 567             return UNSAFE.compareAndExchange$Type$Acquire(handle.base,
 568                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 569                                                {#if[Object]?checkCast(handle, expected):expected},
 570                                                {#if[Object]?checkCast(handle, value):value});
 571         }
 572 
 573         @ForceInline
 574         static $type$ compareAndExchangeRelease(VarHandle ob, $type$ expected, $type$ value) {
 575             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 576             return UNSAFE.compareAndExchange$Type$Release(handle.base,
 577                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 578                                                {#if[Object]?checkCast(handle, expected):expected},
 579                                                {#if[Object]?checkCast(handle, value):value});
 580         }
 581 
 582         @ForceInline
 583         static boolean weakCompareAndSetPlain(VarHandle ob, $type$ expected, $type$ value) {
 584             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 585             return UNSAFE.weakCompareAndSet$Type$Plain(handle.base,
 586                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 587                                                {#if[Object]?checkCast(handle, expected):expected},
 588                                                {#if[Object]?checkCast(handle, value):value});
 589         }
 590 
 591         @ForceInline
 592         static boolean weakCompareAndSet(VarHandle ob, $type$ expected, $type$ value) {
 593             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 594             return UNSAFE.weakCompareAndSet$Type$(handle.base,
 595                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 596                                                {#if[Object]?checkCast(handle, expected):expected},
 597                                                {#if[Object]?checkCast(handle, value):value});
 598         }
 599 
 600         @ForceInline
 601         static boolean weakCompareAndSetAcquire(VarHandle ob, $type$ expected, $type$ value) {
 602             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 603             return UNSAFE.weakCompareAndSet$Type$Acquire(handle.base,
 604                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 605                                                {#if[Object]?checkCast(handle, expected):expected},
 606                                                {#if[Object]?checkCast(handle, value):value});
 607         }
 608 
 609         @ForceInline
 610         static boolean weakCompareAndSetRelease(VarHandle ob, $type$ expected, $type$ value) {
 611             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 612             return UNSAFE.weakCompareAndSet$Type$Release(handle.base,
 613                                                handle.fieldOffset{#if[Object]?, handle.fieldType},
 614                                                {#if[Object]?checkCast(handle, expected):expected},
 615                                                {#if[Object]?checkCast(handle, value):value});
 616         }
 617 
 618         @ForceInline
 619         static $type$ getAndSet(VarHandle ob, $type$ value) {
 620             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 621             return UNSAFE.getAndSet$Type$(handle.base,
 622                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 623                                           {#if[Object]?checkCast(handle, value):value});
 624         }
 625 
 626         @ForceInline
 627         static $type$ getAndSetAcquire(VarHandle ob, $type$ value) {
 628             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 629             return UNSAFE.getAndSet$Type$Acquire(handle.base,
 630                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 631                                           {#if[Object]?checkCast(handle, value):value});
 632         }
 633 
 634         @ForceInline
 635         static $type$ getAndSetRelease(VarHandle ob, $type$ value) {
 636             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 637             return UNSAFE.getAndSet$Type$Release(handle.base,
 638                                           handle.fieldOffset{#if[Value]?, handle.fieldType},
 639                                           {#if[Object]?checkCast(handle, value):value});
 640         }
 641 #end[CAS]
 642 #if[AtomicAdd]
 643 
 644         @ForceInline
 645         static $type$ getAndAdd(VarHandle ob, $type$ value) {
 646             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 647             return UNSAFE.getAndAdd$Type$(handle.base,
 648                                        handle.fieldOffset,
 649                                        value);
 650         }
 651 
 652         @ForceInline
 653         static $type$ getAndAddAcquire(VarHandle ob, $type$ value) {
 654             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 655             return UNSAFE.getAndAdd$Type$Acquire(handle.base,
 656                                        handle.fieldOffset,
 657                                        value);
 658         }
 659 

 726         @ForceInline
 727         static $type$ getAndBitwiseXorRelease(VarHandle ob, $type$ value) {
 728             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 729             return UNSAFE.getAndBitwiseXor$Type$Release(handle.base,
 730                                        handle.fieldOffset,
 731                                        value);
 732         }
 733 
 734         @ForceInline
 735         static $type$ getAndBitwiseXorAcquire(VarHandle ob, $type$ value) {
 736             FieldStaticReadWrite handle = (FieldStaticReadWrite)ob;
 737             return UNSAFE.getAndBitwiseXor$Type$Acquire(handle.base,
 738                                        handle.fieldOffset,
 739                                        value);
 740         }
 741 #end[Bitwise]
 742 
 743         static final VarForm FORM = new VarForm(FieldStaticReadWrite.class, null, $type$.class);
 744     }
 745 
 746 #if[Reference]
 747     static VarHandle makeVarHandleValuesArray(Class<?> arrayClass) {
 748         Class<?> componentType = arrayClass.getComponentType();
 749         assert PrimitiveClass.isPrimitiveValueType(componentType) && UNSAFE.isFlattenedArray(arrayClass);
 750         // should cache these VarHandle for performance
 751         return VarHandles.makeArrayElementHandle(arrayClass);
 752     }
 753 #end[Reference]
 754 
 755     static final class Array extends VarHandle {
 756         final int abase;
 757         final int ashift;
 758 #if[Object]
 759         final Class<{#if[Object]??:$type$[]}> arrayType;
 760         final Class<?> componentType;
 761 #end[Object]
 762 
 763         Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}) {
 764             this(abase, ashift{#if[Object]?, arrayType}, false);
 765         }
 766 
 767         private Array(int abase, int ashift{#if[Object]?, Class<?> arrayType}, boolean exact) {
 768             super(Array.FORM, exact);
 769             this.abase = abase;
 770             this.ashift = ashift;
 771 #if[Object]
 772             this.arrayType = {#if[Object]?arrayType:$type$[].class};
 773             this.componentType = arrayType.getComponentType();

 788                 : new Array(abase, ashift{#if[Object]?, arrayType}, false);
 789         }
 790 
 791         @Override
 792         public Optional<VarHandleDesc> describeConstable() {
 793             var arrayTypeRef = {#if[Object]?arrayType:$type$[].class}.describeConstable();
 794             if (!arrayTypeRef.isPresent())
 795                 return Optional.empty();
 796 
 797             return Optional.of(VarHandleDesc.ofArray(arrayTypeRef.get()));
 798         }
 799 
 800         @Override
 801         final MethodType accessModeTypeUncached(AccessType at) {
 802             return at.accessModeType({#if[Object]?arrayType:$type$[].class}, {#if[Object]?arrayType.getComponentType():$type$.class}, int.class);
 803         }
 804 
 805 #if[Object]
 806         @ForceInline
 807         static Object runtimeTypeCheck(Array handle, Object[] oarray, Object value) {
 808             if (PrimitiveClass.isPrimitiveValueType(handle.componentType))
 809                  Objects.requireNonNull(value);
 810 
 811             if (handle.arrayType == oarray.getClass()) {
 812                 // Fast path: static array type same as argument array type
 813                 return handle.componentType.cast(value);
 814             } else {
 815                 // Slow path: check value against argument array component type
 816                 return reflectiveTypeCheck(oarray, value);
 817             }
 818         }
 819 
 820         @ForceInline
 821         static Object reflectiveTypeCheck(Object[] oarray, Object value) {
 822             try {
 823                 return oarray.getClass().getComponentType().cast(value);
 824             } catch (ClassCastException e) {
 825                 throw new ArrayStoreException();
 826             }
 827         }
 828 #end[Object]
 829 
 830         @ForceInline
 831         static $type$ get(VarHandle ob, Object oarray, int index) {
 832             Array handle = (Array)ob;
 833 #if[Object]
 834             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 835 #else[Object]
 836             $type$[] array = ($type$[]) oarray;
 837 #end[Object]
 838             return array[index];
 839         }
 840 
 841         @ForceInline
 842         static void set(VarHandle ob, Object oarray, int index, $type$ value) {
 843             Array handle = (Array)ob;
 844 #if[Object]
 845             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 846 #else[Object]
 847             $type$[] array = ($type$[]) oarray;
 848 #end[Object]
 849 #if[Reference]
 850             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 851                 // for flattened array, delegate to VarHandle of the inline type array
 852                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 853                 vh.set(oarray, index, reflectiveTypeCheck(array, value));
 854                 return;
 855             }
 856 #end[Reference]
 857             array[index] = {#if[Object]?runtimeTypeCheck(handle, array, value):value};
 858         }
 859 
 860         @ForceInline
 861         static $type$ getVolatile(VarHandle ob, Object oarray, int index) {
 862             Array handle = (Array)ob;
 863 #if[Object]
 864             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 865 #else[Object]
 866             $type$[] array = ($type$[]) oarray;
 867 #end[Object]
 868 #if[Reference]
 869             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 870                 // for flattened array, delegate to VarHandle of the inline type array
 871                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 872                 return vh.getVolatile(oarray, index);
 873             }
 874 #end[Reference]
 875             return UNSAFE.get$Type$Volatile(array,
 876                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
 877         }
 878 
 879         @ForceInline
 880         static void setVolatile(VarHandle ob, Object oarray, int index, $type$ value) {
 881             Array handle = (Array)ob;
 882 #if[Object]
 883             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 884 #else[Object]
 885             $type$[] array = ($type$[]) oarray;
 886 #end[Object]
 887 #if[Reference]
 888             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 889                 // for flattened array, delegate to VarHandle of the inline type array
 890                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 891                 vh.setVolatile(oarray, index, reflectiveTypeCheck(array, value));
 892                 return;
 893             }
 894 #end[Reference]
 895             UNSAFE.put$Type$Volatile(array,
 896                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
 897                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 898         }
 899 
 900         @ForceInline
 901         static $type$ getOpaque(VarHandle ob, Object oarray, int index) {
 902             Array handle = (Array)ob;
 903 #if[Object]
 904             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 905 #else[Object]
 906             $type$[] array = ($type$[]) oarray;
 907 #end[Object]
 908 #if[Reference]
 909             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 910                 // for flattened array, delegate to VarHandle of the inline type array
 911                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 912                 return vh.getOpaque(oarray, index);
 913             }
 914 #end[Reference]
 915             return UNSAFE.get$Type$Opaque(array,
 916                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
 917         }
 918 
 919         @ForceInline
 920         static void setOpaque(VarHandle ob, Object oarray, int index, $type$ value) {
 921             Array handle = (Array)ob;
 922 #if[Object]
 923             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 924 #else[Object]
 925             $type$[] array = ($type$[]) oarray;
 926 #end[Object]
 927 #if[Reference]
 928             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 929                 // for flattened array, delegate to VarHandle of the inline type array
 930                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 931                 vh.setOpaque(oarray, index, reflectiveTypeCheck(array, value));
 932                 return;
 933             }
 934 #end[Reference]
 935             UNSAFE.put$Type$Opaque(array,
 936                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
 937                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 938         }
 939 
 940         @ForceInline
 941         static $type$ getAcquire(VarHandle ob, Object oarray, int index) {
 942             Array handle = (Array)ob;
 943 #if[Object]
 944             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 945 #else[Object]
 946             $type$[] array = ($type$[]) oarray;
 947 #end[Object]
 948 #if[Reference]
 949             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 950                 // for flattened array, delegate to VarHandle of the inline type array
 951                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 952                 return vh.getAcquire(oarray, index);
 953             }
 954 #end[Reference]
 955             return UNSAFE.get$Type$Acquire(array,
 956                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType});
 957         }
 958 
 959         @ForceInline
 960         static void setRelease(VarHandle ob, Object oarray, int index, $type$ value) {
 961             Array handle = (Array)ob;
 962 #if[Object]
 963             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 964 #else[Object]
 965             $type$[] array = ($type$[]) oarray;
 966 #end[Object]
 967 #if[Reference]
 968             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 969                 // for flattened array, delegate to VarHandle of the inline type array
 970                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 971                 vh.setRelease(oarray, index, reflectiveTypeCheck(array, value));
 972                 return;
 973             }
 974 #end[Reference]
 975             UNSAFE.put$Type$Release(array,
 976                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
 977                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
 978         }
 979 #if[CAS]
 980 
 981         @ForceInline
 982         static boolean compareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
 983             Array handle = (Array)ob;
 984 #if[Object]
 985             Object[] array = (Object[]) handle.arrayType.cast(oarray);
 986 #else[Object]
 987             $type$[] array = ($type$[]) oarray;
 988 #end[Object]
 989 #if[Reference]
 990             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
 991                 // for flattened array, delegate to VarHandle of the inline type array
 992                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
 993                 return vh.compareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
 994             }
 995 #end[Reference]
 996             return UNSAFE.compareAndSet$Type$(array,
 997                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
 998                     {#if[Object]?handle.componentType.cast(expected):expected},
 999                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1000         }
1001 
1002         @ForceInline
1003         static $type$ compareAndExchange(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1004             Array handle = (Array)ob;
1005 #if[Object]
1006             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1007 #else[Object]
1008             $type$[] array = ($type$[]) oarray;
1009 #end[Object]
1010 #if[Reference]
1011             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1012                 // for flattened array, delegate to VarHandle of the inline type array
1013                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1014                 return vh.compareAndExchange(oarray, index, expected, reflectiveTypeCheck(array, value));
1015             }
1016 #end[Reference]
1017             return UNSAFE.compareAndExchange$Type$(array,
1018                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1019                     {#if[Object]?handle.componentType.cast(expected):expected},
1020                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1021         }
1022 
1023         @ForceInline
1024         static $type$ compareAndExchangeAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1025             Array handle = (Array)ob;
1026 #if[Object]
1027             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1028 #else[Object]
1029             $type$[] array = ($type$[]) oarray;
1030 #end[Object]
1031 #if[Reference]
1032             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1033                 // for flattened array, delegate to VarHandle of the inline type array
1034                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1035                 return vh.compareAndExchangeAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
1036             }
1037 #end[Reference]
1038             return UNSAFE.compareAndExchange$Type$Acquire(array,
1039                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1040                     {#if[Object]?handle.componentType.cast(expected):expected},
1041                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1042         }
1043 
1044         @ForceInline
1045         static $type$ compareAndExchangeRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1046             Array handle = (Array)ob;
1047 #if[Object]
1048             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1049 #else[Object]
1050             $type$[] array = ($type$[]) oarray;
1051 #end[Object]
1052 #if[Reference]
1053             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1054                 // for flattened array, delegate to VarHandle of the inline type array
1055                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1056                 return vh.compareAndExchangeRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
1057             }
1058 #end[Reference]
1059             return UNSAFE.compareAndExchange$Type$Release(array,
1060                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1061                     {#if[Object]?handle.componentType.cast(expected):expected},
1062                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1063         }
1064 
1065         @ForceInline
1066         static boolean weakCompareAndSetPlain(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1067             Array handle = (Array)ob;
1068 #if[Object]
1069             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1070 #else[Object]
1071             $type$[] array = ($type$[]) oarray;
1072 #end[Object]
1073 #if[Reference]
1074             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1075                 // for flattened array, delegate to VarHandle of the inline type array
1076                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1077                 return vh.weakCompareAndSetPlain(oarray, index, expected, reflectiveTypeCheck(array, value));
1078             }
1079 #end[Reference]
1080             return UNSAFE.weakCompareAndSet$Type$Plain(array,
1081                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1082                     {#if[Object]?handle.componentType.cast(expected):expected},
1083                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1084         }
1085 
1086         @ForceInline
1087         static boolean weakCompareAndSet(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1088             Array handle = (Array)ob;
1089 #if[Object]
1090             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1091 #else[Object]
1092             $type$[] array = ($type$[]) oarray;
1093 #end[Object]
1094 #if[Reference]
1095             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1096                 // for flattened array, delegate to VarHandle of the inline type array
1097                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1098                 return vh.weakCompareAndSet(oarray, index, expected, reflectiveTypeCheck(array, value));
1099             }
1100 #end[Reference]
1101             return UNSAFE.weakCompareAndSet$Type$(array,
1102                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1103                     {#if[Object]?handle.componentType.cast(expected):expected},
1104                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1105         }
1106 
1107         @ForceInline
1108         static boolean weakCompareAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1109             Array handle = (Array)ob;
1110 #if[Object]
1111             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1112 #else[Object]
1113             $type$[] array = ($type$[]) oarray;
1114 #end[Object]
1115 #if[Reference]
1116             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1117                 // for flattened array, delegate to VarHandle of the inline type array
1118                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1119                 return vh.weakCompareAndSetAcquire(oarray, index, expected, reflectiveTypeCheck(array, value));
1120             }
1121 #end[Reference]
1122             return UNSAFE.weakCompareAndSet$Type$Acquire(array,
1123                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1124                     {#if[Object]?handle.componentType.cast(expected):expected},
1125                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1126         }
1127 
1128         @ForceInline
1129         static boolean weakCompareAndSetRelease(VarHandle ob, Object oarray, int index, $type$ expected, $type$ value) {
1130             Array handle = (Array)ob;
1131 #if[Object]
1132             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1133 #else[Object]
1134             $type$[] array = ($type$[]) oarray;
1135 #end[Object]
1136 #if[Reference]
1137             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1138                 // for flattened array, delegate to VarHandle of the inline type array
1139                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1140                 return vh.weakCompareAndSetRelease(oarray, index, expected, reflectiveTypeCheck(array, value));
1141             }
1142 #end[Reference]
1143             return UNSAFE.weakCompareAndSet$Type$Release(array,
1144                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Object]?, handle.componentType},
1145                     {#if[Object]?handle.componentType.cast(expected):expected},
1146                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1147         }
1148 
1149         @ForceInline
1150         static $type$ getAndSet(VarHandle ob, Object oarray, int index, $type$ value) {
1151             Array handle = (Array)ob;
1152 #if[Object]
1153             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1154 #else[Object]
1155             $type$[] array = ($type$[]) oarray;
1156 #end[Object]
1157 #if[Reference]
1158             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1159                 // for flattened array, delegate to VarHandle of the inline type array
1160                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1161                 return vh.getAndSet(oarray, index, reflectiveTypeCheck(array, value));
1162             }
1163 #end[Reference]
1164             return UNSAFE.getAndSet$Type$(array,
1165                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1166                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1167         }
1168 
1169         @ForceInline
1170         static $type$ getAndSetAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1171             Array handle = (Array)ob;
1172 #if[Object]
1173             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1174 #else[Object]
1175             $type$[] array = ($type$[]) oarray;
1176 #end[Object]
1177 #if[Reference]
1178             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1179                 // for flattened array, delegate to VarHandle of the inline type array
1180                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1181                 return vh.getAndSetAcquire(oarray, index, reflectiveTypeCheck(array, value));
1182             }
1183 #end[Reference]
1184             return UNSAFE.getAndSet$Type$Acquire(array,
1185                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1186                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1187         }
1188 
1189         @ForceInline
1190         static $type$ getAndSetRelease(VarHandle ob, Object oarray, int index, $type$ value) {
1191             Array handle = (Array)ob;
1192 #if[Object]
1193             Object[] array = (Object[]) handle.arrayType.cast(oarray);
1194 #else[Object]
1195             $type$[] array = ($type$[]) oarray;
1196 #end[Object]
1197 #if[Reference]
1198             if (UNSAFE.isFlattenedArray(oarray.getClass())) {
1199                 // for flattened array, delegate to VarHandle of the inline type array
1200                 VarHandle vh = makeVarHandleValuesArray(oarray.getClass());
1201                 return vh.getAndSetRelease(oarray, index, reflectiveTypeCheck(array, value));
1202             }
1203 #end[Reference]
1204             return UNSAFE.getAndSet$Type$Release(array,
1205                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase{#if[Value]?, handle.componentType},
1206                     {#if[Object]?runtimeTypeCheck(handle, array, value):value});
1207         }
1208 #end[CAS]
1209 #if[AtomicAdd]
1210 
1211         @ForceInline
1212         static $type$ getAndAdd(VarHandle ob, Object oarray, int index, $type$ value) {
1213             Array handle = (Array)ob;
1214             $type$[] array = ($type$[]) oarray;
1215             return UNSAFE.getAndAdd$Type$(array,
1216                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
1217                     value);
1218         }
1219 
1220         @ForceInline
1221         static $type$ getAndAddAcquire(VarHandle ob, Object oarray, int index, $type$ value) {
1222             Array handle = (Array)ob;
1223             $type$[] array = ($type$[]) oarray;
1224             return UNSAFE.getAndAdd$Type$Acquire(array,
1225                     (((long) Preconditions.checkIndex(index, array.length, Preconditions.AIOOBE_FORMATTER)) << handle.ashift) + handle.abase,
< prev index next >