问题
I am trying to understand the point of entry into JVM. After doing my research I have learnt that JNI_CreateJavaVM
(at least in HotSpot JVM) is the method that is called to launch the JVM.
My question now is who calls the JNI_CreateJavaVM
method ? I tried looking at the JDK source here JDK7 Hotspot. But it is not very clear and I was not able to find any 'int main
' method.
Lets say I create a simple java program and compile it to Hello.java
. Now when I run 'java Hello
' from the command line, what exactly happens? What is the first method called?
ANSWER: @apangin definitely pointed me in the right direction(see comment below). The main method is located here main method for java launcher. And from there it calls JLI_launch from where the JNI_CreateJavaVM method is invoked eventually.
回答1:
java (java.exe) is the launcher - the small program written in C.
The sources are in JDK repository, not HotSpot.
Java launcher first locates an installed JRE, creates a new virtual machine via JNI_CreateJavaVM
, searches for the main
method using JNI, and finally invokes this method with JNI CallStaticVoidMethod
function.
来源:https://stackoverflow.com/questions/30093539/how-is-jni-createjavavm-invoked-when-running-a-java-app-from-the-command-line