In thread.cpp
the method Threads::create_vm
is defined which initializes the main thread and the VM thread. While I found this code location, I would like to know how the main thread knows which Java main()
method to execute, i.e., in which class to look for, but I couldn't find that out.
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). 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
. 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?
When VM is created, it does not know what class/method will be executed in it. It is a job of a launcher to invoke main Java method using one of JNI functions. BTW, this method does not necessarily need to be called 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?
You probably want to modify Java launcher then. See java.c.