AaronBeers
AaronBeers

Reputation: 43

Can the main method used to start a JVM be determined from a core file?

On startup, a JVM finds a user specified class and runs the method contained therein with the signature "public static void main(String[])".

The thread executing the main method can obviously terminate while the JVM continues to run other threads that the main method had spawned. Therefore, extracting a Java stack trace (e.g. "jstack" output) is not sufficient to find out the initial class from which the JVM was started. I'm also not aware of other commands typically included in a JDK that will extract that information from a running JVM or core file.

I'm working on some automation for analysis of core files, and it would be helpful to understand the class from which a JVM was started, even when no threads are running code under that class at the time the core file was created.

Question: Do JVMs in general (and both Oracle and OpenJDK specifically) keep track of the class from which the main method was called?

Upvotes: 0

Views: 98

Answers (1)

apangin
apangin

Reputation: 98334

jinfo utility (included in OpenJDK and Oracle JDK) can tell the main class. It works both for live JVMs and for core dumps.

E.g. here is how to find the Java command line from the core dump:

jinfo /path/to/java core.1234 | grep sun.java.command

Starting from JDK 9 jinfo works only for live processes while jhsdb jinfo works for core dumps.

Upvotes: 2

Related Questions