While debugging a production crash with huge Xms(24GB) and Xmx(30GB) sizes, we got a heap dump of 18GB to analyse for out of memory root cause. We were not having any big machines to run the MAT(Memory Analysis Tool) to analyse the heap dump and all the time we were getting out of memory in MAT itself in midway of analysis. While searching on google we got few good references like this but there also we found we have to put huge Xms and Xmx for MAT itself and our laptops were not well equipped to do so.
We had 8GB laptops to analyse a 18GB dump and we had to set garbage collection alogoritms to keep the MAT getting out of memory while running it in command line mode instead of GUI as it takes more memory to analyse.
Below are few steps which you need to follow to analyse the huge heap dumps with out Out of memory errors in MAT.
1. Download the latest MAT for here
2. cd to the MAT installation folder and open the MemoryAnalyzer.ini file and update below settings.
Note: Here we are using a 8GB laptop so settings are set accordingly. If you have higher configuration or lower you have to set the Xms and Xmx accordingly.
-Xms6144m -Xmx8192m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+CMSClassUnloadingEnabled -XX:+UseCMSInitiatingOccupancyOnly
3. Make sure your hard disk where the dump file is stored is having twice the free space as of the size of dump file.
Example: I used a 18GB heap dump and had to make sure 36GB of free space is available as it generates many files in the process of finding the leak suspects.
4. Open command prompt in administrator mode and cd to the MAT installation directory and run below commands to start the analysis.
./ParseHeapDump.sh /opt/heap_dump/jvm.hprof org.eclipse.mat.api:suspects ./ParseHeapDump.sh /opt/heap_dump/jvm.hprof org.eclipse.mat.api:overview ./ParseHeapDump.sh /opt/heap_dump/jvm.hprof org.eclipse.mat.api:top_components
ParseHeapDump.bat D:\heap_dump\jvm.hprof org.eclipse.mat.api:suspects ParseHeapDump.bat D:\heap_dump\jvm.hprof org.eclipse.mat.api:overview ParseHeapDump.bat D:\heap_dump\jvm.hprof org.eclipse.mat.api:top_components
The final output of above commands will be very small and you can actually mail it to others. It will come like below screenshot.
Leak suspects generated by MAT after 12 hours of analysis.