Execution Engine

=Execution Engine=

As we all know, the Bytecode is "kind of" human readable so it must be converted to the machine language so it can be executed by the machine in the JVM. The Execution Engine is the responsible of this task by transforming the Bytecode using an Interpreter or an Just In Time Compiler (JIT):
 * Interpreter: self explanatory; it reads, interprets and executes the instructions as they are loaded. It is not the most efficient way since:
 * it reads and interprets everytime instead of "compiling" it.
 * it's slow running the interpreted intruction.
 * JIT: In Oracle JVM it's called Hotspot compiler. It runs as an interpreter and the compiler compiles all the bytecode into machine code which will be stored in a cache for the first time. This way it won't be necessary to interpret the instruction again. Taking that into account, the JIT compiler is continously checking how many times a method is called so it compiles it only when the frequency is appropiated.

That's one of the reasons why the first time we run a web application after a deploy (for example) it is slower than the second time. So it's obvious that it's faster to use a JVM that use an interpreter if our code is going to be executed just once.

We can dissasemble the code generated by JIT. First, you need to the apropiated dissasembler and copy it to your $JAVA_HOME\jre\bin:
 * hsdis-i386.dll for windows 32 bits JVM
 * hsdis-amd64.dll for windows 64 bits JVM
 * linux-libhsdis-i386.so for linux 32 bits JVM
 * linux-libhsdis-amd64.so for linux 64 JVM
 * solaris-libhsdis-i386.so for solaris 32 bits JVM
 * solaris-libhsdis-amd64.so for solaris 64 bits JVM

Use java with these parameters
 * -XX:+UnlockDiagnosticVMOptions
 * -XX:+PrintAssembly

More info at: https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly