何时触发完全GC [英] When is a Full GC triggered

查看:88
本文介绍了何时触发完全GC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解

次要GC

发生在年轻一代中的GC通常称为次要(Minor),因为完成活动所需的时间通常很少,因此完成时间较少(我说的是典型的Java应用程序,考虑到它的弱点).世代假设)和一个复制收集器,该复制收集器具有较少数量的要重定位和重映射的对象.

a GC that happens in the young gen is usually called Minor because it takes less time to complete as the live-set will be usually small (i'm talking about typical java application considering the weak generational hypothesis) and a copying collector with less number of objects to relocate and remap.

主要GC

在旧一代中发生的GC通常被称为专业GC,因为完成直播所需的时间要长得多(与年轻一代相比),所以它需要花费更多的时间才能完成,因此通常会压缩旧版本.一代和紧实的时间随着老一代的大小线性增加.

a GC that occurs in the old gen is usually called Major GC because it takes more time to complete as live-set will be mostly big (compared to young gen) and it usually compacts the old gen and the time for compaction increases linearly with the old generation size.

不幸的是,GC日志将旧的收集报告为完全GC,而仅收集了旧的收集.但是在Java内存管理白皮书中,有一个完整GC的概念,其中收集了整个堆.

Unfortunately the GC logs report the old generation collection as Full GC while its only the Old generation that's being collected. But in java memory management white paper there's a notion of Full GC in which the entire heap is collected.

A Full GC will be triggered whenever the heap fills up. In such a case the 
young generation is collected first followed by the old generation. If the 
old generation is too full to accept the content of the young generation,
the young generation GC is omitted and the old generation GC is used to 
collect the full heap, either in parallel or serial. Either way the whole 
heap is collected with a stop-the-world event.

如果年轻一代填满时总是有次要GC,而老一代填满时总是有Major GC,那么什么时候会发生所谓的Full GC?如果年轻一代和老一代的收藏家都在尽自己的一份力量,堆怎么变得满满的?

If there's always a Minor GC when the young gen fills up and if there's always a Major GC when the old gen fills up, when will this so called Full GC happen ? How come the heap becomes full if both the young gen and old gen collectors are doing their part ?

感谢您的时间:)

推荐答案

区域大小发生变化时,就会出现一个年轻一代和老一代都被收集的完整GC.

A Full GC where in both the young and old generations are collected occurs when there's change in region size.

例如,如果我们提到

-Xms1024m -Xmx2048m -XX:PermSize=512m -XX:MaxPermSize=1024m

JVM最初以1GB的堆开始,但从OS保留2GB的空间.因此,随着这些区域的使用量增加,基于VM的人体工程学,将调整年轻人和老年人的大小,直到达到最大保留大小2GB.

JVM initially starts with 1GB of heap but reserves space for 2GB from OS. So as the usage of these regions increases, based on VM ergonomics, Young and old generations are resized until they reach the max reserved size of 2GB.

同样的事情也适用于PermSize,每次PermGen调整大小时,都会出现完整的GC.

Same thing applies for PermSize as well, every time PermGen resizes, a full GC will occur.

这篇关于何时触发完全GC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