Typically, in order for the JVM to discover your native functionality, they are named in a certain way. For example, for java.lang.Object.registerNatives, the corresponding C function is named java_java_lang_object_ Registernatives. By using registernatives(or, more specifically, theJNI function registernatives) , you can name any C function you want.
Here is the relevant C code ( from OpenJDK6):
Static Jninativemethod methods[] = {
{"hashcode", "() I", (void *) &jvm_ Ihashcode},
{"wait", "(J) V", (void *) &jvm_monitorwait} ,
{"notify", "() V", (void *) &jvm_ Monitornotify},
{"notifyall", "() V", (void *) &jvm_ Monitornotifyall},
{"clone", "() ljava/lang/object; " , (void *) &jvm_clone},
};
Jniexport void Jnicall
Java_java_lang_object_registernatives (jnienv *env, Jclass CLS)
{
(*env)->registernatives (env, Cls,methods, sizeof (methods)/sizeof (Methods[0]));
}
(Please note thatObject.getclass is not on the list ; It is still known as the "standard" name of Java_java_lang_object_getclass. for the listed features, the associated C function, as in this table, is more handy than writing a bunch of forwarding functions.
If you are embedding Java in a C program and want to link to this function within the program itself, registering local functions is also useful because these are not usually found through the standard method lookup mechanism. Registering local functions can also be used to "rebind" a local method to another C function ( which would be useful if your program supports dynamic loading and unloading of modules).
We encourage you to read the JNI book, which says there are other things, and so on.
The role of the Registernatives () method of the Object