JVM Memory Area Division Eden space,survivor Space,tenured Gen,perm Gen

Source: Internet
Author: User

The JVM area is generally divided into two categories, the heap and the non-heap areas. The heap is also divided into: Eden Space (Eden), Survivor Space (Survivor area), tenured Gen (old age-pension area). Non-heap: code cache, Perm Gen (Permanent generation), JVM stack (Java Virtual machine stack), local method Statck (native methods Stack).

The hotspot virtual machine GC algorithm uses the Generational collection algorithm:

1, a person (object) out (new) will be in Eden Space (Eden) Carefree life, until the GC came to break their quiet life. The GC will ask each object what the case is, there is no money (reference to this object) Ah, because the GC wants to make money, money can blackmail it. Then the rich will enter Survivor space (Survivor area), and the poor will kill directly.

2, not enter Survivor Space (Survivor area) after the guarantee that the person is safe, but at least can live a period of time. The GC will be regularly (customizable) to extort these people, and every time the billionaire gives the money, the GC is satisfied and lets it enter the genured Gen (pension area). Wanyuanhu not live several times extortion there is no money, GC see no value, directly kill off.

3, enter into the old-age area of the basic can ensure personal safety, but some billionaires will also splurge into poor, as long as the money is not, GC or kill off.

The purpose of the partition: the new district because the object produces more and most of it is toward the birth, so the direct use of marker-cleanup algorithm. And the old-life is very strong, the use of replication algorithm, for different situations using different algorithms.

In the non-heap region, the definition of class and method is put in Perm Gen, and the JVM stack area is referenced by method parameters, local variables, etc., and the execution order of the method is based on the first in and out mode of the stack.

GC Working mechanism

Sun's JVM memory pool is divided into the following sections:

Eden Space (Heap)

Memory is initially allocated from this thread pool to most objects.

Survivor Space (Heap)

Used to hold objects that have not been reclaimed after garbage collection in the Eden Space memory pool.

Tenured Generation (heap)

Used to keep objects that have existed for some time in the Survivor space memory pool.

Permanent Generation (NON-HEAP)

Save the virtual machine's own static (reflective) data, such as class and method objects. Java Virtual machines share these class data. This area is divided into read-only and write-only.

Code Cache (NON-HEAP)

The HotSpot Java Virtual machine includes a memory for compiling and saving the local code (native code), called the "Codes cache".

In short, the JVM's memory recycling process is this:

Objects are created in Eden Space, and when Eden Space is full, the GC scans all objects in Eden space once, copies all valid objects to the first survivor space, and frees up space occupied by invalid objects. When Eden space becomes full again, it starts the mobile program to copy the valid objects in Eden space to the second survivor space, and also copies the valid objects from the first survivor space to the second survivor space. If a valid object that is populated in the second survivor space is referenced by the object in the first survivor space or Eden space, those objects are long-lived, and the objects are copied to the permanent Generation.

If the garbage collector does not make enough space based on this small amount of adjustment collection, it runs the full GC, at which point the JVM GC stops all threads running in the heap and performs cleanup actions.

JVM Memory Area Division Eden space,survivor Space,tenured Gen,perm Gen

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.