Top Description Fields Constructors Methods
org.lwjgl.system.jni

public Class JNINativeInterface

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.*, org.lwjgl.system.*, java.lang.reflect.*

Bindings to the Java Native Interface (JNI).

The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.

The most important benefit of the JNI is that it imposes no restrictions on the implementation of the underlying Java VM. Therefore, Java VM vendors can add support for the JNI without affecting other parts of the VM. Programmers can write one version of a native application or library and expect it to work with all Java VMs supporting the JNI.

LWJGL: Only functions that can reasonably be called from Java are exposed.

Field Summary

Modifier and TypeField and Description
public static final int
JNI_ABORT

Used in ReleaseScalarArrayElements.

public static final int
JNI_COMMIT

Used in ReleaseScalarArrayElements.

public static final int
JNI_EDETACHED

Possible return values for JNI functions.

public static final int
JNI_EEXIST

Possible return values for JNI functions.

public static final int
JNI_EINVAL

Possible return values for JNI functions.

public static final int
JNI_ENOMEM

Possible return values for JNI functions.

public static final int
JNI_ERR

Possible return values for JNI functions.

public static final int
JNI_EVERSION

Possible return values for JNI functions.

public static final int
JNI_FALSE

jboolean constants.

public static final int
JNI_OK

Possible return values for JNI functions.

public static final int
JNI_TRUE

jboolean constants.

public static final int
JNI_VERSION_10

JNI versions.

public static final int
JNI_VERSION_19

JNI versions.

public static final int
JNI_VERSION_1_1

JNI versions.

public static final int
JNI_VERSION_1_2

JNI versions.

public static final int
JNI_VERSION_1_4

JNI versions.

public static final int
JNI_VERSION_1_6

JNI versions.

public static final int
JNI_VERSION_1_8

JNI versions.

public static final int
JNI_VERSION_20

JNI versions.

public static final int
JNI_VERSION_21

JNI versions.

public static final int
JNI_VERSION_9

JNI versions.

public static final int
JNIGlobalRefType

jobjectRefType: Return values from GetObjectRefType.

public static final int
JNIInvalidRefType

jobjectRefType: Return values from GetObjectRefType.

public static final int
JNILocalRefType

jobjectRefType: Return values from GetObjectRefType.

public static final int
JNIWeakGlobalRefType

jobjectRefType: Return values from GetObjectRefType.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static void
DeleteGlobalRef(long
a global reference
globalRef
)

Deletes the global reference pointed to by globalRef.

public static void
DeleteWeakGlobalRef(long weakGlobalRef)

Delete the VM resources needed for the given weak global reference.

public static native long
FromReflectedField(Field field)

Converts a Field to a field ID.

public static native long
FromReflectedMethod(Method method)

Converts a Method or Constructor object to a method ID.

