vmtool
vmtool利用JVMTI接口,实现查询内存对象,强制GC等功能。
命令选项
命令选项 | 描述 |
---|---|
-a, --action <action> | 指定执行动作,可选值为forceGc , getInstances |
-c, --classloader <hash> | 指定ClassLoader的哈希值 |
--classLoaderClass <name> | 指定ClassLoader的类名 |
--className <name> | 指定类的名称 |
-x, --expand <level> | 指定扩展对象层级,默认1 |
--express <expression> | ognl表达式,默认为instances |
--libPath <path> | 额外库路径 |
-l, --limit <number> | 限制返回实例个数,默认10 ,-1 表示无限制 |
-h, --help | 帮助 |
示例
bash
# 强制执行gc
[arthas@17028]$ vmtool -a forceGc
# 查看java.util.List在内存中的实例
[arthas@17028]$ vmtool -a getInstances --className java.util.List
@List[][
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
@ArrayList[isEmpty=false;size=2],
]
# 查看SpringBoot服务实例
[arthas@17028]$ vmtool -a getInstances --className io.github.passerr.system.application.service.UserService
@UserService[][
@UserService$$EnhancerBySpringCGLIB$$7fb5d73c[io.github.passerr.system.application.service.UserService@2fe33319],
@UserService[io.github.passerr.system.application.service.UserService@2fe33319],
]
# 指定ClassLoader查看实例 通过sc -d查询类加载器的哈希值
[arthas@17028]$ vmtool -a getInstances -c 9c7af21 --className io.github.passerr.system.application.service.UserService
@UserService[][
@UserService$$EnhancerBySpringCGLIB$$7fb5d73c[io.github.passerr.system.application.service.UserService@2fe33319],
@UserService[io.github.passerr.system.application.service.UserService@2fe33319],
]
# 查询实例并执行ognl表达式
vmtool -a getInstances --className java.util.Random --express "instances[0].seed.value"
@Long[0]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35