JVM效能除錯之jmap
阿新 • • 發佈:2019-02-07
jmap 的用途是為了展示java程序的記憶體對映資訊,或者堆記憶體詳情
常用的引數如下:
histo
jmap -histo pid 展示class的記憶體情況
展示的資訊為編號,例項數,位元組,類名
例如:
Java程式碼- jmap -histo:live 2540
- num #instances #bytes class name
- ----------------------------------------------
- 1: 20981 908120 [C
-
2: 21015
- 4: 9999 159984 org.learn.util.User
- 5: 312 59216 [Ljava.lang.Object;
heap
jmap -heap pid 展示pid的整體堆資訊
如:
Java程式碼- $ jmap -heap 29030
- JVM version is 16.3-b01
- using thread-local object allocation.
-
Parallel GC with 13
- Heap Configuration:
- MinHeapFreeRatio = 40
- MaxHeapFreeRatio = 70
- MaxHeapSize = 8436842496 (8046.0MB)
- NewSize = 5439488 (5.1875MB)
- MaxNewSize = 17592186044415 MB
- OldSize = 5439488 (5.1875MB)
- NewRatio = 2
-
SurvivorRatio = 8
- PermSize = 21757952 (20.75MB)
- MaxPermSize = 88080384 (84.0MB)
- Heap Usage:
- PS Young Generation
- Eden Space:
- capacity = 87883776 (83.8125MB)
- used = 31053080 (29.614524841308594MB)
- free = 56830696 (54.197975158691406MB)
- 35.33425782706469% used
- From Space:
- capacity = 13828096 (13.1875MB)
- used = 196608 (0.1875MB)
- free = 13631488 (13.0MB)
- 1.4218009478672986% used
- To Space:
- capacity = 16384000 (15.625MB)
- used = 0 (0.0MB)
- free = 16384000 (15.625MB)
- 0.0% used
- PS Old Generation
- capacity = 156172288 (148.9375MB)
- used = 27098208 (25.842864990234375MB)
- free = 129074080 (123.09463500976562MB)
- 17.35148299805917% used
- PS Perm Generation
- capacity = 88080384 (84.0MB)
- used = 50847592 (48.492042541503906MB)
- free = 37232792 (35.507957458496094MB)
- 57.728622073218936% used
對應的說明如下:
Java程式碼- Parallel GC with 13 thread(s) #13個gc執行緒
- Heap Configuration:#堆記憶體初始化配置
- MinHeapFreeRatio = 40 #-XX:MinHeapFreeRatio設定JVM堆最小空閒比率
- MaxHeapFreeRatio = 70 #-XX:MaxHeapFreeRatio設定JVM堆最大空閒比率
- MaxHeapSize = 8436842496 (8046.0MB)#-XX:MaxHeapSize=設定JVM堆的最大大小
- NewSize = 5439488 (5.1875MB) #-XX:NewSize=設定JVM堆的‘新生代’的預設大小
- MaxNewSize = 17592186044415 MB #-XX:MaxNewSize=設定JVM堆的‘新生代’的最大大小
- OldSize = 5439488 (5.1875MB) #-XX:OldSize=設定JVM堆的‘老生代’的大小
- NewRatio = 2 #-XX:NewRatio=:‘新生代’和‘老生代’的大小比率
- SurvivorRatio = 8 #-XX:SurvivorRatio=設定年輕代中Eden區與Survivor區的大小比值
- PermSize = 21757952 (20.75MB) #-XX:PermSize=<value>:設定JVM堆的‘永生代’的初始大小
- MaxPermSize = 88080384 (84.0MB) #-XX:MaxPermSize=<value>:設定JVM堆的‘永生代’的最大大小
- Heap Usage:
- PS Young Generation
- Eden Space:#Eden區記憶體分佈
- capacity = 87883776 (83.8125MB)
- used = 31053080 (29.614524841308594MB)
- free = 56830696 (54.197975158691406MB)
- 35.33425782706469% used
- From Space:#其中一個Survivor區的記憶體分佈
- capacity = 13828096 (13.1875MB)
- used = 196608 (0.1875MB)
- free = 13631488 (13.0MB)
- 1.4218009478672986% used
- To Space:#另一個Survivor區的記憶體分佈
- capacity = 16384000 (15.625MB)
- used = 0 (0.0MB)
- free = 16384000 (15.625MB)
- 0.0% used
- PS Old Generation#當前的Old區記憶體分佈
- capacity = 156172288 (148.9375MB)
- used = 27098208 (25.842864990234375MB)
- free = 129074080 (123.09463500976562MB)
- 17.35148299805917% used
- PS Perm Generation#當前的 “永生代” 記憶體分佈
- capacity = 88080384 (84.0MB)
- used = 50847592 (48.492042541503906MB)
- free = 37232792 (35.507957458496094MB)
- 57.728622073218936% used
dump
jmap -dump:<dump-options> pid 把pid的整體堆資訊輸出
dump-options:
live
format=b
file=<file>
匯出的檔案可以供分析用,比如jhat或者mat,以便查詢記憶體溢位原因
例如:
Java程式碼- jmap -dump:live,format=b,file=tomcat.bin 29030