Java source code is compiled into bytecode for the JVM. But, how does JVM convert bytecode into machine code? Does it re-compile bytecode into machine code and then run it? Or does it simply just run the bytecode, directly?
JVM Bytecode Execution – Compilation vs Direct Running
compilationjavajvm
Best Answer
Byte code usually cannot be run directly on the processor, since the hardware doesn't have the opcodes
aload
,getfield
etc.The JVM either interprets the byte code, i.e. it looks up the things to do on the hardware for each opcode in some internal data structure, or it compiles the byte code to real machine code and simply calls the compiled code when a Java routine is called. Which to do when is an interesting question and the subject of much optimization research.