public final class UnsafeOperations extends Object
Modifier and Type | Method and Description |
---|---|
<T> T |
allocateInstance(Class<T> clazz)
Construct and allocate on the heap an instant of the given class, without calling the class constructor
|
void |
copyPrimitiveAtOffset(Object source,
Object copy,
Class<?> type,
long offset)
Copies the primitive of the specified type from the given field offset in the source object
to the same location in the copy
|
void |
copyPrimitiveField(Object source,
Object copy,
Field field)
Copy the value from the given field from the source into the target.
|
<T> T |
deepCopy(T obj)
Performs a deep copy of the object.
|
<T> T |
deepCopy(T o,
IdentityHashMap<Object,Object> referencesToReuse)
Performs a deep copy of the object.
|
Object |
deepCopyArray(Object arrayOriginal,
IdentityHashMap<Object,Object> visited)
Performs a deep copy of the array.
|
void |
deepCopyArrayAtOffset(Object source,
Object copy,
Class<?> fieldClass,
long offset)
Copies the array of the specified type from the given field offset in the source object
to the same location in the copy, visiting the array during the copy so that its contents are also copied
|
void |
deepCopyArrayAtOffset(Object source,
Object copy,
Class<?> fieldClass,
long offset,
IdentityHashMap<Object,Object> referencesToReuse)
Copies the array of the specified type from the given field offset in the source object
to the same location in the copy, visiting the array during the copy so that its contents are also copied
|
void |
deepCopyArrayField(Object obj,
Object copy,
Field field)
Copies the array of the specified type from the given field in the source object
to the same field in the copy, visiting the array during the copy so that its contents are also copied
|
void |
deepCopyArrayField(Object obj,
Object copy,
Field field,
IdentityHashMap<Object,Object> referencesToReuse)
Copies the array of the specified type from the given field in the source object
to the same field in the copy, visiting the array during the copy so that its contents are also copied
|
void |
deepCopyObjectAtOffset(Object source,
Object copy,
Class<?> fieldClass,
long offset)
Copies the object of the specified type from the given field offset in the source object
to the same location in the copy, visiting the object during the copy so that its fields are also copied
|
void |
deepCopyObjectAtOffset(Object source,
Object copy,
Class<?> fieldClass,
long offset,
IdentityHashMap<Object,Object> referencesToReuse)
Copies the object of the specified type from the given field offset in the source object
to the same location in the copy, visiting the object during the copy so that its fields are also copied
|
void |
deepCopyObjectField(Object obj,
Object copy,
Field field)
Copies the object of the specified type from the given field in the source object
to the same field in the copy, visiting the object during the copy so that its fields are also copied
|
void |
deepCopyObjectField(Object source,
Object copy,
Field field,
IdentityHashMap<Object,Object> referencesToReuse)
Copies the object of the specified type from the given field in the source object
to the same field in the copy, visiting the object during the copy so that its fields are also copied
|
long |
deepSizeOf(Object o)
Determines the deep memory size of the given object (object or array), visiting all its references
|
Object |
fromAddress(long address)
Returns the object located at the given memory address
|
int |
getAddressSize()
Get the size in bytes of a native pointer - either 4 or 8 (for 32-bit or 64-bit JRE).
|
boolean |
getBoolean(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
byte |
getByte(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
char |
getChar(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
double |
getDouble(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
float |
getFloat(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
int |
getInt(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
long |
getLong(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
Object |
getObject(Object parent,
long offset)
Retrieve the object at the given offset of the supplied parent object
|
long |
getObjectFieldOffset(Field f)
Gets an offset for the given field relative to the field base.
|
short |
getShort(Object parent,
long offset)
Retrieve the value at the given offset of the supplied parent object
|
static UnsafeOperations |
getUnsafeOperations()
Returns the (singleton) UnsafeOperations instance
|
static boolean |
isUnsafeAvailable()
Check whether the Unsafe API is accessible
|
void |
putBoolean(Object parent,
long offset,
boolean value)
Puts the value at the given offset of the supplied parent object
|
void |
putByte(Object parent,
long offset,
byte value)
Puts the value at the given offset of the supplied parent object
|
void |
putChar(Object parent,
long offset,
char value)
Puts the value at the given offset of the supplied parent object
|
void |
putDefaultBoolean(Object parent,
long offset)
Resets to false the boolean value at the given offset of the supplied parent object
|
void |
putDefaultByte(Object parent,
long offset)
Resets to 0 the byte value at the given offset of the supplied parent object
|
void |
putDefaultChar(Object parent,
long offset)
Resets to u0000 the char value at the given offset of the supplied parent object
|
void |
putDefaultDouble(Object parent,
long offset)
Resets to 0.0d the double value at the given offset of the supplied parent object
|
void |
putDefaultFloat(Object parent,
long offset)
Resets to 0.0f the float value at the given offset of the supplied parent object
|
void |
putDefaultInt(Object parent,
long offset)
Resets to 0 the int value at the given offset of the supplied parent object
|
void |
putDefaultLong(Object parent,
long offset)
Resets to 0 the long value at the given offset of the supplied parent object
|
void |
putDefaultShort(Object parent,
long offset)
Resets to 0 the short value at the given offset of the supplied parent object
|
void |
putDouble(Object parent,
long offset,
double value)
Puts the value at the given offset of the supplied parent object
|
void |
putFloat(Object parent,
long offset,
float value)
Puts the value at the given offset of the supplied parent object
|
void |
putInt(Object parent,
long offset,
int value)
Puts the value at the given offset of the supplied parent object
|
void |
putLong(Object parent,
long offset,
long value)
Puts the value at the given offset of the supplied parent object
|
void |
putNullObject(Object parent,
long offset)
Write a null value to the given offset of the supplied parent object
|
void |
putObject(Object parent,
long offset,
Object value)
Puts the object's reference at the given offset of the supplied parent object
|
void |
putPrimitiveDefaultAtOffset(Object copy,
Class<?> type,
long offset)
Restores the primitive at the given field to its default value.
|
void |
putShort(Object parent,
long offset,
short value)
Puts the value at the given offset of the supplied parent object
|
<T> T |
shallowCopy(T obj)
Performs a shallow copy of the given object - a new instance is allocated with the same contents.
|
long |
shallowSizeOf(Class<?> clazz)
Determines the shallow memory size of an instance of the given class
|
long |
shallowSizeOf(Object obj)
Determines the shallow memory size of the given object (object or array)
|
long |
toAddress(Object obj)
Convert the object reference to a memory address represented as a signed long
|
public static final UnsafeOperations getUnsafeOperations()
public static boolean isUnsafeAvailable()
public final <T> T allocateInstance(Class<T> clazz) throws IllegalStateException
T
- Type of the instance to be constructedclazz
- Class to create instant forIllegalStateException
- Indicates a problem occurredpublic final long getObjectFieldOffset(Field f)
f
- The Field to determine the offset forpublic final <T> T shallowCopy(T obj)
T
- The type being copiedobj
- Object to copypublic final long toAddress(Object obj)
obj
- The objectpublic final Object fromAddress(long address)
address
- The address (a signed long) for the objectpublic final void copyPrimitiveField(Object source, Object copy, Field field)
source
- The object to copy fromcopy
- The target objectfield
- Field to be copiedpublic final void copyPrimitiveAtOffset(Object source, Object copy, Class<?> type, long offset)
source
- The object to copy fromcopy
- The target objecttype
- The type of primitive at the given offset - e.g. java.lang.Boolean.TYPEoffset
- The offset to copy frompublic final void putPrimitiveDefaultAtOffset(Object copy, Class<?> type, long offset)
copy
- The target objecttype
- The type of primitive at the given offset - e.g. java.lang.Boolean.TYPEoffset
- The offset to reset to its default valuepublic <T> T deepCopy(T obj)
T
- The type being copiedobj
- The object to perform a deep copy for.public <T> T deepCopy(T o, IdentityHashMap<Object,Object> referencesToReuse)
T
- The type being copiedo
- The object to perform a deep copy for.referencesToReuse
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final void deepCopyObjectAtOffset(Object source, Object copy, Class<?> fieldClass, long offset)
source
- The object to copy fromcopy
- The target objectfieldClass
- The declared type of object at the given offsetoffset
- The offset to copy frompublic final void deepCopyObjectAtOffset(Object source, Object copy, Class<?> fieldClass, long offset, IdentityHashMap<Object,Object> referencesToReuse)
source
- The object to copy fromcopy
- The target objectfieldClass
- The declared type of object at the given offsetoffset
- The offset to copy fromreferencesToReuse
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final void deepCopyObjectField(Object source, Object copy, Field field, IdentityHashMap<Object,Object> referencesToReuse)
source
- The object to copy fromcopy
- The target objectfield
- Field to be copiedreferencesToReuse
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final void deepCopyObjectField(Object obj, Object copy, Field field)
obj
- The object to copy fromcopy
- The target objectfield
- Field to be copiedpublic final void deepCopyArrayAtOffset(Object source, Object copy, Class<?> fieldClass, long offset)
source
- The object to copy fromcopy
- The target objectfieldClass
- The declared type of array at the given offsetoffset
- The offset to copy frompublic final void deepCopyArrayAtOffset(Object source, Object copy, Class<?> fieldClass, long offset, IdentityHashMap<Object,Object> referencesToReuse)
source
- The object to copy fromcopy
- The target objectfieldClass
- The declared type of array at the given offsetoffset
- The offset to copy fromreferencesToReuse
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final void deepCopyArrayField(Object obj, Object copy, Field field, IdentityHashMap<Object,Object> referencesToReuse)
obj
- The object to copy fromcopy
- The target objectfield
- Field to be copiedreferencesToReuse
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final void deepCopyArrayField(Object obj, Object copy, Field field)
obj
- The object to copy fromcopy
- The target objectfield
- Field to be copiedpublic final Object deepCopyArray(Object arrayOriginal, IdentityHashMap<Object,Object> visited)
arrayOriginal
- The array to perform a deep copy for.visited
- An identity map of references to reuse - this is further populated as the copy progresses.
The key is the original object reference - the value is the copied instance for that original.public final long shallowSizeOf(Class<?> clazz)
clazz
- The class to calculate the shallow size forpublic final long shallowSizeOf(Object obj)
obj
- The object instance to calculate the shallow size forpublic final long deepSizeOf(Object o)
o
- The object instance to calculate the deep size forpublic final int getAddressSize()
public final Object getObject(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final boolean getBoolean(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final char getChar(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final short getShort(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final int getInt(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final long getLong(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final float getFloat(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final double getDouble(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final byte getByte(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putNullObject(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultBoolean(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultChar(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultShort(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultInt(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultLong(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultFloat(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultDouble(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putDefaultByte(Object parent, long offset)
parent
- The Object's parentoffset
- The offsetpublic final void putObject(Object parent, long offset, Object value)
parent
- The Object's parentoffset
- The offsetvalue
- Object to be putpublic final void putBoolean(Object parent, long offset, boolean value)
parent
- The Object's parentoffset
- The offsetvalue
- boolean to be putpublic final void putChar(Object parent, long offset, char value)
parent
- The Object's parentoffset
- The offsetvalue
- char to be putpublic final void putShort(Object parent, long offset, short value)
parent
- The Object's parentoffset
- The offsetvalue
- short to be putpublic final void putInt(Object parent, long offset, int value)
parent
- The Object's parentoffset
- The offsetvalue
- int to be putpublic final void putLong(Object parent, long offset, long value)
parent
- The Object's parentoffset
- The offsetvalue
- long to be putpublic final void putFloat(Object parent, long offset, float value)
parent
- The Object's parentoffset
- The offsetvalue
- float to be putpublic final void putDouble(Object parent, long offset, double value)
parent
- The Object's parentoffset
- The offsetvalue
- double to be putCopyright © 2010–2018 Jadira Systems. All rights reserved.