Accessing Attach API?

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Apr 13 09:08:38 UTC 2016


Hi,

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.

This hack in JDK 9 build helps, of course:

diff -r 1d992540870f make/common/Modules.gmk
--- a/make/common/Modules.gmk	Sat Apr 09 19:49:32 2016 +0100
+++ b/make/common/Modules.gmk	Wed Apr 13 12:07:25 2016 +0300
@@ -68,6 +68,7 @@
     jdk.security.jgss \
     jdk.unsupported \
     jdk.vm.ci \
+    jdk.attach \
     #

 # to be deprivileged

What is the actual way out?

Thanks,
-Aleksey



More information about the jigsaw-dev mailing list