β

Java进程内存分析工具之jmap

四号程序员 153 阅读

jmap是java 7后自带的轻量级内存分析工具,原文介绍可以见官网, 《The jmap Utility》

1 堆栈分析

获取GC算法,新生代,老年代,永久代空间占用分析

jmap -heap 29620
Attaching to process ID 29620, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.6.0-rc-b100
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 67108864 (64.0MB)
   NewSize          = 2228224 (2.125MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 4194304 (4.0MB)
   NewRatio         = 8
   SurvivorRatio    = 8
   PermSize         = 12582912 (12.0MB)
   MaxPermSize      = 67108864 (64.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 2031616 (1.9375MB)
   used     = 70984 (0.06769561767578125MB)
   free     = 1960632 (1.8698043823242188MB)
.4939673639112905% used
Eden Space:
   capacity = 1835008 (1.75MB)
   used     = 36152 (0.03447723388671875MB)
   free     = 1798856 (1.7155227661132812MB)
.9701276506696428% used
From Space:
   capacity = 196608 (0.1875MB)
   used     = 34832 (0.0332183837890625MB)
   free     = 161776 (0.1542816162109375MB)
.716471354166668% used
To Space:
   capacity = 196608 (0.1875MB)
   used     = 0 (0.0MB)
   free     = 196608 (0.1875MB)
.0% used
tenured generation:
   capacity = 15966208 (15.2265625MB)
   used     = 9577760 (9.134063720703125MB)
   free     = 6388448 (6.092498779296875MB)
.98769400974859% used
Perm Generation:
   capacity = 12582912 (12.0MB)
   used     = 1469408 (1.401336669921875MB)
   free     = 11113504 (10.598663330078125MB)
.677805582682291% used

2 堆详细对象分析

jmap -histo 29620
num   #instances    #bytes  class name
--------------------------------------
:      1414     6013016  [I
:       793      482888  [B
:      2502      334928  <constMethodKlass>
:       280      274976  <instanceKlassKlass>
:       324      227152  [D
:      2502      200896  <methodKlass>
:      2094      187496  [C
:       280      172248  <constantPoolKlass>
:      3767      139000  [Ljava.lang.Object;
:       260      122416  <constantPoolCacheKlass>
:      3304      112864  <symbolKlass>
:       160       72960  java2d.Tools$3
:       192       61440  <objArrayKlassKlass>
:       219       55640  [F
:      2114       50736  java.lang.String
:      2079       49896  java.util.HashMap$Entry
:       528       48344  [S
:      1940       46560  java.util.Hashtable$Entry
:       481       46176  java.lang.Class
:        92       43424  javax.swing.plaf.metal.MetalScrollButton
... more lines removed here to reduce output...
:         1           8  java.util.Hashtable$EmptyIterator
:         1           8  sun.java2d.pipe.SolidTextRenderer
Total    61297    10152040

3 永久代分析

jmap -permstat 29620
Attaching to process ID 29620, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.6.0-rc-b100
4 intern Strings occupying 1082616 bytes.
finding class loader instances ..Unknown oop at 0xd0400900
Oop's klass is 0xd0bf8408
Unknown oop at 0xd0401100
Oop's klass is null
done.
computing per loader stat ..done.
please wait.. computing liveness.........................................done.
class_loader    classes bytes   parent_loader   alive?  type
<bootstrap>     1846 5321080  null        live   <internal>
xd0bf3828  0      0      null         live    sun/misc/Launcher$ExtClassLoader@0xd8c98c78
xd0d2f370  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0c99280  1   1440      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0b71d90  0      0   0xd0b5b9c0    live java/util/ResourceBundle$RBClassLoader@0xd8d042e8
xd0d2f4c0  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0b5bf98  1    920   0xd0b5bf38      dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0c99248  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f488  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0b5bf38  6   11832  0xd0b5b9c0      dead    sun/reflect/misc/MethodUtil@0xd8e8e560
xd0d2f338  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f418  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f3a8  1    904     null          dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0b5b9c0  317 1397448 0xd0bf3828     live    sun/misc/Launcher$AppClassLoader@0xd8cb83d8
xd0d2f300  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f3e0  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0ec3968  1   1440      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0e0a248  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0c99210  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f450  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0d2f4f8  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
xd0e0a280  1    904      null         dead    sun/reflect/DelegatingClassLoader@0xd8c22f50
total = 22      2186    6746816   N/A   alive=4, dead=18       N/A
作者:四号程序员
Keep It Simple And Stupid
原文地址:Java进程内存分析工具之jmap, 感谢原作者分享。

发表评论