Package one.microstream.memory
Class XMemory
- java.lang.Object
 - 
- one.microstream.memory.XMemory
 
 
- 
public final class XMemory extends Object
Util class for low-level VM memory operations and information that makes the call site independent of a certain JVM implementation (e.g. java.misc.Unsafe). 
- 
- 
Constructor Summary
Constructors Constructor Description XMemory() 
- 
Method Summary
Modifier and Type Method Description static longallocate(long bytes)static ByteBufferallocateDirectNative(int capacity)Alias forByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder()).static ByteBufferallocateDirectNative(long capacity)static ByteBufferallocateDirectNativeDefault()static byte[]asByteArray(long value)static byte[]asByteArray(long[] longArray)static intbitSize_boolean()static intbitSize_byte()static intbitSize_char()static intbitSize_double()static intbitSize_float()static intbitSize_int()static intbitSize_long()static intbitSize_short()static intbyteSize_boolean()static intbyteSize_byte()static intbyteSize_char()static intbyteSize_double()static intbyteSize_float()static intbyteSize_int()static intbyteSize_long()static intbyteSize_short()static longbyteSizeArray_boolean(long elementCount)static longbyteSizeArray_byte(long elementCount)static longbyteSizeArray_char(long elementCount)static longbyteSizeArray_double(long elementCount)static longbyteSizeArray_float(long elementCount)static longbyteSizeArray_int(long elementCount)static longbyteSizeArray_long(long elementCount)static longbyteSizeArray_short(long elementCount)static longbyteSizeArrayObject(long elementCount)static intbyteSizeFieldValue(Class<?> type)static intbyteSizeFieldValue(Field field)static intbyteSizeInstance(Class<?> c)static intbyteSizeObjectHeader(Class<?> c)static intbyteSizePrimitive(Class<?> type)static intbyteSizeReference()static voidcopyArrayToAddress(boolean[] array, long targetAddress)static voidcopyArrayToAddress(byte[] array, long targetAddress)static voidcopyArrayToAddress(char[] array, long targetAddress)static voidcopyArrayToAddress(double[] array, long targetAddress)static voidcopyArrayToAddress(float[] array, long targetAddress)static voidcopyArrayToAddress(int[] array, long targetAddress)static voidcopyArrayToAddress(long[] array, long targetAddress)static voidcopyArrayToAddress(short[] array, long targetAddress)static voidcopyRange(long sourceAddress, long targetAddress, long length)static voidcopyRangeToArray(long sourceAddress, boolean[] target)static voidcopyRangeToArray(long sourceAddress, byte[] target)static voidcopyRangeToArray(long sourceAddress, char[] target)static voidcopyRangeToArray(long sourceAddress, double[] target)static voidcopyRangeToArray(long sourceAddress, float[] target)static voidcopyRangeToArray(long sourceAddress, int[] target)static voidcopyRangeToArray(long sourceAddress, long[] target)static voidcopyRangeToArray(long sourceAddress, short[] target)static booleandeallocateDirectByteBuffer(ByteBuffer directBuffer)static intdefaultBufferSize()Arbitrary value that coincidently matches most hardware's standard page sizes without being hard-tied to an actual pageSize system value.static voidensureClassInitialized(Class<?> c)static voidensureClassInitialized(Class<?> c, Iterable<Field> usedFields)static voidfillMemory(long address, long length, byte value)static voidfree(long address)static booleanget_boolean(long address)static booleanget_boolean(Object instance, long offset)static byteget_byte(long address)static byteget_byte(Object instance, long offset)static charget_char(long address)static charget_char(Object instance, long offset)static doubleget_double(long address)static doubleget_double(Object instance, long offset)static floatget_float(long address)static floatget_float(Object instance, long offset)static intget_int(long address)static intget_int(Object instance, long offset)static longget_long(long address)static longget_long(Object instance, long offset)static shortget_short(long address)static shortget_short(Object instance, long offset)static longgetDirectByteBufferAddress(ByteBuffer directBuffer)static ObjectgetObject(Object instance, long offset)static longgetPositionLimit(ByteBuffer buffer)static ByteBufferguaranteeDirectByteBuffer(ByteBuffer directBuffer)static voidguaranteeUsability()static <T> TinstantiateBlank(Class<T> c)static booleanisBigEndianNativeOrder()static booleanisDirectByteBuffer(ByteBuffer byteBuffer)static booleanisLittleEndianNativeOrder()static MemoryAccessormemoryAccessor()static MemoryAccessormemoryAccessorReversing()static MemorySizePropertiesmemorySizeProperties()static ByteOrdernativeByteOrder()static longobjectFieldOffset(Class<?> c, Field field)static longobjectFieldOffset(Field field)static long[]objectFieldOffsets(Class<?> c, Field[] fields)static long[]objectFieldOffsets(Field[] fields)static intpageSize()static ByteOrderparseByteOrder(String name)Parses aStringinstance to aByteOrderinstance according toByteOrder#toString()or throws anIllegalArgumentExceptionif the passed string does not match exactely one of theByteOrderconstant instances' string representation.static longreallocate(long address, long bytes)static voidset_boolean(long address, boolean value)static voidset_boolean(Object instance, long offset, boolean value)static voidset_booleanInBytes(byte[] bytes, int index, boolean value)static voidset_byte(long address, byte value)static voidset_byte(Object instance, long offset, byte value)static voidset_byteInBytes(byte[] bytes, int index, byte value)static voidset_char(long address, char value)static voidset_char(Object instance, long offset, char value)static voidset_charInBytes(byte[] bytes, int index, char value)static voidset_double(long address, double value)static voidset_double(Object instance, long offset, double value)static voidset_doubleInBytes(byte[] bytes, int index, double value)static voidset_float(long address, float value)static voidset_float(Object instance, long offset, float value)static voidset_floatInBytes(byte[] bytes, int index, float value)static voidset_int(long address, int value)static voidset_int(Object instance, long offset, int value)static voidset_intInBytes(byte[] bytes, int index, int value)static voidset_long(long address, long value)static voidset_long(Object instance, long offset, long value)static voidset_longInBytes(byte[] bytes, int index, long value)static voidset_short(long address, short value)static voidset_short(Object instance, long offset, short value)static voidset_shortInBytes(byte[] bytes, int index, short value)static voidsetMemoryAccessor(MemoryAccessor memoryAccessor)static <H extends MemoryAccessor & MemorySizeProperties>
voidsetMemoryHandling(H memoryHandler)static voidsetMemoryHandling(MemoryAccessor memoryAccessor, MemorySizeProperties memorySizeProperties)static voidsetObject(Object instance, long offset, Object value)static ByteBuffersetPositionLimit(ByteBuffer buffer, int position, int limit)static ByteBuffersetPositionLimit(ByteBuffer buffer, long positionLimit)static byte[]toArray(ByteBuffer source)static byte[]toArray(ByteBuffer source, int position, int length) 
 - 
 
