Memory analysis with Eclipse 3.5
Eclipse Galileo (3.5) will be released on June 24, 2009 and comes with a really good and easy-to-use JVM Memory Analyzer.
Here is a quick memory analysis walkthrough :
Creating a heap dump
You can dump the memory of a Java process anytime using jmap which is included in the JDK.
To ensure jmap is working for you, get your java process ID :
ps -Af | grep java
or, if you want to dump eclipse memory :
ps -Af | grep eclipse
Then ask jmap to output a memory summary :
jmap <pid>
Jmap output :
Attaching to process ID 356, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_16-133
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
(...)
If you get an error, take a look at the end of this post for a few tips.
Ok so jmap works for you. Now dump the complete memory in a file :
jmap -heap:format=b <pid>
There is now a file named heap.bin in your current directory.
Installing Memory Analyzer
Start Eclipse, use Help->Install new software… and select Memory Analyzer from the Galileo update site :
Opening the dump
Switch to Memory Analysis perspective
Use File->Open Head Dump… and select heap.bin
You can now digg into your application heap memory and ensure that no objects is using more memory than it should. Memory Analyzer also includes really nice features like an automatic leak search :
Have fun and catch the leaks
jmap tips
If you have problems running jmap, try the following tips :
- Be sure to use the jmap binary packaged with the JVM you are running : jmap from a Java 5 JDK will not be able to dump memory from a Java 6 VM : you’ll get this stacktrace :
Attaching to process ID 704, please wait...
Exception in thread "main" java.lang.RuntimeException: gHotSpotVMTypes was not initialized properly in the remote process; can not continue
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:111)
at sun.jvm.hotspot.HotSpotTypeDataBase.(HotSpotTypeDataBase.java:68)
at sun.jvm.hotspot.MacOSXTypeDataBase.(MacOSXTypeDataBase.java:35)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:560)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:481)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:319)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:146)
at sun.jvm.hotspot.tools.JMap.main(JMap.java:128)
- jmap needs high system privileges. If you can’t attach to a java process with the following error :
Attaching to process ID 704, please wait...
attach: task_for_pid(704) failed (5)
Error attaching to process: Error attaching to process, or no such process
…, try to use sudo : sudo jmap <pid>. (See Ken Sipe's blog for additional information)





