JAVA Garbage Collector Overview

Source: Internet
Author: User

JAVA Garbage Collector Overview

1. Combination of garbage collectors

There are a total of 7 JAVA garbage collectors, minus G1, which has not yet been officially used in a large scale. There are also 6, 3 in the new generation and 3 in the old generation.

Because the garbage collector is a group of tasks, these six collectors constitute a total of 5 usage modes.

Parameters

Description

-XX: + UseSerialGC

Default value for Jvm running in Client mode. After this switch is enabled, memory is recycled using the collector combination of Serial + Serial Old.

-XX: + UseParNewGC

Turn on this switch and use the ParNew + Serial Old collector for garbage collection

-XX: + UseConcMarkSweepGC

Use the collector combination of ParNew + CMS + Serial Old for memory recovery, and use Serial Old as the backup collector for CMS after "Concurrent Mode Failure" fails.

-XX: + UseParallelGC

Default value for Jvm running in Server mode. After this switch is enabled, use the collector combination of Parallel Scavenge + Serial Old for collection.

-XX: + UseParallelOldGC

Use the collector combination of Parallel Scavenge + Parallel Old for collection

I have read Mr. Zhou Zhiming's book "deep understanding of Java virtual machines". Section 3.4 (page 55) contains a garbage collector diagram. Among them, the new generation of serial collectors and the old generation of CMS collectors do not directly call the method. Therefore, I drew a picture again to help myself understand the content.

2. Legend of the spam collector combination relationship

The six common garbage collectors are scheduled and used by these five methods.

3. Some JVM Parameters

Some other Java virtual machine parameters can be viewed as needed.

-XX: Invalid vorratio

Capacity Ratio of the Eden region to the region vor region in the new generation. The default value is 8, which indicates Eden: Subrvivor = 8.

-XX: PretenureSizeThreshold

The size of objects directly promoted to the old age. After this parameter is set, objects larger than this parameter will be directly allocated in the old age.

-XX: MaxTenuringThreshold

The age of the object promoted to the old age. After each Minor GC operation, the age is added with 1. When the value of this parameter is exceeded, the old age is entered.

-XX: UseAdaptiveSizePolicy

Dynamically adjust the size of each region in the java heap and the age of the old age

-XX: + HandlePromotionFailure

Whether to allow the new generation of collection guarantees. After one minor gc, when the other shard VOR has insufficient space, it will be directly retained in the old age.

-XX: ParallelGCThreads

Set the number of threads for memory collection by parallel GC.

-XX: GCTimeRatio

The percentage of GC time to total time. The default value is 99, that is, 1% of GC time is allowed. It is only valid when the Parallel Scavenge collector is used.

-XX: MaxGCPauseMillis

Sets the maximum pause time for GC, which is valid under the Parallel Scavenge collector.

-XX: CMSInitiatingOccupancyFraction

Sets the size of the space used by the CMS collector to start garbage collection. The default value is 68%, which is only valid when the CMS collector is used.-XX: CMSInitiatingOccupancyFraction = 70

-XX: + UseCMSCompactAtFullCollection

Because the CMS collector generates fragments, this parameter sets whether a memory fragment process is required after the Garbage Collector, which is only valid when the CMS collector

-XX: + CMSFullGCBeforeCompaction

Sets the CMS collector to perform a memory fragment process after several spam collections, which is usually used together with the UseCMSCompactAtFullCollection parameter.

-XX: + UseFastAccessorMethods

Original Type optimization

-XX: + DisableExplicitGC

Disable manual System. gc?

-XX: + CMSParallelRemarkEnabled

Lower mark pause

-XX: LargePageSizeInBytes

The memory page size cannot be too large, which will affect the Perm size.-XX: LargePageSizeInBytes = 128 m



4. Features of jdk gc combination

New Generation GC

GC in old age and persistent generation

-XX: + UseSerialGC

Serial GC

Serial Old Serial GC

-XX: + UseParallelGC

Parallel Scavenge Parallel GC collection

Serial Old Serial GC

-XX: + UseConcMarkSweepGC

ParNew parallel GC

CMS concurrent GC
When "Concurrent Mode Failure" appears
Serial GC using Serial Old

-XX: + UseParNewGC

ParNew parallel GC

Serial Old Serial GC

-XX: + UseParallelOldGC

Parallel Scavenge Parallel GC collection

Parallel Old Parallel GC

-XX: + UseConcMarkSweepGC
-XX: + UseParNewGC

Serial GC

CMS concurrent GC
When "Concurrent Mode Failure" appears
Serial GC using Serial Old

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.