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!
getUnsafe
Modifier and Type | Field and Description |
---|---|
public static final int | ADDRESS_SIZE
The value of |
public static final int | ARRAY_BOOLEAN_BASE_OFFSET
The value of |
public static final int | ARRAY_BOOLEAN_INDEX_SCALE
The value of |
public static final int | ARRAY_BYTE_BASE_OFFSET
The value of |
public static final int | ARRAY_BYTE_INDEX_SCALE
The value of |
public static final int | ARRAY_CHAR_BASE_OFFSET
The value of |
public static final int | ARRAY_CHAR_INDEX_SCALE
The value of |
public static final int | ARRAY_DOUBLE_BASE_OFFSET
The value of |
public static final int | ARRAY_DOUBLE_INDEX_SCALE
The value of |
public static final int | ARRAY_FLOAT_BASE_OFFSET
The value of |
public static final int | ARRAY_FLOAT_INDEX_SCALE
The value of |
public static final int | ARRAY_INT_BASE_OFFSET
The value of |
public static final int | ARRAY_INT_INDEX_SCALE
The value of |
public static final int | ARRAY_LONG_BASE_OFFSET
The value of |
public static final int | ARRAY_LONG_INDEX_SCALE
The value of |
public static final int | ARRAY_OBJECT_BASE_OFFSET
The value of |
public static final int | ARRAY_OBJECT_INDEX_SCALE
The value of |
public static final int | ARRAY_SHORT_BASE_OFFSET
The value of |
public static final int | ARRAY_SHORT_INDEX_SCALE
The value of |
public static final int | INVALID_FIELD_OFFSET
This constant differs from all results that will ever be returned from
|
private static final Unsafe |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public int | |
private long | |
public native Object | |
public long | |
private native long | |
private void | |
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 | |
public int | arrayBaseOffset(Class<?> arrayClass)
Reports the offset of the first element in the storage allocation of a given array class. |
private native int | |
public int | arrayIndexScale(Class<?> arrayClass)
Reports the scale factor for addressing elements in the storage allocation of a given array class. |
private native int | |
private byte | Returns: the result of the conversionthe boolean to be converted to byte (and then normalized) b)Convert a boolean value to a byte. |
private boolean | Returns: the result of the conversionthe 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 | |
private 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 typethe 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 | |
private void | |
private void | |
public final boolean | |
public final boolean | |
public final boolean | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final double | |
public final double | |
public final double | |
public final float | |
public final float | |
public final float | |
public final native int | |
public final int | |
public final int | |
public final native long | |
public final long | |
public final long | |
public final native Object | |
public final Object | |
public final Object | |
public final short | |
public final short | |
public final short | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | Returns: true if successfulAtomically updates Java variable to |
public final boolean | Returns: true if successfulAtomically updates Java variable to |
public final native boolean | Returns: true if successfulAtomically updates Java variable to |
public final native boolean | Returns: true if successfulAtomically updates Java variable to |
public final native boolean | Returns: true if successfulAtomically updates Java variable to |
public final boolean | |
private static char | |
private static short | |
private static int | |
private static long | |
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 | |
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 addressRounds down address to a data cache line boundary as
determined by |
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 |
private native void | |
private void | |
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 | |
public long | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final double | |
public final double | |
public final double | |
public final float | |
public final float | |
public final float | |
public final int | Returns: the previous valueobject/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 |
public final int | |
public final int | |
public final long | Returns: the previous valueobject/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 |
public final long | |
public final long | |
public final short | |
public final short | |
public final short | |
public final boolean | |
public final boolean | |
public final boolean | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final int | Returns: the previous valueobject/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 | |
public final int | |
public final long | |
public final long | |
public final long | |
public final short | |
public final short | |
public final short | |
public final boolean | |
public final boolean | |
public final boolean | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final int | |
public final int | |
public final int | |
public final long | |
public final long | |
public final long | |
public final short | |
public final short | |
public final short | |
public final boolean | |
public final boolean | |
public final boolean | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final int | |
public final int | |
public final int | |
public final long | |
public final long | |
public final long | |
public final short | |
public final short | |
public final short | |
public final boolean | |
public final boolean | |
public final boolean | |
public final byte | |
public final byte | |
public final byte | |
public final char | |
public final char | |
public final char | |
public final double | |
public final double | |
public final double | |
public final float | |
public final float | |
public final float | |
public final int | Returns: the previous valueobject/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 |
public final int | |
public final int | |
public final long | Returns: the previous valueobject/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 |
public final long | |
public final long | |
public final Object | Returns: the previous valueobject/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 |
public final Object | |
public final Object | |
public final short | |
public final short | |
public final short | |
public native boolean | |
public final boolean | |
public final boolean | |
public native boolean | |
public native byte | |
public byte | |
public final byte | |
public final byte | |
public native byte | |
public native char | |
public char | |
public final char | |
public final char | |
public final char | |
public final char | |
public native char | |
public native double | |
public double | |
public final double | |
public final double | |
public native double | |
public native float | |
public float | |
public final float | |
public final float | |
public native float | |
public native int | Returns: the value fetched from the indicated Java variableJava 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 | |
public final int | |
public final int | |
public final int | |
public final int | |
public native int | |
public int | Returns: the number of samples actually retrieved; or -1 if the load average is unobtainable.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 | |
public native long | |
public long | |
public final long | |
public final long | |
public final long | Returns: the value fetched from the indicated objectJava 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 objectJava 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 |
public native long | |
public native Object | |
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 | |
public short | |
public final short | |
public final short | |
public final short | |
public final short | |
public native short | |
public native Object | Returns: the value fetched from the indicated native variablea 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 | |
private RuntimeException | Returns: an exception objectCreate 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 cleanthe 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.
|
public static boolean | |
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 | |
private static int | |
private static long | |
private static long | |
private static long | |
private static short | |
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 | |
public native void | park(boolean isAbsolute, long time)
Blocks current thread, returning when a balancing
|
private static byte | |
private static short | |
private static int | |
private static int | |
public void | |
public void | |
public native void | |
public final void | putBooleanOpaque(Object o, long offset, boolean x)
Opaque version of |
public final void | putBooleanRelease(Object o, long offset, boolean x)
Release version of |
public native void | putBooleanVolatile(Object o, long offset, boolean x)
Volatile version of |
public native void | |
public void | |
public final void | |
public final void | |
public native void | |
public native void | |
public void | |
public final void | |
public final void | |
public final void | |
public final void | |
public native void | |
public native void | |
public void | |
public final void | putDoubleOpaque(Object o, long offset, double x)
Opaque version of |
public final void | putDoubleRelease(Object o, long offset, double x)
Release version of |
public native void | putDoubleVolatile(Object o, long offset, double x)
Volatile version of |
public native void | |
public void | |
public final void | putFloatOpaque(Object o, long offset, float x)
Opaque version of |
public final void | putFloatRelease(Object o, long offset, float x)
Release version of |
public native void | |
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 | |
public final void | |
private void | |
private void | |
public final void | |
public final void | |
public final void | |
public native void | |
public native void | |
public void | |
public final void | |
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 | |
private void | |
public final void | |
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 |
public native void | |
public native void | |
public final void | putReferenceOpaque(Object o, long offset, Object x)
Opaque version of |
public final void | putReferenceRelease(Object o, long offset, Object x)
Release version of |
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 | |
public void | |
public final void | putShortOpaque(Object o, long offset, short x)
Opaque version of |
private void | |
public final void | putShortRelease(Object o, long offset, short x)
Release version of |
public final void | |
public final void | |
public native void | |
public long | reallocateMemory(long address, long bytes)
Resizes a new block of native memory, to the given size in bytes. |
private native long | |
private void | |
private static native void | |
private char | |
public void | |
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 | |
private void | |
public boolean | Returns: false only if a call toensureClassInitialized would have no effectDetects 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 |
private native Object | |
public long | staticFieldOffset(Field f)
Reports the location of a given static field, in conjunction with |
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 | |
private static void | throwIllegalAccessError()
Throws IllegalAccessError; for use by the VM for access control error support. |
private static void | |
private static int | |
private static int | |
private static long | |
private static long | |
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.
|
public native void | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
public final boolean | |
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 | |
private native void |