Как видеть скомпилированный код JIT в JVM?

Существует две опции, явный делегат или делегат, замаскированный как конструкция lamba:

явный делегат

myObjects.RemoveAll(delegate (MyObject m) { return m.X >= 10; });

лямбда

myObjects.RemoveAll(m => m.X >= 10);
<час>

Дополнение:

Производительность, мудрая, оба равны. На самом деле, обе конструкции языка генерируют тот же IL, когда скомпилировано. Это вызвано тем, что C# 3.0 является в основном расширением на C# 2.0, таким образом, это компилирует в конструкции C# 2.0:)

76
задан assylias 7 August 2014 в 06:48
поделиться

2 ответа

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

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=#

when you're running your code.

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

45
ответ дан 24 November 2019 в 11:14
поделиться

Я считаю, что WinDbg будет вам полезен, если вы запускает его на машине Windows. Я только что запустил одну банку.

  • Затем я подключился к процессу java через Windbg
  • Проверял потоки командой ~ ; Было 11 потоков, 0 поток был основным рабочим потоком
  • Перешел на 0-поток - ~ 0s
  • Просмотрен через неуправляемый стек вызовов на kb , там было:

    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.

5
ответ дан 24 November 2019 в 11:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: