diff --git a/core/src/main/java/com/taobao/arthas/core/command/klass100/ClassLoaderCommand.java b/core/src/main/java/com/taobao/arthas/core/command/klass100/ClassLoaderCommand.java index 9aeff13ce98..f93189fc5ef 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/klass100/ClassLoaderCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/klass100/ClassLoaderCommand.java @@ -46,7 +46,7 @@ " classloader -c 327a647b -r META-INF/MANIFEST.MF\n" + " classloader -a\n" + " classloader -a -c 327a647b\n" + - " classloader -c 659e0bfd --load com.test.Demo\n" + + " classloader -c 659e0bfd --load demo.MathGame\n" + Constants.WIKI + Constants.WIKI_HOME + "classloader") public class ClassLoaderCommand extends AnnotatedCommand { private boolean isTree = false; @@ -202,7 +202,8 @@ private void processResources(CommandProcess process, Instrumentation inst) { } } process.write(com.taobao.arthas.core.util.Constants.EMPTY_STRING); - process.write(affect.rCnt(rowCount) + "\n"); + affect.rCnt(rowCount); + process.write(affect + "\n"); process.end(); } diff --git a/site/src/site/sphinx/classloader.md b/site/src/site/sphinx/classloader.md index c7f6233b6a4..c76e3e0ca2e 100644 --- a/site/src/site/sphinx/classloader.md +++ b/site/src/site/sphinx/classloader.md @@ -17,116 +17,95 @@ classloader |[a]|列出所有ClassLoader加载的类,请谨慎使用| |`[c:]`|ClassLoader的hashcode| |`[c: r:]`|用ClassLoader去查找resource| +|`[c: load:]`|用ClassLoader去加载指定的类| ### 使用参考 -* 按类加载类型查看统计信息 +#### 按类加载类型查看统计信息 -```s +```bash $ classloader - name numberOfInstances loadedCountTotal - com.taobao.pandora.service.loader.ModuleClassLoader 29 11659 - com.taobao.pandora.boot.loader.ReLaunchURLClassLoader 1 5308 - BootstrapClassLoader 1 3711 - com.taobao.arthas.agent.ArthasClassloader 2 2825 - sun.reflect.DelegatingClassLoader 332 332 - java.net.URLClassLoader 1 285 - sun.misc.Launcher$AppClassLoader 1 77 - sun.misc.Launcher$ExtClassLoader 1 46 - com.alibaba.fastjson.util.ASMClassLoader 2 3 - org.jvnet.hk2.internal.DelegatingClassLoader 2 2 - sun.reflect.misc.MethodUtil 1 1 -Affect(row-cnt:11) cost in 66 ms. + name numberOfInstances loadedCountTotal + com.taobao.arthas.agent.ArthasClassloader 1 2115 + BootstrapClassLoader 1 1861 + sun.reflect.DelegatingClassLoader 5 5 + sun.misc.Launcher$AppClassLoader 1 4 + sun.misc.Launcher$ExtClassLoader 1 1 +Affect(row-cnt:5) cost in 3 ms. ``` -* 按类加载实例查看统计信息 +#### 按类加载实例查看统计信息 ```bash $ classloader -l - name loadedCount hash parent - BootstrapClassLoader 3711 null null - com.alibaba.fastjson.util.ASMClassLoader@3bbaa1b8 2 3bbaa1b8 monitor's ModuleClassLoader - com.alibaba.fastjson.util.ASMClassLoader@5e255d0b 1 5e255d0b eagleeye-core's ModuleClassLoader - com.taobao.arthas.agent.ArthasClassloader@4fa2d7e6 1795 4fa2d7e6 sun.misc.Launcher$ExtClassLoader@a38d7a3 - com.taobao.arthas.agent.ArthasClassloader@522400c2 1033 522400c2 sun.misc.Launcher$ExtClassLoader@a38d7a3 - com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@1817d444 5308 1817d444 sun.misc.Launcher$AppClassLoader@14dad5dc - tbsession's ModuleClassLoader 285 609cd4d8 null - pandora-qos-service's ModuleClassLoader 267 2f8dad04 null - pandora-framework's ModuleClassLoader 78 4009e306 null - filesync-client's ModuleClassLoader 4 4b8ee4de null - rocketmq-client's ModuleClassLoader 431 247bddad null - eagleeye-core's ModuleClassLoader 451 1ba9117e null - alimonitor-jmonitor's ModuleClassLoader 134 22fcf7ab null - metaq-client's ModuleClassLoader 35 41a2befb null - hsf-mock's ModuleClassLoader 3 2002fc1d null - monitor's ModuleClassLoader 1427 131ef10 null - spas-sdk-service's ModuleClassLoader 7 10d307f1 null - vipserver-client's ModuleClassLoader 137 7a419da4 null - metrics's ModuleClassLoader 146 696da30b null - mtop-uncenter's ModuleClassLoader 922 79d8407f null - spas-sdk-client's ModuleClassLoader 235 4944252c null - live-profiler-pandora's ModuleClassLoader 1 6913c1fb null - notify-tr-client's ModuleClassLoader 472 fba92d3 null - ons-sdk's ModuleClassLoader 70 23348b5d null - tair-plugin's ModuleClassLoader 1053 7c9d8e2 null - tddl-client's ModuleClassLoader 2354 4988d8b8 null - config-client's ModuleClassLoader 93 429bffaa null - diamond-client's ModuleClassLoader 360 3d5c822d null - pandolet's ModuleClassLoader 99 41e1e210 null - hsf's ModuleClassLoader 1796 3232a28a null - acl.plugin's ModuleClassLoader 379 67080771 null - buc.sso.client.plugin's ModuleClassLoader 195 13b6aecc null - unitrouter's ModuleClassLoader 64 7e5afaa6 null - switch's ModuleClassLoader 104 24313fcc null - hsf-notify-client's ModuleClassLoader 57 4d0f2471 null - java.net.URLClassLoader@7ec7ffd3 285 7ec7ffd3 sun.misc.Launcher$ExtClassLoader@a38d7a3 - javax.management.remote.rmi.NoCallStackClassLoader@53f65459 1 53f65459 null - javax.management.remote.rmi.NoCallStackClassLoader@2833cc44 1 2833cc44 null - org.jvnet.hk2.internal.DelegatingClassLoader@72cda8ee 1 72cda8ee monitor's ModuleClassLoader - org.jvnet.hk2.internal.DelegatingClassLoader@1f57f96d 1 1f57f96d monitor's ModuleClassLoader - sun.misc.Launcher$AppClassLoader@14dad5dc 77 14dad5dc sun.misc.Launcher$ExtClassLoader@a38d7a3 - sun.misc.Launcher$ExtClassLoader@a38d7a3 46 a38d7a3 null - sun.reflect.misc.MethodUtil@1201f221 1 1201f221 sun.misc.Launcher$AppClassLoader@14dad5dc + name loadedCount hash parent + BootstrapClassLoader 1861 null null + com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69 + sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69 + sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null +Affect(row-cnt:4) cost in 2 ms. ``` -* 查看ClassLoader的继承树 +#### 查看ClassLoader的继承树 -```shell +```bash $ classloader -t +-BootstrapClassLoader -+-unitrouter's ModuleClassLoader -+-diamond-client's ModuleClassLoader -+-sun.misc.Launcher$ExtClassLoader@548a102f -| +-sun.misc.Launcher$AppClassLoader@14dad5dc -| +-com.taobao.arthas.agent.AgentLauncher$1@334e6bb8 -| | +-sun.reflect.DelegatingClassLoader@328b3a05 -| | +-sun.reflect.DelegatingClassLoader@73f44f24 ++-sun.misc.Launcher$ExtClassLoader@66350f69 + +-com.taobao.arthas.agent.ArthasClassloader@68b31f0a + +-sun.misc.Launcher$AppClassLoader@3d4eac69 +Affect(row-cnt:4) cost in 3 ms. ``` -* 查看URLClassLoader实际的urls - -```shell -$ classloader -c 5ffe9775 -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/commons-lang-2.6.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/log4j-1.2.16.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/logger.api-0.1.4.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.api-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.container-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.thirdcontainer-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/picocontainer-2.14.3.jar +#### 查看URLClassLoader实际的urls + +```bash +$ classloader -c 3d4eac69 +file:/private/tmp/arthas-demo.jar +file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar + +Affect(row-cnt:9) cost in 3 ms. ``` -* 使用ClassLoader去查找resource +#### 使用ClassLoader去查找resource -```shell -$ classloader -c 226b143b -r META-INF/MANIFEST.MF - jar:file:/Users/hello/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar!/META-INF/MANIFEST.MF - jar:file:/Users/hello/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar!/META-INF/MANIFEST.MF +```bash +$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF + jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF + jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF + jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF ``` 也可以尝试查找类的class文件: -```shell +```bash $ classloader -c 1b6d3586 -r java/lang/String.class jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class ``` + +#### 使用ClassLoader去加载类 + +```bash +$ classloader -c 3d4eac69 --load demo.MathGame +load class success. + class-info demo.MathGame + code-source /private/tmp/arthas-demo.jar + name demo.MathGame + isInterface false + isAnnotation false + isEnum false + isAnonymousClass false + isArray false + isLocalClass false + isMemberClass false + isPrimitive false + isSynthetic false + simple-name MathGame + modifier public + annotation + interfaces + super-class +-java.lang.Object + class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69 + +-sun.misc.Launcher$ExtClassLoader@66350f69 + classLoaderHash 3d4eac69 +``` diff --git a/site/src/site/sphinx/en/classloader.md b/site/src/site/sphinx/en/classloader.md index 4d2976704aa..5cbe19a29f0 100644 --- a/site/src/site/sphinx/en/classloader.md +++ b/site/src/site/sphinx/en/classloader.md @@ -9,121 +9,100 @@ View hierarchy, urls and classes-loading info for the class-loaders. |Name|Specification| |---:|:---| -|[l]|list all class loader instances| +|[l]|list all classloader instances| |[t]|print classloader's hierarchy| -|[a]|list all the classes loaded by all the class loaders (use it with great caution since the output can be huge)| +|[a]|list all the classes loaded by all the classloaders (use it with great caution since the output can be huge)| |[c:]|print classloader's hashcode| -|[c: r:]|using class loader to search resource| +|`[c: r:]`|using ClassLoader to search resource| +|`[c: load:]`|using ClassLoader to load class| ### Usage -* View statistics categorized by class type +#### View statistics categorized by class type ```bash $ classloader - name numberOfInstances loadedCountTotal - com.taobao.pandora.service.loader.ModuleClassLoader 29 11659 - com.taobao.pandora.boot.loader.ReLaunchURLClassLoader 1 5308 - BootstrapClassLoader 1 3711 - com.taobao.arthas.agent.ArthasClassloader 2 2825 - sun.reflect.DelegatingClassLoader 332 332 - java.net.URLClassLoader 1 285 - sun.misc.Launcher$AppClassLoader 1 77 - sun.misc.Launcher$ExtClassLoader 1 46 - com.alibaba.fastjson.util.ASMClassLoader 2 3 - org.jvnet.hk2.internal.DelegatingClassLoader 2 2 - sun.reflect.misc.MethodUtil 1 1 -Affect(row-cnt:11) cost in 66 ms. + name numberOfInstances loadedCountTotal + com.taobao.arthas.agent.ArthasClassloader 1 2115 + BootstrapClassLoader 1 1861 + sun.reflect.DelegatingClassLoader 5 5 + sun.misc.Launcher$AppClassLoader 1 4 + sun.misc.Launcher$ExtClassLoader 1 1 +Affect(row-cnt:5) cost in 3 ms. ``` -* View statistics categorized by loaded classes number +#### View statistics categorized by loaded classes number ```bash $ classloader -l - name loadedCount hash parent - BootstrapClassLoader 3711 null null - com.alibaba.fastjson.util.ASMClassLoader@3bbaa1b8 2 3bbaa1b8 monitor's ModuleClassLoader - com.alibaba.fastjson.util.ASMClassLoader@5e255d0b 1 5e255d0b eagleeye-core's ModuleClassLoader - com.taobao.arthas.agent.ArthasClassloader@4fa2d7e6 1795 4fa2d7e6 sun.misc.Launcher$ExtClassLoader@a38d7a3 - com.taobao.arthas.agent.ArthasClassloader@522400c2 1033 522400c2 sun.misc.Launcher$ExtClassLoader@a38d7a3 - com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@1817d444 5308 1817d444 sun.misc.Launcher$AppClassLoader@14dad5dc - tbsession's ModuleClassLoader 285 609cd4d8 null - pandora-qos-service's ModuleClassLoader 267 2f8dad04 null - pandora-framework's ModuleClassLoader 78 4009e306 null - filesync-client's ModuleClassLoader 4 4b8ee4de null - rocketmq-client's ModuleClassLoader 431 247bddad null - eagleeye-core's ModuleClassLoader 451 1ba9117e null - alimonitor-jmonitor's ModuleClassLoader 134 22fcf7ab null - metaq-client's ModuleClassLoader 35 41a2befb null - hsf-mock's ModuleClassLoader 3 2002fc1d null - monitor's ModuleClassLoader 1427 131ef10 null - spas-sdk-service's ModuleClassLoader 7 10d307f1 null - vipserver-client's ModuleClassLoader 137 7a419da4 null - metrics's ModuleClassLoader 146 696da30b null - mtop-uncenter's ModuleClassLoader 922 79d8407f null - spas-sdk-client's ModuleClassLoader 235 4944252c null - live-profiler-pandora's ModuleClassLoader 1 6913c1fb null - notify-tr-client's ModuleClassLoader 472 fba92d3 null - ons-sdk's ModuleClassLoader 70 23348b5d null - tair-plugin's ModuleClassLoader 1053 7c9d8e2 null - tddl-client's ModuleClassLoader 2354 4988d8b8 null - config-client's ModuleClassLoader 93 429bffaa null - diamond-client's ModuleClassLoader 360 3d5c822d null - pandolet's ModuleClassLoader 99 41e1e210 null - hsf's ModuleClassLoader 1796 3232a28a null - acl.plugin's ModuleClassLoader 379 67080771 null - buc.sso.client.plugin's ModuleClassLoader 195 13b6aecc null - unitrouter's ModuleClassLoader 64 7e5afaa6 null - switch's ModuleClassLoader 104 24313fcc null - hsf-notify-client's ModuleClassLoader 57 4d0f2471 null - java.net.URLClassLoader@7ec7ffd3 285 7ec7ffd3 sun.misc.Launcher$ExtClassLoader@a38d7a3 - javax.management.remote.rmi.NoCallStackClassLoader@53f65459 1 53f65459 null - javax.management.remote.rmi.NoCallStackClassLoader@2833cc44 1 2833cc44 null - org.jvnet.hk2.internal.DelegatingClassLoader@72cda8ee 1 72cda8ee monitor's ModuleClassLoader - org.jvnet.hk2.internal.DelegatingClassLoader@1f57f96d 1 1f57f96d monitor's ModuleClassLoader - sun.misc.Launcher$AppClassLoader@14dad5dc 77 14dad5dc sun.misc.Launcher$ExtClassLoader@a38d7a3 - sun.misc.Launcher$ExtClassLoader@a38d7a3 46 a38d7a3 null - sun.reflect.misc.MethodUtil@1201f221 1 1201f221 sun.misc.Launcher$AppClassLoader@14dad5dc + name loadedCount hash parent + BootstrapClassLoader 1861 null null + com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69 + sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69 + sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null +Affect(row-cnt:4) cost in 2 ms. ``` -* View class-loaders hierarchy +#### View class-loaders hierarchy -```shell +```bash $ classloader -t +-BootstrapClassLoader -+-unitrouter's ModuleClassLoader -+-diamond-client's ModuleClassLoader -+-sun.misc.Launcher$ExtClassLoader@548a102f -| +-sun.misc.Launcher$AppClassLoader@14dad5dc -| +-com.taobao.arthas.agent.AgentLauncher$1@334e6bb8 -| | +-sun.reflect.DelegatingClassLoader@328b3a05 -| | +-sun.reflect.DelegatingClassLoader@73f44f24 ++-sun.misc.Launcher$ExtClassLoader@66350f69 + +-com.taobao.arthas.agent.ArthasClassloader@68b31f0a + +-sun.misc.Launcher$AppClassLoader@3d4eac69 +Affect(row-cnt:4) cost in 3 ms. ``` -* Show the URLs from which to load classes and resources for one particular URLClassLoader +#### Show the URLs of the URLClassLoader -```shell -$ classloader -c 5ffe9775 -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/commons-lang-2.6.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/log4j-1.2.16.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/logger.api-0.1.4.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.api-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.container-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.thirdcontainer-2.0.7-SNAPSHOT.jar -file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/picocontainer-2.14.3.jar +```bash +$ classloader -c 3d4eac69 +file:/private/tmp/arthas-demo.jar +file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar + +Affect(row-cnt:9) cost in 3 ms. ``` -* Use one class loader to search one particular resource +#### Use the classloader to load resource -```shell -$ classloader -c 226b143b -r META-INF/MANIFEST.MF - jar:file:/Users/hello/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar!/META-INF/MANIFEST.MF - jar:file:/Users/hello/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar!/META-INF/MANIFEST.MF +```bash +$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF + jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF + jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF + jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF ``` -* Use one class loader to search one particular class +Use the classloader to load `.class` resource ```shell $ classloader -c 1b6d3586 -r java/lang/String.class jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class ``` + +#### Use the classloader to load class + +```bash +$ classloader -c 3d4eac69 --load demo.MathGame +load class success. + class-info demo.MathGame + code-source /private/tmp/arthas-demo.jar + name demo.MathGame + isInterface false + isAnnotation false + isEnum false + isAnonymousClass false + isArray false + isLocalClass false + isMemberClass false + isPrimitive false + isSynthetic false + simple-name MathGame + modifier public + annotation + interfaces + super-class +-java.lang.Object + class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69 + +-sun.misc.Launcher$ExtClassLoader@66350f69 + classLoaderHash 3d4eac69 +``` \ No newline at end of file