Azul的“无休止"的解释垃圾收集器 [英] Explanation of Azul's "pauseless" garbage collector

查看:35
本文介绍了Azul的“无休止"的解释垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚读到这个:

http://www.artima.com/lejava/articles/azul_pauseless_gc.html

虽然我有一些编译器方面的经验,但我没有做过任何与垃圾收集相关的事情;对我来说是一个大黑匣子.

Although I've some experience with compilers, I've done nothing related with garbage collection; is a big black box to me.

我一直在努力理解文章中提到的问题.我理解这个问题(在执行大多数垃圾收集器时会有一个暂停),并且我理解他们声称他们的实现没有这个问题.但我不明白为什么/如何首先发生问题(这似乎被认为在原文中可以理解),因此我不明白为什么他们的解决方案可能有效.

I've struggled to understand the issues mentioned by the article. I understand the problem (there's a pause when executing most garbage collectors), and I understand that they claim that their implementation doesn't have that problem. But I don't understand why/how the problem happens in the first place (that much seems to be assumed to be understood on the original text), and in consequence I don't get why their solution might work.

谁能给我解释一下:

  1. 为什么垃圾收集器通常会有这种停顿
  2. 为什么 Azul 的 gc 没有这个问题?

当以图形方式解释时,我倾向于更好地理解这类事情 - 可能使用代码编辑器完成的小型内存架构就足够了.

I tend to understand this kind of things better when explained graphically - probably a small memory schema done with the code editor would suffice.

谢谢!

推荐答案

他们谈到了在压缩堆时不可避免地发生的暂停.您会看到,当您分配和释放大量不同大小的对象时,您会将堆碎片化(就像您将硬盘碎片化一样).当碎片变得过于极端时,您必须通过保留一大块内存来清理/碎片整理/压缩堆,将所有对象移到那里(没有任何碎片)并将它们以前的位置用作没有任何对象的新内存块,即没有碎片.

They talk about the pause that inevitably occurs when compacting the heap. You see, when you allocate and deallocate lots of objects of different sizes as you go, you fragment the heap (much like you fragment your harddrive). When fragmentation becomes too extreme, you have to clean up/defragment/compact the heap by reserving a huge chunk of memory, moving all objects there (without any fragmentation) and use their former locations as a fresh chunk of memory without any objects in it, i.e. without fragmentation.

当你这样做时,你对你移动的所有对象的所有引用都无效.为了防止这种情况,您必须防止使用引用预压缩对象位置的引用.到目前为止,最简单的方法是暂停整个应用程序,移动对象,然后去更新所有引用.当然,这会产生很大的开销.

When you do that, you invalidate all references to all objects you moved around. To prevent this, you must prevent that a reference that refers to a pre-compaction object location is used. The by far easiest way to do so is to pause the whole application, move the objects around and then go and update all references. Of course this can incur a significant overhead.

所以 Azul 提出的解决方案是这样的:他们建立了一个读取屏障",允许 GC 拦截解引用,这样他们就可以懒惰地更新实际使用的引用.

So the solution Azul proposes goes like this: They establish a "read barrier" that allows the GC to intercept dereferencing, and this way they can lazily update the references that are actually used.

这篇关于Azul的“无休止"的解释垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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