记住在G1算法中设置的内容是什么? [英] What is remembered set in G1 algorithms used for?

查看:221
本文介绍了记住在G1算法中设置的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚读了一些有关G1算法的博客.

I just read some blogs about G1 algorithm.

我对使用记忆集的方法感到困惑.

The usage of remembered-set is confused to me.

这是我的想法:

由于我们可以使用DFS遍历GC-Roots中的每个引用,所以为什么需要记忆集?

Since we can use DFS to walk through every reference from GC-Roots, why do we need remembered-set?

使所有博客都说我们使用记住集"的原因是,我们不需要检查每个区域来查看是否存在GC-Roots引用的对象

Cause all the blogs to say the reason why we use remembered-set is we don't need to check every region to see if there is an object that is referenced by GC-Roots

推荐答案

您需要先了解Card Table是什么,IMO.如果存在从old generationyoung的引用,如何扫描仅 young generation区域并清理它?您需要精确地跟踪"这些连接所在的位置-因此在扫描young generation时,您可以清理它而不会破坏堆.

You need to understand what Card Table is first, IMO. How do you scan only young generation region and clean it, if there are references from old generation back to young? You need to "track" exactly where these connections are present - so while scanning young generation you could clean it without breaking the heap.

考虑一下:如果存在引用对象B,则无法标记要删除的对象A.但请记住,现在-您只属于年轻收藏 .因此,要跟踪这些连接",将实现Card Table.这张卡片表中的每一位都说,老一代的某个部分是脏的",这意味着在扫描年轻一代的同时也要扫描老一代的那部分.

Think about it: you can't mark for removal an Object A that it is in young generation now, if there is a reference B to it, from old generation. But remember that right now - you are in the young collection only. So to track these "connections" a Card Table is implemented. Each bit from this card table says that a certain portion of the old generation is "dirty", meaning also scan that portion from the old generation while scanning young.

您为什么需要那个?扫描年轻对象的全部目的是扫描一小部分堆,而不是全部.此card table实现了这一目标.

Why do you need that? The entire point of scanning young is to scan a little piece of the heap, not all. This card table achieves that.

G1具有区域.如果您正在扫描regionA并发现它具有指向其他regionB的指针怎么办?仅将这些信息放在Card Table中是不够的.您的卡表只会知道regionA,而下次扫描regionB时-您又如何知道也应该扫描regionA?如果不这样做,很显然堆完整性会被破坏.

G1 has regions. What if you are scanning regionA and you see that it has pointers to some other regionB? Simply putting this information in the Card Table is not enough. Your card table will only know about regionA, and next time you scan regionB - how do you know you are supposed to scan regionA also? If you don't do that, obviously the heap integrity is broken.

因此:remembered sets.这些集合由异步线程填充:它扫描card table,并根据该信息还扫描这些脏"区域的指针指向何处.它跟踪该regionA -> regionB连接.每个区域都有自己的remembered set.

As such : remembered sets. These sets are populated by an asynchronous thread: it scans the card table and according to that information it also scans where these "dirty" regions have pointers to. It keeps track of that regionA -> regionB connection. Each region has it's own remembered set.

因此,当您到达需要发生GC的地步时,在扫描regionB时也要查看它的remembered set并发现您还需要扫描regionA.

So when you reach the point that GC needs to happen, when scanning regionB you also look at it's remembered set and find out that you also need to scan regionA.

在实践中,这就是G1世代相传的原因:这些remembered sets事实证明是巨大.如果将堆划分为youngold,则无需保留年轻代之间的连接,无论如何都可以一次扫描它们,从而减少了这些集合的消耗. G1希望保留200ms(默认)承诺-为此,您需要一次扫描年轻一代 (因为remembered sets中的区域之间没有连接,否则会堆积完整性已消失),但同时如果您使年轻一代变小-remembered sets的大小将很大.

In practice, this is why G1 became generational : these remembered sets turned out to be huge. If you divide the heap in young and old, there is no need to keep the connections between young generations, you scan them all at once anyway, thus taking away the burned on the size of these sets. G1 wants to keep that 200ms (default) promise - to do that, you need to scan young generation all at once (because there is no connection between regions in remembered sets and otherwise heap integrity is gone), but at the same time if you make young generation small - the size of remembered sets will be big.

因此,触摸这些设置是工程奇迹,恕我直言.

As such, touching these settings is an engineering miracle, IMHO.

这篇关于记住在G1算法中设置的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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