MinorGC and FullGC triggering conditions

Foreword

Whether it is the daily work, interview or business, we will often come into contact GC. We all know that GC is a garbage collection policy of java. GC help us save a lot of things. In the GC, I often hear belongs MinorGC and FullGC up. So under what circumstances would trigger both GC it?

MinorGC trigger conditions

It will judge the virtual machine before making minorGC old's whether the largest contiguous space available is greater than the new generation of all objects of the total space

    1, if it is larger than the direct execution minorGC

    2, is less than, determines whether to open HandlerPromotionFailure, not open directly FullGC

    3, if turned HanlerPromotionFailure, JVM determines whether the largest contiguous memory space is greater than the previous year old promotion ( promotion years old object average size) size average , is less than the direct execution FullGC

    4, if it is larger than performing minorGC

For HandlerPromotionFailure, we can understand, before it happens Minor GC, virtual opportunity to check old's biggest contiguous memory space is greater than all the objects in the new generation of space, if this condition is met, Minor GC is safe. If you do not set up a virtual opportunity to view HanlerPromotionFailure set value is allowed to act as a failure, if allowed, will continue to check whether old's maximum available contiguous memory space than the previous promotion to the old year target of average size, if more than just attempt Minor GC, if less than or HanlerPromotionFailure risk-averse will conduct a Full GC. Guarantees above like you go to buy a house, go to the bank loans. If your loan amount is relatively large, then the bank will usually require you to provide a guarantor. To put it plainly, the bank is worried enough to pay your monthly loan. Here's the equivalent of your old sponsor. If the monthly income of your sponsor's enough of your monthly payments. That bank certainly will not lend to you. In the jvm it is certainly a direct implementation of Full GC. (Forced some metaphor can be understood that like ..)

FullGC trigger conditions

  • Old's lack of space

     If you create a large object, Eden area which does not fit this large object, it will directly save them years old, years old if space is insufficient, it will trigger Full GC. To avoid this, the best idea is not to create too much of an object.

  • Persistent lack of space on behalf of

    If there is permanent generation space, then among the system needs to load the class, calling many ways, while among the permanent generation is not enough space, then the trigger a Full GC

  • YGC appear promotion failure

    promotion failure occurred in the Young GC, if Survivor areas which survived to the age reached a set value, which will be copied to the target area of ​​the Survivor's old, old age if space is insufficient, there will be promotion failure occurs, it is next Full GC occurs.

  • Promoted to average total size of the old age and old age is greater than the free space occurs when Statistics YGC

      In the event of YGC will determine whether safety, security here means that the current space can accommodate YGC old's promotion of the average size of the object, if not safe, they will not perform YGC, executed instead FullGC.

  • Display call System.gc

Here we call System.gc not necessarily immediately triggered FullGC

to sum up

Here a brief summary of the trigger conditions MinorGC and FullGC of. The JVM to facilitate better understanding of the GC.

Original link: https://blog.csdn.net/summerZBH123/article/details/81131945

Guess you like

Origin www.cnblogs.com/leeego-123/p/11298342.html