一句话:提出 Refgraph GC,跨 FFI 回收两个托管语言间的循环垃圾,且只需修改一方运行时。
跨托管语言的 FFI 日益常见,但用户级库实现的 FFI 无法回收跨语言边界的循环垃圾,即一组通过循环引用相互持有的对象。本文提出 Refgraph GC,通过协调两种语言的垃圾收集器来回收此类循环垃圾;它只需修改其中一种语言的托管运行时,而无需修改另一种语言。文章论证了该算法的可靠性与完备性,并实现了一个让 Ruby 程序访问 JavaScript 库的 FFI 进行实验。实验展示了该方案在实际 FFI 中跨语言回收循环垃圾的可行性,并对双方运行时保持最小侵入。
A growing number of libraries written in managed languages, such as Python and JavaScript, are bringing about new demand for a foreign language interface (FFI) between two managed languages. Such an FFI allows a host-language program to seamlessly call a library function written in a foreign language and exchange objects. It is often implemented by a user-level library but such implementation cannot reclaim cyclic garbage, or a group of objects with circular references, across the language boundary. This paper proposes Refgraph GC , which enables FFI implementation that can reclaim cyclic garbage. Refgraph GC coordinates the garbage collectors of two languages and it needs to modify the managed runtime of one language only. It does not modify that of the other language. This paper discusses the soundness and completeness of the proposed algorithm and also shows the results of the experiments with our implementation of FFI with Refgraph GC. This FFI allows a Ruby program to access a JavaScript library.
@article{paperbot2013,
title = {Collecting Cyclic Garbage across Foreign Function Interfaces: Who Takes the Last Piece of Cake?},
author = {Tetsuro Yamazaki and Tomoki Nakamaru and Ryota Shioya and Tomoharu Ugawa and Shigeru Chiba},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {PLDI},
year = {2023},
doi = {10.1145/3591244}
}