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 will explain in detail how to analyze the composition of JVM memory area, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
When a variable is defined in a method (code block), java allocates JVM memory space for the variable on the stack. When the scope of the variable is exceeded, java automatically frees the JVM memory space allocated for the variable; and the JVM memory allocated in the heap is managed by the automatic garbage collector of the java virtual machine.
JVM memory region composition
There are four types of JVM memory:
1. Stacksegment-the compiler automatically allocates and releases the parameter values of the function and the values of local variables. After the execution of the specific method, the system automatically releases JVM memory resources.
2. Heapsegment-generally allocated and released by programmers to store objects and arrays created by new. Jvm looks at this object from time to time and reclaims it if there is no reference to this object.
3. Static zone (datasegment)-stores global variables, static variables and string constants without releasing
4. Code area (codesegment)-holds the binary code of a method in a program, and multiple objects share a code space area
When a variable is defined in a method (code block), java allocates JVM memory space for the variable in the stack. When the scope of the variable is exceeded, java will automatically release the JVM memory space allocated for the variable. The JVM memory allocated in the heap is managed by the automatic garbage collector of the java virtual machine. The advantage of the heap is that it can dynamically allocate JVM memory, and the lifetime does not have to tell the compiler in advance, because it allocates JVM memory dynamically at run time. The disadvantage is that the JVM memory is allocated dynamically at run time, the access speed is slow; the advantage of the stack is that the access speed is faster than the heap, and the disadvantage is that the data size and lifetime in the stack must be fixed inflexibility.
◆ java heap consists of Perm area and Heap area, Heap area consists of Old area and New area, and New area is divided into Eden area, From area, To area, Heap= {Old+NEW= {Eden,From,To}}, as shown in figure 1.
Heap distinguishes two chunks, one is NEWGeneration, the other is OldGeneration. In NewGeneration, there is a space called Eden, which is mainly used to store newborn objects, and there are two SurvivorSpaces (from,to), which are used to store objects that survive each garbage collection. In OldGeneration, it mainly stores JVM memory objects with a long life cycle in the application, as well as a PermanentGeneration, which is mainly used to put JVM's own reflection objects, such as class objects and method objects.
In the NewGeneration block, garbage collection generally uses the Copying algorithm, which is fast. Each time GC, the surviving objects are first copied to a SurvivorSpace by Eden, and when the SurvivorSpace space is full, the remaining live objects are copied directly to the OldGeneration. Therefore, after each GC, the EdenJVM memory block is emptied. In OldGeneration blocks, garbage collection generally uses mark-compact 's algorithm, which is slower, but reduces JVM memory requirements.
Garbage collection is divided into multiple levels. Garbage collection at level 0 (Full) will collect garbage in OLD segment; level 1 or above is partial garbage collection and only garbage in NEW will be collected. JVM memory overflow usually occurs after garbage collection in OLD segment or Perm segment, and there is still no JVM memory space to accommodate new Java objects.
The frequency of JVM calling GC is still very high, and garbage collection is carried out in two main cases: when the application thread is idle, and when the JVM memory heap is insufficient, GC will be called constantly. If continuous collection cannot solve the problem of insufficient JVM memory heap, an outofmemory error will be reported. Because this exception depends on the operating environment of the system, it is impossible to predict when it will occur.
According to the mechanism of GC, the running of the program will cause the change of the running environment of the system and increase the trigger chance of GC. In order to avoid these problems, the design and writing of the program should avoid the JVM memory occupation of junk objects and the overhead of GC. The display call System.GC () can only suggest that JVM needs to collect garbage objects in JVM memory, but it does not have to be recycled immediately. One is that it does not solve the situation of empty JVM memory resources, and it will also increase the consumption of GC.
◆ when a URL is accessed, the JVM memory region request process is as follows:
A.JVM attempts to initialize a JVM memory region in Eden for related Java objects
b. When there is enough Eden space, the JVM memory request ends. Otherwise, to the next step,
C.JVM attempts to release all inactive objects in Eden (this belongs to garbage collection of 1 or higher). After release, if there is still not enough Eden space for new objects, it attempts to put some active objects in Eden into the Survivor area.
The D.Survivor area is used as the intermediate exchange area between Eden and OLD. When there is enough space in the OLD area, the objects in the Survivor area will be moved to the Old area, otherwise they will be retained in the Survivor area.
e. When there is not enough space in the OLD area, JVM will conduct a full garbage collection (level 0) in the OLD area.
f. After complete garbage collection, if Survivor and OLD areas are still unable to store some objects copied from Eden, resulting in JVM being unable to create JVM memory areas for new objects in Eden area, a "outofmemory error" will occur.
On how to parse the composition of JVM memory area to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.