呼叫JavaCalls::call()方法來執行Java方法

mangcubwwd發表於2022-05-04

之前多次提到接觸到呼叫JavaCalls::call()方法來執行Java方法,如:

(1)Java主類裝載時,呼叫JavaCalls::call()方法執行的Java方法checkAndLoadMain()方法

(2)類的初始化過程中,呼叫JavaCalls::call()方法執行的Java方法<clinit>方法

可以看出,JavaCalls::call()方法為虛擬機器呼叫Java方法提供了便利,Java虛擬機器有invokestatic、invokedynamic、invokestatic、invokespecial、invokevirtual幾種方法呼叫指令,每個負責呼叫不同的方法,而這些方法都定義在JavaCalls類中,如下:

原始碼位置:/src/share/vm/runtime/javaCalls.hpp
// All calls to Java have to go via JavaCalls. Sets up the stack frame
// and makes sure that the last_Java_frame pointers are chained correctly.
 
class   JavaCalls: AllStatic {
    static   void   call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
   public  :
    // Optimized Constuctor call
    static   void   call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
 
    // call_special
    // ------------
    // The receiver must be first oop in argument list
    // receiver表示方法的接收者,如A.main()呼叫中,A就是方法的接收者
    static   void   call_special(JavaValue* result, KlassHandle klass, Symbol* name,Symbol* signature, JavaCallArguments* args, TRAPS);
 
    static   void   call_special(JavaValue* result, Handle receiver, KlassHandle klass,Symbol* name, Symbol* signature, TRAPS);   // No args
    static   void   call_special(JavaValue* result, Handle receiver, KlassHandle klass,Symbol* name, Symbol* signature, Handle arg1, TRAPS);
    static   void   call_special(JavaValue* result, Handle receiver, KlassHandle klass,Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69929371/viewspace-2890683/,如需轉載,請註明出處,否則將追究法律責任。

相關文章