Java JNI implementation principle (5) JNI method interpretation call

Source: Internet
Author: User

Hotspot mainly has two kinds of interpreters. The Template Intepreter is also called the asm interprete interpreter. The introduction below is basically based on the template interpreter. We will give an example of invokespecial, the following code explains invokespecial using the templateTable method [cpp] void TemplateTable: invokespecial (int byte_no) {transition (vtos, vtos); assert (byte_no = f1_byte, "use this argument"); prepare_invoke (rbx, noreg, byte_no); // do the call _ verify_oop (rbx); _ profile_call (rax); _ jump_from_interpreted (rb X, rax);} The TemplateTable: prepare_invoke-> TemplateTable: resolve_cache_and_index in the prepare_invoke function can be viewed in detail 1. first, check whether the constantpoolcache saves the method pointer to the constantpoolcache of the thread. If there is a method, jcc will be used to jump to the Label resolved, lable resolved ends the bind to the end of the function after the first running of the method. 2. if the cache does not exist, you will try to use interpreterRuntime: resolve_invoke to find the correct method and save it to the constant pool cache [cpp] case Bytecodes: _ invokevirtual: case Bytecodes :: _ invokespecial: case Bytecodes: _ invokestatic: case Bytecodes: _ invokeinterface: entry = break (address, InterpreterRuntime: break); break; and interpreterRuntime: resolve_invoke --> LinkResolver:: resolve_invoke --> LinkResolver: resolve_s Pecial_call --> LinkResolver: linktime_resolve_special_method --> LinkResolver: resolve_method call LinkResolver: resolve_method to find the actual call method, use runtime_resolve_special_method to store the method pointer As methodhandle in CallInfo and return it to InterperterRuntime: resolve_invoke. At the same time, in the case of CallInfo: set_common setting-Xcomp, determine whether. We can see that the method prepare_invoke has found the methodoop pointer and stored it in the Register rbx function jump_from_interpreted [cpp] void InterpreterMacroAssembler: jump_from_interpreted (Register method, Register temp) {Register (); if (JvmtiExport: threads () {Label run_compiled_code; // JVMTI events, such as single-stepping, are implemented partly by avoiding running // compiled code in threads for whi Ch the event is enabled. check here for // interp_only_mode if these events CAN be enabled. get_thread (temp); // interp_only is an int, on little endian it is sufficient to test the byte only // Is a cmpl faster (ce cmpb (Address (temp, JavaThread :: interp_only_mode_offset (), 0); jcc (Assembler: zero, run_compiled_code); jmp (Address (method, methodOopDesc: interpreter_entry_offset (); bind (run_compil Ed_code);} jmp (Address (method, methodOopDesc: from_interpreted_offset ();} The _ from_interpreted_entry in methodoop is redirected, that is, in the previous blog (java JNI (4) initialize the JNI method), The generate_native_entry mentioned in this blog does not involve too many calls to the native method, instead, the asm interpreter explains how to link the corresponding method and find the entry for processing the method.

Related Article

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.