fix the issue when the woven code is still running and throw NullPointerException after executing the stop command. #1094

pull/1097/head
hengyunabc 5 years ago
parent fa5fc3d575
commit 79ba5271f9

@ -8,7 +8,12 @@ import java.lang.reflect.Method;
* Created by vlinux on 15/8/23.
*/
public class Spy {
public static final String ON_BEFORE = "methodOnBegin";
public static final String ON_RETURN = "methodOnReturnEnd";
public static final String ON_THROWS = "methodOnThrowingEnd";
public static final String BEFORE_INVOKE = "methodOnInvokeBeforeTracing";
public static final String AFTER_INVOKE = "methodOnInvokeAfterTracing";
public static final String THROW_INVOKE = "methodOnInvokeThrowTracing";
// -- 各种Advice的钩子引用 --
public static volatile Method ON_BEFORE_METHOD;
@ -53,13 +58,7 @@ public class Spy {
* to avoid classloader leak.
*/
public static void destroy() {
CLASSLOADER = null;
ON_BEFORE_METHOD = null;
ON_RETURN_METHOD = null;
ON_THROWS_METHOD = null;
BEFORE_INVOKING_METHOD = null;
AFTER_INVOKING_METHOD = null;
THROW_INVOKING_METHOD = null;
initEmptySpy();
// clear the reference to ArthasClassLoader in AgentLauncher
if (AGENT_RESET_METHOD != null) {
try {
@ -71,4 +70,62 @@ public class Spy {
AGENT_RESET_METHOD = null;
}
private static void initEmptySpy() {
try {
Class<?> adviceWeaverClass = Spy.class;
Method onBefore = adviceWeaverClass.getMethod(Spy.ON_BEFORE, int.class, ClassLoader.class, String.class,
String.class, String.class, Object.class, Object[].class);
Method onReturn = adviceWeaverClass.getMethod(Spy.ON_RETURN, Object.class);
Method onThrows = adviceWeaverClass.getMethod(Spy.ON_THROWS, Throwable.class);
Method beforeInvoke = adviceWeaverClass.getMethod(Spy.BEFORE_INVOKE, int.class, String.class, String.class,
String.class, int.class);
Method afterInvoke = adviceWeaverClass.getMethod(Spy.AFTER_INVOKE, int.class, String.class, String.class,
String.class, int.class);
Method throwInvoke = adviceWeaverClass.getMethod(Spy.THROW_INVOKE, int.class, String.class, String.class,
String.class, int.class);
Spy.init(null, onBefore, onReturn, onThrows, beforeInvoke, afterInvoke, throwInvoke);
} catch (Exception e) {
}
}
/**
* empty method
*
* @see com.taobao.arthas.core.advisor.AdviceWeaver#methodOnBegin(int,
* ClassLoader, String, String, String, Object, Object[])
* @param adviceId
* @param loader
* @param className
* @param methodName
* @param methodDesc
* @param target
* @param args
*/
public static void methodOnBegin(int adviceId, ClassLoader loader, String className, String methodName,
String methodDesc, Object target, Object[] args) {
}
/**
* empty method
*
* @see com.taobao.arthas.core.advisor.AdviceWeaver#methodOnReturnEnd(Object)
* @param returnObject
*/
public static void methodOnReturnEnd(Object returnObject) {
}
public static void methodOnThrowingEnd(Throwable throwable) {
}
public static void methodOnInvokeBeforeTracing(int adviceId, String owner, String name, String desc,
int lineNumber) {
}
public static void methodOnInvokeAfterTracing(int adviceId, String owner, String name, String desc,
int lineNumber) {
}
public static void methodOnInvokeThrowTracing(int adviceId, String owner, String name, String desc,
int lineNumber) {
}
}

Loading…
Cancel
Save