Jvm gc (1)

Source: Internet
Author: User

I. Memory Distribution

1. Default Generation Distribution

2. Generation Distribution of parallel collector

II. Memory Division

1. Young Generation

1) objects with short lifecycles are classified as young generation. Due to the short life cycle, many of these objects become inactive during GC. Therefore, for young

Generation objects, using the copy algorithm, only need to copy a small number of surviving objects to space. The smaller the number of surviving objects, the higher the efficiency of the copy algorithm.

2) The GC of young generation is called minor GC. After several times of minor GC, the surviving objects will be removed from young generation and moved to tenured generation.

3) young generation is divided:

1.3.1 EDEN: whenever an object is created, it is always allocated in this area.

1.3.2 explain vor1: from space in the copy Algorithm

1.3.3 Classification vor2: To sapce in the copy algorithm (note: the identities of classification vor1 and classification vor2 are exchanged after each minor GC)

4) During minor GC, the Eden + kernel vor1 (2) object will be copied to kernel vor2 (1.

2. tenured generation

1) objects with long lifecycles are classified into tenured generation. Generally, objects that are still alive after multiple minor GC operations will be moved to tenured generation.

(Of course, in minor GC, if the number of surviving objects exceeds the capacity of zoovor, the objects that cannot be stored will be directly migrated to tenured generation)

2) The GC of tenured generation is called Major GC, which is generally called full GC.

3) use the compactiion algorithm. Because the tenured generaion area is relatively large and the object lifecycle is common, compaction takes some time.

Therefore, the GC time for this part is relatively long.

4) Minor GC may cause full GC. When the space of Eden + from space is larger than the remaining space in the tenured generation area, full GC is triggered. This is a pessimistic algorithm,

To ensure that all objects in Eden + from space survive, you must have enough tenured generation space to store these objects.

3. permanet generation

1) this region is relatively stable and mainly used to store classloader information, such as class information and method information.

2) For spring hibernate frameworks that require dynamic type support, this region requires sufficient space.

 

3. Reclaim Algorithm

1. reference counting)

The old recycling algorithm. The principle is that this object has a reference, that is, adding a count. deleting a reference reduces the count. During garbage collection, only objects with zero collection count are used.

The most critical issue of this algorithm is that it cannot handle circular references.

2. Mark-clear (mark-sweep)

This algorithm is executed in two phases. In the first stage, all referenced objects are marked from the reference root node. In the second stage, the whole heap is traversed to clear unmarked objects.

This algorithm suspends the entire application and generates memory fragments.

3. Copy)

This algorithm divides the memory space into two equal regions and uses only one of them at a time. During garbage collection, traverse the current region and copy the objects in use to another region.

This algorithm only processes objects in use at a time, so the replication cost is relatively small. At the same time, the corresponding memory can be organized after the replication, but there is a "Fragmentation" problem.

Of course, the disadvantage of this algorithm is also obvious, that is, it requires two times of memory space.

4. Mark-compact)

This algorithm combines the advantages of "tag-clear" and "copy" algorithms. It is also divided into two phases,

In the first stage, all referenced objects are marked from the root node,

In the second stage, the whole heap is traversed, And the unlabeled objects are cleared and the surviving objects are "COMPRESSED" to one of the heap parts, which are discharged in order.

This algorithm avoids the "tag-clear" fragmentation problem, and also avoids the space problem of the "copy" algorithm.

5. incremental collecting)

The garbage collection algorithm is implemented, that is, garbage collection is performed simultaneously by the application.

6. Generational collecting)

Based on the garbage collection algorithm obtained after object lifecycle analysis. Divides objects into young, old, and persistent generations, and recycles objects in different lifecycles using different algorithms.

 

4. Collector

1. Serial collector

A single thread is used to process all garbage collection tasks. Because multi-thread interaction is not required, the efficiency is relatively high. However, the advantages of multi-processor cannot be used, so this collector is suitable for single-processor machines.

Of course, this collector can also be used in small data volumes (100 m(Left and right) on a multi-processor machine. Available-XX: + useserialgcOpen.

2.ParallelCollector

Applicability: medium and large applications with high throughput requirements, multiple CPUs, and no application response time requirements. Example: background processing and scientific computing.

Parallel garbage collection for young generation can reduce the garbage collection time. Generally used on multi-threaded Multi-processor machines. Use-XX: + useparallelgcOpen.

In Java se6.0, You can heap the old generation for parallel collection. Use-XX: + useparalleloldgc.

This collector can be configured as follows:

-XX: parallelgcthreads = <n> Number of parallel garbage collection threads. This value can be set to be equal to the number of machine Processors

-XX: maxgcpausemillis = <n> maximum pause time for garbage collection

-XX: gctimeratio = <n> Ratio of the garbage collection time to the non-garbage collection time. The formula is 1/(1 + n ).

For example, when-XX: gctimeratio = 19, it indicates that 5% of the time is used for garbage collection. The default value is 99, that is, 1% of the time is used for garbage collection.

 

3.CurrentCollector

Applicability: medium and large applications with high response time requirements, multiple CPUs, and high response time requirements. Such as Web server/application server, telecom exchange, and integrated development environment.

Use-XX: + useconcmarksweepgcOpen.

 

The concurrent collector uses a multi-processor for a short pause. In a system with N processors, K available processors are used for concurrent collection. Generally, 1 <= k <= N/4

You can use the concurrent collector on a host with only one processor and set it to the incremental mode to get a short pause time.

1) floating garbage: Because the application is running at the same time for garbage collection, some garbage may be generated when the garbage collection is completed, resulting in "floating garbage", which must be

The next garbage collection cycle can be cleared. Therefore, the concurrent collector generally requires 20% of the reserved space for these floating spam.

 

2) Concurrent mode failure: Because concurrent collection starts to execute concurrent collection when the application is running, set-XX: cmsinitiatingoccupancyfraction = <n> to specify the number of remaining heaps.

Ensure that there is sufficient memory space for the program to use before the collection is complete.

Jvm gc (1)

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.