GC Garbage Collection algorithm

Source: Internet
Author: User

GC Judging whether an object survives an algorithm
1> Reference counting algorithm 2> root search algorithm (GC root)
GC garbage Collection algorithm1> markup Cleanup Algorithm (MARK-SWEEP): Divided into two stages, mark and clear, first mark out the objects that can be recycled, after marking the unified collection. Disadvantages are as follows:a) Low efficiency: The labeling and removal process is not efficient;
b) Space problem: a large number of discontinuous memory fragments are generated after the purge.
2> copy Algorithm (Copying): divides memory into two blocks of equal size, using only one block at a time, and when cleanup is needed, copies the surviving objects directly to another. This approach is simple and efficient, and there is no fragmentation problem, and the disadvantage is that the actual available memory is reduced to half the original. 3> marker Grooming Algorithm (mark-compact): Similar to tag cleanup, the point is that the collation moves to one end of the surviving object without fragmentation. 4> Generational collection algorithm (generational Collection): divides memory into blocks based on the difference in the survival cycle.
GC Recovery algorithm for JVM virtual machines1> Collection: Divided into the younger generation and the old age2> Replication Collection: The younger generation uses 2 surviving zones for replication (default scale: 8:1:1, where 1 is used for swapping, so the actual usable is 90%)3> labeling: old age due to the high survival rate of the object, it is suitable for recycling using tag grooming or labeling cleanup
JVM garbage collector1> Young Generation: Serial, Partnew, Parallel scavenge-g12> older generation (tenured Generation): CMS, Serial old (MSC) , Parallel old-to-g1serial:jdk1.3.1 version, characterized by single-threaded collection, stop the Worldpartnew:serial multi-threaded version, stop the Worldparallel Scavenge: Similar to partnew, but also multi-threaded, except that throughput can be controlled by parameters (that is, the GC's pause time and GC time scale)
Serial old: Single-threaded collection, using the markup grooming algorithm Parallel the older version of Old:parallel scavenge, using multithreading and tagging algorithm concurrent Mark Sweep (CMS) : The collector with the shortest GC pause time, can control the compression of the fragment by parameters (whether to turn on the compression switch and the frequency setting of compression) G1 (garbage first): G1 to the new generation and the old era of the same management, divided into a number of fixed-size independent regions region, Using the labeling algorithm to realize low-pause recovery without sacrificing throughput
MINORGC and FULLGC1> Generation GC (Minor GC): Refers to a new generation of garbage collection, typically a short life cycle of objects (for example: method internal declaration objects), through the survival Zone exchange to deal with, so fast recoverya) Trigger condition: Fires when an object is created when there is not enough space in Eden, and when a single object is larger than the surviving area when the minor GC is executed, the old age is shifted by assigning a security mechanism.
b) Recommended: Due to minor GC speed, it is recommended that the unused objects in time to be empty, in favor of the object in the new generation recovery;        It is not recommended to create large objects with short life cycles that cause frequent GCparameters can be used to set the threshold to direct large objects into the old age     (by default, 15 times in the surviving zone will be moved to the old age; dynamic Age Judgment: all objects of the same age in the surviving area are larger than half of the surviving space, and objects older than or equal to that age can enter the old era directly). 2> old age GC (full gc/major GC): Refers to garbage collection occurring in the old age, which is slow (10 times times slower than MINORGC) and has a pause response (stop the World).      If the FULLGC is very frequent (more than 90%) will severely affect service performance, you will need to adjust the heap memory parameter size or move large objects to heap external memory.     Example:/usr/local/java/bin/jstat-gccause 16463 1000 # View GC changes (16463 for process id,1000 means update results every 1000 milliseconds)

conditions for GC recovery of permanent generations1> all instances of this class have been reclaimed, that is, no instance of the class exists in the heap;2> the ClassLoader of the class has been reclaimed;3> the class object of that category is not referenced anywhere, and the method of accessing the class can be accessed anywhere by reflection.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

GC Garbage Collection algorithm

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.