JVM GC Algorithm garbage collector

Source: Internet
Author: User

There are three garbage collection algorithms for the JVM: 1. Mark-Clear (Mark-sweep): Nothing to say, direct 2. Mark-Organize (mark-compact) 3. Copy Generational Collection AlgorithmsThe current garbage collection is using generational collection algorithmsIt also derived a lot of garbage collector "generational collection" (generational Collection) algorithm, the Java heap is divided into the new generation and the old age, so that according to the characteristics of each era to adopt the most appropriate collection algorithm.  In the Cenozoic, every garbage collection is found to have a large number of objects died, only a small number of survival, then choose the replication algorithm, only need to pay a small number of surviving objects of the replication cost can be completed collection.    In the old age, because of the high survival rate of the object and the lack of additional space to guarantee it, it must be recycled using the "mark-clean" or "mark-sweep" algorithm. "Mark-Organize" is usually selected. Because "Mark-clean" creates a lot of discontinuous space. There will be a lot of debris. Serial collectorThe serial collector is the oldest, most stable, and efficient collector, which can cause a long pause, using only one thread to recycle. The new generation, the old generation uses the serial recovery, the Cenozoic replication algorithm, the old generation mark-compression; The garbage collection process will stop the World (service pause) parameter control:-XX:+USESERIALGC serial collectorparnew CollectorThe Parnew collector is actually a multithreaded version of the serial collector. Cenozoic parallel, old age serial; New generation replication algorithm, old age token-compression parameter control:-XX:+USEPARNEWGC parnew collector-xx:parallelgcthreads Limit number of threadsParallel CollectorThe Parallel scavenge collector is similar to the Parnew collector, and the Parallel collector pays more attention to the throughput of the system. Parameters can be used to turn on the adaptive adjustment strategy, the virtual opportunity to collect performance monitoring information according to the current system operation, dynamically adjust these parameters to provide the most suitable pause time or maximum throughput, or the time of the GC can be controlled by parameters not more than milliseconds or scale; Cenozoic replication Algorithms, Old age marker-Compression parameter control:-XX:+USEPARALLELGC using parallel collector + old age serialParallel Old collectorParallel old is an older version of the Parallel scavenge collector, using multithreading and the "mark-and-organize" algorithm. This collector was only started in JDK 1.6 to provide parameter control: -xx:+useparalleloldgc  using parallel collector + old age parallel  cms collector cms (Concurrent Mark Sweep) collector is a collector with the goal of obtaining the shortest recovery pause time. At present, a large part of the Java applications are concentrated in the Internet or B/s system services, such applications pay particular attention to the response of the service, the hope that the system will be the shortest time to pause, in order to bring a better user experience. From the name (including "Mark Sweep") you can see that the CMS collector is implemented based on the "tag-purge" algorithm, its operation is more complex than the previous collectors, the entire process is divided into 4 steps, including the:  initial tag (CMS initial Mark) concurrent (CMS concurrent mark) re-tagging (CMS remark) concurrent Cleanup (CMS concurrent sweep)   where the initial tag, re-tagging these two steps still requires "Stop the World". The initial tag simply marks the object that the GC Roots can directly relate to, is fast, the concurrent tagging phase is the process of GC Roots tracing, and the re-tagging phase is to fix the concurrency tag period. The mark record of the part of the object that caused the tag to change as the user program continues to work, the period of time will generally be slightly longer than the initial marking phase, but much shorter than the time of the concurrent tag.        because the collector thread can work with the user thread during the longest concurrent markup and concurrent cleanup process throughout the process, the overall The memory recycling process for the CMS collector is performed concurrently with the user thread. Old age collectors (new generation using parnew)    Benefits: Concurrent collection, low pauses      drawbacks: generating large amounts of space debris, concurrency phase reduces throughput     Parameter control:-xx:+useconcmarksweepgc   using the CMS collector               -xx:+ UAfter SECMSCOMPACTATFULLCOLLECTION FULL GC, the defragmentation process is exclusive, causing the pause time to grow              -XX:+CMSFullGCsBeforeCompaction   set up a few full GC to defragment once             -XX:ParallelCMSThreads   Set the number of threads for the CMS (typically approximately equal to the number of available CPUs)

JVM GC algorithm 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.