????Java Code Instrumentation??λ????
public class JavaDynAgent {
private static Instrumentation instrumentation;
private static Object lockObject = new Object();
public JavaDynAgent() {
}
public static void agentmain(String args?? Instrumentation inst) {
Object var2 = lockObject;
synchronized(lockObject) {
if(instrumentation == null) {
instrumentation = inst;
System.out.println("0->" + inst);
} else {
System.out.println("1->" + inst);
}
}
}
public static Instrumentation getInstrumentation() {
return instrumentation;
}
}
?????????????
????1.??pid??????????????????????????????jar?????????????agentmain????????Instrumentation
????2.????Instrumentation?????????JDK????????????????????ж????????塣
???????com.sun.tools.attach.VirtualMachine??jar???? jdk??lib?е?tools.jar????????????????????jar????????????漰????????????windows??linux???????jar???
???????????????????
????1.????????? jdk/lib/tools.jar????????????VirtualMachine??
????2.????????? javaagent.jar ????????agentmain???
????3.?????????????JDK????