-JVM JAVA virtual machine tuning memory of introduction

A. The new generation, old time, permanent behalf

The new generation is divided into three regions, a region Eden and two Survivor areas, the ratio between them (8: 1: 1), this ratio is to be modified. Under normal circumstances, the main object is allocated on the new generation of the Eden area, in a few cases may also be assigned directly in the old era. (Copy here using the Java virtual machine each time you use the new generation of Eden and where a Survivor (From), after a Minor GC, Eden and Survivor will also live objects once copied onto another piece of space Survivor algorithm GC), finally clean out Eden and just spent Survivor (From) space. At this time, the age of the space in the Survivor surviving object is set to 1, after each of these objects in a Survivor areas get through the GC, their age incremented by one, when the object reaches a certain age Age (default 15), the We will move them to the old era.

In the new generation when GC, it is possible to encounter another piece of Survivor space is not enough space to store a new generation of live objects collected on down, these objects will go directly to the old year by allocating guarantee mechanism;
Here Insert Picture Description

1.Eden District

Eden area is located in the young generation of Java heap, where the new object is allocated memory, because the heap is shared by all threads, and therefore need to lock memory allocated on the heap. The Sun JDK to enhance efficiency, will be assigned to each new thread on an independent spaces exclusive Eden by the thread, this space is called TLAB (Thread Local Allocation Buffer). Memory allocation does not need to lock in on TLAB, therefore JVM will try to allocate on TLAB when the object to allocate memory thread. If the object is too large or TLAB run out, it can still be allocated on the heap. If you have run out of memory Eden District will conduct a Minor GC (young GC).

2.Survivor from to

Survival same area and Eden districts are the young generation of Java heap. Survival district has two, one called from area to area as the other one, these two zones is relative in the event of a Minor GC after, from region to region and will be interchangeable. In the event of Minor GC, Eden area and Survivalfrom area will put some still live objects copied into Survival to area and clear the memory. Survival to some of the area will have to survive old enough to object to the old generation.

3. The old generation

Are stored in the old generation of longer survival time, the size of large objects, use tags to organize old generation algorithm. Year old generation of capacity is full, will trigger a Major GC (full GC), resource recovery objects old generation and the young generation no longer in use.

Second Summary:

  1. Minor GC is happening in the new generation garbage collection, replication algorithm used;
  2. In each new generation of space used is not more than 90%, mainly used to store objects newborn;
  3. Minor GC after each collection region and a Survivor Eden area have been emptied;
  4. Old's use of Full GC, using the mark - sweep algorithm;

Resources:

Published 215 original articles · won praise 135 · Views 1.14 million +

Guess you like

Origin blog.csdn.net/weinichendian/article/details/104938929