In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of the loading process of Java class, which is very detailed and has certain reference value. Friends who are interested must finish it!
Java: class loading proc
1. Load-3 things
1. Get the binary byte stream that defines this class through the full class name (eg: obtained from jar, war)
two。 Convert the static storage structure represented by the byte stream into the run-time data structure of the method area
3. A Class object representing the class is generated in memory as the access entry for the data in the method area.
two。 Connect
Some of the contents of the load phase and the connection phase are crossed, and the connection phase may start running before the load is finished.
2.1. Verification
2.2. Prepare for
Preparation phase: the stage in which memory is formally allocated to class variables and the initial values of class variables are set, which are allocated in the method area. Note:
1. At this time, memory allocation includes only class variables (static), but not instance variables, which are allocated in the Java heap along with the objects when the objects are instantiated.
two。 With the exception of variables that contain final modifications, all assign values such as 0 _ null _ false.
In the following example, the value of value is copied to 111 instead of 0. 0.
Public static final int value=1112.3. Analysis
The parsing phase is the process by which the virtual machine replaces symbolic references in the constant pool with direct references.
That is to get the pointer or offset of a class or field or method in memory.
What is a symbolic reference?
* for example, the org.simple.People class references the org.simple.Language class
* the People class does not know the actual memory address of the Language class at compile time, so it can only use the symbol org.simple.Language
3. Initialization
Initialization is the last step of class loading and the actual execution of the Java program code (bytecode) defined in the class. The initialization phase is the execution of the class constructor.
< clinit >The process of () method.
For
< clinit >() method, the virtual machine itself ensures its security in a multithreaded environment. Because
< clinit >() the method is thread-safe with locks, so class initialization in a multithreaded environment can cause deadlocks that are difficult to find.
For the initialization phase, the class must be initialized when the virtual machine strictly specifies that there are and only 5 cases:
When you encounter four direct code instructions of new, getstatic, putstatic, or invokestatic, such as new a class, read a static field (not decorated by final), or call a class's static method.
When a reflection call is made to a class using the method of the java.lang.reflect package, if the class is not initialized, it needs to be initialized.
Initialize a class and trigger the initialization of the parent class first if its parent class has not been initialized.
When the virtual machine starts, the user needs to define a main class to execute (the class that contains the main method), and the virtual machine initializes this class first.
When using JDK1.7 's dynamic dynamic language, if the final parsing structure of a MethodHandle instance is a method handle of REF_getStatic, REF_putStatic, REF_invokeStatic, and the handle is not initialized, it needs to be initialized by a trigger.
The above is all the content of the article "sample Analysis of the Java Class loading process". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow 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.