-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
ArthasClassloader support load class from SystemClassLoader #995
Comments
测试支持从 SystemClassLoader加载类的: |
尝试了允许加载SystemClassLoader的类,发现容易出问题。仍保持现状。 public class ArthasClassloader extends URLClassLoader {
private final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
public ArthasClassloader(URL[] urls) {
super(urls, ClassLoader.getSystemClassLoader().getParent());
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class<?> loadedClass = findLoadedClass(name);
if (loadedClass == null) {
loadedClass = doLoadClass(name);
}
if (resolve) {
resolveClass(loadedClass);
}
return loadedClass;
}
private Class<?> doLoadClass(String name) throws ClassNotFoundException {
// 1) 优先从parent里加载系统类,避免抛出ClassNotFoundException
if (name != null && (name.startsWith("sun.") || name.startsWith("java."))) {
return super.loadClass(name, false);
}
// 2) Try to find locally
try {
Class<?> cls = findClass(name);
return cls;
} catch (Exception ex) {
// Ignore and continue
}
// 3) Try to find SystemClassLoader. agent jar should load by SystemClassLoader.
try {
return systemClassLoader.loadClass(name);
} catch (Exception ex) {
// Ignore and continue
}
// 4) Use standard loading
return super.loadClass(name, false);
}
} 如果是使用 jacoco ,它本身有参数可以 exclude 掉classloader,可以把arthas的 classloader exclude掉。 https://www.jacoco.org/jacoco/trunk/doc/agent.html |
之前遇到一个问题是我们一个agent 增强了netty用的类(落日志之类),arthas就起不动,报class not found. 感觉和这个issue是有关的。 |
因为agent插入了自己的类。agent的类通常是由 System ClassLoader加载的,但 ArthasClassLoader目前不允许加载 SystemClassLoader里的类。 |
|
考虑增加一个白名单,在配置的名单里的类,则从优先从 SystemClassLoader里加载。
但外部配置的加载有点麻烦,只能做有限度的支持。
在某些情况下,一些其它的字节码修改的agent 可以会拉截到 arthas 里的类,然后插入自己的Agent里的代码,这样子导致出错。
尽管这个逻辑是不对的,但 ArthasClassloader 本身是否应该支持加载 SystemClassLoader里的类?
修改之后,有没有可能影响到 ognl 的执行?
The text was updated successfully, but these errors were encountered: