classloader

查看classloader的继承树,urls,类加载信息

classloader 命令将 JVM 中所有的classloader的信息统计出来,并可以展示继承树,urls等。

可以让指定的classloader去getResources,打印出所有查找到的resources的url。对于ResourceNotFoundException比较有用。

参数说明

参数名称 参数说明
[l] 按类加载实例进行统计
[t] 打印所有ClassLoader的继承树
[a] 列出所有ClassLoader加载的类,请谨慎使用
[c:] ClassLoader的hashcode
[c: r:] 用ClassLoader去查找resource
[c: load:] 用ClassLoader去加载指定的类

使用参考

按类加载类型查看统计信息

  1. $ classloader
  2. name numberOfInstances loadedCountTotal
  3. com.taobao.arthas.agent.ArthasClassloader 1 2115
  4. BootstrapClassLoader 1 1861
  5. sun.reflect.DelegatingClassLoader 5 5
  6. sun.misc.Launcher$AppClassLoader 1 4
  7. sun.misc.Launcher$ExtClassLoader 1 1
  8. Affect(row-cnt:5) cost in 3 ms.

按类加载实例查看统计信息

  1. $ classloader -l
  2. name loadedCount hash parent
  3. BootstrapClassLoader 1861 null null
  4. com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69
  5. sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69
  6. sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null
  7. Affect(row-cnt:4) cost in 2 ms.

查看ClassLoader的继承树

  1. $ classloader -t
  2. +-BootstrapClassLoader
  3. +-sun.misc.Launcher$ExtClassLoader@66350f69
  4. +-com.taobao.arthas.agent.ArthasClassloader@68b31f0a
  5. +-sun.misc.Launcher$AppClassLoader@3d4eac69
  6. Affect(row-cnt:4) cost in 3 ms.

查看URLClassLoader实际的urls

  1. $ classloader -c 3d4eac69
  2. file:/private/tmp/arthas-demo.jar
  3. file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar
  4. Affect(row-cnt:9) cost in 3 ms.

使用ClassLoader去查找resource

  1. $ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF
  2. jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF
  3. jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF
  4. jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF

也可以尝试查找类的class文件:

  1. $ classloader -c 1b6d3586 -r java/lang/String.class
  2. jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class

使用ClassLoader去加载类

  1. $ classloader -c 3d4eac69 --load demo.MathGame
  2. load class success.
  3. class-info demo.MathGame
  4. code-source /private/tmp/arthas-demo.jar
  5. name demo.MathGame
  6. isInterface false
  7. isAnnotation false
  8. isEnum false
  9. isAnonymousClass false
  10. isArray false
  11. isLocalClass false
  12. isMemberClass false
  13. isPrimitive false
  14. isSynthetic false
  15. simple-name MathGame
  16. modifier public
  17. annotation
  18. interfaces
  19. super-class +-java.lang.Object
  20. class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69
  21. +-sun.misc.Launcher$ExtClassLoader@66350f69
  22. classLoaderHash 3d4eac69