Top Description Fields Constructors Methods
jdk.internal.misc

public final Class Unsafe

extends Object
Class Inheritance
Imports
jdk.internal.ref.Cleaner, jdk.internal.vm.annotation.ForceInline, .IntrinsicCandidate, sun.nio.ch.DirectBuffer, java.lang.reflect.Field, java.security.ProtectionDomain

A collection of methods for performing low-level, unsafe operations. Although the class and all methods are public, use of this class is limited because only trusted code can obtain instances of it

Note

It is the responsibility of the caller to make sure arguments are checked before methods of this class are called. While some rudimentary checks are performed on the input, the checks are best effort and when performance is an overriding priority, as when methods of this class are optimized by the runtime compiler, some or all checks (if any) may be elided. Hence, the caller must not rely on the checks and corresponding exceptions!

Author
John R. Rose
See Also
getUnsafe

Field Summary

Modifier and TypeField and Description
public static final int
ADDRESS_SIZE

The value of addressSize()

public static final int
ARRAY_BOOLEAN_BASE_OFFSET

The value of arrayBaseOffset(boolean[].class)

public static final int
ARRAY_BOOLEAN_INDEX_SCALE

The value of arrayIndexScale(boolean[].class)

public static final int
ARRAY_BYTE_BASE_OFFSET

The value of arrayBaseOffset(byte[].class)

public static final int
ARRAY_BYTE_INDEX_SCALE

The value of arrayIndexScale(byte[].class)

public static final int
ARRAY_CHAR_BASE_OFFSET

The value of arrayBaseOffset(char[].class)

public static final int
ARRAY_CHAR_INDEX_SCALE

The value of arrayIndexScale(char[].class)

public static final int
ARRAY_DOUBLE_BASE_OFFSET

The value of arrayBaseOffset(double[].class)

public static final int
ARRAY_DOUBLE_INDEX_SCALE

The value of arrayIndexScale(double[].class)

public static final int
ARRAY_FLOAT_BASE_OFFSET

The value of arrayBaseOffset(float[].class)

public static final int
ARRAY_FLOAT_INDEX_SCALE

The value of arrayIndexScale(float[].class)

public static final int
ARRAY_INT_BASE_OFFSET

The value of arrayBaseOffset(int[].class)

public static final int
ARRAY_INT_INDEX_SCALE

The value of arrayIndexScale(int[].class)

public static final int
ARRAY_LONG_BASE_OFFSET

The value of arrayBaseOffset(long[].class)

public static final int
ARRAY_LONG_INDEX_SCALE

The value of arrayIndexScale(long[].class)

public static final int
ARRAY_OBJECT_BASE_OFFSET

The value of arrayBaseOffset(Object[].class)

public static final int
ARRAY_OBJECT_INDEX_SCALE

The value of arrayIndexScale(Object[].class)

public static final int
ARRAY_SHORT_BASE_OFFSET

The value of arrayBaseOffset(short[].class)

public static final int
ARRAY_SHORT_INDEX_SCALE

The value of arrayIndexScale(short[].class)

public static final int
INVALID_FIELD_OFFSET

This constant differs from all results that will ever be returned from staticFieldOffset, objectFieldOffset, or arrayBaseOffset.

private static final Unsafe

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
addressSize()

Reports the size in bytes of a native pointer, as stored via putAddress.

private long
alignToHeapWordSize(long bytes)

Round up allocation size to a multiple of HeapWordSize.

public native Object
allocateInstance(Class<?> cls)

Allocates an instance but does not run any constructor.

public long
allocateMemory(long bytes)

Allocates a new block of native memory, of the given size in bytes.

private native long
allocateMemory0(long bytes)

private void
allocateMemoryChecks(long bytes)

Validate the arguments to allocateMemory

public Object
allocateUninitializedArray(Class<?>
array component type to allocate
componentType
,
int
array size to allocate
length
)

Allocates an array of a given type, but does not do zeroing.

private Object
allocateUninitializedArray0(Class<?> componentType, int length)

public int
arrayBaseOffset(Class<?> arrayClass)

Reports the offset of the first element in the storage allocation of a given array class.

private native int
arrayBaseOffset0(Class<?> arrayClass)

public int
arrayIndexScale(Class<?> arrayClass)

Reports the scale factor for addressing elements in the storage allocation of a given array class.

private native int
arrayIndexScale0(Class<?> arrayClass)

private byte

Returns:

the result of the conversion
bool2byte
(boolean
the boolean to be converted to byte (and then normalized)
b
)

Convert a boolean value to a byte.

private boolean

Returns:

the result of the conversion
byte2bool
(byte
the byte to be converted to boolean
b
)

The JVM converts integral values to boolean values using two different conventions, byte testing against zero and truncation to least-significant bit.

private short
c2s(char s)

private void
checkNativeAddress(long address)

Check the validity of a native address (the equivalent of void*)

