JMap

JMap is java utility to create core file or heap dump running java process id. To describe bit more it prints shared object memory maps or heap memory details of a given process or core file or a remote debug server



Let see what different options we see from Jmap.

You will find jmap.exe under %Java_Home%/bin/



We can generate three option using JMap.

Histogram
Heap Dump
Core Dump

Histogram 

Histogram is used to identify the memory leak when there frequency OOM (Out Of Memory) errors occur in running process.

syntax

jmap -histo <pid>
   
example

$ jmap -histo 2748

 num     #instances         #bytes  class name
----------------------------------------------
   1:          9804       19070632  [Ljava.util.HashMap$Entry;
   2:         38074        6216960  [Ljava.lang.Object;
   3:         62256        4727832  [C
   4:         19665        3124744  <constMethodKlass>
   5:         19665        2365864  <methodKlass>
   6:         57843        2313720  java.lang.String
   7:          1662        2060528  <constantPoolKlass>
   8:         21121        1842344  [S
   9:         37772        1743888  <symbolKlass>
  10:          2554        1655632  [I
  11:         63710        1529040  java.lang.Integer
  12:          1662        1264184  <instanceKlassKlass>
  13:          1515        1196224  <constantPoolCacheKlass>
  14:         24351        1168848  java.util.HashMap$Entry
  

Heap Dump

 A heap dump is a snapshot of the memory of a Java process.  The snapshot contains information about the Java objects and classes in the heap at the moment the snapshot is triggered.  Typically, a full garbage collection is triggered before the heap dump is written, so the dump contains information about the remaining objects in the heap.
  
syntax
  
  jmap -dump:<dump-options> <pid>
  
  dump-options:
        file=<file>  dump heap to <file>

example

   jmap -dump:file=heap.bin 2456


Core Dump

A core file represents the recorded state of memory of the JVM when it crashed (i.e. not Java level information that can be analysed in a profiling tool). This type of file is indicative of either a bug in the JVM or a problem with a native library that you're calling from within your Java application through JNI. 


syntax

 jmap -dump:<dump-options> <pid>

 dump-options:
      format=b     binary default

example

jmap -dump:format=b,file=dump.hprof /usr/bin/java core.3334


You can get all the details when you run the -h option with jmap.


JDK/bin > jmap -h

Usage:
    jmap -histo <pid>
      (to connect to running process and print histogram of java object heap
    jmap -dump:<dump-options> <pid>
      (to connect to running process and dump java heap)

    dump-options:
      format=b     binary default
      file=<file>  dump heap to <file>

Post a Comment

0 Comments