伯姆和标记指针

发布于 2024-10-11 00:28:38 字数 210 浏览 3 评论 0原文

标记指针是实现动态语言时的常见优化:利用对齐要求,这意味着指针的低两位或三位始终为零,并使用它们来存储类型信息。

假设您正在使用 Boehm 垃圾收集器,它的工作原理基本上是通过查看活动数据来查找看起来像指针的东西。标记指针看起来不像指针,因为它们的低位非零。

这是一个令人震惊的问题吗?也就是说,如果您使用 Boehm,您是否必须放弃标记指针?或者它有办法解决这个问题吗?

Tagged pointers are a common optimization when implementing dynamic languages: take advantage of alignment requirements that mean the low two or three bits of a pointer will always be zero, and use them to store type information.

Suppose you're using the Boehm garbage collector, which basically works by looking at active data for things that look like pointers. Tagged pointers don't look like pointers, in the sense that their low bits are nonzero.

Is this a showstopper, i.e. do you have to ditch tagged pointers if you're using Boehm? Or does it have a way around this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三人与歌 2024-10-18 00:28:38

据我所知,伯姆可以通过正确的选择来处理这个问题。它能够以很小的代价检测内部指针。也可以编写自己的扫描代码。基本上,可能有足够的钩子来处理任何事情。

我写了自己的收集器,它在堆上是精确的,在堆栈上是保守的。它不涉及 C 语言的指针。对于某些应用程序来说,它会更快,因为它了解很多关于我的语言分配对象的信息,并且不关心使用传统 C++ 析构函数管理的其他内容。

然而,它不是增量的或分代的,并且它也不能处理线程(它不够智能,无法用信号停止线程)。然而,从好的方面来说,它不需要 Boehm 所做的神奇链接技术(捕获 malloc 等)。严重的缺点是您不能将托管对象放入非托管对象中。

AFAIK Boehm can handle this with the right options. It is capable, at a small price, of detecting interior pointers. It is also possible to write your own scanning code. Basically there are probably enough hooks to handle just about anything.

I have written my own collector, it is precise on the heap and conservative on the stack. It does not touch C made pointers. For some applications it will be faster because it knows a lot about my language allocated objects and doesn't care about other stuff which is managed, say, using traditional C++ destructors.

However it isn't incremental or generational, and it doesn't handle threads as well (it's not smart enough to stop threads with signals). On the plus side, however, it doesn't require magic linkage techniques which Boehm does (to capture mallocs, etc). On the seriously minus side you can't put managed objects into unmanaged ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文