[PRL] almost tail-calling (was: Re: deeep stack)
Bryan Chadwick
chadwick at ccs.neu.edu
Fri May 23 14:23:56 EDT 2008
-Xmx is Heap size... -Xss is stack...
>% for i in 4 8 16 32; do echo " $i:"; java -Xss${i}M Stack; done
4:
257616
172244
8:
519760
347006
16:
1044048
696532
32:
2092624
1395582
class Stack{
public static void main(String args[]){
System.out.println(" "+depth0()+
"\n "+depth1(1));
}
static int depth0(){
try{ return 1+depth0(); }
catch(Error e){ return 1; }
}
static int depth1(int i){
try{ return depth1(i+1); }
catch(Error e){ return i; }
}
}
> Yes, and of course it's also dependent on system memory; I tried to
> control for this, but discovered that (at least on my OSX 10.4 Java 1.5)
> mac, the -Xmx command-line argument had no effect on this number.
>
> Also, you need look no further than Joshua Zucker's post yesterday on
> plt-scheme to see an example where you want a tail-calling loop to go
> deeper than hundreds of millions.
More information about the PRL
mailing list