40 import jdk.internal.org.objectweb.asm.ClassVisitor; |
41 import jdk.internal.org.objectweb.asm.ClassVisitor; |
41 import jdk.internal.org.objectweb.asm.ClassWriter; |
42 import jdk.internal.org.objectweb.asm.ClassWriter; |
42 import jdk.internal.org.objectweb.asm.MethodVisitor; |
43 import jdk.internal.org.objectweb.asm.MethodVisitor; |
43 import jdk.internal.org.objectweb.asm.Opcodes; |
44 import jdk.internal.org.objectweb.asm.Opcodes; |
44 |
45 |
45 import javax.tools.ToolProvider; |
|
46 import java.io.FileOutputStream; |
46 import java.io.FileOutputStream; |
47 import java.io.IOException; |
47 import java.io.IOException; |
48 import java.io.InputStream; |
48 import java.io.InputStream; |
49 import java.lang.instrument.ClassFileTransformer; |
49 import java.lang.instrument.ClassFileTransformer; |
50 import java.lang.instrument.IllegalClassFormatException; |
50 import java.lang.instrument.IllegalClassFormatException; |
130 public static void runAgent(Path agent) throws Exception { |
130 public static void runAgent(Path agent) throws Exception { |
131 String vmName = ManagementFactory.getRuntimeMXBean().getName(); |
131 String vmName = ManagementFactory.getRuntimeMXBean().getName(); |
132 int p = vmName.indexOf('@'); |
132 int p = vmName.indexOf('@'); |
133 assert p != -1 : "VM name not in <pid>@<host> format: " + vmName; |
133 assert p != -1 : "VM name not in <pid>@<host> format: " + vmName; |
134 String pid = vmName.substring(0, p); |
134 String pid = vmName.substring(0, p); |
135 ClassLoader cl = ToolProvider.getSystemToolClassLoader(); |
135 ClassLoader cl = ClassLoader.getSystemClassLoader(); |
136 Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl); |
136 Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl); |
137 Method attach = c.getDeclaredMethod("attach", String.class); |
137 Method attach = c.getDeclaredMethod("attach", String.class); |
138 Method loadAgent = c.getDeclaredMethod("loadAgent", String.class); |
138 Method loadAgent = c.getDeclaredMethod("loadAgent", String.class); |
139 Method detach = c.getDeclaredMethod("detach"); |
139 Method detach = c.getDeclaredMethod("detach"); |
140 Object vm = attach.invoke(null, pid); |
140 Object vm = attach.invoke(null, pid); |