public static ByteBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetBooleanArrayElements
(byte[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetBooleanArrayRegion(byte[]
a Java array
array
,
int
the starting index
start
,
ByteBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static ByteBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetByteArrayElements
(byte[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetByteArrayRegion(byte[]
a Java array
array
,
int
the starting index
start
,
ByteBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static ShortBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetCharArrayElements
(char[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetCharArrayRegion(char[]
a Java array
array
,
int
the starting index
start
,
ShortBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static native long

Returns:

the starting address of the memory region referenced by the buffer. Returns NULL if the memory region is undefined, if the given object is not a direct java.nio.Buffer, or if JNI access to direct buffers is not supported by this virtual machine.
GetDirectBufferAddress
(Buffer
a direct java.nio.Buffer object (must not be NULL)
buf
)

Fetches and returns the starting address of the memory region referenced by the given direct java.nio.Buffer.

public static DoubleBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetDoubleArrayElements
(double[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetDoubleArrayRegion(double[]
a Java array
array
,
int
the starting index
start
,
DoubleBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static FloatBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetFloatArrayElements
(float[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetFloatArrayRegion(float[]
a Java array
array
,
int
the starting index
start
,
FloatBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static IntBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetIntArrayElements
(int[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetIntArrayRegion(int[]
a Java array
array
,
int
the starting index
start
,
IntBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static int
GetJavaVM(PointerBuffer
a pointer to where the result should be placed
vm
)

Returns the Java VM interface (used in the Invocation API) associated with the current thread.

public static LongBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetLongArrayElements
(long[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetLongArrayRegion(long[]
a Java array
array
,
int
the starting index
start
,
LongBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static native int
GetObjectRefType(Object
a local, global or weak global reference
obj
)

Returns the type of the object referred to by the obj argument.

public static ShortBuffer

Returns:

a pointer to the array elements, or NULL if the operation fails
GetShortArrayElements
(short[]
the primitive array
array
,
ByteBuffer
a pointer to a boolean
isCopy
)

Returns the body of the primitive array.

public static void
GetShortArrayRegion(short[]
a Java array
array
,
int
the starting index
start
,
ShortBuffer
the destination buffer
buf
)

Copies a region of a primitive array into a buffer.

public static void
GetStringRegion(String str, int start, ByteBuffer buf)

Copies len number of Unicode characters beginning at offset start to the given buffer buf.

public static void
GetStringUTFRegion(String str, int start, int len, ByteBuffer buf)

Translates len number of Unicode characters beginning at offset start into modified UTF-8 encoding and place the result in the given buffer buf.

public static native int

Returns:

the major version number in the higher 16 bits and the minor version number in the lower 16 bits
GetVersion
()

Returns the version of the native method interface.

public static native void
nDeleteGlobalRef(long globalRef)

Unsafe version of: DeleteGlobalRef

public static native void
nDeleteWeakGlobalRef(long weakGlobalRef)

Unsafe version of: DeleteWeakGlobalRef

public static ByteBuffer

Returns:

a local reference to the newly-instantiated java.nio.ByteBuffer object. Returns NULL if an exception occurs, or if JNI access to direct buffers is not supported by this virtual machine.
NewDirectByteBuffer
(long
the starting address of the memory region (must not be NULL)
address
,
long
the size in bytes of the memory region (must be positive)
capacity
)

Allocates and returns a direct java.nio.ByteBuffer referring to the block of memory starting at the memory address address and extending capacity bytes.

public static native long

Returns:

a global reference, or NULL if the system runs out of memory
NewGlobalRef
(Object
a global or local reference
obj
)

Creates a new global reference to the object referred to by the obj argument.

public static native long
NewWeakGlobalRef(Object obj)

Creates a new weak global reference.

public static native long
nGetBooleanArrayElements(byte[] array, long isCopy)

Unsafe version of: GetBooleanArrayElements

public static native void
nGetBooleanArrayRegion(byte[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetBooleanArrayRegion

public static native long
nGetByteArrayElements(byte[] array, long isCopy)

Unsafe version of: GetByteArrayElements

public static native void
nGetByteArrayRegion(byte[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetByteArrayRegion

public static native long
nGetCharArrayElements(char[] array, long isCopy)

Unsafe version of: GetCharArrayElements

public static native void
nGetCharArrayRegion(char[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetCharArrayRegion

public static native long
nGetDoubleArrayElements(double[] array, long isCopy)

Unsafe version of: GetDoubleArrayElements

public static native void
nGetDoubleArrayRegion(double[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetDoubleArrayRegion

public static native long
nGetFloatArrayElements(float[] array, long isCopy)

Unsafe version of: GetFloatArrayElements

public static native void
nGetFloatArrayRegion(float[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetFloatArrayRegion

public static native long
nGetIntArrayElements(int[] array, long isCopy)

Unsafe version of: GetIntArrayElements

public static native void
nGetIntArrayRegion(int[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetIntArrayRegion

public static native int
nGetJavaVM(long vm)

Unsafe version of: GetJavaVM

public static native long
nGetLongArrayElements(long[] array, long isCopy)

Unsafe version of: GetLongArrayElements

public static native void
nGetLongArrayRegion(long[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetLongArrayRegion

public static native long
nGetShortArrayElements(short[] array, long isCopy)

Unsafe version of: GetShortArrayElements

public static native void
nGetShortArrayRegion(short[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: GetShortArrayRegion

public static native void
nGetStringRegion(String str, int start, int len, long buf)

Unsafe version of: GetStringRegion

public static native void
nGetStringUTFRegion(String str, int start, int len, long buf)

Unsafe version of: GetStringUTFRegion

public static native ByteBuffer
nNewDirectByteBuffer(long address, long capacity)

Unsafe version of: NewDirectByteBuffer

public static native void
noop()

No-op JNI function for benchmarking.

public static native int
nRegisterNatives(Class<?> targetClass, long methods, int
the number of native methods in the class
nMethods
)

Unsafe version of: RegisterNatives

public static native void
nReleaseBooleanArrayElements(byte[] array, long elems, int mode)

Unsafe version of: ReleaseBooleanArrayElements

public static native void
nReleaseByteArrayElements(byte[] array, long elems, int mode)

Unsafe version of: ReleaseByteArrayElements

public static native void
nReleaseCharArrayElements(char[] array, long elems, int mode)

Unsafe version of: ReleaseCharArrayElements

public static native void
nReleaseDoubleArrayElements(double[] array, long elems, int mode)

Unsafe version of: ReleaseDoubleArrayElements

public static native void
nReleaseFloatArrayElements(float[] array, long elems, int mode)

Unsafe version of: ReleaseFloatArrayElements

public static native void
nReleaseIntArrayElements(int[] array, long elems, int mode)

Unsafe version of: ReleaseIntArrayElements

public static native void
nReleaseLongArrayElements(long[] array, long elems, int mode)

Unsafe version of: ReleaseLongArrayElements

public static native void
nReleaseShortArrayElements(short[] array, long elems, int mode)

Unsafe version of: ReleaseShortArrayElements

public static native void
nSetBooleanArrayRegion(byte[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetBooleanArrayRegion

public static native void
nSetByteArrayRegion(byte[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetByteArrayRegion

public static native void
nSetCharArrayRegion(char[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetCharArrayRegion

public static native void
nSetDoubleArrayRegion(double[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetDoubleArrayRegion

public static native void
nSetFloatArrayRegion(float[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetFloatArrayRegion

public static native void
nSetIntArrayRegion(int[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetIntArrayRegion

public static native void
nSetLongArrayRegion(long[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetLongArrayRegion

public static native void
nSetShortArrayRegion(short[] array, int start, int
the number of elements to be copied
len
,
long buf)

Unsafe version of: SetShortArrayRegion

public static native Field
nToReflectedField(Class<?> cls, long fieldID, boolean isStatic)

Unsafe version of: ToReflectedField

public static native Method
nToReflectedMethod(Class<?> cls, long methodID, boolean isStatic)

Unsafe version of: ToReflectedMethod

public static int

Returns:

“0” on success; returns a negative value on failure
RegisterNatives
(Class<?> targetClass, JNINativeMethod.Buffer
the native methods in the class
methods
)

Registers native methods with the class specified by the targetClass argument.

public static void
ReleaseBooleanArrayElements(byte[]
a Java array object
array
,
ByteBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseByteArrayElements(byte[]
a Java array object
array
,
ByteBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseCharArrayElements(char[]
a Java array object
array
,
ShortBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseDoubleArrayElements(double[]
a Java array object
array
,
DoubleBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseFloatArrayElements(float[]
a Java array object
array
,
FloatBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseIntArrayElements(int[]
a Java array object
array
,
IntBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseLongArrayElements(long[]
a Java array object
array
,
LongBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
ReleaseShortArrayElements(short[]
a Java array object
array
,
ShortBuffer
a pointer to array elements
elems
,
int
the release mode. One of:
0COMMITABORT
mode
)

Informs the VM that the native code no longer needs access to elems.

public static void
SetBooleanArrayRegion(byte[]
a Java array
array
,
int
the starting index
start
,
ByteBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetByteArrayRegion(byte[]
a Java array
array
,
int
the starting index
start
,
ByteBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetCharArrayRegion(char[]
a Java array
array
,
int
the starting index
start
,
ShortBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetDoubleArrayRegion(double[]
a Java array
array
,
int
the starting index
start
,
DoubleBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetFloatArrayRegion(float[]
a Java array
array
,
int
the starting index
start
,
FloatBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetIntArrayRegion(int[]
a Java array
array
,
int
the starting index
start
,
IntBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetLongArrayRegion(long[]
a Java array
array
,
int
the starting index
start
,
LongBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static void
SetShortArrayRegion(short[]
a Java array
array
,
int
the starting index
start
,
ShortBuffer
the source buffer
buf
)

Copies back a region of a primitive array from a buffer.

public static Field
ToReflectedField(Class<?> cls, long fieldID, boolean
must be set to TRUE if fieldID refers to a static field, and FALSE otherwise
isStatic
)

Converts a field ID derived from cls to a Field object.

public static Method
ToReflectedMethod(Class<?> cls, long methodID, boolean
must be set to TRUE if the method ID refers to a static field, and # FALSE otherwise
isStatic
)

Converts a method ID derived from cls to a Method or Constructor object.

public static native int

Returns:

“0” on success; returns a negative value on failure
UnregisterNatives
(Class<?>
a Java class object
targetClass
)

Unregisters native methods of a class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait