JVM garbage algorithm and garbage collector

Source: Internet
Author: User

When it comes to JVM garbage collection, we usually ask three questions, what is a recycled object? When do I recycle? How to recycle? The main areas reclaimed by JVM garbage collection are the Java heap, and by understanding the structure of the JVM's memory, we know that the heap is primarily responsible for object and array storage. The heap can also be subdivided. First, heap memory classification

1. Cenozoic-new objects into the Cenozoic, the Cenozoic can be divided into three regions Eden-new objects first entered the region from Survior-Cenozoic another region to Survior-Ibid. 2. Old Generation--the objects that survived after n garbage collection in the new generation were placed in the old age. And large objects go straight into the old age. New objects come into the Eden area. Because most of the objects are going to die, according to empirical analysis, the average Eden and Survior size ratio is 8:1. When Eden is full, the minor GC is performed once, and if the object size is larger than the Survior area size, the object enters the old age area. Why generational is required because if all objects are marked-cleaned in the same way, the efficiency is low and cleanup causes the virtual machine to pause and affect performance. Why there are 2 survior areas, this is to reduce the production of debris. When a MINORGC is performed, if there is only one survior zone, the fragment is generated. If there are 2 Survior, Eden and the surviving object of a survior are copied to another Survior area, there is no fragmentation

Second, when the recovery when the heap memory is not enough to recycle, there are 2 kinds of recovery Method 1. Minor GC--New Generation GC recovery, fast, high frequency 2. Full GC trigger-the old age GC recovery, slower than MINORGC 10 times times slower, low frequency three, recycling objects 1. Reference counting algorithm Basic principle: Add a reference counter to the object, and whenever there is a place to refer to it, the counter value is incremented by 1, and when the reference is invalidated, the counter value is reduced by 1. An object with a counter of 0 at any moment is an advantage that cannot be reused: simple, efficient disadvantage: it is difficult to handle circular reference 2. The basic principle of the Accessibility analysis algorithm: from GC Roots (each specific implementation of the GC Roots different definitions) as a starting point, search down the object they refer to, you can generate a reference tree, the tree node as an achievable object, and vice versa as to how to determine the object is dead four, how to reclaim 1. Recovery Algorithm 1. The basic principle of the markup cleanup algorithm (Mark-sweep) is to mark out all the objects that are available from the root node, and then clear all unmarked objects disadvantage: low efficiency, need to traverse from beginning to end, produce more discontinuous fragments 2. The basic principle of the replication algorithm (Copying) is to mark out all the objects that are available from the root node, and then clear all untagged objects Advantages: High efficiency, regardless of the complexity of fragmentation and other disadvantages: only half of memory 3. The basic principle of the tagging algorithm (mark-compact) is to mark out all the objects that are accessible from the root node, then move all objects to one end, and then clear out the memory benefits beyond the bounds: no memory fragmentation Disadvantage: The object is moved on top of the tag, the cost is relatively high, The efficiency is also not high 4. Generational recovery algorithm 2. The new generation of collector serial single-threaded: simple and efficient parnew serial multi-threaded version, with the CMS, can not be combined with PS parallel scavenge copy algorithm, multi-threaded parallel, suitable for the response time requirements of the scene of the old age collector serial Old single-thread, with the older version of Psparallel-PS CMS get the shortest time target collector G1 based on the tag collation, with very precise control over Java heap     java garbage Collection Basics "http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Java Virtual machine in detail----JVM FAQ Summary" Http://www.cnblogs.com/smyhvae/p/4810168.htmL

JVM garbage algorithm and 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.