Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Sep 2001 03:24:27 +0900
From:      shudo@computer.org
To:        meshko@cs.brandeis.edu
Cc:        shudo@computer.org, java@FreeBSD.ORG
Subject:   Re: offtopic question [Re: Shujit doesn't work with Forte and JDK1.3.1 on FreeBSD]
Message-ID:  <20010922032427U.shudoh@aist.go.jp>
In-Reply-To: <Pine.LNX.4.33.0109211315090.8265-100000@calliope.cs.brandeis.edu>
References:  <20010922021111P.shudoh@aist.go.jp> <Pine.LNX.4.33.0109211315090.8265-100000@calliope.cs.brandeis.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
----Next_Part(Sat_Sep_22_03:24:27_2001_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

From: Mikhail Kruk <meshko@cs.brandeis.edu>

> > Those shuJIT's bugs are very interesting for me. Almost
> > all the bugs are related to synchronization. One of them
> > involves tail recursion elimination (an optimization
> > technique) of a synchronized method.
>
> This is very interesting. Is this a common practice to eliminate tail
> recursion in Java JIT compilers or is it only shujit that does that?

Some JIT compilers including IBM JITC do the tail
recursion elimination.

I attach test programs for the optimization, Base.java
and Extended.java. The Extended class is derived from
the Base class and the two classes have a method named
foo. The foo method call foo(), so the call may be
recursive.

The invocation of foo() in Extened#foo() is always a
tail recursion because the Extended class is a final
class. The invocation of foo() in Base#foo() is not
always a tail recursion because it can be overridden.

Please try and see the results with various JVMs and JIT compilers.

  % java Extended
  % java Base

If tail recursion elimination is performed, the program
does not stop. Otherwise the program produces
StackOverflowError and stops.

The Extended program does not stop with shuJIT, but the
Base program stops. With IBM JDK, both the Extended and
the Base programs do not stop. ShuJIT treats the
Extended#foo() has a tail recursion and IBM JDK treats
both as tail recursion.

Why the IBM JITC can eliminate a tail recursion in Base#foo()...
I need write more and more to explain it endlessly, so now I stop writing.

> In general is it a common optimization in procedural languages like Java,
> C etc?

I'm not sure whether it is common or not in procedural
languages. At least, of course, not so as functional
languages.

  Kazuyuki Shudo

----Next_Part(Sat_Sep_22_03:24:27_2001_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="Base.java"

public class Base {
  public static void main(String args[]) {
    new Base().foo(new Object());
  }

  public Object foo(Object obj) {
    return foo(obj);
  }
}

----Next_Part(Sat_Sep_22_03:24:27_2001_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="Extended.java"

public final class Extended extends Base {
  public static void main(String args[]) {
    new Extended().foo(new Object());
  }

  public Object foo(Object obj) {
    return foo(obj);
  }
}

----Next_Part(Sat_Sep_22_03:24:27_2001_559)----

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010922032427U.shudoh>