javajava-8heap-dumpjmapjcmd

why there is difference in Heap dump size generated by jmap and jcmd?


I am trying to take heap dump using below 2 commands

  1. jcmd $pid GC.heap_dump /tmp/filename.dump
  2. jmap -dump:format=b,file=/tmp/filename.dump $pid

jcmd produces file size of ~300M and jmap produces file size of ~1.4G. why these are different sizes, do we have any additional information in jmap ? am I missing some arguments in jcmd ?

JDK is 1.8.0_162

Xms and Xmx is 4G


Solution

  • By Default (When no [options] are provided],

    JMAP took an all-objects dump and JCMD took only live-objects dump.

    Using JMAP command: While using this command you don't need to specify anything as it is by default produce the heap dump of all the objects. If you need live objects alone, you can pass '-dump:live' option in JMAP.

    Using JCMD command: While using this command you have to pass -all option. Otherwise, it will request a full GC and generates only live objects dump.

    JCMD - without any options of object state - By default it dumps only the live objects.

    JMAP - without any options of object state - By default it dumps all the objects.

    For more information refer here