1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.misc;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.ref.Cleaner;
  30 import jdk.internal.vm.annotation.ForceInline;
  31 import sun.nio.ch.DirectBuffer;
  32 
  33 import java.lang.reflect.Field;
  34 import java.security.ProtectionDomain;
  35 
  36 import static jdk.internal.misc.UnsafeConstants.*;
  37 
  38 /**
  39  * A collection of methods for performing low-level, unsafe operations.
  40  * Although the class and all methods are public, use of this class is
  41  * limited because only trusted code can obtain instances of it.
  42  *
  43  * <em>Note:</em> It is the resposibility of the caller to make sure
  44  * arguments are checked before methods of this class are
  45  * called. While some rudimentary checks are performed on the input,
  46  * the checks are best effort and when performance is an overriding
  47  * priority, as when methods of this class are optimized by the
  48  * runtime compiler, some or all checks (if any) may be elided. Hence,
  49  * the caller must not rely on the checks and corresponding
  50  * exceptions!
  51  *
  52  * @author John R. Rose
  53  * @see #getUnsafe
  54  */
  55 
  56 public final class Unsafe {
  57 
  58     private static native void registerNatives();
  59     static {
  60         registerNatives();
  61     }
  62 
  63     private Unsafe() {}
  64 
  65     private static final Unsafe theUnsafe = new Unsafe();
  66 
  67     /**
  68      * Provides the caller with the capability of performing unsafe
  69      * operations.
  70      *
  71      * <p>The returned {@code Unsafe} object should be carefully guarded
  72      * by the caller, since it can be used to read and write data at arbitrary
  73      * memory addresses.  It must never be passed to untrusted code.
  74      *
  75      * <p>Most methods in this class are very low-level, and correspond to a
  76      * small number of hardware instructions (on typical machines).  Compilers
  77      * are encouraged to optimize these methods accordingly.
  78      *
  79      * <p>Here is a suggested idiom for using unsafe operations:
  80      *
  81      * <pre> {@code
  82      * class MyTrustedClass {
  83      *   private static final Unsafe unsafe = Unsafe.getUnsafe();
  84      *   ...
  85      *   private long myCountAddress = ...;
  86      *   public int getCount() { return unsafe.getByte(myCountAddress); }
  87      * }}</pre>
  88      *
  89      * (It may assist compilers to make the local variable {@code final}.)
  90      */
  91     public static Unsafe getUnsafe() {
  92         return theUnsafe;
  93     }
  94 
  95     /// peek and poke operations
  96     /// (compilers should optimize these to memory ops)
  97 
  98     // These work on object fields in the Java heap.
  99     // They will not work on elements of packed arrays.
 100 
 101     /**
 102      * Fetches a value from a given Java variable.
 103      * More specifically, fetches a field or array element within the given
 104      * object {@code o} at the given offset, or (if {@code o} is null)
 105      * from the memory address whose numerical value is the given offset.
 106      * <p>
 107      * The results are undefined unless one of the following cases is true:
 108      * <ul>
 109      * <li>The offset was obtained from {@link #objectFieldOffset} on
 110      * the {@link java.lang.reflect.Field} of some Java field and the object
 111      * referred to by {@code o} is of a class compatible with that
 112      * field's class.
 113      *
 114      * <li>The offset and object reference {@code o} (either null or
 115      * non-null) were both obtained via {@link #staticFieldOffset}
 116      * and {@link #staticFieldBase} (respectively) from the
 117      * reflective {@link Field} representation of some Java field.
 118      *
 119      * <li>The object referred to by {@code o} is an array, and the offset
 120      * is an integer of the form {@code B+N*S}, where {@code N} is
 121      * a valid index into the array, and {@code B} and {@code S} are
 122      * the values obtained by {@link #arrayBaseOffset} and {@link
 123      * #arrayIndexScale} (respectively) from the array's class.  The value
 124      * referred to is the {@code N}<em>th</em> element of the array.
 125      *
 126      * </ul>
 127      * <p>
 128      * If one of the above cases is true, the call references a specific Java
 129      * variable (field or array element).  However, the results are undefined
 130      * if that variable is not in fact of the type returned by this method.
 131      * <p>
 132      * This method refers to a variable by means of two parameters, and so
 133      * it provides (in effect) a <em>double-register</em> addressing mode
 134      * for Java variables.  When the object reference is null, this method
 135      * uses its offset as an absolute address.  This is similar in operation
 136      * to methods such as {@link #getInt(long)}, which provide (in effect) a
 137      * <em>single-register</em> addressing mode for non-Java variables.
 138      * However, because Java variables may have a different layout in memory
 139      * from non-Java variables, programmers should not assume that these
 140      * two addressing modes are ever equivalent.  Also, programmers should
 141      * remember that offsets from the double-register addressing mode cannot
 142      * be portably confused with longs used in the single-register addressing
 143      * mode.
 144      *
 145      * @param o Java heap object in which the variable resides, if any, else
 146      *        null
 147      * @param offset indication of where the variable resides in a Java heap
 148      *        object, if any, else a memory address locating the variable
 149      *        statically
 150      * @return the value fetched from the indicated Java variable
 151      * @throws RuntimeException No defined exceptions are thrown, not even
 152      *         {@link NullPointerException}
 153      */
 154     @HotSpotIntrinsicCandidate
 155     public native int getInt(Object o, long offset);
 156 
 157     /**
 158      * Stores a value into a given Java variable.
 159      * <p>
 160      * The first two parameters are interpreted exactly as with
 161      * {@link #getInt(Object, long)} to refer to a specific
 162      * Java variable (field or array element).  The given value
 163      * is stored into that variable.
 164      * <p>
 165      * The variable must be of the same type as the method
 166      * parameter {@code x}.
 167      *
 168      * @param o Java heap object in which the variable resides, if any, else
 169      *        null
 170      * @param offset indication of where the variable resides in a Java heap
 171      *        object, if any, else a memory address locating the variable
 172      *        statically
 173      * @param x the value to store into the indicated Java variable
 174      * @throws RuntimeException No defined exceptions are thrown, not even
 175      *         {@link NullPointerException}
 176      */
 177     @HotSpotIntrinsicCandidate
 178     public native void putInt(Object o, long offset, int x);
 179 
 180     /**
 181      * Fetches a reference value from a given Java variable.
 182      * @see #getInt(Object, long)
 183      */
 184     @HotSpotIntrinsicCandidate
 185     public native Object getReference(Object o, long offset);
 186 
 187     /**
 188      * Stores a reference value into a given Java variable.
 189      * <p>
 190      * Unless the reference {@code x} being stored is either null
 191      * or matches the field type, the results are undefined.
 192      * If the reference {@code o} is non-null, card marks or
 193      * other store barriers for that object (if the VM requires them)
 194      * are updated.
 195      * @see #putInt(Object, long, int)
 196      */
 197     @HotSpotIntrinsicCandidate
 198     public native void putReference(Object o, long offset, Object x);
 199 
 200     /** @see #getInt(Object, long) */
 201     @HotSpotIntrinsicCandidate
 202     public native boolean getBoolean(Object o, long offset);
 203 
 204     /** @see #putInt(Object, long, int) */
 205     @HotSpotIntrinsicCandidate
 206     public native void    putBoolean(Object o, long offset, boolean x);
 207 
 208     /** @see #getInt(Object, long) */
 209     @HotSpotIntrinsicCandidate
 210     public native byte    getByte(Object o, long offset);
 211 
 212     /** @see #putInt(Object, long, int) */
 213     @HotSpotIntrinsicCandidate
 214     public native void    putByte(Object o, long offset, byte x);
 215 
 216     /** @see #getInt(Object, long) */
 217     @HotSpotIntrinsicCandidate
 218     public native short   getShort(Object o, long offset);
 219 
 220     /** @see #putInt(Object, long, int) */
 221     @HotSpotIntrinsicCandidate
 222     public native void    putShort(Object o, long offset, short x);
 223 
 224     /** @see #getInt(Object, long) */
 225     @HotSpotIntrinsicCandidate
 226     public native char    getChar(Object o, long offset);
 227 
 228     /** @see #putInt(Object, long, int) */
 229     @HotSpotIntrinsicCandidate
 230     public native void    putChar(Object o, long offset, char x);
 231 
 232     /** @see #getInt(Object, long) */
 233     @HotSpotIntrinsicCandidate
 234     public native long    getLong(Object o, long offset);
 235 
 236     /** @see #putInt(Object, long, int) */
 237     @HotSpotIntrinsicCandidate
 238     public native void    putLong(Object o, long offset, long x);
 239 
 240     /** @see #getInt(Object, long) */
 241     @HotSpotIntrinsicCandidate
 242     public native float   getFloat(Object o, long offset);
 243 
 244     /** @see #putInt(Object, long, int) */
 245     @HotSpotIntrinsicCandidate
 246     public native void    putFloat(Object o, long offset, float x);
 247 
 248     /** @see #getInt(Object, long) */
 249     @HotSpotIntrinsicCandidate
 250     public native double  getDouble(Object o, long offset);
 251 
 252     /** @see #putInt(Object, long, int) */
 253     @HotSpotIntrinsicCandidate
 254     public native void    putDouble(Object o, long offset, double x);
 255 
 256     /**
 257      * Fetches a native pointer from a given memory address.  If the address is
 258      * zero, or does not point into a block obtained from {@link
 259      * #allocateMemory}, the results are undefined.
 260      *
 261      * <p>If the native pointer is less than 64 bits wide, it is extended as
 262      * an unsigned number to a Java long.  The pointer may be indexed by any
 263      * given byte offset, simply by adding that offset (as a simple integer) to
 264      * the long representing the pointer.  The number of bytes actually read
 265      * from the target address may be determined by consulting {@link
 266      * #addressSize}.
 267      *
 268      * @see #allocateMemory
 269      * @see #getInt(Object, long)
 270      */
 271     @ForceInline
 272     public long getAddress(Object o, long offset) {
 273         if (ADDRESS_SIZE == 4) {
 274             return Integer.toUnsignedLong(getInt(o, offset));
 275         } else {
 276             return getLong(o, offset);
 277         }
 278     }
 279 
 280     /**
 281      * Stores a native pointer into a given memory address.  If the address is
 282      * zero, or does not point into a block obtained from {@link
 283      * #allocateMemory}, the results are undefined.
 284      *
 285      * <p>The number of bytes actually written at the target address may be
 286      * determined by consulting {@link #addressSize}.
 287      *
 288      * @see #allocateMemory
 289      * @see #putInt(Object, long, int)
 290      */
 291     @ForceInline
 292     public void putAddress(Object o, long offset, long x) {
 293         if (ADDRESS_SIZE == 4) {
 294             putInt(o, offset, (int)x);
 295         } else {
 296             putLong(o, offset, x);
 297         }
 298     }
 299 
 300     // These read VM internal data.
 301 
 302     /**
 303      * Fetches an uncompressed reference value from a given native variable
 304      * ignoring the VM's compressed references mode.
 305      *
 306      * @param address a memory address locating the variable
 307      * @return the value fetched from the indicated native variable
 308      */
 309     public native Object getUncompressedObject(long address);
 310 
 311     // These work on values in the C heap.
 312 
 313     /**
 314      * Fetches a value from a given memory address.  If the address is zero, or
 315      * does not point into a block obtained from {@link #allocateMemory}, the
 316      * results are undefined.
 317      *
 318      * @see #allocateMemory
 319      */
 320     @ForceInline
 321     public byte getByte(long address) {
 322         return getByte(null, address);
 323     }
 324 
 325     /**
 326      * Stores a value into a given memory address.  If the address is zero, or
 327      * does not point into a block obtained from {@link #allocateMemory}, the
 328      * results are undefined.
 329      *
 330      * @see #getByte(long)
 331      */
 332     @ForceInline
 333     public void putByte(long address, byte x) {
 334         putByte(null, address, x);
 335     }
 336 
 337     /** @see #getByte(long) */
 338     @ForceInline
 339     public short getShort(long address) {
 340         return getShort(null, address);
 341     }
 342 
 343     /** @see #putByte(long, byte) */
 344     @ForceInline
 345     public void putShort(long address, short x) {
 346         putShort(null, address, x);
 347     }
 348 
 349     /** @see #getByte(long) */
 350     @ForceInline
 351     public char getChar(long address) {
 352         return getChar(null, address);
 353     }
 354 
 355     /** @see #putByte(long, byte) */
 356     @ForceInline
 357     public void putChar(long address, char x) {
 358         putChar(null, address, x);
 359     }
 360 
 361     /** @see #getByte(long) */
 362     @ForceInline
 363     public int getInt(long address) {
 364         return getInt(null, address);
 365     }
 366 
 367     /** @see #putByte(long, byte) */
 368     @ForceInline
 369     public void putInt(long address, int x) {
 370         putInt(null, address, x);
 371     }
 372 
 373     /** @see #getByte(long) */
 374     @ForceInline
 375     public long getLong(long address) {
 376         return getLong(null, address);
 377     }
 378 
 379     /** @see #putByte(long, byte) */
 380     @ForceInline
 381     public void putLong(long address, long x) {
 382         putLong(null, address, x);
 383     }
 384 
 385     /** @see #getByte(long) */
 386     @ForceInline
 387     public float getFloat(long address) {
 388         return getFloat(null, address);
 389     }
 390 
 391     /** @see #putByte(long, byte) */
 392     @ForceInline
 393     public void putFloat(long address, float x) {
 394         putFloat(null, address, x);
 395     }
 396 
 397     /** @see #getByte(long) */
 398     @ForceInline
 399     public double getDouble(long address) {
 400         return getDouble(null, address);
 401     }
 402 
 403     /** @see #putByte(long, byte) */
 404     @ForceInline
 405     public void putDouble(long address, double x) {
 406         putDouble(null, address, x);
 407     }
 408 
 409     /** @see #getAddress(Object, long) */
 410     @ForceInline
 411     public long getAddress(long address) {
 412         return getAddress(null, address);
 413     }
 414 
 415     /** @see #putAddress(Object, long, long) */
 416     @ForceInline
 417     public void putAddress(long address, long x) {
 418         putAddress(null, address, x);
 419     }
 420 
 421 
 422 
 423     /// helper methods for validating various types of objects/values
 424 
 425     /**
 426      * Create an exception reflecting that some of the input was invalid
 427      *
 428      * <em>Note:</em> It is the resposibility of the caller to make
 429      * sure arguments are checked before the methods are called. While
 430      * some rudimentary checks are performed on the input, the checks
 431      * are best effort and when performance is an overriding priority,
 432      * as when methods of this class are optimized by the runtime
 433      * compiler, some or all checks (if any) may be elided. Hence, the
 434      * caller must not rely on the checks and corresponding
 435      * exceptions!
 436      *
 437      * @return an exception object
 438      */
 439     private RuntimeException invalidInput() {
 440         return new IllegalArgumentException();
 441     }
 442 
 443     /**
 444      * Check if a value is 32-bit clean (32 MSB are all zero)
 445      *
 446      * @param value the 64-bit value to check
 447      *
 448      * @return true if the value is 32-bit clean
 449      */
 450     private boolean is32BitClean(long value) {
 451         return value >>> 32 == 0;
 452     }
 453 
 454     /**
 455      * Check the validity of a size (the equivalent of a size_t)
 456      *
 457      * @throws RuntimeException if the size is invalid
 458      *         (<em>Note:</em> after optimization, invalid inputs may
 459      *         go undetected, which will lead to unpredictable
 460      *         behavior)
 461      */
 462     private void checkSize(long size) {
 463         if (ADDRESS_SIZE == 4) {
 464             // Note: this will also check for negative sizes
 465             if (!is32BitClean(size)) {
 466                 throw invalidInput();
 467             }
 468         } else if (size < 0) {
 469             throw invalidInput();
 470         }
 471     }
 472 
 473     /**
 474      * Check the validity of a native address (the equivalent of void*)
 475      *
 476      * @throws RuntimeException if the address is invalid
 477      *         (<em>Note:</em> after optimization, invalid inputs may
 478      *         go undetected, which will lead to unpredictable
 479      *         behavior)
 480      */
 481     private void checkNativeAddress(long address) {
 482         if (ADDRESS_SIZE == 4) {
 483             // Accept both zero and sign extended pointers. A valid
 484             // pointer will, after the +1 below, either have produced
 485             // the value 0x0 or 0x1. Masking off the low bit allows
 486             // for testing against 0.
 487             if ((((address >> 32) + 1) & ~1) != 0) {
 488                 throw invalidInput();
 489             }
 490         }
 491     }
 492 
 493     /**
 494      * Check the validity of an offset, relative to a base object
 495      *
 496      * @param o the base object
 497      * @param offset the offset to check
 498      *
 499      * @throws RuntimeException if the size is invalid
 500      *         (<em>Note:</em> after optimization, invalid inputs may
 501      *         go undetected, which will lead to unpredictable
 502      *         behavior)
 503      */
 504     private void checkOffset(Object o, long offset) {
 505         if (ADDRESS_SIZE == 4) {
 506             // Note: this will also check for negative offsets
 507             if (!is32BitClean(offset)) {
 508                 throw invalidInput();
 509             }
 510         } else if (offset < 0) {
 511             throw invalidInput();
 512         }
 513     }
 514 
 515     /**
 516      * Check the validity of a double-register pointer
 517      *
 518      * Note: This code deliberately does *not* check for NPE for (at
 519      * least) three reasons:
 520      *
 521      * 1) NPE is not just NULL/0 - there is a range of values all
 522      * resulting in an NPE, which is not trivial to check for
 523      *
 524      * 2) It is the responsibility of the callers of Unsafe methods
 525      * to verify the input, so throwing an exception here is not really
 526      * useful - passing in a NULL pointer is a critical error and the
 527      * must not expect an exception to be thrown anyway.
 528      *
 529      * 3) the actual operations will detect NULL pointers anyway by
 530      * means of traps and signals (like SIGSEGV).
 531      *
 532      * @param o Java heap object, or null
 533      * @param offset indication of where the variable resides in a Java heap
 534      *        object, if any, else a memory address locating the variable
 535      *        statically
 536      *
 537      * @throws RuntimeException if the pointer is invalid
 538      *         (<em>Note:</em> after optimization, invalid inputs may
 539      *         go undetected, which will lead to unpredictable
 540      *         behavior)
 541      */
 542     private void checkPointer(Object o, long offset) {
 543         if (o == null) {
 544             checkNativeAddress(offset);
 545         } else {
 546             checkOffset(o, offset);
 547         }
 548     }
 549 
 550     /**
 551      * Check if a type is a primitive array type
 552      *
 553      * @param c the type to check
 554      *
 555      * @return true if the type is a primitive array type
 556      */
 557     private void checkPrimitiveArray(Class<?> c) {
 558         Class<?> componentType = c.getComponentType();
 559         if (componentType == null || !componentType.isPrimitive()) {
 560             throw invalidInput();
 561         }
 562     }
 563 
 564     /**
 565      * Check that a pointer is a valid primitive array type pointer
 566      *
 567      * Note: pointers off-heap are considered to be primitive arrays
 568      *
 569      * @throws RuntimeException if the pointer is invalid
 570      *         (<em>Note:</em> after optimization, invalid inputs may
 571      *         go undetected, which will lead to unpredictable
 572      *         behavior)
 573      */
 574     private void checkPrimitivePointer(Object o, long offset) {
 575         checkPointer(o, offset);
 576 
 577         if (o != null) {
 578             // If on heap, it must be a primitive array
 579             checkPrimitiveArray(o.getClass());
 580         }
 581     }
 582 
 583 
 584     /// wrappers for malloc, realloc, free:
 585 
 586     /**
 587      * Allocates a new block of native memory, of the given size in bytes.  The
 588      * contents of the memory are uninitialized; they will generally be
 589      * garbage.  The resulting native pointer will never be zero, and will be
 590      * aligned for all value types.  Dispose of this memory by calling {@link
 591      * #freeMemory}, or resize it with {@link #reallocateMemory}.
 592      *
 593      * <em>Note:</em> It is the resposibility of the caller to make
 594      * sure arguments are checked before the methods are called. While
 595      * some rudimentary checks are performed on the input, the checks
 596      * are best effort and when performance is an overriding priority,
 597      * as when methods of this class are optimized by the runtime
 598      * compiler, some or all checks (if any) may be elided. Hence, the
 599      * caller must not rely on the checks and corresponding
 600      * exceptions!
 601      *
 602      * @throws RuntimeException if the size is negative or too large
 603      *         for the native size_t type
 604      *
 605      * @throws OutOfMemoryError if the allocation is refused by the system
 606      *
 607      * @see #getByte(long)
 608      * @see #putByte(long, byte)
 609      */
 610     public long allocateMemory(long bytes) {
 611         allocateMemoryChecks(bytes);
 612 
 613         if (bytes == 0) {
 614             return 0;
 615         }
 616 
 617         long p = allocateMemory0(bytes);
 618         if (p == 0) {
 619             throw new OutOfMemoryError();
 620         }
 621 
 622         return p;
 623     }
 624 
 625     /**
 626      * Validate the arguments to allocateMemory
 627      *
 628      * @throws RuntimeException if the arguments are invalid
 629      *         (<em>Note:</em> after optimization, invalid inputs may
 630      *         go undetected, which will lead to unpredictable
 631      *         behavior)
 632      */
 633     private void allocateMemoryChecks(long bytes) {
 634         checkSize(bytes);
 635     }
 636 
 637     /**
 638      * Resizes a new block of native memory, to the given size in bytes.  The
 639      * contents of the new block past the size of the old block are
 640      * uninitialized; they will generally be garbage.  The resulting native
 641      * pointer will be zero if and only if the requested size is zero.  The
 642      * resulting native pointer will be aligned for all value types.  Dispose
 643      * of this memory by calling {@link #freeMemory}, or resize it with {@link
 644      * #reallocateMemory}.  The address passed to this method may be null, in
 645      * which case an allocation will be performed.
 646      *
 647      * <em>Note:</em> It is the resposibility of the caller to make
 648      * sure arguments are checked before the methods are called. While
 649      * some rudimentary checks are performed on the input, the checks
 650      * are best effort and when performance is an overriding priority,
 651      * as when methods of this class are optimized by the runtime
 652      * compiler, some or all checks (if any) may be elided. Hence, the
 653      * caller must not rely on the checks and corresponding
 654      * exceptions!
 655      *
 656      * @throws RuntimeException if the size is negative or too large
 657      *         for the native size_t type
 658      *
 659      * @throws OutOfMemoryError if the allocation is refused by the system
 660      *
 661      * @see #allocateMemory
 662      */
 663     public long reallocateMemory(long address, long bytes) {
 664         reallocateMemoryChecks(address, bytes);
 665 
 666         if (bytes == 0) {
 667             freeMemory(address);
 668             return 0;
 669         }
 670 
 671         long p = (address == 0) ? allocateMemory0(bytes) : reallocateMemory0(address, bytes);
 672         if (p == 0) {
 673             throw new OutOfMemoryError();
 674         }
 675 
 676         return p;
 677     }
 678 
 679     /**
 680      * Validate the arguments to reallocateMemory
 681      *
 682      * @throws RuntimeException if the arguments are invalid
 683      *         (<em>Note:</em> after optimization, invalid inputs may
 684      *         go undetected, which will lead to unpredictable
 685      *         behavior)
 686      */
 687     private void reallocateMemoryChecks(long address, long bytes) {
 688         checkPointer(null, address);
 689         checkSize(bytes);
 690     }
 691 
 692     /**
 693      * Sets all bytes in a given block of memory to a fixed value
 694      * (usually zero).
 695      *
 696      * <p>This method determines a block's base address by means of two parameters,
 697      * and so it provides (in effect) a <em>double-register</em> addressing mode,
 698      * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
 699      * the offset supplies an absolute base address.
 700      *
 701      * <p>The stores are in coherent (atomic) units of a size determined
 702      * by the address and length parameters.  If the effective address and
 703      * length are all even modulo 8, the stores take place in 'long' units.
 704      * If the effective address and length are (resp.) even modulo 4 or 2,
 705      * the stores take place in units of 'int' or 'short'.
 706      *
 707      * <em>Note:</em> It is the resposibility of the caller to make
 708      * sure arguments are checked before the methods are called. While
 709      * some rudimentary checks are performed on the input, the checks
 710      * are best effort and when performance is an overriding priority,
 711      * as when methods of this class are optimized by the runtime
 712      * compiler, some or all checks (if any) may be elided. Hence, the
 713      * caller must not rely on the checks and corresponding
 714      * exceptions!
 715      *
 716      * @throws RuntimeException if any of the arguments is invalid
 717      *
 718      * @since 1.7
 719      */
 720     public void setMemory(Object o, long offset, long bytes, byte value) {
 721         setMemoryChecks(o, offset, bytes, value);
 722 
 723         if (bytes == 0) {
 724             return;
 725         }
 726 
 727         setMemory0(o, offset, bytes, value);
 728     }
 729 
 730     /**
 731      * Sets all bytes in a given block of memory to a fixed value
 732      * (usually zero).  This provides a <em>single-register</em> addressing mode,
 733      * as discussed in {@link #getInt(Object,long)}.
 734      *
 735      * <p>Equivalent to {@code setMemory(null, address, bytes, value)}.
 736      */
 737     public void setMemory(long address, long bytes, byte value) {
 738         setMemory(null, address, bytes, value);
 739     }
 740 
 741     /**
 742      * Validate the arguments to setMemory
 743      *
 744      * @throws RuntimeException if the arguments are invalid
 745      *         (<em>Note:</em> after optimization, invalid inputs may
 746      *         go undetected, which will lead to unpredictable
 747      *         behavior)
 748      */
 749     private void setMemoryChecks(Object o, long offset, long bytes, byte value) {
 750         checkPrimitivePointer(o, offset);
 751         checkSize(bytes);
 752     }
 753 
 754     /**
 755      * Sets all bytes in a given block of memory to a copy of another
 756      * block.
 757      *
 758      * <p>This method determines each block's base address by means of two parameters,
 759      * and so it provides (in effect) a <em>double-register</em> addressing mode,
 760      * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
 761      * the offset supplies an absolute base address.
 762      *
 763      * <p>The transfers are in coherent (atomic) units of a size determined
 764      * by the address and length parameters.  If the effective addresses and
 765      * length are all even modulo 8, the transfer takes place in 'long' units.
 766      * If the effective addresses and length are (resp.) even modulo 4 or 2,
 767      * the transfer takes place in units of 'int' or 'short'.
 768      *
 769      * <em>Note:</em> It is the resposibility of the caller to make
 770      * sure arguments are checked before the methods are called. While
 771      * some rudimentary checks are performed on the input, the checks
 772      * are best effort and when performance is an overriding priority,
 773      * as when methods of this class are optimized by the runtime
 774      * compiler, some or all checks (if any) may be elided. Hence, the
 775      * caller must not rely on the checks and corresponding
 776      * exceptions!
 777      *
 778      * @throws RuntimeException if any of the arguments is invalid
 779      *
 780      * @since 1.7
 781      */
 782     public void copyMemory(Object srcBase, long srcOffset,
 783                            Object destBase, long destOffset,
 784                            long bytes) {
 785         copyMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes);
 786 
 787         if (bytes == 0) {
 788             return;
 789         }
 790 
 791         copyMemory0(srcBase, srcOffset, destBase, destOffset, bytes);
 792     }
 793 
 794     /**
 795      * Sets all bytes in a given block of memory to a copy of another
 796      * block.  This provides a <em>single-register</em> addressing mode,
 797      * as discussed in {@link #getInt(Object,long)}.
 798      *
 799      * Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.
 800      */
 801     public void copyMemory(long srcAddress, long destAddress, long bytes) {
 802         copyMemory(null, srcAddress, null, destAddress, bytes);
 803     }
 804 
 805     /**
 806      * Validate the arguments to copyMemory
 807      *
 808      * @throws RuntimeException if any of the arguments is invalid
 809      *         (<em>Note:</em> after optimization, invalid inputs may
 810      *         go undetected, which will lead to unpredictable
 811      *         behavior)
 812      */
 813     private void copyMemoryChecks(Object srcBase, long srcOffset,
 814                                   Object destBase, long destOffset,
 815                                   long bytes) {
 816         checkSize(bytes);
 817         checkPrimitivePointer(srcBase, srcOffset);
 818         checkPrimitivePointer(destBase, destOffset);
 819     }
 820 
 821     /**
 822      * Copies all elements from one block of memory to another block,
 823      * *unconditionally* byte swapping the elements on the fly.
 824      *
 825      * <p>This method determines each block's base address by means of two parameters,
 826      * and so it provides (in effect) a <em>double-register</em> addressing mode,
 827      * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
 828      * the offset supplies an absolute base address.
 829      *
 830      * <em>Note:</em> It is the resposibility of the caller to make
 831      * sure arguments are checked before the methods are called. While
 832      * some rudimentary checks are performed on the input, the checks
 833      * are best effort and when performance is an overriding priority,
 834      * as when methods of this class are optimized by the runtime
 835      * compiler, some or all checks (if any) may be elided. Hence, the
 836      * caller must not rely on the checks and corresponding
 837      * exceptions!
 838      *
 839      * @throws RuntimeException if any of the arguments is invalid
 840      *
 841      * @since 9
 842      */
 843     public void copySwapMemory(Object srcBase, long srcOffset,
 844                                Object destBase, long destOffset,
 845                                long bytes, long elemSize) {
 846         copySwapMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
 847 
 848         if (bytes == 0) {
 849             return;
 850         }
 851 
 852         copySwapMemory0(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
 853     }
 854 
 855     private void copySwapMemoryChecks(Object srcBase, long srcOffset,
 856                                       Object destBase, long destOffset,
 857                                       long bytes, long elemSize) {
 858         checkSize(bytes);
 859 
 860         if (elemSize != 2 && elemSize != 4 && elemSize != 8) {
 861             throw invalidInput();
 862         }
 863         if (bytes % elemSize != 0) {
 864             throw invalidInput();
 865         }
 866 
 867         checkPrimitivePointer(srcBase, srcOffset);
 868         checkPrimitivePointer(destBase, destOffset);
 869     }
 870 
 871    /**
 872      * Copies all elements from one block of memory to another block, byte swapping the
 873      * elements on the fly.
 874      *
 875      * This provides a <em>single-register</em> addressing mode, as
 876      * discussed in {@link #getInt(Object,long)}.
 877      *
 878      * Equivalent to {@code copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize)}.
 879      */
 880     public void copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize) {
 881         copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize);
 882     }
 883 
 884     /**
 885      * Disposes of a block of native memory, as obtained from {@link
 886      * #allocateMemory} or {@link #reallocateMemory}.  The address passed to
 887      * this method may be null, in which case no action is taken.
 888      *
 889      * <em>Note:</em> It is the resposibility of the caller to make
 890      * sure arguments are checked before the methods are called. While
 891      * some rudimentary checks are performed on the input, the checks
 892      * are best effort and when performance is an overriding priority,
 893      * as when methods of this class are optimized by the runtime
 894      * compiler, some or all checks (if any) may be elided. Hence, the
 895      * caller must not rely on the checks and corresponding
 896      * exceptions!
 897      *
 898      * @throws RuntimeException if any of the arguments is invalid
 899      *
 900      * @see #allocateMemory
 901      */
 902     public void freeMemory(long address) {
 903         freeMemoryChecks(address);
 904 
 905         if (address == 0) {
 906             return;
 907         }
 908 
 909         freeMemory0(address);
 910     }
 911 
 912     /**
 913      * Validate the arguments to freeMemory
 914      *
 915      * @throws RuntimeException if the arguments are invalid
 916      *         (<em>Note:</em> after optimization, invalid inputs may
 917      *         go undetected, which will lead to unpredictable
 918      *         behavior)
 919      */
 920     private void freeMemoryChecks(long address) {
 921         checkPointer(null, address);
 922     }
 923 
 924     /// random queries
 925 
 926     /**
 927      * This constant differs from all results that will ever be returned from
 928      * {@link #staticFieldOffset}, {@link #objectFieldOffset},
 929      * or {@link #arrayBaseOffset}.
 930      */
 931     public static final int INVALID_FIELD_OFFSET = -1;
 932 
 933     /**
 934      * Reports the location of a given field in the storage allocation of its
 935      * class.  Do not expect to perform any sort of arithmetic on this offset;
 936      * it is just a cookie which is passed to the unsafe heap memory accessors.
 937      *
 938      * <p>Any given field will always have the same offset and base, and no
 939      * two distinct fields of the same class will ever have the same offset
 940      * and base.
 941      *
 942      * <p>As of 1.4.1, offsets for fields are represented as long values,
 943      * although the Sun JVM does not use the most significant 32 bits.
 944      * However, JVM implementations which store static fields at absolute
 945      * addresses can use long offsets and null base pointers to express
 946      * the field locations in a form usable by {@link #getInt(Object,long)}.
 947      * Therefore, code which will be ported to such JVMs on 64-bit platforms
 948      * must preserve all bits of static field offsets.
 949      * @see #getInt(Object, long)
 950      */
 951     public long objectFieldOffset(Field f) {
 952         if (f == null) {
 953             throw new NullPointerException();
 954         }
 955 
 956         return objectFieldOffset0(f);
 957     }
 958 
 959     /**
 960      * Reports the location of the field with a given name in the storage
 961      * allocation of its class.
 962      *
 963      * @throws NullPointerException if any parameter is {@code null}.
 964      * @throws InternalError if there is no field named {@code name} declared
 965      *         in class {@code c}, i.e., if {@code c.getDeclaredField(name)}
 966      *         would throw {@code java.lang.NoSuchFieldException}.
 967      *
 968      * @see #objectFieldOffset(Field)
 969      */
 970     public long objectFieldOffset(Class<?> c, String name) {
 971         if (c == null || name == null) {
 972             throw new NullPointerException();
 973         }
 974 
 975         return objectFieldOffset1(c, name);
 976     }
 977 
 978     /**
 979      * Reports the location of a given static field, in conjunction with {@link
 980      * #staticFieldBase}.
 981      * <p>Do not expect to perform any sort of arithmetic on this offset;
 982      * it is just a cookie which is passed to the unsafe heap memory accessors.
 983      *
 984      * <p>Any given field will always have the same offset, and no two distinct
 985      * fields of the same class will ever have the same offset.
 986      *
 987      * <p>As of 1.4.1, offsets for fields are represented as long values,
 988      * although the Sun JVM does not use the most significant 32 bits.
 989      * It is hard to imagine a JVM technology which needs more than
 990      * a few bits to encode an offset within a non-array object,
 991      * However, for consistency with other methods in this class,
 992      * this method reports its result as a long value.
 993      * @see #getInt(Object, long)
 994      */
 995     public long staticFieldOffset(Field f) {
 996         if (f == null) {
 997             throw new NullPointerException();
 998         }
 999 
1000         return staticFieldOffset0(f);
1001     }
1002 
1003     /**
1004      * Reports the location of a given static field, in conjunction with {@link
1005      * #staticFieldOffset}.
1006      * <p>Fetch the base "Object", if any, with which static fields of the
1007      * given class can be accessed via methods like {@link #getInt(Object,
1008      * long)}.  This value may be null.  This value may refer to an object
1009      * which is a "cookie", not guaranteed to be a real Object, and it should
1010      * not be used in any way except as argument to the get and put routines in
1011      * this class.
1012      */
1013     public Object staticFieldBase(Field f) {
1014         if (f == null) {
1015             throw new NullPointerException();
1016         }
1017 
1018         return staticFieldBase0(f);
1019     }
1020 
1021     /**
1022      * Detects if the given class may need to be initialized. This is often
1023      * needed in conjunction with obtaining the static field base of a
1024      * class.
1025      * @return false only if a call to {@code ensureClassInitialized} would have no effect
1026      */
1027     public boolean shouldBeInitialized(Class<?> c) {
1028         if (c == null) {
1029             throw new NullPointerException();
1030         }
1031 
1032         return shouldBeInitialized0(c);
1033     }
1034 
1035     /**
1036      * Ensures the given class has been initialized. This is often
1037      * needed in conjunction with obtaining the static field base of a
1038      * class.
1039      */
1040     public void ensureClassInitialized(Class<?> c) {
1041         if (c == null) {
1042             throw new NullPointerException();
1043         }
1044 
1045         ensureClassInitialized0(c);
1046     }
1047 
1048     /**
1049      * Reports the offset of the first element in the storage allocation of a
1050      * given array class.  If {@link #arrayIndexScale} returns a non-zero value
1051      * for the same class, you may use that scale factor, together with this
1052      * base offset, to form new offsets to access elements of arrays of the
1053      * given class.
1054      *
1055      * @see #getInt(Object, long)
1056      * @see #putInt(Object, long, int)
1057      */
1058     public int arrayBaseOffset(Class<?> arrayClass) {
1059         if (arrayClass == null) {
1060             throw new NullPointerException();
1061         }
1062 
1063         return arrayBaseOffset0(arrayClass);
1064     }
1065 
1066 
1067     /** The value of {@code arrayBaseOffset(boolean[].class)} */
1068     public static final int ARRAY_BOOLEAN_BASE_OFFSET
1069             = theUnsafe.arrayBaseOffset(boolean[].class);
1070 
1071     /** The value of {@code arrayBaseOffset(byte[].class)} */
1072     public static final int ARRAY_BYTE_BASE_OFFSET
1073             = theUnsafe.arrayBaseOffset(byte[].class);
1074 
1075     /** The value of {@code arrayBaseOffset(short[].class)} */
1076     public static final int ARRAY_SHORT_BASE_OFFSET
1077             = theUnsafe.arrayBaseOffset(short[].class);
1078 
1079     /** The value of {@code arrayBaseOffset(char[].class)} */
1080     public static final int ARRAY_CHAR_BASE_OFFSET
1081             = theUnsafe.arrayBaseOffset(char[].class);
1082 
1083     /** The value of {@code arrayBaseOffset(int[].class)} */
1084     public static final int ARRAY_INT_BASE_OFFSET
1085             = theUnsafe.arrayBaseOffset(int[].class);
1086 
1087     /** The value of {@code arrayBaseOffset(long[].class)} */
1088     public static final int ARRAY_LONG_BASE_OFFSET
1089             = theUnsafe.arrayBaseOffset(long[].class);
1090 
1091     /** The value of {@code arrayBaseOffset(float[].class)} */
1092     public static final int ARRAY_FLOAT_BASE_OFFSET
1093             = theUnsafe.arrayBaseOffset(float[].class);
1094 
1095     /** The value of {@code arrayBaseOffset(double[].class)} */
1096     public static final int ARRAY_DOUBLE_BASE_OFFSET
1097             = theUnsafe.arrayBaseOffset(double[].class);
1098 
1099     /** The value of {@code arrayBaseOffset(Object[].class)} */
1100     public static final int ARRAY_OBJECT_BASE_OFFSET
1101             = theUnsafe.arrayBaseOffset(Object[].class);
1102 
1103     /**
1104      * Reports the scale factor for addressing elements in the storage
1105      * allocation of a given array class.  However, arrays of "narrow" types
1106      * will generally not work properly with accessors like {@link
1107      * #getByte(Object, long)}, so the scale factor for such classes is reported
1108      * as zero.
1109      *
1110      * @see #arrayBaseOffset
1111      * @see #getInt(Object, long)
1112      * @see #putInt(Object, long, int)
1113      */
1114     public int arrayIndexScale(Class<?> arrayClass) {
1115         if (arrayClass == null) {
1116             throw new NullPointerException();
1117         }
1118 
1119         return arrayIndexScale0(arrayClass);
1120     }
1121 
1122 
1123     /** The value of {@code arrayIndexScale(boolean[].class)} */
1124     public static final int ARRAY_BOOLEAN_INDEX_SCALE
1125             = theUnsafe.arrayIndexScale(boolean[].class);
1126 
1127     /** The value of {@code arrayIndexScale(byte[].class)} */
1128     public static final int ARRAY_BYTE_INDEX_SCALE
1129             = theUnsafe.arrayIndexScale(byte[].class);
1130 
1131     /** The value of {@code arrayIndexScale(short[].class)} */
1132     public static final int ARRAY_SHORT_INDEX_SCALE
1133             = theUnsafe.arrayIndexScale(short[].class);
1134 
1135     /** The value of {@code arrayIndexScale(char[].class)} */
1136     public static final int ARRAY_CHAR_INDEX_SCALE
1137             = theUnsafe.arrayIndexScale(char[].class);
1138 
1139     /** The value of {@code arrayIndexScale(int[].class)} */
1140     public static final int ARRAY_INT_INDEX_SCALE
1141             = theUnsafe.arrayIndexScale(int[].class);
1142 
1143     /** The value of {@code arrayIndexScale(long[].class)} */
1144     public static final int ARRAY_LONG_INDEX_SCALE
1145             = theUnsafe.arrayIndexScale(long[].class);
1146 
1147     /** The value of {@code arrayIndexScale(float[].class)} */
1148     public static final int ARRAY_FLOAT_INDEX_SCALE
1149             = theUnsafe.arrayIndexScale(float[].class);
1150 
1151     /** The value of {@code arrayIndexScale(double[].class)} */
1152     public static final int ARRAY_DOUBLE_INDEX_SCALE
1153             = theUnsafe.arrayIndexScale(double[].class);
1154 
1155     /** The value of {@code arrayIndexScale(Object[].class)} */
1156     public static final int ARRAY_OBJECT_INDEX_SCALE
1157             = theUnsafe.arrayIndexScale(Object[].class);
1158 
1159     /**
1160      * Reports the size in bytes of a native pointer, as stored via {@link
1161      * #putAddress}.  This value will be either 4 or 8.  Note that the sizes of
1162      * other primitive types (as stored in native memory blocks) is determined
1163      * fully by their information content.
1164      */
1165     public int addressSize() {
1166         return ADDRESS_SIZE;
1167     }
1168 
1169     /** The value of {@code addressSize()} */
1170     public static final int ADDRESS_SIZE = ADDRESS_SIZE0;
1171 
1172     /**
1173      * Reports the size in bytes of a native memory page (whatever that is).
1174      * This value will always be a power of two.
1175      */
1176     public int pageSize() { return PAGE_SIZE; }
1177 
1178     /// random trusted operations from JNI:
1179 
1180     /**
1181      * Tells the VM to define a class, without security checks.  By default, the
1182      * class loader and protection domain come from the caller's class.
1183      */
1184     public Class<?> defineClass(String name, byte[] b, int off, int len,
1185                                 ClassLoader loader,
1186                                 ProtectionDomain protectionDomain) {
1187         if (b == null) {
1188             throw new NullPointerException();
1189         }
1190         if (len < 0) {
1191             throw new ArrayIndexOutOfBoundsException();
1192         }
1193 
1194         return defineClass0(name, b, off, len, loader, protectionDomain);
1195     }
1196 
1197     public native Class<?> defineClass0(String name, byte[] b, int off, int len,
1198                                         ClassLoader loader,
1199                                         ProtectionDomain protectionDomain);
1200 
1201     /**
1202      * Defines a class but does not make it known to the class loader or system dictionary.
1203      * <p>
1204      * For each CP entry, the corresponding CP patch must either be null or have
1205      * the a format that matches its tag:
1206      * <ul>
1207      * <li>Integer, Long, Float, Double: the corresponding wrapper object type from java.lang
1208      * <li>Utf8: a string (must have suitable syntax if used as signature or name)
1209      * <li>Class: any java.lang.Class object
1210      * <li>String: any object (not just a java.lang.String)
1211      * <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
1212      * </ul>
1213      * @param hostClass context for linkage, access control, protection domain, and class loader
1214      * @param data      bytes of a class file
1215      * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
1216      */
1217     public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
1218         if (hostClass == null || data == null) {
1219             throw new NullPointerException();
1220         }
1221         if (hostClass.isArray() || hostClass.isPrimitive()) {
1222             throw new IllegalArgumentException();
1223         }
1224 
1225         return defineAnonymousClass0(hostClass, data, cpPatches);
1226     }
1227 
1228     /**
1229      * Allocates an instance but does not run any constructor.
1230      * Initializes the class if it has not yet been.
1231      */
1232     @HotSpotIntrinsicCandidate
1233     public native Object allocateInstance(Class<?> cls)
1234         throws InstantiationException;
1235 
1236     /**
1237      * Allocates an array of a given type, but does not do zeroing.
1238      * <p>
1239      * This method should only be used in the very rare cases where a high-performance code
1240      * overwrites the destination array completely, and compilers cannot assist in zeroing elimination.
1241      * In an overwhelming majority of cases, a normal Java allocation should be used instead.
1242      * <p>
1243      * Users of this method are <b>required</b> to overwrite the initial (garbage) array contents
1244      * before allowing untrusted code, or code in other threads, to observe the reference
1245      * to the newly allocated array. In addition, the publication of the array reference must be
1246      * safe according to the Java Memory Model requirements.
1247      * <p>
1248      * The safest approach to deal with an uninitialized array is to keep the reference to it in local
1249      * variable at least until the initialization is complete, and then publish it <b>once</b>, either
1250      * by writing it to a <em>volatile</em> field, or storing it into a <em>final</em> field in constructor,
1251      * or issuing a {@link #storeFence} before publishing the reference.
1252      * <p>
1253      * @implnote This method can only allocate primitive arrays, to avoid garbage reference
1254      * elements that could break heap integrity.
1255      *
1256      * @param componentType array component type to allocate
1257      * @param length array size to allocate
1258      * @throws IllegalArgumentException if component type is null, or not a primitive class;
1259      *                                  or the length is negative
1260      */
1261     public Object allocateUninitializedArray(Class<?> componentType, int length) {
1262        if (componentType == null) {
1263            throw new IllegalArgumentException("Component type is null");
1264        }
1265        if (!componentType.isPrimitive()) {
1266            throw new IllegalArgumentException("Component type is not primitive");
1267        }
1268        if (length < 0) {
1269            throw new IllegalArgumentException("Negative length");
1270        }
1271        return allocateUninitializedArray0(componentType, length);
1272     }
1273 
1274     @HotSpotIntrinsicCandidate
1275     private Object allocateUninitializedArray0(Class<?> componentType, int length) {
1276        // These fallbacks provide zeroed arrays, but intrinsic is not required to
1277        // return the zeroed arrays.
1278        if (componentType == byte.class)    return new byte[length];
1279        if (componentType == boolean.class) return new boolean[length];
1280        if (componentType == short.class)   return new short[length];
1281        if (componentType == char.class)    return new char[length];
1282        if (componentType == int.class)     return new int[length];
1283        if (componentType == float.class)   return new float[length];
1284        if (componentType == long.class)    return new long[length];
1285        if (componentType == double.class)  return new double[length];
1286        return null;
1287     }
1288 
1289     /** Throws the exception without telling the verifier. */
1290     public native void throwException(Throwable ee);
1291 
1292     /**
1293      * Atomically updates Java variable to {@code x} if it is currently
1294      * holding {@code expected}.
1295      *
1296      * <p>This operation has memory semantics of a {@code volatile} read
1297      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1298      *
1299      * @return {@code true} if successful
1300      */
1301     @HotSpotIntrinsicCandidate
1302     public final native boolean compareAndSetReference(Object o, long offset,
1303                                                        Object expected,
1304                                                        Object x);
1305 
1306     @HotSpotIntrinsicCandidate
1307     public final native Object compareAndExchangeReference(Object o, long offset,
1308                                                            Object expected,
1309                                                            Object x);
1310 
1311     @HotSpotIntrinsicCandidate
1312     public final Object compareAndExchangeReferenceAcquire(Object o, long offset,
1313                                                            Object expected,
1314                                                            Object x) {
1315         return compareAndExchangeReference(o, offset, expected, x);
1316     }
1317 
1318     @HotSpotIntrinsicCandidate
1319     public final Object compareAndExchangeReferenceRelease(Object o, long offset,
1320                                                            Object expected,
1321                                                            Object x) {
1322         return compareAndExchangeReference(o, offset, expected, x);
1323     }
1324 
1325     @HotSpotIntrinsicCandidate
1326     public final boolean weakCompareAndSetReferencePlain(Object o, long offset,
1327                                                          Object expected,
1328                                                          Object x) {
1329         return compareAndSetReference(o, offset, expected, x);
1330     }
1331 
1332     @HotSpotIntrinsicCandidate
1333     public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,
1334                                                            Object expected,
1335                                                            Object x) {
1336         return compareAndSetReference(o, offset, expected, x);
1337     }
1338 
1339     @HotSpotIntrinsicCandidate
1340     public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,
1341                                                            Object expected,
1342                                                            Object x) {
1343         return compareAndSetReference(o, offset, expected, x);
1344     }
1345 
1346     @HotSpotIntrinsicCandidate
1347     public final boolean weakCompareAndSetReference(Object o, long offset,
1348                                                     Object expected,
1349                                                     Object x) {
1350         return compareAndSetReference(o, offset, expected, x);
1351     }
1352 
1353     /**
1354      * Atomically updates Java variable to {@code x} if it is currently
1355      * holding {@code expected}.
1356      *
1357      * <p>This operation has memory semantics of a {@code volatile} read
1358      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1359      *
1360      * @return {@code true} if successful
1361      */
1362     @HotSpotIntrinsicCandidate
1363     public final native boolean compareAndSetInt(Object o, long offset,
1364                                                  int expected,
1365                                                  int x);
1366 
1367     @HotSpotIntrinsicCandidate
1368     public final native int compareAndExchangeInt(Object o, long offset,
1369                                                   int expected,
1370                                                   int x);
1371 
1372     @HotSpotIntrinsicCandidate
1373     public final int compareAndExchangeIntAcquire(Object o, long offset,
1374                                                          int expected,
1375                                                          int x) {
1376         return compareAndExchangeInt(o, offset, expected, x);
1377     }
1378 
1379     @HotSpotIntrinsicCandidate
1380     public final int compareAndExchangeIntRelease(Object o, long offset,
1381                                                          int expected,
1382                                                          int x) {
1383         return compareAndExchangeInt(o, offset, expected, x);
1384     }
1385 
1386     @HotSpotIntrinsicCandidate
1387     public final boolean weakCompareAndSetIntPlain(Object o, long offset,
1388                                                    int expected,
1389                                                    int x) {
1390         return compareAndSetInt(o, offset, expected, x);
1391     }
1392 
1393     @HotSpotIntrinsicCandidate
1394     public final boolean weakCompareAndSetIntAcquire(Object o, long offset,
1395                                                      int expected,
1396                                                      int x) {
1397         return compareAndSetInt(o, offset, expected, x);
1398     }
1399 
1400     @HotSpotIntrinsicCandidate
1401     public final boolean weakCompareAndSetIntRelease(Object o, long offset,
1402                                                      int expected,
1403                                                      int x) {
1404         return compareAndSetInt(o, offset, expected, x);
1405     }
1406 
1407     @HotSpotIntrinsicCandidate
1408     public final boolean weakCompareAndSetInt(Object o, long offset,
1409                                               int expected,
1410                                               int x) {
1411         return compareAndSetInt(o, offset, expected, x);
1412     }
1413 
1414     @HotSpotIntrinsicCandidate
1415     public final byte compareAndExchangeByte(Object o, long offset,
1416                                              byte expected,
1417                                              byte x) {
1418         long wordOffset = offset & ~3;
1419         int shift = (int) (offset & 3) << 3;
1420         if (BIG_ENDIAN) {
1421             shift = 24 - shift;
1422         }
1423         int mask           = 0xFF << shift;
1424         int maskedExpected = (expected & 0xFF) << shift;
1425         int maskedX        = (x & 0xFF) << shift;
1426         int fullWord;
1427         do {
1428             fullWord = getIntVolatile(o, wordOffset);
1429             if ((fullWord & mask) != maskedExpected)
1430                 return (byte) ((fullWord & mask) >> shift);
1431         } while (!weakCompareAndSetInt(o, wordOffset,
1432                                                 fullWord, (fullWord & ~mask) | maskedX));
1433         return expected;
1434     }
1435 
1436     @HotSpotIntrinsicCandidate
1437     public final boolean compareAndSetByte(Object o, long offset,
1438                                            byte expected,
1439                                            byte x) {
1440         return compareAndExchangeByte(o, offset, expected, x) == expected;
1441     }
1442 
1443     @HotSpotIntrinsicCandidate
1444     public final boolean weakCompareAndSetByte(Object o, long offset,
1445                                                byte expected,
1446                                                byte x) {
1447         return compareAndSetByte(o, offset, expected, x);
1448     }
1449 
1450     @HotSpotIntrinsicCandidate
1451     public final boolean weakCompareAndSetByteAcquire(Object o, long offset,
1452                                                       byte expected,
1453                                                       byte x) {
1454         return weakCompareAndSetByte(o, offset, expected, x);
1455     }
1456 
1457     @HotSpotIntrinsicCandidate
1458     public final boolean weakCompareAndSetByteRelease(Object o, long offset,
1459                                                       byte expected,
1460                                                       byte x) {
1461         return weakCompareAndSetByte(o, offset, expected, x);
1462     }
1463 
1464     @HotSpotIntrinsicCandidate
1465     public final boolean weakCompareAndSetBytePlain(Object o, long offset,
1466                                                     byte expected,
1467                                                     byte x) {
1468         return weakCompareAndSetByte(o, offset, expected, x);
1469     }
1470 
1471     @HotSpotIntrinsicCandidate
1472     public final byte compareAndExchangeByteAcquire(Object o, long offset,
1473                                                     byte expected,
1474                                                     byte x) {
1475         return compareAndExchangeByte(o, offset, expected, x);
1476     }
1477 
1478     @HotSpotIntrinsicCandidate
1479     public final byte compareAndExchangeByteRelease(Object o, long offset,
1480                                                     byte expected,
1481                                                     byte x) {
1482         return compareAndExchangeByte(o, offset, expected, x);
1483     }
1484 
1485     @HotSpotIntrinsicCandidate
1486     public final short compareAndExchangeShort(Object o, long offset,
1487                                                short expected,
1488                                                short x) {
1489         if ((offset & 3) == 3) {
1490             throw new IllegalArgumentException("Update spans the word, not supported");
1491         }
1492         long wordOffset = offset & ~3;
1493         int shift = (int) (offset & 3) << 3;
1494         if (BIG_ENDIAN) {
1495             shift = 16 - shift;
1496         }
1497         int mask           = 0xFFFF << shift;
1498         int maskedExpected = (expected & 0xFFFF) << shift;
1499         int maskedX        = (x & 0xFFFF) << shift;
1500         int fullWord;
1501         do {
1502             fullWord = getIntVolatile(o, wordOffset);
1503             if ((fullWord & mask) != maskedExpected) {
1504                 return (short) ((fullWord & mask) >> shift);
1505             }
1506         } while (!weakCompareAndSetInt(o, wordOffset,
1507                                                 fullWord, (fullWord & ~mask) | maskedX));
1508         return expected;
1509     }
1510 
1511     @HotSpotIntrinsicCandidate
1512     public final boolean compareAndSetShort(Object o, long offset,
1513                                             short expected,
1514                                             short x) {
1515         return compareAndExchangeShort(o, offset, expected, x) == expected;
1516     }
1517 
1518     @HotSpotIntrinsicCandidate
1519     public final boolean weakCompareAndSetShort(Object o, long offset,
1520                                                 short expected,
1521                                                 short x) {
1522         return compareAndSetShort(o, offset, expected, x);
1523     }
1524 
1525     @HotSpotIntrinsicCandidate
1526     public final boolean weakCompareAndSetShortAcquire(Object o, long offset,
1527                                                        short expected,
1528                                                        short x) {
1529         return weakCompareAndSetShort(o, offset, expected, x);
1530     }
1531 
1532     @HotSpotIntrinsicCandidate
1533     public final boolean weakCompareAndSetShortRelease(Object o, long offset,
1534                                                        short expected,
1535                                                        short x) {
1536         return weakCompareAndSetShort(o, offset, expected, x);
1537     }
1538 
1539     @HotSpotIntrinsicCandidate
1540     public final boolean weakCompareAndSetShortPlain(Object o, long offset,
1541                                                      short expected,
1542                                                      short x) {
1543         return weakCompareAndSetShort(o, offset, expected, x);
1544     }
1545 
1546 
1547     @HotSpotIntrinsicCandidate
1548     public final short compareAndExchangeShortAcquire(Object o, long offset,
1549                                                      short expected,
1550                                                      short x) {
1551         return compareAndExchangeShort(o, offset, expected, x);
1552     }
1553 
1554     @HotSpotIntrinsicCandidate
1555     public final short compareAndExchangeShortRelease(Object o, long offset,
1556                                                     short expected,
1557                                                     short x) {
1558         return compareAndExchangeShort(o, offset, expected, x);
1559     }
1560 
1561     @ForceInline
1562     private char s2c(short s) {
1563         return (char) s;
1564     }
1565 
1566     @ForceInline
1567     private short c2s(char s) {
1568         return (short) s;
1569     }
1570 
1571     @ForceInline
1572     public final boolean compareAndSetChar(Object o, long offset,
1573                                            char expected,
1574                                            char x) {
1575         return compareAndSetShort(o, offset, c2s(expected), c2s(x));
1576     }
1577 
1578     @ForceInline
1579     public final char compareAndExchangeChar(Object o, long offset,
1580                                              char expected,
1581                                              char x) {
1582         return s2c(compareAndExchangeShort(o, offset, c2s(expected), c2s(x)));
1583     }
1584 
1585     @ForceInline
1586     public final char compareAndExchangeCharAcquire(Object o, long offset,
1587                                             char expected,
1588                                             char x) {
1589         return s2c(compareAndExchangeShortAcquire(o, offset, c2s(expected), c2s(x)));
1590     }
1591 
1592     @ForceInline
1593     public final char compareAndExchangeCharRelease(Object o, long offset,
1594                                             char expected,
1595                                             char x) {
1596         return s2c(compareAndExchangeShortRelease(o, offset, c2s(expected), c2s(x)));
1597     }
1598 
1599     @ForceInline
1600     public final boolean weakCompareAndSetChar(Object o, long offset,
1601                                                char expected,
1602                                                char x) {
1603         return weakCompareAndSetShort(o, offset, c2s(expected), c2s(x));
1604     }
1605 
1606     @ForceInline
1607     public final boolean weakCompareAndSetCharAcquire(Object o, long offset,
1608                                                       char expected,
1609                                                       char x) {
1610         return weakCompareAndSetShortAcquire(o, offset, c2s(expected), c2s(x));
1611     }
1612 
1613     @ForceInline
1614     public final boolean weakCompareAndSetCharRelease(Object o, long offset,
1615                                                       char expected,
1616                                                       char x) {
1617         return weakCompareAndSetShortRelease(o, offset, c2s(expected), c2s(x));
1618     }
1619 
1620     @ForceInline
1621     public final boolean weakCompareAndSetCharPlain(Object o, long offset,
1622                                                     char expected,
1623                                                     char x) {
1624         return weakCompareAndSetShortPlain(o, offset, c2s(expected), c2s(x));
1625     }
1626 
1627     /**
1628      * The JVM converts integral values to boolean values using two
1629      * different conventions, byte testing against zero and truncation
1630      * to least-significant bit.
1631      *
1632      * <p>The JNI documents specify that, at least for returning
1633      * values from native methods, a Java boolean value is converted
1634      * to the value-set 0..1 by first truncating to a byte (0..255 or
1635      * maybe -128..127) and then testing against zero. Thus, Java
1636      * booleans in non-Java data structures are by convention
1637      * represented as 8-bit containers containing either zero (for
1638      * false) or any non-zero value (for true).
1639      *
1640      * <p>Java booleans in the heap are also stored in bytes, but are
1641      * strongly normalized to the value-set 0..1 (i.e., they are
1642      * truncated to the least-significant bit).
1643      *
1644      * <p>The main reason for having different conventions for
1645      * conversion is performance: Truncation to the least-significant
1646      * bit can be usually implemented with fewer (machine)
1647      * instructions than byte testing against zero.
1648      *
1649      * <p>A number of Unsafe methods load boolean values from the heap
1650      * as bytes. Unsafe converts those values according to the JNI
1651      * rules (i.e, using the "testing against zero" convention). The
1652      * method {@code byte2bool} implements that conversion.
1653      *
1654      * @param b the byte to be converted to boolean
1655      * @return the result of the conversion
1656      */
1657     @ForceInline
1658     private boolean byte2bool(byte b) {
1659         return b != 0;
1660     }
1661 
1662     /**
1663      * Convert a boolean value to a byte. The return value is strongly
1664      * normalized to the value-set 0..1 (i.e., the value is truncated
1665      * to the least-significant bit). See {@link #byte2bool(byte)} for
1666      * more details on conversion conventions.
1667      *
1668      * @param b the boolean to be converted to byte (and then normalized)
1669      * @return the result of the conversion
1670      */
1671     @ForceInline
1672     private byte bool2byte(boolean b) {
1673         return b ? (byte)1 : (byte)0;
1674     }
1675 
1676     @ForceInline
1677     public final boolean compareAndSetBoolean(Object o, long offset,
1678                                               boolean expected,
1679                                               boolean x) {
1680         return compareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));
1681     }
1682 
1683     @ForceInline
1684     public final boolean compareAndExchangeBoolean(Object o, long offset,
1685                                                    boolean expected,
1686                                                    boolean x) {
1687         return byte2bool(compareAndExchangeByte(o, offset, bool2byte(expected), bool2byte(x)));
1688     }
1689 
1690     @ForceInline
1691     public final boolean compareAndExchangeBooleanAcquire(Object o, long offset,
1692                                                     boolean expected,
1693                                                     boolean x) {
1694         return byte2bool(compareAndExchangeByteAcquire(o, offset, bool2byte(expected), bool2byte(x)));
1695     }
1696 
1697     @ForceInline
1698     public final boolean compareAndExchangeBooleanRelease(Object o, long offset,
1699                                                        boolean expected,
1700                                                        boolean x) {
1701         return byte2bool(compareAndExchangeByteRelease(o, offset, bool2byte(expected), bool2byte(x)));
1702     }
1703 
1704     @ForceInline
1705     public final boolean weakCompareAndSetBoolean(Object o, long offset,
1706                                                   boolean expected,
1707                                                   boolean x) {
1708         return weakCompareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));
1709     }
1710 
1711     @ForceInline
1712     public final boolean weakCompareAndSetBooleanAcquire(Object o, long offset,
1713                                                          boolean expected,
1714                                                          boolean x) {
1715         return weakCompareAndSetByteAcquire(o, offset, bool2byte(expected), bool2byte(x));
1716     }
1717 
1718     @ForceInline
1719     public final boolean weakCompareAndSetBooleanRelease(Object o, long offset,
1720                                                          boolean expected,
1721                                                          boolean x) {
1722         return weakCompareAndSetByteRelease(o, offset, bool2byte(expected), bool2byte(x));
1723     }
1724 
1725     @ForceInline
1726     public final boolean weakCompareAndSetBooleanPlain(Object o, long offset,
1727                                                        boolean expected,
1728                                                        boolean x) {
1729         return weakCompareAndSetBytePlain(o, offset, bool2byte(expected), bool2byte(x));
1730     }
1731 
1732     /**
1733      * Atomically updates Java variable to {@code x} if it is currently
1734      * holding {@code expected}.
1735      *
1736      * <p>This operation has memory semantics of a {@code volatile} read
1737      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1738      *
1739      * @return {@code true} if successful
1740      */
1741     @ForceInline
1742     public final boolean compareAndSetFloat(Object o, long offset,
1743                                             float expected,
1744                                             float x) {
1745         return compareAndSetInt(o, offset,
1746                                  Float.floatToRawIntBits(expected),
1747                                  Float.floatToRawIntBits(x));
1748     }
1749 
1750     @ForceInline
1751     public final float compareAndExchangeFloat(Object o, long offset,
1752                                                float expected,
1753                                                float x) {
1754         int w = compareAndExchangeInt(o, offset,
1755                                       Float.floatToRawIntBits(expected),
1756                                       Float.floatToRawIntBits(x));
1757         return Float.intBitsToFloat(w);
1758     }
1759 
1760     @ForceInline
1761     public final float compareAndExchangeFloatAcquire(Object o, long offset,
1762                                                   float expected,
1763                                                   float x) {
1764         int w = compareAndExchangeIntAcquire(o, offset,
1765                                              Float.floatToRawIntBits(expected),
1766                                              Float.floatToRawIntBits(x));
1767         return Float.intBitsToFloat(w);
1768     }
1769 
1770     @ForceInline
1771     public final float compareAndExchangeFloatRelease(Object o, long offset,
1772                                                   float expected,
1773                                                   float x) {
1774         int w = compareAndExchangeIntRelease(o, offset,
1775                                              Float.floatToRawIntBits(expected),
1776                                              Float.floatToRawIntBits(x));
1777         return Float.intBitsToFloat(w);
1778     }
1779 
1780     @ForceInline
1781     public final boolean weakCompareAndSetFloatPlain(Object o, long offset,
1782                                                      float expected,
1783                                                      float x) {
1784         return weakCompareAndSetIntPlain(o, offset,
1785                                      Float.floatToRawIntBits(expected),
1786                                      Float.floatToRawIntBits(x));
1787     }
1788 
1789     @ForceInline
1790     public final boolean weakCompareAndSetFloatAcquire(Object o, long offset,
1791                                                        float expected,
1792                                                        float x) {
1793         return weakCompareAndSetIntAcquire(o, offset,
1794                                             Float.floatToRawIntBits(expected),
1795                                             Float.floatToRawIntBits(x));
1796     }
1797 
1798     @ForceInline
1799     public final boolean weakCompareAndSetFloatRelease(Object o, long offset,
1800                                                        float expected,
1801                                                        float x) {
1802         return weakCompareAndSetIntRelease(o, offset,
1803                                             Float.floatToRawIntBits(expected),
1804                                             Float.floatToRawIntBits(x));
1805     }
1806 
1807     @ForceInline
1808     public final boolean weakCompareAndSetFloat(Object o, long offset,
1809                                                 float expected,
1810                                                 float x) {
1811         return weakCompareAndSetInt(o, offset,
1812                                              Float.floatToRawIntBits(expected),
1813                                              Float.floatToRawIntBits(x));
1814     }
1815 
1816     /**
1817      * Atomically updates Java variable to {@code x} if it is currently
1818      * holding {@code expected}.
1819      *
1820      * <p>This operation has memory semantics of a {@code volatile} read
1821      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1822      *
1823      * @return {@code true} if successful
1824      */
1825     @ForceInline
1826     public final boolean compareAndSetDouble(Object o, long offset,
1827                                              double expected,
1828                                              double x) {
1829         return compareAndSetLong(o, offset,
1830                                  Double.doubleToRawLongBits(expected),
1831                                  Double.doubleToRawLongBits(x));
1832     }
1833 
1834     @ForceInline
1835     public final double compareAndExchangeDouble(Object o, long offset,
1836                                                  double expected,
1837                                                  double x) {
1838         long w = compareAndExchangeLong(o, offset,
1839                                         Double.doubleToRawLongBits(expected),
1840                                         Double.doubleToRawLongBits(x));
1841         return Double.longBitsToDouble(w);
1842     }
1843 
1844     @ForceInline
1845     public final double compareAndExchangeDoubleAcquire(Object o, long offset,
1846                                                         double expected,
1847                                                         double x) {
1848         long w = compareAndExchangeLongAcquire(o, offset,
1849                                                Double.doubleToRawLongBits(expected),
1850                                                Double.doubleToRawLongBits(x));
1851         return Double.longBitsToDouble(w);
1852     }
1853 
1854     @ForceInline
1855     public final double compareAndExchangeDoubleRelease(Object o, long offset,
1856                                                         double expected,
1857                                                         double x) {
1858         long w = compareAndExchangeLongRelease(o, offset,
1859                                                Double.doubleToRawLongBits(expected),
1860                                                Double.doubleToRawLongBits(x));
1861         return Double.longBitsToDouble(w);
1862     }
1863 
1864     @ForceInline
1865     public final boolean weakCompareAndSetDoublePlain(Object o, long offset,
1866                                                       double expected,
1867                                                       double x) {
1868         return weakCompareAndSetLongPlain(o, offset,
1869                                      Double.doubleToRawLongBits(expected),
1870                                      Double.doubleToRawLongBits(x));
1871     }
1872 
1873     @ForceInline
1874     public final boolean weakCompareAndSetDoubleAcquire(Object o, long offset,
1875                                                         double expected,
1876                                                         double x) {
1877         return weakCompareAndSetLongAcquire(o, offset,
1878                                              Double.doubleToRawLongBits(expected),
1879                                              Double.doubleToRawLongBits(x));
1880     }
1881 
1882     @ForceInline
1883     public final boolean weakCompareAndSetDoubleRelease(Object o, long offset,
1884                                                         double expected,
1885                                                         double x) {
1886         return weakCompareAndSetLongRelease(o, offset,
1887                                              Double.doubleToRawLongBits(expected),
1888                                              Double.doubleToRawLongBits(x));
1889     }
1890 
1891     @ForceInline
1892     public final boolean weakCompareAndSetDouble(Object o, long offset,
1893                                                  double expected,
1894                                                  double x) {
1895         return weakCompareAndSetLong(o, offset,
1896                                               Double.doubleToRawLongBits(expected),
1897                                               Double.doubleToRawLongBits(x));
1898     }
1899 
1900     /**
1901      * Atomically updates Java variable to {@code x} if it is currently
1902      * holding {@code expected}.
1903      *
1904      * <p>This operation has memory semantics of a {@code volatile} read
1905      * and write.  Corresponds to C11 atomic_compare_exchange_strong.
1906      *
1907      * @return {@code true} if successful
1908      */
1909     @HotSpotIntrinsicCandidate
1910     public final native boolean compareAndSetLong(Object o, long offset,
1911                                                   long expected,
1912                                                   long x);
1913 
1914     @HotSpotIntrinsicCandidate
1915     public final native long compareAndExchangeLong(Object o, long offset,
1916                                                     long expected,
1917                                                     long x);
1918 
1919     @HotSpotIntrinsicCandidate
1920     public final long compareAndExchangeLongAcquire(Object o, long offset,
1921                                                            long expected,
1922                                                            long x) {
1923         return compareAndExchangeLong(o, offset, expected, x);
1924     }
1925 
1926     @HotSpotIntrinsicCandidate
1927     public final long compareAndExchangeLongRelease(Object o, long offset,
1928                                                            long expected,
1929                                                            long x) {
1930         return compareAndExchangeLong(o, offset, expected, x);
1931     }
1932 
1933     @HotSpotIntrinsicCandidate
1934     public final boolean weakCompareAndSetLongPlain(Object o, long offset,
1935                                                     long expected,
1936                                                     long x) {
1937         return compareAndSetLong(o, offset, expected, x);
1938     }
1939 
1940     @HotSpotIntrinsicCandidate
1941     public final boolean weakCompareAndSetLongAcquire(Object o, long offset,
1942                                                       long expected,
1943                                                       long x) {
1944         return compareAndSetLong(o, offset, expected, x);
1945     }
1946 
1947     @HotSpotIntrinsicCandidate
1948     public final boolean weakCompareAndSetLongRelease(Object o, long offset,
1949                                                       long expected,
1950                                                       long x) {
1951         return compareAndSetLong(o, offset, expected, x);
1952     }
1953 
1954     @HotSpotIntrinsicCandidate
1955     public final boolean weakCompareAndSetLong(Object o, long offset,
1956                                                long expected,
1957                                                long x) {
1958         return compareAndSetLong(o, offset, expected, x);
1959     }
1960 
1961     /**
1962      * Fetches a reference value from a given Java variable, with volatile
1963      * load semantics. Otherwise identical to {@link #getReference(Object, long)}
1964      */
1965     @HotSpotIntrinsicCandidate
1966     public native Object getReferenceVolatile(Object o, long offset);
1967 
1968     /**
1969      * Stores a reference value into a given Java variable, with
1970      * volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}
1971      */
1972     @HotSpotIntrinsicCandidate
1973     public native void putReferenceVolatile(Object o, long offset, Object x);
1974 
1975     /** Volatile version of {@link #getInt(Object, long)}  */
1976     @HotSpotIntrinsicCandidate
1977     public native int     getIntVolatile(Object o, long offset);
1978 
1979     /** Volatile version of {@link #putInt(Object, long, int)}  */
1980     @HotSpotIntrinsicCandidate
1981     public native void    putIntVolatile(Object o, long offset, int x);
1982 
1983     /** Volatile version of {@link #getBoolean(Object, long)}  */
1984     @HotSpotIntrinsicCandidate
1985     public native boolean getBooleanVolatile(Object o, long offset);
1986 
1987     /** Volatile version of {@link #putBoolean(Object, long, boolean)}  */
1988     @HotSpotIntrinsicCandidate
1989     public native void    putBooleanVolatile(Object o, long offset, boolean x);
1990 
1991     /** Volatile version of {@link #getByte(Object, long)}  */
1992     @HotSpotIntrinsicCandidate
1993     public native byte    getByteVolatile(Object o, long offset);
1994 
1995     /** Volatile version of {@link #putByte(Object, long, byte)}  */
1996     @HotSpotIntrinsicCandidate
1997     public native void    putByteVolatile(Object o, long offset, byte x);
1998 
1999     /** Volatile version of {@link #getShort(Object, long)}  */
2000     @HotSpotIntrinsicCandidate
2001     public native short   getShortVolatile(Object o, long offset);
2002 
2003     /** Volatile version of {@link #putShort(Object, long, short)}  */
2004     @HotSpotIntrinsicCandidate
2005     public native void    putShortVolatile(Object o, long offset, short x);
2006 
2007     /** Volatile version of {@link #getChar(Object, long)}  */
2008     @HotSpotIntrinsicCandidate
2009     public native char    getCharVolatile(Object o, long offset);
2010 
2011     /** Volatile version of {@link #putChar(Object, long, char)}  */
2012     @HotSpotIntrinsicCandidate
2013     public native void    putCharVolatile(Object o, long offset, char x);
2014 
2015     /** Volatile version of {@link #getLong(Object, long)}  */
2016     @HotSpotIntrinsicCandidate
2017     public native long    getLongVolatile(Object o, long offset);
2018 
2019     /** Volatile version of {@link #putLong(Object, long, long)}  */
2020     @HotSpotIntrinsicCandidate
2021     public native void    putLongVolatile(Object o, long offset, long x);
2022 
2023     /** Volatile version of {@link #getFloat(Object, long)}  */
2024     @HotSpotIntrinsicCandidate
2025     public native float   getFloatVolatile(Object o, long offset);
2026 
2027     /** Volatile version of {@link #putFloat(Object, long, float)}  */
2028     @HotSpotIntrinsicCandidate
2029     public native void    putFloatVolatile(Object o, long offset, float x);
2030 
2031     /** Volatile version of {@link #getDouble(Object, long)}  */
2032     @HotSpotIntrinsicCandidate
2033     public native double  getDoubleVolatile(Object o, long offset);
2034 
2035     /** Volatile version of {@link #putDouble(Object, long, double)}  */
2036     @HotSpotIntrinsicCandidate
2037     public native void    putDoubleVolatile(Object o, long offset, double x);
2038 
2039 
2040 
2041     /** Acquire version of {@link #getReferenceVolatile(Object, long)} */
2042     @HotSpotIntrinsicCandidate
2043     public final Object getReferenceAcquire(Object o, long offset) {
2044         return getReferenceVolatile(o, offset);
2045     }
2046 
2047     /** Acquire version of {@link #getBooleanVolatile(Object, long)} */
2048     @HotSpotIntrinsicCandidate
2049     public final boolean getBooleanAcquire(Object o, long offset) {
2050         return getBooleanVolatile(o, offset);
2051     }
2052 
2053     /** Acquire version of {@link #getByteVolatile(Object, long)} */
2054     @HotSpotIntrinsicCandidate
2055     public final byte getByteAcquire(Object o, long offset) {
2056         return getByteVolatile(o, offset);
2057     }
2058 
2059     /** Acquire version of {@link #getShortVolatile(Object, long)} */
2060     @HotSpotIntrinsicCandidate
2061     public final short getShortAcquire(Object o, long offset) {
2062         return getShortVolatile(o, offset);
2063     }
2064 
2065     /** Acquire version of {@link #getCharVolatile(Object, long)} */
2066     @HotSpotIntrinsicCandidate
2067     public final char getCharAcquire(Object o, long offset) {
2068         return getCharVolatile(o, offset);
2069     }
2070 
2071     /** Acquire version of {@link #getIntVolatile(Object, long)} */
2072     @HotSpotIntrinsicCandidate
2073     public final int getIntAcquire(Object o, long offset) {
2074         return getIntVolatile(o, offset);
2075     }
2076 
2077     /** Acquire version of {@link #getFloatVolatile(Object, long)} */
2078     @HotSpotIntrinsicCandidate
2079     public final float getFloatAcquire(Object o, long offset) {
2080         return getFloatVolatile(o, offset);
2081     }
2082 
2083     /** Acquire version of {@link #getLongVolatile(Object, long)} */
2084     @HotSpotIntrinsicCandidate
2085     public final long getLongAcquire(Object o, long offset) {
2086         return getLongVolatile(o, offset);
2087     }
2088 
2089     /** Acquire version of {@link #getDoubleVolatile(Object, long)} */
2090     @HotSpotIntrinsicCandidate
2091     public final double getDoubleAcquire(Object o, long offset) {
2092         return getDoubleVolatile(o, offset);
2093     }
2094 
2095     /*
2096       * Versions of {@link #putReferenceVolatile(Object, long, Object)}
2097       * that do not guarantee immediate visibility of the store to
2098       * other threads. This method is generally only useful if the
2099       * underlying field is a Java volatile (or if an array cell, one
2100       * that is otherwise only accessed using volatile accesses).
2101       *
2102       * Corresponds to C11 atomic_store_explicit(..., memory_order_release).
2103       */
2104 
2105     /** Release version of {@link #putReferenceVolatile(Object, long, Object)} */
2106     @HotSpotIntrinsicCandidate
2107     public final void putReferenceRelease(Object o, long offset, Object x) {
2108         putReferenceVolatile(o, offset, x);
2109     }
2110 
2111     /** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */
2112     @HotSpotIntrinsicCandidate
2113     public final void putBooleanRelease(Object o, long offset, boolean x) {
2114         putBooleanVolatile(o, offset, x);
2115     }
2116 
2117     /** Release version of {@link #putByteVolatile(Object, long, byte)} */
2118     @HotSpotIntrinsicCandidate
2119     public final void putByteRelease(Object o, long offset, byte x) {
2120         putByteVolatile(o, offset, x);
2121     }
2122 
2123     /** Release version of {@link #putShortVolatile(Object, long, short)} */
2124     @HotSpotIntrinsicCandidate
2125     public final void putShortRelease(Object o, long offset, short x) {
2126         putShortVolatile(o, offset, x);
2127     }
2128 
2129     /** Release version of {@link #putCharVolatile(Object, long, char)} */
2130     @HotSpotIntrinsicCandidate
2131     public final void putCharRelease(Object o, long offset, char x) {
2132         putCharVolatile(o, offset, x);
2133     }
2134 
2135     /** Release version of {@link #putIntVolatile(Object, long, int)} */
2136     @HotSpotIntrinsicCandidate
2137     public final void putIntRelease(Object o, long offset, int x) {
2138         putIntVolatile(o, offset, x);
2139     }
2140 
2141     /** Release version of {@link #putFloatVolatile(Object, long, float)} */
2142     @HotSpotIntrinsicCandidate
2143     public final void putFloatRelease(Object o, long offset, float x) {
2144         putFloatVolatile(o, offset, x);
2145     }
2146 
2147     /** Release version of {@link #putLongVolatile(Object, long, long)} */
2148     @HotSpotIntrinsicCandidate
2149     public final void putLongRelease(Object o, long offset, long x) {
2150         putLongVolatile(o, offset, x);
2151     }
2152 
2153     /** Release version of {@link #putDoubleVolatile(Object, long, double)} */
2154     @HotSpotIntrinsicCandidate
2155     public final void putDoubleRelease(Object o, long offset, double x) {
2156         putDoubleVolatile(o, offset, x);
2157     }
2158 
2159     // ------------------------------ Opaque --------------------------------------
2160 
2161     /** Opaque version of {@link #getReferenceVolatile(Object, long)} */
2162     @HotSpotIntrinsicCandidate
2163     public final Object getReferenceOpaque(Object o, long offset) {
2164         return getReferenceVolatile(o, offset);
2165     }
2166 
2167     /** Opaque version of {@link #getBooleanVolatile(Object, long)} */
2168     @HotSpotIntrinsicCandidate
2169     public final boolean getBooleanOpaque(Object o, long offset) {
2170         return getBooleanVolatile(o, offset);
2171     }
2172 
2173     /** Opaque version of {@link #getByteVolatile(Object, long)} */
2174     @HotSpotIntrinsicCandidate
2175     public final byte getByteOpaque(Object o, long offset) {
2176         return getByteVolatile(o, offset);
2177     }
2178 
2179     /** Opaque version of {@link #getShortVolatile(Object, long)} */
2180     @HotSpotIntrinsicCandidate
2181     public final short getShortOpaque(Object o, long offset) {
2182         return getShortVolatile(o, offset);
2183     }
2184 
2185     /** Opaque version of {@link #getCharVolatile(Object, long)} */
2186     @HotSpotIntrinsicCandidate
2187     public final char getCharOpaque(Object o, long offset) {
2188         return getCharVolatile(o, offset);
2189     }
2190 
2191     /** Opaque version of {@link #getIntVolatile(Object, long)} */
2192     @HotSpotIntrinsicCandidate
2193     public final int getIntOpaque(Object o, long offset) {
2194         return getIntVolatile(o, offset);
2195     }
2196 
2197     /** Opaque version of {@link #getFloatVolatile(Object, long)} */
2198     @HotSpotIntrinsicCandidate
2199     public final float getFloatOpaque(Object o, long offset) {
2200         return getFloatVolatile(o, offset);
2201     }
2202 
2203     /** Opaque version of {@link #getLongVolatile(Object, long)} */
2204     @HotSpotIntrinsicCandidate
2205     public final long getLongOpaque(Object o, long offset) {
2206         return getLongVolatile(o, offset);
2207     }
2208 
2209     /** Opaque version of {@link #getDoubleVolatile(Object, long)} */
2210     @HotSpotIntrinsicCandidate
2211     public final double getDoubleOpaque(Object o, long offset) {
2212         return getDoubleVolatile(o, offset);
2213     }
2214 
2215     /** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */
2216     @HotSpotIntrinsicCandidate
2217     public final void putReferenceOpaque(Object o, long offset, Object x) {
2218         putReferenceVolatile(o, offset, x);
2219     }
2220 
2221     /** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */
2222     @HotSpotIntrinsicCandidate
2223     public final void putBooleanOpaque(Object o, long offset, boolean x) {
2224         putBooleanVolatile(o, offset, x);
2225     }
2226 
2227     /** Opaque version of {@link #putByteVolatile(Object, long, byte)} */
2228     @HotSpotIntrinsicCandidate
2229     public final void putByteOpaque(Object o, long offset, byte x) {
2230         putByteVolatile(o, offset, x);
2231     }
2232 
2233     /** Opaque version of {@link #putShortVolatile(Object, long, short)} */
2234     @HotSpotIntrinsicCandidate
2235     public final void putShortOpaque(Object o, long offset, short x) {
2236         putShortVolatile(o, offset, x);
2237     }
2238 
2239     /** Opaque version of {@link #putCharVolatile(Object, long, char)} */
2240     @HotSpotIntrinsicCandidate
2241     public final void putCharOpaque(Object o, long offset, char x) {
2242         putCharVolatile(o, offset, x);
2243     }
2244 
2245     /** Opaque version of {@link #putIntVolatile(Object, long, int)} */
2246     @HotSpotIntrinsicCandidate
2247     public final void putIntOpaque(Object o, long offset, int x) {
2248         putIntVolatile(o, offset, x);
2249     }
2250 
2251     /** Opaque version of {@link #putFloatVolatile(Object, long, float)} */
2252     @HotSpotIntrinsicCandidate
2253     public final void putFloatOpaque(Object o, long offset, float x) {
2254         putFloatVolatile(o, offset, x);
2255     }
2256 
2257     /** Opaque version of {@link #putLongVolatile(Object, long, long)} */
2258     @HotSpotIntrinsicCandidate
2259     public final void putLongOpaque(Object o, long offset, long x) {
2260         putLongVolatile(o, offset, x);
2261     }
2262 
2263     /** Opaque version of {@link #putDoubleVolatile(Object, long, double)} */
2264     @HotSpotIntrinsicCandidate
2265     public final void putDoubleOpaque(Object o, long offset, double x) {
2266         putDoubleVolatile(o, offset, x);
2267     }
2268 
2269     /**
2270      * Unblocks the given thread blocked on {@code park}, or, if it is
2271      * not blocked, causes the subsequent call to {@code park} not to
2272      * block.  Note: this operation is "unsafe" solely because the
2273      * caller must somehow ensure that the thread has not been
2274      * destroyed. Nothing special is usually required to ensure this
2275      * when called from Java (in which there will ordinarily be a live
2276      * reference to the thread) but this is not nearly-automatically
2277      * so when calling from native code.
2278      *
2279      * @param thread the thread to unpark.
2280      */
2281     @HotSpotIntrinsicCandidate
2282     public native void unpark(Object thread);
2283 
2284     /**
2285      * Blocks current thread, returning when a balancing
2286      * {@code unpark} occurs, or a balancing {@code unpark} has
2287      * already occurred, or the thread is interrupted, or, if not
2288      * absolute and time is not zero, the given time nanoseconds have
2289      * elapsed, or if absolute, the given deadline in milliseconds
2290      * since Epoch has passed, or spuriously (i.e., returning for no
2291      * "reason"). Note: This operation is in the Unsafe class only
2292      * because {@code unpark} is, so it would be strange to place it
2293      * elsewhere.
2294      */
2295     @HotSpotIntrinsicCandidate
2296     public native void park(boolean isAbsolute, long time);
2297 
2298     /**
2299      * Gets the load average in the system run queue assigned
2300      * to the available processors averaged over various periods of time.
2301      * This method retrieves the given {@code nelem} samples and
2302      * assigns to the elements of the given {@code loadavg} array.
2303      * The system imposes a maximum of 3 samples, representing
2304      * averages over the last 1,  5,  and  15 minutes, respectively.
2305      *
2306      * @param loadavg an array of double of size nelems
2307      * @param nelems the number of samples to be retrieved and
2308      *        must be 1 to 3.
2309      *
2310      * @return the number of samples actually retrieved; or -1
2311      *         if the load average is unobtainable.
2312      */
2313     public int getLoadAverage(double[] loadavg, int nelems) {
2314         if (nelems < 0 || nelems > 3 || nelems > loadavg.length) {
2315             throw new ArrayIndexOutOfBoundsException();
2316         }
2317 
2318         return getLoadAverage0(loadavg, nelems);
2319     }
2320 
2321     // The following contain CAS-based Java implementations used on
2322     // platforms not supporting native instructions
2323 
2324     /**
2325      * Atomically adds the given value to the current value of a field
2326      * or array element within the given object {@code o}
2327      * at the given {@code offset}.
2328      *
2329      * @param o object/array to update the field/element in
2330      * @param offset field/element offset
2331      * @param delta the value to add
2332      * @return the previous value
2333      * @since 1.8
2334      */
2335     @HotSpotIntrinsicCandidate
2336     public final int getAndAddInt(Object o, long offset, int delta) {
2337         int v;
2338         do {
2339             v = getIntVolatile(o, offset);
2340         } while (!weakCompareAndSetInt(o, offset, v, v + delta));
2341         return v;
2342     }
2343 
2344     @ForceInline
2345     public final int getAndAddIntRelease(Object o, long offset, int delta) {
2346         int v;
2347         do {
2348             v = getInt(o, offset);
2349         } while (!weakCompareAndSetIntRelease(o, offset, v, v + delta));
2350         return v;
2351     }
2352 
2353     @ForceInline
2354     public final int getAndAddIntAcquire(Object o, long offset, int delta) {
2355         int v;
2356         do {
2357             v = getIntAcquire(o, offset);
2358         } while (!weakCompareAndSetIntAcquire(o, offset, v, v + delta));
2359         return v;
2360     }
2361 
2362     /**
2363      * Atomically adds the given value to the current value of a field
2364      * or array element within the given object {@code o}
2365      * at the given {@code offset}.
2366      *
2367      * @param o object/array to update the field/element in
2368      * @param offset field/element offset
2369      * @param delta the value to add
2370      * @return the previous value
2371      * @since 1.8
2372      */
2373     @HotSpotIntrinsicCandidate
2374     public final long getAndAddLong(Object o, long offset, long delta) {
2375         long v;
2376         do {
2377             v = getLongVolatile(o, offset);
2378         } while (!weakCompareAndSetLong(o, offset, v, v + delta));
2379         return v;
2380     }
2381 
2382     @ForceInline
2383     public final long getAndAddLongRelease(Object o, long offset, long delta) {
2384         long v;
2385         do {
2386             v = getLong(o, offset);
2387         } while (!weakCompareAndSetLongRelease(o, offset, v, v + delta));
2388         return v;
2389     }
2390 
2391     @ForceInline
2392     public final long getAndAddLongAcquire(Object o, long offset, long delta) {
2393         long v;
2394         do {
2395             v = getLongAcquire(o, offset);
2396         } while (!weakCompareAndSetLongAcquire(o, offset, v, v + delta));
2397         return v;
2398     }
2399 
2400     @HotSpotIntrinsicCandidate
2401     public final byte getAndAddByte(Object o, long offset, byte delta) {
2402         byte v;
2403         do {
2404             v = getByteVolatile(o, offset);
2405         } while (!weakCompareAndSetByte(o, offset, v, (byte) (v + delta)));
2406         return v;
2407     }
2408 
2409     @ForceInline
2410     public final byte getAndAddByteRelease(Object o, long offset, byte delta) {
2411         byte v;
2412         do {
2413             v = getByte(o, offset);
2414         } while (!weakCompareAndSetByteRelease(o, offset, v, (byte) (v + delta)));
2415         return v;
2416     }
2417 
2418     @ForceInline
2419     public final byte getAndAddByteAcquire(Object o, long offset, byte delta) {
2420         byte v;
2421         do {
2422             v = getByteAcquire(o, offset);
2423         } while (!weakCompareAndSetByteAcquire(o, offset, v, (byte) (v + delta)));
2424         return v;
2425     }
2426 
2427     @HotSpotIntrinsicCandidate
2428     public final short getAndAddShort(Object o, long offset, short delta) {
2429         short v;
2430         do {
2431             v = getShortVolatile(o, offset);
2432         } while (!weakCompareAndSetShort(o, offset, v, (short) (v + delta)));
2433         return v;
2434     }
2435 
2436     @ForceInline
2437     public final short getAndAddShortRelease(Object o, long offset, short delta) {
2438         short v;
2439         do {
2440             v = getShort(o, offset);
2441         } while (!weakCompareAndSetShortRelease(o, offset, v, (short) (v + delta)));
2442         return v;
2443     }
2444 
2445     @ForceInline
2446     public final short getAndAddShortAcquire(Object o, long offset, short delta) {
2447         short v;
2448         do {
2449             v = getShortAcquire(o, offset);
2450         } while (!weakCompareAndSetShortAcquire(o, offset, v, (short) (v + delta)));
2451         return v;
2452     }
2453 
2454     @ForceInline
2455     public final char getAndAddChar(Object o, long offset, char delta) {
2456         return (char) getAndAddShort(o, offset, (short) delta);
2457     }
2458 
2459     @ForceInline
2460     public final char getAndAddCharRelease(Object o, long offset, char delta) {
2461         return (char) getAndAddShortRelease(o, offset, (short) delta);
2462     }
2463 
2464     @ForceInline
2465     public final char getAndAddCharAcquire(Object o, long offset, char delta) {
2466         return (char) getAndAddShortAcquire(o, offset, (short) delta);
2467     }
2468 
2469     @ForceInline
2470     public final float getAndAddFloat(Object o, long offset, float delta) {
2471         int expectedBits;
2472         float v;
2473         do {
2474             // Load and CAS with the raw bits to avoid issues with NaNs and
2475             // possible bit conversion from signaling NaNs to quiet NaNs that
2476             // may result in the loop not terminating.
2477             expectedBits = getIntVolatile(o, offset);
2478             v = Float.intBitsToFloat(expectedBits);
2479         } while (!weakCompareAndSetInt(o, offset,
2480                                                 expectedBits, Float.floatToRawIntBits(v + delta)));
2481         return v;
2482     }
2483 
2484     @ForceInline
2485     public final float getAndAddFloatRelease(Object o, long offset, float delta) {
2486         int expectedBits;
2487         float v;
2488         do {
2489             // Load and CAS with the raw bits to avoid issues with NaNs and
2490             // possible bit conversion from signaling NaNs to quiet NaNs that
2491             // may result in the loop not terminating.
2492             expectedBits = getInt(o, offset);
2493             v = Float.intBitsToFloat(expectedBits);
2494         } while (!weakCompareAndSetIntRelease(o, offset,
2495                                                expectedBits, Float.floatToRawIntBits(v + delta)));
2496         return v;
2497     }
2498 
2499     @ForceInline
2500     public final float getAndAddFloatAcquire(Object o, long offset, float delta) {
2501         int expectedBits;
2502         float v;
2503         do {
2504             // Load and CAS with the raw bits to avoid issues with NaNs and
2505             // possible bit conversion from signaling NaNs to quiet NaNs that
2506             // may result in the loop not terminating.
2507             expectedBits = getIntAcquire(o, offset);
2508             v = Float.intBitsToFloat(expectedBits);
2509         } while (!weakCompareAndSetIntAcquire(o, offset,
2510                                                expectedBits, Float.floatToRawIntBits(v + delta)));
2511         return v;
2512     }
2513 
2514     @ForceInline
2515     public final double getAndAddDouble(Object o, long offset, double delta) {
2516         long expectedBits;
2517         double v;
2518         do {
2519             // Load and CAS with the raw bits to avoid issues with NaNs and
2520             // possible bit conversion from signaling NaNs to quiet NaNs that
2521             // may result in the loop not terminating.
2522             expectedBits = getLongVolatile(o, offset);
2523             v = Double.longBitsToDouble(expectedBits);
2524         } while (!weakCompareAndSetLong(o, offset,
2525                                                  expectedBits, Double.doubleToRawLongBits(v + delta)));
2526         return v;
2527     }
2528 
2529     @ForceInline
2530     public final double getAndAddDoubleRelease(Object o, long offset, double delta) {
2531         long expectedBits;
2532         double v;
2533         do {
2534             // Load and CAS with the raw bits to avoid issues with NaNs and
2535             // possible bit conversion from signaling NaNs to quiet NaNs that
2536             // may result in the loop not terminating.
2537             expectedBits = getLong(o, offset);
2538             v = Double.longBitsToDouble(expectedBits);
2539         } while (!weakCompareAndSetLongRelease(o, offset,
2540                                                 expectedBits, Double.doubleToRawLongBits(v + delta)));
2541         return v;
2542     }
2543 
2544     @ForceInline
2545     public final double getAndAddDoubleAcquire(Object o, long offset, double delta) {
2546         long expectedBits;
2547         double v;
2548         do {
2549             // Load and CAS with the raw bits to avoid issues with NaNs and
2550             // possible bit conversion from signaling NaNs to quiet NaNs that
2551             // may result in the loop not terminating.
2552             expectedBits = getLongAcquire(o, offset);
2553             v = Double.longBitsToDouble(expectedBits);
2554         } while (!weakCompareAndSetLongAcquire(o, offset,
2555                                                 expectedBits, Double.doubleToRawLongBits(v + delta)));
2556         return v;
2557     }
2558 
2559     /**
2560      * Atomically exchanges the given value with the current value of
2561      * a field or array element within the given object {@code o}
2562      * at the given {@code offset}.
2563      *
2564      * @param o object/array to update the field/element in
2565      * @param offset field/element offset
2566      * @param newValue new value
2567      * @return the previous value
2568      * @since 1.8
2569      */
2570     @HotSpotIntrinsicCandidate
2571     public final int getAndSetInt(Object o, long offset, int newValue) {
2572         int v;
2573         do {
2574             v = getIntVolatile(o, offset);
2575         } while (!weakCompareAndSetInt(o, offset, v, newValue));
2576         return v;
2577     }
2578 
2579     @ForceInline
2580     public final int getAndSetIntRelease(Object o, long offset, int newValue) {
2581         int v;
2582         do {
2583             v = getInt(o, offset);
2584         } while (!weakCompareAndSetIntRelease(o, offset, v, newValue));
2585         return v;
2586     }
2587 
2588     @ForceInline
2589     public final int getAndSetIntAcquire(Object o, long offset, int newValue) {
2590         int v;
2591         do {
2592             v = getIntAcquire(o, offset);
2593         } while (!weakCompareAndSetIntAcquire(o, offset, v, newValue));
2594         return v;
2595     }
2596 
2597     /**
2598      * Atomically exchanges the given value with the current value of
2599      * a field or array element within the given object {@code o}
2600      * at the given {@code offset}.
2601      *
2602      * @param o object/array to update the field/element in
2603      * @param offset field/element offset
2604      * @param newValue new value
2605      * @return the previous value
2606      * @since 1.8
2607      */
2608     @HotSpotIntrinsicCandidate
2609     public final long getAndSetLong(Object o, long offset, long newValue) {
2610         long v;
2611         do {
2612             v = getLongVolatile(o, offset);
2613         } while (!weakCompareAndSetLong(o, offset, v, newValue));
2614         return v;
2615     }
2616 
2617     @ForceInline
2618     public final long getAndSetLongRelease(Object o, long offset, long newValue) {
2619         long v;
2620         do {
2621             v = getLong(o, offset);
2622         } while (!weakCompareAndSetLongRelease(o, offset, v, newValue));
2623         return v;
2624     }
2625 
2626     @ForceInline
2627     public final long getAndSetLongAcquire(Object o, long offset, long newValue) {
2628         long v;
2629         do {
2630             v = getLongAcquire(o, offset);
2631         } while (!weakCompareAndSetLongAcquire(o, offset, v, newValue));
2632         return v;
2633     }
2634 
2635     /**
2636      * Atomically exchanges the given reference value with the current
2637      * reference value of a field or array element within the given
2638      * object {@code o} at the given {@code offset}.
2639      *
2640      * @param o object/array to update the field/element in
2641      * @param offset field/element offset
2642      * @param newValue new value
2643      * @return the previous value
2644      * @since 1.8
2645      */
2646     @HotSpotIntrinsicCandidate
2647     public final Object getAndSetReference(Object o, long offset, Object newValue) {
2648         Object v;
2649         do {
2650             v = getReferenceVolatile(o, offset);
2651         } while (!weakCompareAndSetReference(o, offset, v, newValue));
2652         return v;
2653     }
2654 
2655     @ForceInline
2656     public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {
2657         Object v;
2658         do {
2659             v = getReference(o, offset);
2660         } while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));
2661         return v;
2662     }
2663 
2664     @ForceInline
2665     public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {
2666         Object v;
2667         do {
2668             v = getReferenceAcquire(o, offset);
2669         } while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));
2670         return v;
2671     }
2672 
2673     @HotSpotIntrinsicCandidate
2674     public final byte getAndSetByte(Object o, long offset, byte newValue) {
2675         byte v;
2676         do {
2677             v = getByteVolatile(o, offset);
2678         } while (!weakCompareAndSetByte(o, offset, v, newValue));
2679         return v;
2680     }
2681 
2682     @ForceInline
2683     public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {
2684         byte v;
2685         do {
2686             v = getByte(o, offset);
2687         } while (!weakCompareAndSetByteRelease(o, offset, v, newValue));
2688         return v;
2689     }
2690 
2691     @ForceInline
2692     public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {
2693         byte v;
2694         do {
2695             v = getByteAcquire(o, offset);
2696         } while (!weakCompareAndSetByteAcquire(o, offset, v, newValue));
2697         return v;
2698     }
2699 
2700     @ForceInline
2701     public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) {
2702         return byte2bool(getAndSetByte(o, offset, bool2byte(newValue)));
2703     }
2704 
2705     @ForceInline
2706     public final boolean getAndSetBooleanRelease(Object o, long offset, boolean newValue) {
2707         return byte2bool(getAndSetByteRelease(o, offset, bool2byte(newValue)));
2708     }
2709 
2710     @ForceInline
2711     public final boolean getAndSetBooleanAcquire(Object o, long offset, boolean newValue) {
2712         return byte2bool(getAndSetByteAcquire(o, offset, bool2byte(newValue)));
2713     }
2714 
2715     @HotSpotIntrinsicCandidate
2716     public final short getAndSetShort(Object o, long offset, short newValue) {
2717         short v;
2718         do {
2719             v = getShortVolatile(o, offset);
2720         } while (!weakCompareAndSetShort(o, offset, v, newValue));
2721         return v;
2722     }
2723 
2724     @ForceInline
2725     public final short getAndSetShortRelease(Object o, long offset, short newValue) {
2726         short v;
2727         do {
2728             v = getShort(o, offset);
2729         } while (!weakCompareAndSetShortRelease(o, offset, v, newValue));
2730         return v;
2731     }
2732 
2733     @ForceInline
2734     public final short getAndSetShortAcquire(Object o, long offset, short newValue) {
2735         short v;
2736         do {
2737             v = getShortAcquire(o, offset);
2738         } while (!weakCompareAndSetShortAcquire(o, offset, v, newValue));
2739         return v;
2740     }
2741 
2742     @ForceInline
2743     public final char getAndSetChar(Object o, long offset, char newValue) {
2744         return s2c(getAndSetShort(o, offset, c2s(newValue)));
2745     }
2746 
2747     @ForceInline
2748     public final char getAndSetCharRelease(Object o, long offset, char newValue) {
2749         return s2c(getAndSetShortRelease(o, offset, c2s(newValue)));
2750     }
2751 
2752     @ForceInline
2753     public final char getAndSetCharAcquire(Object o, long offset, char newValue) {
2754         return s2c(getAndSetShortAcquire(o, offset, c2s(newValue)));
2755     }
2756 
2757     @ForceInline
2758     public final float getAndSetFloat(Object o, long offset, float newValue) {
2759         int v = getAndSetInt(o, offset, Float.floatToRawIntBits(newValue));
2760         return Float.intBitsToFloat(v);
2761     }
2762 
2763     @ForceInline
2764     public final float getAndSetFloatRelease(Object o, long offset, float newValue) {
2765         int v = getAndSetIntRelease(o, offset, Float.floatToRawIntBits(newValue));
2766         return Float.intBitsToFloat(v);
2767     }
2768 
2769     @ForceInline
2770     public final float getAndSetFloatAcquire(Object o, long offset, float newValue) {
2771         int v = getAndSetIntAcquire(o, offset, Float.floatToRawIntBits(newValue));
2772         return Float.intBitsToFloat(v);
2773     }
2774 
2775     @ForceInline
2776     public final double getAndSetDouble(Object o, long offset, double newValue) {
2777         long v = getAndSetLong(o, offset, Double.doubleToRawLongBits(newValue));
2778         return Double.longBitsToDouble(v);
2779     }
2780 
2781     @ForceInline
2782     public final double getAndSetDoubleRelease(Object o, long offset, double newValue) {
2783         long v = getAndSetLongRelease(o, offset, Double.doubleToRawLongBits(newValue));
2784         return Double.longBitsToDouble(v);
2785     }
2786 
2787     @ForceInline
2788     public final double getAndSetDoubleAcquire(Object o, long offset, double newValue) {
2789         long v = getAndSetLongAcquire(o, offset, Double.doubleToRawLongBits(newValue));
2790         return Double.longBitsToDouble(v);
2791     }
2792 
2793 
2794     // The following contain CAS-based Java implementations used on
2795     // platforms not supporting native instructions
2796 
2797     @ForceInline
2798     public final boolean getAndBitwiseOrBoolean(Object o, long offset, boolean mask) {
2799         return byte2bool(getAndBitwiseOrByte(o, offset, bool2byte(mask)));
2800     }
2801 
2802     @ForceInline
2803     public final boolean getAndBitwiseOrBooleanRelease(Object o, long offset, boolean mask) {
2804         return byte2bool(getAndBitwiseOrByteRelease(o, offset, bool2byte(mask)));
2805     }
2806 
2807     @ForceInline
2808     public final boolean getAndBitwiseOrBooleanAcquire(Object o, long offset, boolean mask) {
2809         return byte2bool(getAndBitwiseOrByteAcquire(o, offset, bool2byte(mask)));
2810     }
2811 
2812     @ForceInline
2813     public final boolean getAndBitwiseAndBoolean(Object o, long offset, boolean mask) {
2814         return byte2bool(getAndBitwiseAndByte(o, offset, bool2byte(mask)));
2815     }
2816 
2817     @ForceInline
2818     public final boolean getAndBitwiseAndBooleanRelease(Object o, long offset, boolean mask) {
2819         return byte2bool(getAndBitwiseAndByteRelease(o, offset, bool2byte(mask)));
2820     }
2821 
2822     @ForceInline
2823     public final boolean getAndBitwiseAndBooleanAcquire(Object o, long offset, boolean mask) {
2824         return byte2bool(getAndBitwiseAndByteAcquire(o, offset, bool2byte(mask)));
2825     }
2826 
2827     @ForceInline
2828     public final boolean getAndBitwiseXorBoolean(Object o, long offset, boolean mask) {
2829         return byte2bool(getAndBitwiseXorByte(o, offset, bool2byte(mask)));
2830     }
2831 
2832     @ForceInline
2833     public final boolean getAndBitwiseXorBooleanRelease(Object o, long offset, boolean mask) {
2834         return byte2bool(getAndBitwiseXorByteRelease(o, offset, bool2byte(mask)));
2835     }
2836 
2837     @ForceInline
2838     public final boolean getAndBitwiseXorBooleanAcquire(Object o, long offset, boolean mask) {
2839         return byte2bool(getAndBitwiseXorByteAcquire(o, offset, bool2byte(mask)));
2840     }
2841 
2842 
2843     @ForceInline
2844     public final byte getAndBitwiseOrByte(Object o, long offset, byte mask) {
2845         byte current;
2846         do {
2847             current = getByteVolatile(o, offset);
2848         } while (!weakCompareAndSetByte(o, offset,
2849                                                   current, (byte) (current | mask)));
2850         return current;
2851     }
2852 
2853     @ForceInline
2854     public final byte getAndBitwiseOrByteRelease(Object o, long offset, byte mask) {
2855         byte current;
2856         do {
2857             current = getByte(o, offset);
2858         } while (!weakCompareAndSetByteRelease(o, offset,
2859                                                  current, (byte) (current | mask)));
2860         return current;
2861     }
2862 
2863     @ForceInline
2864     public final byte getAndBitwiseOrByteAcquire(Object o, long offset, byte mask) {
2865         byte current;
2866         do {
2867             // Plain read, the value is a hint, the acquire CAS does the work
2868             current = getByte(o, offset);
2869         } while (!weakCompareAndSetByteAcquire(o, offset,
2870                                                  current, (byte) (current | mask)));
2871         return current;
2872     }
2873 
2874     @ForceInline
2875     public final byte getAndBitwiseAndByte(Object o, long offset, byte mask) {
2876         byte current;
2877         do {
2878             current = getByteVolatile(o, offset);
2879         } while (!weakCompareAndSetByte(o, offset,
2880                                                   current, (byte) (current & mask)));
2881         return current;
2882     }
2883 
2884     @ForceInline
2885     public final byte getAndBitwiseAndByteRelease(Object o, long offset, byte mask) {
2886         byte current;
2887         do {
2888             current = getByte(o, offset);
2889         } while (!weakCompareAndSetByteRelease(o, offset,
2890                                                  current, (byte) (current & mask)));
2891         return current;
2892     }
2893 
2894     @ForceInline
2895     public final byte getAndBitwiseAndByteAcquire(Object o, long offset, byte mask) {
2896         byte current;
2897         do {
2898             // Plain read, the value is a hint, the acquire CAS does the work
2899             current = getByte(o, offset);
2900         } while (!weakCompareAndSetByteAcquire(o, offset,
2901                                                  current, (byte) (current & mask)));
2902         return current;
2903     }
2904 
2905     @ForceInline
2906     public final byte getAndBitwiseXorByte(Object o, long offset, byte mask) {
2907         byte current;
2908         do {
2909             current = getByteVolatile(o, offset);
2910         } while (!weakCompareAndSetByte(o, offset,
2911                                                   current, (byte) (current ^ mask)));
2912         return current;
2913     }
2914 
2915     @ForceInline
2916     public final byte getAndBitwiseXorByteRelease(Object o, long offset, byte mask) {
2917         byte current;
2918         do {
2919             current = getByte(o, offset);
2920         } while (!weakCompareAndSetByteRelease(o, offset,
2921                                                  current, (byte) (current ^ mask)));
2922         return current;
2923     }
2924 
2925     @ForceInline
2926     public final byte getAndBitwiseXorByteAcquire(Object o, long offset, byte mask) {
2927         byte current;
2928         do {
2929             // Plain read, the value is a hint, the acquire CAS does the work
2930             current = getByte(o, offset);
2931         } while (!weakCompareAndSetByteAcquire(o, offset,
2932                                                  current, (byte) (current ^ mask)));
2933         return current;
2934     }
2935 
2936 
2937     @ForceInline
2938     public final char getAndBitwiseOrChar(Object o, long offset, char mask) {
2939         return s2c(getAndBitwiseOrShort(o, offset, c2s(mask)));
2940     }
2941 
2942     @ForceInline
2943     public final char getAndBitwiseOrCharRelease(Object o, long offset, char mask) {
2944         return s2c(getAndBitwiseOrShortRelease(o, offset, c2s(mask)));
2945     }
2946 
2947     @ForceInline
2948     public final char getAndBitwiseOrCharAcquire(Object o, long offset, char mask) {
2949         return s2c(getAndBitwiseOrShortAcquire(o, offset, c2s(mask)));
2950     }
2951 
2952     @ForceInline
2953     public final char getAndBitwiseAndChar(Object o, long offset, char mask) {
2954         return s2c(getAndBitwiseAndShort(o, offset, c2s(mask)));
2955     }
2956 
2957     @ForceInline
2958     public final char getAndBitwiseAndCharRelease(Object o, long offset, char mask) {
2959         return s2c(getAndBitwiseAndShortRelease(o, offset, c2s(mask)));
2960     }
2961 
2962     @ForceInline
2963     public final char getAndBitwiseAndCharAcquire(Object o, long offset, char mask) {
2964         return s2c(getAndBitwiseAndShortAcquire(o, offset, c2s(mask)));
2965     }
2966 
2967     @ForceInline
2968     public final char getAndBitwiseXorChar(Object o, long offset, char mask) {
2969         return s2c(getAndBitwiseXorShort(o, offset, c2s(mask)));
2970     }
2971 
2972     @ForceInline
2973     public final char getAndBitwiseXorCharRelease(Object o, long offset, char mask) {
2974         return s2c(getAndBitwiseXorShortRelease(o, offset, c2s(mask)));
2975     }
2976 
2977     @ForceInline
2978     public final char getAndBitwiseXorCharAcquire(Object o, long offset, char mask) {
2979         return s2c(getAndBitwiseXorShortAcquire(o, offset, c2s(mask)));
2980     }
2981 
2982 
2983     @ForceInline
2984     public final short getAndBitwiseOrShort(Object o, long offset, short mask) {
2985         short current;
2986         do {
2987             current = getShortVolatile(o, offset);
2988         } while (!weakCompareAndSetShort(o, offset,
2989                                                 current, (short) (current | mask)));
2990         return current;
2991     }
2992 
2993     @ForceInline
2994     public final short getAndBitwiseOrShortRelease(Object o, long offset, short mask) {
2995         short current;
2996         do {
2997             current = getShort(o, offset);
2998         } while (!weakCompareAndSetShortRelease(o, offset,
2999                                                current, (short) (current | mask)));
3000         return current;
3001     }
3002 
3003     @ForceInline
3004     public final short getAndBitwiseOrShortAcquire(Object o, long offset, short mask) {
3005         short current;
3006         do {
3007             // Plain read, the value is a hint, the acquire CAS does the work
3008             current = getShort(o, offset);
3009         } while (!weakCompareAndSetShortAcquire(o, offset,
3010                                                current, (short) (current | mask)));
3011         return current;
3012     }
3013 
3014     @ForceInline
3015     public final short getAndBitwiseAndShort(Object o, long offset, short mask) {
3016         short current;
3017         do {
3018             current = getShortVolatile(o, offset);
3019         } while (!weakCompareAndSetShort(o, offset,
3020                                                 current, (short) (current & mask)));
3021         return current;
3022     }
3023 
3024     @ForceInline
3025     public final short getAndBitwiseAndShortRelease(Object o, long offset, short mask) {
3026         short current;
3027         do {
3028             current = getShort(o, offset);
3029         } while (!weakCompareAndSetShortRelease(o, offset,
3030                                                current, (short) (current & mask)));
3031         return current;
3032     }
3033 
3034     @ForceInline
3035     public final short getAndBitwiseAndShortAcquire(Object o, long offset, short mask) {
3036         short current;
3037         do {
3038             // Plain read, the value is a hint, the acquire CAS does the work
3039             current = getShort(o, offset);
3040         } while (!weakCompareAndSetShortAcquire(o, offset,
3041                                                current, (short) (current & mask)));
3042         return current;
3043     }
3044 
3045     @ForceInline
3046     public final short getAndBitwiseXorShort(Object o, long offset, short mask) {
3047         short current;
3048         do {
3049             current = getShortVolatile(o, offset);
3050         } while (!weakCompareAndSetShort(o, offset,
3051                                                 current, (short) (current ^ mask)));
3052         return current;
3053     }
3054 
3055     @ForceInline
3056     public final short getAndBitwiseXorShortRelease(Object o, long offset, short mask) {
3057         short current;
3058         do {
3059             current = getShort(o, offset);
3060         } while (!weakCompareAndSetShortRelease(o, offset,
3061                                                current, (short) (current ^ mask)));
3062         return current;
3063     }
3064 
3065     @ForceInline
3066     public final short getAndBitwiseXorShortAcquire(Object o, long offset, short mask) {
3067         short current;
3068         do {
3069             // Plain read, the value is a hint, the acquire CAS does the work
3070             current = getShort(o, offset);
3071         } while (!weakCompareAndSetShortAcquire(o, offset,
3072                                                current, (short) (current ^ mask)));
3073         return current;
3074     }
3075 
3076 
3077     @ForceInline
3078     public final int getAndBitwiseOrInt(Object o, long offset, int mask) {
3079         int current;
3080         do {
3081             current = getIntVolatile(o, offset);
3082         } while (!weakCompareAndSetInt(o, offset,
3083                                                 current, current | mask));
3084         return current;
3085     }
3086 
3087     @ForceInline
3088     public final int getAndBitwiseOrIntRelease(Object o, long offset, int mask) {
3089         int current;
3090         do {
3091             current = getInt(o, offset);
3092         } while (!weakCompareAndSetIntRelease(o, offset,
3093                                                current, current | mask));
3094         return current;
3095     }
3096 
3097     @ForceInline
3098     public final int getAndBitwiseOrIntAcquire(Object o, long offset, int mask) {
3099         int current;
3100         do {
3101             // Plain read, the value is a hint, the acquire CAS does the work
3102             current = getInt(o, offset);
3103         } while (!weakCompareAndSetIntAcquire(o, offset,
3104                                                current, current | mask));
3105         return current;
3106     }
3107 
3108     /**
3109      * Atomically replaces the current value of a field or array element within
3110      * the given object with the result of bitwise AND between the current value
3111      * and mask.
3112      *
3113      * @param o object/array to update the field/element in
3114      * @param offset field/element offset
3115      * @param mask the mask value
3116      * @return the previous value
3117      * @since 9
3118      */
3119     @ForceInline
3120     public final int getAndBitwiseAndInt(Object o, long offset, int mask) {
3121         int current;
3122         do {
3123             current = getIntVolatile(o, offset);
3124         } while (!weakCompareAndSetInt(o, offset,
3125                                                 current, current & mask));
3126         return current;
3127     }
3128 
3129     @ForceInline
3130     public final int getAndBitwiseAndIntRelease(Object o, long offset, int mask) {
3131         int current;
3132         do {
3133             current = getInt(o, offset);
3134         } while (!weakCompareAndSetIntRelease(o, offset,
3135                                                current, current & mask));
3136         return current;
3137     }
3138 
3139     @ForceInline
3140     public final int getAndBitwiseAndIntAcquire(Object o, long offset, int mask) {
3141         int current;
3142         do {
3143             // Plain read, the value is a hint, the acquire CAS does the work
3144             current = getInt(o, offset);
3145         } while (!weakCompareAndSetIntAcquire(o, offset,
3146                                                current, current & mask));
3147         return current;
3148     }
3149 
3150     @ForceInline
3151     public final int getAndBitwiseXorInt(Object o, long offset, int mask) {
3152         int current;
3153         do {
3154             current = getIntVolatile(o, offset);
3155         } while (!weakCompareAndSetInt(o, offset,
3156                                                 current, current ^ mask));
3157         return current;
3158     }
3159 
3160     @ForceInline
3161     public final int getAndBitwiseXorIntRelease(Object o, long offset, int mask) {
3162         int current;
3163         do {
3164             current = getInt(o, offset);
3165         } while (!weakCompareAndSetIntRelease(o, offset,
3166                                                current, current ^ mask));
3167         return current;
3168     }
3169 
3170     @ForceInline
3171     public final int getAndBitwiseXorIntAcquire(Object o, long offset, int mask) {
3172         int current;
3173         do {
3174             // Plain read, the value is a hint, the acquire CAS does the work
3175             current = getInt(o, offset);
3176         } while (!weakCompareAndSetIntAcquire(o, offset,
3177                                                current, current ^ mask));
3178         return current;
3179     }
3180 
3181 
3182     @ForceInline
3183     public final long getAndBitwiseOrLong(Object o, long offset, long mask) {
3184         long current;
3185         do {
3186             current = getLongVolatile(o, offset);
3187         } while (!weakCompareAndSetLong(o, offset,
3188                                                 current, current | mask));
3189         return current;
3190     }
3191 
3192     @ForceInline
3193     public final long getAndBitwiseOrLongRelease(Object o, long offset, long mask) {
3194         long current;
3195         do {
3196             current = getLong(o, offset);
3197         } while (!weakCompareAndSetLongRelease(o, offset,
3198                                                current, current | mask));
3199         return current;
3200     }
3201 
3202     @ForceInline
3203     public final long getAndBitwiseOrLongAcquire(Object o, long offset, long mask) {
3204         long current;
3205         do {
3206             // Plain read, the value is a hint, the acquire CAS does the work
3207             current = getLong(o, offset);
3208         } while (!weakCompareAndSetLongAcquire(o, offset,
3209                                                current, current | mask));
3210         return current;
3211     }
3212 
3213     @ForceInline
3214     public final long getAndBitwiseAndLong(Object o, long offset, long mask) {
3215         long current;
3216         do {
3217             current = getLongVolatile(o, offset);
3218         } while (!weakCompareAndSetLong(o, offset,
3219                                                 current, current & mask));
3220         return current;
3221     }
3222 
3223     @ForceInline
3224     public final long getAndBitwiseAndLongRelease(Object o, long offset, long mask) {
3225         long current;
3226         do {
3227             current = getLong(o, offset);
3228         } while (!weakCompareAndSetLongRelease(o, offset,
3229                                                current, current & mask));
3230         return current;
3231     }
3232 
3233     @ForceInline
3234     public final long getAndBitwiseAndLongAcquire(Object o, long offset, long mask) {
3235         long current;
3236         do {
3237             // Plain read, the value is a hint, the acquire CAS does the work
3238             current = getLong(o, offset);
3239         } while (!weakCompareAndSetLongAcquire(o, offset,
3240                                                current, current & mask));
3241         return current;
3242     }
3243 
3244     @ForceInline
3245     public final long getAndBitwiseXorLong(Object o, long offset, long mask) {
3246         long current;
3247         do {
3248             current = getLongVolatile(o, offset);
3249         } while (!weakCompareAndSetLong(o, offset,
3250                                                 current, current ^ mask));
3251         return current;
3252     }
3253 
3254     @ForceInline
3255     public final long getAndBitwiseXorLongRelease(Object o, long offset, long mask) {
3256         long current;
3257         do {
3258             current = getLong(o, offset);
3259         } while (!weakCompareAndSetLongRelease(o, offset,
3260                                                current, current ^ mask));
3261         return current;
3262     }
3263 
3264     @ForceInline
3265     public final long getAndBitwiseXorLongAcquire(Object o, long offset, long mask) {
3266         long current;
3267         do {
3268             // Plain read, the value is a hint, the acquire CAS does the work
3269             current = getLong(o, offset);
3270         } while (!weakCompareAndSetLongAcquire(o, offset,
3271                                                current, current ^ mask));
3272         return current;
3273     }
3274 
3275 
3276 
3277     /**
3278      * Ensures that loads before the fence will not be reordered with loads and
3279      * stores after the fence; a "LoadLoad plus LoadStore barrier".
3280      *
3281      * Corresponds to C11 atomic_thread_fence(memory_order_acquire)
3282      * (an "acquire fence").
3283      *
3284      * A pure LoadLoad fence is not provided, since the addition of LoadStore
3285      * is almost always desired, and most current hardware instructions that
3286      * provide a LoadLoad barrier also provide a LoadStore barrier for free.
3287      * @since 1.8
3288      */
3289     @HotSpotIntrinsicCandidate
3290     public native void loadFence();
3291 
3292     /**
3293      * Ensures that loads and stores before the fence will not be reordered with
3294      * stores after the fence; a "StoreStore plus LoadStore barrier".
3295      *
3296      * Corresponds to C11 atomic_thread_fence(memory_order_release)
3297      * (a "release fence").
3298      *
3299      * A pure StoreStore fence is not provided, since the addition of LoadStore
3300      * is almost always desired, and most current hardware instructions that
3301      * provide a StoreStore barrier also provide a LoadStore barrier for free.
3302      * @since 1.8
3303      */
3304     @HotSpotIntrinsicCandidate
3305     public native void storeFence();
3306 
3307     /**
3308      * Ensures that loads and stores before the fence will not be reordered
3309      * with loads and stores after the fence.  Implies the effects of both
3310      * loadFence() and storeFence(), and in addition, the effect of a StoreLoad
3311      * barrier.
3312      *
3313      * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
3314      * @since 1.8
3315      */
3316     @HotSpotIntrinsicCandidate
3317     public native void fullFence();
3318 
3319     /**
3320      * Ensures that loads before the fence will not be reordered with
3321      * loads after the fence.
3322      */
3323     public final void loadLoadFence() {
3324         loadFence();
3325     }
3326 
3327     /**
3328      * Ensures that stores before the fence will not be reordered with
3329      * stores after the fence.
3330      */
3331     public final void storeStoreFence() {
3332         storeFence();
3333     }
3334 
3335 
3336     /**
3337      * Throws IllegalAccessError; for use by the VM for access control
3338      * error support.
3339      * @since 1.8
3340      */
3341     private static void throwIllegalAccessError() {
3342         throw new IllegalAccessError();
3343     }
3344 
3345     /**
3346      * Throws NoSuchMethodError; for use by the VM for redefinition support.
3347      * @since 13
3348      */
3349     private static void throwNoSuchMethodError() {
3350         throw new NoSuchMethodError();
3351     }
3352 
3353     /**
3354      * @return Returns true if the native byte ordering of this
3355      * platform is big-endian, false if it is little-endian.
3356      */
3357     public final boolean isBigEndian() { return BIG_ENDIAN; }
3358 
3359     /**
3360      * @return Returns true if this platform is capable of performing
3361      * accesses at addresses which are not aligned for the type of the
3362      * primitive type being accessed, false otherwise.
3363      */
3364     public final boolean unalignedAccess() { return UNALIGNED_ACCESS; }
3365 
3366     /**
3367      * Fetches a value at some byte offset into a given Java object.
3368      * More specifically, fetches a value within the given object
3369      * <code>o</code> at the given offset, or (if <code>o</code> is
3370      * null) from the memory address whose numerical value is the
3371      * given offset.  <p>
3372      *
3373      * The specification of this method is the same as {@link
3374      * #getLong(Object, long)} except that the offset does not need to
3375      * have been obtained from {@link #objectFieldOffset} on the
3376      * {@link java.lang.reflect.Field} of some Java field.  The value
3377      * in memory is raw data, and need not correspond to any Java
3378      * variable.  Unless <code>o</code> is null, the value accessed
3379      * must be entirely within the allocated object.  The endianness
3380      * of the value in memory is the endianness of the native platform.
3381      *
3382      * <p> The read will be atomic with respect to the largest power
3383      * of two that divides the GCD of the offset and the storage size.
3384      * For example, getLongUnaligned will make atomic reads of 2-, 4-,
3385      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
3386      * respectively.  There are no other guarantees of atomicity.
3387      * <p>
3388      * 8-byte atomicity is only guaranteed on platforms on which
3389      * support atomic accesses to longs.
3390      *
3391      * @param o Java heap object in which the value resides, if any, else
3392      *        null
3393      * @param offset The offset in bytes from the start of the object
3394      * @return the value fetched from the indicated object
3395      * @throws RuntimeException No defined exceptions are thrown, not even
3396      *         {@link NullPointerException}
3397      * @since 9
3398      */
3399     @HotSpotIntrinsicCandidate
3400     public final long getLongUnaligned(Object o, long offset) {
3401         if ((offset & 7) == 0) {
3402             return getLong(o, offset);
3403         } else if ((offset & 3) == 0) {
3404             return makeLong(getInt(o, offset),
3405                             getInt(o, offset + 4));
3406         } else if ((offset & 1) == 0) {
3407             return makeLong(getShort(o, offset),
3408                             getShort(o, offset + 2),
3409                             getShort(o, offset + 4),
3410                             getShort(o, offset + 6));
3411         } else {
3412             return makeLong(getByte(o, offset),
3413                             getByte(o, offset + 1),
3414                             getByte(o, offset + 2),
3415                             getByte(o, offset + 3),
3416                             getByte(o, offset + 4),
3417                             getByte(o, offset + 5),
3418                             getByte(o, offset + 6),
3419                             getByte(o, offset + 7));
3420         }
3421     }
3422     /**
3423      * As {@link #getLongUnaligned(Object, long)} but with an
3424      * additional argument which specifies the endianness of the value
3425      * as stored in memory.
3426      *
3427      * @param o Java heap object in which the variable resides
3428      * @param offset The offset in bytes from the start of the object
3429      * @param bigEndian The endianness of the value
3430      * @return the value fetched from the indicated object
3431      * @since 9
3432      */
3433     public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {
3434         return convEndian(bigEndian, getLongUnaligned(o, offset));
3435     }
3436 
3437     /** @see #getLongUnaligned(Object, long) */
3438     @HotSpotIntrinsicCandidate
3439     public final int getIntUnaligned(Object o, long offset) {
3440         if ((offset & 3) == 0) {
3441             return getInt(o, offset);
3442         } else if ((offset & 1) == 0) {
3443             return makeInt(getShort(o, offset),
3444                            getShort(o, offset + 2));
3445         } else {
3446             return makeInt(getByte(o, offset),
3447                            getByte(o, offset + 1),
3448                            getByte(o, offset + 2),
3449                            getByte(o, offset + 3));
3450         }
3451     }
3452     /** @see #getLongUnaligned(Object, long, boolean) */
3453     public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {
3454         return convEndian(bigEndian, getIntUnaligned(o, offset));
3455     }
3456 
3457     /** @see #getLongUnaligned(Object, long) */
3458     @HotSpotIntrinsicCandidate
3459     public final short getShortUnaligned(Object o, long offset) {
3460         if ((offset & 1) == 0) {
3461             return getShort(o, offset);
3462         } else {
3463             return makeShort(getByte(o, offset),
3464                              getByte(o, offset + 1));
3465         }
3466     }
3467     /** @see #getLongUnaligned(Object, long, boolean) */
3468     public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {
3469         return convEndian(bigEndian, getShortUnaligned(o, offset));
3470     }
3471 
3472     /** @see #getLongUnaligned(Object, long) */
3473     @HotSpotIntrinsicCandidate
3474     public final char getCharUnaligned(Object o, long offset) {
3475         if ((offset & 1) == 0) {
3476             return getChar(o, offset);
3477         } else {
3478             return (char)makeShort(getByte(o, offset),
3479                                    getByte(o, offset + 1));
3480         }
3481     }
3482 
3483     /** @see #getLongUnaligned(Object, long, boolean) */
3484     public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {
3485         return convEndian(bigEndian, getCharUnaligned(o, offset));
3486     }
3487 
3488     /**
3489      * Stores a value at some byte offset into a given Java object.
3490      * <p>
3491      * The specification of this method is the same as {@link
3492      * #getLong(Object, long)} except that the offset does not need to
3493      * have been obtained from {@link #objectFieldOffset} on the
3494      * {@link java.lang.reflect.Field} of some Java field.  The value
3495      * in memory is raw data, and need not correspond to any Java
3496      * variable.  The endianness of the value in memory is the
3497      * endianness of the native platform.
3498      * <p>
3499      * The write will be atomic with respect to the largest power of
3500      * two that divides the GCD of the offset and the storage size.
3501      * For example, putLongUnaligned will make atomic writes of 2-, 4-,
3502      * or 8-byte storage units if the offset is zero mod 2, 4, or 8,
3503      * respectively.  There are no other guarantees of atomicity.
3504      * <p>
3505      * 8-byte atomicity is only guaranteed on platforms on which
3506      * support atomic accesses to longs.
3507      *
3508      * @param o Java heap object in which the value resides, if any, else
3509      *        null
3510      * @param offset The offset in bytes from the start of the object
3511      * @param x the value to store
3512      * @throws RuntimeException No defined exceptions are thrown, not even
3513      *         {@link NullPointerException}
3514      * @since 9
3515      */
3516     @HotSpotIntrinsicCandidate
3517     public final void putLongUnaligned(Object o, long offset, long x) {
3518         if ((offset & 7) == 0) {
3519             putLong(o, offset, x);
3520         } else if ((offset & 3) == 0) {
3521             putLongParts(o, offset,
3522                          (int)(x >> 0),
3523                          (int)(x >>> 32));
3524         } else if ((offset & 1) == 0) {
3525             putLongParts(o, offset,
3526                          (short)(x >>> 0),
3527                          (short)(x >>> 16),
3528                          (short)(x >>> 32),
3529                          (short)(x >>> 48));
3530         } else {
3531             putLongParts(o, offset,
3532                          (byte)(x >>> 0),
3533                          (byte)(x >>> 8),
3534                          (byte)(x >>> 16),
3535                          (byte)(x >>> 24),
3536                          (byte)(x >>> 32),
3537                          (byte)(x >>> 40),
3538                          (byte)(x >>> 48),
3539                          (byte)(x >>> 56));
3540         }
3541     }
3542 
3543     /**
3544      * As {@link #putLongUnaligned(Object, long, long)} but with an additional
3545      * argument which specifies the endianness of the value as stored in memory.
3546      * @param o Java heap object in which the value resides
3547      * @param offset The offset in bytes from the start of the object
3548      * @param x the value to store
3549      * @param bigEndian The endianness of the value
3550      * @throws RuntimeException No defined exceptions are thrown, not even
3551      *         {@link NullPointerException}
3552      * @since 9
3553      */
3554     public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {
3555         putLongUnaligned(o, offset, convEndian(bigEndian, x));
3556     }
3557 
3558     /** @see #putLongUnaligned(Object, long, long) */
3559     @HotSpotIntrinsicCandidate
3560     public final void putIntUnaligned(Object o, long offset, int x) {
3561         if ((offset & 3) == 0) {
3562             putInt(o, offset, x);
3563         } else if ((offset & 1) == 0) {
3564             putIntParts(o, offset,
3565                         (short)(x >> 0),
3566                         (short)(x >>> 16));
3567         } else {
3568             putIntParts(o, offset,
3569                         (byte)(x >>> 0),
3570                         (byte)(x >>> 8),
3571                         (byte)(x >>> 16),
3572                         (byte)(x >>> 24));
3573         }
3574     }
3575     /** @see #putLongUnaligned(Object, long, long, boolean) */
3576     public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {
3577         putIntUnaligned(o, offset, convEndian(bigEndian, x));
3578     }
3579 
3580     /** @see #putLongUnaligned(Object, long, long) */
3581     @HotSpotIntrinsicCandidate
3582     public final void putShortUnaligned(Object o, long offset, short x) {
3583         if ((offset & 1) == 0) {
3584             putShort(o, offset, x);
3585         } else {
3586             putShortParts(o, offset,
3587                           (byte)(x >>> 0),
3588                           (byte)(x >>> 8));
3589         }
3590     }
3591     /** @see #putLongUnaligned(Object, long, long, boolean) */
3592     public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {
3593         putShortUnaligned(o, offset, convEndian(bigEndian, x));
3594     }
3595 
3596     /** @see #putLongUnaligned(Object, long, long) */
3597     @HotSpotIntrinsicCandidate
3598     public final void putCharUnaligned(Object o, long offset, char x) {
3599         putShortUnaligned(o, offset, (short)x);
3600     }
3601     /** @see #putLongUnaligned(Object, long, long, boolean) */
3602     public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
3603         putCharUnaligned(o, offset, convEndian(bigEndian, x));
3604     }
3605 
3606     private static int pickPos(int top, int pos) { return BIG_ENDIAN ? top - pos : pos; }
3607 
3608     // These methods construct integers from bytes.  The byte ordering
3609     // is the native endianness of this platform.
3610     private static long makeLong(byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
3611         return ((toUnsignedLong(i0) << pickPos(56, 0))
3612               | (toUnsignedLong(i1) << pickPos(56, 8))
3613               | (toUnsignedLong(i2) << pickPos(56, 16))
3614               | (toUnsignedLong(i3) << pickPos(56, 24))
3615               | (toUnsignedLong(i4) << pickPos(56, 32))
3616               | (toUnsignedLong(i5) << pickPos(56, 40))
3617               | (toUnsignedLong(i6) << pickPos(56, 48))
3618               | (toUnsignedLong(i7) << pickPos(56, 56)));
3619     }
3620     private static long makeLong(short i0, short i1, short i2, short i3) {
3621         return ((toUnsignedLong(i0) << pickPos(48, 0))
3622               | (toUnsignedLong(i1) << pickPos(48, 16))
3623               | (toUnsignedLong(i2) << pickPos(48, 32))
3624               | (toUnsignedLong(i3) << pickPos(48, 48)));
3625     }
3626     private static long makeLong(int i0, int i1) {
3627         return (toUnsignedLong(i0) << pickPos(32, 0))
3628              | (toUnsignedLong(i1) << pickPos(32, 32));
3629     }
3630     private static int makeInt(short i0, short i1) {
3631         return (toUnsignedInt(i0) << pickPos(16, 0))
3632              | (toUnsignedInt(i1) << pickPos(16, 16));
3633     }
3634     private static int makeInt(byte i0, byte i1, byte i2, byte i3) {
3635         return ((toUnsignedInt(i0) << pickPos(24, 0))
3636               | (toUnsignedInt(i1) << pickPos(24, 8))
3637               | (toUnsignedInt(i2) << pickPos(24, 16))
3638               | (toUnsignedInt(i3) << pickPos(24, 24)));
3639     }
3640     private static short makeShort(byte i0, byte i1) {
3641         return (short)((toUnsignedInt(i0) << pickPos(8, 0))
3642                      | (toUnsignedInt(i1) << pickPos(8, 8)));
3643     }
3644 
3645     private static byte  pick(byte  le, byte  be) { return BIG_ENDIAN ? be : le; }
3646     private static short pick(short le, short be) { return BIG_ENDIAN ? be : le; }
3647     private static int   pick(int   le, int   be) { return BIG_ENDIAN ? be : le; }
3648 
3649     // These methods write integers to memory from smaller parts
3650     // provided by their caller.  The ordering in which these parts
3651     // are written is the native endianness of this platform.
3652     private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {
3653         putByte(o, offset + 0, pick(i0, i7));
3654         putByte(o, offset + 1, pick(i1, i6));
3655         putByte(o, offset + 2, pick(i2, i5));
3656         putByte(o, offset + 3, pick(i3, i4));
3657         putByte(o, offset + 4, pick(i4, i3));
3658         putByte(o, offset + 5, pick(i5, i2));
3659         putByte(o, offset + 6, pick(i6, i1));
3660         putByte(o, offset + 7, pick(i7, i0));
3661     }
3662     private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {
3663         putShort(o, offset + 0, pick(i0, i3));
3664         putShort(o, offset + 2, pick(i1, i2));
3665         putShort(o, offset + 4, pick(i2, i1));
3666         putShort(o, offset + 6, pick(i3, i0));
3667     }
3668     private void putLongParts(Object o, long offset, int i0, int i1) {
3669         putInt(o, offset + 0, pick(i0, i1));
3670         putInt(o, offset + 4, pick(i1, i0));
3671     }
3672     private void putIntParts(Object o, long offset, short i0, short i1) {
3673         putShort(o, offset + 0, pick(i0, i1));
3674         putShort(o, offset + 2, pick(i1, i0));
3675     }
3676     private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {
3677         putByte(o, offset + 0, pick(i0, i3));
3678         putByte(o, offset + 1, pick(i1, i2));
3679         putByte(o, offset + 2, pick(i2, i1));
3680         putByte(o, offset + 3, pick(i3, i0));
3681     }
3682     private void putShortParts(Object o, long offset, byte i0, byte i1) {
3683         putByte(o, offset + 0, pick(i0, i1));
3684         putByte(o, offset + 1, pick(i1, i0));
3685     }
3686 
3687     // Zero-extend an integer
3688     private static int toUnsignedInt(byte n)    { return n & 0xff; }
3689     private static int toUnsignedInt(short n)   { return n & 0xffff; }
3690     private static long toUnsignedLong(byte n)  { return n & 0xffl; }
3691     private static long toUnsignedLong(short n) { return n & 0xffffl; }
3692     private static long toUnsignedLong(int n)   { return n & 0xffffffffl; }
3693 
3694     // Maybe byte-reverse an integer
3695     private static char convEndian(boolean big, char n)   { return big == BIG_ENDIAN ? n : Character.reverseBytes(n); }
3696     private static short convEndian(boolean big, short n) { return big == BIG_ENDIAN ? n : Short.reverseBytes(n)    ; }
3697     private static int convEndian(boolean big, int n)     { return big == BIG_ENDIAN ? n : Integer.reverseBytes(n)  ; }
3698     private static long convEndian(boolean big, long n)   { return big == BIG_ENDIAN ? n : Long.reverseBytes(n)     ; }
3699 
3700 
3701 
3702     private native long allocateMemory0(long bytes);
3703     private native long reallocateMemory0(long address, long bytes);
3704     private native void freeMemory0(long address);
3705     private native void setMemory0(Object o, long offset, long bytes, byte value);
3706     @HotSpotIntrinsicCandidate
3707     private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
3708     private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);
3709     private native long objectFieldOffset0(Field f);
3710     private native long objectFieldOffset1(Class<?> c, String name);
3711     private native long staticFieldOffset0(Field f);
3712     private native Object staticFieldBase0(Field f);
3713     private native boolean shouldBeInitialized0(Class<?> c);
3714     private native void ensureClassInitialized0(Class<?> c);
3715     private native int arrayBaseOffset0(Class<?> arrayClass);
3716     private native int arrayIndexScale0(Class<?> arrayClass);
3717     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
3718     private native int getLoadAverage0(double[] loadavg, int nelems);
3719 
3720 
3721     /**
3722      * Invokes the given direct byte buffer's cleaner, if any.
3723      *
3724      * @param directBuffer a direct byte buffer
3725      * @throws NullPointerException     if {@code directBuffer} is null
3726      * @throws IllegalArgumentException if {@code directBuffer} is non-direct,
3727      *                                  or is a {@link java.nio.Buffer#slice slice}, or is a
3728      *                                  {@link java.nio.Buffer#duplicate duplicate}
3729      */
3730     public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
3731         if (!directBuffer.isDirect())
3732             throw new IllegalArgumentException("buffer is non-direct");
3733 
3734         DirectBuffer db = (DirectBuffer) directBuffer;
3735         if (db.attachment() != null)
3736             throw new IllegalArgumentException("duplicate or slice");
3737 
3738         Cleaner cleaner = db.cleaner();
3739         if (cleaner != null) {
3740             cleaner.clean();
3741         }
3742     }
3743 
3744     // The following deprecated methods are used by JSR 166.
3745 
3746     @Deprecated(since="12", forRemoval=true)
3747     public final Object getObject(Object o, long offset) {
3748         return getReference(o, offset);
3749     }
3750     @Deprecated(since="12", forRemoval=true)
3751     public final Object getObjectVolatile(Object o, long offset) {
3752         return getReferenceVolatile(o, offset);
3753     }
3754     @Deprecated(since="12", forRemoval=true)
3755     public final Object getObjectAcquire(Object o, long offset) {
3756         return getReferenceAcquire(o, offset);
3757     }
3758     @Deprecated(since="12", forRemoval=true)
3759     public final Object getObjectOpaque(Object o, long offset) {
3760         return getReferenceOpaque(o, offset);
3761     }
3762 
3763 
3764     @Deprecated(since="12", forRemoval=true)
3765     public final void putObject(Object o, long offset, Object x) {
3766         putReference(o, offset, x);
3767     }
3768     @Deprecated(since="12", forRemoval=true)
3769     public final void putObjectVolatile(Object o, long offset, Object x) {
3770         putReferenceVolatile(o, offset, x);
3771     }
3772     @Deprecated(since="12", forRemoval=true)
3773     public final void putObjectOpaque(Object o, long offset, Object x) {
3774         putReferenceOpaque(o, offset, x);
3775     }
3776     @Deprecated(since="12", forRemoval=true)
3777     public final void putObjectRelease(Object o, long offset, Object x) {
3778         putReferenceRelease(o, offset, x);
3779     }
3780 
3781 
3782     @Deprecated(since="12", forRemoval=true)
3783     public final Object getAndSetObject(Object o, long offset, Object newValue) {
3784         return getAndSetReference(o, offset, newValue);
3785     }
3786     @Deprecated(since="12", forRemoval=true)
3787     public final Object getAndSetObjectAcquire(Object o, long offset, Object newValue) {
3788         return getAndSetReferenceAcquire(o, offset, newValue);
3789     }
3790     @Deprecated(since="12", forRemoval=true)
3791     public final Object getAndSetObjectRelease(Object o, long offset, Object newValue) {
3792         return getAndSetReferenceRelease(o, offset, newValue);
3793     }
3794 
3795 
3796     @Deprecated(since="12", forRemoval=true)
3797     public final boolean compareAndSetObject(Object o, long offset, Object expected, Object x) {
3798         return compareAndSetReference(o, offset, expected, x);
3799     }
3800     @Deprecated(since="12", forRemoval=true)
3801     public final Object compareAndExchangeObject(Object o, long offset, Object expected, Object x) {
3802         return compareAndExchangeReference(o, offset, expected, x);
3803     }
3804     @Deprecated(since="12", forRemoval=true)
3805     public final Object compareAndExchangeObjectAcquire(Object o, long offset, Object expected, Object x) {
3806         return compareAndExchangeReferenceAcquire(o, offset, expected, x);
3807     }
3808     @Deprecated(since="12", forRemoval=true)
3809     public final Object compareAndExchangeObjectRelease(Object o, long offset, Object expected, Object x) {
3810         return compareAndExchangeReferenceRelease(o, offset, expected, x);
3811     }
3812 
3813 
3814     @Deprecated(since="12", forRemoval=true)
3815     public final boolean weakCompareAndSetObject(Object o, long offset, Object expected, Object x) {
3816         return weakCompareAndSetReference(o, offset, expected, x);
3817     }
3818     @Deprecated(since="12", forRemoval=true)
3819     public final boolean weakCompareAndSetObjectAcquire(Object o, long offset, Object expected, Object x) {
3820         return weakCompareAndSetReferenceAcquire(o, offset, expected, x);
3821     }
3822     @Deprecated(since="12", forRemoval=true)
3823     public final boolean weakCompareAndSetObjectPlain(Object o, long offset, Object expected, Object x) {
3824         return weakCompareAndSetReferencePlain(o, offset, expected, x);
3825     }
3826     @Deprecated(since="12", forRemoval=true)
3827     public final boolean weakCompareAndSetObjectRelease(Object o, long offset, Object expected, Object x) {
3828         return weakCompareAndSetReferenceRelease(o, offset, expected, x);
3829     }
3830 }