4
This chapter serves as the reference section for the JNI functions. It provides a complete listing of all the JNI functions. It also presents the exact layout of the interface function table, which is the means for accessing native methods through the JNI.A portion of this chapter is adapted from Netscape's JRI documentation.
The reference material groups functions by their usage. The reference section is organized by the following functional areas:
typedef const struct JNINativeInterface *JNIEnv; |
The VM initializes the function table, as shown by Code Example 4-1. Note that the first three entries are reserved for future compatibility with COM. In addition, we reserve a number of additional NULL entries near the beginning of the function table, so that, for example, a future class-related JNI operation can be added after FindClass, rather than at the end of the table.
Note that the function table can be shared among all JNI interface pointers.
jint GetVersion(JNIEnv *env);Returns the version of the native method interface.
env: the JNI interface pointer.
In JDK1.1, GetVersion() returns 0x00010001.
jclass DefineClass(JNIEnv *env, jobject loader,
const char *buf, jsize bufLen);Defines a class from a buffer of raw class data.
env: the JNI interface pointer.
loader: a class loader assigned to the defined class.
buf: buffer containing the .class file data.
ClassFormatError: if the class data does not specify a valid class.jclass FindClass(JNIEnv *env, const char *name);
This function loads a locally defined class. It searches the directories and zip files specified by the CLASSPATH environment variable for the class with the specified name.
env: the JNI interface pointer.
name: a fully qualified class name (that is, a package name, delimited by "/", followed by the class name). If the name begins with "[" (the array signature character), it returns an array class.
jclass GetSuperclass(JNIEnv *env, jclass clazz);
If clazz represents any class other than the class Object, then this function returns the object that represents the superclass of the class specified by clazz.
If clazz specifies the class Object or clazz represents an interface, this function returns NULL.
env: the JNI interface pointer.clazz, or NULL.jboolean IsSubclassOf(JNIEnv *env, jclass clazz1,
jclass clazz2);
Determines whether an object of clazz1 can be safely cast to clazz2.
env: the JNI interface pointer.
clazz1: the first class argument.
clazz2: the second class argument.
JNI_TRUE if either of the following is true:· The first and second class arguments refer to the same Java class.
· The first class is a subclass of the second class.
· The first class has the second class as one of its interfaces.
jint Throw(JNIEnv *env, jobject obj);
Causes a java.lang.Throwable object to be thrown.
env: the JNI interface pointer.
obj: a java.lang.Throwable object.
jint ThrowNew(JNIEnv *env, jclass clazz,
const char *message);
Constructs an exception object from the specified class with the message specified by message and causes that exception to be thrown.
env: the JNI interface pointer.
clazz: a subclass of java.lang.Throwable.
message: the message used to construct the java.lang.Throwable object.
jobject ExceptionOccurred(JNIEnv *env);
Determines if an exception is being thrown. The exception stays being thrown until either the native code calls ExceptionClear(), or the Java code handles the exception.
env: the JNI interface pointer.void ExceptionDescribe(JNIEnv *env);
Prints an exception and a backtrace of the stack to a system error reporting channel, such as stderr. This is a convenience routine provided for debugging.
env: the JNI interface pointer.void ExceptionClear(JNIEnv *env);Clears any exception that is currently being thrown. If no exception is currently being thrown, this routine has no effect.
env: the JNI interface pointer.void FatalError(JNIEnv *env, char * msg);Raises a fatal error and does not expect the VM to recover.
env: the JNI interface pointer.jref NewGlobalRef(JNIEnv *env, jref ref);
Creates a new global reference to the object referred to by the ref argument. The ref argument may be a global or local reference. Global references must be explicitly disposed of by calling DeleteGlobalRef().
env: the JNI interface pointer.
ref: a global or local reference.
void DeleteGlobalRef(JNIEnv *env, jref *globalRef);
Deletes the global reference pointed to by globalRef and sets *globalRef to NULL.
env: the JNI interface pointer.
globalRef: a global reference.
void DeleteLocalRef(JNIEnv *env, jref *localRef);
Deletes the local reference pointed to by localRef and sets *localRef to NULL.
env: the JNI interface pointer.jobject AllocObject(JNIEnv *env, jclass clazz);Allocates a new Java object without invoking any of the constructors for the object. Returns a reference to the object.
The clazz argument must not refer to an array class.
env: the JNI interface pointer.InstantiationException: if the class is an interface or an abstract class.jobject NewObject(JNIEnv *env, jclass clazz,
jmethodID methodID, ...);
Constructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with <init> as the method name and void (V) as the return type.
Programmers place all arguments that are to be passed to the constructor immediately following the methodID argument. NewObject() accepts these arguments and passes them to the Java method that the programmer wishes to invoke.
env: the JNI interface pointer.
methodID: the method ID of the constructor.
InstantiationException: if the class is an interface or an abstract class.jobject NewObjectA(JNIEnv *env, jclass clazz,
jmethodID methodID, jvalue *args);
Constructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with <init> as the method name and void (V) as the return type.
Programmers place all arguments that are to be passed to the constructor in an args array of jvalues that immediately follows the methodID argument. NewObjectA() accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.
env: the JNI interface pointer.
methodID: the method ID of the constructor.
args: an array of arguments to the constructor.
InstantiationException: if the class is an interface or an abstract class.jobject NewObjectV(JNIEnv *env, jclass clazz,
jmethodID methodID, va_list args);
Constructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with <init> as the method name and void (V) as the return type.
Programmers place all arguments that are to be passed to the constructor in an args argument of type va_list that immediately follows the methodID argument. NewObjectV() accepts these arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
env: the JNI interface pointer.
methodID: the method ID of the constructor.
args: a va_list of arguments to the constructor.
InstantiationException: if the class is an interface or an abstract class.jclass GetObjectClass(JNIEnv *env, jobject obj);Returns the class of an object.
env: the JNI interface pointer.
obj: a Java object (must not be NULL).
jboolean IsInstanceOf(JNIEnv *env, jobject obj,
jclass clazz);Tests whether an object is an instance of a class.
env: the JNI interface pointer.JNI_TRUE if obj can be cast to clazz; otherwise, returns JNI_FALSE. A NULL object can be cast to any class.jboolean IsSameObject(JNIEnv *env, jobject ref1,
jobject ref2);Tests whether two references refer to the same Java object.
env: the JNI interface pointer.JNI_TRUE if ref1 and ref2 refer to the same Java object, or are both NULL; otherwise, returns JNI_FALSE.jfieldID GetFieldID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);Returns the field ID for an instance (non-static) field of a class. The field is specified by its name and signature. The GetField and SetField families of accessor functions use field IDs to retrieve object fields.
env: the JNI interface pointer.
name: the field name in a 0-terminated UTF-8 string.
sig: the field signature in a 0-terminated UTF-8 string.
NULL if the operation fails.NoSuchFieldError: if the specified field cannot be found. GetField(JNIEnv *env, jobject obj,
jfieldID fieldID);
This family of accessor routines returns the value of an instance (non-static) field of an object. The field to access is specified by a field ID obtained by calling GetFieldID().
Table 4-1 describes the GetField routine name and result type. Note that GetField is not a real function name, nor is NativeType a real type name. You should replace GetField with one of the actual routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.
obj: a Java object (must not be NULL).
void SetField(JNIEnv *env, jobject obj, jfieldID fieldID,
NativeType value);
This family of accessor routines sets the value of an instance (non-static) field of an object. The field to access is specified by a field ID obtained by calling GetFieldID().
Table 4-2 describes the SetField routine name and value type. Note that SetField is not a real function name, nor is NativeType a real type name. You should replace SetField with one of the actual routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.
obj: a Java object (must not be NULL).
value: the new value of the field.
jmethodID GetMethodID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);
Returns the method ID for an instance (non-static) method of a class or interface. The method may be defined in one of the clazz's super classes and inherited by clazz. The method is determined by its name and signature.
To obtain the method ID of a constructor, supply <init> as the method name and void (V) as the return type.
env: the JNI interface pointer.
name: the method name in a 0-terminated UTF-8 string.
sig: the method signature in 0-terminated UTF-8 string.
NoSuchMethodError: if the specified method cannot be found. CallMethod(JNIEnv *env, jobject obj,
jmethodID methodID, ...);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetMethodID().
When this function is used to call private methods and constructors, the method ID must be derived from the real class of obj, not from one of its super classes.
Programmers place all arguments that are to be passed to the method immediately following the methodID argument. The CallMethod routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.
Table 4-3 describes each of the method calling routines according to their result type. Note that CallMethod is not a real function name, nor is NativeType a real type name. You should replace CallMethod with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallMethodA(JNIEnv *env, jobject obj,
jmethodID methodID, jvalue *args);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetMethodID().
When this function is used to call private methods and constructors, the method ID must be derived from the real class of obj, not from one of its super classes.
Programmers place all arguments to the method in an args array of jvalues that immediately follows the methodID argument. The CallMethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-4 describes each of the CallMethodA method calling routines according to their result types. Note that CallMethodA is not a real function name, nor is NativeType a real type name. You should replace CallMethodA with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallMethodV(JNIEnv *env, jobject obj,
jmethodID methodID, va_list args);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetMethodID().
When this function is used to call private methods and constructors, the method ID must be derived from the real class of obj, not from one of its super classes.
Programmers place all arguments to the method in an args argument of type va_list that immediately follows the methodID argument. The CallMethodV routine accepts the arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-5 describes each of the CallMethodV method calling routines according to their result types. Note that CallMethodV is not a real function name, nor is NativeType a real type name. You should replace CallMethodV with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallNonvirtualMethod(JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, ...);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified class and method ID. The methodID argument must be obtained by calling GetMethodID() on the class clazz.
The CallNonvirtualMethod and CallMethod families of routines are different. The CallMethod routines invoke the method based on the class of the object, whereas the CallNonvirtualMethod routines invoke the method based on the class, designated by the clazz parameter, from which the method ID is obtained. The method ID must be obtained from the real class of the object or from one of its superclasses.
Programmers place all arguments that are to be passed to the method immediately following the methodID argument. The CallNonvirtualMethod routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.
Table 4-6 describes each of the method calling routines according to their result type. Note that CallNonvirtualMethod is not a real function name, nor is NativeType a real type name. You should replace CallNonvirtualMethod with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallNonvirtualMethodA(JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, jvalue *args);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified class and method ID. The methodID argument must be obtained by calling GetMethodID() on the class clazz.
The CallNonvirtualMethodA family of routines and the CallMethodA family of routines are different. CallMethodA routines invoke the method based on the class of the object, while CallNonvirtualMethodA routines invoke the method based on the class, designated by the clazz parameter, from which the method ID is obtained. The method ID must be obtained from the real class of the object or from one of its superclasses.
Programmers place all arguments to the method in an args array of jvalues that immediately follows the methodID argument. The CallNonvirtualMethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-7 describes each of the CallNonvirtualMethodA method calling routines according to their result types. Note that CallNonvirtualMethodA is not a real function name, nor is NativeType a real type name. You should replace CallNonvirtualMethodA with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallNonvirtualMethodV(JNIEnv *env, jobject obj,
jclass clazz, jmethodID methodID, va_list args);
This family of operations invokes an instance (non-static) method on a Java object, according to the specified class and method ID. The methodID argument must be obtained by calling GetMethodID() on the class clazz.
The CallNonvirtualMethodV family of routines and the CallMethodV family of routines are different. The CallMethodV routines invoke the method based on the class of the object, while the CallNonvirtualMethodV routines invoke the method based on the class, designated by the clazz parameter, from which the method ID is obtained. The method ID must be obtained from the real class of the object or from one of its superclasses.
Programmers place all arguments to the method in an args argument of type va_list that immediately follows the methodID argument. The CallNonvirtualMethodV routine accepts the arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-8 describes each of the method calling routines according to their result types. Note that CallNonvirtualMethodV is not a real function name, nor is NativeType a real type name. You should replace CallNonvirtualMethodV with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);Returns the field ID for a static field of a class. The field is specified by its name and signature. The GetStaticField and SetStaticField families of accessor functions use field IDs to retrieve static fields.
env: the JNI interface pointer.
name: the static field name in a 0-terminated UTF-8 string.
sig: the field signature in a 0-terminated UTF-8 string.
NoSuchFieldError: if the specified static field cannot be found. GetStaticField(JNIEnv *env, jclass clazz,
jfieldID fieldID);
This family of accessor routines returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling GetStaticFieldID().
Table 4-9 describes the family of get routine names and result types. Note that GetStaticField is not a real function name, nor is NativeType a real type name. You should replace GetStaticField with one of the actual static field accessor routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.void SetStaticField(JNIEnv *env, jclass clazz,
jfieldID fieldID, NativeType value);
This family of accessor routines sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling GetStaticFieldID().
Table 4-10 describes the set routine name and value types. Note that SetStaticField is not a real function name, nor is NativeType a real type name. You should replace SetStaticField with one of the actual set static field routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.
value: the new value of the field.
jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);Returns the method ID for a static method of a class. The method is specified by its name and signature.
env: the JNI interface pointer.
name: the static method name in a 0-terminated UTF-8 string.
sig: the method signature in a 0-terminated UTF-8 string.
NoSuchMethodError: if the specified static method cannot be found. CallStaticMethod(JNIEnv *env, jclass clazz,
jmethodID methodID, ...);
This family of operations invokes a static method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetStaticMethodID().
The method ID must be derived from clazz, not from one of its superclasses.
Programmers place all arguments that are to be passed to the method immediately following the methodID argument. The CallStaticMethod routine accepts these arguments and passes them to the Java method that the programmer wishes to invoke.
Table 4-11 describes each of the method calling routines according to their result types. Note that CallStaticMethod is not a real function name, nor is NativeType a real type name. You should replace CallStaticMethod with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallStaticMethodA(JNIEnv *env, jclass clazz,
jmethodID methodID, jvalue *args);
This family of operations invokes a static method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetStaticMethodID().
The method ID must be derived from clazz, not from one of its superclasses.
Programmers place all arguments to the method in an args array of jvalues that immediately follows the methodID argument. The CallStaticMethodA routine accepts the arguments in this array, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-12 describes each of the static method calling routines according to their result types. Note that CallStaticMethodA is not a real function name, nor is NativeType a real type name. You should replace CallStaticMethodA with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer. CallStaticMethodV(JNIEnv *env, jclass clazz,
jmethodID methodID, va_list args);
This family of operations invokes a static method on a Java object, according to the specified method ID. The methodID argument must be obtained by calling GetStaticMethodID().
The method ID must be derived from clazz, not from one of its superclasses.
Programmers place all arguments to the method in an args argument of type va_list that immediately follows the methodID argument. The CallStaticMethodV routine accepts the arguments, and, in turn, passes them to the Java method that the programmer wishes to invoke.
Table 4-13 describes each of the method calling routines according to their result types. Note that CallStaticMethodV is not a real function name, nor is NativeType a real type name. You should replace CallStaticMethodV with one of the actual method calling routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.jstring NewString(JNIEnv *env, const jchar *unicodeChars,
jsize len);
Constructs a new java.lang.String object from an array of Unicode characters.
env: the JNI interface pointer.
unicodeChars: pointer to a Unicode string.
len: length of the Unicode string.
jsize GetStringLength(JNIEnv *env, jstring string);Returns the length (the count of Unicode characters) of a Java string.
env: the JNI interface pointer.const jchar * GetStringChars(JNIEnv *env, jstring string,
jboolean *isCopy);
Returns a pointer to the array of Unicode characters of the string. This pointer is valid until ReleaseStringchars() is called.
If isCopy is not NULL, then *isCopy is set to one if a copy is made, or it is set to zero if no copy is made.
env: the JNI interface pointer.
isCopy: a pointer to a boolean.
NULL if the operation fails.void ReleaseStringChars(JNIEnv *env, jstring string,
const jchar *chars);
Informs the VM that the native code no longer needs access to chars. The chars argument is a pointer obtained from string using GetStringChars().
env: the JNI interface pointer.
chars: a pointer to a Unicode string.
jstring NewStringUTF(JNIEnv *env, const char *bytes,
jsize length);
Constructs a new java.lang.String object from an array of UTF-8 characters.
env: the JNI interface pointer, or NULL if the string cannot be constructed.
bytes: the pointer to a UTF-8 string.
length: the length of the UTF-8 string.
NULL if the string cannot be constructed.jsize GetStringUTFLength(JNIEnv *env, jstring string);Returns the UTF-8 length in bytes of a string.
env: the JNI interface pointer.jbyte* GetStringUTFChars(JNIEnv *env, jstring string,
jboolean *isCopy);
Returns a pointer to an array of UTF-8 characters of the string. This array is valid until it is released by ReleaseStringUTFChars().
If isCopy is not NULL, then *isCopy is set to one if a copy is made, or it is set to zero if no copy is made.
env: the JNI interface pointer.
isCopy: a pointer to a boolean.
NULL if the operation fails.void ReleaseStringUTFChars(JNIEnv *env, jstring string,
const jbyte *utf);
Informs the VM that the native code no longer needs access to utf. The utf argument is a pointer derived from string using GetStringUTFChars().
env: the JNI interface pointer.
utf: a pointer to a UTF-8 string.
jsize GetArrayLength(JNIEnv *env, jarray array);Returns the number of elements in the array.
env: the JNI interface pointer.jarray NewObjectArray(JNIEnv *env, jsize length,
jclass elementClass, jobject initialElement);
Constructs a new array holding objects in class elementClass. All elements are initially set to initialElement.
env: the JNI interface pointer.
elementClass: array element class.
initialElement: initialization value.
NULL if the array cannot be constructed.jobject GetObjectArrayElement(JNIEnv *env, jarray array,
jsize index);
Returns an element of an Object array.
env: the JNI interface pointer.ArrayIndexOutOfBoundsException: if index does not specify a valid index in the array.void SetObjectArrayElement(JNIEnv *env, jarray array,
jsize index, jobject value);
Sets an element of an Object array.
env: the JNI interface pointer.ArrayIndexOutOfBoundsException: if index does not specify a valid index in the array.
ArrayStoreException: if the class of value is not a subclass of the element class of the array.
jarray NewScalarArray(JNIEnv *env, jsize length);A family of operations to construct a new scalar array object. Table 4-14 describes the specific scalar array constructors. Note that NewScalarArray is not a real function name. You should replace NewScalarArray with one of the actual scalar array constructor routine names from the table.
env: the JNI interface pointer. GetScalarArrayElements(JNIEnv *env,
jarray array, jboolean *isCopy);
A family of functions that returns the body of the scalar array. The result is valid until the corresponding ReleaseScalarArrayElements() 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 until ReleaseScalarArrayElements() is called.
If isCopy is not NULL, then *isCopy is set to one if a copy is made, or it is set to zero if no copy is made.
Table 4-15 describes the specific scalar array element accessors. Note that GetScalarArrayElements is not a real function name, nor is NativeArrayType a real type name. You should replace GetScalarArrayElements with one of the actual scalar element accessor routine names from the table, and replace NativeArrayType with the corresponding native array type for that routine.
Regardless of how boolean arrays are represented in the Java VM, GetBooleanArrayElements() always returns a pointer to jbooleans, with each byte denoting an element (that is, the unpacked representation). All arrays of other types are guaranteed to be contiguous in memory.
env: the JNI interface pointer.
isCopy: a pointer to a boolean.
void ReleaseScalarArrayElements(JNIEnv *env, jarray array,
NativeArrayType elems, jint mode);
A family of functions that informs the VM that the native code no longer needs access to elems. The elems argument is a pointer derived from array using the corresponding GetScalarArrayElements(). If necessary, 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 if elems is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in Table 4-16:
In most cases, programmers pass zero 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 must be used with extreme care.
Table 4-17 describes the specific routines that comprise the family of scalar array disposers. Note that ReleaseScalarArrayElements is not a real function name, nor is NativeArrayType a real type name. You should replace ReleaseScalarArrayElements with one of the actual scalar array disposer routine names from the table, and replace NativeArrayType with the corresponding native array type for that routine.
env: the JNI interface pointer.
elems: a pointer to array elements.
GetScalarArrayRegion(JNIEnv *env, jarray array,
jsize start, jsize len, NativeType *buf);A family of functions that copies a region of a scalar array into a buffer.
Table 4-18 describes the specific scalar array element accessors. Note that GetScalarArrayRegion is not a real function name, nor is NativeType a real type name. You should replace GetScalarArrayRegion with one of the actual scalar element accessor routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.
len: the number of elements to be copied.
ArrayIndexOutOfBoundsException: if (start + len - 1) does not specify a valid index in the array.void SetScalarArrayRegion(JNIEnv *env, jarray array,
jsize start, jsize len, NativeType *buf);A family of functions that copies back a region of a scalar array from a buffer.
Table 4-19 describes the specific scalar array element accessors. Note that SetScalarArrayRegion is not a real function name, nor is NativeType a real type name. You should replace SetScalarArrayRegion with one of the actual scalar element accessor routine names from the table, and replace NativeType with the corresponding native type for that routine.
env: the JNI interface pointer.
len: the number of elements to be copied.
ArrayIndexOutOfBoundsException: if (start + len - 1)does not specify a valid index in the array.jint RegisterNatives(JNIEnv *env, jclass clazz,
char** nameArray, char** sigArray,
void** nativeProcArray);
Registers native methods with the class specified by the clazz argument. The nameArray parameter specifies a NULL-terminated array of strings containing the names of the native methods. The sigArray parameter specifies a NULL-terminated array of strings containing the signatures of the native methods. The nativeProcArray parameter specifies the array of corresponding native method procedure addresses. All three arrays should be the same length.
The native methods nominally must have the following signature:
|
env: the JNI interface pointer.
nameArray: the names of native methods in the class.
sigArray: the signatures of native methods in the class.
nativeProcArray: an array of pointers to native methods.
NoSuchMethodError: if a specified method cannot be found or if the method is not native.jint UnregisterNatives(JNIEnv *env, jclass clazz);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.
env: the JNI interface pointer.jint MonitorEnter(JNIEnv *env, jref ref);
Enters the monitor associated with the underlying Java object referred to by ref.
Each Java objects has a monitor associated with it. If the current thread already owns the monitor associated with ref, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with ref is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1. If another thread already owns the monitor associated with ref, the current thread waits until the monitor is released, then tries again to gain ownership.
env: the JNI interface pointer.
ref: a normal Java object or class object.
jint MonitorExit(JNIEnv *env, jref ref);
The current thread must be the owner of the monitor associated with the underlying Java object referred to by ref. The thread decrements the counter indicating the number of times it has entered this monitor. If as a result the value of the counter becomes zero, the current thread releases the montior.
env: the JNI interface pointer.
ref: a normal Java object or class object.
jint GetJavaVM(JNIEnv *env, JavaVM **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.
env: the JNI interface pointer.
vm: a pointer to where the result should be placed.
Java Native Method Interface Specification (HTML generated by wegis on December 06, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to sl@eng.sun.com