Pre-compilation
Java source Code-->JVM byte code (class file)
The approximate compilation process:
Parsing and filling symbols table--Annotation processing--analysis and bytecode generation
In particular, lexical analysis, grammar analysis, the construction of syntax tree, and so on, this stage is almost no optimization of the code, to die is to do some redundancy, such as int a = 3 + 1; change to int a = 4;
It is worth talking about the process of solving the grammatical sugar, Java has a large number of syntactic sugar, generics, auto-loading/unpacking, variable-length parameters, Foreach loop and so on.
Having grammatical sugars does not necessarily represent a performance boost, most of the time it may be for the convenience of developers, and it can or may not be the extreme. At the same time, beware of grammatical sugar traps, such as automatic boxing (don't expect to be packaged into classes at any time).
Post-compilation
BYTE-to-machine code (for the platform)
You can compare this phase of the compiler to the C + + compiler because it functions similarly.
The interpreter and the compiler, the former can run directly, explain a sentence to run a sentence, so inefficient; the latter compiles the running code into a machine code before it runs, it needs to wait for compilation time, but runs fast.
C + + compiler: Static, the source code all compiled into machine code to run, compile and run a very open point.
JIT (JVM built-in): The instant compiler, the use of what is compiled, compile and run is a cross. There is usually an interpreter and a compiler that performs the work together.
Java code optimization is mostly concentrated in the JIT, the optimization of the algorithm is dazzling, loop expansion, method within the chain, constant overlap and so on.
PS: A small point of concern, local variables do not have access to the flag, although you can write:
finalint0;
But this final is meaningless or meaningless, meaning that there is no representation in the class file, and final meaning is only guaranteed in the pre-compilation. If reflection can modify the method body, then this is interesting (in fact, reflection cannot modify the method body =.) =
Reading notes JVM Quest VI: The compiler's Stuff