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

Alan Bateman Alan.Bateman at
Thu May 18 15:19:11 UTC 2017

On 18/05/2017 15:20, Rafael Winterhalter wrote:

> 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:
> cannot open shared object file: No such file or directory
Ugh, when -javaagent is specified then it is supposed to work as if 
`--add-modules java.instrument` is also on the command line. This 
ensures that the java.instrument module is resolved. The intention was 
also to get a useful error if the run-time image doesn't contain 

Another example is `*` which should work as if 
`--add-modules` is specified on the command line. 
Also `-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI` which is 
supposed to add `--add-modules`. I just checked both 
of these and the error is helpful as I expected.

As regards the attach mechanism then it will work when it is compiled in 
and enabled in the target VM. When I say "compiled in" then I mean the 
support is in libjvm. When using jlink when you can select the minimal 
VM to get a much smaller VM that doesn't have the serviceability 
features. That won't be typical of course so assume it is libjvm then 
you should be able to attach and troubleshooting tools such as `jcmd` 
will work. If you attempt to load a java agent then the target VM will 
attempt to resolve and load the java.instrument module and so will fail 
if the run-time image doesn't have the module.

You are right that java.instrument is small but it's always been a goal 
to be able to create run-time images that only contain java.base.

I didn't understand your comment about an "unused warnings" in the IDE. 
Do you mean `requires java.instrument` rather than specifying 
java.instrument to the `jlink --add-modules` option?


More information about the jigsaw-dev mailing list