Read the directory

  • An overview,
  • Second, javac compilation process

An overview,

We all know that *.java files must be compiled into *.class files to be recognized by the JVM. This part of the work is mainly done by Javac.

But the *.class file is not a machine language, so how do you get it to recognize it? The JVM is required to compile *.class files into machine code, which is done by the JIT compiler.

In addition to these two compilers, there is another kind of compiler that directly compiles *. Java files to native machine code. We call it AOT compiler.

Second, javac compilation process

First, let’s get a copy of the source code for Javac (based on OpenJDk8).Hg.openjdk.java.net/jdk8/jdk8/l…And then JDK_SRC_HOME langtools/SRC/share/classes/com/sun all the source files in the directory is copied to the project source directory, the generateddirectoryAs follows:

We execute the Main method of com.sun.tools.javac.Main just as we used the javac command in the command window:

From the Sun Javac code, the compilation process can be roughly divided into three steps:

  • The process of parsing and populating symbol tables
  • Annotation processing by the plug-in annotation processor
  • Analysis and bytecode generation processes

What these three steps do is roughly as follows:

The relationship and order of interaction between these three steps is shown below, and you can see that if the annotation processor makes changes to the syntax tree during annotation processing, the compiler will go back to parsing and filling the symbol table for reprocessing until the annotation processor has made no further changes to the syntax tree.

Javac compiler entry is com. Sun. View Javac. Main. JavaCompiler class, the above three steps of code were focused on the class of the compile () and compile2 () :

Write articles carefully and share with your heart. This article is over here, like friends can help forward and pay attention to it, thank you for your support!