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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the memory structure of JVM? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The memory structure of JVM is roughly as follows:
Heap: thread sharing. All object instances and arrays are allocated on the heap. The objects that the recycler mainly manages.
Heap memory is the largest piece of JVM made up of the young and the old, while the younger generation is divided into three parts, Eden space, From Survivor space and To Survivor space. By default, the younger generation is allocated according to the 8:1:1 ratio.
Method Method Area: thread sharing. Stores class information, constants, static variables, and code compiled by the immediate compiler.
Method JVM Stack: thread private. Store local variables, operation stacks, dynamic links, method exits, object pointers.
Local method stack (Native Method Stack): thread private. Serves the Native method used by the virtual machine. For example, when Java uses interface services written by c or C++, the code runs in this area.
Program counter (Program Counter Register): thread private. Some articles are also translated into PC registers (PC Register), the same thing. It can be seen as a line number indicator of the bytecode executed by the current thread. Point to the next instruction to be executed.
First look at a picture, which can clearly explain the layout of JVM memory structure and the corresponding control parameters:
(the picture comes from the Internet)
Control parameters
-Xms sets the minimum space size of the heap.
-Xmx sets the maximum space size of the heap.
-XX:NewSize sets the minimum space size of the new generation.
-XX:MaxNewSize sets the maximum space size of the new generation.
-XX:PermSize sets the minimum space size of the permanent generation.
-XX:MaxPermSize sets the maximum space size of the permanent generation.
-Xss sets the stack size for each thread.
(1) Program counter: thread is private. A program counter is a small piece of memory space that can be seen as a line number indicator of the bytecode executed by the current thread. The bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to be executed. Branch, loop, jump, exception handling, thread recovery registry functions all rely on the value of this counter. In order to restore to the correct execution position after thread switching, each thread needs an independent program counter, and the counters between each thread do not affect each other and are stored independently. This type of memory area is called "thread private" memory. Program counters are the only areas where no Out Of Memory Error is specified in the java virtual machine specification.
(2) Java virtual machine stack: it is also private to threads and has the same life cycle as threads. Virtual machine stack describes the memory model of Java method execution: when each method executes, it creates a stack frame to store local variable table, Operand stack, dynamic link, method exit and other information. Usually we divide java into heap memory and stack memory, in which the "stack" is now referred to as the virtual machine stack, or the local variable table part of the virtual machine stack. The memory space required by the local variable table is allocated during compilation. When entering a method, how much local variable space needs to be allocated in the stack frame is completely determined, and the size of the local variable table will not be changed during the operation of the method.
There are two possible exceptions in the Java virtual stack:
StackOverflowError: the stack depth of the thread request is greater than the depth allowed by the virtual machine
OutOfMemoryError: unable to apply for enough memory when the virtual machine stack is expanded
(3) Local method stack: thread is private. The functions of the local method stack and the virtual machine stack are very similar, the main difference between them is that the virtual machine stack performs Java methods (that is, bytecode) for the virtual machine, while the local method stack serves the Native methods used by the virtual machine. Like the virtual machine stack, the local method stack throws StackOverflowError and OutOfMemoryError exceptions.
(4) Java heap: shared by all threads. The Java heap is created when the virtual machine starts and is the largest block of memory managed by the Java virtual machine. The sole purpose of the Java heap is to hold object instances and arrays.
1. The Java heap is the main area managed by the garbage collector, so it is also called the "GC heap". From the perspective of memory recovery, as most of the current collectors use generation-by-generation collection algorithms, the Java heap can be subdivided into new generation and old age, and then subdivided into Eden space, From Survivor space, To Survivor space and so on. From the perspective of memory allocation, the Java heap shared by threads can be divided into allocation buffers private to multiple threads. But no matter how you divide it, the object instances are stored in any area.
2. The implementation of Java heap can be either fixed or extended. Current virtual machines are implemented as extensible, controlling heap size through-Xmx and-Xms.
3. Java heap does not need continuous memory physically, as long as it is logically continuous. If there is no memory in the heap to complete instance allocation and can no longer be extended, an OutOfMemoryError exception will be thrown.
(5) method area: shared by all threads. Used to store data such as class information, constants, static variables, code compiled by just-in-time compiler, which have been loaded by the virtual machine. The method zone also has an alias called Non-Heap (not heap), which is used to distinguish it from the Java heap. For HotSpot virtual machines, the method zone is also used to be called "permanent generation" (Permancent Generation), but this is only for HotSpot virtual machines, other virtual machine implementations do not have this concept. Relatively speaking, garbage collection behavior is relatively rare in this area, but it is not impossible to collect. The goal of memory collection in this area is mainly for constant pool collection and type unloading.
Also note that memory model and memory structure are two completely different concepts! In the next chapter, after talking about JVM's GC, let's take a look at the memory model. We all know that java runs across platforms through a java virtual machine. But how does it come true? are there any rules?
Answer: different computer operating systems have different operations on the memory model, so it is necessary to have a unified specification to complete the operation. So we have to use the JAVA memory model (Java Memory Model,JMM)
After reading the above, have you mastered the method of JVM memory structure? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.