The following compilation mechansims are knows:
Most vendor implementations of Java do just-in-time compilation to machine code. It's also possible to compile the ".class" files before run time (ask Oracle).
Unfortunately, compiling from bytecode -> machine-code is hardly as efficient (with respect to the generated code) as compilation from the Abstract Syntax Tree (AST) -> machine code. Lots of information is already lost in the process from going from AST to bytecode.
I suspect this is not such an issue in Java because of the close match between language and JVM. Last I checked it looked like decompilers were rebuilding perfect ASTs for the bytecodes they were working with. -- LukeGorrie
Check out how OberonLanguage realises "Write Once, Run Anyway". They ship around the tree representation such as generated by the compiler front-end, then use the local (native) compiler back-end to generate machine code. This is much more efficient.
"Microsoft's Java VM contains an innovative Just-in-Time (JIT) compiler that uses this compile-on-the-fly strategy. Instead of interpreting bytecodes one at a time, the JIT compiler translates bytecodes into native machine instructions and executes them on the host processor."
http://www.microsoft.com/Mind/0596/jakarta/jakarta.htm[many others have JITs to]
And in a recent presentation I saw on Oracle's implementation of Java in their servers, they said that they compile the ".class" files in advance (when packages are installed in the server?), and that this is very fast.
SGI were doing something like this in around 1996. Their IRIX VM would JIT classes as they were loaded, and then embed the mips code in the class files for next time. -- LukeGorrie
See also: HotSpot