public class MemoryRegion extends Object implements Memory
If asserts are enabled in the JVM, the methods in this class perform bounds checking against the region's defined boundaries and then redirect the call to the parent Memory class. If the parent class is also a MemoryRegion it does a similar check and then calls its parent. The root of this hierarchy will be a NativeMemory class that ultimately performs the desired task. If asserts are not enabled the JIT compiler will eliminate all the asserts and the hierarchical calls should collapse to a call to the NativeMemory method.
Because asserts must be specifically enabled in the JVM, it is incumbent on the user of this class to make sure that their code is thoroughly tested. Violating memory bounds can cause memory segment faults, which takes down the JVM and can be very difficult to debug.
NativeMemory| Constructor and Description |
|---|
MemoryRegion(Memory memory,
long memOffsetBytes,
long capacityBytes)
Defines a region of the given parent Memory by defining an offset and capacity that are
within the boundaries of the parent.
|
MemoryRegion(Memory memory,
long memOffsetBytes,
long capacityBytes,
MemoryRequest memReq)
Defines a region of the given parent Memory by defining an offset and capacity that are
within the boundaries of the parent.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
array()
Returns the backing on-heap primitive array if there is one, otherwise returns null
|
Memory |
asReadOnlyMemory()
Returns a read-only version of this memory
|
ByteBuffer |
byteBuffer()
Returns the backing ByteBuffer if there is one, otherwise returns null
|
void |
clear()
Clears all bytes of this Memory to zero
|
void |
clear(long offsetBytes,
long lengthBytes)
Clears a portion of this Memory to zero.
|
void |
clearBits(long offsetBytes,
byte bitMask)
Clears the bits defined by the bitMask
|
void |
copy(long srcOffsetBytes,
long dstOffsetBytes,
long lengthBytes)
Copies bytes from a source region of this Memory to a destination region of this Memory.
|
void |
fill(byte value)
Fills all bytes of this Memory region to the given byte value.
|
void |
fill(long offsetBytes,
long lengthBytes,
byte value)
Fills a portion of this Memory region to the given byte value.
|
long |
getAddress(long offsetBytes)
Returns the start address of this Memory relative to its parent plus the given offsetBytes.
|
int |
getAndAddInt(long offsetBytes,
int delta)
Atomically adds the given value to the integer located at offsetBytes.
|
long |
getAndAddLong(long offsetBytes,
long delta)
Atomically adds the given value to the long located at offsetBytes.
|
int |
getAndSetInt(long offsetBytes,
int newValue)
Atomically exchanges the given value with the current value located at offsetBytes.
|
long |
getAndSetLong(long offsetBytes,
long newValue)
Atomically exchanges the given value with the current value located at offsetBytes.
|
boolean |
getBoolean(long offsetBytes)
Gets the boolean value at the given offset
|
void |
getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffset,
int length)
Gets the boolean array at the given offset
|
byte |
getByte(long offsetBytes)
Gets the byte at the given offset
|
void |
getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffset,
int length)
Gets the byte array at the given offset
|
long |
getCapacity()
Gets the capacity of this Memory in bytes
|
char |
getChar(long offsetBytes)
Gets the char at the given offset
|
void |
getCharArray(long offsetBytes,
char[] dstArray,
int dstOffset,
int length)
Gets the char array at the given offset
|
long |
getCumulativeOffset(long offsetBytes)
Returns the cumulative offset in bytes of this Memory from the base Memory including the given
offset.
|
double |
getDouble(long offsetBytes)
Gets the double at the given offset
|
void |
getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffset,
int length)
Gets the double array at the given offset
|
float |
getFloat(long offsetBytes)
Gets the float at the given offset
|
void |
getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffset,
int length)
Gets the float array at the given offset
|
int |
getInt(long offsetBytes)
Gets the int at the given offset
|
void |
getIntArray(long offsetBytes,
int[] dstArray,
int dstOffset,
int length)
Gets the int array at the given offset
|
long |
getLong(long offsetBytes)
Gets the long at the given offset
|
void |
getLongArray(long offsetBytes,
long[] dstArray,
int dstOffset,
int length)
Gets the long array at the given offset
|
MemoryRequest |
getMemoryRequest()
Returns a MemoryRequest or null
|
NativeMemory |
getNativeMemory()
Returns the root NativeMemory, which could also be the derived MemoryMappedFile or AllocMemory.
|
Object |
getParent()
Gets the parent Memory or backing array.
|
short |
getShort(long offsetBytes)
Gets the short at the given offset
|
void |
getShortArray(long offsetBytes,
short[] dstArray,
int dstOffset,
int length)
Gets the short array at the given offset
|
boolean |
hasArray()
Returns true if this Memory is backed by an on-heap primitive array
|
boolean |
hasByteBuffer()
Returns true if this Memory is backed by a ByteBuffer
|
boolean |
isAllBitsClear(long offsetBytes,
byte bitMask)
Returns true if all bits defined by the bitMask are clear
|
boolean |
isAllBitsSet(long offsetBytes,
byte bitMask)
Returns true if all bits defined by the bitMask are set
|
boolean |
isAllocated()
Returns true if this Memory has a capacity greater than zero
|
boolean |
isAnyBitsClear(long offsetBytes,
byte bitMask)
Returns true if any bits defined by the bitMask are clear
|
boolean |
isAnyBitsSet(long offsetBytes,
byte bitMask)
Returns true if any bits defined by the bitMask are set
|
boolean |
isDirect()
Returns true if the backing memory is direct (off-heap) memory.
|
boolean |
isReadOnly()
Returns true if this Memory is read only
|
void |
putBoolean(long offsetBytes,
boolean srcValue)
Puts the boolean value at the given offset
|
void |
putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffset,
int length)
Puts the boolean array at the given offset
|
void |
putByte(long offsetBytes,
byte srcValue)
Puts the byte value at the given offset
|
void |
putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffset,
int length)
Puts the byte array at the given offset
|
void |
putChar(long offsetBytes,
char srcValue)
Puts the char value at the given offset
|
void |
putCharArray(long offsetBytes,
char[] srcArray,
int srcOffset,
int length)
Puts the char array at the given offset
|
void |
putDouble(long offsetBytes,
double srcValue)
Puts the double value at the given offset
|
void |
putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffset,
int length)
Puts the double array at the given offset
|
void |
putFloat(long offsetBytes,
float srcValue)
Puts the float value at the given offset
|
void |
putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffset,
int length)
Puts the float array at the given offset
|
void |
putInt(long offsetBytes,
int srcValue)
Puts the int value at the given offset
|
void |
putIntArray(long offsetBytes,
int[] srcArray,
int srcOffset,
int length)
Puts the int array at the given offset
|
void |
putLong(long offsetBytes,
long srcValue)
Puts the long value at the given offset
|
void |
putLongArray(long offsetBytes,
long[] srcArray,
int srcOffset,
int length)
Puts the long array at the given offset
|
void |
putShort(long offsetBytes,
short srcValue)
Puts the short value at the given offset
|
void |
putShortArray(long offsetBytes,
short[] srcArray,
int srcOffset,
int length)
Puts the short array at the given offset
|
void |
reassign(long memOffsetBytes,
long capacityBytes)
Reassign the offset and capacity of this MemoryRegion
|
void |
setBits(long offsetBytes,
byte bitMask)
Sets the bits defined by the bitMask
|
void |
setMemoryRequest(MemoryRequest memReq)
Sets a MemoryRequest
|
String |
toHexString(String header,
long offsetBytes,
int lengthBytes)
Returns a formatted hex string of an area of this Memory.
|
public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes)
memory - the parent MemorymemOffsetBytes - the starting offset in bytes of this region with respect to the
start of the parent memory.capacityBytes - the capacity in bytes of this region.public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes, MemoryRequest memReq)
memory - the parent MemorymemOffsetBytes - the starting offset in bytes of this region with respect to the
start of the parent memory.capacityBytes - the capacity in bytes of this region.memReq - a MemoryRequest objectpublic void reassign(long memOffsetBytes,
long capacityBytes)
memOffsetBytes - the given offset from the parent's startcapacityBytes - the given capacity of this regionpublic void clear()
Memorypublic void clear(long offsetBytes,
long lengthBytes)
Memorypublic void clearBits(long offsetBytes,
byte bitMask)
Memorypublic void copy(long srcOffsetBytes,
long dstOffsetBytes,
long lengthBytes)
Memorypublic void fill(byte value)
Memorypublic void fill(long offsetBytes,
long lengthBytes,
byte value)
Memorypublic int getAndAddInt(long offsetBytes,
int delta)
MemorygetAndAddInt in interface MemoryoffsetBytes - offset bytes relative to this Memory startdelta - the amount to addpublic long getAndAddLong(long offsetBytes,
long delta)
MemorygetAndAddLong in interface MemoryoffsetBytes - offset bytes relative to this Memory startdelta - the amount to addpublic int getAndSetInt(long offsetBytes,
int newValue)
MemorygetAndSetInt in interface MemoryoffsetBytes - offset bytes relative to this Memory startnewValue - new valuepublic long getAndSetLong(long offsetBytes,
long newValue)
MemorygetAndSetLong in interface MemoryoffsetBytes - offset bytes relative to this Memory startnewValue - new valuepublic boolean getBoolean(long offsetBytes)
MemorygetBoolean in interface MemoryoffsetBytes - offset bytes relative to this Memory startpublic void getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffset,
int length)
MemorygetBooleanArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public byte getByte(long offsetBytes)
Memorypublic void getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffset,
int length)
MemorygetByteArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public char getChar(long offsetBytes)
Memorypublic void getCharArray(long offsetBytes,
char[] dstArray,
int dstOffset,
int length)
MemorygetCharArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public double getDouble(long offsetBytes)
Memorypublic void getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffset,
int length)
MemorygetDoubleArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public float getFloat(long offsetBytes)
Memorypublic void getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffset,
int length)
MemorygetFloatArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public int getInt(long offsetBytes)
Memorypublic void getIntArray(long offsetBytes,
int[] dstArray,
int dstOffset,
int length)
MemorygetIntArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public long getLong(long offsetBytes)
Memorypublic void getLongArray(long offsetBytes,
long[] dstArray,
int dstOffset,
int length)
MemorygetLongArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public short getShort(long offsetBytes)
Memorypublic void getShortArray(long offsetBytes,
short[] dstArray,
int dstOffset,
int length)
MemorygetShortArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public boolean isAllBitsClear(long offsetBytes,
byte bitMask)
MemoryisAllBitsClear in interface MemoryoffsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedpublic boolean isAllBitsSet(long offsetBytes,
byte bitMask)
MemoryisAllBitsSet in interface MemoryoffsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedpublic boolean isAnyBitsClear(long offsetBytes,
byte bitMask)
MemoryisAnyBitsClear in interface MemoryoffsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedpublic boolean isAnyBitsSet(long offsetBytes,
byte bitMask)
MemoryisAnyBitsSet in interface MemoryoffsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedpublic void putBoolean(long offsetBytes,
boolean srcValue)
MemoryputBoolean in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcValue - the value to putpublic void putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffset,
int length)
MemoryputBooleanArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putByte(long offsetBytes,
byte srcValue)
Memorypublic void putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffset,
int length)
MemoryputByteArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putChar(long offsetBytes,
char srcValue)
Memorypublic void putCharArray(long offsetBytes,
char[] srcArray,
int srcOffset,
int length)
MemoryputCharArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putDouble(long offsetBytes,
double srcValue)
Memorypublic void putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffset,
int length)
MemoryputDoubleArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putFloat(long offsetBytes,
float srcValue)
Memorypublic void putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffset,
int length)
MemoryputFloatArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putInt(long offsetBytes,
int srcValue)
Memorypublic void putIntArray(long offsetBytes,
int[] srcArray,
int srcOffset,
int length)
MemoryputIntArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putLong(long offsetBytes,
long srcValue)
Memorypublic void putLongArray(long offsetBytes,
long[] srcArray,
int srcOffset,
int length)
MemoryputLongArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void putShort(long offsetBytes,
short srcValue)
Memorypublic void putShortArray(long offsetBytes,
short[] srcArray,
int srcOffset,
int length)
MemoryputShortArray in interface MemoryoffsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.public void setBits(long offsetBytes,
byte bitMask)
Memorypublic Object array()
Memorypublic Memory asReadOnlyMemory()
MemoryasReadOnlyMemory in interface Memorypublic ByteBuffer byteBuffer()
MemorybyteBuffer in interface Memorypublic final long getAddress(long offsetBytes)
getAddress in interface MemoryoffsetBytes - the given offset in bytes from the start address of this Memory
relative to its parent.NativeMemory.getAddress(long)public long getCapacity()
MemorygetCapacity in interface Memorypublic long getCumulativeOffset(long offsetBytes)
MemorygetCumulativeOffset in interface MemoryoffsetBytes - the given offset in bytespublic MemoryRequest getMemoryRequest()
MemorygetMemoryRequest in interface Memorypublic NativeMemory getNativeMemory()
MemorygetNativeMemory in interface Memorypublic Object getParent()
Memorypublic boolean hasArray()
Memorypublic boolean hasByteBuffer()
MemoryhasByteBuffer in interface Memorypublic boolean isAllocated()
MemoryisAllocated in interface Memorypublic boolean isDirect()
Memorypublic boolean isReadOnly()
MemoryisReadOnly in interface Memorypublic void setMemoryRequest(MemoryRequest memReq)
MemorysetMemoryRequest in interface MemorymemReq - the MemoryRequestpublic String toHexString(String header, long offsetBytes, int lengthBytes)
MemorytoHexString in interface Memoryheader - decriptive headeroffsetBytes - offset bytes relative to this Memory startlengthBytes - number of bytes to convert to a hex stringCopyright © 2015–2016 Yahoo! Inc.. All rights reserved.