From owner-freebsd-java Fri Sep 21 11:23:26 2001 Delivered-To: freebsd-java@freebsd.org Received: from mx1.aist.go.jp (mx1.aist.go.jp [150.29.246.133]) by hub.freebsd.org (Postfix) with ESMTP id D961B37B42B for ; Fri, 21 Sep 2001 11:23:19 -0700 (PDT) Received: from rpsmtp1.aist.go.jp by mx1.aist.go.jp with ESMTP id f8LIMvN27065; Sat, 22 Sep 2001 03:22:57 +0900 (JST) env-from (k.shudou@aist.go.jp) Received: from mail11.aist.go.jp by rpsmtp1.aist.go.jp with ESMTP id f8LIMuA20754; Sat, 22 Sep 2001 03:22:56 +0900 (JST) env-from (k.shudou@aist.go.jp) Received: from localhost by mail11.aist.go.jp with ESMTP id f8LIMtx20219; Sat, 22 Sep 2001 03:22:55 +0900 (JST) env-from (k.shudou@aist.go.jp) 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] From: shudo@computer.org In-Reply-To: References: <20010922021111P.shudoh@aist.go.jp> X-Mailer: Mew version 1.94.2 on XEmacs 21.1 (Cuyahoga Valley) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Sep_22_03:24:27_2001_559)--" Content-Transfer-Encoding: 7bit Message-Id: <20010922032427U.shudoh@aist.go.jp> Date: Sat, 22 Sep 2001 03:24:27 +0900 X-Dispatcher: imput version 20000228(IM140) Lines: 86 Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org ----Next_Part(Sat_Sep_22_03:24:27_2001_559)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Mikhail Kruk > > 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