< prev index next >

test/jdk/java/lang/instrument/TraceUsageAgent.java

Print this page

30  * Agent used by TraceUsageTest. The premain and agentmain methods invoke Instrumentation
31  * methods so the usages can be traced by the test.
32  */
33 public class TraceUsageAgent {
34     public static void premain(String methodNames, Instrumentation inst) throws Exception {
35         test(methodNames, inst);
36     }
37 
38     public static void agentmain(String methodNames, Instrumentation inst) throws Exception {
39         test(methodNames, inst);
40     }
41 
42     private static void test(String methodNames, Instrumentation inst) throws Exception {
43         for (String methodName : methodNames.split(",")) {
44             switch (methodName) {
45                 case "addTransformer" -> {
46                     var transformer = new ClassFileTransformer() { };
47                     inst.addTransformer(transformer);
48                 }
49                 case "retransformClasses" -> {
50                     inst.retransformClasses(Object.class);
51                 }
52                 case "redefineModule" -> {
53                     Module base = Object.class.getModule();
54                     inst.redefineModule(base, Set.of(), Map.of(), Map.of(), Set.of(), Map.of());
55                 }
56                 default -> {
57                     throw new RuntimeException("Unknown method name: " + methodName);
58                 }
59             }
60         }
61     }
62 }

30  * Agent used by TraceUsageTest. The premain and agentmain methods invoke Instrumentation
31  * methods so the usages can be traced by the test.
32  */
33 public class TraceUsageAgent {
34     public static void premain(String methodNames, Instrumentation inst) throws Exception {
35         test(methodNames, inst);
36     }
37 
38     public static void agentmain(String methodNames, Instrumentation inst) throws Exception {
39         test(methodNames, inst);
40     }
41 
42     private static void test(String methodNames, Instrumentation inst) throws Exception {
43         for (String methodName : methodNames.split(",")) {
44             switch (methodName) {
45                 case "addTransformer" -> {
46                     var transformer = new ClassFileTransformer() { };
47                     inst.addTransformer(transformer);
48                 }
49                 case "retransformClasses" -> {
50                     inst.retransformClasses(Integer.class);
51                 }
52                 case "redefineModule" -> {
53                     Module base = Object.class.getModule();
54                     inst.redefineModule(base, Set.of(), Map.of(), Map.of(), Set.of(), Map.of());
55                 }
56                 default -> {
57                     throw new RuntimeException("Unknown method name: " + methodName);
58                 }
59             }
60         }
61     }
62 }
< prev index next >