JMap
命令格式
jmap [option] LVMID
option
参数
dump
: 生成堆转储快照。finalizerinfo
: 显示在F-Queue
队列等待Finalizer
线程指向finalizer
方法的对象。heap
: 显示java
堆详细信息。permstat
: 显示永久代的信息。F
: 当dump
没有响应时,强制生成dump
快照。
例子
1.打印dump
文件: -dump::live,format=b,file=<filename> pid
ubuntu@VM-0-7-ubuntu:~$ jmap -dump:live,format=b,file=dump.hprof 17281
Dumping heap to /home/ubuntu/dump.hprof ...
Heap dump file created
使用
Memory Anlysis Tool
打开dump.hprof
文件。
2.打印等待回收对象的信息: finalizerinfo
ubuntu@VM-0-7-ubuntu:~$ jmap -finalizerinfo 17281\
Attaching to process ID 17281, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13
Number of objects pending for finalization: 0
3.打印 heap
概要信息,GC
算法,heap
的配置及 wise heap
的使用情况。
ubuntu@VM-0-7-ubuntu:~$ jmap -heap 17281
Attaching to process ID 17281, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13
using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 4294967296 (4096.0MB)
NewSize = 1363144 (1.2999954223632812MB)
MaxNewSize = 2576351232 (2457.0MB)
OldSize = 5452592 (5.1999969482421875MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 1048576 (1.0MB)
Heap Usage:
G1 Heap:
regions = 4096
capacity = 4294967296 (4096.0MB)
used = 201207848 (191.88675689697266MB)
free = 4093759448 (3904.1132431030273MB)
4.6847352758049965% used
G1 Young Generation:
Eden Space:
regions = 110
capacity = 676331520 (645.0MB)
used = 115343360 (110.0MB)
free = 560988160 (535.0MB)
17.05426356589147% used
Survivor Space:
regions = 0
capacity = 0 (0.0MB)
used = 0 (0.0MB)
free = 0 (0.0MB)
0.0% used
G1 Old Generation:
regions = 84
capacity = 397410304 (379.0MB)
used = 85864488 (81.88675689697266MB)
free = 311545816 (297.11324310302734MB)
21.60600445830413% used
18946 interned Strings occupying 1962664 bytes.
4.打印堆的对象统计,包括对象数、内存大小
因为在 dump:live
前会进行 full gc
,如果带上 live
则只统计活对象,因此不加live
的堆大小要大于加 live
堆的大小。
ubuntu@VM-0-7-ubuntu:~$ jmap -histo:live 17281 | more
num #instances #bytes class name
----------------------------------------------
1: 1114112 17825792 litchi.core.dispatch.disruptor.MessageBuffer
2: 54327 17504752 [Ljava.lang.Object;
3: 62303 6787608 [C
4: 118637 4745480 java.util.LinkedHashMap$Entry
5: 3929 4598656 [I
6: 100741 3223712 java.util.HashMap$Node
7: 2681 3000848 [B
8: 35196 2534112 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$ShortcutDependencyDescriptor
9: 18731 2422224 [Ljava.util.HashMap$Node;
10: 96340 2312160 java.lang.String
11: 112836 1805376 java.lang.Integer
12: 63212 1517088 java.util.ArrayList
13: 35196 1407840 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement
14: 18581 1040536 java.util.LinkedHashMap
15: 28470 911040 java.util.concurrent.ConcurrentHashMap$Node
16: 8158 903496 java.lang.Class
17: 37532 900768 java.util.LinkedList$Node
18: 35205 844880 [Ljava.lang.annotation.Annotation;
19: 18931 605792 java.lang.ref.WeakReference
20: 16263 460424 [Ljava.lang.Class;
21: 9415 451920 java.util.HashMap
22: 17895 429480 litchi.core.common.extend.Dual
23: 4603 405064 java.lang.reflect.Method
24: 546 358176 io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue
25: 2538 304560 com.kd.shared.dataconfig.model.MonsterArmyConfig
class name
是对象类型,说明如下:
- B: byte
- C: char
- D: double
- F: float
- I: int
- J: long
- Z: boolean
- [ : 数组,如[I表示int[]
- [L + 类名 其他对象
5.参数 -F。
强制模式。如果指定的pid
没有响应,请使用jmap -dump
或jmap -histo
选项。此模式下,不支持live子选项。
JProfiler
用 JProfiler 分析导出的文件,看下面的线程 Actor-4-1,圈红的函数发生了死循环。
idea 可以有插件使用:
window 杀死进程
taskkill -f /pid 9884
9884 是进程id,可以通过 jps 查看
[1] JProfiler11安装