问题描述
我试图了解进入 JVM 的切入点.经过研究,我发现JNI_CreateJavaVM
(至少在 HotSpot JVM 中)是启动JVM的方法.
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.
我现在的问题是谁调用了JNI_CreateJavaVM
方法?我尝试在此处 JDK7热点中查看JDK源.但这不是很清楚,我找不到任何"int main
"方法.
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.
可以说我创建了一个简单的Java程序并将其编译为Hello.java
.现在,当我从命令行运行"java Hello
"时,究竟发生了什么?什么叫第一种方法?
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?
答案:@apangin肯定会向我指出正确的方向(请参见下面的评论).主要方法位于此处 main Java启动器的方法.然后从那里最终调用JNI_CreateJavaVM方法的地方调用JLI_launch.
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.
推荐答案
java(java.exe)是启动器-用C编写的小程序.
源文件在JDK存储库中,而不是HotSpot中.
java (java.exe) is the launcher - the small program written in C.
The sources are in JDK repository, not HotSpot.
Java启动器首先找到一个已安装的JRE,通过JNI_CreateJavaVM
创建一个新的虚拟机,使用JNI搜索main
方法,最后使用JNI CallStaticVoidMethod
函数调用该方法.
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.
这篇关于从命令行运行Java应用程序时如何调用JNI_CreateJavaVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!