Analyse large heap dump using Eclipse MAT

It is easy to analyse a heapdump when the dump file size is reasonable. But to analyse a large heap dump (specially a dump from production) is not straightforward. I personally prefer the Eclipse Memory Analyser. When I try to load the large dump using the UI it just get crashed. Here are the steps I am showing how to analyse the heap from commandline and then view it using the UI.

Generate index from command-line

My heap dump size is approximately 30gb. To generate index and I provide 22gb memory from commandline. My Java version is 17 (Eclipse requires version 11 or later). And I executed the command in Mac which has 32gb memory. Below is the command.

/Applications/mat.app/Contents/MacOS/MemoryAnalyzer -consolelog -application org.eclipse.mat.api.parse "/Heapdump/analyse.dump" -vm /jdk-17.0.1.jdk/Contents/Home/bin/java -vmargs -Xmx22g -XX:-UseGCOverheadLimit
Above command takes several minutes to finish and below is the output for my heap dump.
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by org.eclipse.osgi.internal.framework.SystemBundleActivator (file:/Applications/mat.app/Contents/Eclipse/plugins/org.eclipse.osgi_3.16.300.v20210525-1715.jar)
WARNING: Please consider reporting this to the maintainers of org.eclipse.osgi.internal.framework.SystemBundleActivator
WARNING: System::setSecurityManager will be removed in a future release
Task: Parsing analyse.dump
[Task: Parsing /Heapdump/analyse.dump
[
Subtask: Scanning /Heapdump/analyse.dump
[....................
[INFO] Wrote threads call stacks to /Heapdump/analyse.dump.threads
[....................
[INFO] Heap /Heapdump/analyse.dump.dump contains 263,511,984 objects
[....................
Subtask: Extracting objects from /Heapdump/analyse.dump.dump
[................................................................................Task: Removing unreachable objects
[
Subtask: Searching for unreachable objects
[
Subtask: Marking reachable objects
[.
Subtask: Re-indexing objects
[.
[INFO] Removed 174,619 unreachable objects using 14,634,072 bytes
[..
Subtask: Re-indexing classes
[...
Subtask: Writing /Heapdump/analyse.dump.idx.index
[....
Subtask: Writing /Heapdump/analyse.dump.o2c.index
[.....
Subtask: Writing /Heapdump/analyse.dump.a2s.index
[......
Subtask: Re-indexing outbound index
[.......
Subtask: Writing /Heapdump/analyse.dump.inbound.index
[........
Subtask: Writing /Heapdump/analyse.dump.outbound.index
[.........
Subtask: Writing /Heapdump/analyse.dump.o2hprof.index
[.........Task: Calculating Dominator Tree
[
Subtask: Dominator Tree calculation
[
Subtask: Depth-first search
[....................
Subtask: Computing dominators
[..............................................
Subtask: Calculate retained sizes
[............................................................
Subtask: Create dominators index file
[................................................................................]

Load generated index into UI

This command basically generates several index files ends with analyse.outbound.index and a single file analyse.threads. As you have the index generated, it would be much easier to load the dump into the UI. But before doing that you need to point Eclipse MAT to a java that is version 11 or greater, and also provide some memory to it. I provide 22gb memory to it. Here is you you can configure. 1. Open the /Applications/mat.app/Contents/Info.plist and update the -vm path.
<!-- To use a specific Java version (instead of the default) uncomment the following option and 
		edit it to add a VM. Installed VMs can be found via $/usr/libexec/java_home -V
		<string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java</string>
	-->
<string>-vm</string><string>/jdk-17.0.1.jdk/Contents/Home/bin/java</string>
2. Update -vm in /Applications/mat.app/Contents/Eclipse/MemoryAnalyzer.ini. Make sure you put it before the -vmargs. And also update how much memory you want to put. Here is mine:
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.6.200.v20210416-2027.jar
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.2.200.v20210527-0259
-vm /jdk-17.0.1.jdk/Contents/Home/bin/
-vmargs
-Xmx22g
-Dorg.eclipse.swt.internal.carbon.smallFonts
-XstartOnFirstThread
All set! now open your Eclipse MAT, click Open a Heap Dump, and then select the analyse.dump to open. This will take a few minutes to generate a report which later you can analyse. You could generate the report from the command line too. But as my UI could do it for me I didn't try the commandline.


Notes:

If you do not provide the -vm from the commandline you'd end up with error like below:
2022-01-04 19:08:16.855 MemoryAnalyzer[23910:1364729] Cannot find executable for CFBundle 0x7f88b3508420 </Library/Internet Plug-Ins/JavaAppletPlugin.plugin> (not loaded)
Image showing error: The JVM shared library "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/../lib/server/libjvm.dylib" does not contain the JNI_CreateJavaVM symbol.



If you do not provide the -vm in Info.plist, You'd see the same error while opening the Eclipse MAT ui.

Comments