alibaba / arthas

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
https://arthas.aliyun.com/
Apache License 2.0
35.65k stars 7.49k forks source link

No class or method is affected when trying command like trace or watch #198

Closed ralf0131 closed 5 years ago

ralf0131 commented 6 years ago
  1. 先确认Arthas已经挂载到正确的Java进程里面了,检查Arthas连上时输出的PID,确认是想要挂载的目标进程ID(和 ps -ef 的结果比对)
  2. 先用sc或者sm搜索对应的类和方法,确认已经被JVM加载
  3. ~/logs/arthas/arthas.log中查找有没有Method code too large的异常
  4. 存在该异常时,尝试用reset class_name命令对类进行恢复,再进行trace,watch等操作
  5. 系统级别的类默认不能进行增强,需要增强是请参考这里unsafe开关,增强系统类时请谨慎操作

English version

  1. Please confirm that Arthas is attached to the correct JVM. Check the PID Arthas output when connection has established with the actual process id (using ps -ef)
  2. Check the class has been loaded by this JVM by using sc or sm command.
  3. Check whether there is Method code too large exception in ~/logs/arthas/arthas.log
  4. If there is such exception, try to use reset class_name to eliminate the modified byte code and try again.
  5. Enhancing classes begin with java.* are disabled by default, please refer to this to opt-in.
ahzpc007 commented 6 years ago

@ralf0131 hi,有个问题请教下 自己写的demo程序,本地启动后,能通过arthas找到该进程 [5]: 23737 com/study/atm/Demo 使用watch命令后,提示 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). 使用sc命令 $ sc com/study/atm/Demo Affect(row-cnt:0) cost in 47 ms. 看样子似乎没有被JVM加载,这一点比较奇怪,因为程序已经跑起来,而且arthas也能查到此进程。
Hearen commented 6 years ago

@ahzpc007 Would you elaborate your question to help us re-produce your issue?

xuzhouxing commented 6 years ago

思路很清晰,重点是需要找对pid,看看自己进入的是哪一个

ahzpc007 commented 5 years ago

思路很清晰,重点是需要找对pid,看看自己进入的是哪一个

目前只是在本地出现过一次,测试或线上环境都能正常使用, 可能是确实是pid选择问题。

szlzhm commented 5 years ago

我这里也遇到这样的问题,我的java编译用java1.8.0_161,运行环境是java1.8.0_181,ubuntu 16.0 64位,springboot应用。下面是命令好相关故障: 命令:trace com.kc.Compare compare 故障输出: Press Ctrl+c to abort Affect(class-cnt:1, method-cnt:1) cost in 183 ms.

然后就没有输出了。 我这个命令本来是有输出的,运行了多次后,就不论怎样都没有输出了。 我的PID选择没有错误,使用的版本是3.0.5, 打开unsafe也没用

beigekaoke commented 2 years ago

我这里也遇到这样的问题,我的java编译用java1.8.0_161,运行环境是java1.8.0_181,ubuntu 16.0 64位,springboot应用。下面是命令好相关故障: 命令:trace com.kc.Compare compare 故障输出: Press Ctrl+c to abort Affect(class-cnt:1, method-cnt:1) cost in 183 ms.

然后就没有输出了。 我这个命令本来是有输出的,运行了多次后,就不论怎样都没有输出了。 我的PID选择没有错误,使用的版本是3.0.5, 打开unsafe也没用

这个解决了吗?