JVM GC Garbage collector detailed __ virtual machines

Source: Internet
Author: User
Tags garbage collection
http://blog.csdn.net/java2000_wl/article/details/8030172 Click on the Open link
HotSpot JVM Collector

There are 7 collectors, divided into two, the new generation of collectors, the following is the old age collector. If there is a connection between the two collectors, it means they can be used in combination.serial (serial GC) collectorThe serial collector is a new generation collector, single-threaded execution, using a replication algorithm. It must suspend all other worker threads (user threads) while it is garbage collected. Is the default Cenozoic collector in JVM client mode. For environments that qualify for a single CPU, the serial collector is naturally able to achieve the highest single thread collection efficiency due to the lack of thread interaction overhead, concentrating on garbage collection.parnew (parallel gc) collectorThe Parnew collector is actually a multi-threaded version of the serial collector, with the same behavior as the serial collector, in addition to using multiple threads for garbage collection.Parallel Scavenge (Parallel recovery GC) collectorThe Parallel scavenge collector is also a new generation collector, and it is also a collector with a replication algorithm and a parallel multithreaded collector. The feature of the parallel scavenge collector is that its focus is different from that of other collectors, and the focus of collectors such as CMS is to minimize the downtime of user threads while garbage collection is possible, while the parallel scavenge collector's goal is to achieve a controllable throughput. Throughput = Program Run time/(program run time + garbage collection time), the virtual machine runs for 100 minutes altogether. The garbage collection takes 1 minutes, and the throughput is 99%.Serial old (serial GC) collectorSerial old is the older version of the serial collector, which uses a single thread to perform the collection, using the "tag-collation" algorithm. The main use of virtual machines in client mode.Parallel old (parallel gc) collectorParallel old is the older version of the Parallel scavenge collector, using multithreaded and "tag-organize" algorithms. CMS (concurrent GC) collectorThe CMS (Concurrent Mark Sweep) collector is a collector with the goal of obtaining the shortest recovery pause time. The CMS collector is based on the "tag-purge" algorithm, and the entire collection process is divided into 4 steps: ①. Initial tag (CMS initial mark) ②. Concurrency token (CMS concurrenr mark) ③. Re-mark (CMS remark) ④. Concurrency Cleanup ( CMS concurrent sweep in which the two steps of initial marking and re tagging need to pause other user threads. The initial tag merely marks the object that the GC ROOTS can directly relate to, the speed is very fast, the concurrent marking stage is the GC ROOTS root search algorithm stage, will determine whether the object survives.      The re-marking phase is intended to modify the tag records of the part of the object that caused the markup to change as the user program continues to run, which is slightly longer than the stage of the initial tag, but shorter than the concurrent markup phase. Because collector threads can work with user threads throughout the longest concurrent markup and concurrency cleanup process, the CMS Collector's memory recycle process is executed concurrently with the user thread. The advantages of the CMS collector: Concurrent collection, low pause, but the CMS is far from perfect, there are three major shortcomings: The CMS collector is very sensitive to CPU resources. In the concurrency phase, the user thread does not pause, but consumes CPU resources and causes the referral program to slow down and the total throughput down. The number of recycle threads that the CMS defaults to boot is: (number of CPUs +3)/4. The CMS collector is unable to handle floating garbage, and "Concurrent Mode failure" may occur, resulting in another full GC after failure. Since the CMS concurrent cleanup phase user thread is still running, accompanied by the running of the program from the hot will be new garbage generation, this part of the garbage in the process of marking, the CMS can not be processed in this collection, it has to leave the next GC to clean it out. This part of the rubbish is called "floating rubbish". Also because the user thread in the garbage collection phase still needs to run,
That is, you need to reserve enough memory space for the user thread to use, so the CMS collector cannot wait until the old age is almost fully populated and collected, as other collectors do, and you need to reserve a portion of the memory space for the operation of the program when the concurrent collection occurs. By default, the CMS collector is activated when 68% of the space is used in the old age, or it can provide a trigger percentage by the value of the parameter-xx:cmsinitiatingoccupancyfraction to reduce the number of memory collections to improve performance. If the memory reserved during the CMS operation does not meet the needs of other threads of the program, "Concurrent Mode failure" will fail, at which point the virtual machine will start the backup plan: temporarily enable the serial old collector to recreate the garbage collection of the older age, So the pause time is very long. Therefore, the parameter-xx:cmsinitiatingoccupancyfraction set too high will easily lead to "Concurrent Mode failure" failure, performance is reduced. Finally, the CMS is a collector based on the "tag-purge" algorithm that is collected with a "tag-purge" algorithm, resulting in a lot of fragmentation. Too much space debris will cause a lot of trouble to object allocation, such as large objects, memory space can not find a contiguous space to allocate had to trigger a full GC in advance. To address this problem, the CMS collector provides a-xx:usecmscompactatfullcollection switch parameter for adding a defragmentation process after the full GC, and also through-XX: After the Cmsfullgcbeforecompaction parameter setting executes the number of uncompressed full GC, follow the defragmentation process.G1 CollectorThe G1 (garbage) collector is a new collector provided by JDK1.7, which is based on the "tag-collation" algorithm, which means that no memory fragmentation is generated. There is also a feature before the collector to collect the range is the entire Cenozoic or the old age, while the G1 will be the entire Java heap (including the Cenozoic, old age).Garbage collector Parameter Summary-xx:+<option> Enable options-xx:-<option> do not enable options-xx:<option>=<number>-xx:<option>=<string >

