Arthas: No class or method is affected/Trace, watch等命令无法找到对应的类和方法

Created on 17 Sep 2018  ·  32Comments  ·  Source: alibaba/arthas

  1. 先用sc或者sm搜索对应的类和方法,确认已经被JVM加载
  2. $HOME/logs/arthas/arthas.log中查找有没有Method code too large的异常
  3. 存在该异常时,尝试用reset class_name命令对类进行恢复,再进行trace,watch等操作
  4. 查找内部类要用 $ 符号拼出正确的类名,比如sc outer-class$inner-class
  5. 系统级别的类(即java.*)默认不能进行增强,需要增强是请参考这里的unsafe开关,增强系统类时请谨慎操作
  6. 连错了进程,如果之前连过别的进程,且没有shutdown退出,则下次连别的进程时,默认还会连到之前连的进程上。
  7. 由Arthas自身的ClassLoader加载的类不能被增强
question-answered

Most helpful comment

我的类明明有的,为什么用arthas找到类。
No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /home/tomcat/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.

All 32 comments

另外,数组类、接口类、枚举类以及java.lang.Class/java.lang.Integer/java.lang.reflect.Method等类都是不能进行增强的

找类需要加包名,如:com.xxx.xxx.xxxController

If you would like to search for an inner class, you have to use sc outer-class$inner-class.
查找内部类,需要按照如下格式进行 sc outer-class$inner-class

直接 sc *Controller* 就行

Need to add English translation.

image
image

reset后又trace还是提示相同的错误,日志还是提示该类还是无法增强,

PS:该类有13k行左右。

PS:该类有13k行左右。

这个没有办法。JVM本身有限制。

PS:该类有13k行左右。

这个没有办法。JVM本身有限制。

这个场景描述的真好,难道jvm在针对我?
这个场景和我的问题的区别在哪?
image

jad: fail to decompile class,caused by java.lang.VerifyError
image

jad: fail to decompile class,caused by java.lang.VerifyError

有没有可以重现的Demo

jad: fail to decompile class,caused by java.lang.VerifyError

有没有可以重现的Demo

我试试能不能把这个类分离出来

@xiqicode 参考这个: https://github.com/alibaba/arthas/issues/675#issuecomment-487856710

我的类明明有的,为什么用arthas找到类。
No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /home/tomcat/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.

问题:问啥会链接另外一个进程?pid 确认没有问题

背景:在这台机器上部署了多个程序。

开始能找到,后边过一段时间后找不到了。最后发现连接到了另外一个进程
使用sc controller 发现了另外一个进程的类

问题:问啥会链接另外一个进程?pid 确认没有问题

背景:在这台机器上部署了多个程序。

开始能找到,后边过一段时间后找不到了。最后发现连接到了另外一个进程
使用sc _controller_ 发现了另外一个进程的类

先 shutdown ,或者指定另外的端口。不然会直接连接到之前进程 listen的端口。

我把2个进程都重启,解决了

问题:问啥会链接另外一个进程?pid 确认没有问题
背景:在这台机器上部署了多个程序。
开始能找到,后边过一段时间后找不到了。最后发现连接到了另外一个进程
使用sc _controller_ 发现了另外一个进程的类

先 shutdown ,或者指定另外的端口。不然会直接连接到之前进程 listen的端口。

多谢

使用watch命令时,怎么区分同一个类中的同名方法呢?
比如demoMethod(String)和demoMethod(String,String)

使用watch命令时,怎么区分同一个类中的同名方法呢?
比如demoMethod(String)和demoMethod(String,String)

参考: https://github.com/alibaba/arthas/issues/434

请问长度限制是多少?我两个controller加起来不到200行。。。

No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /home/momobot/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.

想要使用watch命令监控第三方包内的方法,但是一直找不到该类。请问这种情况是什么问题导致的,可以怎么解决?

