Java class load basic process detailed introduction _java

Source: Internet
Author: User
Tags class definition constant constructor

Java class load basic process detailed introduction

Basic process:

    • Loads the binary byte stream of the definition class, based on the fully qualified name of the class.
    • Converts the static storage structure represented by a byte stream into the RUN-TIME data structure of the method area
    • Generates a Java.lang.Class object representing this class in memory as a method of accessing various data access portals of this class

The array class itself is not created by the class loader, created directly by the Java Virtual machine, and the element type of the array class is loaded by the ClassLoader.
The element type of an array class: The array removes the type after all dimensions,

File Format verification:

    1. 0xCAFEBABY magic number beginning;
    2. The primary and secondary version number of the current virtual machine can be processed;
    3. Constant type;
    4. Index execution type;
    5. UTF8 encoded data type,

Meta-data validation: Byte code description information Semantic Analysis:

    1. Whether there is a parent class;
    2. Whether the parent class inherits the final modified class;
    3. Whether the non-pumping class implements the method that needs to be implemented in the parent class or interface;
    4. The fields in the class, the method coverage, the overload contradiction;

BYTE code verification: through semantic flow and control flow analysis to determine the legality of the program, correctness, method body analysis and verification.

    1. Symbolic reference verification: the virtual machine converts symbolic references into direct references, parsing phase, and verifying the matching of information outside the class itself.
    2. Whether the fully qualified name described by character can find the corresponding class in the symbolic reference;
    3. Specifies whether the class has a descriptor that conforms to the Method field, and the method and field described by the simple name;
    4. The accessibility of a class, field, method in a symbolic reference.

Preparation: Allocates memory for the class variable in the method area and sets the class variable initial value.

    1. The initial value is usually the 0 value of the data type, and the final decorated value is directly initialized to the corresponding value.
    2. Class variables are static-decorated variables that are distinguished from instance variables.

Parsing: Virtual machines replace symbolic references in a constant pool with direct reference procedures

Constant_class_info,constant_fieldref_info,constant_methodref_info..

    1. Symbolic reference: A set of symbols to describe the referenced target, any form of literal, as long as the use can be ambiguous positioning to the target, with the virtual machine memory implementation independent, unrelated reference to the target is loaded.
    2. Direct reference: A pointer to a target directly, an offset, or a handle to the target, which is related to the memory implemented by the virtual machine, must already be loaded for the related target object directly.
    3. 。。。

Initialization: Starts executing Java program code in class definition. Executes the Class Builder <cinit> () method,

<cinit> ():

    1. The compiler creates a combination of the assignment action of the class variable in the class file, and the static statement block, which is automatically collected by the order in which the class is defined, and the static statement block can access only the variables previously defined.
    2. Different from the constructor method of the class, you do not need to display a call to the parent class constructor, the virtual machine guarantees the child class's <cinit> () before the execution of the parent class <cinit> () has been completed.
    3. The static statement block in the parent class executes before.
    4. <cinit> () is not required for a class or interface and is not generated if there are no variable assignment operations or static statement blocks.
    5. The interface's <cinit> () does not need to perform the <cinit> () of the parent interface first, nor is the implementation class <cinit> () of the same interface.
    6. Thread Safety: Virtual machines Ensure that <cinit> () is properly locked, synchronized, and only one thread at a time accesses the <cinit> () of the initialization class in a multithreaded environment

Thank you for reading, I hope to help you, thank you for your support for this site!

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.