Avoid append spy jar to BootstrapClassLoader multiple times. fix #996

This commit is contained in:
hengyunabc 2019-12-31 15:43:13 +08:00
parent eeb579f131
commit 4cf5d3b3a4

View File

@ -71,7 +71,18 @@ public class AgentBootstrap {
private static ClassLoader getClassLoader(Instrumentation inst, File spyJarFile, File agentJarFile) throws Throwable {
// 将Spy添加到BootstrapClassLoader
inst.appendToBootstrapClassLoaderSearch(new JarFile(spyJarFile));
ClassLoader parent = ClassLoader.getSystemClassLoader().getParent();
Class<?> spyClass = null;
if (parent != null) {
try {
parent.loadClass("java.arthas.Spy");
} catch (Throwable e) {
// ignore
}
}
if (spyClass == null) {
inst.appendToBootstrapClassLoaderSearch(new JarFile(spyJarFile));
}
// 构造自定义的类加载器尽量减少Arthas对现有工程的侵蚀
return loadOrDefineClassLoader(agentJarFile);