< prev index next >

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

Print this page




  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.access.foreign.MemoryAddressProxy;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 
  30 import java.util.Objects;
  31 
  32 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  33 
  34 #warn
  35 
  36 final class VarHandleMemoryAddressAs$Type$s {
  37 
  38     static final boolean BE = UNSAFE.isBigEndian();
  39 


  40 #if[floatingPoint]
  41     @ForceInline
  42     static $rawType$ convEndian(boolean big, $type$ v) {
  43         $rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v);
  44         return big == BE ? rv : $RawBoxType$.reverseBytes(rv);
  45     }
  46 
  47     @ForceInline
  48     static $type$ convEndian(boolean big, $rawType$ rv) {
  49         rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv);
  50         return $Type$.$rawType$BitsTo$Type$(rv);
  51     }
  52 #else[floatingPoint]
  53 #if[byte]
  54     @ForceInline
  55     static $type$ convEndian(boolean big, $type$ n) {
  56         return n;
  57     }
  58 #else[byte]
  59     @ForceInline
  60     static $type$ convEndian(boolean big, $type$ n) {
  61         return big == BE ? n : $BoxType$.reverseBytes(n);
  62     }
  63 #end[byte]
  64 #end[floatingPoint]
  65 
  66     @ForceInline
  67     static MemoryAddressProxy checkAddress(Object obb, long offset, long length, boolean ro) {
  68         MemoryAddressProxy oo = (MemoryAddressProxy)Objects.requireNonNull(obb);
  69         oo.checkAccess(offset, length, ro);
  70         return oo;
  71     }
  72     
  73     @ForceInline
  74     static long offset(MemoryAddressProxy bb, long offset, long alignment) {












  75         long address = bb.unsafeGetOffset() + offset;
  76         if ((address & alignment) != 0) {
  77             throw VarHandleMemoryAddressBase.newIllegalStateExceptionForMisalignedAccess(address);
  78         }
  79         return address;
  80     }
  81     
  82     @ForceInline
  83     static $type$ get0(VarHandleMemoryAddressBase handle, Object obb, long base) {
  84         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
  85 #if[floatingPoint]
  86         $rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
  87                 bb.unsafeGetBase(),
  88                 offset(bb, base, handle.alignment),
  89                 handle.be);
  90         return $Type$.$rawType$BitsTo$Type$(rawValue);
  91 #else[floatingPoint]
  92 #if[byte]
  93         return UNSAFE.get$Type$(
  94                 bb.unsafeGetBase(),
  95                 offset(bb, base, handle.alignment));
  96 #else[byte]
  97         return UNSAFE.get$Type$Unaligned(
  98                 bb.unsafeGetBase(),
  99                 offset(bb, base, handle.alignment),
 100                 handle.be);
 101 #end[byte]
 102 #end[floatingPoint]
 103     }
 104 
 105     @ForceInline
 106     static void set0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 107         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 108 #if[floatingPoint]
 109         UNSAFE.put$RawType$Unaligned(
 110                 bb.unsafeGetBase(),
 111                 offset(bb, base, handle.alignment),
 112                 $Type$.$type$ToRaw$RawType$Bits(value),
 113                 handle.be);
 114 #else[floatingPoint]
 115 #if[byte]
 116         UNSAFE.put$Type$(
 117                 bb.unsafeGetBase(),
 118                 offset(bb, base, handle.alignment),
 119                 value);
 120 #else[byte]
 121         UNSAFE.put$Type$Unaligned(
 122                 bb.unsafeGetBase(),
 123                 offset(bb, base, handle.alignment),
 124                 value,
 125                 handle.be);
 126 #end[byte]
 127 #end[floatingPoint]
 128     }
 129 
 130     @ForceInline
 131     static $type$ getVolatile0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 132         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 133         return convEndian(handle.be,
 134                           UNSAFE.get$RawType$Volatile(
 135                                   bb.unsafeGetBase(),
 136                                   offset(bb, base, handle.alignment)));
 137     }
 138 
 139     @ForceInline
 140     static void setVolatile0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 141         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 142         UNSAFE.put$RawType$Volatile(
 143                 bb.unsafeGetBase(),
 144                 offset(bb, base, handle.alignment),
 145                 convEndian(handle.be, value));
 146     }
 147 
 148     @ForceInline
 149     static $type$ getAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 150         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 151         return convEndian(handle.be,
 152                           UNSAFE.get$RawType$Acquire(
 153                                   bb.unsafeGetBase(),
 154                                   offset(bb, base, handle.alignment)));
 155     }
 156 
 157     @ForceInline
 158     static void setRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 159         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 160         UNSAFE.put$RawType$Release(
 161                 bb.unsafeGetBase(),
 162                 offset(bb, base, handle.alignment),
 163                 convEndian(handle.be, value));
 164     }
 165 
 166     @ForceInline
 167     static $type$ getOpaque0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 168         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 169         return convEndian(handle.be,
 170                           UNSAFE.get$RawType$Opaque(
 171                                   bb.unsafeGetBase(),
 172                                   offset(bb, base, handle.alignment)));
 173     }
 174 
 175     @ForceInline
 176     static void setOpaque0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 177         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 178         UNSAFE.put$RawType$Opaque(
 179                 bb.unsafeGetBase(),
 180                 offset(bb, base, handle.alignment),
 181                 convEndian(handle.be, value));
 182     }
 183 #if[CAS]
 184 
 185     @ForceInline
 186     static boolean compareAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 187         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 188         return UNSAFE.compareAndSet$RawType$(
 189                 bb.unsafeGetBase(),
 190                 offset(bb, base, handle.alignment),
 191                 convEndian(handle.be, expected), convEndian(handle.be, value));
 192     }
 193 
 194     @ForceInline
 195     static $type$ compareAndExchange0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 196         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 197         return convEndian(handle.be,
 198                           UNSAFE.compareAndExchange$RawType$(
 199                                   bb.unsafeGetBase(),
 200                                   offset(bb, base, handle.alignment),
 201                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 202     }
 203 
 204     @ForceInline
 205     static $type$ compareAndExchangeAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 206         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 207         return convEndian(handle.be,
 208                           UNSAFE.compareAndExchange$RawType$Acquire(
 209                                   bb.unsafeGetBase(),
 210                                   offset(bb, base, handle.alignment),
 211                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 212     }
 213 
 214     @ForceInline
 215     static $type$ compareAndExchangeRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 216         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 217         return convEndian(handle.be,
 218                           UNSAFE.compareAndExchange$RawType$Release(
 219                                   bb.unsafeGetBase(),
 220                                   offset(bb, base, handle.alignment),
 221                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 222     }
 223 
 224     @ForceInline
 225     static boolean weakCompareAndSetPlain0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 226         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 227         return UNSAFE.weakCompareAndSet$RawType$Plain(
 228                 bb.unsafeGetBase(),
 229                 offset(bb, base, handle.alignment),
 230                 convEndian(handle.be, expected), convEndian(handle.be, value));
 231     }
 232 
 233     @ForceInline
 234     static boolean weakCompareAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 235         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 236         return UNSAFE.weakCompareAndSet$RawType$(
 237                 bb.unsafeGetBase(),
 238                 offset(bb, base, handle.alignment),
 239                 convEndian(handle.be, expected), convEndian(handle.be, value));
 240     }
 241 
 242     @ForceInline
 243     static boolean weakCompareAndSetAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 244         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 245         return UNSAFE.weakCompareAndSet$RawType$Acquire(
 246                 bb.unsafeGetBase(),
 247                 offset(bb, base, handle.alignment),
 248                 convEndian(handle.be, expected), convEndian(handle.be, value));
 249     }
 250 
 251     @ForceInline
 252     static boolean weakCompareAndSetRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 253         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 254         return UNSAFE.weakCompareAndSet$RawType$Release(
 255                 bb.unsafeGetBase(),
 256                 offset(bb, base, handle.alignment),
 257                 convEndian(handle.be, expected), convEndian(handle.be, value));
 258     }
 259 
 260     @ForceInline
 261     static $type$ getAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 262         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 263         return convEndian(handle.be,
 264                           UNSAFE.getAndSet$RawType$(
 265                                   bb.unsafeGetBase(),
 266                                   offset(bb, base, handle.alignment),
 267                                   convEndian(handle.be, value)));
 268     }
 269 
 270     @ForceInline
 271     static $type$ getAndSetAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 272         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 273         return convEndian(handle.be,
 274                           UNSAFE.getAndSet$RawType$Acquire(
 275                                   bb.unsafeGetBase(),
 276                                   offset(bb, base, handle.alignment),
 277                                   convEndian(handle.be, value)));
 278     }
 279 
 280     @ForceInline
 281     static $type$ getAndSetRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 282         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 283         return convEndian(handle.be,
 284                           UNSAFE.getAndSet$RawType$Release(
 285                                   bb.unsafeGetBase(),
 286                                   offset(bb, base, handle.alignment),
 287                                   convEndian(handle.be, value)));
 288     }
 289 #end[CAS]
 290 #if[AtomicAdd]
 291 
 292     @ForceInline
 293     static $type$ getAndAdd0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 294         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 295         if (handle.be == BE) {
 296             return UNSAFE.getAndAdd$RawType$(
 297                     bb.unsafeGetBase(),
 298                     offset(bb, base, handle.alignment),
 299                     delta);
 300         } else {
 301             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignment), delta);
 302         }
 303     }
 304 
 305     @ForceInline
 306     static $type$ getAndAddAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 307         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 308         if (handle.be == BE) {
 309             return UNSAFE.getAndAdd$RawType$Acquire(
 310                     bb.unsafeGetBase(),
 311                     offset(bb, base, handle.alignment),
 312                     delta);
 313         } else {
 314             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignment), delta);
 315         }
 316     }
 317 
 318     @ForceInline
 319     static $type$ getAndAddRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 320         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 321         if (handle.be == BE) {
 322             return UNSAFE.getAndAdd$RawType$Release(
 323                     bb.unsafeGetBase(),
 324                     offset(bb, base, handle.alignment),
 325                     delta);
 326         } else {
 327             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignment), delta);
 328         }
 329     }
 330 
 331     @ForceInline
 332     static $type$ getAndAddConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ delta) {
 333         $type$ nativeExpectedValue, expectedValue;
 334         Object base = bb.unsafeGetBase();
 335         do {
 336             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 337             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 338         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 339                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
 340         return expectedValue;
 341     }
 342 #end[AtomicAdd]
 343 #if[Bitwise]
 344 
 345     @ForceInline
 346     static $type$ getAndBitwiseOr0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 347         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 348         if (handle.be == BE) {
 349             return UNSAFE.getAndBitwiseOr$RawType$(
 350                     bb.unsafeGetBase(),
 351                     offset(bb, base, handle.alignment),
 352                     value);
 353         } else {
 354             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 355         }
 356     }
 357 
 358     @ForceInline
 359     static $type$ getAndBitwiseOrRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 360         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 361         if (handle.be == BE) {
 362             return UNSAFE.getAndBitwiseOr$RawType$Release(
 363                     bb.unsafeGetBase(),
 364                     offset(bb, base, handle.alignment),
 365                     value);
 366         } else {
 367             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 368         }
 369     }
 370 
 371     @ForceInline
 372     static $type$ getAndBitwiseOrAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 373         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 374         if (handle.be == BE) {
 375             return UNSAFE.getAndBitwiseOr$RawType$Acquire(
 376                     bb.unsafeGetBase(),
 377                     offset(bb, base, handle.alignment),
 378                     value);
 379         } else {
 380             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 381         }
 382     }
 383 
 384     @ForceInline
 385     static $type$ getAndBitwiseOrConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 386         $type$ nativeExpectedValue, expectedValue;
 387         Object base = bb.unsafeGetBase();
 388         do {
 389             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 390             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 391         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 392                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue | value)));
 393         return expectedValue;
 394     }
 395 
 396     @ForceInline
 397     static $type$ getAndBitwiseAnd0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 398         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 399         if (handle.be == BE) {
 400             return UNSAFE.getAndBitwiseAnd$RawType$(
 401                     bb.unsafeGetBase(),
 402                     offset(bb, base, handle.alignment),
 403                     value);
 404         } else {
 405             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 406         }
 407     }
 408 
 409     @ForceInline
 410     static $type$ getAndBitwiseAndRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 411         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 412         if (handle.be == BE) {
 413             return UNSAFE.getAndBitwiseAnd$RawType$Release(
 414                     bb.unsafeGetBase(),
 415                     offset(bb, base, handle.alignment),
 416                     value);
 417         } else {
 418             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 419         }
 420     }
 421 
 422     @ForceInline
 423     static $type$ getAndBitwiseAndAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 424         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 425         if (handle.be == BE) {
 426             return UNSAFE.getAndBitwiseAnd$RawType$Acquire(
 427                     bb.unsafeGetBase(),
 428                     offset(bb, base, handle.alignment),
 429                     value);
 430         } else {
 431             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 432         }
 433     }
 434 
 435     @ForceInline
 436     static $type$ getAndBitwiseAndConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 437         $type$ nativeExpectedValue, expectedValue;
 438         Object base = bb.unsafeGetBase();
 439         do {
 440             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 441             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 442         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 443                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue & value)));
 444         return expectedValue;
 445     }
 446 
 447 
 448     @ForceInline
 449     static $type$ getAndBitwiseXor0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 450         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 451         if (handle.be == BE) {
 452             return UNSAFE.getAndBitwiseXor$RawType$(
 453                     bb.unsafeGetBase(),
 454                     offset(bb, base, handle.alignment),
 455                     value);
 456         } else {
 457             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 458         }
 459     }
 460 
 461     @ForceInline
 462     static $type$ getAndBitwiseXorRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 463         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 464         if (handle.be == BE) {
 465             return UNSAFE.getAndBitwiseXor$RawType$Release(
 466                     bb.unsafeGetBase(),
 467                     offset(bb, base, handle.alignment),
 468                     value);
 469         } else {
 470             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 471         }
 472     }
 473 
 474     @ForceInline
 475     static $type$ getAndBitwiseXorAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 476         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 477         if (handle.be == BE) {
 478             return UNSAFE.getAndBitwiseXor$RawType$Acquire(
 479                     bb.unsafeGetBase(),
 480                     offset(bb, base, handle.alignment),
 481                     value);
 482         } else {
 483             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignment), value);
 484         }
 485     }
 486 
 487     @ForceInline
 488     static $type$ getAndBitwiseXorConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 489         $type$ nativeExpectedValue, expectedValue;
 490         Object base = bb.unsafeGetBase();
 491         do {
 492             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 493             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 494         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 495                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue ^ value)));
 496         return expectedValue;
 497     }
 498 #end[Bitwise]
 499 }


  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.access.foreign.MemoryAddressProxy;
  28 import jdk.internal.vm.annotation.ForceInline;
  29 
  30 import java.util.Objects;
  31 
  32 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  33 
  34 #warn
  35 
  36 final class VarHandleMemoryAddressAs$Type$s {
  37 
  38     static final boolean BE = UNSAFE.isBigEndian();
  39 
  40     static final int VM_ALIGN = $BoxType$.BYTES - 1;
  41 
  42 #if[floatingPoint]
  43     @ForceInline
  44     static $rawType$ convEndian(boolean big, $type$ v) {
  45         $rawType$ rv = $Type$.$type$ToRaw$RawType$Bits(v);
  46         return big == BE ? rv : $RawBoxType$.reverseBytes(rv);
  47     }
  48 
  49     @ForceInline
  50     static $type$ convEndian(boolean big, $rawType$ rv) {
  51         rv = big == BE ? rv : $RawBoxType$.reverseBytes(rv);
  52         return $Type$.$rawType$BitsTo$Type$(rv);
  53     }
  54 #else[floatingPoint]
  55 #if[byte]
  56     @ForceInline
  57     static $type$ convEndian(boolean big, $type$ n) {
  58         return n;
  59     }
  60 #else[byte]
  61     @ForceInline
  62     static $type$ convEndian(boolean big, $type$ n) {
  63         return big == BE ? n : $BoxType$.reverseBytes(n);
  64     }
  65 #end[byte]
  66 #end[floatingPoint]
  67 
  68     @ForceInline
  69     static MemoryAddressProxy checkAddress(Object obb, long offset, long length, boolean ro) {
  70         MemoryAddressProxy oo = (MemoryAddressProxy)Objects.requireNonNull(obb);
  71         oo.checkAccess(offset, length, ro);
  72         return oo;
  73     }
  74     
  75     @ForceInline
  76     static long offset(MemoryAddressProxy bb, long offset, long alignmentMask) {
  77         long address = bb.unsafeGetOffset() + offset;
  78         if ((address & alignmentMask) != 0) {
  79             throw VarHandleMemoryAddressBase.newIllegalStateExceptionForMisalignedAccess(address);
  80         }
  81         if ((address & VM_ALIGN) != 0) {
  82             throw VarHandleMemoryAddressBase.newIllegalStateExceptionForMisalignedAccess(address);
  83         }
  84         return address;
  85     }
  86 
  87     @ForceInline
  88     static long offsetNoVMAlignCheck(MemoryAddressProxy bb, long offset, long alignmentMask) {
  89         long address = bb.unsafeGetOffset() + offset;
  90         if ((address & alignmentMask) != 0) {
  91             throw VarHandleMemoryAddressBase.newIllegalStateExceptionForMisalignedAccess(address);
  92         }
  93         return address;
  94     }
  95     
  96     @ForceInline
  97     static $type$ get0(VarHandleMemoryAddressBase handle, Object obb, long base) {
  98         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
  99 #if[floatingPoint]
 100         $rawType$ rawValue = UNSAFE.get$RawType$Unaligned(
 101                 bb.unsafeGetBase(),
 102                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
 103                 handle.be);
 104         return $Type$.$rawType$BitsTo$Type$(rawValue);
 105 #else[floatingPoint]
 106 #if[byte]
 107         return UNSAFE.get$Type$(
 108                 bb.unsafeGetBase(),
 109                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask));
 110 #else[byte]
 111         return UNSAFE.get$Type$Unaligned(
 112                 bb.unsafeGetBase(),
 113                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
 114                 handle.be);
 115 #end[byte]
 116 #end[floatingPoint]
 117     }
 118 
 119     @ForceInline
 120     static void set0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 121         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 122 #if[floatingPoint]
 123         UNSAFE.put$RawType$Unaligned(
 124                 bb.unsafeGetBase(),
 125                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
 126                 $Type$.$type$ToRaw$RawType$Bits(value),
 127                 handle.be);
 128 #else[floatingPoint]
 129 #if[byte]
 130         UNSAFE.put$Type$(
 131                 bb.unsafeGetBase(),
 132                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
 133                 value);
 134 #else[byte]
 135         UNSAFE.put$Type$Unaligned(
 136                 bb.unsafeGetBase(),
 137                 offsetNoVMAlignCheck(bb, base, handle.alignmentMask),
 138                 value,
 139                 handle.be);
 140 #end[byte]
 141 #end[floatingPoint]
 142     }
 143 
 144     @ForceInline
 145     static $type$ getVolatile0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 146         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 147         return convEndian(handle.be,
 148                           UNSAFE.get$RawType$Volatile(
 149                                   bb.unsafeGetBase(),
 150                                   offset(bb, base, handle.alignmentMask)));
 151     }
 152 
 153     @ForceInline
 154     static void setVolatile0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 155         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 156         UNSAFE.put$RawType$Volatile(
 157                 bb.unsafeGetBase(),
 158                 offset(bb, base, handle.alignmentMask),
 159                 convEndian(handle.be, value));
 160     }
 161 
 162     @ForceInline
 163     static $type$ getAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 164         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 165         return convEndian(handle.be,
 166                           UNSAFE.get$RawType$Acquire(
 167                                   bb.unsafeGetBase(),
 168                                   offset(bb, base, handle.alignmentMask)));
 169     }
 170 
 171     @ForceInline
 172     static void setRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 173         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 174         UNSAFE.put$RawType$Release(
 175                 bb.unsafeGetBase(),
 176                 offset(bb, base, handle.alignmentMask),
 177                 convEndian(handle.be, value));
 178     }
 179 
 180     @ForceInline
 181     static $type$ getOpaque0(VarHandleMemoryAddressBase handle, Object obb, long base) {
 182         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, true);
 183         return convEndian(handle.be,
 184                           UNSAFE.get$RawType$Opaque(
 185                                   bb.unsafeGetBase(),
 186                                   offset(bb, base, handle.alignmentMask)));
 187     }
 188 
 189     @ForceInline
 190     static void setOpaque0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 191         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 192         UNSAFE.put$RawType$Opaque(
 193                 bb.unsafeGetBase(),
 194                 offset(bb, base, handle.alignmentMask),
 195                 convEndian(handle.be, value));
 196     }
 197 #if[CAS]
 198 
 199     @ForceInline
 200     static boolean compareAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 201         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 202         return UNSAFE.compareAndSet$RawType$(
 203                 bb.unsafeGetBase(),
 204                 offset(bb, base, handle.alignmentMask),
 205                 convEndian(handle.be, expected), convEndian(handle.be, value));
 206     }
 207 
 208     @ForceInline
 209     static $type$ compareAndExchange0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 210         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 211         return convEndian(handle.be,
 212                           UNSAFE.compareAndExchange$RawType$(
 213                                   bb.unsafeGetBase(),
 214                                   offset(bb, base, handle.alignmentMask),
 215                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 216     }
 217 
 218     @ForceInline
 219     static $type$ compareAndExchangeAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 220         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 221         return convEndian(handle.be,
 222                           UNSAFE.compareAndExchange$RawType$Acquire(
 223                                   bb.unsafeGetBase(),
 224                                   offset(bb, base, handle.alignmentMask),
 225                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 226     }
 227 
 228     @ForceInline
 229     static $type$ compareAndExchangeRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 230         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 231         return convEndian(handle.be,
 232                           UNSAFE.compareAndExchange$RawType$Release(
 233                                   bb.unsafeGetBase(),
 234                                   offset(bb, base, handle.alignmentMask),
 235                                   convEndian(handle.be, expected), convEndian(handle.be, value)));
 236     }
 237 
 238     @ForceInline
 239     static boolean weakCompareAndSetPlain0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 240         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 241         return UNSAFE.weakCompareAndSet$RawType$Plain(
 242                 bb.unsafeGetBase(),
 243                 offset(bb, base, handle.alignmentMask),
 244                 convEndian(handle.be, expected), convEndian(handle.be, value));
 245     }
 246 
 247     @ForceInline
 248     static boolean weakCompareAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 249         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 250         return UNSAFE.weakCompareAndSet$RawType$(
 251                 bb.unsafeGetBase(),
 252                 offset(bb, base, handle.alignmentMask),
 253                 convEndian(handle.be, expected), convEndian(handle.be, value));
 254     }
 255 
 256     @ForceInline
 257     static boolean weakCompareAndSetAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 258         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 259         return UNSAFE.weakCompareAndSet$RawType$Acquire(
 260                 bb.unsafeGetBase(),
 261                 offset(bb, base, handle.alignmentMask),
 262                 convEndian(handle.be, expected), convEndian(handle.be, value));
 263     }
 264 
 265     @ForceInline
 266     static boolean weakCompareAndSetRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ expected, $type$ value) {
 267         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 268         return UNSAFE.weakCompareAndSet$RawType$Release(
 269                 bb.unsafeGetBase(),
 270                 offset(bb, base, handle.alignmentMask),
 271                 convEndian(handle.be, expected), convEndian(handle.be, value));
 272     }
 273 
 274     @ForceInline
 275     static $type$ getAndSet0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 276         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 277         return convEndian(handle.be,
 278                           UNSAFE.getAndSet$RawType$(
 279                                   bb.unsafeGetBase(),
 280                                   offset(bb, base, handle.alignmentMask),
 281                                   convEndian(handle.be, value)));
 282     }
 283 
 284     @ForceInline
 285     static $type$ getAndSetAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 286         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 287         return convEndian(handle.be,
 288                           UNSAFE.getAndSet$RawType$Acquire(
 289                                   bb.unsafeGetBase(),
 290                                   offset(bb, base, handle.alignmentMask),
 291                                   convEndian(handle.be, value)));
 292     }
 293 
 294     @ForceInline
 295     static $type$ getAndSetRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 296         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 297         return convEndian(handle.be,
 298                           UNSAFE.getAndSet$RawType$Release(
 299                                   bb.unsafeGetBase(),
 300                                   offset(bb, base, handle.alignmentMask),
 301                                   convEndian(handle.be, value)));
 302     }
 303 #end[CAS]
 304 #if[AtomicAdd]
 305 
 306     @ForceInline
 307     static $type$ getAndAdd0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 308         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 309         if (handle.be == BE) {
 310             return UNSAFE.getAndAdd$RawType$(
 311                     bb.unsafeGetBase(),
 312                     offset(bb, base, handle.alignmentMask),
 313                     delta);
 314         } else {
 315             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
 316         }
 317     }
 318 
 319     @ForceInline
 320     static $type$ getAndAddAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 321         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 322         if (handle.be == BE) {
 323             return UNSAFE.getAndAdd$RawType$Acquire(
 324                     bb.unsafeGetBase(),
 325                     offset(bb, base, handle.alignmentMask),
 326                     delta);
 327         } else {
 328             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
 329         }
 330     }
 331 
 332     @ForceInline
 333     static $type$ getAndAddRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ delta) {
 334         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 335         if (handle.be == BE) {
 336             return UNSAFE.getAndAdd$RawType$Release(
 337                     bb.unsafeGetBase(),
 338                     offset(bb, base, handle.alignmentMask),
 339                     delta);
 340         } else {
 341             return getAndAddConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), delta);
 342         }
 343     }
 344 
 345     @ForceInline
 346     static $type$ getAndAddConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ delta) {
 347         $type$ nativeExpectedValue, expectedValue;
 348         Object base = bb.unsafeGetBase();
 349         do {
 350             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 351             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 352         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 353                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue + delta)));
 354         return expectedValue;
 355     }
 356 #end[AtomicAdd]
 357 #if[Bitwise]
 358 
 359     @ForceInline
 360     static $type$ getAndBitwiseOr0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 361         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 362         if (handle.be == BE) {
 363             return UNSAFE.getAndBitwiseOr$RawType$(
 364                     bb.unsafeGetBase(),
 365                     offset(bb, base, handle.alignmentMask),
 366                     value);
 367         } else {
 368             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 369         }
 370     }
 371 
 372     @ForceInline
 373     static $type$ getAndBitwiseOrRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 374         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 375         if (handle.be == BE) {
 376             return UNSAFE.getAndBitwiseOr$RawType$Release(
 377                     bb.unsafeGetBase(),
 378                     offset(bb, base, handle.alignmentMask),
 379                     value);
 380         } else {
 381             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 382         }
 383     }
 384 
 385     @ForceInline
 386     static $type$ getAndBitwiseOrAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 387         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 388         if (handle.be == BE) {
 389             return UNSAFE.getAndBitwiseOr$RawType$Acquire(
 390                     bb.unsafeGetBase(),
 391                     offset(bb, base, handle.alignmentMask),
 392                     value);
 393         } else {
 394             return getAndBitwiseOrConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 395         }
 396     }
 397 
 398     @ForceInline
 399     static $type$ getAndBitwiseOrConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 400         $type$ nativeExpectedValue, expectedValue;
 401         Object base = bb.unsafeGetBase();
 402         do {
 403             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 404             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 405         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 406                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue | value)));
 407         return expectedValue;
 408     }
 409 
 410     @ForceInline
 411     static $type$ getAndBitwiseAnd0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 412         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 413         if (handle.be == BE) {
 414             return UNSAFE.getAndBitwiseAnd$RawType$(
 415                     bb.unsafeGetBase(),
 416                     offset(bb, base, handle.alignmentMask),
 417                     value);
 418         } else {
 419             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 420         }
 421     }
 422 
 423     @ForceInline
 424     static $type$ getAndBitwiseAndRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 425         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 426         if (handle.be == BE) {
 427             return UNSAFE.getAndBitwiseAnd$RawType$Release(
 428                     bb.unsafeGetBase(),
 429                     offset(bb, base, handle.alignmentMask),
 430                     value);
 431         } else {
 432             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 433         }
 434     }
 435 
 436     @ForceInline
 437     static $type$ getAndBitwiseAndAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 438         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 439         if (handle.be == BE) {
 440             return UNSAFE.getAndBitwiseAnd$RawType$Acquire(
 441                     bb.unsafeGetBase(),
 442                     offset(bb, base, handle.alignmentMask),
 443                     value);
 444         } else {
 445             return getAndBitwiseAndConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 446         }
 447     }
 448 
 449     @ForceInline
 450     static $type$ getAndBitwiseAndConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 451         $type$ nativeExpectedValue, expectedValue;
 452         Object base = bb.unsafeGetBase();
 453         do {
 454             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 455             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 456         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 457                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue & value)));
 458         return expectedValue;
 459     }
 460 
 461 
 462     @ForceInline
 463     static $type$ getAndBitwiseXor0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 464         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 465         if (handle.be == BE) {
 466             return UNSAFE.getAndBitwiseXor$RawType$(
 467                     bb.unsafeGetBase(),
 468                     offset(bb, base, handle.alignmentMask),
 469                     value);
 470         } else {
 471             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 472         }
 473     }
 474 
 475     @ForceInline
 476     static $type$ getAndBitwiseXorRelease0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 477         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 478         if (handle.be == BE) {
 479             return UNSAFE.getAndBitwiseXor$RawType$Release(
 480                     bb.unsafeGetBase(),
 481                     offset(bb, base, handle.alignmentMask),
 482                     value);
 483         } else {
 484             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 485         }
 486     }
 487 
 488     @ForceInline
 489     static $type$ getAndBitwiseXorAcquire0(VarHandleMemoryAddressBase handle, Object obb, long base, $type$ value) {
 490         MemoryAddressProxy bb = checkAddress(obb, base, handle.length, false);
 491         if (handle.be == BE) {
 492             return UNSAFE.getAndBitwiseXor$RawType$Acquire(
 493                     bb.unsafeGetBase(),
 494                     offset(bb, base, handle.alignmentMask),
 495                     value);
 496         } else {
 497             return getAndBitwiseXorConvEndianWithCAS(bb, offset(bb, base, handle.alignmentMask), value);
 498         }
 499     }
 500 
 501     @ForceInline
 502     static $type$ getAndBitwiseXorConvEndianWithCAS(MemoryAddressProxy bb, long offset, $type$ value) {
 503         $type$ nativeExpectedValue, expectedValue;
 504         Object base = bb.unsafeGetBase();
 505         do {
 506             nativeExpectedValue = UNSAFE.get$RawType$Volatile(base, offset);
 507             expectedValue = $RawBoxType$.reverseBytes(nativeExpectedValue);
 508         } while (!UNSAFE.weakCompareAndSet$RawType$(base, offset,
 509                 nativeExpectedValue, $RawBoxType$.reverseBytes(expectedValue ^ value)));
 510         return expectedValue;
 511     }
 512 #end[Bitwise]
 513 }
< prev index next >