[英]How can I find out the class containing the main() method inside the OpenJDK JVM (Hotspot) code?
In thread.cpp
the method Threads::create_vm
is defined which initializes the main thread and the VM thread . 在
thread.cpp
,定义了Threads::create_vm
方法来初始化主线程和VM线程 。 While I found this code location, I would like to know how the main thread knows which Java main()
method to execute, ie, in which class to look for, but I couldn't find that out. 当我找到此代码位置时,我想知道主线程如何知道要执行哪个Java
main()
方法,即在哪个类中查找,但我找不到。
As soon as possible after the VM creation (or even before), I would like to obtain the class name (and its package) of the class that contains the main method (and as a first step, just printf
it). 在创建VM之后(或什至之前),我想尽快获取包含main方法的类的类名称(及其包)(第一步,只需对其进行
printf
)。 I thought about looking at the bottom-most entry in the stack frame of the main thread , yet the stack frame does not yet exist during Threads::create_vm
. 我考虑过要查看主线程堆栈框架中最底层的条目,但是在
Threads::create_vm
期间该堆栈框架尚不存在。 Can someone help me pointing me in the right direction? 有人可以帮我指出正确的方向吗?
tl;dr: I want to modify the OpenJDK source to print the class name of the class containing the Java main()
method, how to do this? tl; dr:我想修改OpenJDK源代码以打印包含Java
main()
方法的类的类名,该怎么做?
When VM is created, it does not know what class/method will be executed in it. 创建VM后,它不知道将在其中执行什么类/方法。 It is a job of a launcher to invoke main Java method using one of JNI functions .
使用JNI函数之一调用主Java方法是启动程序的工作 。 BTW, this method does not necessarily need to be called
main
. 顺便说一句,此方法不一定需要称为
main
。
I want to modify the OpenJDK source to print the class name of the class containing the Java main() method, how to do this?
我想修改OpenJDK源代码以打印包含Java main()方法的类的类名,该怎么做?
You probably want to modify Java launcher then. 您可能想要修改Java启动器。 See java.c .
参见java.c。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.