Question

If I have a class inside a JAR (compiled with mvn assembly:assembly) which I'm trying to profile, what's the command to get a valid core dump which I can use with jhat or the Eclipse Memory Analyzer?

I tried running this:

java -agentlib:hprof=heap=sites,cpu=samples,file=profile.hprof,format=b -jar the-jar.jar

and the core dump is created when I stop the process.

But neither jhat or the Eclipse Memory Analyzer recognize this as a valid dump.

jhat gives me this warning:

Resolving 0 objects...
WARNING:  hprof file does not include java.lang.Class!
WARNING:  hprof file does not include java.lang.String!
WARNING:  hprof file does not include java.lang.ClassLoader!

Also reading through the hprof documentation, I see that I must pass the class name. How do I do that when it's inside the JAR?

Was it helpful?

Solution

The fact the the class was loaded from a JAR file is not relevant for the heap dump.

You can use jmap to get usable HPROF heap dumps without modifying the start command.

jmap -heap:format=b <pid>

where is the process id that you can get the with the jps command line utility. Both executables are part of the JDK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top