Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the process of loading the Java class

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people do not understand the knowledge points of this article "Java class loading process", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the process of Java class loading" article.

The Java virtual machine shields the information related to the specific operating system platform, which urges Java programs to run on various platforms without modification as long as the relevant code is run on the Java virtual machine.

Load

In the loading phase, the class class file is read into memory and a java.lang.class object is created for it. In this process, the virtual machine does three main things:

1. Gets the binary byte stream that defines this class through the fully qualified name of a class.

two。 Converts the static storage structure represented by this byte stream into the run-time data structure of the method area.

3. Generate a java.lang.Class object representing this class in the Java heap as access to the method area data

Validate

The verification phase is the first step of the link, and the function is to ensure that the byte stream of the Class file contains information that conforms to the JVM specification and will not cause harm to JVM. If validation fails, a java.lang.VerifyError exception or its subclass exception is thrown. The verification process is divided into four stages.

1. File format verification: verify that the byte stream file conforms to the specification of the Class file format and can be processed correctly by the current virtual machine.

two。 Metadata verification: semantic analysis of the information described by bytecode to ensure that the information described by bytecode conforms to the specification of Java language.

3. Bytecode verification: the main purpose is to analyze the data flow and control flow to ensure that the method of the checked class will not harm the virtual machine at runtime.

4. Symbol reference verification: symbol reference verification occurs when the virtual machine converts a symbol reference to a direct reference, which occurs during the parsing phase.

Prepare for

The preparation phase allocates memory for variables and sets the initialization of class variables. Only the variables of the class (static-decorated variables) are assigned at this stage, not the instance variables of the class. For variables that are no longer final, JVM sets them to zero instead of the value of their assignment statement:

Pirvate static int size = 12

So at this stage, the value of size is 0, not 12. Final-decorated class variables will be assigned to real values.

Parsing

The parsing process is to replace symbolic references in the constant pool with direct references. Mainly includes the resolution of four types of references. Class or interface parsing, field parsing, method parsing, interface method parsing.

Initialization

In the preparation phase, the class variables have been initialized once, and at this stage, the variables and other resources of the class are initialized according to the programmer's program plan. These resources include static {} blocks, constructors, initialization of parent classes, and so on.

As for the use and uninstall phase, I will not explain too much here, the usage process is executed according to the behavior defined by the program, and the uninstall is done by GC.

Use

New thread-program counter-jvm stack execution (object reference)-heap memory (direct reference)-method area.

Uninstall

GC garbage collection.

The mechanism, significance and method of parental appointment.

Mechanism

Boot (Bootstrap) classloader-> standard extension (Extension) classloader-> system (System) classloader-> context (Custom) classloader loads from left to right: first delegate the loading task to the parent class loader, recursively, if the parent class loader can complete the class loading task, it returns successfully Load it yourself only if the parent class loader cannot complete this load task.

Meaning.

Prevent multiple copies of the same bytecode in memory

Using the delegate mechanism, the parent class will be found recursively. If class A refers to the class BMagol Java virtual machine, the class B will be loaded using the class loader that loads class A, and if the class A loader has already loaded class A, then B will not load the bytecode of class A when it uses the class loader of A to load.

Method

Launch (Bootstrap) class loader

Standard extension (Extension) class loader

Application class loader (Application)

Context (Custom) class loader

The above is the content of this article on "what is the process of Java class loading". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report