Transferred from: http://blog.csdn.net/cutesource/article/details/5904542
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java code compilation is done by the Java source compiler, and the flowchart is as follows:
The execution of Java bytecode is done by the JVM execution engine, and the flowchart is as follows:
The entire process of compiling and executing Java code consists of the following three important mechanisms:
- Java source Code compilation mechanism
- Class loading mechanism
- Class execution mechanism
Java source Code compilation mechanism
Java source code compilation consists of the following three processes:
- Parse and input to symbol table
- Annotation processing
- Semantic analysis and generation of class files
The flowchart is as follows:
The resulting class file is made up of the following sections:
- Structure information. Includes the class file format version number and the number and size of each part of the information
- Meta data. The information that corresponds to the declarations and constants in the Java source code. Contains class/inherited superclass/implemented interface declaration information, domain and method declaration information, and constant pool
- Method information. Corresponds to the information in the Java source code for statements and expressions. Includes byte code, exception Processor table, evaluation stack and local variable size, type record of evaluation stack, debug symbol information
Class loading mechanism
The class loading of the JVM is done through ClassLoader and its subclasses, and the hierarchy and loading order of the classes can be described as follows:
1) Bootstrap ClassLoader
Responsible for loading all classes in Jre/lib/rt.jar in $java_home, implemented by C + +, not classloader subclasses
2) Extension ClassLoader
Some jar packages that are responsible for loading the extensions in the JAVA platform, including the jar packages in $java_home Jre/lib/*.jar or-djava.ext.dirs specified directories
3) App ClassLoader
Responsible for documenting the jar packages specified in the Classpath and the class in the directory
4) Custom ClassLoader
The ClassLoader that the application customizes according to its own needs, such as Tomcat and JBoss, will be implemented according to the Java EE specification itself ClassLoader
The load process checks to see if the class is loaded, the check order is bottom-up, and the custom ClassLoader to bootstrap ClassLoader-by-layer check, as long as a certain classloader is loaded as if the class has been loaded. Ensure that only all classloader of this class are loaded once. The order of loading is top-down, that is, the upper layer tries to load the class one at a level.
Class execution mechanism
The JVM is a stack-based architecture that executes class bytecode. After the thread is created, the program counter (PC) and stack (stack) are generated, and the program counter holds the offset of the next instruction to be executed in the method, and the stack frames are stored in each stack frame, and each stack frame corresponds to each call of each method, and the stack frame is made up of the local variable area and the operand stack. Local variables are used to store local variables and parameters in the method, which are used to store the intermediate results produced during the execution of the method. The structure of the stack is as follows:
JVM Learning Notes (ii)------The entire process of compiling and executing Java code "go"