views:

6320

answers:

5

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?

+1  A: 

You can use HAT, The Java Heap Analysis Tool

CMS
I can't accept your answer until you've updated the link.
Nick Stinemates
Done, sorry for the typo.
CMS
+12  A: 

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.

Cowan
I'd just like to add a +100 for Eclipse Memory Analyzer. I'm currently attempting to sift thru a 400mb+ heap dump file, and it took jhat more than 70 minutes to read the file, before it caused a complete JVM crash. EMA is able to open it up in < 5 minutes.
matt b
Too bad MAT often fails to read heaps... :-(
Vladimir Dyuzhev
A: 

Just get the Eclipse Memory Analyzer. There's nothing better out there and it's free.

JHAT is only usable for "toy applications"

kohlerm
JHAT is necessary for impressing those "l33t" hackers who hand-build a BSD distro starting with the LILO. Wait... they'd never use java anyway. :-)
James Schek
+1  A: 

You can also use HeapWalker from the Netbeans Profiler or the Visual VM stand-alone tool. Visual VM is a good alternative to HAT as it is stand alone, but is much easier to use than HAT.

You need Java 6+ to fully use Visual VM.

James Schek
You should add a note that this is for Java 6 and 7 only.
Nick Stinemates
AFAIK, HeapWalker and VisualVM do not require Java 6/7 to read HPROF files.
James Schek
I just tried to load it with Java 5 and it said 'Please use Java 6 or 7'What am I doing wrong?
Nick Stinemates
Hmm. Perhaps you have to run Java 6, but can read a Java 5 HPROF (maybe that's how I got it to work). I know you cannot create a heap-dump from Visual VM on an app running Java 5. Will update.
James Schek