On 04/13/2016 12:08 PM, Aleksey Shipilev wrote: > OpenJDK JOL is using Attach API to get the access to Instrumentation > instance without forcing user to -javaagent: the JAR. I think ByteBuddy > is using similar mechanism. > > How is one supposed to use Attach API these post-Jigsaw days? > > Before JDK 9, we could poll VirtualMachine from tools.jar, and then use > the snippet from the original Javadoc: > > http://docs.oracle.com/javase/8/docs/jdk/api/attach/spec/com/sun/tools/attach/VirtualMachine.html > > ...then, after tools.jar was gone in JDK 9, the classes were still > available on classpath, and we could do, e.g.: > System.getClassloader().loadClass("com.sun.tools.attach.VirtualMachine"). > > Now, with Jigsaw integrated, this class is not available, because > jdk.attach is not a platform module. I see there are attempts to expose > SPI via com.sun.tools.attach.spi.AttachProvider -- but of course, > AttachProvider is also not available to feed it to ServiceLoader.
Wait, I confused myself with multiple JDK builds here. This actually works in JDK 9b113: Class<?> vmClass = ClassLoader.getSystemClassLoader() .loadClass("com.sun.tools.attach.VirtualMachine"); Therefore, we are fine at the moment. Is this behavior to stay? Thanks, -Aleksey