- 
- 
Method Detail
- 
setMemoryHandling
public static final <H extends MemoryAccessor & MemorySizeProperties> void setMemoryHandling(H memoryHandler)
 
- 
setMemoryAccessor
public static final void setMemoryAccessor(MemoryAccessor memoryAccessor)
 
- 
setMemoryHandling
public static final void setMemoryHandling(MemoryAccessor memoryAccessor, MemorySizeProperties memorySizeProperties)
 
- 
memoryAccessor
public static final MemoryAccessor memoryAccessor()
 
- 
memoryAccessorReversing
public static final MemoryAccessor memoryAccessorReversing()
 
- 
memorySizeProperties
public static final MemorySizeProperties memorySizeProperties()
 
- 
guaranteeUsability
public static final void guaranteeUsability()
 
- 
getDirectByteBufferAddress
public static final long getDirectByteBufferAddress(ByteBuffer directBuffer)
 
- 
deallocateDirectByteBuffer
public static final boolean deallocateDirectByteBuffer(ByteBuffer directBuffer)
 
- 
isDirectByteBuffer
public static final boolean isDirectByteBuffer(ByteBuffer byteBuffer)
 
- 
guaranteeDirectByteBuffer
public static final ByteBuffer guaranteeDirectByteBuffer(ByteBuffer directBuffer)
 
- 
allocate
public static final long allocate(long bytes)
 
- 
reallocate
public static final long reallocate(long address, long bytes) 
- 
free
public static final void free(long address)
 
- 
fillMemory
public static final void fillMemory(long address, long length, byte value) 
- 
defaultBufferSize
public static final int defaultBufferSize()
Arbitrary value that coincidently matches most hardware's standard page sizes without being hard-tied to an actual pageSize system value. So this value is an educated guess and almost always a "good" value when paged-sized-ish buffer sizes are needed, while still not being at the mercy of an OS's JVM implementation.- Returns:
 - a "good" value for a paged-sized-ish default buffer size.
 
 
