Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我的实现 GC 的思路 #5

Open
hackwaly opened this issue Sep 12, 2019 · 0 comments
Open

我的实现 GC 的思路 #5

hackwaly opened this issue Sep 12, 2019 · 0 comments

Comments

@hackwaly
Copy link
Owner

hackwaly commented Sep 12, 2019

1,每个gcref指向的struct的第一个(或-1个)字段,保存类型的metadata,里面有记录struct里哪些字段是gcref,以及他们的位置(最好是挨着放一起,这样记录下开始位置和数量就ok了)。

2,stack 里将 gcref 类型的变量,全部挨着放在一起叫 gcref stack。stack里在最前面保存一个 gcref stack中gcref的数量。gcref stack预留好寄存器里gcref在发生gc时要spill到gcref stack里的位置。

3,不搞 gc 的yield point了。也就是不在函数的进入或者退出的地方、循环的back edge前面等这些地方加判断是否需要 gc。而是通过外部线程暂停需要gc的线程,拿到pc,根据预先记录好的信息,计算出哪些寄存器是gcref,将它们存到栈上预留的gcref stack上。然后扫描stack就简单了。

4,stack 上预留给寄存器gcref的空间,不用每个frame都预留,只需要最里层的frame留就行了。那么这样依赖,gcref stack最好是放在栈顶。并且不要函数内支持动态扩展栈

5,把数据类型分为几大类:是否mutable,是否sendable,是否不可能含循环引用。针对特定的类型进行特定的gc方式。比如说 immutable + cyclic 可以用 traced gc。mutable + non-cyclic 可以用引用计数。mutable + sendable 可以从语言层面上搞成像js里transferable那样的。

6,no-escape的数据可以直接分配在栈里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant