[alibaba/arthas]trace函数 classloader can not load SpyAPI

2024-07-09 262 views
2
环境信息
  • arthas-boot.jar 或者 as.sh 的版本:3.5.4
  • 目标进程的JVM版本: jdk1.8
重现问题的步骤
  1. trace com.xx.integration.cas.filter.util.CasHelper checkToken --skipJDKMethod false
期望的结果

正常trace

其他信息

sc -d com.xx.integration.cas.filter.util.CasHelper 信息

 class-info        com.xx.integration.cas.filter.util.CasHelper                                                                                                                                                                  
 code-source       /app/jetty/server/docker_jetty/work/jetty-10_206_191_110-8080-air-atms-service_war-_-any-/webapp/WEB-INF/lib/erui-cas-2.0.0.RC4.jar                                                                           
 name              com.xx.integration.cas.filter.util.CasHelper                                                                                                                                                                  
 isInterface       false                                                                                                                                                                                                         
 isAnnotation      false                                                                                                                                                                                                         
 isEnum            false                                                                                                                                                                                                         
 isAnonymousClass  false                                                                                                                                                                                                         
 isArray           false                                                                                                                                                                                                         
 isLocalClass      false                                                                                                                                                                                                         
 isMemberClass     false                                                                                                                                                                                                         
 isPrimitive       false                                                                                                                                                                                                         
 isSynthetic       false                                                                                                                                                                                                         
 simple-name       CasHelper                                                                                                                                                                                                     
 modifier          public                                                                                                                                                                                                        
 annotation                                                                                                                                                                                                                      
 interfaces                                                                                                                                                                                                                      
 super-class       +-java.lang.Object                                                                                                                                                                                            
 class-loader      +-WebAppClassLoader{363509958}@15aab8c6                                                                                                                                                                       
                     +-startJarLoader@e2144e4                                                                                                                                                                                    
                       +-sun.misc.Launcher$AppClassLoader@5c647e05                                                                                                                                                               
                         +-sun.misc.Launcher$ExtClassLoader@3d988038                         
 classLoaderHash   15aab8c6             

sm -d com.xx.integration.cas.filter.util.CasHelper checkToken 信息

 declaring-class  com.xx.integration.cas.filter.util.CasHelper                                                                                                                                                                
 method-name      checkToken                                                                                                                                                                                                     
 modifier         public,static                                                                                                                                                                                                  
 annotation                                                                                                                                                                                                                      
 parameters       javax.servlet.http.HttpServletRequest                                                                                                                                                                          
                  javax.servlet.http.HttpServletResponse                                                                                                                                                                         
 return           boolean                                                                                                                                                                                                        
 exceptions                                                                                                                                                                                                                      
 classLoaderHash  15aab8c6    
实际运行的结果
No class or method is affected, try:
1. Execute `sm CLASS_NAME METHOD_NAME` to make sure the method you are tracing actually exists (it might be in your parent class).
2. Execute `options unsafe true`, if you want to enhance the classes under the `java.*` package.
3. Execute `reset CLASS_NAME` and try again, your method body might be too large.
4. Check arthas log: /home/mwopr/logs/arthas/arthas.log
5. Visit https://github.com/alibaba/arthas/issues/47 for more details.
2021-09-29 11:14:06 [arthas-command-execute] ERROR c.t.arthas.core.advisor.Enhancer -the classloader can not load SpyAPI, ignore it. classloader: org.eclipse.jetty.webapp.WebAppClassLoader, className: com/xx/integration/cas/f
ilter/util/CasHelper
java.lang.ClassNotFoundException: java.arthas.SpyAPI
        at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:565)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at com.taobao.arthas.core.advisor.Enhancer.transform(Enhancer.java:116)
        at com.taobao.arthas.core.advisor.TransformerManager$1.transform(TransformerManager.java:51)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
        at com.taobao.arthas.core.advisor.Enhancer.enhance(Enhancer.java:396)
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.enhance(EnhancerCommand.java:168)
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.process(EnhancerCommand.java:115)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

麻烦大佬帮忙看下为什么不行 我查看了一下其他issue,是因为不支持的原因吗

回答

9

可以下载全量包,解压之后,找到 arthas.properties 文件,把这一行注释打开:

arthas.enhanceLoaders=java.lang.ClassLoader

这个问题的原因,主要是 org.eclipse.jetty.webapp.WebAppClassLoader 不支持加载append 到bootstrap classloader里的java.arthas.SpyAPI类。

5

可以了,非常感谢