Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are "live" objects in java heap? (heap dump with jmap)

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:

  1. Objects in young generation;

  2. 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.

like image 818
auntyellow Avatar asked Dec 17 '22 17:12

auntyellow


1 Answers

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.

like image 85
Alexey Ragozin Avatar answered Jan 12 '23 22:01

Alexey Ragozin