Java GC中的压缩是什么? [英] What is a compaction in Java GC?

查看:109
本文介绍了Java GC中的压缩是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 http://www.cubrid.org/blog/tags/Garbage %20Collection/文章提供了Java中GC的高级介绍.它说:

I read http://www.cubrid.org/blog/tags/Garbage%20Collection/ article which gives high level picture of GC in Java. It says:

压缩任务是通过压缩内存来消除内存碎片,以便删除分配的内存区域之间的空白空间..

是否应将对象移至其他位置以填充孔?

Should objects be moved into anther places in order to fill holes?

我认为对象已移动.如果是这样,则意味着地址已更改,因此也应更新对该对象的引用?

I think that objects are moved. If so that mean addresses are changed and so reference to that object also should be updated?

要查找所有反向参考并更新它们似乎太复杂了...

It seems too complicated task to find all back reference and update them...

推荐答案

是的,任意对象在内存中任意移动,是的,这需要更新对这些对象的引用.一个人也可以使用间接方式,但是它具有各种缺点,而且我不知道有任何高性能的GC在这样做.

Yes, arbitrary objects are moved arbitrarily through memory, and yes this requires updating the references to those objects. One could also use indirection but that has various downsides and I'm not aware of any high performance GC doing it.

确实有些复杂,但是就GC优化而言,它是相当不错的.基本的 mark-compact 效果很好,它基本上只是按地址顺序遍历所有对象,将它们移动到最小的可用地址,并随即构建一个中断表",其中包含必要的信息(起始地址->位移),用于快速固定引用,然后在第二遍中进行处理.这些都不要求任何信息或簿记,而无需任何标记清除收集器已经需要的信息(对象类型,引用的位置等).

It's indeed somewhat complicated, but as far as GC optimizations go it's rather benign. Basic mark-compact works rather well and it basically just goes over all objects in address order, moves them to the smallest available address, and builds a "break table" as it goes which contains the necessary information (start address -> displacement) for quickly fixing up references, which it then does in a second pass. None of this requires information or bookkeeping beyond what any mark-sweep collector already needs (object types, locations of references, etc).

当您按代际设置将对象移出苗圃时,您也(大致)知道旧参考的位置.您需要知道这一点才能进行次要收藏.

And when you move objects out of the nursery in a generational setting, you also know (roughly) where the old references are. You needed to know that to do a minor collection.

这篇关于Java GC中的压缩是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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