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

1

7

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.

Ayrshire answered 3/4, 2019 at 13:30 Comment(2)
@Holger sorry for my poor english. #2 I mean objects that are no longer used / referenced but not collected yet.Ayrshire
sorry for my stupid mistake :-pAyrshire
Z
16

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.

Zoospore answered 3/4, 2019 at 17:58 Comment(1)
When you use live option, full GC is performed by the JVM which could literally hang the application until its complete, in some cases takes a long time and it may not even finish for application that use large heaps. In such cases, there is a good chance of getting the heap dump done if you drop the live optionTrampoline

© 2022 - 2024 — McMap. All rights reserved.