May 16th, 2007

tail-call optimization in Java

RSS icon RSS Category: Personal
Fallback Featured Image

Doug Lea wrote:

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

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?
Cliff

Leave a Reply

What are we buying today?

Note: this is a guest blog post by Shrinidhi Narasimhan. It’s 2021 and recommendation engines are

July 5, 2021 - by Rohan Rao
The Emergence of Automated Machine Learning in Industry

This post was originally published by K-Tech, Centre of Excellence for Data Science and AI,

June 30, 2021 - by Parul Pandey
What does it take to win a Kaggle competition? Let’s hear it from the winner himself.

In this series of interviews, I present the stories of established Data Scientists and Kaggle

June 14, 2021 - by Parul Pandey
Snowflake on H2O.ai
H2O Integrates with Snowflake Snowpark/Java UDFs: How to better leverage the Snowflake Data Marketplace and deploy In-Database

One of the goals of machine learning is to find unknown predictive features, even hidden

June 9, 2021 - by Eric Gudgion
Getting the best out of H2O.ai’s academic program

“H2O.ai provides impressively scalable implementations of many of the important machine learning tools in a

May 19, 2021 - by Ana Visneski and Jo-Fai Chow
Regístrese para su prueba gratuita y podrá explorar H2O AI Hybrid Cloud

Recientemente, lanzamos nuestra prueba gratuita de 14 días de H2O AI Hybrid Cloud, lo que

May 17, 2021 - by Ana Visneski and Jo-Fai Chow

Start your 14-day free trial today