Here are the most common ways to do it. You will use these if you have OutOfMemoryException (OOM) and you would like to take a look to the issue to determine the root cause.
1. For Hotspot/Oracle JDK, you need to add the following parameters to JAVA_OPTIONS-XX:+HeapDumpOnOutOfMemoryError
2. Similarly for JRockit, you need to the JAVA_OPTIONS below:-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\myApp\hprof-dumps
But, lets say that you are experiencing OOM, but you still don't determine the root cause of the issue.
You might probably need to restart as soon as you see performance issues or even better daily.
Then, #1 and #2 won't help.
You can use a tool like the ones below:
3. Jmap, e.g.:<JAVA_HOME>/bin/jmap -dump:format=b,file=c:\temp\heap.hprof <PID>
4. Or if you have already a core file and you would like to have a heap dump as well, you can also get a heap dump:jmap -dump:format=b,file=heap.hprof $JAVA_HOME/bin/java /home/lmestre/core.27436
5. Or even jrcmd for JRockit:
%JROCKIT_HOME%\bin\jrcmd <pid of target JVM> hprofdump filename=<full path name to the target dump file name>
6. If you have a Windows Service, you can check This My Oracle Support Doc:
How Do I Get A Java Heap Dump When Running Weblogic As A Windows Service? (Hotspot JVM) (Doc ID 1264826.1
To analyse the heap dump, you can use Eclipse MAT.
Here are some helpful documents to trobleshoot OOM:
Oracle WebLogic Server Support Pattern: Troubleshooting Out of Memory and Memory Leak Problems (Doc ID 877172.1
ORACLE JRockit and Memory Consumption - Memory Leaks In Java Heap (Doc ID 1137239.1