[Java Study Notes] JVM class Processing

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

1. Loading of Classes
Load: search for and load binary data of the class. Put. the binary data of the class file is read into the memory, stored in the Method Area of the runtime data area, and a Java is created in the heap area. lang. class Object (this is the final product of class loading), used to encapsulate the data structure of the class in the Method Area, andProgramProvides interfaces for the data structure of the category class in the method area.

2. Verify the class:
Verification: ensure the correctness of the loaded class. The checked content includes the structure check of the class file, semantic check, bytecode verification, and binary compatibility verification.

3. Prepare the class:
Allocate memory for the static variables of the class and initialize it as the default value) and parse the binary data of the class (convert the symbols in the class to direct reference ).

4. Class parsing:
Replace the reference in the class with a pointer.

5. class initialization:
Initialization: Assign the correct initial value to the static variables of the class. JVM initializes the class only when the program actively uses a class or interface for the first time, call static methods of a class, call reflection methods, and initialize subclasses of A Class ). If the class is not loaded or connected, load and connect the class first. If the class has a direct parent class, initialize the parent class first, and then execute the initialization statement, the class initialization is complete.
There are several passive usage cases that will not cause class initialization:

A. for static final variables, if the value of the variable can be calculated during compilation, the class initialization will not be caused, but the value will be saved directly in the byte stream, therefore, when accessing, it is actually the access value. For example:
Public static final int A = 2*3; then public static final int B = (INT) (math. Random () * 5) will lead to class initialization.

B. When initializing a class, it is required that all its parent classes have been initialized, but this rule does not apply to interfaces. However, when initializing a class, it does not initialize the interface it implements first. When initializing an interface, it does not initialize its parent interface first.

C. Calling the loadclass () method of the classloader class to load a class is not an active use of the class and will not lead to class initialization.

 

Class lifecycle:

After the sample class is loaded, connected, and initialized, its lifecycle begins. When the class object representing the sample class is no longer referenced, that is, it cannot be touched in a timely manner, the class object will end its lifecycle, and the data of the sample class in the method area will also be uninstalled, end the lifecycle of the sample class.

Classes loaded by the JVM class loaders are never uninstalled during the JVM life cycle. The classes loaded by the custom class loader can be detached.

 

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.