Package com.kenai.jffi
Class ObjectBuffer
- java.lang.Object
-
- com.kenai.jffi.ObjectBuffer
-
final class ObjectBuffer extends java.lang.Object
Holds objects the native code must handle - such as primitive arrays
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
ARRAY
(package private) static int
BOOLEAN
(package private) static int
BUFFER
(package private) static int
BYTE
(package private) static int
CHAR
static int
CLEAR
For OUT arrays, clear the temporary native memory area(package private) static int
DOUBLE
(package private) static int
FLAGS_MASK
(package private) static int
FLAGS_SHIFT
(package private) static int
FLOAT
static int
IN
Copy the array contents to native memory before calling the function(package private) static int
INDEX_MASK
(package private) static int
INDEX_SHIFT
private int[]
info
The flags/offset/length descriptor array.private int
infoIndex
The index of the next descriptor storage slot(package private) static int
INT
(package private) static int
JNI
static int
JNIENV
The JNIEnv addressstatic int
JNIOBJECT
The jobject handle(package private) static int
LONG
private int
objectIndex
The index of the next object storage slotprivate java.lang.Object[]
objects
The objects stored in this bufferstatic int
OUT
After calling the function, reload the array contents from native memorystatic int
PINNED
Pin the array memory and pass the JVM memory pointer directly to the function(package private) static int
PRIM_MASK
(package private) static int
SHORT
(package private) static int
TYPE_MASK
(package private) static int
TYPE_SHIFT
static int
ZERO_TERMINATE
Append a NUL byte to the array contents after copying to native memory
-
Constructor Summary
Constructors Constructor Description ObjectBuffer()
ObjectBuffer(int objectCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
ensureSpace()
Ensures that sufficient space is available to insert at least one more object(package private) int[]
info()
Gets the object descriptor array.(package private) static int
makeBufferFlags(int index)
Encodes the native object flags for an NIO Buffer.private static int
makeJNIFlags(int index, int type)
(package private) static int
makeObjectFlags(int ioflags, int type, int index)
Encodes the native object flags for an array.(package private) int
objectCount()
Gets the number of objects stored in thisObjectBuffer
.(package private) java.lang.Object[]
objects()
Gets the array of stored objects.void
putArray(int index, boolean[] array, int offset, int length, int flags)
Adds a java boolean array as a pointer parameter.void
putArray(int index, byte[] array, int offset, int length, int flags)
Adds a java byte array as a pointer parameter.void
putArray(int index, char[] array, int offset, int length, int flags)
Adds a java char array as a pointer parameter.void
putArray(int index, double[] array, int offset, int length, int flags)
Adds a java double array as a pointer parameter.void
putArray(int index, float[] array, int offset, int length, int flags)
Adds a java float array as a pointer parameter.void
putArray(int index, int[] array, int offset, int length, int flags)
Adds a java int array as a pointer parameter.void
putArray(int index, long[] array, int offset, int length, int flags)
Adds a java long array as a pointer parameter.void
putArray(int index, short[] array, int offset, int length, int flags)
Adds a java short array as a pointer parameter.void
putDirectBuffer(int index, java.nio.Buffer obj, int offset, int length)
Adds a java direct buffer as a pointer parameter.void
putJNI(int index, java.lang.Object obj, int type)
Put the address of the current JNIEnv into this parameter position(package private) void
putObject(java.lang.Object array, int offset, int length, int flags)
-
-
-
Field Detail
-
IN
@Native public static final int IN
Copy the array contents to native memory before calling the function- See Also:
- Constant Field Values
-
OUT
@Native public static final int OUT
After calling the function, reload the array contents from native memory- See Also:
- Constant Field Values
-
ZERO_TERMINATE
@Native public static final int ZERO_TERMINATE
Append a NUL byte to the array contents after copying to native memory- See Also:
- Constant Field Values
-
PINNED
@Native public static final int PINNED
Pin the array memory and pass the JVM memory pointer directly to the function- See Also:
- Constant Field Values
-
CLEAR
@Native public static final int CLEAR
For OUT arrays, clear the temporary native memory area- See Also:
- Constant Field Values
-
INDEX_SHIFT
@Native static final int INDEX_SHIFT
- See Also:
- Constant Field Values
-
INDEX_MASK
@Native static final int INDEX_MASK
- See Also:
- Constant Field Values
-
TYPE_SHIFT
@Native static final int TYPE_SHIFT
- See Also:
- Constant Field Values
-
TYPE_MASK
@Native static final int TYPE_MASK
- See Also:
- Constant Field Values
-
PRIM_MASK
@Native static final int PRIM_MASK
- See Also:
- Constant Field Values
-
FLAGS_SHIFT
@Native static final int FLAGS_SHIFT
- See Also:
- Constant Field Values
-
FLAGS_MASK
@Native static final int FLAGS_MASK
- See Also:
- Constant Field Values
-
ARRAY
@Native static final int ARRAY
- See Also:
- Constant Field Values
-
BUFFER
@Native static final int BUFFER
- See Also:
- Constant Field Values
-
JNI
@Native static final int JNI
- See Also:
- Constant Field Values
-
BYTE
@Native static final int BYTE
- See Also:
- Constant Field Values
-
SHORT
@Native static final int SHORT
- See Also:
- Constant Field Values
-
INT
@Native static final int INT
- See Also:
- Constant Field Values
-
LONG
@Native static final int LONG
- See Also:
- Constant Field Values
-
FLOAT
@Native static final int FLOAT
- See Also:
- Constant Field Values
-
DOUBLE
@Native static final int DOUBLE
- See Also:
- Constant Field Values
-
BOOLEAN
@Native static final int BOOLEAN
- See Also:
- Constant Field Values
-
CHAR
@Native static final int CHAR
- See Also:
- Constant Field Values
-
JNIENV
@Native public static final int JNIENV
The JNIEnv address- See Also:
- Constant Field Values
-
JNIOBJECT
@Native public static final int JNIOBJECT
The jobject handle- See Also:
- Constant Field Values
-
objects
private java.lang.Object[] objects
The objects stored in this buffer
-
info
private int[] info
The flags/offset/length descriptor array. Along with each object, a 3-tuple is stored in the descriptor array. The first element of the tuple stores a mask of the type, parameter index and array flags The second element stores the offset within the array the data starts. The third element stores the length of data.
-
infoIndex
private int infoIndex
The index of the next descriptor storage slot
-
objectIndex
private int objectIndex
The index of the next object storage slot
-
-
Method Detail
-
objectCount
final int objectCount()
Gets the number of objects stored in thisObjectBuffer
.- Returns:
- the number of objects already stored.
-
info
final int[] info()
Gets the object descriptor array.- Returns:
- An array of integers describing the objects stored.
-
objects
final java.lang.Object[] objects()
Gets the array of stored objects.- Returns:
- An array of objects stored in this buffer.
-
ensureSpace
private final void ensureSpace()
Ensures that sufficient space is available to insert at least one more object
-
makeObjectFlags
static final int makeObjectFlags(int ioflags, int type, int index)
Encodes the native object flags for an array.- Parameters:
ioflags
- The array flags (IN, OUT) for the object.type
- The type of the object.index
- The parameter index the object should be passed as.- Returns:
- A bitmask of flags.
-
makeBufferFlags
static final int makeBufferFlags(int index)
Encodes the native object flags for an NIO Buffer.- Parameters:
index
- The parameter index of the buffer.- Returns:
- A bitmask of flags.
-
makeJNIFlags
private static final int makeJNIFlags(int index, int type)
-
putArray
public void putArray(int index, byte[] array, int offset, int length, int flags)
Adds a java byte array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT, NULTERMINATE)
-
putArray
public void putArray(int index, short[] array, int offset, int length, int flags)
Adds a java short array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, int[] array, int offset, int length, int flags)
Adds a java int array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, long[] array, int offset, int length, int flags)
Adds a java long array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, float[] array, int offset, int length, int flags)
Adds a java float array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, double[] array, int offset, int length, int flags)
Adds a java double array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, boolean[] array, int offset, int length, int flags)
Adds a java boolean array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putArray
public void putArray(int index, char[] array, int offset, int length, int flags)
Adds a java char array as a pointer parameter.- Parameters:
array
- The java array to use as the pointer parameter.offset
- The offset from the start of the array.length
- The length of the array to use.flags
- The flags to use (IN, OUT)
-
putDirectBuffer
public void putDirectBuffer(int index, java.nio.Buffer obj, int offset, int length)
Adds a java direct buffer as a pointer parameter.- Parameters:
buffer
- The buffer to use as a pointer argument.offset
- An offset to add to the buffer native address.length
- The length of the buffer to use.
-
putJNI
public void putJNI(int index, java.lang.Object obj, int type)
Put the address of the current JNIEnv into this parameter position- Parameters:
index
- The index of the parameter.
-
putObject
void putObject(java.lang.Object array, int offset, int length, int flags)
-
-