java堆分析工具jmap

jmap是比较地道本土的堆分析工具,应该掌握,下面讲讲如何运用。

// 打印jvm的堆状况,主要是年轻代和老年代信息
jmap -heap <pid>
如:
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 536870912 (512.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 268435456 (256.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 46661632 (44.5MB)
   used     = 1139464 (1.0866775512695312MB)
   free     = 45522168 (43.41332244873047MB)
   2.441972025324789% used
From Space:
   capacity = 524288 (0.5MB)
   used     = 0 (0.0MB)
   free     = 524288 (0.5MB)
   0.0% used
To Space:
   capacity = 1048576 (1.0MB)
   used     = 0 (0.0MB)
   free     = 1048576 (1.0MB)
   0.0% used
PS Old Generation
   capacity = 112721920 (107.5MB)
   used     = 54152304 (51.64366149902344MB)
   free     = 58569616 (55.85633850097656MB)
   48.04061534792878% used
PS Perm Generation
   capacity = 94371840 (90.0MB)
   used     = 94050296 (89.69335174560547MB)
   free     = 321544 (0.30664825439453125MB)
   99.65927971733942% used

37542 interned Strings occupying 3976528 bytes.
// 上面的信息比较笼统,我们还可以打印出具体类及实例信息, 将有助于帮助我们分析堆里面到底有哪些类的实例等
jmap -histo[:live只处理存活对象] <pid>
如,

 num     #instances         #bytes  class name
----------------------------------------------
   1:        152516       24683264  <constMethodKlass>
   2:        152516       19540560  <methodKlass>
   3:         15131       18875008  <constantPoolKlass>
   4:        201534       18312296  [C
   5:         15131       11855656  <instanceKlassKlass>
   6:         12595       10850176  <constantPoolCacheKlass>
   7:         94350        5198896  [B
   8:        182201        4372824  java.lang.String
   9:        109840        3514880  java.util.HashMap$Entry
  10:         18069        2334792  [Ljava.util.HashMap$Entry;
  11:          3889        2233712  <methodDataKlass>
  12:         46910        2159984  [Ljava.lang.Object;
  13:         16277        2034144  java.lang.Class
  14:         17040        2024080  [I
  15:         22528        1588768  [S
  16:         24126        1174880  [[I
  17:         23542         941680  java.util.LinkedHashMap$Entry
// 除此之外,我们可以将堆信息dump成文件,通过其他工具如jhat, mat做进一步分析
jmap -dump:live,format=b,file=heap.bin <pid>

自己去实践实践吧。

收工。

你可能感兴趣的:(java,JMAP)