编程与软件工程more-magic.net
Chicken Scheme 内部:垃圾回收器
Chicken Scheme internals: the garbage collector
2014 — 2019,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章深入剖析 Chicken Scheme 的垃圾回收器实现,其核心是 'Cheney on the M.T.A.' 技术:把代码转成续延传递风格(CPS),用 C 栈本身作为新生代,栈满时把存活对象复制到堆并通过 longjmp 重置栈。文章配有图解,展示了这套机制如何在 C 之上实现高效的 Scheme 内存管理。
为什么经久不衰:它把一个通常晦涩的 GC 主题讲得清晰透彻,且 Cheney-on-the-MTA 是用 C 实现 Lisp 类语言的经典技巧,对任何想理解语言运行时和内存管理的人都有长期参考价值。
HN 评论精选
用三步概括了 Cheney-on-the-MTA 的核心机制
Cheney-on-the-MTA 是经典。简言之:1) 转换成续延传递风格;2) 把每个续延当普通 C 函数调用,从而用 C 栈充当新生代;3) 栈到达上限时,把所有可达对象复制到堆,通过 longjmp() 跳回栈底'释放'新生代,然后继续执行。
ridiculous_fish查看英文原文
Cheney-on-the-MTA is a classic. tl;dr: 1. Transform into continuation-passing style. 2. Use the C stack as the young generation by calling each continuation as an ordinary C function. 3. When the stack reaches a limit, copy all reachable objects to the heap, "free" the young gen via longjmp() back to the bottom of the stack, and continue on.
推荐了技术源头 Henry Baker 的系列论文
Henry Baker 的 'Cheney on the M.T.A.' 论文(本文所述技术的基础)非常棒。他的研究论文合集里还有不少有趣的东西,比如关于栈上分配的 'CONS should not CONS its arguments'、与线性逻辑相关的 use-once 变量(早在 1993 年就类似 C++ 的 unique_ptr),以及著名的 HAKMEM。
gjm11查看英文原文
Henry Baker's "Cheney on the M.T.A." paper (which is the basis for the stuff described here) is very nice. There's a collection of Baker's research papers here: http://www.pipeline.com/~hbaker1/ which includes the "Cheney on the M.T.A." paper (http://www.pipeline.com/~hbaker1/CheneyMTA.html) and a bunch of other interesting things (mostly with a lispy flavour). A few specific examples: http://www.pipeline.com/~hbaker1/Prag-Parse.html -- a nice technique (not invented by Baker) for simple parsing tasks, and a neat Lisp implementation. http://www.pipeline.com/~hbaker1/LazyAlloc.html -- you might notice that the "M.T.A." paper is subtitled "CONS should not CONS its arguments, part II"; this is the original "CONS should not CONS its arguments" and is also about allocating things on the stack that you might not expect to be stack-allocatable. http://www.pipeline.com/~hbaker1/Use1Var.html -- "use-once" variables (related to "linear logic", which is not Baker's creation), not a million miles from C++'s auto_ptr/unique_ptr but Baker was advocating this stuff as early as 1993. And some other interesting things due to people other than Baker, such as a copy of the famous HAKMEM (http://www.pipeline.com/~hbaker1/hakmem/hakmem.html).
从初学者角度指出 Chicken 文档不如 Racket
我想学一门 Lisp 方言,试了 Chicken 一阵后换到了 Racket。原因是文档:Chicken 的文档常常对应旧版本,我经常卡住;Racket 的文档和指南则非常出色。Chicken 无疑是门很棒的语言,只是对新手不够友好。
apples_oranges查看英文原文
I wanted to learn a LISP-like language and tried Chicken for a bit and then switched to Racket. Reason: Documentation. I constantly got stuck with Chicken, often because the documentation available is for a previous version. No such problems with Racket and their, imho, excellent guide. No doubt Chicken is a great language with cool features, it's just not very beginner friendly.
提醒旧链接失效,附上早年讨论帖
之前的讨论:https://news.ycombinator.com/item?id=7499101 。遗憾的是 pipeline.com 上的链接已经失效,Wayback Machine 也只能打开 Cheney on the MTA 论文的第一页。
snazz查看英文原文
Previous discussion: https://news.ycombinator.com/item?id=7499101 Unfortunately, the pipeline.com links no longer work, and I haven’t been able to coax the Wayback Machine into giving me more than the first page of the Cheney on the MTA paper.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选