In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how the JVM class loading process is, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
class loading procedure
Class files need to be loaded into the virtual machine before they can be run and used, so how does the virtual machine load these Class files?
There are three main steps to load Class files: Load-> Connect-> Initialize. The connection process can be divided into three steps: validation-> preparation-> parsing.
parsing
The resolution phase is the process by which the virtual machine replaces symbolic references within the constant pool with direct references. Parsing actions are mainly performed for class or interface, field, class method, interface method, method type, method handle, and call qualifier 7 class symbol references.
A symbolic reference is a set of symbols describing a target, and can be any literal. A direct reference is either a pointer directly to the target, a relative offset, or a handle indirectly located to the target. Symbolic references are not enough when the program is actually running, for example: when the program executes a method, the system needs to know exactly where the method is located. The Java Virtual Machine has a method table for each class to store all the methods in the class. When you need to call a method of a class, you can call the method directly as long as you know the offset of the method in the square column. By parsing the reference to the operation symbol, it can be directly converted to the position of the target method in the method table of the class, so that the method can be invoked.
In summary, the parsing stage is the process in which the virtual machine replaces symbolic references in the constant pool with direct references, that is, to obtain pointers or offsets to classes, fields, and methods in memory.
initialization
Initialization is the final step in class loading and the actual execution of Java program code (bytecode) defined in the class, and the initialization phase is the process of executing the class constructor () method.
For calls to the () method, the virtual machine ensures its own security in a multithreaded environment. Because the () method is thread-safe with locks, class initialization in a multithreaded environment can cause deadlocks, which are difficult to detect.
For the initialization phase, the VM strictly specifies that there are and only five situations in which classes must be initialized:
When encountering new, getstatic, putstatic, or invokestatic, such as new a class, reading a static field (not modified by final), or calling a static method of a class.
When reflecting calls to a class using methods in the java.lang.reflect package, you need to trigger initialization if the class is not initialized.
Initialize a class, triggering initialization of its parent class if it is not already initialized.
When the virtual machine starts, the user needs to define a main class to execute (the class containing the main method), and the virtual machine initializes this class first.
When using JDK 1.7 dynamic language, if the last parsed structure of a MethodHandle instance is the method handle of REF_getStatic, REF_putStatic, REF_invokeStatic, and this handle is not initialized, trigger initialization is required.
The above is "JVM class loading process is how" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.