private void
checkOffset(Object
the base object
o
,
long
the offset to check
offset
)

Check the validity of an offset, relative to a base object

private void
checkPointer(Object
Java heap object, or null
o
,
long
indication of where the variable resides in a Java heap object, if any, else a memory address locating the variable statically
offset
)

Check the validity of a double-register pointer Note: This code deliberately does *not* check for NPE for (at least) three reasons: 1) NPE is not just NULL/0 - there is a range of values all resulting in an NPE, which is not trivial to check for 2) It is the responsibility of the callers of Unsafe methods to verify the input, so throwing an exception here is not really useful - passing in a NULL pointer is a critical error and the must not expect an exception to be thrown anyway.

private void

Returns:

true if the type is a primitive array type
checkPrimitiveArray
(Class<?>
the type to check
c
)

Check if a type is a primitive array type

private void
checkPrimitivePointer(Object o, long offset)

Check that a pointer is a valid primitive array type pointer Note: pointers off-heap are considered to be primitive arrays

private void
checkSize(long size)

Check the validity of a size (the equivalent of a size_t)

private void
checkWritebackEnabled()

Validate that the current hardware supports memory writeback.

private void
checkWritebackMemory(long address, long length)

Validate the arguments to writebackMemory

public final boolean
compareAndExchangeBoolean(Object o, long offset, boolean expected, boolean x)

public final boolean
compareAndExchangeBooleanAcquire(Object o, long offset, boolean expected, boolean x)

public final boolean
compareAndExchangeBooleanRelease(Object o, long offset, boolean expected, boolean x)

public final byte
compareAndExchangeByte(Object o, long offset, byte expected, byte x)

public final byte
compareAndExchangeByteAcquire(Object o, long offset, byte expected, byte x)

public final byte
compareAndExchangeByteRelease(Object o, long offset, byte expected, byte x)

public final char
compareAndExchangeChar(Object o, long offset, char expected, char x)

public final char
compareAndExchangeCharAcquire(Object o, long offset, char expected, char x)

public final char
compareAndExchangeCharRelease(Object o, long offset, char expected, char x)

public final double
compareAndExchangeDouble(Object o, long offset, double expected, double x)

public final double
compareAndExchangeDoubleAcquire(Object o, long offset, double expected, double x)

public final double
compareAndExchangeDoubleRelease(Object o, long offset, double expected, double x)

public final float
compareAndExchangeFloat(Object o, long offset, float expected, float x)

public final float
compareAndExchangeFloatAcquire(Object o, long offset, float expected, float x)

public final float
compareAndExchangeFloatRelease(Object o, long offset, float expected, float x)

public final native int
compareAndExchangeInt(Object o, long offset, int expected, int x)

public final int
compareAndExchangeIntAcquire(Object o, long offset, int expected, int x)

public final int
compareAndExchangeIntRelease(Object o, long offset, int expected, int x)

public final native long
compareAndExchangeLong(Object o, long offset, long expected, long x)

public final long
compareAndExchangeLongAcquire(Object o, long offset, long expected, long x)

public final long
compareAndExchangeLongRelease(Object o, long offset, long expected, long x)

public final native Object
compareAndExchangeReference(Object o, long offset, Object expected, Object x)

public final Object
public final Object
public final short
compareAndExchangeShort(Object o, long offset, short expected, short x)

public final short
compareAndExchangeShortAcquire(Object o, long offset, short expected, short x)

public final short
compareAndExchangeShortRelease(Object o, long offset, short expected, short x)

public final boolean
compareAndSetBoolean(Object o, long offset, boolean expected, boolean x)

public final boolean
compareAndSetByte(Object o, long offset, byte expected, byte x)

public final boolean
compareAndSetChar(Object o, long offset, char expected, char x)

public final boolean

Returns:

true if successful
compareAndSetDouble
(Object o, long offset, double expected, double x)

Atomically updates Java variable to x if it is currently holding expected.

public final boolean

Returns:

true if successful
compareAndSetFloat
(Object o, long offset, float expected, float x)

Atomically updates Java variable to x if it is currently holding expected.

public final native boolean

Returns:

true if successful
compareAndSetInt
(Object o, long offset, int expected, int x)

Atomically updates Java variable to x if it is currently holding expected.

public final native boolean

Returns:

true if successful
compareAndSetLong
(Object o, long offset, long expected, long x)

Atomically updates Java variable to x if it is currently holding expected.

public final native boolean

Returns:

true if successful
compareAndSetReference
(Object o, long offset, Object expected, Object x)

Atomically updates Java variable to x if it is currently holding expected.

public final boolean
compareAndSetShort(Object o, long offset, short expected, short x)

private static char
convEndian(boolean big, char n)

private static short
convEndian(boolean big, short n)

private static int
convEndian(boolean big, int n)

private static long
convEndian(boolean big, long n)

public void
copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes)

