Search code examples
javajvmjitjrockit

Why do JIT Compiler need to translate bytecode to another intermediate representation before generating machine code


I am studying about JVM using the excellent book Oracle JRockit: The Definite Guide. One thing I doesn't really get is the need of JIT compiler to translate bytecode to another intermediate representation (IR), optimize them then translate to native code.

According to Wikipedia, bytecode is already a type of IR. Why JIT compiler in JRockit doesn't optimize the bytecode directly? My guess is it is harder to perform optimization on bytecode than on another IR (for example: C) but I am not sure at all.


Solution

  • Some optimizations depend on target architecture (instruction set, etc.) and therefore aren't possible on bytecode, which is architecture-independent.