Parameters Description

-xx:+useserialgc

The JVM runs the default value in client mode, and when this switch is turned on, memory recycling is performed using the collector combination of serial + serial old
-xx:+useparnewgc When this switch is turned on, garbage collection is used with the Parnew + serial old collector
-xx:+useconcmarksweepgc Use Parnew + CMS + serial old collector for memory recycling, serial old as a CMS in the "Concurrent Mode failure" after the failure of the backup collector use.
-xx:+useparallelgc The JVM runs the default value in Server mode, and when this switch is turned on, it is recycled using the collector combination of parallel scavenge + serial old
-xx:+useparalleloldgc Recycling using the collector combination of Parallel scavenge + Parallel old
-xx:survivorratio The capacity ratio of the new generation in the Eden region and the survivor region defaults to 8, representing Eden:subrvivor = 8:1
-xx:pretenuresizethreshold Directly promoted to the old age object size, after setting this parameter, objects larger than this parameter will be assigned directly in the old age
-xx:maxtenuringthreshold The age of the object of the old year, after each minor GC, the age of 1, when more than the value of this parameter into the old age
-xx:useadaptivesizepolicy Dynamically adjusting the size of each area in the Java heap and the age of entry into the old age
-xx:+handlepromotionfailure Whether the new generation is allowed to collect security, after a minor GC, another piece of survivor space is not enough, will be directly in the old age to retain
-xx:parallelgcthreads Set the number of threads for a parallel GC to recycle memory
-xx:gctimeratio GC time as the total time of the column, the default value is 99, that is, allow 1% GC time, only when using the parallel scavenge collector is valid
-xx:maxgcpausemillis Sets the maximum pause time for the GC, valid under the parallel scavenge collector
-xx:cmsinitiatingoccupancyfraction Set the CMS collector to start garbage collection after the old age space is used, the default value is 68%, only when the CMS collector is valid,-xx:cmsinitiatingoccupancyfraction=70
-xx:+usecmscompactatfullcollection
Because the CMS collector produces fragmentation, this parameter sets whether a memory defragmentation process is required after the garbage collector, only when the CMS collector is available
-xx:+cmsfullgcbeforecompaction
Set up the CMS collector to perform a memory defragmentation process after several garbage collections, typically with the usecmscompactatfullcollection parameter
-xx:+usefastaccessormethods
Original type optimization
-xx:+disableexplicitgc
Whether to turn off manual System.GC
-xx:+cmsparallelremarkenabled
Lower Mark pauses
-xx:largepagesizeinbytes
The size of the memory page cannot be set too large, affecting the size of the perm,-xx:largepagesizeinbytes=128m


Client, Server mode default GC

The new

generation GC method old age and persistent generation GC method

Client

Serial serial GC Serial Old serial GC
Server Parallel Scavenge Parallel Recovery GC Parallel Old parallel GC


Sun/oracle JDK GC Combination method

The new

generation GC method old age and persistent generation GC method

-xx:+useserialgc

Serial serial GC Serial Old serial GC
-xx:+useparallelgc Parallel Scavenge Parallel Recovery GC Serial Old parallel GC
-xx:+useconcmarksweepgc Parnew Parallel GC CMS Concurrent GC
When "Concurrent Mode failure" appears
Using serial old serial GC
-xx:+useparnewgc Parnew Parallel GC Serial Old serial GC
-xx:+useparalleloldgc Parallel Scavenge Parallel Recovery GC Parallel Old parallel GC
-xx:+useconcmarksweepgc
-xx:+useparnewgc
Serial serial GC CMS Concurrent GC
When "Concurrent Mode failure" appears
Using serial old serial GC


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.