Reading notes JVM Quest VI: The compiler's Stuff

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.