-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat: reflect analysis #3069
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
base: master
Are you sure you want to change the base?
feat: reflect analysis #3069
Conversation
…orresponding to sun.reflect.GeneratedMethodAccessor to assist in troubleshooting insufficient metaspace problem.
@hengyunabc PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new reflection analysis feature to help troubleshoot insufficient metaspace problems by analyzing sun.reflect.GeneratedMethodAccessor
classes and their corresponding methods.
- Added a new
reflect-analysis
command that can output results to console or CSV file - Implemented reflection analysis using ASM bytecode analysis to extract method invocation information
- Created supporting infrastructure including models, views, and utilities for the new feature
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
MapUtil.java | Added utility class for optimized HashMap capacity calculation |
ResultViewResolver.java | Registered the new ReflectAnalysisView for rendering results |
ReflectAnalysisView.java | View class for formatting reflection analysis output |
ReflectAnalysisModel.java | Model class containing reflection analysis data |
ReflectAnalysisCommand.java | Main command implementation with ASM bytecode analysis |
BuiltinCommandPack.java | Added ReflectAnalysisCommand to available commands |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
core/src/main/java/com/taobao/arthas/core/command/klass100/ReflectAnalysisCommand.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/taobao/arthas/core/command/klass100/ReflectAnalysisCommand.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/taobao/arthas/core/command/klass100/ReflectAnalysisCommand.java
Outdated
Show resolved
Hide resolved
麻烦解析下原理,怎么工作的,解决哪些问题。 |
解决的问题在某些情况下(比如动态加载类后未正确卸载)会不断地产生sun.reflect.GeneratedMethodAccessor对象导致元空间(通过JVM参数限定了大小)不足,从而不断地触发FullGc导致服务不稳定甚至不可用,此时需要知道大量的sun.reflect.GeneratedMethodAccessor所对应的方法才能知道问题出在哪里。 原理1.查找当前JVM中所有的sun.reflect.GeneratedMethodAccessor类; package sun.reflect;
import cn.ares.boot.demo.user.request.UserRequest;
import java.lang.reflect.InvocationTargetException;
import sun.reflect.MethodAccessorImpl;
public class GeneratedMethodAccessor1
extends MethodAccessorImpl {
/*
* Loose catch block
*/
public Object invoke(Object object, Object[] objectArray) throws InvocationTargetException {
UserRequest userRequest;
block5: {
if (object == null) {
throw new NullPointerException();
}
userRequest = (UserRequest)object;
if (objectArray == null || objectArray.length == 0) break block5;
throw new IllegalArgumentException();
}
try {
return userRequest.getId();
}
catch (Throwable throwable) {
throw new InvocationTargetException(throwable);
}
catch (ClassCastException | NullPointerException runtimeException) {
throw new IllegalArgumentException(super.toString());
}
}
} 3.根据类+方法名作统计计数; |
@hengyunabc PTAL |
感觉是一个非常小众的场景,直接 heapdump 应该也可以分析出来。 或者直接用 classloader 命令来查看有哪些 classloader,再看它们加载的类列表。 |
确实是一个偏小众的需求,但通过classloader查看只能查看到sun.reflect.GeneratedMethodAccessor这一层,sun.reflect.GeneratedMethodAccessor背后所对应的方法是无法统计的,heapdump是可以分析出来的但这个过程也并不是很简单,Arthas是否有计划实现一个插件机制将一些非核心的指令迁移过去并更方便用户自己扩展与贡献。 |
purpose
Added reflection analysis function to analyze all the methods corresponding to sun.reflect.GeneratedMethodAccessor to assist in troubleshooting insufficient metaspace problem.
usage
1.reflect-analysis
2.reflect-analysis reflect-analysis-result.csv
When it is a relative path, the file will be generated in a temporary directory.
Example