In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to in-depth understanding of JVM memory structure, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Whether you are familiar with the JVM memory structure, here is a description, mainly including class loading subsystem, method area, PC register, heap and stack, etc., in which the method area is shared by all threads, and garbage collection will clean up useless type objects in the method area.
JVM memory structure
1) load subsystems such as JVM memory structure
Load connection initialization
(2) the method area of JVM memory structure.
Shared by all threads. Garbage collection also cleans up useless type objects in the method area.
a. Type information.
When the class loader loads the class, it is extracted from the class file.
The full valid name of the class
The full valid name of the parent class (except interfaceandjava.lang.Object, because there is no parent class)
Modifiers for types
Type Direct Interface list
b. Constant pool.
Stores symbolic references to all types, fields, and methods used by a type.
c. Domain information.
Jvm must keep information about all fields of the type and the order in which they are declared in the method area.
Information about the domain includes:
domain name
Domain Typ
Domain modifier (publicprivateprotectedstaticfinalvolatiletransient... )
d. Method information.
Method name
Method return type
Method parameters
Modifiers for methods
Bytecode of the method (except abstractandnative) (pointed to by the PC register)
The size of the local variable area of Operand stack and method stack frame
Abnormal table
e. Static variable of the class (all objects share a copy)
f. Class is declared as a final class variable (all objects share a copy)
g. A reference to the class loader that loads a class
References to the h.Class class
i. Method table.
j. An example:
ClassLava {privateintspeed=5; voidflow ();} ClassVolcano {publicstaticvoidmain (String [] args) {Lavalava=newLava (); lava.flow ();}}
Let's describe how the bytecode of the * * instruction of the main () method is executed. This is just one of the many differences between different jvm implementations.
In order to run this program, you passed "Volcano" to jvm in some way. With this name, jvm finds the class file (Volcano.class) and reads it in. It extracts the type information from the class file and puts it in the method area. By parsing the bytecode in the existing method area, jvm activates the main () method. When executed, jvm maintains a pointer to the constant pool of the current class (Volcano).
Notice that jvm starts execution before the Lava class is loaded. Like most jvm, execution does not wait until all classes have been loaded, it only loads when needed.
The * instruction of main () tells jvm to allocate enough memory for the class listed in the constant pool * item.
Jvm uses a pointer to the Volcano constant pool to find the * * entry, which it finds to be a symbolic reference to the Lava class, and then checks the method area to see if lava has been loaded.
This symbolic reference is simply the full valid name of the class lava, "lava". Here we see how important a good data structure is in order for jvm to find a class from a name as soon as possible. Here jvm implementers can use a variety of methods, such as hash tables, lookup trees, and so on. The same algorithm can be used for the implementation of forName () of the Class class.
When jvm discovers that a class called "Lava" has not been loaded, it starts to find and load the class file "Lava.class". It extracts type information from the class file and puts it in the method area.
Jvm then replaces the symbolic reference of the constant pool * * item with a pointer directly to the lava class in the method area. In the future, you can use this pointer to quickly find the lava class. This replacement process is called constant pool parsing (constantpoolresolution). What we replace here is a native pointer.
Jvm is finally starting to allocate space for the new lava object. This time, jvm still needs the information in the method area. It uses a pointer to lava data (the pointer to the volcano constant pool * * entry just now) to find out exactly how much space a lava object needs.
Once jvm knows the space required by a Lava object, it allocates the space on the heap and initializes the instance's variable speed to the default value of 0. If the parent of the lava also has an instance variable, it will also be initialized.
When the reference to the newly generated lava object is pushed onto the stack, the * instruction ends. The following instruction uses this reference to activate the java code to set the speed variable to the initial value, 5. Another instruction uses this reference to activate the flow () method of the Lava object.
(3) the heap of JVM memory structure.
Stores all objects and arrays at run time.
(4) the stack of JVM memory structure.
Each time a new thread is started, a stack is assigned.
(5) PC register of JVM memory structure (program counter)
Always points to the instruction that the thread will execute next. The position of the instruction is placed in the method bytecode in the method area. The content is the offset relative to the instruction.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.