public final class UnsafeUtil extends Object
assertHasUnsafe() method, before
calling any of the other methods.
Avoid `import static` for these individual methods. Always qualify method usages with `UnsafeUtil` so use sites
show up in code greps.| Modifier and Type | Field and Description |
|---|---|
static boolean |
allowUnalignedMemoryAccess |
static boolean |
storeByteOrderIsNative |
| Constructor and Description |
|---|
UnsafeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int |
arrayBaseOffset(Class klass) |
static int |
arrayIndexScale(Class klass) |
static int |
arrayOffset(int index,
int base,
int scale) |
static void |
assertHasUnsafe() |
static boolean |
compareAndSwapLong(Object obj,
long offset,
long expected,
long update)
Atomically compare the current value of the given long field with the expected value, and if they are the
equal, set the field to the updated value and return true.
|
static boolean |
compareAndSwapObject(Object obj,
long offset,
Object expected,
Object update)
Same as compareAndSwapLong, but for object references.
|
static void |
free(long pointer)
Free the memory that was allocated with
malloc(long). |
static int |
getAndAddInt(Object obj,
long offset,
int delta)
Atomically add the given delta to the int field, and return its previous value.
|
static Object |
getAndSetObject(Object obj,
long offset,
Object newValue)
Same as getAndAddInt, but for object references.
|
static byte |
getByte(long address) |
static byte |
getByteVolatile(Object obj,
long offset) |
static long |
getFieldOffset(Class<?> type,
String field)
Get the object-relative field offset.
|
static int |
getInt(long address) |
static int |
getIntVolatile(Object obj,
long offset) |
static long |
getLong(long address) |
static long |
getLongVolatile(Object obj,
long offset) |
static Object |
getObjectVolatile(Object obj,
long offset) |
static short |
getShort(long address) |
static long |
malloc(long sizeInBytes)
Allocate a slab of memory of the given size in bytes, and return a pointer to that memory.
|
static ByteBuffer |
newDirectByteBuffer(long addr,
int cap)
Create a new DirectByteBuffer that wraps the given address and has the given capacity.
|
static void |
putByte(long address,
byte value) |
static void |
putByteVolatile(Object obj,
long offset,
byte value) |
static void |
putInt(long address,
int value) |
static void |
putLong(long address,
long value) |
static void |
putLong(Object obj,
long offset,
long value) |
static void |
putObjectVolatile(Object obj,
long offset,
Object value) |
static void |
putShort(long address,
short value) |
static void |
setMemory(long address,
long bytes,
byte value)
Set the given number of bytes to the given value, starting from the given address.
|
public static final boolean allowUnalignedMemoryAccess
public static final boolean storeByteOrderIsNative
public static void assertHasUnsafe()
LinkageError - if the Unsafe tools are not available on in this JVM.public static long getFieldOffset(Class<?> type, String field)
public static int getAndAddInt(Object obj, long offset, int delta)
public static boolean compareAndSwapLong(Object obj, long offset, long expected, long update)
public static boolean compareAndSwapObject(Object obj, long offset, Object expected, Object update)
public static Object getAndSetObject(Object obj, long offset, Object newValue)
public static long malloc(long sizeInBytes)
public static void free(long pointer)
malloc(long).public static byte getByte(long address)
public static void putByte(long address,
byte value)
public static byte getByteVolatile(Object obj, long offset)
public static void putByteVolatile(Object obj, long offset, byte value)
public static long getLong(long address)
public static void putLong(long address,
long value)
public static int getInt(long address)
public static void putInt(long address,
int value)
public static short getShort(long address)
public static void putShort(long address,
short value)
public static void putLong(Object obj, long offset, long value)
public static long getLongVolatile(Object obj, long offset)
public static int getIntVolatile(Object obj, long offset)
public static int arrayBaseOffset(Class klass)
public static int arrayIndexScale(Class klass)
public static int arrayOffset(int index,
int base,
int scale)
public static void setMemory(long address,
long bytes,
byte value)
public static ByteBuffer newDirectByteBuffer(long addr, int cap) throws Exception
ExceptionCopyright © 2002–2015 The Neo4j Graph Database Project. All rights reserved.