Path: blob/master/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
41159 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.misc;2627import jdk.internal.ref.Cleaner;28import jdk.internal.vm.annotation.ForceInline;29import jdk.internal.vm.annotation.IntrinsicCandidate;30import sun.nio.ch.DirectBuffer;3132import java.lang.reflect.Field;33import java.security.ProtectionDomain;3435import static jdk.internal.misc.UnsafeConstants.*;3637/**38* A collection of methods for performing low-level, unsafe operations.39* Although the class and all methods are public, use of this class is40* limited because only trusted code can obtain instances of it.41*42* <em>Note:</em> It is the responsibility of the caller to make sure43* arguments are checked before methods of this class are44* called. While some rudimentary checks are performed on the input,45* the checks are best effort and when performance is an overriding46* priority, as when methods of this class are optimized by the47* runtime compiler, some or all checks (if any) may be elided. Hence,48* the caller must not rely on the checks and corresponding49* exceptions!50*51* @author John R. Rose52* @see #getUnsafe53*/5455public final class Unsafe {5657private static native void registerNatives();58static {59registerNatives();60}6162private Unsafe() {}6364private static final Unsafe theUnsafe = new Unsafe();6566/**67* Provides the caller with the capability of performing unsafe68* operations.69*70* <p>The returned {@code Unsafe} object should be carefully guarded71* by the caller, since it can be used to read and write data at arbitrary72* memory addresses. It must never be passed to untrusted code.73*74* <p>Most methods in this class are very low-level, and correspond to a75* small number of hardware instructions (on typical machines). Compilers76* are encouraged to optimize these methods accordingly.77*78* <p>Here is a suggested idiom for using unsafe operations:79*80* <pre> {@code81* class MyTrustedClass {82* private static final Unsafe unsafe = Unsafe.getUnsafe();83* ...84* private long myCountAddress = ...;85* public int getCount() { return unsafe.getByte(myCountAddress); }86* }}</pre>87*88* (It may assist compilers to make the local variable {@code final}.)89*/90public static Unsafe getUnsafe() {91return theUnsafe;92}9394/// peek and poke operations95/// (compilers should optimize these to memory ops)9697// These work on object fields in the Java heap.98// They will not work on elements of packed arrays.99100/**101* Fetches a value from a given Java variable.102* More specifically, fetches a field or array element within the given103* object {@code o} at the given offset, or (if {@code o} is null)104* from the memory address whose numerical value is the given offset.105* <p>106* The results are undefined unless one of the following cases is true:107* <ul>108* <li>The offset was obtained from {@link #objectFieldOffset} on109* the {@link java.lang.reflect.Field} of some Java field and the object110* referred to by {@code o} is of a class compatible with that111* field's class.112*113* <li>The offset and object reference {@code o} (either null or114* non-null) were both obtained via {@link #staticFieldOffset}115* and {@link #staticFieldBase} (respectively) from the116* reflective {@link Field} representation of some Java field.117*118* <li>The object referred to by {@code o} is an array, and the offset119* is an integer of the form {@code B+N*S}, where {@code N} is120* a valid index into the array, and {@code B} and {@code S} are121* the values obtained by {@link #arrayBaseOffset} and {@link122* #arrayIndexScale} (respectively) from the array's class. The value123* referred to is the {@code N}<em>th</em> element of the array.124*125* </ul>126* <p>127* If one of the above cases is true, the call references a specific Java128* variable (field or array element). However, the results are undefined129* if that variable is not in fact of the type returned by this method.130* <p>131* This method refers to a variable by means of two parameters, and so132* it provides (in effect) a <em>double-register</em> addressing mode133* for Java variables. When the object reference is null, this method134* uses its offset as an absolute address. This is similar in operation135* to methods such as {@link #getInt(long)}, which provide (in effect) a136* <em>single-register</em> addressing mode for non-Java variables.137* However, because Java variables may have a different layout in memory138* from non-Java variables, programmers should not assume that these139* two addressing modes are ever equivalent. Also, programmers should140* remember that offsets from the double-register addressing mode cannot141* be portably confused with longs used in the single-register addressing142* mode.143*144* @param o Java heap object in which the variable resides, if any, else145* null146* @param offset indication of where the variable resides in a Java heap147* object, if any, else a memory address locating the variable148* statically149* @return the value fetched from the indicated Java variable150* @throws RuntimeException No defined exceptions are thrown, not even151* {@link NullPointerException}152*/153@IntrinsicCandidate154public native int getInt(Object o, long offset);155156/**157* Stores a value into a given Java variable.158* <p>159* The first two parameters are interpreted exactly as with160* {@link #getInt(Object, long)} to refer to a specific161* Java variable (field or array element). The given value162* is stored into that variable.163* <p>164* The variable must be of the same type as the method165* parameter {@code x}.166*167* @param o Java heap object in which the variable resides, if any, else168* null169* @param offset indication of where the variable resides in a Java heap170* object, if any, else a memory address locating the variable171* statically172* @param x the value to store into the indicated Java variable173* @throws RuntimeException No defined exceptions are thrown, not even174* {@link NullPointerException}175*/176@IntrinsicCandidate177public native void putInt(Object o, long offset, int x);178179/**180* Fetches a reference value from a given Java variable.181* @see #getInt(Object, long)182*/183@IntrinsicCandidate184public native Object getReference(Object o, long offset);185186/**187* Stores a reference value into a given Java variable.188* <p>189* Unless the reference {@code x} being stored is either null190* or matches the field type, the results are undefined.191* If the reference {@code o} is non-null, card marks or192* other store barriers for that object (if the VM requires them)193* are updated.194* @see #putInt(Object, long, int)195*/196@IntrinsicCandidate197public native void putReference(Object o, long offset, Object x);198199/** @see #getInt(Object, long) */200@IntrinsicCandidate201public native boolean getBoolean(Object o, long offset);202203/** @see #putInt(Object, long, int) */204@IntrinsicCandidate205public native void putBoolean(Object o, long offset, boolean x);206207/** @see #getInt(Object, long) */208@IntrinsicCandidate209public native byte getByte(Object o, long offset);210211/** @see #putInt(Object, long, int) */212@IntrinsicCandidate213public native void putByte(Object o, long offset, byte x);214215/** @see #getInt(Object, long) */216@IntrinsicCandidate217public native short getShort(Object o, long offset);218219/** @see #putInt(Object, long, int) */220@IntrinsicCandidate221public native void putShort(Object o, long offset, short x);222223/** @see #getInt(Object, long) */224@IntrinsicCandidate225public native char getChar(Object o, long offset);226227/** @see #putInt(Object, long, int) */228@IntrinsicCandidate229public native void putChar(Object o, long offset, char x);230231/** @see #getInt(Object, long) */232@IntrinsicCandidate233public native long getLong(Object o, long offset);234235/** @see #putInt(Object, long, int) */236@IntrinsicCandidate237public native void putLong(Object o, long offset, long x);238239/** @see #getInt(Object, long) */240@IntrinsicCandidate241public native float getFloat(Object o, long offset);242243/** @see #putInt(Object, long, int) */244@IntrinsicCandidate245public native void putFloat(Object o, long offset, float x);246247/** @see #getInt(Object, long) */248@IntrinsicCandidate249public native double getDouble(Object o, long offset);250251/** @see #putInt(Object, long, int) */252@IntrinsicCandidate253public native void putDouble(Object o, long offset, double x);254255/**256* Fetches a native pointer from a given memory address. If the address is257* zero, or does not point into a block obtained from {@link258* #allocateMemory}, the results are undefined.259*260* <p>If the native pointer is less than 64 bits wide, it is extended as261* an unsigned number to a Java long. The pointer may be indexed by any262* given byte offset, simply by adding that offset (as a simple integer) to263* the long representing the pointer. The number of bytes actually read264* from the target address may be determined by consulting {@link265* #addressSize}.266*267* @see #allocateMemory268* @see #getInt(Object, long)269*/270@ForceInline271public long getAddress(Object o, long offset) {272if (ADDRESS_SIZE == 4) {273return Integer.toUnsignedLong(getInt(o, offset));274} else {275return getLong(o, offset);276}277}278279/**280* Stores a native pointer into a given memory address. If the address is281* zero, or does not point into a block obtained from {@link282* #allocateMemory}, the results are undefined.283*284* <p>The number of bytes actually written at the target address may be285* determined by consulting {@link #addressSize}.286*287* @see #allocateMemory288* @see #putInt(Object, long, int)289*/290@ForceInline291public void putAddress(Object o, long offset, long x) {292if (ADDRESS_SIZE == 4) {293putInt(o, offset, (int)x);294} else {295putLong(o, offset, x);296}297}298299// These read VM internal data.300301/**302* Fetches an uncompressed reference value from a given native variable303* ignoring the VM's compressed references mode.304*305* @param address a memory address locating the variable306* @return the value fetched from the indicated native variable307*/308public native Object getUncompressedObject(long address);309310// These work on values in the C heap.311312/**313* Fetches a value from a given memory address. If the address is zero, or314* does not point into a block obtained from {@link #allocateMemory}, the315* results are undefined.316*317* @see #allocateMemory318*/319@ForceInline320public byte getByte(long address) {321return getByte(null, address);322}323324/**325* Stores a value into a given memory address. If the address is zero, or326* does not point into a block obtained from {@link #allocateMemory}, the327* results are undefined.328*329* @see #getByte(long)330*/331@ForceInline332public void putByte(long address, byte x) {333putByte(null, address, x);334}335336/** @see #getByte(long) */337@ForceInline338public short getShort(long address) {339return getShort(null, address);340}341342/** @see #putByte(long, byte) */343@ForceInline344public void putShort(long address, short x) {345putShort(null, address, x);346}347348/** @see #getByte(long) */349@ForceInline350public char getChar(long address) {351return getChar(null, address);352}353354/** @see #putByte(long, byte) */355@ForceInline356public void putChar(long address, char x) {357putChar(null, address, x);358}359360/** @see #getByte(long) */361@ForceInline362public int getInt(long address) {363return getInt(null, address);364}365366/** @see #putByte(long, byte) */367@ForceInline368public void putInt(long address, int x) {369putInt(null, address, x);370}371372/** @see #getByte(long) */373@ForceInline374public long getLong(long address) {375return getLong(null, address);376}377378/** @see #putByte(long, byte) */379@ForceInline380public void putLong(long address, long x) {381putLong(null, address, x);382}383384/** @see #getByte(long) */385@ForceInline386public float getFloat(long address) {387return getFloat(null, address);388}389390/** @see #putByte(long, byte) */391@ForceInline392public void putFloat(long address, float x) {393putFloat(null, address, x);394}395396/** @see #getByte(long) */397@ForceInline398public double getDouble(long address) {399return getDouble(null, address);400}401402/** @see #putByte(long, byte) */403@ForceInline404public void putDouble(long address, double x) {405putDouble(null, address, x);406}407408/** @see #getAddress(Object, long) */409@ForceInline410public long getAddress(long address) {411return getAddress(null, address);412}413414/** @see #putAddress(Object, long, long) */415@ForceInline416public void putAddress(long address, long x) {417putAddress(null, address, x);418}419420421422/// helper methods for validating various types of objects/values423424/**425* Create an exception reflecting that some of the input was invalid426*427* <em>Note:</em> It is the responsibility of the caller to make428* sure arguments are checked before the methods are called. While429* some rudimentary checks are performed on the input, the checks430* are best effort and when performance is an overriding priority,431* as when methods of this class are optimized by the runtime432* compiler, some or all checks (if any) may be elided. Hence, the433* caller must not rely on the checks and corresponding434* exceptions!435*436* @return an exception object437*/438private RuntimeException invalidInput() {439return new IllegalArgumentException();440}441442/**443* Check if a value is 32-bit clean (32 MSB are all zero)444*445* @param value the 64-bit value to check446*447* @return true if the value is 32-bit clean448*/449private boolean is32BitClean(long value) {450return value >>> 32 == 0;451}452453/**454* Check the validity of a size (the equivalent of a size_t)455*456* @throws RuntimeException if the size is invalid457* (<em>Note:</em> after optimization, invalid inputs may458* go undetected, which will lead to unpredictable459* behavior)460*/461private void checkSize(long size) {462if (ADDRESS_SIZE == 4) {463// Note: this will also check for negative sizes464if (!is32BitClean(size)) {465throw invalidInput();466}467} else if (size < 0) {468throw invalidInput();469}470}471472/**473* Check the validity of a native address (the equivalent of void*)474*475* @throws RuntimeException if the address is invalid476* (<em>Note:</em> after optimization, invalid inputs may477* go undetected, which will lead to unpredictable478* behavior)479*/480private void checkNativeAddress(long address) {481if (ADDRESS_SIZE == 4) {482// Accept both zero and sign extended pointers. A valid483// pointer will, after the +1 below, either have produced484// the value 0x0 or 0x1. Masking off the low bit allows485// for testing against 0.486if ((((address >> 32) + 1) & ~1) != 0) {487throw invalidInput();488}489}490}491492/**493* Check the validity of an offset, relative to a base object494*495* @param o the base object496* @param offset the offset to check497*498* @throws RuntimeException if the size is invalid499* (<em>Note:</em> after optimization, invalid inputs may500* go undetected, which will lead to unpredictable501* behavior)502*/503private void checkOffset(Object o, long offset) {504if (ADDRESS_SIZE == 4) {505// Note: this will also check for negative offsets506if (!is32BitClean(offset)) {507throw invalidInput();508}509} else if (offset < 0) {510throw invalidInput();511}512}513514/**515* Check the validity of a double-register pointer516*517* Note: This code deliberately does *not* check for NPE for (at518* least) three reasons:519*520* 1) NPE is not just NULL/0 - there is a range of values all521* resulting in an NPE, which is not trivial to check for522*523* 2) It is the responsibility of the callers of Unsafe methods524* to verify the input, so throwing an exception here is not really525* useful - passing in a NULL pointer is a critical error and the526* must not expect an exception to be thrown anyway.527*528* 3) the actual operations will detect NULL pointers anyway by529* means of traps and signals (like SIGSEGV).530*531* @param o Java heap object, or null532* @param offset indication of where the variable resides in a Java heap533* object, if any, else a memory address locating the variable534* statically535*536* @throws RuntimeException if the pointer is invalid537* (<em>Note:</em> after optimization, invalid inputs may538* go undetected, which will lead to unpredictable539* behavior)540*/541private void checkPointer(Object o, long offset) {542if (o == null) {543checkNativeAddress(offset);544} else {545checkOffset(o, offset);546}547}548549/**550* Check if a type is a primitive array type551*552* @param c the type to check553*554* @return true if the type is a primitive array type555*/556private void checkPrimitiveArray(Class<?> c) {557Class<?> componentType = c.getComponentType();558if (componentType == null || !componentType.isPrimitive()) {559throw invalidInput();560}561}562563/**564* Check that a pointer is a valid primitive array type pointer565*566* Note: pointers off-heap are considered to be primitive arrays567*568* @throws RuntimeException if the pointer is invalid569* (<em>Note:</em> after optimization, invalid inputs may570* go undetected, which will lead to unpredictable571* behavior)572*/573private void checkPrimitivePointer(Object o, long offset) {574checkPointer(o, offset);575576if (o != null) {577// If on heap, it must be a primitive array578checkPrimitiveArray(o.getClass());579}580}581582583/// wrappers for malloc, realloc, free:584585/**586* Round up allocation size to a multiple of HeapWordSize.587*/588private long alignToHeapWordSize(long bytes) {589if (bytes >= 0) {590return (bytes + ADDRESS_SIZE - 1) & ~(ADDRESS_SIZE - 1);591} else {592throw invalidInput();593}594}595596/**597* Allocates a new block of native memory, of the given size in bytes. The598* contents of the memory are uninitialized; they will generally be599* garbage. The resulting native pointer will never be zero, and will be600* aligned for all value types. Dispose of this memory by calling {@link601* #freeMemory}, or resize it with {@link #reallocateMemory}.602*603* <em>Note:</em> It is the responsibility of the caller to make604* sure arguments are checked before the methods are called. While605* some rudimentary checks are performed on the input, the checks606* are best effort and when performance is an overriding priority,607* as when methods of this class are optimized by the runtime608* compiler, some or all checks (if any) may be elided. Hence, the609* caller must not rely on the checks and corresponding610* exceptions!611*612* @throws RuntimeException if the size is negative or too large613* for the native size_t type614*615* @throws OutOfMemoryError if the allocation is refused by the system616*617* @see #getByte(long)618* @see #putByte(long, byte)619*/620public long allocateMemory(long bytes) {621bytes = alignToHeapWordSize(bytes);622623allocateMemoryChecks(bytes);624625if (bytes == 0) {626return 0;627}628629long p = allocateMemory0(bytes);630if (p == 0) {631throw new OutOfMemoryError("Unable to allocate " + bytes + " bytes");632}633634return p;635}636637/**638* Validate the arguments to allocateMemory639*640* @throws RuntimeException if the arguments are invalid641* (<em>Note:</em> after optimization, invalid inputs may642* go undetected, which will lead to unpredictable643* behavior)644*/645private void allocateMemoryChecks(long bytes) {646checkSize(bytes);647}648649/**650* Resizes a new block of native memory, to the given size in bytes. The651* contents of the new block past the size of the old block are652* uninitialized; they will generally be garbage. The resulting native653* pointer will be zero if and only if the requested size is zero. The654* resulting native pointer will be aligned for all value types. Dispose655* of this memory by calling {@link #freeMemory}, or resize it with {@link656* #reallocateMemory}. The address passed to this method may be null, in657* which case an allocation will be performed.658*659* <em>Note:</em> It is the responsibility of the caller to make660* sure arguments are checked before the methods are called. While661* some rudimentary checks are performed on the input, the checks662* are best effort and when performance is an overriding priority,663* as when methods of this class are optimized by the runtime664* compiler, some or all checks (if any) may be elided. Hence, the665* caller must not rely on the checks and corresponding666* exceptions!667*668* @throws RuntimeException if the size is negative or too large669* for the native size_t type670*671* @throws OutOfMemoryError if the allocation is refused by the system672*673* @see #allocateMemory674*/675public long reallocateMemory(long address, long bytes) {676bytes = alignToHeapWordSize(bytes);677678reallocateMemoryChecks(address, bytes);679680if (bytes == 0) {681freeMemory(address);682return 0;683}684685long p = (address == 0) ? allocateMemory0(bytes) : reallocateMemory0(address, bytes);686if (p == 0) {687throw new OutOfMemoryError("Unable to allocate " + bytes + " bytes");688}689690return p;691}692693/**694* Validate the arguments to reallocateMemory695*696* @throws RuntimeException if the arguments are invalid697* (<em>Note:</em> after optimization, invalid inputs may698* go undetected, which will lead to unpredictable699* behavior)700*/701private void reallocateMemoryChecks(long address, long bytes) {702checkPointer(null, address);703checkSize(bytes);704}705706/**707* Sets all bytes in a given block of memory to a fixed value708* (usually zero).709*710* <p>This method determines a block's base address by means of two parameters,711* and so it provides (in effect) a <em>double-register</em> addressing mode,712* as discussed in {@link #getInt(Object,long)}. When the object reference is null,713* the offset supplies an absolute base address.714*715* <p>The stores are in coherent (atomic) units of a size determined716* by the address and length parameters. If the effective address and717* length are all even modulo 8, the stores take place in 'long' units.718* If the effective address and length are (resp.) even modulo 4 or 2,719* the stores take place in units of 'int' or 'short'.720*721* <em>Note:</em> It is the responsibility of the caller to make722* sure arguments are checked before the methods are called. While723* some rudimentary checks are performed on the input, the checks724* are best effort and when performance is an overriding priority,725* as when methods of this class are optimized by the runtime726* compiler, some or all checks (if any) may be elided. Hence, the727* caller must not rely on the checks and corresponding728* exceptions!729*730* @throws RuntimeException if any of the arguments is invalid731*732* @since 1.7733*/734public void setMemory(Object o, long offset, long bytes, byte value) {735setMemoryChecks(o, offset, bytes, value);736737if (bytes == 0) {738return;739}740741setMemory0(o, offset, bytes, value);742}743744/**745* Sets all bytes in a given block of memory to a fixed value746* (usually zero). This provides a <em>single-register</em> addressing mode,747* as discussed in {@link #getInt(Object,long)}.748*749* <p>Equivalent to {@code setMemory(null, address, bytes, value)}.750*/751public void setMemory(long address, long bytes, byte value) {752setMemory(null, address, bytes, value);753}754755/**756* Validate the arguments to setMemory757*758* @throws RuntimeException if the arguments are invalid759* (<em>Note:</em> after optimization, invalid inputs may760* go undetected, which will lead to unpredictable761* behavior)762*/763private void setMemoryChecks(Object o, long offset, long bytes, byte value) {764checkPrimitivePointer(o, offset);765checkSize(bytes);766}767768/**769* Sets all bytes in a given block of memory to a copy of another770* block.771*772* <p>This method determines each block's base address by means of two parameters,773* and so it provides (in effect) a <em>double-register</em> addressing mode,774* as discussed in {@link #getInt(Object,long)}. When the object reference is null,775* the offset supplies an absolute base address.776*777* <p>The transfers are in coherent (atomic) units of a size determined778* by the address and length parameters. If the effective addresses and779* length are all even modulo 8, the transfer takes place in 'long' units.780* If the effective addresses and length are (resp.) even modulo 4 or 2,781* the transfer takes place in units of 'int' or 'short'.782*783* <em>Note:</em> It is the responsibility of the caller to make784* sure arguments are checked before the methods are called. While785* some rudimentary checks are performed on the input, the checks786* are best effort and when performance is an overriding priority,787* as when methods of this class are optimized by the runtime788* compiler, some or all checks (if any) may be elided. Hence, the789* caller must not rely on the checks and corresponding790* exceptions!791*792* @throws RuntimeException if any of the arguments is invalid793*794* @since 1.7795*/796public void copyMemory(Object srcBase, long srcOffset,797Object destBase, long destOffset,798long bytes) {799copyMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes);800801if (bytes == 0) {802return;803}804805copyMemory0(srcBase, srcOffset, destBase, destOffset, bytes);806}807808/**809* Sets all bytes in a given block of memory to a copy of another810* block. This provides a <em>single-register</em> addressing mode,811* as discussed in {@link #getInt(Object,long)}.812*813* Equivalent to {@code copyMemory(null, srcAddress, null, destAddress, bytes)}.814*/815public void copyMemory(long srcAddress, long destAddress, long bytes) {816copyMemory(null, srcAddress, null, destAddress, bytes);817}818819/**820* Validate the arguments to copyMemory821*822* @throws RuntimeException if any of the arguments is invalid823* (<em>Note:</em> after optimization, invalid inputs may824* go undetected, which will lead to unpredictable825* behavior)826*/827private void copyMemoryChecks(Object srcBase, long srcOffset,828Object destBase, long destOffset,829long bytes) {830checkSize(bytes);831checkPrimitivePointer(srcBase, srcOffset);832checkPrimitivePointer(destBase, destOffset);833}834835/**836* Copies all elements from one block of memory to another block,837* *unconditionally* byte swapping the elements on the fly.838*839* <p>This method determines each block's base address by means of two parameters,840* and so it provides (in effect) a <em>double-register</em> addressing mode,841* as discussed in {@link #getInt(Object,long)}. When the object reference is null,842* the offset supplies an absolute base address.843*844* <em>Note:</em> It is the responsibility of the caller to make845* sure arguments are checked before the methods are called. While846* some rudimentary checks are performed on the input, the checks847* are best effort and when performance is an overriding priority,848* as when methods of this class are optimized by the runtime849* compiler, some or all checks (if any) may be elided. Hence, the850* caller must not rely on the checks and corresponding851* exceptions!852*853* @throws RuntimeException if any of the arguments is invalid854*855* @since 9856*/857public void copySwapMemory(Object srcBase, long srcOffset,858Object destBase, long destOffset,859long bytes, long elemSize) {860copySwapMemoryChecks(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);861862if (bytes == 0) {863return;864}865866copySwapMemory0(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);867}868869private void copySwapMemoryChecks(Object srcBase, long srcOffset,870Object destBase, long destOffset,871long bytes, long elemSize) {872checkSize(bytes);873874if (elemSize != 2 && elemSize != 4 && elemSize != 8) {875throw invalidInput();876}877if (bytes % elemSize != 0) {878throw invalidInput();879}880881checkPrimitivePointer(srcBase, srcOffset);882checkPrimitivePointer(destBase, destOffset);883}884885/**886* Copies all elements from one block of memory to another block, byte swapping the887* elements on the fly.888*889* This provides a <em>single-register</em> addressing mode, as890* discussed in {@link #getInt(Object,long)}.891*892* Equivalent to {@code copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize)}.893*/894public void copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize) {895copySwapMemory(null, srcAddress, null, destAddress, bytes, elemSize);896}897898/**899* Disposes of a block of native memory, as obtained from {@link900* #allocateMemory} or {@link #reallocateMemory}. The address passed to901* this method may be null, in which case no action is taken.902*903* <em>Note:</em> It is the responsibility of the caller to make904* sure arguments are checked before the methods are called. While905* some rudimentary checks are performed on the input, the checks906* are best effort and when performance is an overriding priority,907* as when methods of this class are optimized by the runtime908* compiler, some or all checks (if any) may be elided. Hence, the909* caller must not rely on the checks and corresponding910* exceptions!911*912* @throws RuntimeException if any of the arguments is invalid913*914* @see #allocateMemory915*/916public void freeMemory(long address) {917freeMemoryChecks(address);918919if (address == 0) {920return;921}922923freeMemory0(address);924}925926/**927* Validate the arguments to freeMemory928*929* @throws RuntimeException if the arguments are invalid930* (<em>Note:</em> after optimization, invalid inputs may931* go undetected, which will lead to unpredictable932* behavior)933*/934private void freeMemoryChecks(long address) {935checkPointer(null, address);936}937938/**939* Ensure writeback of a specified virtual memory address range940* from cache to physical memory. All bytes in the address range941* are guaranteed to have been written back to physical memory on942* return from this call i.e. subsequently executed store943* instructions are guaranteed not to be visible before the944* writeback is completed.945*946* @param address947* the lowest byte address that must be guaranteed written948* back to memory. bytes at lower addresses may also be949* written back.950*951* @param length952* the length in bytes of the region starting at address953* that must be guaranteed written back to memory.954*955* @throws RuntimeException if memory writeback is not supported956* on the current hardware of if the arguments are invalid.957* (<em>Note:</em> after optimization, invalid inputs may958* go undetected, which will lead to unpredictable959* behavior)960*961* @since 14962*/963964public void writebackMemory(long address, long length) {965checkWritebackEnabled();966checkWritebackMemory(address, length);967968// perform any required pre-writeback barrier969writebackPreSync0();970971// write back one cache line at a time972long line = dataCacheLineAlignDown(address);973long end = address + length;974while (line < end) {975writeback0(line);976line += dataCacheLineFlushSize();977}978979// perform any required post-writeback barrier980writebackPostSync0();981}982983/**984* Validate the arguments to writebackMemory985*986* @throws RuntimeException if the arguments are invalid987* (<em>Note:</em> after optimization, invalid inputs may988* go undetected, which will lead to unpredictable989* behavior)990*/991private void checkWritebackMemory(long address, long length) {992checkNativeAddress(address);993checkSize(length);994}995996/**997* Validate that the current hardware supports memory writeback.998* (<em>Note:</em> this is a belt and braces check. Clients are999* expected to test whether writeback is enabled by calling1000* ({@link isWritebackEnabled #isWritebackEnabled} and avoid1001* calling method {@link writeback #writeback} if it is disabled).1002*1003*1004* @throws RuntimeException if memory writeback is not supported1005*/1006private void checkWritebackEnabled() {1007if (!isWritebackEnabled()) {1008throw new RuntimeException("writebackMemory not enabled!");1009}1010}10111012/**1013* force writeback of an individual cache line.1014*1015* @param address1016* the start address of the cache line to be written back1017*/1018@IntrinsicCandidate1019private native void writeback0(long address);10201021/**1022* Serialize writeback operations relative to preceding memory writes.1023*/1024@IntrinsicCandidate1025private native void writebackPreSync0();10261027/**1028* Serialize writeback operations relative to following memory writes.1029*/1030@IntrinsicCandidate1031private native void writebackPostSync0();10321033/// random queries10341035/**1036* This constant differs from all results that will ever be returned from1037* {@link #staticFieldOffset}, {@link #objectFieldOffset},1038* or {@link #arrayBaseOffset}.1039*/1040public static final int INVALID_FIELD_OFFSET = -1;10411042/**1043* Reports the location of a given field in the storage allocation of its1044* class. Do not expect to perform any sort of arithmetic on this offset;1045* it is just a cookie which is passed to the unsafe heap memory accessors.1046*1047* <p>Any given field will always have the same offset and base, and no1048* two distinct fields of the same class will ever have the same offset1049* and base.1050*1051* <p>As of 1.4.1, offsets for fields are represented as long values,1052* although the Sun JVM does not use the most significant 32 bits.1053* However, JVM implementations which store static fields at absolute1054* addresses can use long offsets and null base pointers to express1055* the field locations in a form usable by {@link #getInt(Object,long)}.1056* Therefore, code which will be ported to such JVMs on 64-bit platforms1057* must preserve all bits of static field offsets.1058* @see #getInt(Object, long)1059*/1060public long objectFieldOffset(Field f) {1061if (f == null) {1062throw new NullPointerException();1063}10641065return objectFieldOffset0(f);1066}10671068/**1069* Reports the location of the field with a given name in the storage1070* allocation of its class.1071*1072* @throws NullPointerException if any parameter is {@code null}.1073* @throws InternalError if there is no field named {@code name} declared1074* in class {@code c}, i.e., if {@code c.getDeclaredField(name)}1075* would throw {@code java.lang.NoSuchFieldException}.1076*1077* @see #objectFieldOffset(Field)1078*/1079public long objectFieldOffset(Class<?> c, String name) {1080if (c == null || name == null) {1081throw new NullPointerException();1082}10831084return objectFieldOffset1(c, name);1085}10861087/**1088* Reports the location of a given static field, in conjunction with {@link1089* #staticFieldBase}.1090* <p>Do not expect to perform any sort of arithmetic on this offset;1091* it is just a cookie which is passed to the unsafe heap memory accessors.1092*1093* <p>Any given field will always have the same offset, and no two distinct1094* fields of the same class will ever have the same offset.1095*1096* <p>As of 1.4.1, offsets for fields are represented as long values,1097* although the Sun JVM does not use the most significant 32 bits.1098* It is hard to imagine a JVM technology which needs more than1099* a few bits to encode an offset within a non-array object,1100* However, for consistency with other methods in this class,1101* this method reports its result as a long value.1102* @see #getInt(Object, long)1103*/1104public long staticFieldOffset(Field f) {1105if (f == null) {1106throw new NullPointerException();1107}11081109return staticFieldOffset0(f);1110}11111112/**1113* Reports the location of a given static field, in conjunction with {@link1114* #staticFieldOffset}.1115* <p>Fetch the base "Object", if any, with which static fields of the1116* given class can be accessed via methods like {@link #getInt(Object,1117* long)}. This value may be null. This value may refer to an object1118* which is a "cookie", not guaranteed to be a real Object, and it should1119* not be used in any way except as argument to the get and put routines in1120* this class.1121*/1122public Object staticFieldBase(Field f) {1123if (f == null) {1124throw new NullPointerException();1125}11261127return staticFieldBase0(f);1128}11291130/**1131* Detects if the given class may need to be initialized. This is often1132* needed in conjunction with obtaining the static field base of a1133* class.1134* @return false only if a call to {@code ensureClassInitialized} would have no effect1135*/1136public boolean shouldBeInitialized(Class<?> c) {1137if (c == null) {1138throw new NullPointerException();1139}11401141return shouldBeInitialized0(c);1142}11431144/**1145* Ensures the given class has been initialized. This is often1146* needed in conjunction with obtaining the static field base of a1147* class.1148*/1149public void ensureClassInitialized(Class<?> c) {1150if (c == null) {1151throw new NullPointerException();1152}11531154ensureClassInitialized0(c);1155}11561157/**1158* Reports the offset of the first element in the storage allocation of a1159* given array class. If {@link #arrayIndexScale} returns a non-zero value1160* for the same class, you may use that scale factor, together with this1161* base offset, to form new offsets to access elements of arrays of the1162* given class.1163*1164* @see #getInt(Object, long)1165* @see #putInt(Object, long, int)1166*/1167public int arrayBaseOffset(Class<?> arrayClass) {1168if (arrayClass == null) {1169throw new NullPointerException();1170}11711172return arrayBaseOffset0(arrayClass);1173}117411751176/** The value of {@code arrayBaseOffset(boolean[].class)} */1177public static final int ARRAY_BOOLEAN_BASE_OFFSET1178= theUnsafe.arrayBaseOffset(boolean[].class);11791180/** The value of {@code arrayBaseOffset(byte[].class)} */1181public static final int ARRAY_BYTE_BASE_OFFSET1182= theUnsafe.arrayBaseOffset(byte[].class);11831184/** The value of {@code arrayBaseOffset(short[].class)} */1185public static final int ARRAY_SHORT_BASE_OFFSET1186= theUnsafe.arrayBaseOffset(short[].class);11871188/** The value of {@code arrayBaseOffset(char[].class)} */1189public static final int ARRAY_CHAR_BASE_OFFSET1190= theUnsafe.arrayBaseOffset(char[].class);11911192/** The value of {@code arrayBaseOffset(int[].class)} */1193public static final int ARRAY_INT_BASE_OFFSET1194= theUnsafe.arrayBaseOffset(int[].class);11951196/** The value of {@code arrayBaseOffset(long[].class)} */1197public static final int ARRAY_LONG_BASE_OFFSET1198= theUnsafe.arrayBaseOffset(long[].class);11991200/** The value of {@code arrayBaseOffset(float[].class)} */1201public static final int ARRAY_FLOAT_BASE_OFFSET1202= theUnsafe.arrayBaseOffset(float[].class);12031204/** The value of {@code arrayBaseOffset(double[].class)} */1205public static final int ARRAY_DOUBLE_BASE_OFFSET1206= theUnsafe.arrayBaseOffset(double[].class);12071208/** The value of {@code arrayBaseOffset(Object[].class)} */1209public static final int ARRAY_OBJECT_BASE_OFFSET1210= theUnsafe.arrayBaseOffset(Object[].class);12111212/**1213* Reports the scale factor for addressing elements in the storage1214* allocation of a given array class. However, arrays of "narrow" types1215* will generally not work properly with accessors like {@link1216* #getByte(Object, long)}, so the scale factor for such classes is reported1217* as zero.1218*1219* @see #arrayBaseOffset1220* @see #getInt(Object, long)1221* @see #putInt(Object, long, int)1222*/1223public int arrayIndexScale(Class<?> arrayClass) {1224if (arrayClass == null) {1225throw new NullPointerException();1226}12271228return arrayIndexScale0(arrayClass);1229}123012311232/** The value of {@code arrayIndexScale(boolean[].class)} */1233public static final int ARRAY_BOOLEAN_INDEX_SCALE1234= theUnsafe.arrayIndexScale(boolean[].class);12351236/** The value of {@code arrayIndexScale(byte[].class)} */1237public static final int ARRAY_BYTE_INDEX_SCALE1238= theUnsafe.arrayIndexScale(byte[].class);12391240/** The value of {@code arrayIndexScale(short[].class)} */1241public static final int ARRAY_SHORT_INDEX_SCALE1242= theUnsafe.arrayIndexScale(short[].class);12431244/** The value of {@code arrayIndexScale(char[].class)} */1245public static final int ARRAY_CHAR_INDEX_SCALE1246= theUnsafe.arrayIndexScale(char[].class);12471248/** The value of {@code arrayIndexScale(int[].class)} */1249public static final int ARRAY_INT_INDEX_SCALE1250= theUnsafe.arrayIndexScale(int[].class);12511252/** The value of {@code arrayIndexScale(long[].class)} */1253public static final int ARRAY_LONG_INDEX_SCALE1254= theUnsafe.arrayIndexScale(long[].class);12551256/** The value of {@code arrayIndexScale(float[].class)} */1257public static final int ARRAY_FLOAT_INDEX_SCALE1258= theUnsafe.arrayIndexScale(float[].class);12591260/** The value of {@code arrayIndexScale(double[].class)} */1261public static final int ARRAY_DOUBLE_INDEX_SCALE1262= theUnsafe.arrayIndexScale(double[].class);12631264/** The value of {@code arrayIndexScale(Object[].class)} */1265public static final int ARRAY_OBJECT_INDEX_SCALE1266= theUnsafe.arrayIndexScale(Object[].class);12671268/**1269* Reports the size in bytes of a native pointer, as stored via {@link1270* #putAddress}. This value will be either 4 or 8. Note that the sizes of1271* other primitive types (as stored in native memory blocks) is determined1272* fully by their information content.1273*/1274public int addressSize() {1275return ADDRESS_SIZE;1276}12771278/** The value of {@code addressSize()} */1279public static final int ADDRESS_SIZE = ADDRESS_SIZE0;12801281/**1282* Reports the size in bytes of a native memory page (whatever that is).1283* This value will always be a power of two.1284*/1285public int pageSize() { return PAGE_SIZE; }12861287/**1288* Reports the size in bytes of a data cache line written back by1289* the hardware cache line flush operation available to the JVM or1290* 0 if data cache line flushing is not enabled.1291*/1292public int dataCacheLineFlushSize() { return DATA_CACHE_LINE_FLUSH_SIZE; }12931294/**1295* Rounds down address to a data cache line boundary as1296* determined by {@link #dataCacheLineFlushSize}1297* @return the rounded down address1298*/1299public long dataCacheLineAlignDown(long address) {1300return (address & ~(DATA_CACHE_LINE_FLUSH_SIZE - 1));1301}13021303/**1304* Returns true if data cache line writeback1305*/1306public static boolean isWritebackEnabled() { return DATA_CACHE_LINE_FLUSH_SIZE != 0; }13071308/// random trusted operations from JNI:13091310/**1311* Tells the VM to define a class, without security checks. By default, the1312* class loader and protection domain come from the caller's class.1313*/1314public Class<?> defineClass(String name, byte[] b, int off, int len,1315ClassLoader loader,1316ProtectionDomain protectionDomain) {1317if (b == null) {1318throw new NullPointerException();1319}1320if (len < 0) {1321throw new ArrayIndexOutOfBoundsException();1322}13231324return defineClass0(name, b, off, len, loader, protectionDomain);1325}13261327public native Class<?> defineClass0(String name, byte[] b, int off, int len,1328ClassLoader loader,1329ProtectionDomain protectionDomain);13301331/**1332* Allocates an instance but does not run any constructor.1333* Initializes the class if it has not yet been.1334*/1335@IntrinsicCandidate1336public native Object allocateInstance(Class<?> cls)1337throws InstantiationException;13381339/**1340* Allocates an array of a given type, but does not do zeroing.1341* <p>1342* This method should only be used in the very rare cases where a high-performance code1343* overwrites the destination array completely, and compilers cannot assist in zeroing elimination.1344* In an overwhelming majority of cases, a normal Java allocation should be used instead.1345* <p>1346* Users of this method are <b>required</b> to overwrite the initial (garbage) array contents1347* before allowing untrusted code, or code in other threads, to observe the reference1348* to the newly allocated array. In addition, the publication of the array reference must be1349* safe according to the Java Memory Model requirements.1350* <p>1351* The safest approach to deal with an uninitialized array is to keep the reference to it in local1352* variable at least until the initialization is complete, and then publish it <b>once</b>, either1353* by writing it to a <em>volatile</em> field, or storing it into a <em>final</em> field in constructor,1354* or issuing a {@link #storeFence} before publishing the reference.1355* <p>1356* @implnote This method can only allocate primitive arrays, to avoid garbage reference1357* elements that could break heap integrity.1358*1359* @param componentType array component type to allocate1360* @param length array size to allocate1361* @throws IllegalArgumentException if component type is null, or not a primitive class;1362* or the length is negative1363*/1364public Object allocateUninitializedArray(Class<?> componentType, int length) {1365if (componentType == null) {1366throw new IllegalArgumentException("Component type is null");1367}1368if (!componentType.isPrimitive()) {1369throw new IllegalArgumentException("Component type is not primitive");1370}1371if (length < 0) {1372throw new IllegalArgumentException("Negative length");1373}1374return allocateUninitializedArray0(componentType, length);1375}13761377@IntrinsicCandidate1378private Object allocateUninitializedArray0(Class<?> componentType, int length) {1379// These fallbacks provide zeroed arrays, but intrinsic is not required to1380// return the zeroed arrays.1381if (componentType == byte.class) return new byte[length];1382if (componentType == boolean.class) return new boolean[length];1383if (componentType == short.class) return new short[length];1384if (componentType == char.class) return new char[length];1385if (componentType == int.class) return new int[length];1386if (componentType == float.class) return new float[length];1387if (componentType == long.class) return new long[length];1388if (componentType == double.class) return new double[length];1389return null;1390}13911392/** Throws the exception without telling the verifier. */1393public native void throwException(Throwable ee);13941395/**1396* Atomically updates Java variable to {@code x} if it is currently1397* holding {@code expected}.1398*1399* <p>This operation has memory semantics of a {@code volatile} read1400* and write. Corresponds to C11 atomic_compare_exchange_strong.1401*1402* @return {@code true} if successful1403*/1404@IntrinsicCandidate1405public final native boolean compareAndSetReference(Object o, long offset,1406Object expected,1407Object x);14081409@IntrinsicCandidate1410public final native Object compareAndExchangeReference(Object o, long offset,1411Object expected,1412Object x);14131414@IntrinsicCandidate1415public final Object compareAndExchangeReferenceAcquire(Object o, long offset,1416Object expected,1417Object x) {1418return compareAndExchangeReference(o, offset, expected, x);1419}14201421@IntrinsicCandidate1422public final Object compareAndExchangeReferenceRelease(Object o, long offset,1423Object expected,1424Object x) {1425return compareAndExchangeReference(o, offset, expected, x);1426}14271428@IntrinsicCandidate1429public final boolean weakCompareAndSetReferencePlain(Object o, long offset,1430Object expected,1431Object x) {1432return compareAndSetReference(o, offset, expected, x);1433}14341435@IntrinsicCandidate1436public final boolean weakCompareAndSetReferenceAcquire(Object o, long offset,1437Object expected,1438Object x) {1439return compareAndSetReference(o, offset, expected, x);1440}14411442@IntrinsicCandidate1443public final boolean weakCompareAndSetReferenceRelease(Object o, long offset,1444Object expected,1445Object x) {1446return compareAndSetReference(o, offset, expected, x);1447}14481449@IntrinsicCandidate1450public final boolean weakCompareAndSetReference(Object o, long offset,1451Object expected,1452Object x) {1453return compareAndSetReference(o, offset, expected, x);1454}14551456/**1457* Atomically updates Java variable to {@code x} if it is currently1458* holding {@code expected}.1459*1460* <p>This operation has memory semantics of a {@code volatile} read1461* and write. Corresponds to C11 atomic_compare_exchange_strong.1462*1463* @return {@code true} if successful1464*/1465@IntrinsicCandidate1466public final native boolean compareAndSetInt(Object o, long offset,1467int expected,1468int x);14691470@IntrinsicCandidate1471public final native int compareAndExchangeInt(Object o, long offset,1472int expected,1473int x);14741475@IntrinsicCandidate1476public final int compareAndExchangeIntAcquire(Object o, long offset,1477int expected,1478int x) {1479return compareAndExchangeInt(o, offset, expected, x);1480}14811482@IntrinsicCandidate1483public final int compareAndExchangeIntRelease(Object o, long offset,1484int expected,1485int x) {1486return compareAndExchangeInt(o, offset, expected, x);1487}14881489@IntrinsicCandidate1490public final boolean weakCompareAndSetIntPlain(Object o, long offset,1491int expected,1492int x) {1493return compareAndSetInt(o, offset, expected, x);1494}14951496@IntrinsicCandidate1497public final boolean weakCompareAndSetIntAcquire(Object o, long offset,1498int expected,1499int x) {1500return compareAndSetInt(o, offset, expected, x);1501}15021503@IntrinsicCandidate1504public final boolean weakCompareAndSetIntRelease(Object o, long offset,1505int expected,1506int x) {1507return compareAndSetInt(o, offset, expected, x);1508}15091510@IntrinsicCandidate1511public final boolean weakCompareAndSetInt(Object o, long offset,1512int expected,1513int x) {1514return compareAndSetInt(o, offset, expected, x);1515}15161517@IntrinsicCandidate1518public final byte compareAndExchangeByte(Object o, long offset,1519byte expected,1520byte x) {1521long wordOffset = offset & ~3;1522int shift = (int) (offset & 3) << 3;1523if (BIG_ENDIAN) {1524shift = 24 - shift;1525}1526int mask = 0xFF << shift;1527int maskedExpected = (expected & 0xFF) << shift;1528int maskedX = (x & 0xFF) << shift;1529int fullWord;1530do {1531fullWord = getIntVolatile(o, wordOffset);1532if ((fullWord & mask) != maskedExpected)1533return (byte) ((fullWord & mask) >> shift);1534} while (!weakCompareAndSetInt(o, wordOffset,1535fullWord, (fullWord & ~mask) | maskedX));1536return expected;1537}15381539@IntrinsicCandidate1540public final boolean compareAndSetByte(Object o, long offset,1541byte expected,1542byte x) {1543return compareAndExchangeByte(o, offset, expected, x) == expected;1544}15451546@IntrinsicCandidate1547public final boolean weakCompareAndSetByte(Object o, long offset,1548byte expected,1549byte x) {1550return compareAndSetByte(o, offset, expected, x);1551}15521553@IntrinsicCandidate1554public final boolean weakCompareAndSetByteAcquire(Object o, long offset,1555byte expected,1556byte x) {1557return weakCompareAndSetByte(o, offset, expected, x);1558}15591560@IntrinsicCandidate1561public final boolean weakCompareAndSetByteRelease(Object o, long offset,1562byte expected,1563byte x) {1564return weakCompareAndSetByte(o, offset, expected, x);1565}15661567@IntrinsicCandidate1568public final boolean weakCompareAndSetBytePlain(Object o, long offset,1569byte expected,1570byte x) {1571return weakCompareAndSetByte(o, offset, expected, x);1572}15731574@IntrinsicCandidate1575public final byte compareAndExchangeByteAcquire(Object o, long offset,1576byte expected,1577byte x) {1578return compareAndExchangeByte(o, offset, expected, x);1579}15801581@IntrinsicCandidate1582public final byte compareAndExchangeByteRelease(Object o, long offset,1583byte expected,1584byte x) {1585return compareAndExchangeByte(o, offset, expected, x);1586}15871588@IntrinsicCandidate1589public final short compareAndExchangeShort(Object o, long offset,1590short expected,1591short x) {1592if ((offset & 3) == 3) {1593throw new IllegalArgumentException("Update spans the word, not supported");1594}1595long wordOffset = offset & ~3;1596int shift = (int) (offset & 3) << 3;1597if (BIG_ENDIAN) {1598shift = 16 - shift;1599}1600int mask = 0xFFFF << shift;1601int maskedExpected = (expected & 0xFFFF) << shift;1602int maskedX = (x & 0xFFFF) << shift;1603int fullWord;1604do {1605fullWord = getIntVolatile(o, wordOffset);1606if ((fullWord & mask) != maskedExpected) {1607return (short) ((fullWord & mask) >> shift);1608}1609} while (!weakCompareAndSetInt(o, wordOffset,1610fullWord, (fullWord & ~mask) | maskedX));1611return expected;1612}16131614@IntrinsicCandidate1615public final boolean compareAndSetShort(Object o, long offset,1616short expected,1617short x) {1618return compareAndExchangeShort(o, offset, expected, x) == expected;1619}16201621@IntrinsicCandidate1622public final boolean weakCompareAndSetShort(Object o, long offset,1623short expected,1624short x) {1625return compareAndSetShort(o, offset, expected, x);1626}16271628@IntrinsicCandidate1629public final boolean weakCompareAndSetShortAcquire(Object o, long offset,1630short expected,1631short x) {1632return weakCompareAndSetShort(o, offset, expected, x);1633}16341635@IntrinsicCandidate1636public final boolean weakCompareAndSetShortRelease(Object o, long offset,1637short expected,1638short x) {1639return weakCompareAndSetShort(o, offset, expected, x);1640}16411642@IntrinsicCandidate1643public final boolean weakCompareAndSetShortPlain(Object o, long offset,1644short expected,1645short x) {1646return weakCompareAndSetShort(o, offset, expected, x);1647}164816491650@IntrinsicCandidate1651public final short compareAndExchangeShortAcquire(Object o, long offset,1652short expected,1653short x) {1654return compareAndExchangeShort(o, offset, expected, x);1655}16561657@IntrinsicCandidate1658public final short compareAndExchangeShortRelease(Object o, long offset,1659short expected,1660short x) {1661return compareAndExchangeShort(o, offset, expected, x);1662}16631664@ForceInline1665private char s2c(short s) {1666return (char) s;1667}16681669@ForceInline1670private short c2s(char s) {1671return (short) s;1672}16731674@ForceInline1675public final boolean compareAndSetChar(Object o, long offset,1676char expected,1677char x) {1678return compareAndSetShort(o, offset, c2s(expected), c2s(x));1679}16801681@ForceInline1682public final char compareAndExchangeChar(Object o, long offset,1683char expected,1684char x) {1685return s2c(compareAndExchangeShort(o, offset, c2s(expected), c2s(x)));1686}16871688@ForceInline1689public final char compareAndExchangeCharAcquire(Object o, long offset,1690char expected,1691char x) {1692return s2c(compareAndExchangeShortAcquire(o, offset, c2s(expected), c2s(x)));1693}16941695@ForceInline1696public final char compareAndExchangeCharRelease(Object o, long offset,1697char expected,1698char x) {1699return s2c(compareAndExchangeShortRelease(o, offset, c2s(expected), c2s(x)));1700}17011702@ForceInline1703public final boolean weakCompareAndSetChar(Object o, long offset,1704char expected,1705char x) {1706return weakCompareAndSetShort(o, offset, c2s(expected), c2s(x));1707}17081709@ForceInline1710public final boolean weakCompareAndSetCharAcquire(Object o, long offset,1711char expected,1712char x) {1713return weakCompareAndSetShortAcquire(o, offset, c2s(expected), c2s(x));1714}17151716@ForceInline1717public final boolean weakCompareAndSetCharRelease(Object o, long offset,1718char expected,1719char x) {1720return weakCompareAndSetShortRelease(o, offset, c2s(expected), c2s(x));1721}17221723@ForceInline1724public final boolean weakCompareAndSetCharPlain(Object o, long offset,1725char expected,1726char x) {1727return weakCompareAndSetShortPlain(o, offset, c2s(expected), c2s(x));1728}17291730/**1731* The JVM converts integral values to boolean values using two1732* different conventions, byte testing against zero and truncation1733* to least-significant bit.1734*1735* <p>The JNI documents specify that, at least for returning1736* values from native methods, a Java boolean value is converted1737* to the value-set 0..1 by first truncating to a byte (0..255 or1738* maybe -128..127) and then testing against zero. Thus, Java1739* booleans in non-Java data structures are by convention1740* represented as 8-bit containers containing either zero (for1741* false) or any non-zero value (for true).1742*1743* <p>Java booleans in the heap are also stored in bytes, but are1744* strongly normalized to the value-set 0..1 (i.e., they are1745* truncated to the least-significant bit).1746*1747* <p>The main reason for having different conventions for1748* conversion is performance: Truncation to the least-significant1749* bit can be usually implemented with fewer (machine)1750* instructions than byte testing against zero.1751*1752* <p>A number of Unsafe methods load boolean values from the heap1753* as bytes. Unsafe converts those values according to the JNI1754* rules (i.e, using the "testing against zero" convention). The1755* method {@code byte2bool} implements that conversion.1756*1757* @param b the byte to be converted to boolean1758* @return the result of the conversion1759*/1760@ForceInline1761private boolean byte2bool(byte b) {1762return b != 0;1763}17641765/**1766* Convert a boolean value to a byte. The return value is strongly1767* normalized to the value-set 0..1 (i.e., the value is truncated1768* to the least-significant bit). See {@link #byte2bool(byte)} for1769* more details on conversion conventions.1770*1771* @param b the boolean to be converted to byte (and then normalized)1772* @return the result of the conversion1773*/1774@ForceInline1775private byte bool2byte(boolean b) {1776return b ? (byte)1 : (byte)0;1777}17781779@ForceInline1780public final boolean compareAndSetBoolean(Object o, long offset,1781boolean expected,1782boolean x) {1783return compareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));1784}17851786@ForceInline1787public final boolean compareAndExchangeBoolean(Object o, long offset,1788boolean expected,1789boolean x) {1790return byte2bool(compareAndExchangeByte(o, offset, bool2byte(expected), bool2byte(x)));1791}17921793@ForceInline1794public final boolean compareAndExchangeBooleanAcquire(Object o, long offset,1795boolean expected,1796boolean x) {1797return byte2bool(compareAndExchangeByteAcquire(o, offset, bool2byte(expected), bool2byte(x)));1798}17991800@ForceInline1801public final boolean compareAndExchangeBooleanRelease(Object o, long offset,1802boolean expected,1803boolean x) {1804return byte2bool(compareAndExchangeByteRelease(o, offset, bool2byte(expected), bool2byte(x)));1805}18061807@ForceInline1808public final boolean weakCompareAndSetBoolean(Object o, long offset,1809boolean expected,1810boolean x) {1811return weakCompareAndSetByte(o, offset, bool2byte(expected), bool2byte(x));1812}18131814@ForceInline1815public final boolean weakCompareAndSetBooleanAcquire(Object o, long offset,1816boolean expected,1817boolean x) {1818return weakCompareAndSetByteAcquire(o, offset, bool2byte(expected), bool2byte(x));1819}18201821@ForceInline1822public final boolean weakCompareAndSetBooleanRelease(Object o, long offset,1823boolean expected,1824boolean x) {1825return weakCompareAndSetByteRelease(o, offset, bool2byte(expected), bool2byte(x));1826}18271828@ForceInline1829public final boolean weakCompareAndSetBooleanPlain(Object o, long offset,1830boolean expected,1831boolean x) {1832return weakCompareAndSetBytePlain(o, offset, bool2byte(expected), bool2byte(x));1833}18341835/**1836* Atomically updates Java variable to {@code x} if it is currently1837* holding {@code expected}.1838*1839* <p>This operation has memory semantics of a {@code volatile} read1840* and write. Corresponds to C11 atomic_compare_exchange_strong.1841*1842* @return {@code true} if successful1843*/1844@ForceInline1845public final boolean compareAndSetFloat(Object o, long offset,1846float expected,1847float x) {1848return compareAndSetInt(o, offset,1849Float.floatToRawIntBits(expected),1850Float.floatToRawIntBits(x));1851}18521853@ForceInline1854public final float compareAndExchangeFloat(Object o, long offset,1855float expected,1856float x) {1857int w = compareAndExchangeInt(o, offset,1858Float.floatToRawIntBits(expected),1859Float.floatToRawIntBits(x));1860return Float.intBitsToFloat(w);1861}18621863@ForceInline1864public final float compareAndExchangeFloatAcquire(Object o, long offset,1865float expected,1866float x) {1867int w = compareAndExchangeIntAcquire(o, offset,1868Float.floatToRawIntBits(expected),1869Float.floatToRawIntBits(x));1870return Float.intBitsToFloat(w);1871}18721873@ForceInline1874public final float compareAndExchangeFloatRelease(Object o, long offset,1875float expected,1876float x) {1877int w = compareAndExchangeIntRelease(o, offset,1878Float.floatToRawIntBits(expected),1879Float.floatToRawIntBits(x));1880return Float.intBitsToFloat(w);1881}18821883@ForceInline1884public final boolean weakCompareAndSetFloatPlain(Object o, long offset,1885float expected,1886float x) {1887return weakCompareAndSetIntPlain(o, offset,1888Float.floatToRawIntBits(expected),1889Float.floatToRawIntBits(x));1890}18911892@ForceInline1893public final boolean weakCompareAndSetFloatAcquire(Object o, long offset,1894float expected,1895float x) {1896return weakCompareAndSetIntAcquire(o, offset,1897Float.floatToRawIntBits(expected),1898Float.floatToRawIntBits(x));1899}19001901@ForceInline1902public final boolean weakCompareAndSetFloatRelease(Object o, long offset,1903float expected,1904float x) {1905return weakCompareAndSetIntRelease(o, offset,1906Float.floatToRawIntBits(expected),1907Float.floatToRawIntBits(x));1908}19091910@ForceInline1911public final boolean weakCompareAndSetFloat(Object o, long offset,1912float expected,1913float x) {1914return weakCompareAndSetInt(o, offset,1915Float.floatToRawIntBits(expected),1916Float.floatToRawIntBits(x));1917}19181919/**1920* Atomically updates Java variable to {@code x} if it is currently1921* holding {@code expected}.1922*1923* <p>This operation has memory semantics of a {@code volatile} read1924* and write. Corresponds to C11 atomic_compare_exchange_strong.1925*1926* @return {@code true} if successful1927*/1928@ForceInline1929public final boolean compareAndSetDouble(Object o, long offset,1930double expected,1931double x) {1932return compareAndSetLong(o, offset,1933Double.doubleToRawLongBits(expected),1934Double.doubleToRawLongBits(x));1935}19361937@ForceInline1938public final double compareAndExchangeDouble(Object o, long offset,1939double expected,1940double x) {1941long w = compareAndExchangeLong(o, offset,1942Double.doubleToRawLongBits(expected),1943Double.doubleToRawLongBits(x));1944return Double.longBitsToDouble(w);1945}19461947@ForceInline1948public final double compareAndExchangeDoubleAcquire(Object o, long offset,1949double expected,1950double x) {1951long w = compareAndExchangeLongAcquire(o, offset,1952Double.doubleToRawLongBits(expected),1953Double.doubleToRawLongBits(x));1954return Double.longBitsToDouble(w);1955}19561957@ForceInline1958public final double compareAndExchangeDoubleRelease(Object o, long offset,1959double expected,1960double x) {1961long w = compareAndExchangeLongRelease(o, offset,1962Double.doubleToRawLongBits(expected),1963Double.doubleToRawLongBits(x));1964return Double.longBitsToDouble(w);1965}19661967@ForceInline1968public final boolean weakCompareAndSetDoublePlain(Object o, long offset,1969double expected,1970double x) {1971return weakCompareAndSetLongPlain(o, offset,1972Double.doubleToRawLongBits(expected),1973Double.doubleToRawLongBits(x));1974}19751976@ForceInline1977public final boolean weakCompareAndSetDoubleAcquire(Object o, long offset,1978double expected,1979double x) {1980return weakCompareAndSetLongAcquire(o, offset,1981Double.doubleToRawLongBits(expected),1982Double.doubleToRawLongBits(x));1983}19841985@ForceInline1986public final boolean weakCompareAndSetDoubleRelease(Object o, long offset,1987double expected,1988double x) {1989return weakCompareAndSetLongRelease(o, offset,1990Double.doubleToRawLongBits(expected),1991Double.doubleToRawLongBits(x));1992}19931994@ForceInline1995public final boolean weakCompareAndSetDouble(Object o, long offset,1996double expected,1997double x) {1998return weakCompareAndSetLong(o, offset,1999Double.doubleToRawLongBits(expected),2000Double.doubleToRawLongBits(x));2001}20022003/**2004* Atomically updates Java variable to {@code x} if it is currently2005* holding {@code expected}.2006*2007* <p>This operation has memory semantics of a {@code volatile} read2008* and write. Corresponds to C11 atomic_compare_exchange_strong.2009*2010* @return {@code true} if successful2011*/2012@IntrinsicCandidate2013public final native boolean compareAndSetLong(Object o, long offset,2014long expected,2015long x);20162017@IntrinsicCandidate2018public final native long compareAndExchangeLong(Object o, long offset,2019long expected,2020long x);20212022@IntrinsicCandidate2023public final long compareAndExchangeLongAcquire(Object o, long offset,2024long expected,2025long x) {2026return compareAndExchangeLong(o, offset, expected, x);2027}20282029@IntrinsicCandidate2030public final long compareAndExchangeLongRelease(Object o, long offset,2031long expected,2032long x) {2033return compareAndExchangeLong(o, offset, expected, x);2034}20352036@IntrinsicCandidate2037public final boolean weakCompareAndSetLongPlain(Object o, long offset,2038long expected,2039long x) {2040return compareAndSetLong(o, offset, expected, x);2041}20422043@IntrinsicCandidate2044public final boolean weakCompareAndSetLongAcquire(Object o, long offset,2045long expected,2046long x) {2047return compareAndSetLong(o, offset, expected, x);2048}20492050@IntrinsicCandidate2051public final boolean weakCompareAndSetLongRelease(Object o, long offset,2052long expected,2053long x) {2054return compareAndSetLong(o, offset, expected, x);2055}20562057@IntrinsicCandidate2058public final boolean weakCompareAndSetLong(Object o, long offset,2059long expected,2060long x) {2061return compareAndSetLong(o, offset, expected, x);2062}20632064/**2065* Fetches a reference value from a given Java variable, with volatile2066* load semantics. Otherwise identical to {@link #getReference(Object, long)}2067*/2068@IntrinsicCandidate2069public native Object getReferenceVolatile(Object o, long offset);20702071/**2072* Stores a reference value into a given Java variable, with2073* volatile store semantics. Otherwise identical to {@link #putReference(Object, long, Object)}2074*/2075@IntrinsicCandidate2076public native void putReferenceVolatile(Object o, long offset, Object x);20772078/** Volatile version of {@link #getInt(Object, long)} */2079@IntrinsicCandidate2080public native int getIntVolatile(Object o, long offset);20812082/** Volatile version of {@link #putInt(Object, long, int)} */2083@IntrinsicCandidate2084public native void putIntVolatile(Object o, long offset, int x);20852086/** Volatile version of {@link #getBoolean(Object, long)} */2087@IntrinsicCandidate2088public native boolean getBooleanVolatile(Object o, long offset);20892090/** Volatile version of {@link #putBoolean(Object, long, boolean)} */2091@IntrinsicCandidate2092public native void putBooleanVolatile(Object o, long offset, boolean x);20932094/** Volatile version of {@link #getByte(Object, long)} */2095@IntrinsicCandidate2096public native byte getByteVolatile(Object o, long offset);20972098/** Volatile version of {@link #putByte(Object, long, byte)} */2099@IntrinsicCandidate2100public native void putByteVolatile(Object o, long offset, byte x);21012102/** Volatile version of {@link #getShort(Object, long)} */2103@IntrinsicCandidate2104public native short getShortVolatile(Object o, long offset);21052106/** Volatile version of {@link #putShort(Object, long, short)} */2107@IntrinsicCandidate2108public native void putShortVolatile(Object o, long offset, short x);21092110/** Volatile version of {@link #getChar(Object, long)} */2111@IntrinsicCandidate2112public native char getCharVolatile(Object o, long offset);21132114/** Volatile version of {@link #putChar(Object, long, char)} */2115@IntrinsicCandidate2116public native void putCharVolatile(Object o, long offset, char x);21172118/** Volatile version of {@link #getLong(Object, long)} */2119@IntrinsicCandidate2120public native long getLongVolatile(Object o, long offset);21212122/** Volatile version of {@link #putLong(Object, long, long)} */2123@IntrinsicCandidate2124public native void putLongVolatile(Object o, long offset, long x);21252126/** Volatile version of {@link #getFloat(Object, long)} */2127@IntrinsicCandidate2128public native float getFloatVolatile(Object o, long offset);21292130/** Volatile version of {@link #putFloat(Object, long, float)} */2131@IntrinsicCandidate2132public native void putFloatVolatile(Object o, long offset, float x);21332134/** Volatile version of {@link #getDouble(Object, long)} */2135@IntrinsicCandidate2136public native double getDoubleVolatile(Object o, long offset);21372138/** Volatile version of {@link #putDouble(Object, long, double)} */2139@IntrinsicCandidate2140public native void putDoubleVolatile(Object o, long offset, double x);2141214221432144/** Acquire version of {@link #getReferenceVolatile(Object, long)} */2145@IntrinsicCandidate2146public final Object getReferenceAcquire(Object o, long offset) {2147return getReferenceVolatile(o, offset);2148}21492150/** Acquire version of {@link #getBooleanVolatile(Object, long)} */2151@IntrinsicCandidate2152public final boolean getBooleanAcquire(Object o, long offset) {2153return getBooleanVolatile(o, offset);2154}21552156/** Acquire version of {@link #getByteVolatile(Object, long)} */2157@IntrinsicCandidate2158public final byte getByteAcquire(Object o, long offset) {2159return getByteVolatile(o, offset);2160}21612162/** Acquire version of {@link #getShortVolatile(Object, long)} */2163@IntrinsicCandidate2164public final short getShortAcquire(Object o, long offset) {2165return getShortVolatile(o, offset);2166}21672168/** Acquire version of {@link #getCharVolatile(Object, long)} */2169@IntrinsicCandidate2170public final char getCharAcquire(Object o, long offset) {2171return getCharVolatile(o, offset);2172}21732174/** Acquire version of {@link #getIntVolatile(Object, long)} */2175@IntrinsicCandidate2176public final int getIntAcquire(Object o, long offset) {2177return getIntVolatile(o, offset);2178}21792180/** Acquire version of {@link #getFloatVolatile(Object, long)} */2181@IntrinsicCandidate2182public final float getFloatAcquire(Object o, long offset) {2183return getFloatVolatile(o, offset);2184}21852186/** Acquire version of {@link #getLongVolatile(Object, long)} */2187@IntrinsicCandidate2188public final long getLongAcquire(Object o, long offset) {2189return getLongVolatile(o, offset);2190}21912192/** Acquire version of {@link #getDoubleVolatile(Object, long)} */2193@IntrinsicCandidate2194public final double getDoubleAcquire(Object o, long offset) {2195return getDoubleVolatile(o, offset);2196}21972198/*2199* Versions of {@link #putReferenceVolatile(Object, long, Object)}2200* that do not guarantee immediate visibility of the store to2201* other threads. This method is generally only useful if the2202* underlying field is a Java volatile (or if an array cell, one2203* that is otherwise only accessed using volatile accesses).2204*2205* Corresponds to C11 atomic_store_explicit(..., memory_order_release).2206*/22072208/** Release version of {@link #putReferenceVolatile(Object, long, Object)} */2209@IntrinsicCandidate2210public final void putReferenceRelease(Object o, long offset, Object x) {2211putReferenceVolatile(o, offset, x);2212}22132214/** Release version of {@link #putBooleanVolatile(Object, long, boolean)} */2215@IntrinsicCandidate2216public final void putBooleanRelease(Object o, long offset, boolean x) {2217putBooleanVolatile(o, offset, x);2218}22192220/** Release version of {@link #putByteVolatile(Object, long, byte)} */2221@IntrinsicCandidate2222public final void putByteRelease(Object o, long offset, byte x) {2223putByteVolatile(o, offset, x);2224}22252226/** Release version of {@link #putShortVolatile(Object, long, short)} */2227@IntrinsicCandidate2228public final void putShortRelease(Object o, long offset, short x) {2229putShortVolatile(o, offset, x);2230}22312232/** Release version of {@link #putCharVolatile(Object, long, char)} */2233@IntrinsicCandidate2234public final void putCharRelease(Object o, long offset, char x) {2235putCharVolatile(o, offset, x);2236}22372238/** Release version of {@link #putIntVolatile(Object, long, int)} */2239@IntrinsicCandidate2240public final void putIntRelease(Object o, long offset, int x) {2241putIntVolatile(o, offset, x);2242}22432244/** Release version of {@link #putFloatVolatile(Object, long, float)} */2245@IntrinsicCandidate2246public final void putFloatRelease(Object o, long offset, float x) {2247putFloatVolatile(o, offset, x);2248}22492250/** Release version of {@link #putLongVolatile(Object, long, long)} */2251@IntrinsicCandidate2252public final void putLongRelease(Object o, long offset, long x) {2253putLongVolatile(o, offset, x);2254}22552256/** Release version of {@link #putDoubleVolatile(Object, long, double)} */2257@IntrinsicCandidate2258public final void putDoubleRelease(Object o, long offset, double x) {2259putDoubleVolatile(o, offset, x);2260}22612262// ------------------------------ Opaque --------------------------------------22632264/** Opaque version of {@link #getReferenceVolatile(Object, long)} */2265@IntrinsicCandidate2266public final Object getReferenceOpaque(Object o, long offset) {2267return getReferenceVolatile(o, offset);2268}22692270/** Opaque version of {@link #getBooleanVolatile(Object, long)} */2271@IntrinsicCandidate2272public final boolean getBooleanOpaque(Object o, long offset) {2273return getBooleanVolatile(o, offset);2274}22752276/** Opaque version of {@link #getByteVolatile(Object, long)} */2277@IntrinsicCandidate2278public final byte getByteOpaque(Object o, long offset) {2279return getByteVolatile(o, offset);2280}22812282/** Opaque version of {@link #getShortVolatile(Object, long)} */2283@IntrinsicCandidate2284public final short getShortOpaque(Object o, long offset) {2285return getShortVolatile(o, offset);2286}22872288/** Opaque version of {@link #getCharVolatile(Object, long)} */2289@IntrinsicCandidate2290public final char getCharOpaque(Object o, long offset) {2291return getCharVolatile(o, offset);2292}22932294/** Opaque version of {@link #getIntVolatile(Object, long)} */2295@IntrinsicCandidate2296public final int getIntOpaque(Object o, long offset) {2297return getIntVolatile(o, offset);2298}22992300/** Opaque version of {@link #getFloatVolatile(Object, long)} */2301@IntrinsicCandidate2302public final float getFloatOpaque(Object o, long offset) {2303return getFloatVolatile(o, offset);2304}23052306/** Opaque version of {@link #getLongVolatile(Object, long)} */2307@IntrinsicCandidate2308public final long getLongOpaque(Object o, long offset) {2309return getLongVolatile(o, offset);2310}23112312/** Opaque version of {@link #getDoubleVolatile(Object, long)} */2313@IntrinsicCandidate2314public final double getDoubleOpaque(Object o, long offset) {2315return getDoubleVolatile(o, offset);2316}23172318/** Opaque version of {@link #putReferenceVolatile(Object, long, Object)} */2319@IntrinsicCandidate2320public final void putReferenceOpaque(Object o, long offset, Object x) {2321putReferenceVolatile(o, offset, x);2322}23232324/** Opaque version of {@link #putBooleanVolatile(Object, long, boolean)} */2325@IntrinsicCandidate2326public final void putBooleanOpaque(Object o, long offset, boolean x) {2327putBooleanVolatile(o, offset, x);2328}23292330/** Opaque version of {@link #putByteVolatile(Object, long, byte)} */2331@IntrinsicCandidate2332public final void putByteOpaque(Object o, long offset, byte x) {2333putByteVolatile(o, offset, x);2334}23352336/** Opaque version of {@link #putShortVolatile(Object, long, short)} */2337@IntrinsicCandidate2338public final void putShortOpaque(Object o, long offset, short x) {2339putShortVolatile(o, offset, x);2340}23412342/** Opaque version of {@link #putCharVolatile(Object, long, char)} */2343@IntrinsicCandidate2344public final void putCharOpaque(Object o, long offset, char x) {2345putCharVolatile(o, offset, x);2346}23472348/** Opaque version of {@link #putIntVolatile(Object, long, int)} */2349@IntrinsicCandidate2350public final void putIntOpaque(Object o, long offset, int x) {2351putIntVolatile(o, offset, x);2352}23532354/** Opaque version of {@link #putFloatVolatile(Object, long, float)} */2355@IntrinsicCandidate2356public final void putFloatOpaque(Object o, long offset, float x) {2357putFloatVolatile(o, offset, x);2358}23592360/** Opaque version of {@link #putLongVolatile(Object, long, long)} */2361@IntrinsicCandidate2362public final void putLongOpaque(Object o, long offset, long x) {2363putLongVolatile(o, offset, x);2364}23652366/** Opaque version of {@link #putDoubleVolatile(Object, long, double)} */2367@IntrinsicCandidate2368public final void putDoubleOpaque(Object o, long offset, double x) {2369putDoubleVolatile(o, offset, x);2370}23712372/**2373* Unblocks the given thread blocked on {@code park}, or, if it is2374* not blocked, causes the subsequent call to {@code park} not to2375* block. Note: this operation is "unsafe" solely because the2376* caller must somehow ensure that the thread has not been2377* destroyed. Nothing special is usually required to ensure this2378* when called from Java (in which there will ordinarily be a live2379* reference to the thread) but this is not nearly-automatically2380* so when calling from native code.2381*2382* @param thread the thread to unpark.2383*/2384@IntrinsicCandidate2385public native void unpark(Object thread);23862387/**2388* Blocks current thread, returning when a balancing2389* {@code unpark} occurs, or a balancing {@code unpark} has2390* already occurred, or the thread is interrupted, or, if not2391* absolute and time is not zero, the given time nanoseconds have2392* elapsed, or if absolute, the given deadline in milliseconds2393* since Epoch has passed, or spuriously (i.e., returning for no2394* "reason"). Note: This operation is in the Unsafe class only2395* because {@code unpark} is, so it would be strange to place it2396* elsewhere.2397*/2398@IntrinsicCandidate2399public native void park(boolean isAbsolute, long time);24002401/**2402* Gets the load average in the system run queue assigned2403* to the available processors averaged over various periods of time.2404* This method retrieves the given {@code nelem} samples and2405* assigns to the elements of the given {@code loadavg} array.2406* The system imposes a maximum of 3 samples, representing2407* averages over the last 1, 5, and 15 minutes, respectively.2408*2409* @param loadavg an array of double of size nelems2410* @param nelems the number of samples to be retrieved and2411* must be 1 to 3.2412*2413* @return the number of samples actually retrieved; or -12414* if the load average is unobtainable.2415*/2416public int getLoadAverage(double[] loadavg, int nelems) {2417if (nelems < 0 || nelems > 3 || nelems > loadavg.length) {2418throw new ArrayIndexOutOfBoundsException();2419}24202421return getLoadAverage0(loadavg, nelems);2422}24232424// The following contain CAS-based Java implementations used on2425// platforms not supporting native instructions24262427/**2428* Atomically adds the given value to the current value of a field2429* or array element within the given object {@code o}2430* at the given {@code offset}.2431*2432* @param o object/array to update the field/element in2433* @param offset field/element offset2434* @param delta the value to add2435* @return the previous value2436* @since 1.82437*/2438@IntrinsicCandidate2439public final int getAndAddInt(Object o, long offset, int delta) {2440int v;2441do {2442v = getIntVolatile(o, offset);2443} while (!weakCompareAndSetInt(o, offset, v, v + delta));2444return v;2445}24462447@ForceInline2448public final int getAndAddIntRelease(Object o, long offset, int delta) {2449int v;2450do {2451v = getInt(o, offset);2452} while (!weakCompareAndSetIntRelease(o, offset, v, v + delta));2453return v;2454}24552456@ForceInline2457public final int getAndAddIntAcquire(Object o, long offset, int delta) {2458int v;2459do {2460v = getIntAcquire(o, offset);2461} while (!weakCompareAndSetIntAcquire(o, offset, v, v + delta));2462return v;2463}24642465/**2466* Atomically adds the given value to the current value of a field2467* or array element within the given object {@code o}2468* at the given {@code offset}.2469*2470* @param o object/array to update the field/element in2471* @param offset field/element offset2472* @param delta the value to add2473* @return the previous value2474* @since 1.82475*/2476@IntrinsicCandidate2477public final long getAndAddLong(Object o, long offset, long delta) {2478long v;2479do {2480v = getLongVolatile(o, offset);2481} while (!weakCompareAndSetLong(o, offset, v, v + delta));2482return v;2483}24842485@ForceInline2486public final long getAndAddLongRelease(Object o, long offset, long delta) {2487long v;2488do {2489v = getLong(o, offset);2490} while (!weakCompareAndSetLongRelease(o, offset, v, v + delta));2491return v;2492}24932494@ForceInline2495public final long getAndAddLongAcquire(Object o, long offset, long delta) {2496long v;2497do {2498v = getLongAcquire(o, offset);2499} while (!weakCompareAndSetLongAcquire(o, offset, v, v + delta));2500return v;2501}25022503@IntrinsicCandidate2504public final byte getAndAddByte(Object o, long offset, byte delta) {2505byte v;2506do {2507v = getByteVolatile(o, offset);2508} while (!weakCompareAndSetByte(o, offset, v, (byte) (v + delta)));2509return v;2510}25112512@ForceInline2513public final byte getAndAddByteRelease(Object o, long offset, byte delta) {2514byte v;2515do {2516v = getByte(o, offset);2517} while (!weakCompareAndSetByteRelease(o, offset, v, (byte) (v + delta)));2518return v;2519}25202521@ForceInline2522public final byte getAndAddByteAcquire(Object o, long offset, byte delta) {2523byte v;2524do {2525v = getByteAcquire(o, offset);2526} while (!weakCompareAndSetByteAcquire(o, offset, v, (byte) (v + delta)));2527return v;2528}25292530@IntrinsicCandidate2531public final short getAndAddShort(Object o, long offset, short delta) {2532short v;2533do {2534v = getShortVolatile(o, offset);2535} while (!weakCompareAndSetShort(o, offset, v, (short) (v + delta)));2536return v;2537}25382539@ForceInline2540public final short getAndAddShortRelease(Object o, long offset, short delta) {2541short v;2542do {2543v = getShort(o, offset);2544} while (!weakCompareAndSetShortRelease(o, offset, v, (short) (v + delta)));2545return v;2546}25472548@ForceInline2549public final short getAndAddShortAcquire(Object o, long offset, short delta) {2550short v;2551do {2552v = getShortAcquire(o, offset);2553} while (!weakCompareAndSetShortAcquire(o, offset, v, (short) (v + delta)));2554return v;2555}25562557@ForceInline2558public final char getAndAddChar(Object o, long offset, char delta) {2559return (char) getAndAddShort(o, offset, (short) delta);2560}25612562@ForceInline2563public final char getAndAddCharRelease(Object o, long offset, char delta) {2564return (char) getAndAddShortRelease(o, offset, (short) delta);2565}25662567@ForceInline2568public final char getAndAddCharAcquire(Object o, long offset, char delta) {2569return (char) getAndAddShortAcquire(o, offset, (short) delta);2570}25712572@ForceInline2573public final float getAndAddFloat(Object o, long offset, float delta) {2574int expectedBits;2575float v;2576do {2577// Load and CAS with the raw bits to avoid issues with NaNs and2578// possible bit conversion from signaling NaNs to quiet NaNs that2579// may result in the loop not terminating.2580expectedBits = getIntVolatile(o, offset);2581v = Float.intBitsToFloat(expectedBits);2582} while (!weakCompareAndSetInt(o, offset,2583expectedBits, Float.floatToRawIntBits(v + delta)));2584return v;2585}25862587@ForceInline2588public final float getAndAddFloatRelease(Object o, long offset, float delta) {2589int expectedBits;2590float v;2591do {2592// Load and CAS with the raw bits to avoid issues with NaNs and2593// possible bit conversion from signaling NaNs to quiet NaNs that2594// may result in the loop not terminating.2595expectedBits = getInt(o, offset);2596v = Float.intBitsToFloat(expectedBits);2597} while (!weakCompareAndSetIntRelease(o, offset,2598expectedBits, Float.floatToRawIntBits(v + delta)));2599return v;2600}26012602@ForceInline2603public final float getAndAddFloatAcquire(Object o, long offset, float delta) {2604int expectedBits;2605float v;2606do {2607// Load and CAS with the raw bits to avoid issues with NaNs and2608// possible bit conversion from signaling NaNs to quiet NaNs that2609// may result in the loop not terminating.2610expectedBits = getIntAcquire(o, offset);2611v = Float.intBitsToFloat(expectedBits);2612} while (!weakCompareAndSetIntAcquire(o, offset,2613expectedBits, Float.floatToRawIntBits(v + delta)));2614return v;2615}26162617@ForceInline2618public final double getAndAddDouble(Object o, long offset, double delta) {2619long expectedBits;2620double v;2621do {2622// Load and CAS with the raw bits to avoid issues with NaNs and2623// possible bit conversion from signaling NaNs to quiet NaNs that2624// may result in the loop not terminating.2625expectedBits = getLongVolatile(o, offset);2626v = Double.longBitsToDouble(expectedBits);2627} while (!weakCompareAndSetLong(o, offset,2628expectedBits, Double.doubleToRawLongBits(v + delta)));2629return v;2630}26312632@ForceInline2633public final double getAndAddDoubleRelease(Object o, long offset, double delta) {2634long expectedBits;2635double v;2636do {2637// Load and CAS with the raw bits to avoid issues with NaNs and2638// possible bit conversion from signaling NaNs to quiet NaNs that2639// may result in the loop not terminating.2640expectedBits = getLong(o, offset);2641v = Double.longBitsToDouble(expectedBits);2642} while (!weakCompareAndSetLongRelease(o, offset,2643expectedBits, Double.doubleToRawLongBits(v + delta)));2644return v;2645}26462647@ForceInline2648public final double getAndAddDoubleAcquire(Object o, long offset, double delta) {2649long expectedBits;2650double v;2651do {2652// Load and CAS with the raw bits to avoid issues with NaNs and2653// possible bit conversion from signaling NaNs to quiet NaNs that2654// may result in the loop not terminating.2655expectedBits = getLongAcquire(o, offset);2656v = Double.longBitsToDouble(expectedBits);2657} while (!weakCompareAndSetLongAcquire(o, offset,2658expectedBits, Double.doubleToRawLongBits(v + delta)));2659return v;2660}26612662/**2663* Atomically exchanges the given value with the current value of2664* a field or array element within the given object {@code o}2665* at the given {@code offset}.2666*2667* @param o object/array to update the field/element in2668* @param offset field/element offset2669* @param newValue new value2670* @return the previous value2671* @since 1.82672*/2673@IntrinsicCandidate2674public final int getAndSetInt(Object o, long offset, int newValue) {2675int v;2676do {2677v = getIntVolatile(o, offset);2678} while (!weakCompareAndSetInt(o, offset, v, newValue));2679return v;2680}26812682@ForceInline2683public final int getAndSetIntRelease(Object o, long offset, int newValue) {2684int v;2685do {2686v = getInt(o, offset);2687} while (!weakCompareAndSetIntRelease(o, offset, v, newValue));2688return v;2689}26902691@ForceInline2692public final int getAndSetIntAcquire(Object o, long offset, int newValue) {2693int v;2694do {2695v = getIntAcquire(o, offset);2696} while (!weakCompareAndSetIntAcquire(o, offset, v, newValue));2697return v;2698}26992700/**2701* Atomically exchanges the given value with the current value of2702* a field or array element within the given object {@code o}2703* at the given {@code offset}.2704*2705* @param o object/array to update the field/element in2706* @param offset field/element offset2707* @param newValue new value2708* @return the previous value2709* @since 1.82710*/2711@IntrinsicCandidate2712public final long getAndSetLong(Object o, long offset, long newValue) {2713long v;2714do {2715v = getLongVolatile(o, offset);2716} while (!weakCompareAndSetLong(o, offset, v, newValue));2717return v;2718}27192720@ForceInline2721public final long getAndSetLongRelease(Object o, long offset, long newValue) {2722long v;2723do {2724v = getLong(o, offset);2725} while (!weakCompareAndSetLongRelease(o, offset, v, newValue));2726return v;2727}27282729@ForceInline2730public final long getAndSetLongAcquire(Object o, long offset, long newValue) {2731long v;2732do {2733v = getLongAcquire(o, offset);2734} while (!weakCompareAndSetLongAcquire(o, offset, v, newValue));2735return v;2736}27372738/**2739* Atomically exchanges the given reference value with the current2740* reference value of a field or array element within the given2741* object {@code o} at the given {@code offset}.2742*2743* @param o object/array to update the field/element in2744* @param offset field/element offset2745* @param newValue new value2746* @return the previous value2747* @since 1.82748*/2749@IntrinsicCandidate2750public final Object getAndSetReference(Object o, long offset, Object newValue) {2751Object v;2752do {2753v = getReferenceVolatile(o, offset);2754} while (!weakCompareAndSetReference(o, offset, v, newValue));2755return v;2756}27572758@ForceInline2759public final Object getAndSetReferenceRelease(Object o, long offset, Object newValue) {2760Object v;2761do {2762v = getReference(o, offset);2763} while (!weakCompareAndSetReferenceRelease(o, offset, v, newValue));2764return v;2765}27662767@ForceInline2768public final Object getAndSetReferenceAcquire(Object o, long offset, Object newValue) {2769Object v;2770do {2771v = getReferenceAcquire(o, offset);2772} while (!weakCompareAndSetReferenceAcquire(o, offset, v, newValue));2773return v;2774}27752776@IntrinsicCandidate2777public final byte getAndSetByte(Object o, long offset, byte newValue) {2778byte v;2779do {2780v = getByteVolatile(o, offset);2781} while (!weakCompareAndSetByte(o, offset, v, newValue));2782return v;2783}27842785@ForceInline2786public final byte getAndSetByteRelease(Object o, long offset, byte newValue) {2787byte v;2788do {2789v = getByte(o, offset);2790} while (!weakCompareAndSetByteRelease(o, offset, v, newValue));2791return v;2792}27932794@ForceInline2795public final byte getAndSetByteAcquire(Object o, long offset, byte newValue) {2796byte v;2797do {2798v = getByteAcquire(o, offset);2799} while (!weakCompareAndSetByteAcquire(o, offset, v, newValue));2800return v;2801}28022803@ForceInline2804public final boolean getAndSetBoolean(Object o, long offset, boolean newValue) {2805return byte2bool(getAndSetByte(o, offset, bool2byte(newValue)));2806}28072808@ForceInline2809public final boolean getAndSetBooleanRelease(Object o, long offset, boolean newValue) {2810return byte2bool(getAndSetByteRelease(o, offset, bool2byte(newValue)));2811}28122813@ForceInline2814public final boolean getAndSetBooleanAcquire(Object o, long offset, boolean newValue) {2815return byte2bool(getAndSetByteAcquire(o, offset, bool2byte(newValue)));2816}28172818@IntrinsicCandidate2819public final short getAndSetShort(Object o, long offset, short newValue) {2820short v;2821do {2822v = getShortVolatile(o, offset);2823} while (!weakCompareAndSetShort(o, offset, v, newValue));2824return v;2825}28262827@ForceInline2828public final short getAndSetShortRelease(Object o, long offset, short newValue) {2829short v;2830do {2831v = getShort(o, offset);2832} while (!weakCompareAndSetShortRelease(o, offset, v, newValue));2833return v;2834}28352836@ForceInline2837public final short getAndSetShortAcquire(Object o, long offset, short newValue) {2838short v;2839do {2840v = getShortAcquire(o, offset);2841} while (!weakCompareAndSetShortAcquire(o, offset, v, newValue));2842return v;2843}28442845@ForceInline2846public final char getAndSetChar(Object o, long offset, char newValue) {2847return s2c(getAndSetShort(o, offset, c2s(newValue)));2848}28492850@ForceInline2851public final char getAndSetCharRelease(Object o, long offset, char newValue) {2852return s2c(getAndSetShortRelease(o, offset, c2s(newValue)));2853}28542855@ForceInline2856public final char getAndSetCharAcquire(Object o, long offset, char newValue) {2857return s2c(getAndSetShortAcquire(o, offset, c2s(newValue)));2858}28592860@ForceInline2861public final float getAndSetFloat(Object o, long offset, float newValue) {2862int v = getAndSetInt(o, offset, Float.floatToRawIntBits(newValue));2863return Float.intBitsToFloat(v);2864}28652866@ForceInline2867public final float getAndSetFloatRelease(Object o, long offset, float newValue) {2868int v = getAndSetIntRelease(o, offset, Float.floatToRawIntBits(newValue));2869return Float.intBitsToFloat(v);2870}28712872@ForceInline2873public final float getAndSetFloatAcquire(Object o, long offset, float newValue) {2874int v = getAndSetIntAcquire(o, offset, Float.floatToRawIntBits(newValue));2875return Float.intBitsToFloat(v);2876}28772878@ForceInline2879public final double getAndSetDouble(Object o, long offset, double newValue) {2880long v = getAndSetLong(o, offset, Double.doubleToRawLongBits(newValue));2881return Double.longBitsToDouble(v);2882}28832884@ForceInline2885public final double getAndSetDoubleRelease(Object o, long offset, double newValue) {2886long v = getAndSetLongRelease(o, offset, Double.doubleToRawLongBits(newValue));2887return Double.longBitsToDouble(v);2888}28892890@ForceInline2891public final double getAndSetDoubleAcquire(Object o, long offset, double newValue) {2892long v = getAndSetLongAcquire(o, offset, Double.doubleToRawLongBits(newValue));2893return Double.longBitsToDouble(v);2894}289528962897// The following contain CAS-based Java implementations used on2898// platforms not supporting native instructions28992900@ForceInline2901public final boolean getAndBitwiseOrBoolean(Object o, long offset, boolean mask) {2902return byte2bool(getAndBitwiseOrByte(o, offset, bool2byte(mask)));2903}29042905@ForceInline2906public final boolean getAndBitwiseOrBooleanRelease(Object o, long offset, boolean mask) {2907return byte2bool(getAndBitwiseOrByteRelease(o, offset, bool2byte(mask)));2908}29092910@ForceInline2911public final boolean getAndBitwiseOrBooleanAcquire(Object o, long offset, boolean mask) {2912return byte2bool(getAndBitwiseOrByteAcquire(o, offset, bool2byte(mask)));2913}29142915@ForceInline2916public final boolean getAndBitwiseAndBoolean(Object o, long offset, boolean mask) {2917return byte2bool(getAndBitwiseAndByte(o, offset, bool2byte(mask)));2918}29192920@ForceInline2921public final boolean getAndBitwiseAndBooleanRelease(Object o, long offset, boolean mask) {2922return byte2bool(getAndBitwiseAndByteRelease(o, offset, bool2byte(mask)));2923}29242925@ForceInline2926public final boolean getAndBitwiseAndBooleanAcquire(Object o, long offset, boolean mask) {2927return byte2bool(getAndBitwiseAndByteAcquire(o, offset, bool2byte(mask)));2928}29292930@ForceInline2931public final boolean getAndBitwiseXorBoolean(Object o, long offset, boolean mask) {2932return byte2bool(getAndBitwiseXorByte(o, offset, bool2byte(mask)));2933}29342935@ForceInline2936public final boolean getAndBitwiseXorBooleanRelease(Object o, long offset, boolean mask) {2937return byte2bool(getAndBitwiseXorByteRelease(o, offset, bool2byte(mask)));2938}29392940@ForceInline2941public final boolean getAndBitwiseXorBooleanAcquire(Object o, long offset, boolean mask) {2942return byte2bool(getAndBitwiseXorByteAcquire(o, offset, bool2byte(mask)));2943}294429452946@ForceInline2947public final byte getAndBitwiseOrByte(Object o, long offset, byte mask) {2948byte current;2949do {2950current = getByteVolatile(o, offset);2951} while (!weakCompareAndSetByte(o, offset,2952current, (byte) (current | mask)));2953return current;2954}29552956@ForceInline2957public final byte getAndBitwiseOrByteRelease(Object o, long offset, byte mask) {2958byte current;2959do {2960current = getByte(o, offset);2961} while (!weakCompareAndSetByteRelease(o, offset,2962current, (byte) (current | mask)));2963return current;2964}29652966@ForceInline2967public final byte getAndBitwiseOrByteAcquire(Object o, long offset, byte mask) {2968byte current;2969do {2970// Plain read, the value is a hint, the acquire CAS does the work2971current = getByte(o, offset);2972} while (!weakCompareAndSetByteAcquire(o, offset,2973current, (byte) (current | mask)));2974return current;2975}29762977@ForceInline2978public final byte getAndBitwiseAndByte(Object o, long offset, byte mask) {2979byte current;2980do {2981current = getByteVolatile(o, offset);2982} while (!weakCompareAndSetByte(o, offset,2983current, (byte) (current & mask)));2984return current;2985}29862987@ForceInline2988public final byte getAndBitwiseAndByteRelease(Object o, long offset, byte mask) {2989byte current;2990do {2991current = getByte(o, offset);2992} while (!weakCompareAndSetByteRelease(o, offset,2993current, (byte) (current & mask)));2994return current;2995}29962997@ForceInline2998public final byte getAndBitwiseAndByteAcquire(Object o, long offset, byte mask) {2999byte current;3000do {3001// Plain read, the value is a hint, the acquire CAS does the work3002current = getByte(o, offset);3003} while (!weakCompareAndSetByteAcquire(o, offset,3004current, (byte) (current & mask)));3005return current;3006}30073008@ForceInline3009public final byte getAndBitwiseXorByte(Object o, long offset, byte mask) {3010byte current;3011do {3012current = getByteVolatile(o, offset);3013} while (!weakCompareAndSetByte(o, offset,3014current, (byte) (current ^ mask)));3015return current;3016}30173018@ForceInline3019public final byte getAndBitwiseXorByteRelease(Object o, long offset, byte mask) {3020byte current;3021do {3022current = getByte(o, offset);3023} while (!weakCompareAndSetByteRelease(o, offset,3024current, (byte) (current ^ mask)));3025return current;3026}30273028@ForceInline3029public final byte getAndBitwiseXorByteAcquire(Object o, long offset, byte mask) {3030byte current;3031do {3032// Plain read, the value is a hint, the acquire CAS does the work3033current = getByte(o, offset);3034} while (!weakCompareAndSetByteAcquire(o, offset,3035current, (byte) (current ^ mask)));3036return current;3037}303830393040@ForceInline3041public final char getAndBitwiseOrChar(Object o, long offset, char mask) {3042return s2c(getAndBitwiseOrShort(o, offset, c2s(mask)));3043}30443045@ForceInline3046public final char getAndBitwiseOrCharRelease(Object o, long offset, char mask) {3047return s2c(getAndBitwiseOrShortRelease(o, offset, c2s(mask)));3048}30493050@ForceInline3051public final char getAndBitwiseOrCharAcquire(Object o, long offset, char mask) {3052return s2c(getAndBitwiseOrShortAcquire(o, offset, c2s(mask)));3053}30543055@ForceInline3056public final char getAndBitwiseAndChar(Object o, long offset, char mask) {3057return s2c(getAndBitwiseAndShort(o, offset, c2s(mask)));3058}30593060@ForceInline3061public final char getAndBitwiseAndCharRelease(Object o, long offset, char mask) {3062return s2c(getAndBitwiseAndShortRelease(o, offset, c2s(mask)));3063}30643065@ForceInline3066public final char getAndBitwiseAndCharAcquire(Object o, long offset, char mask) {3067return s2c(getAndBitwiseAndShortAcquire(o, offset, c2s(mask)));3068}30693070@ForceInline3071public final char getAndBitwiseXorChar(Object o, long offset, char mask) {3072return s2c(getAndBitwiseXorShort(o, offset, c2s(mask)));3073}30743075@ForceInline3076public final char getAndBitwiseXorCharRelease(Object o, long offset, char mask) {3077return s2c(getAndBitwiseXorShortRelease(o, offset, c2s(mask)));3078}30793080@ForceInline3081public final char getAndBitwiseXorCharAcquire(Object o, long offset, char mask) {3082return s2c(getAndBitwiseXorShortAcquire(o, offset, c2s(mask)));3083}308430853086@ForceInline3087public final short getAndBitwiseOrShort(Object o, long offset, short mask) {3088short current;3089do {3090current = getShortVolatile(o, offset);3091} while (!weakCompareAndSetShort(o, offset,3092current, (short) (current | mask)));3093return current;3094}30953096@ForceInline3097public final short getAndBitwiseOrShortRelease(Object o, long offset, short mask) {3098short current;3099do {3100current = getShort(o, offset);3101} while (!weakCompareAndSetShortRelease(o, offset,3102current, (short) (current | mask)));3103return current;3104}31053106@ForceInline3107public final short getAndBitwiseOrShortAcquire(Object o, long offset, short mask) {3108short current;3109do {3110// Plain read, the value is a hint, the acquire CAS does the work3111current = getShort(o, offset);3112} while (!weakCompareAndSetShortAcquire(o, offset,3113current, (short) (current | mask)));3114return current;3115}31163117@ForceInline3118public final short getAndBitwiseAndShort(Object o, long offset, short mask) {3119short current;3120do {3121current = getShortVolatile(o, offset);3122} while (!weakCompareAndSetShort(o, offset,3123current, (short) (current & mask)));3124return current;3125}31263127@ForceInline3128public final short getAndBitwiseAndShortRelease(Object o, long offset, short mask) {3129short current;3130do {3131current = getShort(o, offset);3132} while (!weakCompareAndSetShortRelease(o, offset,3133current, (short) (current & mask)));3134return current;3135}31363137@ForceInline3138public final short getAndBitwiseAndShortAcquire(Object o, long offset, short mask) {3139short current;3140do {3141// Plain read, the value is a hint, the acquire CAS does the work3142current = getShort(o, offset);3143} while (!weakCompareAndSetShortAcquire(o, offset,3144current, (short) (current & mask)));3145return current;3146}31473148@ForceInline3149public final short getAndBitwiseXorShort(Object o, long offset, short mask) {3150short current;3151do {3152current = getShortVolatile(o, offset);3153} while (!weakCompareAndSetShort(o, offset,3154current, (short) (current ^ mask)));3155return current;3156}31573158@ForceInline3159public final short getAndBitwiseXorShortRelease(Object o, long offset, short mask) {3160short current;3161do {3162current = getShort(o, offset);3163} while (!weakCompareAndSetShortRelease(o, offset,3164current, (short) (current ^ mask)));3165return current;3166}31673168@ForceInline3169public final short getAndBitwiseXorShortAcquire(Object o, long offset, short mask) {3170short current;3171do {3172// Plain read, the value is a hint, the acquire CAS does the work3173current = getShort(o, offset);3174} while (!weakCompareAndSetShortAcquire(o, offset,3175current, (short) (current ^ mask)));3176return current;3177}317831793180@ForceInline3181public final int getAndBitwiseOrInt(Object o, long offset, int mask) {3182int current;3183do {3184current = getIntVolatile(o, offset);3185} while (!weakCompareAndSetInt(o, offset,3186current, current | mask));3187return current;3188}31893190@ForceInline3191public final int getAndBitwiseOrIntRelease(Object o, long offset, int mask) {3192int current;3193do {3194current = getInt(o, offset);3195} while (!weakCompareAndSetIntRelease(o, offset,3196current, current | mask));3197return current;3198}31993200@ForceInline3201public final int getAndBitwiseOrIntAcquire(Object o, long offset, int mask) {3202int current;3203do {3204// Plain read, the value is a hint, the acquire CAS does the work3205current = getInt(o, offset);3206} while (!weakCompareAndSetIntAcquire(o, offset,3207current, current | mask));3208return current;3209}32103211/**3212* Atomically replaces the current value of a field or array element within3213* the given object with the result of bitwise AND between the current value3214* and mask.3215*3216* @param o object/array to update the field/element in3217* @param offset field/element offset3218* @param mask the mask value3219* @return the previous value3220* @since 93221*/3222@ForceInline3223public final int getAndBitwiseAndInt(Object o, long offset, int mask) {3224int current;3225do {3226current = getIntVolatile(o, offset);3227} while (!weakCompareAndSetInt(o, offset,3228current, current & mask));3229return current;3230}32313232@ForceInline3233public final int getAndBitwiseAndIntRelease(Object o, long offset, int mask) {3234int current;3235do {3236current = getInt(o, offset);3237} while (!weakCompareAndSetIntRelease(o, offset,3238current, current & mask));3239return current;3240}32413242@ForceInline3243public final int getAndBitwiseAndIntAcquire(Object o, long offset, int mask) {3244int current;3245do {3246// Plain read, the value is a hint, the acquire CAS does the work3247current = getInt(o, offset);3248} while (!weakCompareAndSetIntAcquire(o, offset,3249current, current & mask));3250return current;3251}32523253@ForceInline3254public final int getAndBitwiseXorInt(Object o, long offset, int mask) {3255int current;3256do {3257current = getIntVolatile(o, offset);3258} while (!weakCompareAndSetInt(o, offset,3259current, current ^ mask));3260return current;3261}32623263@ForceInline3264public final int getAndBitwiseXorIntRelease(Object o, long offset, int mask) {3265int current;3266do {3267current = getInt(o, offset);3268} while (!weakCompareAndSetIntRelease(o, offset,3269current, current ^ mask));3270return current;3271}32723273@ForceInline3274public final int getAndBitwiseXorIntAcquire(Object o, long offset, int mask) {3275int current;3276do {3277// Plain read, the value is a hint, the acquire CAS does the work3278current = getInt(o, offset);3279} while (!weakCompareAndSetIntAcquire(o, offset,3280current, current ^ mask));3281return current;3282}328332843285@ForceInline3286public final long getAndBitwiseOrLong(Object o, long offset, long mask) {3287long current;3288do {3289current = getLongVolatile(o, offset);3290} while (!weakCompareAndSetLong(o, offset,3291current, current | mask));3292return current;3293}32943295@ForceInline3296public final long getAndBitwiseOrLongRelease(Object o, long offset, long mask) {3297long current;3298do {3299current = getLong(o, offset);3300} while (!weakCompareAndSetLongRelease(o, offset,3301current, current | mask));3302return current;3303}33043305@ForceInline3306public final long getAndBitwiseOrLongAcquire(Object o, long offset, long mask) {3307long current;3308do {3309// Plain read, the value is a hint, the acquire CAS does the work3310current = getLong(o, offset);3311} while (!weakCompareAndSetLongAcquire(o, offset,3312current, current | mask));3313return current;3314}33153316@ForceInline3317public final long getAndBitwiseAndLong(Object o, long offset, long mask) {3318long current;3319do {3320current = getLongVolatile(o, offset);3321} while (!weakCompareAndSetLong(o, offset,3322current, current & mask));3323return current;3324}33253326@ForceInline3327public final long getAndBitwiseAndLongRelease(Object o, long offset, long mask) {3328long current;3329do {3330current = getLong(o, offset);3331} while (!weakCompareAndSetLongRelease(o, offset,3332current, current & mask));3333return current;3334}33353336@ForceInline3337public final long getAndBitwiseAndLongAcquire(Object o, long offset, long mask) {3338long current;3339do {3340// Plain read, the value is a hint, the acquire CAS does the work3341current = getLong(o, offset);3342} while (!weakCompareAndSetLongAcquire(o, offset,3343current, current & mask));3344return current;3345}33463347@ForceInline3348public final long getAndBitwiseXorLong(Object o, long offset, long mask) {3349long current;3350do {3351current = getLongVolatile(o, offset);3352} while (!weakCompareAndSetLong(o, offset,3353current, current ^ mask));3354return current;3355}33563357@ForceInline3358public final long getAndBitwiseXorLongRelease(Object o, long offset, long mask) {3359long current;3360do {3361current = getLong(o, offset);3362} while (!weakCompareAndSetLongRelease(o, offset,3363current, current ^ mask));3364return current;3365}33663367@ForceInline3368public final long getAndBitwiseXorLongAcquire(Object o, long offset, long mask) {3369long current;3370do {3371// Plain read, the value is a hint, the acquire CAS does the work3372current = getLong(o, offset);3373} while (!weakCompareAndSetLongAcquire(o, offset,3374current, current ^ mask));3375return current;3376}3377337833793380/**3381* Ensures that loads before the fence will not be reordered with loads and3382* stores after the fence; a "LoadLoad plus LoadStore barrier".3383*3384* Corresponds to C11 atomic_thread_fence(memory_order_acquire)3385* (an "acquire fence").3386*3387* Provides a LoadLoad barrier followed by a LoadStore barrier.3388*3389* @since 1.83390*/3391@IntrinsicCandidate3392public native void loadFence();33933394/**3395* Ensures that loads and stores before the fence will not be reordered with3396* stores after the fence; a "StoreStore plus LoadStore barrier".3397*3398* Corresponds to C11 atomic_thread_fence(memory_order_release)3399* (a "release fence").3400*3401* Provides a StoreStore barrier followed by a LoadStore barrier.3402*3403*3404* @since 1.83405*/3406@IntrinsicCandidate3407public native void storeFence();34083409/**3410* Ensures that loads and stores before the fence will not be reordered3411* with loads and stores after the fence. Implies the effects of both3412* loadFence() and storeFence(), and in addition, the effect of a StoreLoad3413* barrier.3414*3415* Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).3416* @since 1.83417*/3418@IntrinsicCandidate3419public native void fullFence();34203421/**3422* Ensures that loads before the fence will not be reordered with3423* loads after the fence.3424*3425* @implNote3426* This method is operationally equivalent to {@link #loadFence()}.3427*3428* @since 93429*/3430public final void loadLoadFence() {3431loadFence();3432}34333434/**3435* Ensures that stores before the fence will not be reordered with3436* stores after the fence.3437*3438* @implNote3439* This method is operationally equivalent to {@link #storeFence()}.3440*3441* @since 93442*/3443public final void storeStoreFence() {3444storeFence();3445}344634473448/**3449* Throws IllegalAccessError; for use by the VM for access control3450* error support.3451* @since 1.83452*/3453private static void throwIllegalAccessError() {3454throw new IllegalAccessError();3455}34563457/**3458* Throws NoSuchMethodError; for use by the VM for redefinition support.3459* @since 133460*/3461private static void throwNoSuchMethodError() {3462throw new NoSuchMethodError();3463}34643465/**3466* @return Returns true if the native byte ordering of this3467* platform is big-endian, false if it is little-endian.3468*/3469public final boolean isBigEndian() { return BIG_ENDIAN; }34703471/**3472* @return Returns true if this platform is capable of performing3473* accesses at addresses which are not aligned for the type of the3474* primitive type being accessed, false otherwise.3475*/3476public final boolean unalignedAccess() { return UNALIGNED_ACCESS; }34773478/**3479* Fetches a value at some byte offset into a given Java object.3480* More specifically, fetches a value within the given object3481* <code>o</code> at the given offset, or (if <code>o</code> is3482* null) from the memory address whose numerical value is the3483* given offset. <p>3484*3485* The specification of this method is the same as {@link3486* #getLong(Object, long)} except that the offset does not need to3487* have been obtained from {@link #objectFieldOffset} on the3488* {@link java.lang.reflect.Field} of some Java field. The value3489* in memory is raw data, and need not correspond to any Java3490* variable. Unless <code>o</code> is null, the value accessed3491* must be entirely within the allocated object. The endianness3492* of the value in memory is the endianness of the native platform.3493*3494* <p> The read will be atomic with respect to the largest power3495* of two that divides the GCD of the offset and the storage size.3496* For example, getLongUnaligned will make atomic reads of 2-, 4-,3497* or 8-byte storage units if the offset is zero mod 2, 4, or 8,3498* respectively. There are no other guarantees of atomicity.3499* <p>3500* 8-byte atomicity is only guaranteed on platforms on which3501* support atomic accesses to longs.3502*3503* @param o Java heap object in which the value resides, if any, else3504* null3505* @param offset The offset in bytes from the start of the object3506* @return the value fetched from the indicated object3507* @throws RuntimeException No defined exceptions are thrown, not even3508* {@link NullPointerException}3509* @since 93510*/3511@IntrinsicCandidate3512public final long getLongUnaligned(Object o, long offset) {3513if ((offset & 7) == 0) {3514return getLong(o, offset);3515} else if ((offset & 3) == 0) {3516return makeLong(getInt(o, offset),3517getInt(o, offset + 4));3518} else if ((offset & 1) == 0) {3519return makeLong(getShort(o, offset),3520getShort(o, offset + 2),3521getShort(o, offset + 4),3522getShort(o, offset + 6));3523} else {3524return makeLong(getByte(o, offset),3525getByte(o, offset + 1),3526getByte(o, offset + 2),3527getByte(o, offset + 3),3528getByte(o, offset + 4),3529getByte(o, offset + 5),3530getByte(o, offset + 6),3531getByte(o, offset + 7));3532}3533}3534/**3535* As {@link #getLongUnaligned(Object, long)} but with an3536* additional argument which specifies the endianness of the value3537* as stored in memory.3538*3539* @param o Java heap object in which the variable resides3540* @param offset The offset in bytes from the start of the object3541* @param bigEndian The endianness of the value3542* @return the value fetched from the indicated object3543* @since 93544*/3545public final long getLongUnaligned(Object o, long offset, boolean bigEndian) {3546return convEndian(bigEndian, getLongUnaligned(o, offset));3547}35483549/** @see #getLongUnaligned(Object, long) */3550@IntrinsicCandidate3551public final int getIntUnaligned(Object o, long offset) {3552if ((offset & 3) == 0) {3553return getInt(o, offset);3554} else if ((offset & 1) == 0) {3555return makeInt(getShort(o, offset),3556getShort(o, offset + 2));3557} else {3558return makeInt(getByte(o, offset),3559getByte(o, offset + 1),3560getByte(o, offset + 2),3561getByte(o, offset + 3));3562}3563}3564/** @see #getLongUnaligned(Object, long, boolean) */3565public final int getIntUnaligned(Object o, long offset, boolean bigEndian) {3566return convEndian(bigEndian, getIntUnaligned(o, offset));3567}35683569/** @see #getLongUnaligned(Object, long) */3570@IntrinsicCandidate3571public final short getShortUnaligned(Object o, long offset) {3572if ((offset & 1) == 0) {3573return getShort(o, offset);3574} else {3575return makeShort(getByte(o, offset),3576getByte(o, offset + 1));3577}3578}3579/** @see #getLongUnaligned(Object, long, boolean) */3580public final short getShortUnaligned(Object o, long offset, boolean bigEndian) {3581return convEndian(bigEndian, getShortUnaligned(o, offset));3582}35833584/** @see #getLongUnaligned(Object, long) */3585@IntrinsicCandidate3586public final char getCharUnaligned(Object o, long offset) {3587if ((offset & 1) == 0) {3588return getChar(o, offset);3589} else {3590return (char)makeShort(getByte(o, offset),3591getByte(o, offset + 1));3592}3593}35943595/** @see #getLongUnaligned(Object, long, boolean) */3596public final char getCharUnaligned(Object o, long offset, boolean bigEndian) {3597return convEndian(bigEndian, getCharUnaligned(o, offset));3598}35993600/**3601* Stores a value at some byte offset into a given Java object.3602* <p>3603* The specification of this method is the same as {@link3604* #getLong(Object, long)} except that the offset does not need to3605* have been obtained from {@link #objectFieldOffset} on the3606* {@link java.lang.reflect.Field} of some Java field. The value3607* in memory is raw data, and need not correspond to any Java3608* variable. The endianness of the value in memory is the3609* endianness of the native platform.3610* <p>3611* The write will be atomic with respect to the largest power of3612* two that divides the GCD of the offset and the storage size.3613* For example, putLongUnaligned will make atomic writes of 2-, 4-,3614* or 8-byte storage units if the offset is zero mod 2, 4, or 8,3615* respectively. There are no other guarantees of atomicity.3616* <p>3617* 8-byte atomicity is only guaranteed on platforms on which3618* support atomic accesses to longs.3619*3620* @param o Java heap object in which the value resides, if any, else3621* null3622* @param offset The offset in bytes from the start of the object3623* @param x the value to store3624* @throws RuntimeException No defined exceptions are thrown, not even3625* {@link NullPointerException}3626* @since 93627*/3628@IntrinsicCandidate3629public final void putLongUnaligned(Object o, long offset, long x) {3630if ((offset & 7) == 0) {3631putLong(o, offset, x);3632} else if ((offset & 3) == 0) {3633putLongParts(o, offset,3634(int)(x >> 0),3635(int)(x >>> 32));3636} else if ((offset & 1) == 0) {3637putLongParts(o, offset,3638(short)(x >>> 0),3639(short)(x >>> 16),3640(short)(x >>> 32),3641(short)(x >>> 48));3642} else {3643putLongParts(o, offset,3644(byte)(x >>> 0),3645(byte)(x >>> 8),3646(byte)(x >>> 16),3647(byte)(x >>> 24),3648(byte)(x >>> 32),3649(byte)(x >>> 40),3650(byte)(x >>> 48),3651(byte)(x >>> 56));3652}3653}36543655/**3656* As {@link #putLongUnaligned(Object, long, long)} but with an additional3657* argument which specifies the endianness of the value as stored in memory.3658* @param o Java heap object in which the value resides3659* @param offset The offset in bytes from the start of the object3660* @param x the value to store3661* @param bigEndian The endianness of the value3662* @throws RuntimeException No defined exceptions are thrown, not even3663* {@link NullPointerException}3664* @since 93665*/3666public final void putLongUnaligned(Object o, long offset, long x, boolean bigEndian) {3667putLongUnaligned(o, offset, convEndian(bigEndian, x));3668}36693670/** @see #putLongUnaligned(Object, long, long) */3671@IntrinsicCandidate3672public final void putIntUnaligned(Object o, long offset, int x) {3673if ((offset & 3) == 0) {3674putInt(o, offset, x);3675} else if ((offset & 1) == 0) {3676putIntParts(o, offset,3677(short)(x >> 0),3678(short)(x >>> 16));3679} else {3680putIntParts(o, offset,3681(byte)(x >>> 0),3682(byte)(x >>> 8),3683(byte)(x >>> 16),3684(byte)(x >>> 24));3685}3686}3687/** @see #putLongUnaligned(Object, long, long, boolean) */3688public final void putIntUnaligned(Object o, long offset, int x, boolean bigEndian) {3689putIntUnaligned(o, offset, convEndian(bigEndian, x));3690}36913692/** @see #putLongUnaligned(Object, long, long) */3693@IntrinsicCandidate3694public final void putShortUnaligned(Object o, long offset, short x) {3695if ((offset & 1) == 0) {3696putShort(o, offset, x);3697} else {3698putShortParts(o, offset,3699(byte)(x >>> 0),3700(byte)(x >>> 8));3701}3702}3703/** @see #putLongUnaligned(Object, long, long, boolean) */3704public final void putShortUnaligned(Object o, long offset, short x, boolean bigEndian) {3705putShortUnaligned(o, offset, convEndian(bigEndian, x));3706}37073708/** @see #putLongUnaligned(Object, long, long) */3709@IntrinsicCandidate3710public final void putCharUnaligned(Object o, long offset, char x) {3711putShortUnaligned(o, offset, (short)x);3712}3713/** @see #putLongUnaligned(Object, long, long, boolean) */3714public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {3715putCharUnaligned(o, offset, convEndian(bigEndian, x));3716}37173718private static int pickPos(int top, int pos) { return BIG_ENDIAN ? top - pos : pos; }37193720// These methods construct integers from bytes. The byte ordering3721// is the native endianness of this platform.3722private static long makeLong(byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {3723return ((toUnsignedLong(i0) << pickPos(56, 0))3724| (toUnsignedLong(i1) << pickPos(56, 8))3725| (toUnsignedLong(i2) << pickPos(56, 16))3726| (toUnsignedLong(i3) << pickPos(56, 24))3727| (toUnsignedLong(i4) << pickPos(56, 32))3728| (toUnsignedLong(i5) << pickPos(56, 40))3729| (toUnsignedLong(i6) << pickPos(56, 48))3730| (toUnsignedLong(i7) << pickPos(56, 56)));3731}3732private static long makeLong(short i0, short i1, short i2, short i3) {3733return ((toUnsignedLong(i0) << pickPos(48, 0))3734| (toUnsignedLong(i1) << pickPos(48, 16))3735| (toUnsignedLong(i2) << pickPos(48, 32))3736| (toUnsignedLong(i3) << pickPos(48, 48)));3737}3738private static long makeLong(int i0, int i1) {3739return (toUnsignedLong(i0) << pickPos(32, 0))3740| (toUnsignedLong(i1) << pickPos(32, 32));3741}3742private static int makeInt(short i0, short i1) {3743return (toUnsignedInt(i0) << pickPos(16, 0))3744| (toUnsignedInt(i1) << pickPos(16, 16));3745}3746private static int makeInt(byte i0, byte i1, byte i2, byte i3) {3747return ((toUnsignedInt(i0) << pickPos(24, 0))3748| (toUnsignedInt(i1) << pickPos(24, 8))3749| (toUnsignedInt(i2) << pickPos(24, 16))3750| (toUnsignedInt(i3) << pickPos(24, 24)));3751}3752private static short makeShort(byte i0, byte i1) {3753return (short)((toUnsignedInt(i0) << pickPos(8, 0))3754| (toUnsignedInt(i1) << pickPos(8, 8)));3755}37563757private static byte pick(byte le, byte be) { return BIG_ENDIAN ? be : le; }3758private static short pick(short le, short be) { return BIG_ENDIAN ? be : le; }3759private static int pick(int le, int be) { return BIG_ENDIAN ? be : le; }37603761// These methods write integers to memory from smaller parts3762// provided by their caller. The ordering in which these parts3763// are written is the native endianness of this platform.3764private void putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7) {3765putByte(o, offset + 0, pick(i0, i7));3766putByte(o, offset + 1, pick(i1, i6));3767putByte(o, offset + 2, pick(i2, i5));3768putByte(o, offset + 3, pick(i3, i4));3769putByte(o, offset + 4, pick(i4, i3));3770putByte(o, offset + 5, pick(i5, i2));3771putByte(o, offset + 6, pick(i6, i1));3772putByte(o, offset + 7, pick(i7, i0));3773}3774private void putLongParts(Object o, long offset, short i0, short i1, short i2, short i3) {3775putShort(o, offset + 0, pick(i0, i3));3776putShort(o, offset + 2, pick(i1, i2));3777putShort(o, offset + 4, pick(i2, i1));3778putShort(o, offset + 6, pick(i3, i0));3779}3780private void putLongParts(Object o, long offset, int i0, int i1) {3781putInt(o, offset + 0, pick(i0, i1));3782putInt(o, offset + 4, pick(i1, i0));3783}3784private void putIntParts(Object o, long offset, short i0, short i1) {3785putShort(o, offset + 0, pick(i0, i1));3786putShort(o, offset + 2, pick(i1, i0));3787}3788private void putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3) {3789putByte(o, offset + 0, pick(i0, i3));3790putByte(o, offset + 1, pick(i1, i2));3791putByte(o, offset + 2, pick(i2, i1));3792putByte(o, offset + 3, pick(i3, i0));3793}3794private void putShortParts(Object o, long offset, byte i0, byte i1) {3795putByte(o, offset + 0, pick(i0, i1));3796putByte(o, offset + 1, pick(i1, i0));3797}37983799// Zero-extend an integer3800private static int toUnsignedInt(byte n) { return n & 0xff; }3801private static int toUnsignedInt(short n) { return n & 0xffff; }3802private static long toUnsignedLong(byte n) { return n & 0xffl; }3803private static long toUnsignedLong(short n) { return n & 0xffffl; }3804private static long toUnsignedLong(int n) { return n & 0xffffffffl; }38053806// Maybe byte-reverse an integer3807private static char convEndian(boolean big, char n) { return big == BIG_ENDIAN ? n : Character.reverseBytes(n); }3808private static short convEndian(boolean big, short n) { return big == BIG_ENDIAN ? n : Short.reverseBytes(n) ; }3809private static int convEndian(boolean big, int n) { return big == BIG_ENDIAN ? n : Integer.reverseBytes(n) ; }3810private static long convEndian(boolean big, long n) { return big == BIG_ENDIAN ? n : Long.reverseBytes(n) ; }3811381238133814private native long allocateMemory0(long bytes);3815private native long reallocateMemory0(long address, long bytes);3816private native void freeMemory0(long address);3817private native void setMemory0(Object o, long offset, long bytes, byte value);3818@IntrinsicCandidate3819private native void copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);3820private native void copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize);3821private native long objectFieldOffset0(Field f);3822private native long objectFieldOffset1(Class<?> c, String name);3823private native long staticFieldOffset0(Field f);3824private native Object staticFieldBase0(Field f);3825private native boolean shouldBeInitialized0(Class<?> c);3826private native void ensureClassInitialized0(Class<?> c);3827private native int arrayBaseOffset0(Class<?> arrayClass);3828private native int arrayIndexScale0(Class<?> arrayClass);3829private native int getLoadAverage0(double[] loadavg, int nelems);383038313832/**3833* Invokes the given direct byte buffer's cleaner, if any.3834*3835* @param directBuffer a direct byte buffer3836* @throws NullPointerException if {@code directBuffer} is null3837* @throws IllegalArgumentException if {@code directBuffer} is non-direct,3838* or is a {@link java.nio.Buffer#slice slice}, or is a3839* {@link java.nio.Buffer#duplicate duplicate}3840*/3841public void invokeCleaner(java.nio.ByteBuffer directBuffer) {3842if (!directBuffer.isDirect())3843throw new IllegalArgumentException("buffer is non-direct");38443845DirectBuffer db = (DirectBuffer) directBuffer;3846if (db.attachment() != null)3847throw new IllegalArgumentException("duplicate or slice");38483849Cleaner cleaner = db.cleaner();3850if (cleaner != null) {3851cleaner.clean();3852}3853}38543855// The following deprecated methods are used by JSR 166.38563857@Deprecated(since="12", forRemoval=true)3858public final Object getObject(Object o, long offset) {3859return getReference(o, offset);3860}3861@Deprecated(since="12", forRemoval=true)3862public final Object getObjectVolatile(Object o, long offset) {3863return getReferenceVolatile(o, offset);3864}3865@Deprecated(since="12", forRemoval=true)3866public final Object getObjectAcquire(Object o, long offset) {3867return getReferenceAcquire(o, offset);3868}3869@Deprecated(since="12", forRemoval=true)3870public final Object getObjectOpaque(Object o, long offset) {3871return getReferenceOpaque(o, offset);3872}387338743875@Deprecated(since="12", forRemoval=true)3876public final void putObject(Object o, long offset, Object x) {3877putReference(o, offset, x);3878}3879@Deprecated(since="12", forRemoval=true)3880public final void putObjectVolatile(Object o, long offset, Object x) {3881putReferenceVolatile(o, offset, x);3882}3883@Deprecated(since="12", forRemoval=true)3884public final void putObjectOpaque(Object o, long offset, Object x) {3885putReferenceOpaque(o, offset, x);3886}3887@Deprecated(since="12", forRemoval=true)3888public final void putObjectRelease(Object o, long offset, Object x) {3889putReferenceRelease(o, offset, x);3890}389138923893@Deprecated(since="12", forRemoval=true)3894public final Object getAndSetObject(Object o, long offset, Object newValue) {3895return getAndSetReference(o, offset, newValue);3896}3897@Deprecated(since="12", forRemoval=true)3898public final Object getAndSetObjectAcquire(Object o, long offset, Object newValue) {3899return getAndSetReferenceAcquire(o, offset, newValue);3900}3901@Deprecated(since="12", forRemoval=true)3902public final Object getAndSetObjectRelease(Object o, long offset, Object newValue) {3903return getAndSetReferenceRelease(o, offset, newValue);3904}390539063907@Deprecated(since="12", forRemoval=true)3908public final boolean compareAndSetObject(Object o, long offset, Object expected, Object x) {3909return compareAndSetReference(o, offset, expected, x);3910}3911@Deprecated(since="12", forRemoval=true)3912public final Object compareAndExchangeObject(Object o, long offset, Object expected, Object x) {3913return compareAndExchangeReference(o, offset, expected, x);3914}3915@Deprecated(since="12", forRemoval=true)3916public final Object compareAndExchangeObjectAcquire(Object o, long offset, Object expected, Object x) {3917return compareAndExchangeReferenceAcquire(o, offset, expected, x);3918}3919@Deprecated(since="12", forRemoval=true)3920public final Object compareAndExchangeObjectRelease(Object o, long offset, Object expected, Object x) {3921return compareAndExchangeReferenceRelease(o, offset, expected, x);3922}392339243925@Deprecated(since="12", forRemoval=true)3926public final boolean weakCompareAndSetObject(Object o, long offset, Object expected, Object x) {3927return weakCompareAndSetReference(o, offset, expected, x);3928}3929@Deprecated(since="12", forRemoval=true)3930public final boolean weakCompareAndSetObjectAcquire(Object o, long offset, Object expected, Object x) {3931return weakCompareAndSetReferenceAcquire(o, offset, expected, x);3932}3933@Deprecated(since="12", forRemoval=true)3934public final boolean weakCompareAndSetObjectPlain(Object o, long offset, Object expected, Object x) {3935return weakCompareAndSetReferencePlain(o, offset, expected, x);3936}3937@Deprecated(since="12", forRemoval=true)3938public final boolean weakCompareAndSetObjectRelease(Object o, long offset, Object expected, Object x) {3939return weakCompareAndSetReferenceRelease(o, offset, expected, x);3940}3941}394239433944