Related articles |
---|
java & tail recursion alti@tcs.informatik.uni-muenchen.de (Thorsten Altenkirch) (2000-04-05) |
Re: java & tail recursion johnsson@spitfire.crt.se (Thomas Johnsson) (2000-04-14) |
Re: java & tail recursion tbecker@pironet.com (Tim Becker) (2000-04-17) |
From: | Thorsten Altenkirch <alti@tcs.informatik.uni-muenchen.de> |
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) {
ct++;
if(i<=0) return;
f(i-1);
}
public static void main(String [] args) {
int n=Integer.parseInt(args[0]);
f(n);
System.out.println(ct);
}
}
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
http://www.tcs.informatik.uni-muenchen.de/~alti
Return to the
comp.compilers page.
Search the
comp.compilers archives again.