vmtool¶
@since 3.5.1
vmtool
利用JVMTI
接口,实现查询内存对象,强制GC等功能。
获取对象¶
$ vmtool --action getInstances --className java.lang.String --limit 10
@String[][
@String[com/taobao/arthas/core/shell/session/Session],
@String[com.taobao.arthas.core.shell.session.Session],
@String[com/taobao/arthas/core/shell/session/Session],
@String[com/taobao/arthas/core/shell/session/Session],
@String[com/taobao/arthas/core/shell/session/Session.class],
@String[com/taobao/arthas/core/shell/session/Session.class],
@String[com/taobao/arthas/core/shell/session/Session.class],
@String[com/],
@String[java/util/concurrent/ConcurrentHashMap$ValueIterator],
@String[java/util/concurrent/locks/LockSupport],
]
通过
--limit
参数,可以限制返回值数量,避免获取超大数据时对JVM造成压力。默认值是10。
指定 classloader name¶
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext
指定 classloader hash¶
可以通过sc
命令查找到加载class的 classloader。
$ sc -d org.springframework.context.ApplicationContext
class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/
name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
...
class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2
+-sun.misc.Launcher$AppClassLoader@75b84c92
+-sun.misc.Launcher$ExtClassLoader@4f023edb
classLoaderHash 19469ea2
然后用-c
/--classloader
参数指定:
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext
指定返回结果展开层数¶
getInstances
action返回结果绑定到instances
变量上,它是数组。
通过
-x
/--expand
参数可以指定结果的展开层次,默认值是1。
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2
执行表达式¶
getInstances
action返回结果绑定到instances
变量上,它是数组。可以通过--express
参数执行指定的表达式。
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()'