具体执行命令详情如下:
$ sm InfluxDB
org.influxdb.InfluxDB$LogLevel (Ljava/lang/String;I)V
org.influxdb.InfluxDB$LogLevel values()[Lorg/influxdb/InfluxDB$LogLevel;
org.influxdb.InfluxDB$LogLevel valueOf(Ljava/lang/String;)Lorg/influxdb/InfluxDB$LogLevel;
org.influxdb.InfluxDB setConnectTimeout(JLjava/util/concurrent/TimeUnit;)V
org.influxdb.InfluxDB setReadTimeout(JLjava/util/concurrent/TimeUnit;)V
org.influxdb.InfluxDB setWriteTimeout(JLjava/util/concurrent/TimeUnit;)V
org.influxdb.InfluxDB enableBatch(IILjava/util/concurrent/TimeUnit;)Lorg/influxdb/InfluxDB;
org.influxdb.InfluxDB disableBatch()V
org.influxdb.InfluxDB setLogLevel(Lorg/influxdb/InfluxDB$LogLevel;)Lorg/influxdb/InfluxDB;
org.influxdb.InfluxDB ping()Lorg/influxdb/dto/Pong;
org.influxdb.InfluxDB createDatabase(Ljava/lang/String;)V
org.influxdb.InfluxDB deleteDatabase(Ljava/lang/String;)V
org.influxdb.InfluxDB describeDatabases()Ljava/util/List;
org.influxdb.InfluxDB write(Lorg/influxdb/dto/BatchPoints;)V
org.influxdb.InfluxDB write(Ljava/lang/String;Ljava/lang/String;Lorg/influxdb/dto/Point;)V
org.influxdb.InfluxDB query(Lorg/influxdb/dto/Query;)Lorg/influxdb/dto/QueryResult;
org.influxdb.InfluxDB query(Lorg/influxdb/dto/Query;Ljava/util/concurrent/TimeUnit;)Lorg/influxdb/dto/QueryResult;
org.influxdb.InfluxDB version()Ljava/lang/String;
org.influxdb.InfluxDBFactory (Ljava/lang/String;I)V
org.influxdb.InfluxDBFactory values()[Lorg/influxdb/InfluxDBFactory;
org.influxdb.InfluxDBFactory valueOf(Ljava/lang/String;)Lorg/influxdb/InfluxDBFactory;
org.influxdb.InfluxDBFactory connect(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/influxdb/InfluxDB;
Affect(row-cnt:22) cost in 74 ms.
$ watch org.influxdb.InfluxDB query "{returnObj}" -x 2
No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /root/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.

5000多行的类,还有子类,报too large了

jdk8后的default 函数参考: https://github.com/alibaba/arthas/issues/1105

[arthas@25752]$ watch java.util.concurrent.ThreadPoolExecutor isTerminated "{params,returnObj}" -x 2
No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /home/jboss/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.
    [arthas@25752]$ sm java.util.concurrent.ThreadPoolExecutor isTerminated
    java.util.concurrent.ThreadPoolExecutor isTerminated()Z
    Affect(row-cnt:1) cost in 12 ms.

[arthas@1768]$ watch com.company.login.servlet.LoginValidServlet info
Affect(class count: 0 , method count: 0) cost in 29 ms, listenerId: 2
No class or method is affected, try:

  1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).
  2. reset CLASS_NAME and try again, your method body might be too large.
  3. check arthas log: /home/user/logs/arthas/arthas.log
  4. visit https://github.com/alibaba/arthas/issues/47 for more details.

[arthas@1768]$ sc com.company.login.servlet.LoginValidServlet
com.company.login.servlet.LoginValidServlet
Affect(row-cnt:1) cost in 12 ms.

[arthas@1768]$ sm com.company.login.servlet.LoginValidServlet
com.company.login.servlet.LoginValidServlet ()V
com.company.login.servlet.LoginValidServlet service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
com.company.login.servlet.LoginValidServlet info(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V
com.company.login.servlet.LoginValidServlet init()V
Affect(row-cnt:9) cost in 14 ms.

log:

2020-09-14 19:14:07 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -enhance matched classes: [class com.company.login.servlet.LoginValidServlet]
2020-09-14 19:14:07 [arthas-command-execute] ERROR c.t.arthas.core.advisor.Enhancer -the classloader can not load SpyAPI, ignore it. classloader: org.apache.catalina.loader.ParallelWebappClassLoader, className: com/company/login/servlet/LoginValidServlet
2020-09-14 19:14:07 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -Success to batch transform classes: [class com.company.login.servlet.LoginValidServlet]

versions:

Server version: Apache Tomcat/8.5.55
Server built: May 5 2020 22:10:54 UTC
Server number: 8.5.55.0
OS Name: Linux
OS Version: 3.10.0-957.21.3.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_252-b09
JVM Vendor: Oracle Corporation

@ralf0131 need help. Maybe Tomcat related.

It's working in my local pc but not working in k8s.

2020-11-15 22:55:57 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -Success to batch transform classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -enhance matched classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] ERROR c.t.arthas.core.advisor.Enhancer -the classloader can not load SpyAPI, ignore it. classloader: com.caucho.loader.EnvironmentClassLoader, className: weaver/login/VerifyLogin

你好,在使用monitor的时候有这样的一个问题

2020-11-15 22:55:57 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -Success to batch transform classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -enhance matched classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] ERROR c.t.arthas.core.advisor.Enhancer -the classloader can not load SpyAPI, ignore it. classloader: com.caucho.loader.EnvironmentClassLoader, className: weaver/login/VerifyLogin

你好,在使用monitor的时候有这样的一个问题

这是因为 com.caucho.loader.EnvironmentClassLoader 不支持加载 append 到 bootstrap classloader里的jar,是它的实现问题。后面arthas会尝试支持这种情况,目前不支持。

2020-11-15 22:55:57 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -Success to batch transform classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -enhance matched classes: [class weaver.login.VerifyLogin]
2020-11-15 23:05:27 [arthas-command-execute] ERROR c.t.arthas.core.advisor.Enhancer -the classloader can not load SpyAPI, ignore it. classloader: com.caucho.loader.EnvironmentClassLoader, className: weaver/login/VerifyLogin
你好,在使用monitor的时候有这样的一个问题

这是因为 com.caucho.loader.EnvironmentClassLoader 不支持加载 append 到 bootstrap classloader里的jar,是它的实现问题。后面arthas会尝试支持这种情况,目前不支持。

我这里报的是 the classloader can not load SpyAPI, ignore it. classloader: org.eclipse.jetty.webapp.WebAppClassLoader, className: com/xxx$

请问也是因为.jetty.webapp.WebAppClassLoader 不支持加载append 到 bootstrap classloader里的jar的原因吗?

我这里报的是 the classloader can not load SpyAPI, ignore it. classloader: org.eclipse.jetty.webapp.WebAppClassLoader, className: com/xxx$

请问也是因为.jetty.webapp.WebAppClassLoader 不支持加载append 到 bootstrap classloader里的jar的原因吗?

是的

请问,如果要watch的方法的包名里包含了中文字符,arthas控制台会显示乱码,从而无法监控此类的方法,怎么办?

不能直接这样使用吗,jdk的类都不能trace吗?

trace --skipJDKMethod false java.text.SimpleDateFormat initialize

不能直接这样使用吗,jdk的类都不能trace吗?

trace --skipJDKMethod false java.text.SimpleDateFormat initialize

仔细看issue里的说明,要打开 unsafe 开关。

Was this page helpful?
0 / 5 - 0 ratings