Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take a heap dump on Java 5 without garbage collecting first?

We have a long running server application running Java 5, and profiling it we can see the old generation growing slowly over time. It's correctly freed on a full GC, but I'd like to be able to look at the unreachable objects in Eclipse MAT using a heap dump. I've successfully obtained a heap dump using +XX:HeapDumpOnCtrlBreak, but the JVM always does a GC before dumping the heap. Apparently this doesn't happen on Java 6 but we're stuck on 5 for now. Is there any way to prevent this?

like image 677
Colin Avatar asked Aug 12 '09 19:08

Colin


1 Answers

use jconsole or visualvm or jmc or ... other jmx management console. open HotSpotDiagnostic in com.sun.management. select method dumpHeap and input two parameters:

  • path to the dump file
  • (true/false) dump only live objects. use false to dump all objects.

Note that the dump file will be written by the JVM you connected to, not by JVisualVM, so if the JVM is running on a different system, it will be written on that system.

enter image description here

like image 175
daggett Avatar answered Sep 28 '22 22:09

daggett