I'm trying to run a program using jol
with Java 9 but with no luck.
I have the following dependency in pom.xml
:
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.9</version>
</dependency>
The program is simple:
package org.example;
import org.openjdk.jol.vm.VM;
public class Example {
public static void main(String[] args) throws Throwable {
System.out.println(VM.current().details());
}
}
Module descriptor:
module java9 {
requires jol.core;
}
When I run the program from IDEA, I see the following output:
# WARNING: Unable to get Instrumentation. Dynamic Attach failed.
You may add this JAR as -javaagent manually, or supply -Djdk.attach.allowAttachSelf
I added -Djdk.attach.allowAttachSelf=true
to the VM arguments in IDEA but it didn't help (still the same output).
P.S. I can run the program successfully from the classpath. Still, it is interesting how to run it from the module path.
Well, I tried debugging this a little further an found that the cause of the warning is
InstrumentationSupport
trying DYNAMIC_ATTACH on the application startup. The relevant section ofdynamicAttach
where the code actually makes use of theVirtualMachine
isThe class is not loaded with initially resolved modules since its package is exported from
jdk.attach
module which is currently missing from the module descriptor. Hence you can update to using the module declarations as :and then allow self-attach further using the VM option as:-
On executing the shared code [
VM.current().details()
], the output shall include details as -