Home >Java >JavaBase >What processes does javac compilation include?

What processes does javac compilation include?

hzc
hzcOriginal
2020-06-18 13:38:317421browse

What processes does javac compilation include?

What processes does javac compilation include?

The java compilation process is mainly divided into the following steps:

1. Lexical analysis : Convert the characters in the source code (various keywords, variables, etc.) into a set of tokens, the smallest unit of program writing for a single character, and token is the smallest unit of the compilation process.

2. Syntax analysis: Construct a collection of tokens into an abstract syntax tree. Each node of the syntax tree represents a syntax structure in the code (such as package, type, interface, modifier, etc.).

3. Fill the symbol table: The symbol table is a table composed of a set of symbol addresses and symbol information. The exit from the process of filling the symbol table is a pending list containing the top-level nodes of each abstract syntax tree (and package-info.java).

4. Plug-in annotation processor processes annotations: The annotation processor can add, delete, or modify any element of the abstract syntax tree. Therefore, whenever the annotation processor modifies the syntax tree, steps 1, 2, and 3 will be re-executed until the annotation processor no longer modifies the syntax tree. Each cycle process is called a Round.

5. Semantic analysis: Context-sensitive review of source programs that are correct in syntax tree structure.

  • Annotation check: including whether variables are declared, whether variables and assignment types match, etc., and constant folding.

  • Data and control flow analysis: further verification of program context logic. Including whether variables are assigned values ​​before use, whether methods have return values, whether exceptions are handled correctly, etc.

6. Decode syntax sugar: Convert advanced syntax (such as generics, variable parameters, unboxing, etc.) into basic syntax structures. These are not supported when the virtual machine is running. Advanced syntax.

7. Generate bytecode: Convert the information in the syntax tree and symbol table into bytecode and write it to the disk, while performing a small amount of code addition and conversion work.

Most of the above content is excerpted from: "In-depth Understanding of Java Virtual Machine" -- Zhou Zhiming

Recommended tutorial: "java tutorial"

The above is the detailed content of What processes does javac compilation include?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn