Steps To Take Heap Dump With JRE
It is very tricky to get a heap dump on right time to get a correct state of a JVM to debug a issue better.How ever many times we face multiple issues just to collect a heap dump and most places we don’t usually install JDK to run a java application instead JRE used widely and unfortunately we don’t have any tools available in JRE to get a on demand heap dump when ever required.
There are many options like
-XX:+HeapDumpOnCtrlBreak which is helpful but not much of use when you want to take a heap dump on demand and not allowed to install JDK of same version as of JRE used.
Incase client is not willing to install JDK just to take heap dumps then as a workaround you can follow below steps to temporarily copy few files, take the heap dump and remove the same file once heapdumps taken. This process does not require any installation. This is very effective when you have only JRE in the application and want to take a heap dump of the JVM to resolve some issue.
Here in this scenario you have to “patch” your JRE with below files of the JDK(same version jre7uXX -> files from jdk7uXX )
Copy the following files to the JRE system:
JDK7uXX\bin\attach.dll copy to %JRE_HOME%\bin\ JDK7uXX\bin\jmap.exe copy to %JRE_HOME%\bin\ JDK7uXX\lib\tools.jar copy to %JRE_HOME%\lib\
Note: No files are overwritten and JRE all files sanity remains intact.
Now you can generate heap dump using below command on jmap
Use jmap to acquire the dump
C:\>jmap -dump:format=b,file=c:\Temp\mymemorydump.hprof 11448 Dumping heap to C:\Temp\mymemorydump.hprof ... Heap dump file created
You can also use script mentioned in “Shell Script For Jmap Heap Dump” thread in case you want to auto generate heap dumps on regular intervals.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.