简体   繁体   English

如何找到OpenJDK JVM(热点)代码中包含main()方法的类?

[英]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.

相关问题 在OracleJDK可以的时候,OpenJDK在jar中找不到主类 - OpenJDK cannot find main class in jar while OracleJDK can Hotspot JVM 的 JITed 代码中可以设置断点吗? - Can breakpoints be placed in JITed code in the Hotspot JVM? 怎么可能在 class 中包含 main 方法,其中包含在 main 中调用的实例的定义? - How is it possible to have the main method inside the class where its containing the definition of the instance being called inside the main? 如何确定代码是否在 JUnit 测试中运行? - How can I find out if code is running inside a JUnit test or not? 如何找出JVM上次收集垃圾的时间? - How can I find out the time the JVM last garbage collected? 如何确定Hotspot JVM决定再次重新编译JIT:ed代码的原因? - How can I determine why the Hotspot JVM decided to re-compile already JIT:ed code a second time? 如何调试Eclipse中的openjdk 9(主要是热点)源代码? - How to debug the openjdk 9 (mainly the hotspot) source code in Eclipse? Java 9在Ubuntu上提供了“找不到主类”的信息,但文件在Windows和Mac上都可以// //如何在OpenJDK中找到主类 - Java 9 gives “Main Class not found” ob Ubuntu, but file works on Windows and Mac // how to find main Class in OpenJDK 编译时,Maven找不到sun.jvm.hotspot - Maven can't find sun.jvm.hotspot when compiling 我可以调用传递jvm参数的main方法吗? - Can I invoke a main method passing jvm parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM