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

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

问题描述

有人可以解释一下G1垃圾收集器的工作原理吗?我无法在任何地方找到任何全面的,易于理解的说明。



谢谢

解决方案

收集器将堆分成固定大小的区域并跟踪这些区域中的实时数据。它保留了一组指针 - 记住的集合 - 进出该区域。当GC被认为是必要的时候,它首先收集数据量较少的地区(因此,垃圾优先)。通常,这可能意味着一步收集整个区域:如果指向一个区域的指针数量为零,则不需要对该区域进行标记或扫描。



对于每个地区,它都会跟踪描述收集这些地区需要多长时间的各种指标。你可以给它一个关于暂停时间的软实时约束,然后它会尽量收集尽可能多的垃圾。



有JavaOne谈话关于该主题的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.

Thanks

解决方案

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.

There is JavaOne talk about G1 and few articles on the topic:

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

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