jvm-garbage collector

Source: Internet
Author: User

This article mainly introduces several garbage collectors of the JVM. As shown below, the above three are the new generation of collectors, the following three are the old collectors, wherein the G1 collector can be used for the new generation and the old age collection work.


JVM garbage collector


1,Serial (serial collector): For the generation of GC, replication algorithm, the default is client mode at startup, the GC thread is single-threaded. The disadvantage is that because of the single-threaded GC, the time to interrupt (Sop-the-world) is larger. (more efficient than parallel collection for a single-core CPU) is as follows:


Serial serial Collector


2,parnew (parallel collector): Similar to serial, the difference is that it is generally used for the generation of parallel recovery, and typically run in server mode (single-core CPU, performance may be worse than serial). As shown below:


Parnew Parallel collector


3,Parallel scavenge (parallel recovery): For the generation of recovery, replication algorithm, parallel collection. The difference from Parnew is that its focus is different, and it can precisely control throughput. "Throughput = Program Run time/(program run time + garbage collection time), for example: The JVM runs a total of 100min. Where garbage collection takes 1min, the throughput is 99% "as shown below:


Parallel Scavenge Parallel Collection


4,Serial old (serial collector): is the older version of the Serial collector, using the tag-compression (Tag-collation) collection algorithm, mainly used to start the JVM of the client mode. Refer to the serial serial collector.


5,Parallel old (parallel collector): is the older version of Parallel, using the tag-compression (Tag-collation) collection algorithm. It can be referenced parallel parallel collection.


6.CMS (concurrent Mark Sweep): Concurrent collector (GC thread runs concurrently with the application thread when GC occurs). is a collector with the shortest response, which is suitable for the operating environment of B/s architecture. Use the tag-clear algorithm, resulting in a large amount of memory fragmentation. The collection of CMS can probably be divided into several steps: "Initial tag initial mark"---> "Concurrent tag Concurrent mark"---> "re-tag remark"---> "Concurrent purge Concurrent sweep". It is as follows:


CMS concurrency Collector

7,G1 collector : is a service-oriented collector, the future is likely to replace the CMS collector. The G1 collector has the following features:

A, concurrency and parallelism: can take advantage of the hardware features of multicore CPUs to shorten the pause time (Stop-the-world) and can be run with the application thread.

B, Sub-band collection: As with other collectors, the concept of generational is also present in G1. G1 can manage the GC on its own, and it can handle objects of different survival times in different ways.

C, Spatial integration: From a holistic perspective, G1 uses a GC algorithm for tag-compression (collation). This means that the JVM runs without generating a lot of memory fragmentation, allowing the program to run for long periods of time.

D, predictable pauses: compared to CMS, G1 can also establish a predictable pause-time model in addition to a shorter pause time.

Without calculating the operation of the remembered set, the operation of the G1 collector can be divided into the following steps: "Initial tag initial marking"---> "Concurrency tag Concurrent marking"---> "final mark End Marking "--->" filter recycle Live data counting and evacuation "


G1 Concurrent Parallel Collection


GC Parameter Summary

-xx:+<option> Enable options

-xx:-<option> do not enable options

-xx:<option>=<number>

-xx:<option>=<string>


  • -XX:+USESERIALGC: Using serial collectors in the new generation and in the old era
  • -xx:survivorratio: Setting the size of the Eden and Survivior extents
  • -xx:newratio: The ratio of the new generation to the old age
  • -XX:+USEPARNEWGC: Using parallel collectors in the Cenozoic
  • -XX:+USEPARALLELGC: The new generation uses the parallel collection collector
  • -XX:+USEPARALLELOLDGC: old age using the parallel collection collector
  • -xx:parallelgcthreads: Set the number of threads to use for garbage collection
  • -XX:+USECONCMARKSWEEPGC: New generation uses parallel collectors, older generations using cms+ serial collectors
  • -xx:parallelcmsthreads: Set the number of threads for the CMS
  • -xx:cmsinitiatingoccupancyfraction: Set the CMS collector to trigger after the old age space is used
  • -xx:+usecmscompactatfullcollection: Set whether the CMS collector will defragment the memory once the garbage collection is complete
  • -xx:cmsfullgcsbeforecompaction: Set the number of times the CMS garbage collection, after the memory compression
  • -xx:+cmsclassunloadingenabled: Allow recycling of class metadata
  • -xx:cmsinitiatingpermoccupancyfraction: When the occupancy rate of the permanent zone reaches this percentage, start the CMS recycle
  • -xx:usecmsinitiatingoccupancyonly: Only when the threshold is reached, the CMS is recycled

GC parameter combinations

GC Parameters------------------------------------------------------------------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


jvm-garbage collector

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.