Virtual machine class loading mechanism (class loading process)

Loading process

Next, we explain in detail the entire process of loading a class in the Add My Group, that is, the specific actions performed in the five stages of loading, verification, preparation for analysis, and initialization.

load

Loading is a stage of the class loading process, I hope the reader is not confused. These two seem to be nouns. The following three things need to be done in the stage of finding a virtual machine at home.
1. Obtain the binary byte stream that defines this class through the fully qualified name of a class.
2. Convert the static storage structure represented by this byte stream into the runtime data structure of the method area.
3. Generate a representative of this class in memory. The object is used as the access entry for various data of the method area
. These three requirements of the virtual machine specification are not specific, so the flexibility of virtual machine implementation and specific applications. All are quite large, for example by the fully qualified name of a class. Obtain the binary byte stream that defines this class. It does not specify the binary byte stream. It must be obtained from a class file. To be precise, it is not specified where or how to obtain it. The virtual machine design team is in the loading phase. A fairly open and broad stage has been built. In the course of the development of Java, fully creative developers have played various tricks on this stage. The most important Java technology is built on this foundation, for example,
1) Reading from the zip package is very common, and eventually the ear will be blown up in the future. The basis of war format
2) Obtain this kind of scene from the network, the most typical is applied
3) Run-time calculation to generate this kind of scene uses the most dynamic proxy technology. In java.lang.reflect.proxy, the generator proxy class of the Process generator shop is used. To generate a binary byte stream shown as the $proxy proxy class for a specific interface.
4) There are other documents produced. A typical application is a JSP application, which has the class corresponding to this file upload.
5) This scenario is relatively rare to read from the database, such as some middleware servers. You can choose to install the application into the database to complete the program code. Distribution between clusters.

It is equivalent to the other stages of the class loading process, the loading stage of a non-array class, to be precise, the binary of the class is obtained during the loading stage. The actions left by yourself are the most controllable for developers, because the loading phase can be done either by using the boot class loader provided by the system or by a user-defined class loader. Developers can control their own acquisition methods through a custom class loader. G overrides the load class method of a class loader.
For the array class, the situation is different. The array class itself is not created by the class loader. It is created directly by the Gava virtual machine. However, the array class is still closely related to the class loader, because the array class The element type. Refers to the array, remove all the dimensions of the type, and finally consider the loader to create it. The process of creating an array class must follow the following principles.
1) If the component type of the array is a reference type, then binding must be used recursively. The loading process defined in to load this component type. The array c will load the class loader of the component type. That name is identified in space
2) If the component type of the array is not a reference type, the kW virtual supervisor will mark the array c as associated with the boot class loader.
3) The visibility of the array type is consistent with the visibility of its component type. If the component type is not a reference type, it is out of the group. The visibility of the class is defaulted to public.

After the loading phase is completed, the binary byte stream outside the virtual machine is stored in the method area according to the format required by the virtual machine. The data storage format in the method sentence is self-defined by the virtual machine. The pectoral specification does not specify the specific data structure of this area, and then instantiate an object of java.lang.class in memory. It is not clearly specified that it is in the Java heap. For the hot stop virtual machine, the Class object is special. Although it is an object, it is stored in the method area. This object will serve as the external interface for the program to access these types of data in the method area. Part of the loading phase and the link phase are intersected. The loading phase has not been completed, and the linking phase may have started, but the actions performed during these loading and loading phases still belong to the content of the linking phase, and the start time of the two phases still maintains a fixed sequence.

Guess you like

Origin blog.csdn.net/weixin_39472101/article/details/110152048