如何使用-XX:+ UnlockDiagnosticVMOptions -XX:CompileCommand =打印与JVM热点选项 [英] How to use -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print option with JVM HotSpot

查看:3668
本文介绍了如何使用-XX:+ UnlockDiagnosticVMOptions -XX:CompileCommand =打印与JVM热点选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是试图用 -XX:+ UnlockDiagnosticVMOptions -XX:CompileCommand =打印,* MyClass.myMethod 命令行中所描述的this帖子

I 'm trying to use -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod command lines as described in this post.

看来这就是它的可用与开放式的JDK https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly )。

It seems thats it's available with open-jdk (https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly).

如何使用这些选项(或类似当量)与Oracle JDK7和JVM热点?

推荐答案

这些说明适用于Linux操作系统(Ubuntu的LTS 10.04.4),但应适用于您的操作系统。下载甲骨文JDK 7U3 并适当设置你的<$ C后$ C> JAVA_HOME 和 PATH 环境变量,执行以下检查可用的选项:

These instructions apply to Linux (Ubuntu 10.04.4 LTS), but should be applicable for your OS. After downloading Oracle JDK 7u3 and appropriately setting your JAVA_HOME and PATH environment variables, execute the following to check available options:

java -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version

您应该看到 UnlockDiagnosticVMOptions CompileCommand PrintAssembly 选项。使用 CompileCommand 选项也将启用 PrintAssembly 选项。但是,您将需要为 PrintAssembly 的热点反汇编插件工作;没有它,你可能会看到类似以下内容:

You should see the UnlockDiagnosticVMOptions, CompileCommand and PrintAssembly options are available. Using the CompileCommand option will also enable the PrintAssembly option. However, you will need the HotSpot disassembler plugin for PrintAssembly to work; without it, you might see something like the following:

$ java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) Server VM (build 22.1-b02, mixed mode)
$ java -server -XX:+UnlockDiagnosticVMOptions '-XX:CompileCommand=print,*Main.main' Main
CompilerOracle: print *Main.main
Java HotSpot(TM) Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output
Compiled method (c2)      68    1 %           Main::main @ 4 (49 bytes)
 total in heap  [0xb3a97548,0xb3a979ec] = 1188
 relocation     [0xb3a97610,0xb3a97624] = 20
 main code      [0xb3a97640,0xb3a97840] = 512
 stub code      [0xb3a97840,0xb3a97850] = 16
 oops           [0xb3a97850,0xb3a97858] = 8
 scopes data    [0xb3a97858,0xb3a97898] = 64
 scopes pcs     [0xb3a97898,0xb3a979e8] = 336
 dependencies   [0xb3a979e8,0xb3a979ec] = 4
Could not load hsdis-i386.so; library not loadable; PrintAssembly is disabled
OopMapSet contains 1 OopMaps

要获得热点反汇编插件,你将需要建立它。纵观OpenJDK的7U2来源,<一个href=\"http://hg.openjdk.java.net/jdk7u/jdk7u2/hotspot/file/0744602f85c6/src/share/tools/hsdis/README\">hsdis插件自述说:

To get the HotSpot disassembler plugin, you will need to build it. Looking at the OpenJDK 7u2 source, the hsdis plugin readme says:

要使用JVM使用的插件,你需要一个新的版本,可以加载它。
  如果你的JVM的产品模式不接受-XX:+ PrintAssembly,
  你没有一个版本是不够新。

To use the plugin with a JVM, you need a new version that can load it. If the product mode of your JVM does not accept -XX:+PrintAssembly, you do not have a version that is new enough.

要建这个项目,你[需要] GNU binutils的副本进行建设。

To build this project you [need] a copy of GNU binutils to build against.

在理论上这应该是可建在Windows上,但得到一个工作
  GNU建立在Windows环境中已经证明,很难。

In theory this should be buildable on Windows but getting a working GNU build environment on Windows has proven difficult.

我们在上面已经甲骨文JDK 7U3支持确认 PrintAssembly 。我跟着hsdis插件自述说明,下载了GNU binutils的2.22,其放置在hsdis 建立/ binutils的目录并运行制作。这最终将产生以下错误:

