保守的垃圾收集器 [英] Conservative garbage collector

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

问题描述

我已经看到垃圾收集器被标记为很多东西 - 代人等等。但是我看到Boehm GC标记为保守。这意味着什么?

解决方案

垃圾回收器必须扫描所有对象和调用(执行堆栈)以识别所有实时地址,然后收集没有实时地址的对象。在某些环境中,GC算法可能是精确的,并且确切知道什么是对象地址,什么不对。在其他环境中,它必须扫描部分存储(最着名的是执行堆栈),其中有可能是对象地址的存储字,并且假设CONSERVATIVE假设它看起来像一个有效地址,并且存在一个对象地址,那么不应该收集对象。



保守收集有很多优点,最值得注意的是代码生成器(如果没有解释)更容易分配变量,当它需要它们时,它不需要严格追踪哪些是对象指针。 (跟踪对象指针位置的需求可能会导致优化程度较低的代码,此外还会使代码生成器变得相当复杂。另外,保守的收集器有一些合理的机会,可用于从未打算支持的编译器垃圾收集,而精确的收集器会要求编译器彻底改变。)

保守方法的主要缺点是完全复制收集器不能实现。复制完成后,必须更新指向复制对象的指针,并且如果不清楚给定位值是否为对象指针或仅是数值,则无法安全地确定该对象是否应该被修改复制。还有一个缺点是,由于随机位模式看起来像他们的地址,一些死的对象可能最终不会被收集,尽管在实践中这不是一个严重的问题。


I've seen garbage collectors labelled as a lot of things- generational, etc. But I've seen the Boehm GC labelled as "conservative". What exactly does that mean?

解决方案

A garbage collector must scan all objects and invocations (execution stack) to identify all of the "live" addresses in the executing program and then "collect" objects that do not have "live" addresses. In some environments it's possible for the GC algorithm to be PRECISE and know exactly what is an object address and what is not. In other environments it must scan parts of storage (most notably the execution stack) where there are words of storage that MIGHT be an object address and make the CONSERVATIVE assumption that if it looks like a valid address, and there is an object that has that address, then the object should not be collected.

There are advantages to conservative collection, most notably that the code generator (if not interpreted) is freer to allocate variables where and when it needs them and it need not keep rigorous track of which are object pointers. (The need to keep track of object pointer locations can lead to less well optimized code, in addition to making the code generator considerably more complex. Also, a conservative collector stands some reasonable chance of being used with a compiler which was never intended to support garbage collection, while a precise collector would require that the compiler be radically altered.)

The major disadvantage of the conservative approach is that a full "copying" collector cannot be implemented. When copying is done the pointers to the copied objects must be updated, and if it's not clear whether a given bit value is an object pointer or just a numeric value, it cannot be safely determined whether or not it should be modified when the object is copied. There's also the disadvantage that some "dead" objects may end up not getting collected, due to random bit patterns that look like their addresses, though in practice this is not a serious concern.

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

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