tags:

views:

465

answers:

2

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

+1  A: 

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
    0008fbac 7c8025cb ntdll!ZwWaitForSingleObject+0xc
    0008fc10 7c802532 kernel32!WaitForSingleObjectEx+0xa8
    0008fc24 00403a13 kernel32!WaitForSingleObject+0x12
    0008fc40 00402f68 java+0x3a13
    0008fee4 004087b8 java+0x2f68
    0008ffc0 7c816fd7 java+0x87b8

    0008fff0 00000000 kernel32!BaseProcessStart+0x23

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

  • Then we can look for method address:
    java+0x2f68 is 00402f68

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

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

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

Andrey Tkach
+7  A: 

Assuming you're using the Sun Hotspot JVM. Add the flag

-XX:+PrintOptoAssembly

To whatever you're running. This will only print the assembly for code that has been JIT'd (i.e. you don't get to see assembly for non JIT'd stuff) but I think that's what you want. If you want to see what everything would like if it were JIT'd you could probably tweak the JIT threshold via:

-XX:CompileThreshold=#

Falaina
Is this option only present in debug builds or anything? Because my JVM ("Java(TM) SE Runtime Environment (build 1.6.0_16-b01") doesn't recognize it even though source on the web indicate this feature being available in Sun Java 6 and OpenJDK.
Joachim Sauer
Yes, DEBUG binaries needed. http://blogs.warwick.ac.uk/richardwarburton/entry/hotspot_print_assembly/
alsor.net