We have confirmed above that Oracle JDK 7u3 supports PrintAssembly. I followed the hsdis plugin readme instructions, downloaded GNU binutils 2.22, placed it in the hsdis build/binutils directory and ran make. This eventually produced the following error:

hsdis.c:32:20: error: sysdep.h: No such file or directory

要解决这个问题,我改变hsdis.c使用下面的补丁:

To correct this, I changed hsdis.c using the following patch:

diff -r 6259c6d3bbb7 src/share/tools/hsdis/hsdis.c
--- a/src/share/tools/hsdis/hsdis.c Mon Dec 12 23:08:01 2011 -0800
+++ b/src/share/tools/hsdis/hsdis.c Thu Feb 23 09:26:37 2012 -0500
@@ -29,7 +29,7 @@

 #include "hsdis.h"

-#include <sysdep.h>
+#include <errno.h>
 #include <libiberty.h>
 #include <bfd.h>
 #include <dis-asm.h>

运行制作当时成功。现在只是在hsdis复制 hsdis-i386.so 插件建立目录到Oracle JDK 7U3 的jre / lib中/ I386 目录

Running make was then successful. Now just copy the hsdis-i386.so plugin in the hsdis build directory to the Oracle JDK 7u3 jre/lib/i386 directory.

现在你可以看到拆解编译code:

Now you can see the disassembled compiled code:

$ java -server -XX:+UnlockDiagnosticVMOptions '-XX:CompileCommand=print,*Main.main' Main
CompilerOracle: print *Main.main
Java HotSpot(TM) Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output
Compiled method (c2)      68    1 %           Main::main @ 4 (49 bytes)
 total in heap  [0xb3999548,0xb39999ec] = 1188
 relocation     [0xb3999610,0xb3999624] = 20
 main code      [0xb3999640,0xb3999840] = 512
 stub code      [0xb3999840,0xb3999850] = 16
 oops           [0xb3999850,0xb3999858] = 8
 scopes data    [0xb3999858,0xb3999898] = 64
 scopes pcs     [0xb3999898,0xb39999e8] = 336
 dependencies   [0xb39999e8,0xb39999ec] = 4
Loaded disassembler from [snip]/jdk1.7.0_03/jre/lib/i386/hsdis-i386.so
Decoding compiled method 0xb3999548:
Code:
[Disassembling for mach='i386']
[Entry Point]
[Verified Entry Point]
[Constants]
  # {method} 'main' '([Ljava/lang/String;)V' in 'Main'
  0xb3999640: call   0xb6ff8510         ;   {runtime_call}
  0xb3999645: data32 xchg %ax,%ax
  0xb3999648: mov    %eax,-0x3000(%esp)
  0xb399964f: push   %ebp
  0xb3999650: sub    $0x38,%esp
  0xb3999656: mov    %ecx,%esi
  0xb3999658: mov    0x4(%esi),%ebp
  0xb399965b: mov    0x8(%esi),%edi
  0xb399965e: mov    (%ecx),%esi
  0xb3999660: mov    %ecx,(%esp)
  0xb3999663: call   0xb7078cf0         ;*iload_3
[snip]
  0xb399983e: hlt    
  0xb399983f: hlt    
[Exception Handler]
[Stub Code]
  0xb3999840: jmp    0xb39981e0         ;   {no_reloc}
[Deopt Handler Code]
  0xb3999845: push   $0xb3999845        ;   {section_word}
  0xb399984a: jmp    0xb397e220         ;   {runtime_call}
  0xb399984f: .byte 0x0
OopMapSet contains 1 OopMaps

#0 
OopMap{off=468}

我使用的测试类是:

The test class I've used is:

public class Main {
    public static void main(final String[] args) {
        long x = 0;
        for (int i = 0; i < 1000000; i++) {
            x += calculate(i);
        }
        System.out.println("x=" + x);
    }

    private static long calculate(final int i) {
        return (long)i * (long)i;
    }
}

这篇关于如何使用-XX:+ UnlockDiagnosticVMOptions -XX:CompileCommand =打印与JVM热点选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