support classes load by bootstrap classloader

pull/1182/head
hengyunabc 5 years ago
parent cead701c71
commit 2f5bc476eb

@ -14,39 +14,45 @@ import com.taobao.arthas.core.shell.system.ProcessAware;
/**
*
* TODO line listener stringkey classname|method|desc|num SpyAPI invoke?
* TODO line listener stringkey classname|method|desc|num
* SpyAPI invoke?
*
* TODO trace trace classname|method|desc|trace ? trace SPYinvoke
* TODO trace trace classname|method|desc|trace ? trace
* SPYinvoke
*
* TODO trace Listener
*
* TODO SPY Object Listener Listener
* Binding ClassLoader ClassLoader
* TODO SPY Object Listener
* Listener Binding
* ClassLoader ClassLoader
*
* ID trace
*
* watch watch TransForm watch
* reset
* watch watch TransForm
* watch reset
*
* watchinmethod
*
* watchinmethod
*
*
* TODO trace linenumber binding mehtodNode
* TODO trace linenumber binding
* mehtodNode
*
* TODO annotation invoke transform
* annotation annotation url ?key/value
* TODO annotation invoke
* transform annotation annotation url ?key/value
*
*
* TODO trace /watch Listener ID trace/watchID
* trace
* TODO trace /watch Listener ID
* trace/watchID trace
*
*
* @author hengyunabc 2020-04-24
*
*/
public class AdviceListenerManager {
private static Timer timer = ArthasBootstrap.getInstance().getTimer();
private static final FakeBootstrapClassLoader FAKEBOOTSTRAPCLASSLOADER = new FakeBootstrapClassLoader();
static {
timer.scheduleAtFixedRate(new TimerTask() {
@ -78,7 +84,7 @@ public class AdviceListenerManager {
}
}
}
}, 3000, 3000);
}
@ -90,7 +96,7 @@ public class AdviceListenerManager {
private String key(String className, String methodName, String methodDesc) {
return className + methodName + methodDesc;
}
private String keyForTrace(String className, String owner, String methodName, String methodDesc) {
return className + owner + methodName + methodDesc;
}
@ -106,7 +112,7 @@ public class AdviceListenerManager {
listeners = new ArrayList<AdviceListener>();
map.put(key, listeners);
}
if(!listeners.contains(listener)) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
@ -120,8 +126,7 @@ public class AdviceListenerManager {
return listeners;
}
public void registerTraceAdviceListener(String className, String owner, String methodName, String methodDesc,
AdviceListener listener) {
@ -133,12 +138,13 @@ public class AdviceListenerManager {
listeners = new ArrayList<AdviceListener>();
map.put(key, listeners);
}
if(!listeners.contains(listener)) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
public List<AdviceListener> queryTraceAdviceListeners(String className, String owner, String methodName, String methodDesc) {
public List<AdviceListener> queryTraceAdviceListeners(String className, String owner, String methodName,
String methodDesc) {
className = className.replace('/', '.');
String key = keyForTrace(className, owner, methodName, methodDesc);
@ -150,6 +156,7 @@ public class AdviceListenerManager {
public static void registerAdviceListener(ClassLoader classLoader, String className, String methodName,
String methodDesc, AdviceListener listener) {
classLoader = wrap(classLoader);
className = className.replace('/', '.');
ClassLoaderAdviceListenerManager manager = adviceListenerMap.get(classLoader);
@ -167,6 +174,7 @@ public class AdviceListenerManager {
public static List<AdviceListener> queryAdviceListeners(ClassLoader classLoader, String className,
String methodName, String methodDesc) {
classLoader = wrap(classLoader);
className = className.replace('/', '.');
ClassLoaderAdviceListenerManager manager = adviceListenerMap.get(classLoader);
@ -176,9 +184,10 @@ public class AdviceListenerManager {
return null;
}
public static void registerTraceAdviceListener(ClassLoader classLoader, String className, String owner, String methodName,
String methodDesc, AdviceListener listener) {
public static void registerTraceAdviceListener(ClassLoader classLoader, String className, String owner,
String methodName, String methodDesc, AdviceListener listener) {
classLoader = wrap(classLoader);
className = className.replace('/', '.');
ClassLoaderAdviceListenerManager manager = adviceListenerMap.get(classLoader);
@ -189,8 +198,10 @@ public class AdviceListenerManager {
}
manager.registerTraceAdviceListener(className, owner, methodName, methodDesc, listener);
}
public static List<AdviceListener> queryTraceAdviceListeners(ClassLoader classLoader, String className, String owner,
String methodName, String methodDesc) {
public static List<AdviceListener> queryTraceAdviceListeners(ClassLoader classLoader, String className,
String owner, String methodName, String methodDesc) {
classLoader = wrap(classLoader);
className = className.replace('/', '.');
ClassLoaderAdviceListenerManager manager = adviceListenerMap.get(classLoader);
@ -200,4 +211,15 @@ public class AdviceListenerManager {
return null;
}
private static ClassLoader wrap(ClassLoader classLoader) {
if (classLoader != null) {
return classLoader;
}
return FAKEBOOTSTRAPCLASSLOADER;
}
private static class FakeBootstrapClassLoader extends ClassLoader {
}
}

Loading…
Cancel
Save