Home >Java >javaTutorial >A brief introduction to CMS recycler in java (picture and text)

A brief introduction to CMS recycler in java (picture and text)

不言
不言forward
2018-09-28 13:59:012820browse

This article brings you a brief introduction (pictures and texts) about the CMS recycler in Java. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

CMS (Concurrent Mark Sweep) collector

It uses a mark and clear algorithm, and it is also a garbage collector that uses multi-threaded parallel collection.

CMS main work steps

The main steps when CMS works are initial marking, concurrent marking, pre-cleaning, re-marking, concurrent clearing and concurrent reset. The initial marking and re-marking are exclusive to system resources, while pre-cleaning, concurrent marking, concurrent clearing and concurrent reset can be executed together with user threads. Therefore it can perform garbage collection while the application is running.

A brief introduction to CMS recycler in java (picture and text)

According to the mark and clear algorithm, initial marking, concurrent marking and re-marking are all to mark objects that need to be recycled. Concurrent cleanup is to recycle garbage objects after marking is completed. Concurrent reset refers to reinitializing the CMS data structure and data after garbage collection is completed to prepare for the next garbage collection.

In the entire CMS recycling process, by default, there will be a pre-cleaning operation after concurrent marking (you can also set the parameter -XX:CMSPrecleaningEnabled to not perform pre-cleaning). Precleaning is concurrent. In addition to preparing and checking for formal cleaning, precleaning also attempts to control a pause time. Since remarking is exclusive to the CPU, if a remarking is triggered immediately after the new generation GC occurs, the pause time may be very long. In order to avoid this situation, during pre-cleaning, you can wait for a new generation GC to occur, then predict the time when the new generation GC may occur based on historical performance data, and then re-mark at the intermediate moment between the current time and the predicted time. In this way, the overlap between the new generation GC and re-marking can be avoided to the greatest extent, and a pause time can be reduced as much as possible.

CMS main parameter settings

-XX: UseConcMarkSweepGC to enable the CMS recycler

-XX:ConcGCThreads Set the number of concurrent threads

-XX:CMSInitiatingOccupancyFraction Set the current When the usage rate of the old generation reaches N, a CMS recycling is performed.

-XX: UseCMSCompactAtFullCollection CMS performs a defragmentation after garbage collection is completed.

-XX:CMSFullGCsBeforeCompaction Sets a memory compression after N times of CMS recycling.

-XX: CMSClassUnloadingEnabled Use CMS mechanism to recycle Perm area Class data

The above is the detailed content of A brief introduction to CMS recycler in java (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete