Acquire Heap Dump from MAT (Memory Analyzer Tool)

aurelien.pupier's picture
Blog Categories: 

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.

  1. Starting the processus requires only two clicks. In the menu, choose "File->Acquire Heap Dump..."
  2. The wizard that will guide you prompts. You can see running java processes.
  3. 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.
  4. 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.)
  5. Be careful: a JDK is required, a JRE is not enough. Are you really the end user that solves my memory issues?
  6. Apply the configuration of the Heap Dump Provider and click OK
  7. 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 ;)
  8. Click on Finish
  9. 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.
  10. A new dialog prompts, for a quick overview, keep "Leak Suspects Report" checked.
  11. Click Finish
  12. 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.