Related articles |
---|
Java Compilers and Tail Recursion jkarney@netgenics.com (Jason Karney) (1997-12-23) |
Re: Java Compilers and Tail Recursion markt@harlequin.co.uk (Mark Tillotson) (1997-12-29) |
Re: Java Compilers and Tail Recursion sborde@microsoft.com (Shri Borde) (1998-01-03) |
Re: Java Compilers and Tail Recursion chase@world.std.com (David Chase) (1998-01-03) |
From: | Mark Tillotson <markt@harlequin.co.uk> |
Newsgroups: | comp.lang.java.machine,comp.compilers |
Date: | 29 Dec 1997 21:04:17 -0500 |
Organization: | Harlequin Ltd, Longstanton House, Cambridge UK |
References: | 97-12-163 |
Keywords: | Java, optimize |
Jason Karney <jkarney@netgenics.com> asked:
| Is the current crop of Java compilers smart enough to optimize tail
| recursion? I am specifically wondering about Symantec and Sun's JDK
| compilers.
Tail-recursion elimination is prohibited by the implementation of the
Java SecurityMangler. See definitions of getClassContext(),
classDepth(), inClass(), classLoaderDepth() etc. (section 20.17.* in
the language spec)
So the answer is you can't do it _and_ support the ClassLoader/
SecurityManager protocol. This is (in my opinion) because that
protocol is an inelegant hack.
It would not be at all difficult to do the elimination, it doesn't
even need a compiler to do it either, an interpreter can just check
for a suitable return bytecode after an invoke opcode (and you have to
check for being in a synchronized method too). It's a simple peephole
optimization, because the method-invocation and return byte codes are
at a high-enough level.
__Mark
[ markt@harlequin.co.uk | http://www.harlequin.co.uk/ | +44(0)1954 785433 ]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.