- 
pageSize
public static final int pageSize()
 
- 
byteSizeInstance
public static final int byteSizeInstance(Class<?> c)
 
- 
byteSizeObjectHeader
public static final int byteSizeObjectHeader(Class<?> c)
 
- 
byteSizeFieldValue
public static final int byteSizeFieldValue(Field field)
 
- 
byteSizeFieldValue
public static final int byteSizeFieldValue(Class<?> type)
 
- 
byteSizeArray_byte
public static final long byteSizeArray_byte(long elementCount)
 
- 
byteSizeArray_boolean
public static final long byteSizeArray_boolean(long elementCount)
 
- 
byteSizeArray_short
public static final long byteSizeArray_short(long elementCount)
 
- 
byteSizeArray_char
public static final long byteSizeArray_char(long elementCount)
 
- 
byteSizeArray_int
public static final long byteSizeArray_int(long elementCount)
 
- 
byteSizeArray_float
public static final long byteSizeArray_float(long elementCount)
 
- 
byteSizeArray_long
public static final long byteSizeArray_long(long elementCount)
 
- 
byteSizeArray_double
public static final long byteSizeArray_double(long elementCount)
 
- 
byteSizeArrayObject
public static final long byteSizeArrayObject(long elementCount)
 
- 
byteSizePrimitive
public static final int byteSizePrimitive(Class<?> type)
 
- 
bitSize_byte
public static final int bitSize_byte()
 
- 
byteSize_byte
public static final int byteSize_byte()
 
- 
byteSize_boolean
public static final int byteSize_boolean()
 
- 
byteSize_short
public static final int byteSize_short()
 
- 
byteSize_char
public static final int byteSize_char()
 
- 
byteSize_int
public static final int byteSize_int()
 
- 
byteSize_float
public static final int byteSize_float()
 
- 
byteSize_long
public static final int byteSize_long()
 
- 
byteSize_double
public static final int byteSize_double()
 
- 
byteSizeReference
public static final int byteSizeReference()
 
- 
bitSize_boolean
public static final int bitSize_boolean()
 
- 
bitSize_short
public static final int bitSize_short()
 
- 
bitSize_char
public static final int bitSize_char()
 
- 
bitSize_int
public static final int bitSize_int()
 
- 
bitSize_float
public static final int bitSize_float()
 
- 
bitSize_long
public static final int bitSize_long()
 
- 
bitSize_double
public static final int bitSize_double()
 
- 
objectFieldOffset
public static final long objectFieldOffset(Field field)
 
- 
objectFieldOffsets
public static final long[] objectFieldOffsets(Field[] fields)
 
- 
get_byte
public static final byte get_byte(long address)
 
- 
get_boolean
public static final boolean get_boolean(long address)
 
- 
get_short
public static final short get_short(long address)
 
- 
get_char
public static final char get_char(long address)
 
- 
get_int
public static final int get_int(long address)
 
- 
get_float
public static final float get_float(long address)
 
- 
get_long
public static final long get_long(long address)
 
- 
get_double
public static final double get_double(long address)
 
- 
get_byte
public static final byte get_byte(Object instance, long offset)
 
- 
get_boolean
public static final boolean get_boolean(Object instance, long offset)
 
- 
get_short
public static final short get_short(Object instance, long offset)
 
- 
get_char
public static final char get_char(Object instance, long offset)
 
- 
get_int
public static final int get_int(Object instance, long offset)
 
- 
get_float
public static final float get_float(Object instance, long offset)
 
- 
get_long
public static final long get_long(Object instance, long offset)
 
- 
get_double
public static final double get_double(Object instance, long offset)
 
- 
set_byte
public static final void set_byte(long address, byte value) 
- 
set_boolean
public static final void set_boolean(long address, boolean value) 
- 
set_short
public static final void set_short(long address, short value) 
- 
set_char
public static final void set_char(long address, char value) 
- 
set_int
public static final void set_int(long address, int value) 
- 
set_float
public static final void set_float(long address, float value) 
- 
set_long
public static final void set_long(long address, long value) 
- 
set_double
public static final void set_double(long address, double value) 
- 
set_byte
public static final void set_byte(Object instance, long offset, byte value)
 
- 
set_boolean
public static final void set_boolean(Object instance, long offset, boolean value)
 
- 
set_short
public static final void set_short(Object instance, long offset, short value)
 
