从命令行运行Java应用程序时如何调用JNI_CreateJavaVM [英] How is JNI_CreateJavaVM invoked when running a java app from the command line

查看:60
本文介绍了从命令行运行Java应用程序时如何调用JNI_CreateJavaVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解进入 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