java & tail recursion

Thorsten Altenkirch <>
5 Apr 2000 22:39:36 -0400

          From comp.compilers

Related articles
java & tail recursion (Thorsten Altenkirch) (2000-04-05)
Re: java & tail recursion (Thomas Johnsson) (2000-04-14)
Re: java & tail recursion (Tim Becker) (2000-04-17)
| List of all articles for this month |

From: Thorsten Altenkirch <>
Newsgroups: comp.compilers
Date: 5 Apr 2000 22:39:36 -0400
Organization: LMU Munich, Theoretical Computer Science
Keywords: Java, optimize, question

Can anybody tell me whether there are any java compilers which do tail
recursion optimisation.
I.e. the following program should not lead to a stack overflow (or
memory error) for large n

public class RecTest {
        static int ct=0;
        static void f(int i) {
                if(i<=0) return;

        public static void main(String [] args) {
                int n=Integer.parseInt(args[0]);

The jdk compiler certainly doesn't optimize. A quick web search on
"java" and "tail recursion" returned a pointer to an old discussion in
comp.compilers with the result that it should be possible.

Dr. Thorsten Altenkirch phone : (+49 89) 2178-2209
Theoretical Computer Science fax : (+49 89) 2178-2238
LMU, D-80538 Munich, Germany Oettingenstr 67, room D105

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.