且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 JVM 中查看 JIT 编译的代码?

更新时间:2023-11-10 18:46:04

假设您使用的是 Sun Hotspot JVM(即 java.com 由 Oracle 提供),您可以添加标志

Assuming you're using the Sun Hotspot JVM (i.e. the one provided on java.com by Oracle), you can add the flag

-XX:+PrintOptoAssembly

-XX:+PrintOptoAssembly

运行代码时.这将打印出 JIT 编译器生成的优化代码,并忽略其余部分.

when running your code. This will print out the optimized code generated by the JIT compiler and leaves out the rest.

如果您想查看整个字节码,包括未优化的部分,请添加

If you want see the entire bytecode, including the unoptimized parts, add

-XX:CompileThreshold=#

-XX:CompileThreshold=#

当您运行代码时.

您可以阅读有关此命令和 JIT 功能的更多信息此处.

You can read more about this command and the functionality of JIT in general here.