Sets all bytes in a given block of memory to a copy of another block.

public void
copyMemory(long srcAddress, long destAddress, long bytes)

Sets all bytes in a given block of memory to a copy of another block.

private native void
copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes)

private void
copyMemoryChecks(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes)

Validate the arguments to copyMemory

public void
copySwapMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize)

Copies all elements from one block of memory to another block, *unconditionally* byte swapping the elements on the fly.

public void
copySwapMemory(long srcAddress, long destAddress, long bytes, long elemSize)

Copies all elements from one block of memory to another block, byte swapping the elements on the fly.

private native void
copySwapMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize)

private void
copySwapMemoryChecks(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes, long elemSize)

public long

Returns:

the rounded down address
dataCacheLineAlignDown
(long address)

Rounds down address to a data cache line boundary as determined by dataCacheLineFlushSize

public int
dataCacheLineFlushSize()

Reports the size in bytes of a data cache line written back by the hardware cache line flush operation available to the JVM or 0 if data cache line flushing is not enabled.

public Class<?>
defineClass(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain protectionDomain)

Tells the VM to define a class, without security checks.

public native Class<?>
defineClass0(String name, byte[] b, int off, int len, ClassLoader loader, ProtectionDomain protectionDomain)

public void
ensureClassInitialized(Class<?> c)

Ensures the given class has been initialized (see JVMS-5.5 for details).

private native void
public void
freeMemory(long address)

Disposes of a block of native memory, as obtained from allocateMemory or reallocateMemory.

private native void
freeMemory0(long address)

private void
freeMemoryChecks(long address)

Validate the arguments to freeMemory

public native void
fullFence()

Ensures that loads and stores before the fence will not be reordered with loads and stores after the fence.

public long
getAddress(Object o, long offset)

Fetches a native pointer from a given memory address.

public long
getAddress(long address)

public final byte
getAndAddByte(Object o, long offset, byte delta)

public final byte
getAndAddByteAcquire(Object o, long offset, byte delta)

public final byte
getAndAddByteRelease(Object o, long offset, byte delta)

public final char
getAndAddChar(Object o, long offset, char delta)

public final char
getAndAddCharAcquire(Object o, long offset, char delta)

public final char
getAndAddCharRelease(Object o, long offset, char delta)

public final double
getAndAddDouble(Object o, long offset, double delta)

public final double
getAndAddDoubleAcquire(Object o, long offset, double delta)

public final double
getAndAddDoubleRelease(Object o, long offset, double delta)

public final float
getAndAddFloat(Object o, long offset, float delta)

public final float
getAndAddFloatAcquire(Object o, long offset, float delta)

public final float
getAndAddFloatRelease(Object o, long offset, float delta)

public final int

Returns:

the previous value
getAndAddInt
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
int
the value to add
delta
)

Atomically adds the given value to the current value of a field or array element within the given object o at the given offset.

public final int
getAndAddIntAcquire(Object o, long offset, int delta)

public final int
getAndAddIntRelease(Object o, long offset, int delta)

public final long

Returns:

the previous value
getAndAddLong
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
long
the value to add
delta
)

Atomically adds the given value to the current value of a field or array element within the given object o at the given offset.

public final long
getAndAddLongAcquire(Object o, long offset, long delta)

public final long
getAndAddLongRelease(Object o, long offset, long delta)

public final short
getAndAddShort(Object o, long offset, short delta)

public final short
getAndAddShortAcquire(Object o, long offset, short delta)

public final short
getAndAddShortRelease(Object o, long offset, short delta)

