In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "sample analysis of the JVM runtime data area in JAVA", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of the JVM runtime data area in JAVA".
I. Preface
The entire JVM runtime datazone and GC garbage collection will be introduced in detail
Second, the overall architecture of the runtime data area
The following is a summary of my own sentence:
It is divided into two categories: thread private and thread sharing, in which program counter, virtual machine stack and local method stack belong to thread private, heap memory and method area memory are shared by thread. Program counter is mainly to record bytecode instructions, CPU context switch thread, switch from one thread to another thread, need to know which step the thread executes, so it is necessary to record this instruction, the program counter does not have OOM and GC. There are stack frames in the virtual machine stack, each stack frame corresponds to each method, and the stack frame is composed of local variable table, Operand stack, method return value address and dynamic link. Virtual machine stack may have stack overflow exception, that is, starkoverflow local method stack stores things related to local methods; heap is a large space, the whole is divided into two blocks, the new generation and the old era, the new generation is divided into Eden area, S0 area, S1 area, garbage collection mainly occurs in the new generation, each area corresponds to a different garbage collection algorithm The method area stores some constants, basic information of classes, and so on. The corresponding implementation of the method area is permanent in JDK7 and metaspace in JDK8.
Program counter
The address used to store the next instruction is private to the thread, and the life cycle is consistent with the life cycle of the thread.
IV. Virtual machine stack
The virtual machine stack is thread-private, and each stack frame corresponds to a call to the Java method, and the life cycle is consistent with the life cycle of the thread. Let's first take a look at the characteristics of the stack.
1. The characteristics of the stack
The stack is the unit of runtime, while the heap is the unit of storage. The characteristics of the stack are first in, first out, last in, first out.
You can set the stack space size with the parameter-Xss
2. The internal structure of the stack frame
3. Local variable scale
Is a numeric array, mainly used to store method parameters and local variables defined in the method, these data types include various basic data types, object references, etc., the required capacity is determined at compilation time, and the size of the local variable table will not be changed during the method run.
Understanding of Slot:
The difference between static variables and local variables:
Summary:
In the stack frame, the local variable table is most closely related to the performance. When the method is executed, the virtual machine uses the local variable table to complete the transmission of the method, and the data in the local variable table is also the GC Root in the accessibility analysis. If an object is still referenced in the local variable table, then the root absolute reachability analysis algorithm, this variable does not belong to garbage objects and will not be recycled by GC.
4. Operand stack
Operand stack is the stack in the stack, also known as expression stack, in the process of method execution, according to bytecode instructions, write data to the stack or extract data, that is, into the stack and out of the stack. It is mainly used to save the intermediate results of the calculation process. Operand stack, which can be regarded as a temporary register, the temporary storage of variables in the process of calculation.
5. Dynamic link
The essence of method rewriting
6. Method return address
Stores the value of the PC register that calls the method
5. Local method stack
Managing local native local methods is thread-private, and the so-called local methods are actually some code written in a non-Java language, which can even deal with the operating system CPU.
VI. Heap
Heap is the core area of memory management, is shared by threads, and belongs to the JVM level, that is, an JVM instance will have a heap space. Note that although the heap is shared by threads as a whole, there is a small piece of internal space that is thread-private cache TLAB.
Almost all object instances are in the heap, which is the key area of GC garbage collection. The reactor as a whole can be divided into Cenozoic and old age, and the Cenozoic can be divided into Eden region and S0 and S1 region.
The ratio of the new generation to the old age is 1. The proportion of space occupied by the Zodiac 2, the Eden and the s0.
1. Set parameters for heap size
-Xms: used to represent the starting memory of the heap area, which by default accounts for 1 / 64 of the physical memory size.
-Xmx is used to represent the maximum memory of the heap area, which accounts for 1/4 of the physical memory by default.
Usually, the starting memory and maximum memory parameters are set to the same, so that after GC cleans up the heap memory, it does not need to re-separate the size of the calculation heap area, thus improving performance. View the set parameters: method 1: jps (View process) jstat-gc process id method 2:-xx:+printGCDetails2, object allocation process
Here, the person who is empty in S0 and S1 is to. The age counter threshold is 15. YGC will trigger when Eden area is full. When S0 and S1 are full, YGC,YGC will not GC s area and Eden Park together.
With regard to garbage collection, it is collected frequently in newborn areas, rarely in nursing areas, and hardly in permanent areas / metaspace.
Visualvm is a common tuning tool for JVM. You can open GC in the heap under the bin of JDK.
Trigger mechanism of young generation (Minor GC)
Trigger mechanism of GC (Major GC/Full GC) in the old era
Full GC trigger mechanism
4. Memory allocation strategy
5. What is TLAB
TLAB indicates that the heap is not necessarily shared.
6. Is heap the only option for allocating object storage?
If there is no escape method for an object after escape analysis, it is possible to optimize the allocation on the stack.
Means of escape analysis:
Note: after the JDK6U23 version, HotSpot has enabled escape analysis by default. So we have come to the conclusion that if local variables can be used in development, do not use definitions outside the method. String constant pools and static variables are stored in the heap after JDK7
7. Method area
The method area can be regarded as a memory space independent of the heap, which is shared by threads, mainly stores class information, runtime pool, etc., and becomes permanent before OOM,JDK8, and JDK8 becomes metaspace. (the biggest difference between metaspace and perpetuation is that metaspace no longer uses JVM memory, but uses local memory technology.)
1. Overview of the method area
2. Set the memory size of the method area
3. How to solve the OOM problem?
4. What is stored in the method area
5. Details of the evolution of the method area.
6. GC of the method area
The above is all the content of the article "sample Analysis of the JVM Runtime data Zone in JAVA". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.