如何将 -XX:UnlockDiagnosticVMOptions -XX:CompileCommand=print 选项与 JVM HotSpot 一起使用
我正在尝试使用 -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod
命令行,如 这篇文章。
看来它可以通过 open-jdk
(https://wikis. oracle.com/display/HotSpotInternals/PrintAssembly)。
如何将这些选项(或类似的选项)与 oracle JDK7 和 JVM HotSpot 结合使用?
I 'm trying to use -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod
command lines as described in this post.
It seems thats it's available with open-jdk
(https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly).
How can I use those options (or similar equivalents) with oracle JDK7 and the JVM HotSpot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些说明适用于 Linux (Ubuntu 10.04.4 LTS),但也应适用于您的操作系统。下载 Oracle JDK 7u3 并正确安装后设置您的
JAVA_HOME
和PATH
环境变量,执行以下命令来检查可用选项:您应该看到
UnlockDiagnosticVMOptions
、CompileCommand
和PrintAssembly
选项可用。使用CompileCommand
选项还将启用PrintAssembly
选项。但是,您需要 HotSpot 反汇编器插件才能使PrintAssembly
正常工作;如果没有它,您可能会看到类似以下内容:要获取 HotSpot 反汇编器插件,您需要构建它。查看 OpenJDK 7u2 源代码, hsdis 插件自述文件 说:
上面我们已经确认Oracle JDK 7u3支持
PrintAssembly
。我按照 hsdis 插件自述文件说明,下载了 GNU binutils 2.22,将其放在 hsdisbuild/binutils
目录中并运行make
。这最终产生了以下错误:为了纠正这个问题,我使用以下补丁更改了 hsdis.c:
然后成功运行
make
。现在只需将 hsdisbuild
目录中的hsdis-i386.so
插件复制到 Oracle JDK 7u3jre/lib/i386
目录即可。现在您可以看到反汇编的编译代码:
我使用的测试类是:
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
andPATH
environment variables, execute the following to check available options:You should see the
UnlockDiagnosticVMOptions
,CompileCommand
andPrintAssembly
options are available. Using theCompileCommand
option will also enable thePrintAssembly
option. However, you will need the HotSpot disassembler plugin forPrintAssembly
to work; without it, you might see something like the following:To get the HotSpot disassembler plugin, you will need to build it. Looking at the OpenJDK 7u2 source, the hsdis plugin readme says:
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 hsdisbuild/binutils
directory and ranmake
. This eventually produced the following error:To correct this, I changed hsdis.c using the following patch:
Running
make
was then successful. Now just copy thehsdis-i386.so
plugin in the hsdisbuild
directory to the Oracle JDK 7u3jre/lib/i386
directory.Now you can see the disassembled compiled code:
The test class I've used is:
就我而言,查看反汇编的编译代码:
在上面的示例中,有一个循环:
for (int i = 0; i < 1 000 000; i++) {...}
,这就是为什么在没有 1 000 000 次迭代的情况下,我们需要 -XX:CompileThreshold=1 选项(-server 默认为 10 000)来查看反汇编的编译代码。
in my case to see the disassembled compiled code:
in example above has is cycle:
for (int i = 0; i < 1 000 000; i++) {...}
,that is why in our case without 1 000 000 iterations we need
-XX:CompileThreshold=1
option (by default 10 000 for -server) to see our disassembled compiled code.