Is there some way to see the native code produces by the JIT in a JVM?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Print the assembly of your hotspots with JMH's perfasm profilers (
LinuxPerfAsmProfiler
orWinPerfAsmProfiler
). JMH does require thehsdis
library since it relies onPrintAssembly
.General usage
As explained by other answers, you can run with the following JVM options:
Filter on a specific method
You can also filter on a specific method with the following syntax:
Notes:
How to: Install the required libraries on Windows
If you are running Windows, this page has instructions on how to build and install
hsdis-amd64.dll
andhsdis-i386.dll
which are required to make it work. We copy below and extend the content of that page* for reference:Where to get prebuilt binaries
You can download prebuilt binaries for Windows from the fcml project
How to build
hsdis-amd64.dll
andhsdis-i386.dll
on WindowsThis version of the guide was prepared on Windows 8.1 64bit using 64-bit Cygwin and producing hsdis-amd64.dll
Install Cygwin. At the
Select Packages
screen, add the following packages (by expanding theDevel
category, then clicking once on theSkip
label next to each package name):make
mingw64-x86_64-gcc-core
(only needed forhsdis-amd64.dll
)mingw64-i686-gcc-core
(only needed forhsdis-i386.dll
)diffutils
(inUtils
category)Run the Cygwin Terminal. This can be done using the Desktop or Start Menu icon created by the installer, and will create your Cygwin home directory (
C:\cygwin\home\<username>\
orC:\cygwin64\home\<username>\
by default).binutils-2.25.tar.bz2
. This should result in a directory namedbinutils-2.25
(or whatever the latest version is) in your Cygwin home directory.src\share\tools
) to your Cygwin home directory.cd ~/hsdis
.To build
hsdis-amd64.dll
, entermake OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
To build
hsdis-i386.dll
, entermake OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
In either case, replace
2.25
with the binutils version you downloaded.OS=Linux
is necessary because, although Cygwin is a Linux-like environment, the hsdis makefile fails to recognize it as such../chew: No such file or directory
andgcc: command not found
. Edit<Cygwin home directory>\hsdis\build\Linux-amd64\bfd\Makefile
in a text editor like Wordpad or Notepad++ to changeSUBDIRS = doc po
(line 342, if using binutils 2.25) toSUBDIRS = po
. Re-run the previous command.The DLL can now be installed by copying it from
hsdis\build\Linux-amd64
orhsdis\build\Linux-i586
to your JRE'sbin\server
orbin\client
directory. You can find all such directories on your system by searching forjava.dll
.Bonus tip: if you prefer Intel ASM syntax to AT&T, specify
-XX:PrintAssemblyOptions=intel
alongside any other PrintAssembly options you use.*page license is Creative Commons
Assuming you're using the Sun Hotspot JVM (i.e. the one provided on java.com by Oracle), you can add the flag
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
when you're running your code.
You can read more about this command and the functionality of JIT in general here.
For the HotSpot (was Sun) JVM, even in product modes:
http://wikis.oracle.com/display/HotSpotInternals/PrintAssembly
Some assembly required: it needs a plugin.
Another way to see machine code and some performance data is to use AMD's CodeAnalyst or OProfile, which have a Java plugin to visualize executing Java code as machine code.
You need an hsdis plugin to use
PrintAssembly
. A convenient choice is the hsdis plugin based on FCML library.It can be compiled for UNIX-like systems and on Windows you can use pre-built libraries available in the FCML download section on Sourceforge:
To install in Windows:
java.dll
(use Windows search). On my system, I found it at two locations:C:\Program Files\Java\jre1.8.0_45\bin\server
C:\Program Files\Java\jdk1.8.0_45\jre\bin\server
To install in Linux:
cd <source code dir>
./configure && make && sudo make install
cd example/hsdis && make && sudo make install
sudo ln -s /usr/local/lib/libhsdis.so <JDK PATH>/lib/amd64/hsdis-amd64.so
sudo ln -s /usr/local/lib/libhsdis.so <JDK PATH>/jre/lib/amd64/hsdis-amd64.so
/usr/lib/jvm/java-8-oracle
How to run it:
Additional configuration parameters:
code Print machine code before the mnemonic.
intel Use the Intel syntax.
gas Use the AT&T assembler syntax (GNU assembler compatible).
dec Prints IMM and displacement as decimal values.
mpad=XX Padding for the mnemonic part of the instruction.
cpad=XX Padding for the machine code.
seg Shows the default segment registers.
zeros Show leading zeros in case of HEX literals.
The Intel syntax is a default one in case of Windows, whereas the AT&T one is a default for the GNU/Linux.
For more details see the FCML Library Reference Manual