The role of the Registernatives () method of the Object

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.