public abstract class GridUnsafe extends Object
Wrapper for Unsafe class.
The following statements for memory access operations are true:
putXxx(long addr, xxx val), getXxx(long addr), putXxx(byte[] arr, long off, xxx val),
getXxx(byte[] arr, long off) and corresponding methods with LE suffix are alignment aware
and can be safely used with unaligned pointers.putXxxField(Object obj, long fieldOff, xxx val) and getXxxField(Object obj, long fieldOff)
methods are not alignment aware and can't be safely used with unaligned pointers. This methods can be safely used
for object field values access because all object fields addresses are aligned.putXxxLE(...) and getXxxLE(...) methods assumes that byte order is fixed as little-endian
while native byte order is big-endian. So it is client code responsibility to check native byte order before
invoking of this methods.| Modifier and Type | Field and Description |
|---|---|
static int |
ADDR_SIZE
Address size.
|
static boolean |
BIG_ENDIAN
Big endian.
|
static long |
BOOLEAN_ARR_OFF |
static int |
BYTE_ARR_INT_OFF |
static long |
BYTE_ARR_OFF |
static long |
CHAR_ARR_OFF |
static long |
DOUBLE_ARR_OFF |
static long |
FLOAT_ARR_OFF |
static long |
INT_ARR_OFF |
static long |
LONG_ARR_OFF |
static ByteOrder |
NATIVE_BYTE_ORDER |
static long |
SHORT_ARR_OFF |
| Modifier and Type | Method and Description |
|---|---|
static ByteBuffer |
allocateBuffer(int len) |
static Object |
allocateInstance(Class cls)
Allocates instance of given class.
|
static long |
allocateMemory(long size)
Allocates memory.
|
static int |
arrayBaseOffset(Class cls)
Returns the offset of the first element in the storage allocation of a given array class.
|
static long |
bufferAddress(ByteBuffer buf)
Returns address of
Buffer instance. |
static void |
cleanDirectBuffer(ByteBuffer buf)
Cleans direct
java.nio.ByteBuffer |
static boolean |
compareAndSwapInt(Object obj,
long off,
int exp,
int upd)
Integer CAS.
|
static boolean |
compareAndSwapLong(Object obj,
long off,
long exp,
long upd)
Long CAS.
|
static void |
copyHeapOffheap(Object srcBase,
long srcOff,
long dstAddr,
long len)
Copy memory from heap to offheap.
|
static void |
copyMemory(long src,
long dst,
long len)
Copies memory.
|
static void |
copyMemory(Object srcBase,
long srcOff,
Object dstBase,
long dstOff,
long len)
Sets all bytes in a given block of memory to a copy of another block.
|
static void |
copyOffheapHeap(long srcAddr,
Object dstBase,
long dstOff,
long len)
Copy memory from offheap to heap.
|
static void |
copyOffheapOffheap(long srcAddr,
long dstAddr,
long len)
Copy memory between offheap locations.
|
static void |
freeBuffer(ByteBuffer buf) |
static void |
freeMemory(long addr)
Frees memory.
|
static boolean |
getBoolean(byte[] arr,
long off)
Gets boolean value from byte array.
|
static boolean |
getBooleanField(Object obj,
long fieldOff)
Gets boolean value from object field.
|
static byte |
getByte(byte[] arr,
long off)
Gets byte value from byte array.
|
static byte |
getByte(long addr)
Gets byte value from given address.
|
static byte |
getByteField(Object obj,
long fieldOff)
Gets byte value from object field.
|
static byte |
getByteVolatile(Object obj,
long off)
Gets byte value with volatile semantic.
|
static char |
getChar(byte[] arr,
long off)
Gets char value from byte array.
|
static char |
getChar(long addr)
Gets char value from given address.
|
static char |
getCharField(Object obj,
long fieldOff)
Gets char value from object field.
|
static char |
getCharLE(byte[] arr,
long off)
Gets char value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static char |
getCharLE(long addr)
Gets char value from given address assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static double |
getDouble(byte[] arr,
long off)
Gets double value from byte array.
|
static double |
getDouble(long addr)
Gets double value from given address.
|
static double |
getDoubleField(Object obj,
long fieldOff)
Gets double value from object field.
|
static double |
getDoubleLE(byte[] arr,
long off)
Gets double value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static double |
getDoubleLE(long addr)
Gets double value from given address assuming that value stored in little-endian byte order
and native byte order is big-endian.
|
static float |
getFloat(byte[] arr,
long off)
Gets float value from byte array.
|
static float |
getFloat(long addr)
Gets float value from given address.
|
static float |
getFloatField(Object obj,
long fieldOff)
Gets float value from object field.
|
static float |
getFloatLE(byte[] arr,
long off)
Gets float value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static float |
getFloatLE(long addr)
Gets float value from given address assuming that value stored in little-endian byte order
and native byte order is big-endian.
|
static int |
getInt(byte[] arr,
long off)
Gets integer value from byte array.
|
static int |
getInt(long addr)
Gets integer value from given address.
|
static int |
getIntField(Object obj,
long fieldOff)
Gets integer value from object field.
|
static int |
getIntLE(byte[] arr,
long off)
Gets integer value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static int |
getIntLE(long addr)
Gets integer value from given address assuming that value stored in little-endian byte order
and native byte order is big-endian.
|
static int |
getIntVolatile(Object obj,
long off)
Gets integer value with volatile semantic.
|
static long |
getLong(byte[] arr,
long off)
Gets long value from byte array.
|
static long |
getLong(long addr)
Gets long value from given address.
|
static long |
getLongField(Object obj,
long fieldOff)
Gets long value from object field.
|
static long |
getLongLE(byte[] arr,
long off)
Gets long value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static long |
getLongLE(long addr)
Gets long value from given address assuming that value stored in little-endian byte order
and native byte order is big-endian.
|
static long |
getLongVolatile(Object obj,
long off)
Gets long value with volatile semantic.
|
static Object |
getObjectField(Object obj,
long fieldOff)
Gets reference from object field.
|
static short |
getShort(byte[] arr,
long off)
Gets short value from byte array.
|
static short |
getShort(long addr)
Gets short value from given address.
|
static short |
getShortField(Object obj,
long fieldOff)
Gets short value from object field.
|
static short |
getShortLE(byte[] arr,
long off)
Gets short value from byte array assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static short |
getShortLE(long addr)
Gets short value from given address assuming that value stored in little-endian byte order and native byte order
is big-endian.
|
static Object |
invoke(Method mtd,
Object... args)
Invokes some method on
sun.misc.Unsafe instance. |
static long |
objectFieldOffset(Field field)
Returns object field offset.
|
static int |
pageSize()
Returns page size.
|
static void |
putBoolean(byte[] arr,
long off,
boolean val)
Stores boolean value into byte array.
|
static void |
putBooleanField(Object obj,
long fieldOff,
boolean val)
Stores boolean value into object field.
|
static void |
putByte(byte[] arr,
long off,
byte val)
Stores byte value into byte array.
|
static void |
putByte(long addr,
byte val)
Stores given byte value.
|
static void |
putByteField(Object obj,
long fieldOff,
byte val)
Stores byte value into object field.
|
static void |
putByteVolatile(Object obj,
long off,
byte val)
Stores byte value with volatile semantic.
|
static void |
putChar(byte[] arr,
long off,
char val)
Stores char value into byte array.
|
static void |
putChar(long addr,
char val)
Stores given char value.
|
static void |
putCharField(Object obj,
long fieldOff,
char val)
Stores char value into object field.
|
static void |
putCharLE(byte[] arr,
long off,
char val)
Stores char value into byte array assuming that value should be stored in little-endian byte order and native
byte order is big-endian.
|
static void |
putCharLE(long addr,
char val)
Stores given char value assuming that value should be stored in little-endian byte order and native byte order
is big-endian.
|
static void |
putDouble(byte[] arr,
long off,
double val)
Stores double value into byte array.
|
static void |
putDouble(long addr,
double val)
Stores given double value.
|
static void |
putDoubleField(Object obj,
long fieldOff,
double val)
Stores double value into object field.
|
static void |
putDoubleLE(byte[] arr,
long off,
double val)
Stores double value into byte array assuming that value should be stored in little-endian byte order and
native byte order is big-endian.
|
static void |
putDoubleLE(long addr,
double val)
Stores given double value assuming that value should be stored in little-endian byte order
and native byte order is big-endian.
|
static void |
putFloat(byte[] arr,
long off,
float val)
Stores float value into byte array.
|
static void |
putFloat(long addr,
float val)
Stores given float value.
|
static void |
putFloatField(Object obj,
long fieldOff,
float val)
Stores float value into object field.
|
static void |
putFloatLE(byte[] arr,
long off,
float val)
Stores float value into byte array assuming that value should be stored in little-endian byte order and native
byte order is big-endian.
|
static void |
putFloatLE(long addr,
float val)
Stores given float value assuming that value should be stored in little-endian byte order
and native byte order is big-endian.
|
static void |
putInt(byte[] arr,
long off,
int val)
Stores integer value into byte array.
|
static void |
putInt(long addr,
int val)
Stores given integer value.
|
static void |
putIntField(Object obj,
long fieldOff,
int val)
Stores integer value into object field.
|
static void |
putIntLE(byte[] arr,
long off,
int val)
Stores integer value into byte array assuming that value should be stored in little-endian byte order and
native byte order is big-endian.
|
static void |
putIntLE(long addr,
int val)
Stores given integer value assuming that value should be stored in little-endian byte order
and native byte order is big-endian.
|
static void |
putIntVolatile(Object obj,
long off,
int val)
Stores integer value with volatile semantic.
|
static void |
putLong(byte[] arr,
long off,
long val)
Stores long value into byte array.
|
static void |
putLong(long addr,
long val)
Stores given integer value.
|
static void |
putLongField(Object obj,
long fieldOff,
long val)
Stores long value into object field.
|
static void |
putLongLE(byte[] arr,
long off,
long val)
Stores long value into byte array assuming that value should be stored in little-endian byte order and native
byte order is big-endian.
|
static void |
putLongLE(long addr,
long val)
Stores given integer value assuming that value should be stored in little-endian byte order
and native byte order is big-endian.
|
static void |
putLongVolatile(Object obj,
long off,
long val)
Stores long value with volatile semantic.
|
static void |
putObjectField(Object obj,
long fieldOff,
Object val)
Stores reference value into object field.
|
static void |
putObjectVolatile(Object obj,
long off,
Object val)
Stores reference value with volatile semantic.
|
static void |
putShort(byte[] arr,
long off,
short val)
Stores short value into byte array.
|
static void |
putShort(long addr,
short val)
Stores given short value.
|
static void |
putShortField(Object obj,
long fieldOff,
short val)
Stores short value into object field.
|
static void |
putShortLE(byte[] arr,
long off,
short val)
Stores short value into byte array assuming that value should be stored in little-endian byte order and native
byte order is big-endian.
|
static void |
putShortLE(long addr,
short val)
Stores given short value assuming that value should be stored in little-endian byte order and native byte
order is big-endian.
|
static ByteBuffer |
reallocateBuffer(ByteBuffer buf,
int len) |
static long |
reallocateMemory(long addr,
long len)
Reallocates memory.
|
static void |
setMemory(long addr,
long len,
byte val)
Fills memory with given value.
|
static Object |
staticFieldBase(Field field)
Returns static field base.
|
static long |
staticFieldOffset(Field field)
Returns static field offset.
|
static ByteBuffer |
wrapPointer(long ptr,
int len)
Wraps pointer to unmanaged memory into direct byte buffer.
|
public static final ByteOrder NATIVE_BYTE_ORDER
public static final boolean BIG_ENDIAN
public static final int ADDR_SIZE
public static final long BYTE_ARR_OFF
public static final int BYTE_ARR_INT_OFF
public static final long SHORT_ARR_OFF
public static final long INT_ARR_OFF
public static final long LONG_ARR_OFF
public static final long FLOAT_ARR_OFF
public static final long DOUBLE_ARR_OFF
public static final long CHAR_ARR_OFF
public static final long BOOLEAN_ARR_OFF
public static ByteBuffer wrapPointer(long ptr, int len)
ptr - Pointer to wrap.len - Memory location length.public static ByteBuffer allocateBuffer(int len)
len - Length.public static void freeBuffer(ByteBuffer buf)
buf - Direct buffer allocated by allocateBuffer(int).public static ByteBuffer reallocateBuffer(ByteBuffer buf, int len)
buf - Buffer.len - New length.public static boolean getBooleanField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putBooleanField(Object obj, long fieldOff, boolean val)
obj - Object.fieldOff - Field offset.val - Value.public static byte getByteField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putByteField(Object obj, long fieldOff, byte val)
obj - Object.fieldOff - Field offset.val - Value.public static short getShortField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putShortField(Object obj, long fieldOff, short val)
obj - Object.fieldOff - Field offset.val - Value.public static char getCharField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putCharField(Object obj, long fieldOff, char val)
obj - Object.fieldOff - Field offset.val - Value.public static int getIntField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putIntField(Object obj, long fieldOff, int val)
obj - Object.fieldOff - Field offset.val - Value.public static long getLongField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putLongField(Object obj, long fieldOff, long val)
obj - Object.fieldOff - Field offset.val - Value.public static float getFloatField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putFloatField(Object obj, long fieldOff, float val)
obj - Object.fieldOff - Field offset.val - Value.public static double getDoubleField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putDoubleField(Object obj, long fieldOff, double val)
obj - Object.fieldOff - Field offset.val - Value.public static Object getObjectField(Object obj, long fieldOff)
obj - Object.fieldOff - Field offset.public static void putObjectField(Object obj, long fieldOff, Object val)
obj - Object.fieldOff - Field offset.val - Value.public static boolean getBoolean(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putBoolean(byte[] arr,
long off,
boolean val)
arr - Byte array.off - Offset.val - Value.public static byte getByte(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putByte(byte[] arr,
long off,
byte val)
arr - Byte array.off - Offset.val - Value.public static short getShort(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putShort(byte[] arr,
long off,
short val)
arr - Byte array.off - Offset.val - Value.public static char getChar(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putChar(byte[] arr,
long off,
char val)
arr - Byte array.off - Offset.val - Value.public static int getInt(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putInt(byte[] arr,
long off,
int val)
arr - Byte array.off - Offset.val - Value.public static long getLong(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putLong(byte[] arr,
long off,
long val)
arr - Byte array.off - Offset.val - Value.public static float getFloat(byte[] arr,
long off)
arr - Object.off - Offset.public static void putFloat(byte[] arr,
long off,
float val)
arr - Byte array.off - Offset.val - Value.public static double getDouble(byte[] arr,
long off)
arr - byte array.off - Offset.public static void putDouble(byte[] arr,
long off,
double val)
arr - Byte array.off - Offset.val - Value.public static short getShortLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putShortLE(byte[] arr,
long off,
short val)
arr - Byte array.off - Offset.val - Value.public static char getCharLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putCharLE(byte[] arr,
long off,
char val)
arr - Byte array.off - Offset.val - Value.public static int getIntLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putIntLE(byte[] arr,
long off,
int val)
arr - Byte array.off - Offset.val - Value.public static long getLongLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putLongLE(byte[] arr,
long off,
long val)
arr - Byte array.off - Offset.val - Value.public static float getFloatLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putFloatLE(byte[] arr,
long off,
float val)
arr - Byte array.off - Offset.val - Value.public static double getDoubleLE(byte[] arr,
long off)
arr - Byte array.off - Offset.public static void putDoubleLE(byte[] arr,
long off,
double val)
arr - Byte array.off - Offset.val - Value.public static byte getByte(long addr)
addr - Address.public static void putByte(long addr,
byte val)
addr - Address.val - Value.public static short getShort(long addr)
addr - Address.public static void putShort(long addr,
short val)
addr - Address.val - Value.public static char getChar(long addr)
addr - Address.public static void putChar(long addr,
char val)
addr - Address.val - Value.public static int getInt(long addr)
addr - Address.public static void putInt(long addr,
int val)
addr - Address.val - Value.public static long getLong(long addr)
addr - Address.public static void putLong(long addr,
long val)
addr - Address.val - Value.public static float getFloat(long addr)
addr - Address.public static void putFloat(long addr,
float val)
addr - Address.val - Value.public static double getDouble(long addr)
addr - Address.public static void putDouble(long addr,
double val)
addr - Address.val - Value.public static short getShortLE(long addr)
addr - Address.public static void putShortLE(long addr,
short val)
addr - Address.val - Value.public static char getCharLE(long addr)
addr - Address.public static void putCharLE(long addr,
char val)
addr - Address.val - Value.public static int getIntLE(long addr)
addr - Address.public static void putIntLE(long addr,
int val)
addr - Address.val - Value.public static long getLongLE(long addr)
addr - Address.public static void putLongLE(long addr,
long val)
addr - Address.val - Value.public static float getFloatLE(long addr)
addr - Address.public static void putFloatLE(long addr,
float val)
addr - Address.val - Value.public static double getDoubleLE(long addr)
addr - Address.public static void putDoubleLE(long addr,
double val)
addr - Address.val - Value.public static long staticFieldOffset(Field field)
field - Field.public static long objectFieldOffset(Field field)
field - Field.public static Object staticFieldBase(Field field)
field - Field.public static long allocateMemory(long size)
size - Size.public static long reallocateMemory(long addr,
long len)
addr - Address.len - Length.public static void setMemory(long addr,
long len,
byte val)
addr - Address.len - Length.val - Value.public static void copyOffheapOffheap(long srcAddr,
long dstAddr,
long len)
srcAddr - Source address.dstAddr - Destination address.len - Length.public static void copyOffheapHeap(long srcAddr,
Object dstBase,
long dstOff,
long len)
srcAddr - Source address.dstBase - Destination base.dstOff - Destination offset.len - Length.public static void copyHeapOffheap(Object srcBase, long srcOff, long dstAddr, long len)
srcBase - Source base.srcOff - Source offset.dstAddr - Destination address.len - Length.public static void copyMemory(long src,
long dst,
long len)
src - Source.dst - Dst.len - Length.public static void copyMemory(Object srcBase, long srcOff, Object dstBase, long dstOff, long len)
srcBase - Source base.srcOff - Source offset.dstBase - Dst base.dstOff - Dst offset.len - Length.public static void freeMemory(long addr)
addr - Address.public static int arrayBaseOffset(Class cls)
cls - Class.public static Object allocateInstance(Class cls) throws InstantiationException
cls - Class.InstantiationExceptionpublic static boolean compareAndSwapInt(Object obj, long off, int exp, int upd)
obj - Object.off - Offset.exp - Expected.upd - Upd.True if operation completed successfully, false - otherwise.public static boolean compareAndSwapLong(Object obj, long off, long exp, long upd)
obj - Object.off - Offset.exp - Expected.upd - Upd.True if operation completed successfully, false - otherwise.public static byte getByteVolatile(Object obj, long off)
obj - Object.off - Offset.public static void putByteVolatile(Object obj, long off, byte val)
obj - Object.off - Offset.val - Value.public static int getIntVolatile(Object obj, long off)
obj - Object.off - Offset.public static void putIntVolatile(Object obj, long off, int val)
obj - Object.off - Offset.val - Value.public static long getLongVolatile(Object obj, long off)
obj - Object.off - Offset.public static void putLongVolatile(Object obj, long off, long val)
obj - Object.off - Offset.val - Value.public static void putObjectVolatile(Object obj, long off, Object val)
obj - Object.off - Offset.val - Value.public static int pageSize()
public static long bufferAddress(ByteBuffer buf)
Buffer instance.buf - Buffer.public static Object invoke(Method mtd, Object... args)
sun.misc.Unsafe instance.mtd - Method.args - Arguments.public static void cleanDirectBuffer(ByteBuffer buf)
java.nio.ByteBufferbuf - Direct buffer.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.8.0 Release Date : February 27 2020