- 
set_char
public static final void set_char(Object instance, long offset, char value)
 
- 
set_int
public static final void set_int(Object instance, long offset, int value)
 
- 
set_float
public static final void set_float(Object instance, long offset, float value)
 
- 
set_long
public static final void set_long(Object instance, long offset, long value)
 
- 
set_double
public static final void set_double(Object instance, long offset, double value)
 
- 
set_byteInBytes
public static final void set_byteInBytes(byte[] bytes, int index, byte value) 
- 
set_booleanInBytes
public static final void set_booleanInBytes(byte[] bytes, int index, boolean value) 
- 
set_shortInBytes
public static final void set_shortInBytes(byte[] bytes, int index, short value) 
- 
set_charInBytes
public static final void set_charInBytes(byte[] bytes, int index, char value) 
- 
set_intInBytes
public static final void set_intInBytes(byte[] bytes, int index, int value) 
- 
set_floatInBytes
public static final void set_floatInBytes(byte[] bytes, int index, float value) 
- 
set_longInBytes
public static final void set_longInBytes(byte[] bytes, int index, long value) 
- 
set_doubleInBytes
public static final void set_doubleInBytes(byte[] bytes, int index, double value) 
- 
copyRange
public static final void copyRange(long sourceAddress, long targetAddress, long length) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, byte[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, boolean[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, short[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, char[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, int[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, float[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, long[] target) 
- 
copyRangeToArray
public static final void copyRangeToArray(long sourceAddress, double[] target) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(byte[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(boolean[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(short[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(char[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(int[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(float[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(long[] array, long targetAddress) 
- 
copyArrayToAddress
public static final void copyArrayToAddress(double[] array, long targetAddress) 
- 
asByteArray
public static final byte[] asByteArray(long[] longArray)
 
- 
asByteArray
public static final byte[] asByteArray(long value)
 
- 
ensureClassInitialized
public static final void ensureClassInitialized(Class<?> c)
 
- 
ensureClassInitialized
public static final void ensureClassInitialized(Class<?> c, Iterable<Field> usedFields)
 
- 
instantiateBlank
public static final <T> T instantiateBlank(Class<T> c) throws InstantiationRuntimeException
- Throws:
 InstantiationRuntimeException
 
- 
nativeByteOrder
public static final ByteOrder nativeByteOrder()
 
- 
isBigEndianNativeOrder
public static final boolean isBigEndianNativeOrder()
 
- 
isLittleEndianNativeOrder
public static final boolean isLittleEndianNativeOrder()
 
- 
parseByteOrder
public static final ByteOrder parseByteOrder(String name)
Parses aStringinstance to aByteOrderinstance according toByteOrder#toString()or throws anIllegalArgumentExceptionif the passed string does not match exactely one of theByteOrderconstant instances' string representation.- Parameters:
 byteOrder- the string representing theByteOrderinstance to be parsed.- Returns:
 - the recognized 
ByteOrder - Throws:
 IllegalArgumentException- if the string can't be recognized as aByteOrderconstant instance.- See Also:
 ByteOrder.toString()
 
- 
allocateDirectNative
public static final ByteBuffer allocateDirectNative(int capacity) throws IllegalArgumentException
Alias forByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder()). SeeByteBuffer.allocateDirect(int)for details.- Parameters:
 capacity- The new buffer's capacity, in bytes- Returns:
 - a newly created direct byte buffer with the specified capacity and the platform's native byte order.
 - Throws:
 IllegalArgumentException- If thecapacityis a negative integer.- See Also:
 ByteBuffer.allocateDirect(int),ByteBuffer.order(ByteOrder)
 
- 
allocateDirectNative
public static final ByteBuffer allocateDirectNative(long capacity) throws IllegalArgumentException
- Throws:
 IllegalArgumentException
 
- 
allocateDirectNativeDefault
public static final ByteBuffer allocateDirectNativeDefault()
 
- 
toArray
public static final byte[] toArray(ByteBuffer source)
 
- 
toArray
public static final byte[] toArray(ByteBuffer source, int position, int length)
 
- 
getPositionLimit
public static final long getPositionLimit(ByteBuffer buffer)
 
- 
setPositionLimit
public static final ByteBuffer setPositionLimit(ByteBuffer buffer, long positionLimit)
 
- 
setPositionLimit
public static final ByteBuffer setPositionLimit(ByteBuffer buffer, int position, int limit)
 
 - 
 
 -