JVM-Garbage Collector, jvm-garbage collection

Source: Internet
Author: User

JVM-Garbage Collector, jvm-garbage collection

This article mainly introduces several JVM garbage collectors. As shown below, the three above are the new generation collectors,

The following three are the collectors of the old generation. The G1 collector can be used for the collection of the new generation and the old generation.


JVM Garbage Collector


1,Serial (Serial collector): Used for the generation of GC, replication algorithm. The default mode is the Client mode at startup, and the GC thread is a single thread. The disadvantage is that a single-thread GC causes a large interruption time (Sop-the-world. (For single-core CPUs, it is more efficient than parallel collection) as follows:


Serial collector


2,ParNew (parallel collector): Similar to Serial, the difference is that it is generally used for parallel collection of new generations, and usually runs in Server mode (single-core CPU, performance may be worse than Serial ). As follows:


ParNew parallel collector


3,Parallel Scavenge (Parallel collection): Used for new generation recycling, copying algorithms, and parallel collection. The difference from ParNew is that it has different concerns and can precisely control the throughput. [Throughput = program running time/(program running time + garbage collection time). For example, the JVM runs for 100 minutes. The garbage collection takes 1 minute, And the throughput is 99%:


Parallel Scavenge Parallel collection


4,Serial Old (Serial collector): It is an old version of the Serial collector. It uses the tag-compression (tag-sort) Collection algorithm and is mainly used for JVM in Client startup mode. See Serial collector.


5,Parallel Old (Parallel collector): It is the old version of Parallel. It uses the tag-compression (tag-sorting) Collection algorithm. For more information, see Parallel collection.


6,CMS (concurrent mark sweep): Concurrent collector (when GC occurs, the GC thread and Application Thread run simultaneously ). It is a collector with the shortest response as the target and is applicable to the operating environment of the B/S architecture. Using the tag-clear algorithm generates a large amount of memory fragments. The collection of CMS can be divided into several steps: [initial mark] ---> [concurrent mark] ---> [remark] ---> [concurrent clear concurrent sweep ]. It is as follows:


CMS concurrent collector

7,G1 collector: It is a server-oriented collector and may replace the CMS collector in the future. The G1 collector has the following features:

A. Concurrency and Parallelism: it can take full advantage of the hardware features of multi-core CPUs to shorten the Stop-the-world and run together with the application thread.

B. Split-band collection: Like other collectors, the concept of Division also exists in G1. G1 can manage GC independently. It can process objects with different survival times in different ways.

C. spatial integration: In general, G1 uses the Mark-compression (sorting) GC algorithm. This means that no large amount of memory fragments are generated during JVM running, so that the program can run for a long time.

D. Predictable pause: Compared with CMS, G1 can create a predictable pause model in addition to a shorter pause time.

If you do not calculate the Remembered Set operation, the G1 collector can be operated in the following steps: [initial mark initial marking] ---> [Mark concurrent marking] ---> [Mark final marking] ---> [filter and recycle live data counting and evacuation]


G1 concurrent collection


GC parameter Summary

-XX: + <option> enable option

-XX:-<option> disable option

-XX: <option >=< number>

-XX: <option >=< string>


  • -XX: + UseSerialGC: Serial collectors are used in the new and old generations.
  • -XX: Adjust vorratio: Set the ratio of eden and vior.
  • -XX: NewRatio: Ratio of the new generation to the old generation
  • -XX: + UseParNewGC: Parallel collectors are used in the new generation.
  • -XX: + UseParallelGC: the new generation uses the parallel collection collector.
  • -XX: + UseParallelOldGC: Parallel collector used in earlier years
  • -XX: ParallelGCThreads: specifies the number of threads used for garbage collection.
  • -XX: + UseConcMarkSweepGC: the new generation uses parallel collectors, while the old generation uses CMS + Serial collectors.
  • -XX: ParallelCMSThreads: sets the number of CMS threads.
  • -XX: CMSInitiatingOccupancyFraction: triggered when you set the space used by the CMS collector in the old age
  • -XX: + UseCMSCompactAtFullCollection: sets whether the CMS collector needs to organize memory fragments after completing garbage collection.
  • -XX: CMSFullGCsBeforeCompaction: specifies the number of times the CMS garbage collection is performed, and the memory is compressed once.
  • -XX: + CMSClassUnloadingEnabled: Class metadata can be recycled.
  • -XX: CMSInitiatingPermOccupancyFraction: When the permanent zone usage reaches one hundred, start CMS Recycle
  • -XX: UseCMSInitiatingOccupancyOnly: indicates that CMS is recycled only when the threshold value is reached.

GC parameter combination

GC parameter ------------------------------------------------------------------ Young -------------------------- tenured

========================================================== ======================================

-XX: + UseSerialGC ---------------------------------------------------- Serial ------------------------- Serial Old

-XX: + UseParallelGC -------------------------------------------------- Parallel Scavenge ------- Serial Old

-XX: + UseConcMarkSweepGC ------------------------------------------- ParNew -------------------- CMS

-XX: + UseParNewGC --------------------------------------------------- ParNew ---------------------- Serial Old

-XX: + UseParallelOldGC ----------------------------------------------- Parallel Scavenge --------- Parallel Old

-XX: + UseConcMarkSweepGC-XX: + UseParNewGC -------- Serial -------------------------- CMS

-XX: + UnlockExperimentalVMOptions-XX: + UseG1GC ------- G1-----------------------------G1


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.