垃圾优先垃圾收集器如何工作? [英] How does the Garbage-First Garbage Collector work?

查看:23
本文介绍了垃圾优先垃圾收集器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下 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:

这篇关于垃圾优先垃圾收集器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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