Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://www.ibm.com/developerworks/java/library/j-diag8.html" rel="noreferrer">Diagnosing Java Code: Improving the Performance of Your Java Code</a> (<a href="http://web.archive.org/web/20120506085636/http://www.ibm.com/developerworks/java/library/j-diag8/index.html" rel="noreferrer">alt</a>) explains why the JVM does not support tail-call optimization.</p> <blockquote> <p>But although it is well known how to automatically transform a tail-recursive function into a simple loop, the Java specification doesn't require that this transformation be made. Presumably, one reason it is not a requirement is that, in general, the transformation can't be made statically in an object-oriented language. Instead, the transformation from tail-recursive function to simple loop must be done dynamically by a JIT compiler. </p> </blockquote> <p>It then gives an example of Java code that won't transform.</p> <blockquote> <p>So, as the example in Listing 3 shows, we cannot expect static compilers to perform transformation of tail recursion on Java code while preserving the semantics of the language. Instead, we must rely on dynamic compilation by the JIT. Depending on the JVM, the JIT may or may not do this.</p> </blockquote> <p>Then it gives a test you can use to figure out if your JIT does this.</p> <p>Naturally, since this is an IBM paper, it includes a plug:</p> <blockquote> <p>I ran this program with a couple of the Java SDKs, and the results were surprising. Running on Sun's Hotspot JVM for version 1.3 reveals that Hotspot doesn't perform the transformation. At default settings, the stack space is exhausted in less than a second on my machine. On the other hand, IBM's JVM for version 1.3 purrs along without a problem, indicating that it does transform the code in this way.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload