Java source code compilation process

Source: Internet
Author: User

Source code (. java file) ---> analysis (lexical and syntax analysis) and filling symbol table ---> annotation processing ---> Semantic Analysis and bytecode generation (. class file) lexical analysis: converts the source code into a Token set, marking is the smallest element in the compilation process. For example, int a = B + 2; ---> int, a, =, B, +, and 2 syntax analysis: the abstract syntax tree is generated by the Token Sequence Based on the syntax. (Abstract syntax tree: Describes the tree expression of the syntax structure of the program code) Fill symbol table: A symbolic table is a table consisting of a set of symbolic addresses and symbolic information (similar to the form of K-V value pairs in a hash table). The information registered by the symbolic table is used at different stages of compilation. For example, in semantic analysis, the symbol table is used for semantic check (for example, to check whether a name is used consistent with the original description) and generates intermediate code. In the generation phase of the target code, when the symbol name and address are allocated, the symbol table is the basis. (Supplement: If your code does not provide any constructor, a default constructor with no parameter access consistent with the current class will be added in this phase.) annotation processing: processing user-defined annotation, additional code can be generated to save the compilation of Common Code Semantic Analysis: 1. annotation check: includes whether the variables are declared before use, and whether the data types between variables and values match, constant folding (int a = 1 + 2; ---> int a = 3;), etc. 2. Data and control flow analysis: including whether there is a returned value exception in each path of the method, and whether to handle the exception. 3. Syntactic sugar refers to adding a syntax to the language without affecting the language function, but it is convenient for programmers to use, the most common syntax sugar in Java is generic, which is not supported by Java virtual machines during runtime. Therefore, you need to restore the original syntax bytecode generation: In addition to bytecode generation, the instance constructor <init> () method and the class constructor <clinit> () method are added to the syntax tree, and the string addition operation is replaced with the append () of StringBuffer or StringBuilder () operation

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.