我正在尝试使用jolJava 9 运行程序,但没有运气.
我有以下依赖pom.xml:
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
该计划很简单:
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());
}
}
Run Code Online (Sandbox Code Playgroud)
模块描述符:
module java9 {
requires jol.core;
}
Run Code Online (Sandbox Code Playgroud)
当我从IDEA运行程序时,我看到以下输出:
# WARNING: Unable to get Instrumentation. Dynamic Attach failed.
You may add this JAR as -javaagent manually, or supply -Djdk.attach.allowAttachSelf
Run Code Online (Sandbox Code Playgroud)
我-Djdk.attach.allowAttachSelf=true在IDEA中添加了VM参数,但它没有帮助(仍然是相同的输出).
PS我可以从类路径成功运行程序.尽管如此,如何从模块路径运行它仍然很有趣.
好吧,我尝试进一步调试,发现警告的原因是在应用程序启动时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);
...
Run Code Online (Sandbox Code Playgroud)
该类未加载最初解析的模块,因为它的包是从jdk.attach模块描述符中当前缺少的模块导出的。因此,您可以更新为使用模块声明:
module java9 { // module name 'joltrial' in output
requires jol.core;
requires jdk.attach;
}
Run Code Online (Sandbox Code Playgroud)
然后允许使用 VM 选项进一步自附加:-
-Djdk.attach.allowAttachSelf=true
Run Code Online (Sandbox Code Playgroud)
执行共享代码 [ 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
694 次 |
| 最近记录: |