Generational Collection Theory of JVM Virtual Machine

Overview : Before learning garbage collection algorithms and garbage collectors, you must know the generational collection theory, so that you can understand the reasons for the three different garbage collection algorithms and understand where the roots of each garbage collection are. It is precisely because of the generational collection theory that there is a garbage collection algorithm, and only with a garbage collection algorithm can there be a garbage collector.

  1. What is the generational collection theory?
    The collector should divide the Java heap into different areas, and then allocate the reclaimed objects to different areas for storage according to their age (age is the number of times the object has survived garbage collection). Obviously, if most of the objects in an area are dying, and it is difficult to survive the garbage collection process, then they should be put together, and each time they are collected, only focus on how to keep a small number of surviving objects instead of marking those large numbers that will be collected. Objects, so that a large amount of memory space can be reclaimed at a small cost (here in the JVM corresponds to the new generation); if the remaining objects are hard to die, put them together, then virtual The computer can use a lower frequency to reclaim this area (here in the JVM corresponds to the old age), so that both the time overhead of garbage collection and the effective use of memory space are taken into account. This is the generational collection theory.

  2. The basis
    of generational collection theory The generational collection theory is nominally a theory, but it is actually a set of empirical rules that conform to the actual operation of most programs. It is based on two generational hypotheses, as shown below, and there is another A cross-generational citation hypothesis that supplements the first two hypotheses.

     ①. 弱分代假说:绝大多数对象都是朝生夕灭的,这个假说奠定了新生代的雏形。
     ②. 强分代假说:熬过越多次垃圾收集的对象就越难以消亡,这个假说奠定了老年代的雏形。
     ③. 跨代引用假说:跨代引用相对同代引用只占极少数,这个假说是为了解决回收新生代对象时,有老年代对象引用了新生代中对象进行提出的。
    

  1. JVM's practice of generational theory
    In JVM, based on the generational collection theory, according to the survival characteristics of the object, the young generation (Young Generation) and the old generation (Old Generation) are divided, and there is a division of the young generation and the old generation, then Garbage collectors for the young and old generations have also been applied, so there are young generation collections (Minor GC), old generation collections (Major GC), global collections (Full GC), and mixed collections (Mixed GC). .
    Note: Some people regard Major GC as a whole heap collection. This is not wrong. After JDK9, the old-generation collector CMS, the most commonly used server-side virtual machine, no longer supports the supporting new-generation collector. Instead, it is CMS. The default new generation solution ParNew is set, so after JDK9, it is good to say that CMS represents the whole heap collection, but Major GC must not be equated with Full GC.

  2. Classification of collectors according to generational collection theory

    Attach a map here
    Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46897923/article/details/114098243