How is JNI_CreateJavaVM invoked when running a java app from the command line

China☆狼群 提交于 2021-02-08 09:58:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!