jmap help shows:
...
-dump:<dump-options> to dump java heap in hprof binary format dump-options: live dump only live objects; if not specified, all objects in the heap are dumped.
...
Once I dump a Tomcat (with java param -Xmx384m) heap:
jmap -dump:file=dump.bin <pid>
I got a dump file of ~300M.
When I dump its heap with live objects only:
jmap -dump:live,file=live-dump.bin <pid>
I got a dump file of ~120M.
My guess of live objects may be:
Objects in young generation;
Objects that are used / referenced / reachable and will not be collected.
Which one is right?
UPDATE
My guess #2 seems correct, and thanks for Alexey Ragozin's explanation (live
option will cause a full GC). I tested again according to his hint:
jmap -dump:file=dump.hprof <pid>
jmap -dump:live,file=live-dump.hprof <pid>
jmap -dump:file=after-live-dump.hprof <pid>
size of these 3 files are:
dump.hprof ~190MB
live-dump.hprof ~40MB
after-live-dump.hprof ~40MB
so after -dump:live
, almost all objects in heap are live.
jmap -dump:live,file=live-dump.bin <pid>
live option in jmap command below forces JVM to do a full GC before dumping content of heap into a file.
After full GC only objects transitively reachable from GC roots (definition of "live") are remaining in heap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With