This article brings you a detailed introduction to the Java class loading process. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The process of Java files from encoding to final execution:
The JVM virtual machine loads the class information in the .class file into the memory and parses it to generate the corresponding class object. The JVM does not load all classes into memory from the beginning, but only loads them when it encounters a class that needs to be run for the first time, and only once.
Load class bytecode files from various sources into memory through the class loader
JVM Three things to accomplish
Class loader
The process of merging the binary code of the java class into the running state of the JVM
Ensure that the loaded byte stream complies with the virtual machine specifications and will not cause security errors
Verification classification
Allocate memory for class variables (note, not instance variables) and assign initial values (the default initial values of the Java virtual machine according to different variable types)
Default initial value
The process of replacing symbol references in the constant pool with direct references
Symbol reference: a string, but this string gives some relevant information that can uniquely identify a method, a variable, or a class
Direct reference: can be understood as a memory address, or an offset Quantity
For example, now call the method hello(), the address of this method is 1234567, then hello is a symbolic reference, 1234567 is a direct reference
In the parsing phase, the virtual machine will The symbolic references of class names, method names, and field names are replaced with specific memory addresses or offsets, that is, direct references
to class variables (variables or statements modified by static ) Initialization is the process of executing the class constructor
Initialization process
The above is the detailed content of Detailed introduction to Java class loading process. For more information, please follow other related articles on the PHP Chinese website!