Смотрим машинные инструкции Java
В Java есть возможность смотреть сгенерированный машинный код с помощью опции +PrintAssembly. Одна эта опции не работает надо добавить +UnlockDiagnosticVMOptions:
java -XX:+PrintAssembly ru.yamakarov.App
Error: VM option 'PrintAssembly' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Добавляем:
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly ru.yamakarov.App
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Could not load hsdis-amd64.dylib; library not loadable; PrintAssembly is disabled
Hello world
Для меня сработала инструкция отсюда
cd $JAVA_HOME/jre/lib/server
wget https://raw.githubusercontent.com/a10y/hsdis-macos/master/hsdis-amd64.dylib
Viola!
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly ru.yamakarov.App
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre/lib/server/hsdis-amd64.dylib
Decoding compiled method 0x000000010fc9c610:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} {0x000000010992b878} 'getSnapshotTransformerList' '()[Lsun/instrument/TransformerManager$TransformerInfo;' in 'sun/instrument/TransformerManager'
# [sp+0x40] (sp of caller)
0x000000010fc9c760: mov 0x8(%rsi),%r10d
0x000000010fc9c764: shl $0x3,%r10
0x000000010fc9c768: cmp %rax,%r10
0x000000010fc9c76b: jne 0x000000010fbdee20 ; {runtime_call}
0x000000010fc9c771: data16 data16 nopw 0x0(%rax,%rax,1)
...
Ох чего-то много непонятных ассемблерных буковок вывелось и метод main
не найти только “Hello world”.