May 16th, 2007

tail-call optimization in Java

Category: Personal
Fallback Featured Image

Doug Lea wrote:

Hi Cliff,
Could you remind us why Java doesn’t allow tail-recursion optimization?

Heh – all things allow “as if” optimizations, ‘cause how you gonna know?     😉
Java likes to hand out decent stack traces, but these are specifically not language designed or required – but in practice decent stack traces ARE required as a primary debugging tool.
You might be able to do tail-RECURSION optimization “as if” with counters somehow.
You might have more trouble doing tail-CALL optimization with counters – and that might mess with the usual Java security model – all things below a security call can get priviledges – which in practice means a stack-crawl the state of the stack around the security call being “known” to the VM (and to the compiler for optimizations).
So: do-able I believe, with some work to keep the security stuff functional & fast.  Stack-traces for recursion are probably OK truncated (since primary usage is debugging, and no language spec requirement).  Stack-traces for tail-calls get chopped is more problematic.  I’m open to suggestions here (maintain a fake 2nd lower-cost stack ?   append frame “tokens” into a buffer ?   )
Any Java language experts Out There want to chime in here?

Leave a Reply

The Making of H2O Driverless AI – Automatic Machine Learning

It is my pleasure to share with you some never before exposed nuggets and insights

December 5, 2018 - by Arno Candel
Gratitude and thank you, makers!

Makers, Happy Thanksgiving - Hope you get to spend time with your loved ones this week. Thank them

November 21, 2018 - by Saurabh Kumar
New features in H2O 3.22

Xia Release (H2O 3.22) There's a new major release of H2O and it's packed with new

November 12, 2018 - by Jo-Fai Chow
Top 5 things you should know about H2O AI World London

We had a blast at H2O AI World London last week! With a record number

November 6, 2018 - by Bruna Smith
Fallback Featured Image
Anomaly Detection with Isolation Forests using H2O

Introduction Anomaly detection is a common data science problem where the goal is to identify odd

November 6, 2018 - by angela
Fallback Featured Image
Launching the Academic Program … OR … What Made My First Four Weeks at so Special!

We just launched the Academic Program at our sold-out H2O AI World London. With

October 30, 2018 - by Conrad

Join the AI Revolution

Subscribe, read the documentation, download or contact us.

Subscribe to the Newsletter

Start Your 21-Day Free Trial Today

Get It Now
Desktop img