Acquire Heap Dump from MAT (Memory Analyzer Tool)
MAT, which stands for Memory Analyzer Tool, is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory consumption. The project got integrated into the release train with Helios and comes with great features. I will highlight one of them, which is pretty useful in debug/development mode. I'm talking about the ability to acquire Heap Dump directly inside MAT.
- Starting the processus requires only two clicks. In the menu, choose "File->Acquire Heap Dump..."
- The wizard that will guide you prompts. You can see running java processes.
- Click on Configure... A new dialog will be displayed. You can specify here which provider to use to make the heap dump. You will see that two providers are available by default:
- jmap tools (for Hotspot VM for instance)
- an helper IBM VM.
- I'm using an Hotspot VM, so I need to specify only the JDK_HOME of my JDK. (This step is required only the first time.)
- Be careful: a JDK is required, a JRE is not enough. Are you really the end user that solves my memory issues?
- Apply the configuration of the Heap Dump Provider and click OK
- Now you're back to the first dialog, select the process that you want to analyze. You will notice at the bottom that a path is automatically generated for the heap dump file. By the way I recommend to choose a folder containing only dumps. MAT generates a lot of other files aside it (for indexation purpose I assume). So if you don't want that it pollutes your home folder (which is used by default), you know what you have to do ;)
- Click on Finish
- Wait for the heap dump to be written to the disk and parsed by MAT. These operations can take some time for huge java heap size.
- A new dialog prompts, for a quick overview, keep "Leak Suspects Report" checked.
- Click Finish
- All right, you have the Heap Dump opened in MAT, ready to be analyzed!
In effect, this way requires that the process is still running. It is a debug/development use case. You still need dumps on OutOfMemoryError for production environment. You can find some information on the way to do that on the MAT wiki. To learn more things about MAT, I recommend you to follow the MAT webinar which happens on September 8th.