public final boolean
getAndBitwiseAndBoolean(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseAndBooleanAcquire(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseAndBooleanRelease(Object o, long offset, boolean mask)

public final byte
getAndBitwiseAndByte(Object o, long offset, byte mask)

public final byte
getAndBitwiseAndByteAcquire(Object o, long offset, byte mask)

public final byte
getAndBitwiseAndByteRelease(Object o, long offset, byte mask)

public final char
getAndBitwiseAndChar(Object o, long offset, char mask)

public final char
getAndBitwiseAndCharAcquire(Object o, long offset, char mask)

public final char
getAndBitwiseAndCharRelease(Object o, long offset, char mask)

public final int

Returns:

the previous value
getAndBitwiseAndInt
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
int
the mask value
mask
)

Atomically replaces the current value of a field or array element within the given object with the result of bitwise AND between the current value and mask.

public final int
getAndBitwiseAndIntAcquire(Object o, long offset, int mask)

public final int
getAndBitwiseAndIntRelease(Object o, long offset, int mask)

public final long
getAndBitwiseAndLong(Object o, long offset, long mask)

public final long
getAndBitwiseAndLongAcquire(Object o, long offset, long mask)

public final long
getAndBitwiseAndLongRelease(Object o, long offset, long mask)

public final short
getAndBitwiseAndShort(Object o, long offset, short mask)

public final short
getAndBitwiseAndShortAcquire(Object o, long offset, short mask)

public final short
getAndBitwiseAndShortRelease(Object o, long offset, short mask)

public final boolean
getAndBitwiseOrBoolean(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseOrBooleanAcquire(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseOrBooleanRelease(Object o, long offset, boolean mask)

public final byte
getAndBitwiseOrByte(Object o, long offset, byte mask)

public final byte
getAndBitwiseOrByteAcquire(Object o, long offset, byte mask)

public final byte
getAndBitwiseOrByteRelease(Object o, long offset, byte mask)

public final char
getAndBitwiseOrChar(Object o, long offset, char mask)

public final char
getAndBitwiseOrCharAcquire(Object o, long offset, char mask)

public final char
getAndBitwiseOrCharRelease(Object o, long offset, char mask)

public final int
getAndBitwiseOrInt(Object o, long offset, int mask)

public final int
getAndBitwiseOrIntAcquire(Object o, long offset, int mask)

public final int
getAndBitwiseOrIntRelease(Object o, long offset, int mask)

public final long
getAndBitwiseOrLong(Object o, long offset, long mask)

public final long
getAndBitwiseOrLongAcquire(Object o, long offset, long mask)

public final long
getAndBitwiseOrLongRelease(Object o, long offset, long mask)

public final short
getAndBitwiseOrShort(Object o, long offset, short mask)

public final short
getAndBitwiseOrShortAcquire(Object o, long offset, short mask)

public final short
getAndBitwiseOrShortRelease(Object o, long offset, short mask)

public final boolean
getAndBitwiseXorBoolean(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseXorBooleanAcquire(Object o, long offset, boolean mask)

public final boolean
getAndBitwiseXorBooleanRelease(Object o, long offset, boolean mask)

public final byte
getAndBitwiseXorByte(Object o, long offset, byte mask)

public final byte
getAndBitwiseXorByteAcquire(Object o, long offset, byte mask)

public final byte
getAndBitwiseXorByteRelease(Object o, long offset, byte mask)

public final char
getAndBitwiseXorChar(Object o, long offset, char mask)

public final char
getAndBitwiseXorCharAcquire(Object o, long offset, char mask)

public final char
getAndBitwiseXorCharRelease(Object o, long offset, char mask)

public final int
getAndBitwiseXorInt(Object o, long offset, int mask)

public final int
getAndBitwiseXorIntAcquire(Object o, long offset, int mask)

public final int
getAndBitwiseXorIntRelease(Object o, long offset, int mask)

public final long
getAndBitwiseXorLong(Object o, long offset, long mask)

public final long
getAndBitwiseXorLongAcquire(Object o, long offset, long mask)

public final long
getAndBitwiseXorLongRelease(Object o, long offset, long mask)

public final short
getAndBitwiseXorShort(Object o, long offset, short mask)

public final short
getAndBitwiseXorShortAcquire(Object o, long offset, short mask)

public final short
getAndBitwiseXorShortRelease(Object o, long offset, short mask)

public final boolean
getAndSetBoolean(Object o, long offset, boolean newValue)

public final boolean
getAndSetBooleanAcquire(Object o, long offset, boolean newValue)

public final boolean
getAndSetBooleanRelease(Object o, long offset, boolean newValue)

public final byte
getAndSetByte(Object o, long offset, byte newValue)

public final byte
getAndSetByteAcquire(Object o, long offset, byte newValue)

public final byte
getAndSetByteRelease(Object o, long offset, byte newValue)

public final char
getAndSetChar(Object o, long offset, char newValue)

public final char
getAndSetCharAcquire(Object o, long offset, char newValue)

public final char
getAndSetCharRelease(Object o, long offset, char newValue)

public final double
getAndSetDouble(Object o, long offset, double newValue)

public final double
getAndSetDoubleAcquire(Object o, long offset, double newValue)

public final double
getAndSetDoubleRelease(Object o, long offset, double newValue)

public final float
getAndSetFloat(Object o, long offset, float newValue)

public final float
getAndSetFloatAcquire(Object o, long offset, float newValue)

public final float
getAndSetFloatRelease(Object o, long offset, float newValue)

public final int

Returns:

the previous value
getAndSetInt
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
int
new value
newValue
)

Atomically exchanges the given value with the current value of a field or array element within the given object o at the given offset.

public final int
getAndSetIntAcquire(Object o, long offset, int newValue)

public final int
getAndSetIntRelease(Object o, long offset, int newValue)

public final long

Returns:

the previous value
getAndSetLong
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
long
new value
newValue
)

Atomically exchanges the given value with the current value of a field or array element within the given object o at the given offset.

public final long
getAndSetLongAcquire(Object o, long offset, long newValue)

public final long
getAndSetLongRelease(Object o, long offset, long newValue)

public final Object

Returns:

the previous value
getAndSetReference
(Object
object/array to update the field/element in
o
,
long
field/element offset
offset
,
Object
new value
newValue
)

Atomically exchanges the given reference value with the current reference value of a field or array element within the given object o at the given offset.

public final Object
getAndSetReferenceAcquire(Object o, long offset, Object newValue)

public final Object
getAndSetReferenceRelease(Object o, long offset, Object newValue)

public final short
getAndSetShort(Object o, long offset, short newValue)

public final short
getAndSetShortAcquire(Object o, long offset, short newValue)

public final short
getAndSetShortRelease(Object o, long offset, short newValue)

public native boolean
getBoolean(Object o, long offset)

public final boolean
getBooleanAcquire(Object o, long offset)

Acquire version of getBooleanVolatile(Object, long)

public final boolean
getBooleanOpaque(Object o, long offset)

Opaque version of getBooleanVolatile(Object, long)

public native boolean
getBooleanVolatile(Object o, long offset)

Volatile version of getBoolean(Object, long)

public native byte
getByte(Object o, long offset)

public byte
getByte(long address)

Fetches a value from a given memory address.

public final byte
getByteAcquire(Object o, long offset)

Acquire version of getByteVolatile(Object, long)

public final byte
getByteOpaque(Object o, long offset)

Opaque version of getByteVolatile(Object, long)

public native byte
getByteVolatile(Object o, long offset)

Volatile version of getByte(Object, long)

public native char
getChar(Object o, long offset)

public char
getChar(long address)

public final char
getCharAcquire(Object o, long offset)

Acquire version of getCharVolatile(Object, long)

public final char
getCharOpaque(Object o, long offset)

Opaque version of getCharVolatile(Object, long)

public final char
getCharUnaligned(Object o, long offset)

public final char
getCharUnaligned(Object o, long offset, boolean bigEndian)

public native char
getCharVolatile(Object o, long offset)

Volatile version of getChar(Object, long)

public native double
getDouble(Object o, long offset)

public double
getDouble(long address)

public final double
getDoubleAcquire(Object o, long offset)

Acquire version of getDoubleVolatile(Object, long)

public final double
getDoubleOpaque(Object o, long offset)

Opaque version of getDoubleVolatile(Object, long)

public native double
getDoubleVolatile(Object o, long offset)

Volatile version of getDouble(Object, long)

public native float
getFloat(Object o, long offset)

public float
getFloat(long address)

public final float
getFloatAcquire(Object o, long offset)

Acquire version of getFloatVolatile(Object, long)

public final float
getFloatOpaque(Object o, long offset)

Opaque version of getFloatVolatile(Object, long)

public native float
getFloatVolatile(Object o, long offset)

Volatile version of getFloat(Object, long)

public native int

Returns:

the value fetched from the indicated Java variable
getInt
(Object
Java heap object in which the variable resides, if any, else null
o
,
long
indication of where the variable resides in a Java heap object, if any, else a memory address locating the variable statically
offset
)

Fetches a value from a given Java variable.

public int
getInt(long address)

public final int
getIntAcquire(Object o, long offset)

Acquire version of getIntVolatile(Object, long)

public final int
getIntOpaque(Object o, long offset)

Opaque version of getIntVolatile(Object, long)

public final int
getIntUnaligned(Object o, long offset)

public final int
getIntUnaligned(Object o, long offset, boolean bigEndian)

public native int
getIntVolatile(Object o, long offset)

Volatile version of getInt(Object, long)

public int

Returns:

the number of samples actually retrieved; or -1 if the load average is unobtainable.
getLoadAverage
(double[]
an array of double of size nelems
loadavg
,
int
the number of samples to be retrieved and must be 1 to 3.
nelems
)

Gets the load average in the system run queue assigned to the available processors averaged over various periods of time.

private native int
getLoadAverage0(double[] loadavg, int nelems)

public native long
getLong(Object o, long offset)

public long
getLong(long address)

public final long
getLongAcquire(Object o, long offset)

Acquire version of getLongVolatile(Object, long)

public final long
getLongOpaque(Object o, long offset)

Opaque version of getLongVolatile(Object, long)

public final long

Returns:

the value fetched from the indicated object
getLongUnaligned
(Object
Java heap object in which the value resides, if any, else null
o
,
long
The offset in bytes from the start of the object
offset
)

Fetches a value at some byte offset into a given Java object.

public final long

Returns:

the value fetched from the indicated object
getLongUnaligned
(Object
Java heap object in which the variable resides
o
,
long
The offset in bytes from the start of the object
offset
,
boolean
The endianness of the value
bigEndian
)

As getLongUnaligned(Object, long) but with an additional argument which specifies the endianness of the value as stored in memory.

public native long
getLongVolatile(Object o, long offset)

Volatile version of getLong(Object, long)

public native Object
getReference(Object o, long offset)

Fetches a reference value from a given Java variable.

public final Object
public final Object
public native Object
getReferenceVolatile(Object o, long offset)

Fetches a reference value from a given Java variable, with volatile load semantics.

public native short
getShort(Object o, long offset)

public short
getShort(long address)

public final short
getShortAcquire(Object o, long offset)

Acquire version of getShortVolatile(Object, long)

public final short
getShortOpaque(Object o, long offset)

Opaque version of getShortVolatile(Object, long)

public final short
getShortUnaligned(Object o, long offset)

public final short
getShortUnaligned(Object o, long offset, boolean bigEndian)

public native short
getShortVolatile(Object o, long offset)

Volatile version of getShort(Object, long)

public native Object

Returns:

the value fetched from the indicated native variable
getUncompressedObject
(long
a memory address locating the variable
address
)

Fetches an uncompressed reference value from a given native variable ignoring the VM's compressed references mode.

public static Unsafe
getUnsafe()

Provides the caller with the capability of performing unsafe operations.

private RuntimeException

Returns:

an exception object
invalidInput
()

Create an exception reflecting that some of the input was invalid

Note

It is the responsibility of the caller to make sure arguments are checked before the methods are called.

public void
invokeCleaner(ByteBuffer
a direct byte buffer
directBuffer
)

Invokes the given direct byte buffer's cleaner, if any.

private boolean

Returns:

true if the value is 32-bit clean
is32BitClean
(long
the 64-bit value to check
value
)

Check if a value is 32-bit clean (32 MSB are all zero)

public final boolean

Returns:

Returns true if the native byte ordering of this platform is big-endian, false if it is little-endian.
isBigEndian
()

public static boolean
isWritebackEnabled()

Returns true if data cache line writeback

public final void
loadFence()

Ensures that loads before the fence will not be reordered with loads and stores after the fence; a "LoadLoad plus LoadStore barrier".

public final void
loadLoadFence()

Ensures that loads before the fence will not be reordered with loads after the fence.

private static int
makeInt(short i0, short i1)

private static int
makeInt(byte i0, byte i1, byte i2, byte i3)

private static long
makeLong(byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7)

private static long
makeLong(short i0, short i1, short i2, short i3)

private static long
makeLong(int i0, int i1)

private static short
makeShort(byte i0, byte i1)

public long
objectFieldOffset(Field f)

Reports the location of a given field in the storage allocation of its class.

public long
objectFieldOffset(Class<?> c, String name)

Reports the location of the field with a given name in the storage allocation of its class.

private native long
private native long
public int
pageSize()

Reports the size in bytes of a native memory page (whatever that is).

public native void
park(boolean isAbsolute, long time)

Blocks current thread, returning when a balancing unpark occurs, or a balancing unpark has already occurred, or the thread is interrupted, or, if not absolute and time is not zero, the given time nanoseconds have elapsed, or if absolute, the given deadline in milliseconds since Epoch has passed, or spuriously (i.e., returning for no "reason").

private static byte
pick(byte le, byte be)

private static short
pick(short le, short be)

private static int
pick(int le, int be)

private static int
pickPos(int top, int pos)

public void
putAddress(Object o, long offset, long x)

Stores a native pointer into a given memory address.

public void
putAddress(long address, long x)

public native void
putBoolean(Object o, long offset, boolean x)

public final void
putBooleanOpaque(Object o, long offset, boolean x)

Opaque version of putBooleanVolatile(Object, long, boolean)

public final void
putBooleanRelease(Object o, long offset, boolean x)

Release version of putBooleanVolatile(Object, long, boolean)

public native void
putBooleanVolatile(Object o, long offset, boolean x)

Volatile version of putBoolean(Object, long, boolean)

public native void
putByte(Object o, long offset, byte x)

public void
putByte(long address, byte x)

Stores a value into a given memory address.

public final void
putByteOpaque(Object o, long offset, byte x)

Opaque version of putByteVolatile(Object, long, byte)

public final void
putByteRelease(Object o, long offset, byte x)

Release version of putByteVolatile(Object, long, byte)

public native void
putByteVolatile(Object o, long offset, byte x)

Volatile version of putByte(Object, long, byte)

public native void
putChar(Object o, long offset, char x)

public void
putChar(long address, char x)

public final void
putCharOpaque(Object o, long offset, char x)

Opaque version of putCharVolatile(Object, long, char)

public final void
putCharRelease(Object o, long offset, char x)

Release version of putCharVolatile(Object, long, char)

public final void
putCharUnaligned(Object o, long offset, char x)

public final void
putCharUnaligned(Object o, long offset, char x, boolean bigEndian)

public native void
putCharVolatile(Object o, long offset, char x)

Volatile version of putChar(Object, long, char)

public native void
putDouble(Object o, long offset, double x)

public void
putDouble(long address, double x)

public final void
putDoubleOpaque(Object o, long offset, double x)

Opaque version of putDoubleVolatile(Object, long, double)

public final void
putDoubleRelease(Object o, long offset, double x)

Release version of putDoubleVolatile(Object, long, double)

public native void
putDoubleVolatile(Object o, long offset, double x)

Volatile version of putDouble(Object, long, double)

public native void
putFloat(Object o, long offset, float x)

public void
putFloat(long address, float x)

public final void
putFloatOpaque(Object o, long offset, float x)

Opaque version of putFloatVolatile(Object, long, float)

public final void
putFloatRelease(Object o, long offset, float x)

Release version of putFloatVolatile(Object, long, float)

public native void
putFloatVolatile(Object o, long offset, float x)

Volatile version of putFloat(Object, long, float)

public native void
putInt(Object
Java heap object in which the variable resides, if any, else null
o
,
long
indication of where the variable resides in a Java heap object, if any, else a memory address locating the variable statically
offset
,
int
the value to store into the indicated Java variable
x
)

Stores a value into a given Java variable.

public void
putInt(long address, int x)

public final void
putIntOpaque(Object o, long offset, int x)

Opaque version of putIntVolatile(Object, long, int)

private void
putIntParts(Object o, long offset, short i0, short i1)

private void
putIntParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3)

public final void
putIntRelease(Object o, long offset, int x)

Release version of putIntVolatile(Object, long, int)

public final void
putIntUnaligned(Object o, long offset, int x)

public final void
putIntUnaligned(Object o, long offset, int x, boolean bigEndian)

public native void
putIntVolatile(Object o, long offset, int x)

Volatile version of putInt(Object, long, int)

public native void
putLong(Object o, long offset, long x)

public void
putLong(long address, long x)

public final void
putLongOpaque(Object o, long offset, long x)

Opaque version of putLongVolatile(Object, long, long)

private void
putLongParts(Object o, long offset, byte i0, byte i1, byte i2, byte i3, byte i4, byte i5, byte i6, byte i7)

private void
putLongParts(Object o, long offset, short i0, short i1, short i2, short i3)

private void
putLongParts(Object o, long offset, int i0, int i1)

public final void
putLongRelease(Object o, long offset, long x)

Release version of putLongVolatile(Object, long, long)

public final void
putLongUnaligned(Object
Java heap object in which the value resides, if any, else null
o
,
long
The offset in bytes from the start of the object
offset
,
long
the value to store
x
)

Stores a value at some byte offset into a given Java object.

public final void
putLongUnaligned(Object
Java heap object in which the value resides
o
,
long
The offset in bytes from the start of the object
offset
,
long
the value to store
x
,
boolean
The endianness of the value
bigEndian
)

As putLongUnaligned(Object, long, long) but with an additional argument which specifies the endianness of the value as stored in memory.

public native void
putLongVolatile(Object o, long offset, long x)

Volatile version of putLong(Object, long, long)

public native void
putReference(Object o, long offset, Object x)

Stores a reference value into a given Java variable.

public final void
public final void
public native void
putReferenceVolatile(Object o, long offset, Object x)

Stores a reference value into a given Java variable, with volatile store semantics.

public native void
putShort(Object o, long offset, short x)

public void
putShort(long address, short x)

public final void
putShortOpaque(Object o, long offset, short x)

Opaque version of putShortVolatile(Object, long, short)

private void
putShortParts(Object o, long offset, byte i0, byte i1)

public final void
putShortRelease(Object o, long offset, short x)

Release version of putShortVolatile(Object, long, short)

public final void
putShortUnaligned(Object o, long offset, short x)

public final void
putShortUnaligned(Object o, long offset, short x, boolean bigEndian)

public native void
putShortVolatile(Object o, long offset, short x)

Volatile version of putShort(Object, long, short)

public long
reallocateMemory(long address, long bytes)

Resizes a new block of native memory, to the given size in bytes.

private native long
reallocateMemory0(long address, long bytes)

private void
reallocateMemoryChecks(long address, long bytes)

Validate the arguments to reallocateMemory

private static native void
private char
s2c(short s)

public void
setMemory(Object o, long offset, long bytes, byte value)

Sets all bytes in a given block of memory to a fixed value (usually zero).

public void
setMemory(long address, long bytes, byte value)

Sets all bytes in a given block of memory to a fixed value (usually zero).

private native void
setMemory0(Object o, long offset, long bytes, byte value)

private void
setMemoryChecks(Object o, long offset, long bytes, byte value)

Validate the arguments to setMemory

public boolean

Returns:

false only if a call to ensureClassInitialized would have no effect
shouldBeInitialized
(Class<?> c)

Detects if the given class may need to be initialized.

private native boolean
public Object
staticFieldBase(Field f)

Reports the location of a given static field, in conjunction with staticFieldOffset.

private native Object
public long
staticFieldOffset(Field f)

Reports the location of a given static field, in conjunction with staticFieldBase.

private native long
public final void
storeFence()

Ensures that loads and stores before the fence will not be reordered with stores after the fence; a "StoreStore plus LoadStore barrier".

public final void
storeStoreFence()

Ensures that stores before the fence will not be reordered with stores after the fence.

public native void
throwException(Throwable ee)

Throws the exception without telling the verifier.

private static void
throwIllegalAccessError()

Throws IllegalAccessError; for use by the VM for access control error support.

private static void
throwNoSuchMethodError()

Throws NoSuchMethodError; for use by the VM for redefinition support.

private static int
toUnsignedInt(byte n)

private static int
toUnsignedInt(short n)

private static long
private static long
toUnsignedLong(short n)

private static long
public final boolean

Returns:

Returns true if this platform is capable of performing accesses at addresses which are not aligned for the type of the primitive type being accessed, false otherwise.
unalignedAccess
()

public native void
unpark(Object
the thread to unpark.
thread
)

Unblocks the given thread blocked on park, or, if it is not blocked, causes the subsequent call to park not to block.

public final boolean
weakCompareAndSetBoolean(Object o, long offset, boolean expected, boolean x)

public final boolean
weakCompareAndSetBooleanAcquire(Object o, long offset, boolean expected, boolean x)

public final boolean
weakCompareAndSetBooleanPlain(Object o, long offset, boolean expected, boolean x)

public final boolean
weakCompareAndSetBooleanRelease(Object o, long offset, boolean expected, boolean x)

public final boolean
weakCompareAndSetByte(Object o, long offset, byte expected, byte x)

public final boolean
weakCompareAndSetByteAcquire(Object o, long offset, byte expected, byte x)

public final boolean
weakCompareAndSetBytePlain(Object o, long offset, byte expected, byte x)

public final boolean
weakCompareAndSetByteRelease(Object o, long offset, byte expected, byte x)

public final boolean
weakCompareAndSetChar(Object o, long offset, char expected, char x)

public final boolean
weakCompareAndSetCharAcquire(Object o, long offset, char expected, char x)

public final boolean
weakCompareAndSetCharPlain(Object o, long offset, char expected, char x)

public final boolean
weakCompareAndSetCharRelease(Object o, long offset, char expected, char x)

public final boolean
weakCompareAndSetDouble(Object o, long offset, double expected, double x)

public final boolean
weakCompareAndSetDoubleAcquire(Object o, long offset, double expected, double x)

public final boolean
weakCompareAndSetDoublePlain(Object o, long offset, double expected, double x)

public final boolean
weakCompareAndSetDoubleRelease(Object o, long offset, double expected, double x)

public final boolean
weakCompareAndSetFloat(Object o, long offset, float expected, float x)

public final boolean
weakCompareAndSetFloatAcquire(Object o, long offset, float expected, float x)

public final boolean
weakCompareAndSetFloatPlain(Object o, long offset, float expected, float x)

public final boolean
weakCompareAndSetFloatRelease(Object o, long offset, float expected, float x)

public final boolean
weakCompareAndSetInt(Object o, long offset, int expected, int x)

public final boolean
weakCompareAndSetIntAcquire(Object o, long offset, int expected, int x)

public final boolean
weakCompareAndSetIntPlain(Object o, long offset, int expected, int x)

public final boolean
weakCompareAndSetIntRelease(Object o, long offset, int expected, int x)

public final boolean
weakCompareAndSetLong(Object o, long offset, long expected, long x)

public final boolean
weakCompareAndSetLongAcquire(Object o, long offset, long expected, long x)

public final boolean
weakCompareAndSetLongPlain(Object o, long offset, long expected, long x)

public final boolean
weakCompareAndSetLongRelease(Object o, long offset, long expected, long x)

public final boolean
weakCompareAndSetReference(Object o, long offset, Object expected, Object x)

public final boolean
public final boolean
weakCompareAndSetReferencePlain(Object o, long offset, Object expected, Object x)

public final boolean
public final boolean
weakCompareAndSetShort(Object o, long offset, short expected, short x)

public final boolean
weakCompareAndSetShortAcquire(Object o, long offset, short expected, short x)

public final boolean
weakCompareAndSetShortPlain(Object o, long offset, short expected, short x)

public final boolean
weakCompareAndSetShortRelease(Object o, long offset, short expected, short x)

private native void
writeback0(long
the start address of the cache line to be written back
address
)

force writeback of an individual cache line.

public void
writebackMemory(long
the lowest byte address that must be guaranteed written back to memory. bytes at lower addresses may also be written back.
address
,
long
the length in bytes of the region starting at address that must be guaranteed written back to memory.
length
)

Ensure writeback of a specified virtual memory address range from cache to physical memory.

private native void
writebackPostSync0()

Serialize writeback operations relative to following memory writes.

private native void
writebackPreSync0()

Serialize writeback operations relative to preceding memory writes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait