Java compilation and interpretation process

tags: java basics

1. Java compilation and interpretation process
(1) The java code is compiled and converted into a bytecode file (.class file) by the front end;
(2) The bytecode file is converted into machine language by the JVM's built-in compiler and run. This part uses different methods in unused JVMs. The following are two more frequently used methods:
1) Just-in-time complier (JIT: ​​just-in-time complier) is a dynamic compilation method that compiles and stores the hot spots in bytecode files, such as the C1 and C2 compilers of the HotSpot virtual machine;
2) Ahead-of-time complier is a static compilation method that compiles bytecode files and related libraries into machine language in advance.

2. The process of front-end compilation
(1) Analyze and fill the symbol table;
The process includes lexical analysis, syntax analysis and symbol table filling;
(2) The annotation processing of the plug-in annotation processor;
(3) Semantic analysis and bytecode generation;

3. The role of Java compilation execution and interpretation execution
(1) HotSpot VM is the virtual machine in Sun JDK and OpenJDK, and it is also the most widely used Java virtual machine.
But today's HotSpot VM not only has a built-in interpreter, but also a built-in advanced JIT (Just In Time Compiler) compiler. When the Java virtual machine is running, the interpreter and the just-in-time compiler can cooperate with each other to complement each other. One thing to note is that whether it is interpreted and executed by an interpreter or compiled and executed by a just-in-time compiler, the final bytecode needs to be converted into the native machine instructions of the corresponding platform.

(2) Since the JIT compiler is built into the HotSpot VM, why do we need to use an interpreter to "drag" the execution performance of the program?
For server-side applications, startup time is not the focus of attention, but for those application scenarios that value startup time, it may be necessary to adopt an architecture where an interpreter and a just-in-time compiler coexist in exchange for a balance.

(3) Since the just-in-time compiler postponed the compilation of local machine instructions to run time, the running performance of Java programs has reached a point where it can compete with C/C++ programs. This is mainly because the JIT compiler can deeply optimize the "hot code" that is frequently called, while the code optimization of the static compiler cannot fully infer runtime hotspots. Therefore, the local machine instructions compiled by the JIT compiler are more It is only natural that directly generated local machine instructions have higher execution efficiency.

4. Optimization of JIT compilation
   Java programs are initially interpreted and executed by an interpreter. When the virtual machine finds that a method or code block is running very frequently, it will regard these codes as "hot codes." In order to improve the execution efficiency of the hot code, at runtime, the virtual machine will compile these codes into machine code related to the local platform, and optimize the compiler to complete this task is called the even compiler.
Two ways to identify hot codes:
(1) Hot spot detection based on sampling
This method is to periodically probe the top of the thread stack. If a certain method is found to appear frequently, it is considered as a hot code;
(2) Hot spot detection based on counter
The virtual machine using this method establishes a counter for each method (even code block) to count the number of executions of the method. If the number of executions exceeds a certain threshold, it is considered a "hot method".

Intelligent Recommendation

C++ and java compilation process

Few people compare C++ and Java compilation together. Indeed, the difference between the two is too great, and there is almost nothing in common. But I still want to compare. 1. C++ compilation proces...

java-cef compilation process

1 Compilation process 1.1 Development tools      Git-2.13.2-64-bit        cmake-3.9.0-rc5-win64-x64        python-2.7.13.amd64     &nbs...

Java compilation process

Preface In the process of learning Java, I used to run the code directly with the IDE. Today, I used the command line window to run the code. As a result, the error I encountered before appeared again...

Java compilation execution process

Articles directory Java compilation execution process Interpreter and timely compiler -Xmixed -Xint -Xcomp Test code Test -xmixed hybrid mode Test -Xint only explanation mode Test -xcomp only compile ...

Java code compilation process

This article is reproduced in the public account: Three Prince Ao Bing Foreword After writing the code for so many years, do you have a clear context for the full process of Java code? Will everyone b...

More Recommendation

Compilation and interpretation, IDEA development, Java annotation

Program compilation and interpretation type language difference Click I understand Developed using IDEA Workers must be good, must first take care of them! Quick: Enter main, get Enter sout to get Not...

Interpretation and compilation

Article catalog 1. Explain the basic concepts and compilation 2. Explain the characteristics and compilation 3. Static language, scripting language 4.`c / c ++ `compiled and running process 4.1 Compil...

JAVA-JAVA compilation and running process

  Java compilation principle *.java→*.class→machine code java compiler (compilation) → virtual machine (interpretation execution) → interpreter (translation) → machine co...

Java language overview and compilation process

Copyright©Stonee Recently studying Java, the teacher is an engineer with extensive engineering experience. I want to write down the thoughts that I can think of through this note.Of course, as th...

Java program compilation and running process

1, write a java source program HelloWorld.java The keyword public indicates an access specifier indicating that the class is a public class that controls access to class members by other objects. The ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top