Taking Heap Dumps From a JVM

Liferay Support does not recommend or endorse specific third-party products over others. Liferay is not responsible for any instructions herein or referenced regarding these products. Any implementation of these principles is the responsibility of the subscriber.

When a system runs into out of memory errors or other memory related issues it is helpful to have a heap dump.

A heap dump is a snapshot of all the objects that are currently in the JVM. The Java heap is the space allocated to the JVM to create new objects in memory. When investigating mismanaged memory, one heap dump is usually good enough if the heap dump is generated when the JVM is experiencing or very close to experiencing an OutOfMemory error. The closer to the OutOfMemory the JVM is when the heap dump is taken, the more useful it will be for troubleshooting any potential Java memory issues.

Note: Heap dumps will take anywhere between ten seconds to several minutes. Heap dumps are saved on disk and will be the same physical size as the JVM's current memory usage.


Automatic Heap Dumps:

Automatically generate a heap dump whenever Out Of Memory exceptions occur by adding the following JVM arguments:

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heapdump.hprof

Manual Heap Dumps:

Step 1

The first piece of information you will need to be able to obtain a thread dump is the java process's PID. The java JDK ships with the jps command which lists all active java process ID's. You can run this command like this: jps -v. The pid is listed as well as the JVM arguments, which will help you to identify which PID belongs to the application server running Liferay Portal.

Here's an example output:

7652 Jps -Denv.class.path=. -Dapplication.home=C:\java\jdk1.6.0_18 -Xms8m

2936 -Dexe4j.semaphoreName=c:_program files (x86)_smartsvn 6_bin_smartsvn.exe0 -Dexe4j.moduleName=C:\Program Files (x86)\SmartSVN 6\bin\smartsvn.exe -Dexe4j.tempDir=C:\Users\liferay\AppData\Local\Temp\e4j8FA1.tmp_dir20624 -Dexe4j.unextractedPosition=211749 -Dexe4j.consoleCodepage=cp0 -Dsun.java2d.noddraw=true -Xms24m -Xmx256m

4752 Bootstrap -Dfile.encoding=UTF8 -Djava.net.preferIPv4Stack=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m -Djava.util.logging.config.file=E:\projects\temp\liferay-portal-6.0-ee-sp2\tomcat-6.0.32\conf\logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=E:\projects\temp\liferay-portal-6.0-ee-sp2\tomcat-6.0.32\endorsed -Dcatalina.base=E:\projects\temp\liferay-portal-6.0-ee-sp2\tomcat-6.0.32 -Dcatalina.home=E:\projects\temp\liferay-portal-6.0-ee-sp2\tomcat-6.0.32 -Djava.io.tmpdir=E:\projects\temp\liferay-portal-6.0-ee-sp2\tomcat-6.0.32\temp

4752 is running Liferay Portal based on the JVM arguments.

Step 1 Alternatives

  1. Windows:

    Ctrl+Shift+Esc to open the task manager and find the PID under 'Processes'.

    From the command prompt, execute netstat command: netstat -noa

    This command will return a list of Active connections. Look for the connection that is using the port your application server is using. As an example, Tomcat uses two connector ports: 8080, 8005, and 8009. After executing netstat -noa command: LISTENING 4752 ESTABLISHED 4752

    Compare 4752 to the other lines and yes, this looks like the PID assigned to Tomcat.

  2. UNIX, Linux and Mac OSX:

    ps -el | grep java

Step 2

Request a heap dump of the live objects from the JVM. From the command prompt execute:

jmap -dump:live,format=b,file=heapdump.hprof <pid>

If you do not use the live option, then jmap, by default, will take a snapshot of all of the memory in the JVM, which may take up to a few hours depending on the heap size.


jcmd  GC.heap_dump /path/to/destination/file.hprof


If you see an error message, Unable to attach to 32-bit process running under WOW64, this is because you are trying to use the jmap tool from JDK 1.6 to take thread dumps from a process running on JDK 1.5. The bundled version of Liferay + Tomcat/Jboss comes with a bundled 32-bit version JRE. In a 64-bit environment, you need to remove the bundled JRE and allow the application server to run on the system installed 64-bit JRE in order for the 64-bit jmap tool to work successfully.

Note: In Linux and UNIX, you may need to run this command as sudo -u user jmap -dump:format=b, file=heapdump.hprof <pid>, where "user" is the user that the java process is running as.

Additional Information

Was this article helpful?
0 out of 0 found this helpful