-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMyAgent.java
More file actions
37 lines (28 loc) · 771 Bytes
/
Copy pathMyAgent.java
File metadata and controls
37 lines (28 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package agent;
import java.lang.instrument.Instrumentation;
public class MyAgent
{
/**
* 该方法在main方法之前运行,与main方法运行在同一个JVM中 并被同一个System ClassLoader装载
* 被统一的安全策略(security policy)和上下文(context)管理
*/
public static void premain(String agentOps, Instrumentation inst)
{
System.out.println("=========premain方法执行========");
System.out.println(agentOps);
// 添加Transformer
inst.addTransformer(new MyTransformer());
}
/**
* 如果不存在 premain(String agentOps, Instrumentation inst) 则会执行 premain(String
* agentOps)
*/
public static void premain(String agentOps)
{
System.out.println("====premain方法执行2====");
System.out.println(agentOps);
}
public static void main(String[] args)
{
}
}