Reputation: 44140
I have a production server running with the following flag: -XX:+HeapDumpOnOutOfMemoryError
Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but no way to get any useful information from it.
Any ideas?
Upvotes: 280
Views: 474541
Reputation: 1035
Opening it with JProfiler helped me a lot.
Shows you the Heap Walker with all the threads, packages, classes and relations between them, so you can navigate, walk the incoming/outgoing references and visualize.
There is a plenty of guides on using it, so getting the general idea on dump analyzing should be enough to start using it.
It requires a paid license, but has 10 days of free trial.
Upvotes: 0
Reputation: 11
You may get some value out of the Oracle Java Platform, Standard Edition Troubleshooting guide, which details the HPROF: A Heap/CPU Profiling Tool. It can be used to receive relevant information from from the JVM, like CPU usage sampling/times and memory allocation. You can take a look into that file with the tool and glean some high-level information.
$ java -agentlib:hprof ToBeProfiledClass
$ java -Xrunhprof[:options] ToBeProfiledClass
Shows allocation for various parts of the program
$ java -agentlib:hprof=heap=sites ToBeProfiledClass
$ java -agentlib:hprof=help
The files are usually large and docs recommend JHAT for visualizing the outputs of the heap dump (Also mentioned above). Can figure out what parts of your program are eating your heap memory and maxing out CPU usage.
Upvotes: 0
Reputation: 606
I'm using IntelliJ IDEA profiler in Ultimate version.
In IDEA, press the Shift button twice.
In Actions
tab write - "profiler".
Choice row "profiler" with icon.
Then Open snapshot..
button.
Upvotes: 0
Reputation: 554
I personally prefer VisualVM. One of the features I like in VisualVM is heap dump comparison. When you are doing a heap dump analysis there are various ways to go about figuring out what caused the crash. One of the ways I have found useful is doing a comparison of healthy vs unhealthy heap dumps.
Following are the steps you can follow for it :
link : https://visualvm.github.io
Upvotes: 16
Reputation: 27677
If you want to do a custom analysis of your heapdump then there's:
This library is fast but you will need to write your analysis code in Java.
From the docs:
Upvotes: 9
Reputation: 827316
You can use JHAT, The Java Heap Analysis Tool provided by default with the JDK. It's command line but starts a web server/browser you use to examine the memory. Not the most user friendly, but at least it's already installed most places you'll go. A very useful view is the "heap histogram" link at the very bottom.
ex: jhat -port 7401 -J-Xmx4G dump.hprof
jhat
can execute OQL "these days" as well (bottom link "execute OQL")
Upvotes: 91
Reputation: 17960
You can also use HeapWalker from the Netbeans Profiler or the Visual VM stand-alone tool. Visual VM is a good alternative to JHAT as it is stand alone, but is much easier to use than JHAT.
You need Java 6+ to fully use Visual VM.
Upvotes: 39
Reputation: 2624
Just get the Eclipse Memory Analyzer. There's nothing better out there and it's free.
JHAT is only usable for "toy applications"
Upvotes: 15
Reputation: 37543
If you want a fairly advanced tool to do some serious poking around, look at the Memory Analyzer project at Eclipse, contributed to them by SAP.
Some of what you can do is mind-blowingly good for finding memory leaks etc -- including running a form of limited SQL (OQL) against the in-memory objects, i.e.
SELECT toString(firstName) FROM com.yourcompany.somepackage.User
Totally brilliant.
Upvotes: 251