public abstract class MemoryIO
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
MemoryIO.CheckedMemorySingletonHolder |
private static class |
MemoryIO.CheckedNativeImpl |
private static class |
MemoryIO.NativeImpl
An implementation of MemoryIO using JNI methods.
|
private static class |
MemoryIO.NativeImpl32
A 32 bit optimized implementation of MemoryIO using JNI.
|
private static class |
MemoryIO.NativeImpl64
A 64 bit optimized implementation of MemoryIO using JNI.
|
private static class |
MemoryIO.SingletonHolder
Holds a single instance of MemoryIO
|
private static class |
MemoryIO.UnsafeImpl
An implementation of MemoryIO using sun.misc.Unsafe
|
private static class |
MemoryIO.UnsafeImpl32
A 32 bit optimized implementation of MemoryIO using sun.misc.Unsafe
|
private static class |
MemoryIO.UnsafeImpl64
A 64 bit optimized implementation of MemoryIO using sun.misc.Unsafe
|
Modifier and Type | Field and Description |
---|---|
private static long |
ADDRESS_MASK
The address mask used to truncate 32bit addresses contained in long values
|
(package private) Foreign |
foreign
A handle to the JNI accessor
|
Modifier | Constructor and Description |
---|---|
private |
MemoryIO() |
Modifier and Type | Method and Description |
---|---|
(package private) abstract void |
_copyMemory(long src,
long dst,
long size)
Copies contents of a native memory location to another native memory location.
|
long |
allocateMemory(long size,
boolean clear)
Allocates native memory.
|
void |
copyMemory(long src,
long dst,
long size)
Copies contents of a native memory location to another native memory location.
|
void |
freeMemory(long address)
Releases memory allocated via
allocateMemory(long, boolean) back to the system. |
abstract long |
getAddress(long address)
Reads a native memory address from a native memory location.
|
abstract byte |
getByte(long address)
Reads an 8 bit integer from a native memory location.
|
abstract void |
getByteArray(long address,
byte[] data,
int offset,
int length)
Reads a java byte array from native memory.
|
abstract void |
getCharArray(long address,
char[] data,
int offset,
int length)
Reads a java char array from native memory.
|
static MemoryIO |
getCheckedInstance() |
long |
getDirectBufferAddress(java.nio.Buffer buffer)
Gets the native memory address of a direct ByteBuffer
|
abstract double |
getDouble(long address)
Reads a 64 bit floating point value from a native memory location.
|
abstract void |
getDoubleArray(long address,
double[] data,
int offset,
int length)
Reads a java double array from native memory.
|
abstract float |
getFloat(long address)
Reads a 32 bit floating point value from a native memory location.
|
abstract void |
getFloatArray(long address,
float[] data,
int offset,
int length)
Reads a java float array from native memory.
|
static MemoryIO |
getInstance()
Gets an instance of MemoryIO that can be used to access native memory.
|
abstract int |
getInt(long address)
Reads a 32 bit integer from a native memory location.
|
abstract void |
getIntArray(long address,
int[] data,
int offset,
int length)
Reads a java int array from native memory.
|
abstract long |
getLong(long address)
Reads a 64 bit integer from a native memory location.
|
abstract void |
getLongArray(long address,
long[] data,
int offset,
int length)
Reads a java long array from native memory.
|
abstract short |
getShort(long address)
Reads a 16 bit integer from a native memory location.
|
abstract void |
getShortArray(long address,
short[] data,
int offset,
int length)
Reads a java short array from native memory.
|
abstract long |
getStringLength(long address)
Gets the length of a native ascii or utf-8 string.
|
abstract byte[] |
getZeroTerminatedByteArray(long address)
Reads a byte array from native memory, stopping when a zero byte is found.
|
abstract byte[] |
getZeroTerminatedByteArray(long address,
int maxlen)
Reads a byte array from native memory, stopping when a zero byte is found,
or the maximum length is reached.
|
byte[] |
getZeroTerminatedByteArray(long address,
long maxlen)
Deprecated.
|
long |
indexOf(long address,
byte value)
Finds the location of a byte value in a native memory region.
|
long |
indexOf(long address,
byte value,
int maxlen)
Finds the location of a byte value in a native memory region.
|
(package private) static boolean |
isUnsafeAvailable()
Determines the best Unsafe implementation to use.
|
abstract long |
memchr(long address,
int value,
long size)
Gets the address of a byte value in a native memory region.
|
abstract void |
memcpy(long dst,
long src,
long size)
Copies bytes from one memory location to another.
|
abstract void |
memmove(long dst,
long src,
long size)
Copies potentially overlapping memory areas.
|
void |
memset(long address,
int value,
long size)
Sets a region of native memory to a specific byte value.
|
java.nio.ByteBuffer |
newDirectByteBuffer(long address,
int capacity)
Creates a new Direct ByteBuffer for a native memory region.
|
private static MemoryIO |
newMemoryIO()
Creates a new instance of MemoryIO optimized for the current platform.
|
private static MemoryIO |
newNativeCheckedImpl() |
private static MemoryIO |
newNativeImpl() |
private static MemoryIO |
newNativeImpl32()
Creates a new JNI implementation of MemoryIO optimized for 32 bit platforms
|
private static MemoryIO |
newNativeImpl64()
Creates a new JNI implementation of MemoryIO optimized for 64 bit platforms
|
private static MemoryIO |
newUnsafeImpl()
Creates a new sun.misc.Unsafe implementation of MemoryIO
|
private static MemoryIO |
newUnsafeImpl32()
Creates a new sun.misc.Unsafe implementation of MemoryIO optimized for 32 bit platforms
|
private static MemoryIO |
newUnsafeImpl64()
Creates a new sun.misc.Unsafe implementation of MemoryIO optimized for 64 bit platforms
|
abstract void |
putAddress(long address,
long value)
Writes a native memory address value to a native memory location.
|
abstract void |
putByte(long address,
byte value)
Writes an 8 bit integer value to a native memory location.
|
abstract void |
putByteArray(long address,
byte[] data,
int offset,
int length)
Writes a java byte array to native memory.
|
abstract void |
putCharArray(long address,
char[] data,
int offset,
int length)
Writes a java char array to native memory.
|
abstract void |
putDouble(long address,
double value)
Writes a 64 bit floating point value to a native memory location.
|
abstract void |
putDoubleArray(long address,
double[] data,
int offset,
int length)
Writes a java double array to native memory.
|
abstract void |
putFloat(long address,
float value)
Writes a 32 bit floating point value to a native memory location.
|
abstract void |
putFloatArray(long address,
float[] data,
int offset,
int length)
Writes a java double array to native memory.
|
abstract void |
putInt(long address,
int value)
Writes a 32 bit integer value to a native memory location.
|
abstract void |
putIntArray(long address,
int[] data,
int offset,
int length)
Writes a java int array to native memory.
|
abstract void |
putLong(long address,
long value)
Writes a 64 bit integer value to a native memory location.
|
abstract void |
putLongArray(long address,
long[] data,
int offset,
int length)
Writes a java long array to native memory.
|
abstract void |
putShort(long address,
short value)
Writes a 16 bit integer value to a native memory location.
|
abstract void |
putShortArray(long address,
short[] data,
int offset,
int length)
Writes a java short array to native memory.
|
abstract void |
putZeroTerminatedByteArray(long address,
byte[] data,
int offset,
int length)
Copies a java byte array to native memory and appends a NUL terminating byte.
|
abstract void |
setMemory(long address,
long size,
byte value)
Sets a region of native memory to a specific byte value.
|
private static void |
verifyAccessor(java.lang.Class unsafeClass,
java.lang.Class primitive)
Verifies that there is are accessor functions (get,put) for a particular
primitive type in the sun.misc.Unsafe class.
|
final Foreign foreign
private static final long ADDRESS_MASK
public static MemoryIO getInstance()
public static MemoryIO getCheckedInstance()
private static MemoryIO newMemoryIO()
private static MemoryIO newNativeImpl()
private static MemoryIO newNativeCheckedImpl()
private static MemoryIO newNativeImpl32()
private static MemoryIO newNativeImpl64()
private static MemoryIO newUnsafeImpl()
private static MemoryIO newUnsafeImpl32()
private static MemoryIO newUnsafeImpl64()
public abstract byte getByte(long address)
address
- The memory location to get the value from.public abstract short getShort(long address)
address
- The memory location to get the value from.public abstract int getInt(long address)
address
- The memory location to get the value from.public abstract long getLong(long address)
address
- The memory location to get the value from.public abstract float getFloat(long address)
address
- The memory location to get the value from.public abstract double getDouble(long address)
address
- The memory location to get the value from.public abstract long getAddress(long address)
address
- The memory location to get the value from.public abstract void putByte(long address, byte value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putShort(long address, short value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putInt(long address, int value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putLong(long address, long value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putFloat(long address, float value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putDouble(long address, double value)
address
- The memory location to put the value.value
- The value to write to memory.public abstract void putAddress(long address, long value)
address
- The memory location to put the value.value
- The value to write to memory.public final void copyMemory(long src, long dst, long size)
src
- The source memory address.dst
- The destination memory address.size
- The number of bytes to copy.abstract void _copyMemory(long src, long dst, long size)
src
- The source memory address.dst
- The destination memory address.size
- The number of bytes to copy.public abstract void setMemory(long address, long size, byte value)
address
- The address of start of the native memory.size
- The number of bytes to set.value
- The value to set the native memory to.public abstract void memcpy(long dst, long src, long size)
dst
- The destination memory address.src
- The source memory address.size
- The number of bytes to copy.public abstract void memmove(long dst, long src, long size)
dst
- The destination memory address.src
- The source memory address.size
- The number of bytes to copy.public final void memset(long address, int value, long size)
address
- The address of start of the native memory.value
- The value to set the native memory to.size
- The number of bytes to set.public abstract long memchr(long address, int value, long size)
address
- The native memory address to start searching.value
- The value to search for.size
- The size of the native memory region being searched.public abstract void putByteArray(long address, byte[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getByteArray(long address, byte[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putCharArray(long address, char[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getCharArray(long address, char[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putShortArray(long address, short[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getShortArray(long address, short[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putIntArray(long address, int[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getIntArray(long address, int[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putLongArray(long address, long[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getLongArray(long address, long[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putFloatArray(long address, float[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getFloatArray(long address, float[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public abstract void putDoubleArray(long address, double[] data, int offset, int length)
address
- The native memory address to copy the array to.data
- The java array to copy.offset
- The offset within the array to start copying from.length
- The number of array elements to copy.public abstract void getDoubleArray(long address, double[] data, int offset, int length)
address
- The native memory address to copy the array from.data
- The java array to copy.offset
- The offset within the array to start copying to.length
- The number of array elements to copy.public final long allocateMemory(long size, boolean clear)
size
- The number of bytes of memory to allocateclear
- Whether the memory should be cleared (each byte set to zero).public final void freeMemory(long address)
allocateMemory(long, boolean)
back to the system.address
- The address of the memory to release.public abstract long getStringLength(long address)
address
- The native address of the string.public abstract byte[] getZeroTerminatedByteArray(long address)
address
- The address to read the data from.public abstract byte[] getZeroTerminatedByteArray(long address, int maxlen)
address
- The address to read the data from.maxlen
- The limit of the memory area to scan for a zero byte.@Deprecated public final byte[] getZeroTerminatedByteArray(long address, long maxlen)
public abstract void putZeroTerminatedByteArray(long address, byte[] data, int offset, int length)
address
- The address to copy to.data
- The byte array to copy to native memoryoffset
- The offset within the byte array to begin copying fromlength
- The number of bytes to copy to native memorypublic final long indexOf(long address, byte value)
address
- The native memory address to start searching from.value
- The value to search for.public final long indexOf(long address, byte value, int maxlen)
address
- The native memory address to start searching from.value
- The value to search for.maxlen
- The maximum number of bytes to search.public final java.nio.ByteBuffer newDirectByteBuffer(long address, int capacity)
address
- The start of the native memory region.capacity
- The size of the native memory region.public final long getDirectBufferAddress(java.nio.Buffer buffer)
buffer
- A direct ByteBuffer to get the address of.private static void verifyAccessor(java.lang.Class unsafeClass, java.lang.Class primitive) throws java.lang.NoSuchMethodException
unsafeClass
- The class of sun.misc.Unsafeprimitive
- The class of the primitive type.java.lang.NoSuchMethodException
- If no accessors for that primitive type exist.static boolean isUnsafeAvailable()