Re: Proper Tail Recursive Java (no more C++)

mw@ipx2.rz.uni-mannheim.de (Marc Wachowitz)
23 Mar 1997 23:24:04 -0500

          From comp.compilers

Related articles
Re: Proper Tail Recursive C++ erik.schnetter@student.uni-tuebingen.de (1997-03-21)
Re: Proper Tail Recursive Java (no more C++) mw@ipx2.rz.uni-mannheim.de (1997-03-23)
| List of all articles for this month |

From: mw@ipx2.rz.uni-mannheim.de (Marc Wachowitz)
Newsgroups: comp.compilers
Date: 23 Mar 1997 23:24:04 -0500
Organization: ---
References: 97-03-129
Keywords: Java

Here's another case where looking up the specification is far superior
to guessing. The topic does even have its own entry in the TOC of the
Java Language Specification; below is the relevant part, quoted from
http://www.javasoft.com/doc/language_specification/15.doc.html#239532


[quote]


        15.11.4.6 Implementation Note: Combining Frames


      In order to allow certain kinds of code optimization, implementations
      are permitted some freedom to combine activation frames. Suppose that
      a method invocation within class C is to invoke a method m within
      class S. Then the current activation frame may be used to provide
      space for S instead of creating a new activation frame only if one of
      the following conditions is true:


          * Class C and class S have the same class loader (pp 20.14) and class
              S is not SecurityManager or a subclass of SecurityManager.
          * Class S has no class loader (this fact indicates that it is a
              system class); class S is not SecurityManager or a subclass of
              SecurityManager; and method m is known not to call, directly or
              indirectly, any method of SecurityManager (pp 20.17) or any of its
              subclasses.


[end of quote]


For many - probably most - situations were tail recursion elimination
is important, I'd expect that a compiler can recognize the above
condition with reasonable effort. (One could also add some runtime
support to find out about a non-predicted callee, but for typical
programming style in the Java community, I doubt that the decrease in
used space would often be worth the increase in time for this
additional effort. At least, such a heuristic optimization should
remain optional.)


It's really somewhat ironic that a considerable majority of the
guesses (and often false views) about Java posted on various
newsgroups could easily be avoided by merely reading the documentation
published on the WWW, given that Java's popularity is largely due to
using it for the WWW ;-)


-- Marc Wachowitz <mw@ipx2.rz.uni-mannheim.de>
--


Post a followup to this message

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