In this post, I will talk about various tools that help you analyze your Java application’s behavior when something has went wrong. This is not an exhaustive list but just the tools that I have used at some point of time and found useful.
This is a tool bundled within JDK and useful for connecting to either running java processes locally/remotely or connecting to a core file.
- Heap Dump: jmap -dump:format=b,file=/tmp/heap.bin PID
This command dumps the heap which can be later analyzed using other tools mentioned below to analyze the application’s memory usage.
- Heap Summary: jmap -heap PID
This command dumps the current memory usage with the division of heap space (Young Gen/Old Gen/Survivor Space) depending on the Garbage Collector used
This tool is also included in JDK and useful to get details of a running application.
- Thread details: jstack -l PID
This command will print the stack trace of all the threads running in the java process. This can be used to get total threads with priority details of those threads.
Bundled within JDK, this tool can be used to analyze the heap dump
- Heap Dump Analysis: jhat Heap_Dump_File
This command will analyze the heap dump file extracting all the object details and publish this details to a web server running on default 7000 port (can be changed using options) where you can see all the object details and even run Object Queries (OQL) against the heap dump.
This tool is also available within JDK and provides UI to connect to running java process and can be used to get a heap dump or used as a profiler.
Memory Analyzer Tool is an eclipse plugin used for heap dump analysis and very useful to find memory leaks or checking the heap usage of the application. More about MAT: MAT. This tool also provides the details of unreachable objects useful to study the behavior of Garbage Collector.
When the Java application is started, it can be asked to dump garbage collector logs using options like –XX:+PrintGCDetails –XX:+PrintGCTimeStamps and -Xloggc:logFile to redirect the logs to a file for further analysis.
GCViewer reads the GC logs to provide a summary of how the garbage collector performed.