GC recovery mechanisms

A, GC things to do

  1, which requires recovery of memory, 2, and when recovered, 3, how recycling

Second, how to determine the memory garbage

  1, reference notation : if the number determined by the determination target object reference may be recovered, any reference count of the object instance can be 0 as garbage collection

   Advantages: high efficiency, little affected by the implementation of the program

   Missing: the case of circular references can not be detected, resulting in a memory leak. eg: there is a reference to the parent pairs, the parent has a child reference, so the two object references are not used 0

  2, reachability analysis : determining whether a chain of references to objects reachable to determine whether the object can be recovered by GC Root up to each object to determine whether

   Can be used as an object GC Root: The virtual machine stack referenced objects (local variable table stack frame), an object method area constant references, an object method area class static property references, native method stacks in the JNI ( Native) a reference to an object, the object reference active threads.

Third, the garbage collection algorithm

  1, mark - sweep algorithm: reachability analysis

  Tag: scanning from root set of objects marked survival, clear: for linear traverse from beginning to end heap memory, memory objects recovered unreachable

 

 

   2, the new generation of replication algorithm :()

  Into the target surface and the free surface, created objects in the object plane, survived the object is copied from the object surface to the free surface, the surface of the object to clear all objects in memory. Object low survival rate (the new generation)

  Solve the fragmentation problem, the new generation, the low survival rate of the object, so the object to be copied is small, this method of memory allocation order, simple and efficient. It will be powerless higher survival rate

  3, Mark - Collation Algorithm years old :()

  Tag: scan from the root set of objects marked survival clear: moving all surviving object and successively arranged in the order of the memory address, then memory address in memory after the end of full recovery. In the mark - sweep algorithm based on the addition of mobile functionality

  4, sub-generation mobile phone algorithms:

  Divided according to different regions of the life cycle of an object at different garbage collection algorithm to improve the efficiency of garbage collection jvm

  GC classification:

    (1/3 heap memory space) Minor GC : All newly created objects are generally in the Cenozoic

      Eden (Eden), 80%, two Survivor areas (from, to), 10%

        Eden is stored in the object, when the threshold is reached (Minor number), will be subject to any of a Eden Survivor in the storage area of ​​the current still alive, remove all objects in Eden, and the age of +1, this time from the current district became district the next time they reach the threshold of Eden, and the current Survivor region has reached the threshold value, then stored to another area Survivor, +1 age, area will become another Survivor from area.

  How objects promoted to the old year:

    1, go through a certain number of Minor (default 15) still live objects, 2, Survivor region can not fit the object 3, the new generation of large objects.

    (2/3 heap memory space) Full GC : objects stored longer life cycle

      Mark - sweep algorithm, mark - Collation Algorithm

      Full GC and Major GC, Full GC slower than Minor GC recovery efficiency, but the low execution frequency.

    Full GC trigger conditions

      Old's lack of space, lack of permanent space on behalf of

Fourth, the garbage collector

  

 Parallel Scavenge CMS and the collector can not coexist, because, and G1 are similar Parallel Scavenge framework used, not better coexistence with CMS

The new generation garbage collector:

   1, Serial collector (-XX: + UseSerialGC, replication algorithm)

    When single-threaded collection, garbage collection, threads must suspend all work

    Simple and efficient, the young generation collector under the Client mode

   2, ParNew collector (-XX: + UseParNewGC, replication algorithm)

    Multithreading collection, as the rest of the behavior, characteristics and Serial collectors

    Less efficient than single-core execution Serial (due to the need to thread switching overhead), have the advantage of multi-core execution

   3, Parallel Scavenge collector (-XX: + UseParallelGC, replication algorithm)

      Throughput = Code Run time / (run code processing time garbage collection time +)

    Compared to the previous two concerns user thread pause time, more concerned about the throughput of the system

    Have the advantage of multi-threaded execution, the young generation collector in Server mode

Old's garbage collector:

   1, Serial Old collector (-XX: + UseSerialOlaGC, Mark - Collation Algorithm)     

    When single-threaded collection, garbage collection, threads must suspend all work

    Simple and efficient, the young generation collector under the Client mode

    2, Parallel Old collector (-XX: + UseParallelOldGC, Mark - Collation Algorithm)

     Multi-threaded throughput priority

   3, CMS collector (-XX: + UseConcMarkSweepGC, mark - sweep algorithm)  

Guess you like

Origin www.cnblogs.com/guanyuehao0107/p/12045317.html