By user13377336 on Aug 11, 2006
Digging OutOfMemoryError in a Java application was very time consuming until I read about the Java Heap Analysis Tool (JHAT). JHAT is a part of jdk's forthcoming feature release Java SE 6.
I was recently tracking down OOMError and with the help of JHAT, I was quickly able to find out which class objects are a cause for this leak. With JHAT, all the objects created on the heap can be viewed in a very user friendly manner. In a nutshell, there are 2 steps by which you can analyze the heap of a java process.
- First, Dump the heap into a file. For java processes which throw OOME, you could use -XX:+HeapDumpOnOutOfMemoryError option to 'java' and the heap will dumped after the OOME from the core file it generates. For the cases, where you do not see a OOME but still want to know whats on your heap, 'jmap' or 'jconsole' can be used. These utilities dump the heap into a file.
- Secondly, you use 'jhat' utility (included in Java SE 6 kit) to create a web based interface to view your heap data from the file generated in first step. This interface provides lot of very useful information about the objects such as reference counts, weak references etc.
I was really impressed with the kind of information you get from this tool. Especially, the querying tool is very useful and innovative. This tool is must to have in the kitty for people working on Optimizations and Performance issues.
For more detailed information, visit Alan's blog.