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
这篇关于垃圾优先垃圾收集器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:垃圾优先垃圾收集器如何工作?


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01