Home >Java >javaTutorial >How Can I View JIT-Compiled Code in the Java Virtual Machine (JVM)?

How Can I View JIT-Compiled Code in the Java Virtual Machine (JVM)?

Linda Hamilton
Linda HamiltonOriginal
2024-12-05 17:14:11330browse

How Can I View JIT-Compiled Code in the Java Virtual Machine (JVM)?

Viewing JIT-Compiled Code in Java Virtual Machine (JVM)

The Java Virtual Machine (JVM) features a Just-In-Time (JIT) compiler that optimizes Java bytecode into native code. To examine this native code, consider the following techniques:

General Usage

Utilize JVM options as follows:

-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly

Specific Method Filtering

You can isolate specific methods using the following syntax:

-XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod

Note:

  • Quotes may be necessary around the second argument, depending on the OS.
  • Method inlining may hinder observability of certain optimizations.

Installation on Windows

For Windows systems, follow the instructions below to build and install required libraries:

Prebuilt Binaries

Download prebuilt binaries for Windows from the fcml project:

  • hsdis-amd64.dll
  • hsdis-i386.dll

Manual Building

  1. Install Cygwin with the following packages:

    • make
    • mingw64-x86_64-gcc-core (for hsdis-amd64.dll)
    • mingw64-i686-gcc-core (for hsdis-i386.dll)
    • diffutils
  2. Extract the GNU binutils source package (e.g., binutils-2.25.tar.bz2) to your Cygwin home directory.
  3. Extract the OpenJDK hsdis directory (from srcsharetools) to your Cygwin home directory.
  4. In Cygwin Terminal, navigate to ~/hsdis.
  5. Build hsdis-amd64.dll (or hsdis-i386.dll) using the appropriate command:
make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
(or)
make OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
  1. Edit hsdisbuildLinux-amd64bfdMakefile and change SUBDIRS = doc po to SUBDIRS = po.
  2. Re-run the build command.
  3. Copy the built DLL to your JRE's binserver or binclient directory.

Additional Tips

For Intel ASM syntax, use the option -XX:PrintAssemblyOptions=intel alongside the PrintAssembly options.

The above is the detailed content of How Can I View JIT-Compiled Code in the Java Virtual Machine (JVM)?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn