Class JNINativeInterface
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 TypeFieldDescriptionstatic final int
Used inReleaseScalarArrayElements
.static final int
Used inReleaseScalarArrayElements
.static final int
Possible return values for JNI functions.static final int
Possible return values for JNI functions.static final int
Possible return values for JNI functions.static final int
Possible return values for JNI functions.static final int
Possible return values for JNI functions.static final int
Possible return values for JNI functions.static final int
jboolean constants.static final int
Possible return values for JNI functions.static final int
jboolean constants.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
JNI versions.static final int
jobjectRefType
: Return values fromGetObjectRefType(java.lang.Object)
.static final int
jobjectRefType
: Return values fromGetObjectRefType(java.lang.Object)
.static final int
jobjectRefType
: Return values fromGetObjectRefType(java.lang.Object)
.static final int
jobjectRefType
: Return values fromGetObjectRefType(java.lang.Object)
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
DeleteGlobalRef
(long globalRef) Deletes the global reference pointed to byglobalRef
.static void
DeleteWeakGlobalRef
(long weakGlobalRef) Delete the VM resources needed for the given weak global reference.static long
FromReflectedField
(Field field) Converts aField
to a field ID.static long
FromReflectedMethod
(Method method) Converts aMethod
orConstructor
object to a method ID.static ByteBuffer
GetBooleanArrayElements
(byte[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetBooleanArrayRegion
(byte[] array, int start, ByteBuffer buf) Copies a region of a primitive array into a buffer.static ByteBuffer
GetByteArrayElements
(byte[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetByteArrayRegion
(byte[] array, int start, ByteBuffer buf) Copies a region of a primitive array into a buffer.static ShortBuffer
GetCharArrayElements
(char[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetCharArrayRegion
(char[] array, int start, ShortBuffer buf) Copies a region of a primitive array into a buffer.static long
Fetches and returns the starting address of the memory region referenced by the given directjava.nio.Buffer
.static DoubleBuffer
GetDoubleArrayElements
(double[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetDoubleArrayRegion
(double[] array, int start, DoubleBuffer buf) Copies a region of a primitive array into a buffer.static FloatBuffer
GetFloatArrayElements
(float[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetFloatArrayRegion
(float[] array, int start, FloatBuffer buf) Copies a region of a primitive array into a buffer.static IntBuffer
GetIntArrayElements
(int[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetIntArrayRegion
(int[] array, int start, IntBuffer buf) Copies a region of a primitive array into a buffer.static int
GetJavaVM
(org.lwjgl.PointerBuffer vm) Returns the Java VM interface (used in the Invocation API) associated with the current thread.static LongBuffer
GetLongArrayElements
(long[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetLongArrayRegion
(long[] array, int start, LongBuffer buf) Copies a region of a primitive array into a buffer.static int
GetObjectRefType
(Object obj) Returns the type of the object referred to by theobj
argument.static ShortBuffer
GetShortArrayElements
(short[] array, ByteBuffer isCopy) Returns the body of the primitive array.static void
GetShortArrayRegion
(short[] array, int start, ShortBuffer buf) Copies a region of a primitive array into a buffer.static void
GetStringRegion
(String str, int start, ByteBuffer buf) Copieslen
number of Unicode characters beginning at offsetstart
to the given bufferbuf
.static void
GetStringUTFRegion
(String str, int start, int len, ByteBuffer buf) Translateslen
number of Unicode characters beginning at offset start into modified UTF-8 encoding and place the result in the given bufferbuf
.static int
Returns the version of the native method interface.static void
nDeleteGlobalRef
(long globalRef) Unsafe version of:DeleteGlobalRef(long)
static void
nDeleteWeakGlobalRef
(long weakGlobalRef) Unsafe version of:DeleteWeakGlobalRef(long)
static ByteBuffer
NewDirectByteBuffer
(long address, long capacity) Allocates and returns a directjava.nio.ByteBuffer
referring to the block of memory starting at the memory address address and extending capacity bytes.static long
NewGlobalRef
(Object obj) Creates a new global reference to the object referred to by theobj
argument.static long
NewWeakGlobalRef
(Object obj) Creates a new weak global reference.static long
nGetBooleanArrayElements
(byte[] array, long isCopy) Unsafe version of:GetBooleanArrayElements(byte[], java.nio.ByteBuffer)
static void
nGetBooleanArrayRegion
(byte[] array, int start, int len, long buf) Unsafe version of:GetBooleanArrayRegion(byte[], int, java.nio.ByteBuffer)
static long
nGetByteArrayElements
(byte[] array, long isCopy) Unsafe version of:GetByteArrayElements(byte[], java.nio.ByteBuffer)
static void
nGetByteArrayRegion
(byte[] array, int start, int len, long buf) Unsafe version of:GetByteArrayRegion(byte[], int, java.nio.ByteBuffer)
static long
nGetCharArrayElements
(char[] array, long isCopy) Unsafe version of:GetCharArrayElements(char[], java.nio.ByteBuffer)
static void
nGetCharArrayRegion
(char[] array, int start, int len, long buf) Unsafe version of:GetCharArrayRegion(char[], int, java.nio.ShortBuffer)
static long
nGetDoubleArrayElements
(double[] array, long isCopy) Unsafe version of:GetDoubleArrayElements(double[], java.nio.ByteBuffer)
static void
nGetDoubleArrayRegion
(double[] array, int start, int len, long buf) Unsafe version of:GetDoubleArrayRegion(double[], int, java.nio.DoubleBuffer)
static long
nGetFloatArrayElements
(float[] array, long isCopy) Unsafe version of:GetFloatArrayElements(float[], java.nio.ByteBuffer)
static void
nGetFloatArrayRegion
(float[] array, int start, int len, long buf) Unsafe version of:GetFloatArrayRegion(float[], int, java.nio.FloatBuffer)
static long
nGetIntArrayElements
(int[] array, long isCopy) Unsafe version of:GetIntArrayElements(int[], java.nio.ByteBuffer)
static void
nGetIntArrayRegion
(int[] array, int start, int len, long buf) Unsafe version of:GetIntArrayRegion(int[], int, java.nio.IntBuffer)
static int
nGetJavaVM
(long vm) Unsafe version of:GetJavaVM(org.lwjgl.PointerBuffer)
static long
nGetLongArrayElements
(long[] array, long isCopy) Unsafe version of:GetLongArrayElements(long[], java.nio.ByteBuffer)
static void
nGetLongArrayRegion
(long[] array, int start, int len, long buf) Unsafe version of:GetLongArrayRegion(long[], int, java.nio.LongBuffer)
static long
nGetShortArrayElements
(short[] array, long isCopy) Unsafe version of:GetShortArrayElements(short[], java.nio.ByteBuffer)
static void
nGetShortArrayRegion
(short[] array, int start, int len, long buf) Unsafe version of:GetShortArrayRegion(short[], int, java.nio.ShortBuffer)
static void
nGetStringRegion
(String str, int start, int len, long buf) Unsafe version of:GetStringRegion(java.lang.String, int, java.nio.ByteBuffer)
static void
nGetStringUTFRegion
(String str, int start, int len, long buf) Unsafe version of:GetStringUTFRegion(java.lang.String, int, int, java.nio.ByteBuffer)
static ByteBuffer
nNewDirectByteBuffer
(long address, long capacity) Unsafe version of:NewDirectByteBuffer(long, long)
static int
nRegisterNatives
(Class<?> targetClass, long methods, int nMethods) static void
nReleaseBooleanArrayElements
(byte[] array, long elems, int mode) Unsafe version of:ReleaseBooleanArrayElements(byte[], java.nio.ByteBuffer, int)
static void
nReleaseByteArrayElements
(byte[] array, long elems, int mode) Unsafe version of:ReleaseByteArrayElements(byte[], java.nio.ByteBuffer, int)
static void
nReleaseCharArrayElements
(char[] array, long elems, int mode) Unsafe version of:ReleaseCharArrayElements(char[], java.nio.ShortBuffer, int)
static void
nReleaseDoubleArrayElements
(double[] array, long elems, int mode) Unsafe version of:ReleaseDoubleArrayElements(double[], java.nio.DoubleBuffer, int)
static void
nReleaseFloatArrayElements
(float[] array, long elems, int mode) Unsafe version of:ReleaseFloatArrayElements(float[], java.nio.FloatBuffer, int)
static void
nReleaseIntArrayElements
(int[] array, long elems, int mode) Unsafe version of:ReleaseIntArrayElements(int[], java.nio.IntBuffer, int)
static void
nReleaseLongArrayElements
(long[] array, long elems, int mode) Unsafe version of:ReleaseLongArrayElements(long[], java.nio.LongBuffer, int)
static void
nReleaseShortArrayElements
(short[] array, long elems, int mode) Unsafe version of:ReleaseShortArrayElements(short[], java.nio.ShortBuffer, int)
static void
nSetBooleanArrayRegion
(byte[] array, int start, int len, long buf) Unsafe version of:SetBooleanArrayRegion(byte[], int, java.nio.ByteBuffer)
static void
nSetByteArrayRegion
(byte[] array, int start, int len, long buf) Unsafe version of:SetByteArrayRegion(byte[], int, java.nio.ByteBuffer)
static void
nSetCharArrayRegion
(char[] array, int start, int len, long buf) Unsafe version of:SetCharArrayRegion(char[], int, java.nio.ShortBuffer)
static void
nSetDoubleArrayRegion
(double[] array, int start, int len, long buf) Unsafe version of:SetDoubleArrayRegion(double[], int, java.nio.DoubleBuffer)
static void
nSetFloatArrayRegion
(float[] array, int start, int len, long buf) Unsafe version of:SetFloatArrayRegion(float[], int, java.nio.FloatBuffer)
static void
nSetIntArrayRegion
(int[] array, int start, int len, long buf) Unsafe version of:SetIntArrayRegion(int[], int, java.nio.IntBuffer)
static void
nSetLongArrayRegion
(long[] array, int start, int len, long buf) Unsafe version of:SetLongArrayRegion(long[], int, java.nio.LongBuffer)
static void
nSetShortArrayRegion
(short[] array, int start, int len, long buf) Unsafe version of:SetShortArrayRegion(short[], int, java.nio.ShortBuffer)
static Field
nToReflectedField
(Class<?> cls, long fieldID, boolean isStatic) Unsafe version of:ToReflectedField(java.lang.Class<?>, long, boolean)
static Method
nToReflectedMethod
(Class<?> cls, long methodID, boolean isStatic) Unsafe version of:ToReflectedMethod(java.lang.Class<?>, long, boolean)
static int
RegisterNatives
(Class<?> targetClass, JNINativeMethod.Buffer methods) Registers native methods with the class specified by thetargetClass
argument.static void
ReleaseBooleanArrayElements
(byte[] array, ByteBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseByteArrayElements
(byte[] array, ByteBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseCharArrayElements
(char[] array, ShortBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseDoubleArrayElements
(double[] array, DoubleBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseFloatArrayElements
(float[] array, FloatBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseIntArrayElements
(int[] array, IntBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseLongArrayElements
(long[] array, LongBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
ReleaseShortArrayElements
(short[] array, ShortBuffer elems, int mode) Informs the VM that the native code no longer needs access toelems
.static void
SetBooleanArrayRegion
(byte[] array, int start, ByteBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetByteArrayRegion
(byte[] array, int start, ByteBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetCharArrayRegion
(char[] array, int start, ShortBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetDoubleArrayRegion
(double[] array, int start, DoubleBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetFloatArrayRegion
(float[] array, int start, FloatBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetIntArrayRegion
(int[] array, int start, IntBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetLongArrayRegion
(long[] array, int start, LongBuffer buf) Copies back a region of a primitive array from a buffer.static void
SetShortArrayRegion
(short[] array, int start, ShortBuffer buf) Copies back a region of a primitive array from a buffer.static Field
ToReflectedField
(Class<?> cls, long fieldID, boolean isStatic) Converts a field ID derived fromcls
to aField
object.static Method
ToReflectedMethod
(Class<?> cls, long methodID, boolean isStatic) static int
UnregisterNatives
(Class<?> targetClass) Unregisters native methods of a class.
-
Field Details
-
JNI_VERSION_1_1
public static final int JNI_VERSION_1_1JNI versions.- See Also:
-
JNI_VERSION_1_2
public static final int JNI_VERSION_1_2JNI versions.- See Also:
-
JNI_VERSION_1_4
public static final int JNI_VERSION_1_4JNI versions.- See Also:
-
JNI_VERSION_1_6
public static final int JNI_VERSION_1_6JNI versions.- See Also:
-
JNI_VERSION_1_8
public static final int JNI_VERSION_1_8JNI versions.- See Also:
-
JNI_VERSION_9
public static final int JNI_VERSION_9JNI versions.- See Also:
-
JNI_VERSION_10
public static final int JNI_VERSION_10JNI versions.- See Also:
-
JNI_VERSION_19
public static final int JNI_VERSION_19JNI versions.- See Also:
-
JNI_VERSION_20
public static final int JNI_VERSION_20JNI versions.- See Also:
-
JNIInvalidRefType
public static final int JNIInvalidRefType- See Also:
-
JNILocalRefType
public static final int JNILocalRefType- See Also:
-
JNIGlobalRefType
public static final int JNIGlobalRefType- See Also:
-
JNIWeakGlobalRefType
public static final int JNIWeakGlobalRefType- See Also:
-
JNI_FALSE
public static final int JNI_FALSEjboolean constants.- See Also:
-
JNI_TRUE
public static final int JNI_TRUEjboolean constants.- See Also:
-
JNI_OK
public static final int JNI_OKPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_ERR
public static final int JNI_ERRPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_EDETACHED
public static final int JNI_EDETACHEDPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_EVERSION
public static final int JNI_EVERSIONPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_ENOMEM
public static final int JNI_ENOMEMPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_EEXIST
public static final int JNI_EEXISTPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_EINVAL
public static final int JNI_EINVALPossible return values for JNI functions.Enum values:
- See Also:
-
JNI_COMMIT
public static final int JNI_COMMITUsed inReleaseScalarArrayElements
.- See Also:
-
JNI_ABORT
public static final int JNI_ABORTUsed inReleaseScalarArrayElements
.- See Also:
-
-
Method Details
-
GetVersion
public static int GetVersion()Returns the version of the native method interface.- Returns:
- the major version number in the higher 16 bits and the minor version number in the lower 16 bits
-
FromReflectedMethod
Converts aMethod
orConstructor
object to a method ID. -
FromReflectedField
Converts aField
to a field ID. -
nToReflectedMethod
Unsafe version of:ToReflectedMethod(java.lang.Class<?>, long, boolean)
-
ToReflectedMethod
- Parameters:
isStatic
- must be set toTRUE
if the method ID refers to a static field, and # FALSE otherwise
-
nToReflectedField
Unsafe version of:ToReflectedField(java.lang.Class<?>, long, boolean)
-
ToReflectedField
Converts a field ID derived fromcls
to aField
object. -
NewGlobalRef
Creates a new global reference to the object referred to by theobj
argument. Theobj
argument may be a global or local reference. Global references must be explicitly disposed of by callingDeleteGlobalRef(long)
.- Parameters:
obj
- a global or local reference- Returns:
- a global reference, or
NULL
if the system runs out of memory
-
nDeleteGlobalRef
public static void nDeleteGlobalRef(long globalRef) Unsafe version of:DeleteGlobalRef(long)
-
DeleteGlobalRef
public static void DeleteGlobalRef(long globalRef) Deletes the global reference pointed to byglobalRef
.- Parameters:
globalRef
- a global reference
-
nGetBooleanArrayElements
public static long nGetBooleanArrayElements(byte[] array, long isCopy) Unsafe version of:GetBooleanArrayElements(byte[], java.nio.ByteBuffer)
-
GetBooleanArrayElements
@Nullable public static ByteBuffer GetBooleanArrayElements(byte[] array, @Nullable ByteBuffer isCopy) Returns the body of the primitive array. The result is valid until theReleaseBooleanArrayElements(byte[], java.nio.ByteBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseBooleanArrayElements(byte[], java.nio.ByteBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseBooleanArrayElements
public static void nReleaseBooleanArrayElements(byte[] array, long elems, int mode) Unsafe version of:ReleaseBooleanArrayElements(byte[], java.nio.ByteBuffer, int)
-
ReleaseBooleanArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetBooleanArrayElements(byte[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetByteArrayElements
public static long nGetByteArrayElements(byte[] array, long isCopy) Unsafe version of:GetByteArrayElements(byte[], java.nio.ByteBuffer)
-
GetByteArrayElements
Returns the body of the primitive array. The result is valid until theReleaseByteArrayElements(byte[], java.nio.ByteBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseByteArrayElements(byte[], java.nio.ByteBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseByteArrayElements
public static void nReleaseByteArrayElements(byte[] array, long elems, int mode) Unsafe version of:ReleaseByteArrayElements(byte[], java.nio.ByteBuffer, int)
-
ReleaseByteArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetByteArrayElements(byte[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetCharArrayElements
public static long nGetCharArrayElements(char[] array, long isCopy) Unsafe version of:GetCharArrayElements(char[], java.nio.ByteBuffer)
-
GetCharArrayElements
Returns the body of the primitive array. The result is valid until theReleaseCharArrayElements(char[], java.nio.ShortBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseCharArrayElements(char[], java.nio.ShortBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseCharArrayElements
public static void nReleaseCharArrayElements(char[] array, long elems, int mode) Unsafe version of:ReleaseCharArrayElements(char[], java.nio.ShortBuffer, int)
-
ReleaseCharArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetCharArrayElements(char[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetShortArrayElements
public static long nGetShortArrayElements(short[] array, long isCopy) Unsafe version of:GetShortArrayElements(short[], java.nio.ByteBuffer)
-
GetShortArrayElements
@Nullable public static ShortBuffer GetShortArrayElements(short[] array, @Nullable ByteBuffer isCopy) Returns the body of the primitive array. The result is valid until theReleaseShortArrayElements(short[], java.nio.ShortBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseShortArrayElements(short[], java.nio.ShortBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseShortArrayElements
public static void nReleaseShortArrayElements(short[] array, long elems, int mode) Unsafe version of:ReleaseShortArrayElements(short[], java.nio.ShortBuffer, int)
-
ReleaseShortArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetShortArrayElements(short[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetIntArrayElements
public static long nGetIntArrayElements(int[] array, long isCopy) Unsafe version of:GetIntArrayElements(int[], java.nio.ByteBuffer)
-
GetIntArrayElements
Returns the body of the primitive array. The result is valid until theReleaseIntArrayElements(int[], java.nio.IntBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseIntArrayElements(int[], java.nio.IntBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseIntArrayElements
public static void nReleaseIntArrayElements(int[] array, long elems, int mode) Unsafe version of:ReleaseIntArrayElements(int[], java.nio.IntBuffer, int)
-
ReleaseIntArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetIntArrayElements(int[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetLongArrayElements
public static long nGetLongArrayElements(long[] array, long isCopy) Unsafe version of:GetLongArrayElements(long[], java.nio.ByteBuffer)
-
GetLongArrayElements
Returns the body of the primitive array. The result is valid until theReleaseLongArrayElements(long[], java.nio.LongBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseLongArrayElements(long[], java.nio.LongBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseLongArrayElements
public static void nReleaseLongArrayElements(long[] array, long elems, int mode) Unsafe version of:ReleaseLongArrayElements(long[], java.nio.LongBuffer, int)
-
ReleaseLongArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetLongArrayElements(long[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetFloatArrayElements
public static long nGetFloatArrayElements(float[] array, long isCopy) Unsafe version of:GetFloatArrayElements(float[], java.nio.ByteBuffer)
-
GetFloatArrayElements
@Nullable public static FloatBuffer GetFloatArrayElements(float[] array, @Nullable ByteBuffer isCopy) Returns the body of the primitive array. The result is valid until theReleaseFloatArrayElements(float[], java.nio.FloatBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseFloatArrayElements(float[], java.nio.FloatBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseFloatArrayElements
public static void nReleaseFloatArrayElements(float[] array, long elems, int mode) Unsafe version of:ReleaseFloatArrayElements(float[], java.nio.FloatBuffer, int)
-
ReleaseFloatArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetFloatArrayElements(float[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetDoubleArrayElements
public static long nGetDoubleArrayElements(double[] array, long isCopy) Unsafe version of:GetDoubleArrayElements(double[], java.nio.ByteBuffer)
-
GetDoubleArrayElements
@Nullable public static DoubleBuffer GetDoubleArrayElements(double[] array, @Nullable ByteBuffer isCopy) Returns the body of the primitive array. The result is valid until theReleaseDoubleArrayElements(double[], java.nio.DoubleBuffer, int)
function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array untilReleaseDoubleArrayElements(double[], java.nio.DoubleBuffer, int)
is called.If
isCopy
is notNULL
, then*isCopy
is set toTRUE
if a copy is made; or it is set toFALSE
if no copy is made.- Parameters:
array
- the primitive arrayisCopy
- a pointer to a boolean- Returns:
- a pointer to the array elements, or
NULL
if the operation fails
-
nReleaseDoubleArrayElements
public static void nReleaseDoubleArrayElements(double[] array, long elems, int mode) Unsafe version of:ReleaseDoubleArrayElements(double[], java.nio.DoubleBuffer, int)
-
ReleaseDoubleArrayElements
Informs the VM that the native code no longer needs access toelems
. Theelems
argument is a pointer derived from array using theGetDoubleArrayElements(double[], java.nio.ByteBuffer)
function. If necessary, this function copies back all changes made to elems to the original array.The
mode
argument provides information on how the array buffer should be released.mode
has no effect ifelems
is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:mode actions 0 copy back the content and free the elems buffer COMMIT
copy back the content but do not free the elems buffer ABORT
free the buffer without copying back the possible changes In most cases, programmers pass “0” to the mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care.
-
nGetBooleanArrayRegion
public static void nGetBooleanArrayRegion(byte[] array, int start, int len, long buf) Unsafe version of:GetBooleanArrayRegion(byte[], int, java.nio.ByteBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetBooleanArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetBooleanArrayRegion
public static void nSetBooleanArrayRegion(byte[] array, int start, int len, long buf) Unsafe version of:SetBooleanArrayRegion(byte[], int, java.nio.ByteBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetBooleanArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetByteArrayRegion
public static void nGetByteArrayRegion(byte[] array, int start, int len, long buf) Unsafe version of:GetByteArrayRegion(byte[], int, java.nio.ByteBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetByteArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetByteArrayRegion
public static void nSetByteArrayRegion(byte[] array, int start, int len, long buf) Unsafe version of:SetByteArrayRegion(byte[], int, java.nio.ByteBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetByteArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetCharArrayRegion
public static void nGetCharArrayRegion(char[] array, int start, int len, long buf) Unsafe version of:GetCharArrayRegion(char[], int, java.nio.ShortBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetCharArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetCharArrayRegion
public static void nSetCharArrayRegion(char[] array, int start, int len, long buf) Unsafe version of:SetCharArrayRegion(char[], int, java.nio.ShortBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetCharArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetShortArrayRegion
public static void nGetShortArrayRegion(short[] array, int start, int len, long buf) Unsafe version of:GetShortArrayRegion(short[], int, java.nio.ShortBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetShortArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetShortArrayRegion
public static void nSetShortArrayRegion(short[] array, int start, int len, long buf) Unsafe version of:SetShortArrayRegion(short[], int, java.nio.ShortBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetShortArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetIntArrayRegion
public static void nGetIntArrayRegion(int[] array, int start, int len, long buf) Unsafe version of:GetIntArrayRegion(int[], int, java.nio.IntBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetIntArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetIntArrayRegion
public static void nSetIntArrayRegion(int[] array, int start, int len, long buf) Unsafe version of:SetIntArrayRegion(int[], int, java.nio.IntBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetIntArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetLongArrayRegion
public static void nGetLongArrayRegion(long[] array, int start, int len, long buf) Unsafe version of:GetLongArrayRegion(long[], int, java.nio.LongBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetLongArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetLongArrayRegion
public static void nSetLongArrayRegion(long[] array, int start, int len, long buf) Unsafe version of:SetLongArrayRegion(long[], int, java.nio.LongBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetLongArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetFloatArrayRegion
public static void nGetFloatArrayRegion(float[] array, int start, int len, long buf) Unsafe version of:GetFloatArrayRegion(float[], int, java.nio.FloatBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetFloatArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetFloatArrayRegion
public static void nSetFloatArrayRegion(float[] array, int start, int len, long buf) Unsafe version of:SetFloatArrayRegion(float[], int, java.nio.FloatBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetFloatArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nGetDoubleArrayRegion
public static void nGetDoubleArrayRegion(double[] array, int start, int len, long buf) Unsafe version of:GetDoubleArrayRegion(double[], int, java.nio.DoubleBuffer)
- Parameters:
len
- the number of elements to be copied
-
GetDoubleArrayRegion
Copies a region of a primitive array into a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the destination buffer
-
nSetDoubleArrayRegion
public static void nSetDoubleArrayRegion(double[] array, int start, int len, long buf) Unsafe version of:SetDoubleArrayRegion(double[], int, java.nio.DoubleBuffer)
- Parameters:
len
- the number of elements to be copied
-
SetDoubleArrayRegion
Copies back a region of a primitive array from a buffer.- Parameters:
array
- a Java arraystart
- the starting indexbuf
- the source buffer
-
nRegisterNatives
- Parameters:
nMethods
- the number of native methods in the class
-
RegisterNatives
Registers native methods with the class specified by thetargetClass
argument. The methods parameter specifies an array of JNINativeMethod structures that contain the names, signatures, and function pointers of the native methods. The name and signature fields of theJNINativeMethod
structure are pointers to modified UTF-8 strings. ThenMethods
parameter specifies the number of native methods in the array.- Parameters:
methods
- the native methods in the class- Returns:
- “0” on success; returns a negative value on failure
-
UnregisterNatives
Unregisters native methods of a class. The class goes back to the state before it was linked or registered with its native method functions.This function should not be used in normal native code. Instead, it provides special programs a way to reload and relink native libraries.
- Parameters:
targetClass
- a Java class object- Returns:
- “0” on success; returns a negative value on failure
-
nGetJavaVM
public static int nGetJavaVM(long vm) Unsafe version of:GetJavaVM(org.lwjgl.PointerBuffer)
-
GetJavaVM
public static int GetJavaVM(org.lwjgl.PointerBuffer vm) Returns the Java VM interface (used in the Invocation API) associated with the current thread. The result is placed at the location pointed to by the second argument,vm
.- Parameters:
vm
- a pointer to where the result should be placed
-
nGetStringRegion
Unsafe version of:GetStringRegion(java.lang.String, int, java.nio.ByteBuffer)
-
GetStringRegion
Copieslen
number of Unicode characters beginning at offsetstart
to the given bufferbuf
. -
nGetStringUTFRegion
Unsafe version of:GetStringUTFRegion(java.lang.String, int, int, java.nio.ByteBuffer)
-
GetStringUTFRegion
Translateslen
number of Unicode characters beginning at offset start into modified UTF-8 encoding and place the result in the given bufferbuf
. -
NewWeakGlobalRef
Creates a new weak global reference. ReturnsNULL
ifobj
refers to null, or if the VM runs out of memory. If the VM runs out of memory, anOutOfMemoryError
will be thrown. -
nDeleteWeakGlobalRef
public static void nDeleteWeakGlobalRef(long weakGlobalRef) Unsafe version of:DeleteWeakGlobalRef(long)
-
DeleteWeakGlobalRef
public static void DeleteWeakGlobalRef(long weakGlobalRef) Delete the VM resources needed for the given weak global reference. -
nNewDirectByteBuffer
Unsafe version of:NewDirectByteBuffer(long, long)
-
NewDirectByteBuffer
Allocates and returns a directjava.nio.ByteBuffer
referring to the block of memory starting at the memory address address and extending capacity bytes.Native code that calls this function and returns the resulting byte-buffer object to Java-level code should ensure that the buffer refers to a valid region of memory that is accessible for reading and, if appropriate, writing. An attempt to access an invalid memory location from Java code will either return an arbitrary value, have no visible effect, or cause an unspecified exception to be thrown.
- Parameters:
address
- the starting address of the memory region (must not beNULL
)capacity
- the size in bytes of the memory region (must be positive)- Returns:
- a local reference to the newly-instantiated
java.nio.ByteBuffer
object. ReturnsNULL
if an exception occurs, or if JNI access to direct buffers is not supported by this virtual machine.
-
GetDirectBufferAddress
Fetches and returns the starting address of the memory region referenced by the given directjava.nio.Buffer
.This function allows native code to access the same memory region that is accessible to Java code via the buffer object.
- Parameters:
buf
- a directjava.nio.Buffer
object (must not beNULL
)- 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 directjava.nio.Buffer
, or if JNI access to direct buffers is not supported by this virtual machine.
-
GetObjectRefType
Returns the type of the object referred to by theobj
argument. The argumentobj
can either be a local, global or weak global reference.- Parameters:
obj
- a local, global or weak global reference
-