Attaching to a JVM image that does not include java.instrument

Rafael Winterhalter rafael.wth at gmail.com
Thu May 18 14:20:59 UTC 2017


Hei,

I found that it is impossible to dynamically attach to a JVM that does not
include the java.instrument module when built with jlink. This is a result
of the instrumentation API and its infrastructure missing from the image.

rafael at rafc:~/jdk9-test/greetingsapp$ ./bin/java
-javaagent:/home/rafael/.m2/repository/sample-agent/sample-agent/1.0-SNAPSHOT/sample-agent-1.0-SNAPSHOT.jar
-m com.greetings/com.greetings.Main
Error occurred during initialization of VM

Could not find agent library instrument on the library path, with error:
libinstrument.so: cannot open shared object file: No such file or directory

It is of course neither possible to attach an agent to the JVM on the
command line. This problem resolves when explicitly including the
java.instrumentation module what does however render an unused warning in
most IDEs.

I understand that one target of the jlink tool is to reduce the JVM's size.
For the example greetings app, the size different is however minimal:

rafael at rafc:~/jdk9-test$ du -sh greetingsapp-instrument
45M greetingsapp-instrument
rafael at rafc:~/jdk9-test$ du -sh greetingsapp
44M greetingsapp

I would therefore suggest to always include the instrumentation module when
building with jlink.I would find it rather confusing to end users not being
able to attach an agent more or less all existing tooling demands this
ability, especially since users of Java applications are not always
responsible for building applications.

At a minimum, I would suggest a better error message and the rejection of
the javaagent parameter on the bundled command java executable. However, I
strongly suggest to not go for this solution as the instrumentation module
is unlikely to be included by any main application what would result in
such images never being compatible with agents, this breaking compatibility
of jlink built images to basically any Java tooling including that provided
by Oracle.

Best regards, Rafael


More information about the jigsaw-dev mailing list