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.

Memory chart

Memory chart

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 :

Installing Memory Analyzer

Installing Memory Analyzer

Opening the dump

Switch to Memory Analysis perspective

Perspectives : select Memory Analysis

Perspectives : select Memory Analysis

Use File->Open Head Dump… and select heap.bin
Memory summary

Memory summary

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 :

Leak suspects report

Leak suspects report

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(
    at sun.jvm.hotspot.HotSpotTypeDataBase.(
    at sun.jvm.hotspot.MacOSXTypeDataBase.(
    at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(
    at sun.jvm.hotspot.bugspot.BugSpotAgent.go(
    at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(

  • 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)

  • Pingback: agilesWissen » 5 short Eclipse 3.5 links()

  • Burçak Otlu

    I’m trying to run jmap within eclipse ide (kepler); however when I click on acquire heap dump there is no pid to select although my program is running.

    On the other hand since eclipse is using its own jdk I don’t know how to configure IBM or HDROF heap dump providers.

    By the way my OS is windows.

    Any idea to solve this problem?

    Thanks in advance.