Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 514 Vote(s) - 3.65 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to see JIT-compiled code in JVM?

#1
Is there some way to see the native code produces by the JIT in a JVM?
Reply

#2
I believe WinDbg would be helpful if you are running it on windows machine.
I have just run one jar.

- Then I attached to the java process
through **Windbg**
- Examined threads by **~** command; There were 11 threads, 0 thread was main worker thread
- Switched to 0-thread - **~0s**
- Looked through unmanmaged callstack by **kb** there was:

0008fba8 7c90e9c0 ntdll!KiFastSystemCallRet<br>
0008fbac 7c8025cb ntdll!ZwWaitForSingleObject+0xc<br>
0008fc10 7c802532 kernel32!WaitForSingleObjectEx+0xa8<br>
0008fc24 00403a13 kernel32!WaitForSingleObject+0x12<br>
**0008fc40 00402f68 java+0x3a13<br>
0008fee4 004087b8 java+0x2f68<br>
0008ffc0 7c816fd7 java+0x87b8**<br>
0008fff0 00000000 kernel32!BaseProcessStart+0x23<br>

Highlighted lines is direct running JIT-ed code on JVM.

- Then we can look for method address:<br>
**java+0x2f68 is 00402f68**<br/>

- On WinDBG:<br> Click View -->
Disassembly.<br> Click Edit --> Go to
Address.<br> Put **00402f68** there<br>
and got

00402f68 55 push ebp<br>
00402f69 8bec mov ebp,esp<br>
00402f6b 81ec80020000 sub esp,280h<br>
00402f71 53 push ebx<br>
00402f72 56 push esi<br>
00402f73 57 push edi<br>
**...** and so on

For additional info here is the [Example][1] how to trace back JIT-ed code from memory dumps using process explorer and WinDbg.


[1]:

[To see links please register here]

Reply

#3
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.
Reply

#4
Print the assembly of your hotspots with JMH's perfasm profilers (`LinuxPerfAsmProfiler` or `WinPerfAsmProfiler`). JMH does require the `hsdis` library since it relies on `PrintAssembly`.
Reply

#5
###General usage

As explained by other answers, you can run with the following JVM options:

-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly

###Filter on a specific method

You can also filter on a specific method with the following syntax:

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

Notes:

- you might need to put the second argument within quotes depending on OS etc.
- if the method gets inlined, you could miss some optimisations

###How to: Install the required libraries on Windows

If you are running Windows, [this page][1] has instructions on how to build and install `hsdis-amd64.dll` and `hsdis-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][2] project

- [hsdis-amd64.dll][3]
- [hsdis-i386.dll][4]

**How to build `hsdis-amd64.dll` and `hsdis-i386.dll` on Windows**

*This version of the guide was prepared on Windows 8.1 64bit using 64-bit Cygwin and producing hsdis-amd64.dll*


1. [Install Cygwin][5]. At the `Select Packages` screen, add the following packages (by expanding the `Devel` category, then clicking once on the `Skip` label next to each package name):

- `make`
- `mingw64-x86_64-gcc-core` (only needed for `hsdis-amd64.dll`)
- `mingw64-i686-gcc-core` (only needed for `hsdis-i386.dll`)
- `diffutils` (in `Utils` category)

2. 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>\` or `C:\cygwin64\home\<username>\` by default).
3. [Download the latest GNU binutils source package][6] and extract its contents to your Cygwin home directory. At the time of writing, the latest package is `binutils-2.25.tar.bz2`. This should result in a directory named `binutils-2.25` (or whatever the latest version is) in your Cygwin home directory.
4. Download the OpenJDK source by [going to the JDK 8 Updates repository][7], selecting the tag corresponding to your installed JRE version, and clicking bz2. Extract the hsdis directory (found in `src\share\tools`) to your Cygwin home directory.
5. In the Cygwin Terminal, enter `cd ~/hsdis`.
6. To build `hsdis-amd64.dll`, enter

`make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25`

To build `hsdis-i386.dll`, enter

`make 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.
7. The build will fail with messages `./chew: No such file or directory` and `gcc: command not found`. Edit `<Cygwin home directory>\hsdis\build\Linux-amd64\bfd\Makefile` in a text editor like Wordpad or Notepad++ to change `SUBDIRS = doc po` (line 342, if using binutils 2.25) to `SUBDIRS = po`. Re-run the previous command.

The DLL can now be installed by copying it from `hsdis\build\Linux-amd64` or `hsdis\build\Linux-i586` to your JRE's `bin\server` or `bin\client` directory. You can find all such directories on your system by searching for `java.dll`.

Bonus tip: if you prefer Intel ASM syntax to AT&T, specify `-XX:PrintAssemblyOptions=intel` alongside any other PrintAssembly options you use.

<sub>*page license is Creative Commons</sub>


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

[6]:

[To see links please register here]

[7]:

[To see links please register here]

Reply

#6
For the HotSpot (was Sun) JVM, even in product modes:

[

[To see links please register here]

][1]

Some assembly required: it needs a plugin.

[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through