Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arthas增强类以后参数名会抹除 #2800

Open
1 task
zhuchunfeng opened this issue Feb 19, 2024 · 1 comment
Open
1 task

arthas增强类以后参数名会抹除 #2800

zhuchunfeng opened this issue Feb 19, 2024 · 1 comment
Labels
bug Something isn't working question-answered wontfix This will not be worked on

Comments

@zhuchunfeng
Copy link

环境信息

  • Arthas 版本: 3.7.2
  • 操作系统版本: win11家庭版和centos7上有同样的问题
  • 目标进程的JVM版本: java version "1.8.0_202"

重现问题的步骤

  1. 重写equals方法
  2. 启动arthas, 增强该类
  3. 获取该类的equals方法参数名, 由原先的obj变成arg0
  4. 执行reset重置
  5. 获取该类的equals方法参数名, 依然是arg0

期望的结果

增强类后, 不改变重写的方法的参数名

实际运行的结果

增强类后, 重写的方法的参数名会变成arg0, arg1 .... , 由于业务程序需要反射获取参数名, 更改参数名会造成业务程序的bug

java -jar arthas-boot.jar
[INFO] JAVA_HOME: D:\Program Files\Java\jre1.8.0_202
[INFO] arthas-boot version: 3.7.2
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 2996 com.qualsen.QAIotBizApplication
  [2]: 7956
  [3]: 18552 org.jetbrains.jps.cmdline.Launcher
  [4]: 3020 org.jetbrains.idea.maven.server.RemoteMavenServer36
1
[INFO] arthas home: C:\Users\zhu\.arthas\lib\3.7.2\arthas
[INFO] Try to attach process 2996
[INFO] Found java home from System Env JAVA_HOME: D:\Program Files\Java\jdk1.8.0_202
[INFO] Attach process 2996 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.  
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-' 
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-. 
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----' 

wiki       https://arthas.aliyun.com/doc
tutorials  https://arthas.aliyun.com/doc/arthas-tutorials.html
version    3.7.2
main_class
pid        2996
time       2024-02-19 10:04:41

[arthas@2996]$ ognl -c 18b4aac2 '@com.qualsen.thingsmind.biz.report.service.QtmpBizReportService1@class.getMethods()[0].getParameters()'
@Parameter[][
    @Parameter[java.lang.Object obj],
]
[arthas@2996]$ watch com.qualsen.thingsmind.biz.report.service.QtmpBizReportService1 * '{params,returnObj,throwExp}'  -n 5  -x 3
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 2) cost in 65 ms, listenerId: 1
[arthas@2996]$ ognl -c 18b4aac2 '@com.qualsen.thingsmind.biz.report.service.QtmpBizReportService1@class.getMethods()[0].getParameters()'
@Parameter[][
    @Parameter[java.lang.Object arg0],
]
[arthas@2996]$ reset
Affect(class count: 1 , method count: 0) cost in 10 ms, listenerId: 0
[arthas@2996]$ ognl -c 18b4aac2 '@com.qualsen.thingsmind.biz.report.service.QtmpBizReportService1@class.getMethods()[0].getParameters()'
@Parameter[][
    @Parameter[java.lang.Object arg0],
]
[arthas@2996]$

image

@hengyunabc hengyunabc added the bug Something isn't working label Mar 21, 2024
@hengyunabc hengyunabc added this to the 4.0.0 milestone Mar 21, 2024
@hengyunabc hengyunabc added the wontfix This will not be worked on label Mar 21, 2024
@hengyunabc hengyunabc removed this from the 4.0.0 milestone Mar 21, 2024
@hengyunabc
Copy link
Collaborator

这个是 JDK 自身的bug,参考: https://bugs.openjdk.org/browse/JDK-8240908

测试 jdk 17 仍然有,jdk 21是可以正常运行的。上面的issue显示是 jdk 19才修复。

可以自己简单写一个代码来测试,只要触发 retransformClasses,函数参数名称信息就会丢失。

            Method method = MathGame.class.getMethod("primeFactors", int.class);
            
            Parameter[] parameters = method.getParameters();
            
            System.err.println("parameters.length: " + parameters.length);
            for (Parameter parameter : parameters) {
                System.err.println("parameter: " + parameter.getName());
                System.err.println("parameter: " + parameter);
            }
            
            Instrumentation inst = ByteBuddyAgent.install();
            
            inst.retransformClasses(MathGame.class);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question-answered wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants