News for hackers. Stuff that matters.
Re:Show HN: Tail Recursion Optimization for the JVM by ridiculous_fish on Wednesday April 22, 2020 @10:27PM (#22952291)
JavaScriptCore has probably the best answer for this question, and it's the hilariously-named "Shadow Chicken" mechanism.

JSC's call stack is the C stack, and this stack has real TCO. There is a separate, heap-allocated "shadow" stack which records calls (but not returns). A single recycled C-stack frame may correspond to multiple shadow-stack calls, but between the two, a debugger can recover many tail calls.

It's best effort. The GC may collect frames if it chooses to. Highly optimized code won't touch the shadow stack. etc. But it's good enough for a debugger.

It's named "Shadow Chicken" because it's a shadow stack inspired by CHICKEN scheme, which uses the legendary Cheney-on-the-MTA strategy.

https://trac.webkit.org/changeset/199076/webkit

There are no comments on this comment yet.