JVM memory management and JVM garbage collection mechanism

Source: Internet
Author: User

JVM memory management and JVM garbage collection mechanism (1)

This paper describes the JVM memory management and JVM garbage collection concepts of JVM learning notes, the JVM memory structure consists of heap, stack, local method stack, method area and so on, in addition, the JVM uses different garbage collection mechanism for the Cenozoic and the old generation respectively.

AD:

You are familiar with the JVM memory composition structure and the JVM garbage collection mechanism, here and everyone to share briefly, hoping to help you learn, first look at the JVM memory structure, it is composed of heap, stack, local method stack, method area and so on, the structure diagram is as follows.

JVM Learning notes JVM memory management and JVM garbage collection

JVM Memory Composition Structure

The JVM memory structure consists of heap, stack, local method stack, method area and so on, and the structure diagram is as follows:

New Generation , the old generation "style=" margin:0px; padding:0px; border-width:0px; border-style:initial; List-style:none; " >

1) Heap

All the memory of objects created by new is allocated in the heap, and its size can be controlled by-XMX and-XMS. The heap is divided into the Cenozoic and the old generation, and the Cenozoic is further divided into the Eden and survivor areas, and the final survivor is composed of Fromspace and tospace, and the structure diagram is as follows:

New Generation , the old generation "style=" margin:0px; padding:0px; border-width:0px; border-style:initial; List-style:none; " >

Cenozoic. New objects are used to allocate memory in the Cenozoic, Eden Space is not enough, the surviving objects will be transferred to the survivor, the Cenozoic size can be controlled by-xmn, you can also use-xx:survivorratio to control the proportions of Eden and survivor old generation. For storing objects that are still alive after multiple garbage collection in the Cenozoic

2) stack

Each thread executes each method by applying a stack frame in the stack, each of which includes a local variable area and an operand stack to hold temporary variables, parameters, and intermediate results during the method call.

3) Local Method stack

Used to support the execution of the native method, which stores the state of each native method call

4) Method Area

Contains the class information to load, static variables, constants of the final type, properties, and method information. The JVM uses durable generation (permanetgeneration) to store the method area, and the minimum and maximum values can be specified by-xx:permsize and-xx:maxpermsize. After introducing the JVM memory composition structure, let's look at the JVM garbage collection mechanism.


JVM memory management and JVM garbage collection mechanism (2) 2010-09-26 16:42 Cutesource blog.csdn.net I want to comment (0) Size:T | TCenozoicThe old generation "style=" margin:0px; padding:0px; Border-width:medium; List-style:none; " >

This paper describes the JVM memory management and JVM garbage collection concepts of JVM learning notes, the JVM memory structure consists of heap, stack, local method stack, method area and so on, in addition, the JVM uses different garbage collection mechanism for the Cenozoic and the old generation respectively.

AD:

JVM garbage collection mechanism

The JVM uses different garbage collection mechanisms for the Cenozoic and the old generation respectively

New generation of GC:

The new generation usually has a shorter survival time, so the so-called copying algorithm is used to retrieve the surviving object based on the copying algorithm, and copy it into a completely unused space, corresponding to the Cenozoic, which is copy between Eden and Fromspace or Tospace. The Cenozoic uses a free pointer to control the GC trigger, the pointer keeps the last allocated object in the Cenozoic interval, and when a new object is allocated memory, it is used to check if the space is sufficient and not enough to trigger the GC. When objects are continuously allocated, the objects gradually go from Eden to Survivor, and finally to the old generation,

Using JAVAVISUALVM to view, can obviously observe the new generation full after the object will be transferred to the old generation, and then empty continue to load, when the old generation is full, will be reported OutOfMemory exception, as shown:

New Generation , the old generation "style=" margin:0px; padding:0px; border-width:0px; border-style:initial; List-style:none; " >


JVM provides serial GC (SERIALGC), parallel reclaim GC (Parallelscavenge), and parallel GC (PARNEW) on execution mechanism

1) Serial GC

The entire scanning and copying process is a single-threaded way, suitable for single CPU, the new generation of small space and the demand for pause time is not very high application, is the client level of the default GC mode, can be-XX:+USESERIALGC to enforce the specified

2) Parallel Recovery GC

In the entire scanning and replication process in a multi-threaded way, for multi-CPU, the time required for a short pause on the application, the server level is the default use of GC mode, can be-XX:+USEPARALLELGC to enforce the designation, with-XX: Parallelgcthreads=4 to specify the number of threads

3) Parallel GC

Use with concurrent GC for legacy generations

GC for old generation:

The old generation and the new generation, the object survival time is longer, more stable, so the mark (Mark) algorithm for recycling, so-called Mark is to scan out the surviving objects, and then to reclaim unmarked objects, after recycling the empty space is either merged, or marked out for the next allocation, The bottom line is to reduce the loss of efficiency caused by memory fragmentation. The JVM provides a serial GC (SERIALMSC), parallel GC (PARALLELMSC), and concurrent GC (CMS) on the execution mechanism, and the details of the algorithm need to be further studied.

The various GC mechanisms above need to be combined, as specified in the following table:

New Generation , the old generation "style=" margin:0px; padding:0px; border-width:0px; border-style:initial; List-style:none; " >

JVM memory management and JVM garbage collection mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.