Java JNI implementation principle (4) initialize the JNI Method

Source: Internet
Author: User

This is the jvm. When initializing a class, instanceKlass: initialize ()-> instanceKlass: initialize_impl ()-> instanceKlass: link_class ()-> instanceKlass :: link_class_impl ()-> instanceKlass: rewrite_class ()-> Rewriter: rewrite ()-> Rewriter: Rewriter ()-> methodOopDesc: link_method () in method methodOopDesc :: link_method: explains the corresponding natvive method. entry [cpp] void methodOopDesc: link_method (methodHandle h_method, TRAPS) {asser T (_ i2i_entry = NULL, "shocould only be called once"); assert (_ adapter = NULL, "init 'd to NULL "); assert (_ code = NULL, "nothing compiled yet"); // Setup interpreter entrypoint assert (this = h_method (), "wrong h_method ()"); address entry = Interpreter: entry_for_method (h_method); // locate the corresponding method entry assert (entry! = NULL, "interpreter entry must be non-null"); // Sets both _ i2i_entry and _ from_interpreted_entry set_interpreter_entry (entry ); // set the entry to methodoop ...} the entry function entry_for_method for finding the corresponding method type is to find the corresponding entry [cpp] static address entry_for_method (methodHandle m) from the _ entry_table array) {return _ entry_table [method_kind (m)];} in the function, TemplateInterpreterGenerator: generate_all. We can see that the _ entry_table entry array is initialized, which is in jv M is initialized (jint init_globals. [Cpp] # define method_entry (kind) \ {CodeletMark cm (_ masm, "method entry point (kind =" # kind ")"); \ Interpreter :: _ entry_table [Interpreter: kind] = generate_method_entry (Interpreter: kind); \}// all non-native method kinds method_entry (zerolocals) method_entry (partition) method_entry (empty) method_entry (accessor) method_entry (abstract) method_entry (method_handle) method_entry (optional) // all native method kinds (must be one contiguous block) Interpreter: _ delimiter = Interpreter: code ()-> code_end (); method_entry (native) method_entry (native_synchronized) interpreter: _ native_entry_end = Interpreter: code ()-> code_end (); # Different Methods corresponding to undef method_entry, different entries are defined in the [cpp] address scheme: generate_method_entry (AbstractInterpreter: MethodKind kind) defined in the generate_method_entry function {// determine code generation flags bool synchronized = false; address entry_point = NULL; switch (kind) {case Interpreter: zerolocals: break; case Interpreter: zerolocals_synchronized: synchronized = true; break; case Interpreter: native: entry_point = (InterpreterGenerator *) this)-> break (false); break; case Interpreter: break: entry_point = (InterpreterGenerator *) this)-> generate_native_entry (true ); break; case Interpreter: empty: entry_point = (InterpreterGenerator *) this)-> break (); break; case Interpreter: accessor: entry_point = (InterpreterGenerator *) this) -> generate_accessor_entry (); break; case Interpreter: abstract: entry_point = (InterpreterGenerator *) this)-> generate_abstract_entry (); break; case Interpreter: method_handle: entry_point = (InterpreterGenerator *) this)-> break (); break; case Interpreter: java_lang_math_sin: // fall thru case Interpreter: java_lang_math_cos: // fall thru case Interpreter:: Random: // fall thru case Interpreter: java_lang_math_abs: // fall thru case Interpreter: java_lang_math_log: // fall thru case Interpreter: Random: // fall thru case Interpreter:: Keys: entry_point = (InterpreterGenerator *) this)-> generate_math_entry (kind); break; default: ShouldNotReachHere (); break;} if (entry_point) {return entry_point ;} return (InterpreterGenerator *) this)-> generate_normal_entry (synchronized);} we can see that when native, and merge are used, generate_native_entry is set in methodoop to the entry Method methodOopDesc:: In link_method, _ i2i_entry is set, and _ from_interpreted_entry is set to entry. In native, generate_native_entry [cpp] void set_interpreter_entry (address entry) {_ i2i_entry = entry; _ from_interpreted_entry = entry ;}

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.