How does the Garbage-First Garbage Collector work?(垃圾优先垃圾收集器如何工作?)
问题描述
谁能解释一下 G1 垃圾收集器的工作原理?我还没有在任何地方找到任何全面、易于理解的描述.
Can someone explain how the G1 Garbage Collector works please? I haven't been able to find any comprehensive, easy-to-understand descriptions anywhere yet.
谢谢
推荐答案
收集器将堆分成固定大小的区域并跟踪这些区域中的实时数据.它保留了一组指针——记忆集"——进出该区域.当认为有必要进行 GC 时,它首先收集实时数据较少的区域(因此,垃圾优先").通常,这可能意味着一步收集整个区域:如果指向某个区域的指针数量为零,则不需要对该区域进行标记或扫描.
The collector splits the heap up into fixed-size regions and tracks the live data in those regions. It keeps a set of pointers — the "remembered set" — into and out of the region. When a GC is deemed necessary, it collects the regions with less live data first (hence, "garbage first"). Often, this can mean collecting an entire region in one step: if the number of pointers into a region is zero, then it doesn't need to do a mark or sweep of that region.
对于每个区域,它会跟踪描述收集它们需要多长时间的各种指标.您可以给它一个关于暂停时间的软实时约束,然后它会尝试在该受限时间内尽可能多地收集垃圾.
For each region, it tracks various metrics that describe how long it will take to collect them. You can give it a soft real-time constraint about pause times, and it then tries to collect as much garbage as it can in that constrained time.
有JavaOne谈G1,也有几篇关于这个话题的文章:
There is JavaOne talk about G1 and few articles on the topic:
- http://developers.sun.com/learning/javaoneonline/j1sessn.jsp
- http://www.fasterj.com/articles/G1.shtml
- http://www.drdobbs.com/java/219401061
- http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All
这篇关于垃圾优先垃圾收集器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:垃圾优先垃圾收集器如何工作?


基础教程推荐
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01