[Haskell-cafe] Haskell on JVM

Claus Reinke claus.reinke at talk21.com
Fri Jun 26 11:02:39 EDT 2009

> For example, Clojure lacks proper tail recrusion  optimization due to
> some missing functionality in the JVM. But does anybody know the  
> details?

|Basically, the JVM lacks a native ability to do tail calls. It does  
|not have an instruction to remove/replace a stack frame without 
|executing an actual return to the calling method/function.

There is a conflict between preserving stack layout and efficient
tail calls. Unfortunately, stack inspection appears to be used for
security aspects in JVM. That doesn't make tail calls impossible,
but may have slowed down progress as this argument always
comes up in discussing tail calls on the JVM (since its byte code
isn't just an internal detail, but an externally used API).

None of the various partial workarounds are quite satisfactory
(jumps work only locally, there is an upper size limit on how
much code can be considered as local, trampolines return before 
each call, there are alternatives that clear the stack not before
each call, but every n calls, ..., see the various Haskell to Java/JVM

I was curious about the current state (the issue is as old as JVM),
and here's what I've found so far (more concrete/official info would
be appreciated):

    tail calls in the VM [2007]

    RFE: Tail Call Optimization [2002]


    Tail Call Optimization in the Java HotSpot(TM) VM [2009]

Still cooking, still not done, it seems, but perhaps closer than ever?


More information about the Haskell-Cafe mailing list