import{_ as c,o as r,c as l,a,b as e,w as d,e as s,d as t,r as o}from"./app.977e81c1.js";const p={},u=a("h1",{id:"vmtool",tabindex:"-1"},[a("a",{class:"header-anchor",href:"#vmtool","aria-hidden":"true"},"#"),s(" vmtool")],-1),m=a("div",{class:"custom-container tip"},[a("p",{class:"custom-container-title"},"\u63D0\u793A"),a("p",null,"@since 3.5.1")],-1),v={href:"https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn&id=command-vmtool",target:"_blank",rel:"noopener noreferrer"},h=a("code",null,"vmtool",-1),b=s("\u5728\u7EBF\u6559\u7A0B"),g=a("p",null,[a("code",null,"vmtool"),s(" \u5229\u7528"),a("code",null,"JVMTI"),s("\u63A5\u53E3\uFF0C\u5B9E\u73B0\u67E5\u8BE2\u5185\u5B58\u5BF9\u8C61\uFF0C\u5F3A\u5236 GC \u7B49\u529F\u80FD\u3002")],-1),k={href:"https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html",target:"_blank",rel:"noopener noreferrer"},_=s("JVM Tool Interface"),x=t(`
$ 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],
]
\u63D0\u793A
\u901A\u8FC7 --limit
\u53C2\u6570\uFF0C\u53EF\u4EE5\u9650\u5236\u8FD4\u56DE\u503C\u6570\u91CF\uFF0C\u907F\u514D\u83B7\u53D6\u8D85\u5927\u6570\u636E\u65F6\u5BF9 JVM \u9020\u6210\u538B\u529B\u3002\u9ED8\u8BA4\u503C\u662F 10\u3002
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext
\u53EF\u4EE5\u901A\u8FC7sc
\u547D\u4EE4\u67E5\u627E\u5230\u52A0\u8F7D class \u7684 classloader\u3002
$ 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
\u7136\u540E\u7528-c
/--classloader
\u53C2\u6570\u6307\u5B9A\uFF1A
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext
\u63D0\u793A
getInstances
action \u8FD4\u56DE\u7ED3\u679C\u7ED1\u5B9A\u5230instances
\u53D8\u91CF\u4E0A\uFF0C\u5B83\u662F\u6570\u7EC4\u3002
\u901A\u8FC7 -x
/--expand
\u53C2\u6570\u53EF\u4EE5\u6307\u5B9A\u7ED3\u679C\u7684\u5C55\u5F00\u5C42\u6B21\uFF0C\u9ED8\u8BA4\u503C\u662F 1\u3002
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2
\u63D0\u793A
getInstances
action \u8FD4\u56DE\u7ED3\u679C\u7ED1\u5B9A\u5230instances
\u53D8\u91CF\u4E0A\uFF0C\u5B83\u662F\u6570\u7EC4\u3002\u53EF\u4EE5\u901A\u8FC7--express
\u53C2\u6570\u6267\u884C\u6307\u5B9A\u7684\u8868\u8FBE\u5F0F\u3002
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()'
vmtool --action forceGc
thread id \u901A\u8FC7-t
\u53C2\u6570\u6307\u5B9A\uFF0C\u53EF\u4EE5\u4F7F\u7528 thread
\u547D\u4EE4\u83B7\u53D6\u3002
vmtool --action interruptThread -t 1