How to run jol on Java 9?

I am trying to run a program using jolwith Java 9 but 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=trueVM arguments to IDEA, but that didn't help (all the same output).

PS I can successfully run the program from the class. However, I wonder how to start it from the path to the module.

+6
source share
1 answer

, , InstrumentationSupport DYNAMIC_ATTACH , dynamicAttach, VirtualMachine,

String name = "com.sun.tools.attach.VirtualMachine";
try {
    // JDK 9+ makes this class available on class path
    vmClass = ClassLoader.getSystemClassLoader().loadClass(name);
...

, jdk.attach, , , :

module java9 {    // module name 'joltrial' in output
    requires jol.core;
    requires jdk.attach;
} 

VM : -

-Djdk.attach.allowAttachSelf=true

[ VM.current().details()] -

/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java -Djdk.attach.allowAttachSelf=true "-javaagent:/Applications/IntelliJ IDEA 2017.3 CE EAP.app/Contents/lib/idea_rt.jar=53783:/Applications/IntelliJ IDEA 2017.3 CE EAP.app/Contents/bin" -Dfile.encoding=UTF-8 -p .../joltrial/target/classes:.../.m2/repository/org/openjdk/jol/jol-core/0.9/jol-core-0.9.jar -m joltrial/com.Sample
# WARNING: Unable to attach Serviceability Agent. Unable to attach even with module exceptions: [org.openjdk.jol.vm.sa.SASupportException: Sense failed., org.openjdk.jol.vm.sa.SASupportException: Sense failed., org.openjdk.jol.vm.sa.SASupportException: Sense failed.]
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# WARNING | Compressed references base/shifts are guessed by the experiment!
# WARNING | Therefore, computed addresses are just guesses, and ARE NOT RELIABLE.
# WARNING | Make sure to attach Serviceability Agent to get the reliable addresses.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

Process finished with exit code 0
+4

All Articles