Skip to content

Commit

Permalink
Avoid append spy jar to BootstrapClassLoader multiple times. fix #996
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Dec 31, 2019
1 parent eeb579f commit 4cf5d3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion agent/src/main/java/com/taobao/arthas/agent/AgentBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ public synchronized static void resetArthasClassLoader() {

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);
Expand Down

0 comments on commit 4cf5d3b

Please sign in to comment.