I was wondering, is it possible to get eyes on the actual machine code that the HotSpot compiler generates when it compiles a given Java bytecode class or method?
Asked
Active
Viewed 1,102 times
7
-
possible duplicate of [How Translate ByteCode to Machine Native Code](http://stackoverflow.com/questions/8167479/how-translate-bytecode-to-machine-native-code) – Richard J. Ross III Jul 12 '14 at 23:48
-
Even if it's ... it won't be readable. – Rahul Jul 12 '14 at 23:53
-
I actually don't want to use it to improve performance, just to get eyes on the actual machine code for a computer architecture course. – Recusiwe Jul 12 '14 at 23:53
-
Though there are [3rd-party tools](http://stackoverflow.com/questions/8167479/how-translate-bytecode-to-machine-native-code?rq=1) for such compilation, this is not what normally happening, unless your inquiry is about [JIT](http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/underst_jit.html) compilation. – PM 77-1 Jul 12 '14 at 23:54
-
My inquiry is just to get a look on the actual machine code to describe the different levels. – Recusiwe Jul 12 '14 at 23:56
-
Creating it on your own can be a bit fiddly (as mentioned in the answer below, this requires the hsdis-file, and obtaining or even compiling this may not be worth the effort if you "just want to have a look at the results") - but you can find several StackOverflow answers where people posted the JIT-result-machine code for analyzing certain problems. – Marco13 Jul 13 '14 at 00:23
-
See also this Question: http://stackoverflow.com/questions/9341083/how-to-use-xxunlockdiagnosticvmoptions-xxcompilecommand-print-option-with-j – Stephen C Jul 13 '14 at 00:45
1 Answers
11
Yes, with -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
the Hotspot VM can give you that information when it actually executes (compiles) a given bytecode method.
See for example HotSpotInternals Wiki:Print Assembly for details. It does require a disassembler module (hsdis-*.dll on Windows).
A bit more comfortable is using JITWatch (but it uses the same infrastructure from HotSpot).

try-catch-finally
- 7,436
- 6
- 46
- 67

eckes
- 10,103
- 1
- 59
- 71