The following file is miscompiled by gcj -C: public class Outer extends Thread { public class Inner extends Thread { private Inner () { start (); } } } It uses the wrong "this" to call start(): Outer$Inner(Outer); Code: 0: aload_0 1: aload_1 2: putfield #12; //Field this$0:LOuter; 5: aload_0 6: invokespecial #15; //Method java/lang/Thread."<init>":()V 9: aload_1 10: invokevirtual #18; //Method java/lang/Thread.start:()V 13: return } Sun's compiler outputs correct code: private Outer$Inner(Outer); Code: 0: aload_0 1: aload_1 2: putfield #1; //Field this$0:LOuter; 5: aload_0 6: invokespecial #2; //Method java/lang/Thread."<init>":()V 9: aload_0 10: invokevirtual #3; //Method start:()V 13: return } The difference is at 9. Note: The bug does not occur if you just replace start() (which is declared in java.lang.Thread) with notify() (which is declared in java.lang.Object).
Confirmed.
The relevant part of the JLS is section 15.12.1 @ http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448
I'm testing a patch.
The patch is tested and is in the gcc patch queue @ http://www.dberlin.org/cgi-bin/patches.py
Another testcase: ------------------------------- 8< ------------------------------- class Snafu { public void whoami( ) { System.out.println( this.getClass( ).getName( )); } } public class PR23230 extends Snafu { class Foo extends Snafu { Foo( ) { whoami( ); } } void bar( ) { new Foo( ); } public static void main( String[] args) { new PR23230( ).bar( ); } } ------------------------------- 8< -------------------------------
*** Bug 23220 has been marked as a duplicate of this bug. ***
Subject: Bug 23230 CVSROOT: /cvs/gcc Module name: gcc Changes by: aph@gcc.gnu.org 2005-08-11 11:49:27 Modified files: gcc/java : ChangeLog java-gimplify.c parse.y Log message: 2005-08-10 Andrew Haley <aph@redhat.com> * java-gimplify.c (java_gimplify_modify_expr): Fix any pointer type mismatches to make legal GIMPLE. 2005-08-10 Robin Green <greenrd@greenrd.org> PR java/23230: * parse.y (maybe_use_access_method): Generalize check from java.lang.Object to any superclass of current_class Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1652&r2=1.1653 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-gimplify.c.diff?cvsroot=gcc&r1=1.20&r2=1.21 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&r1=1.550&r2=1.551
Subject: Bug 23230 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: aph@gcc.gnu.org 2005-08-11 13:03:51 Modified files: gcc/java : ChangeLog parse.y Log message: 2005-08-10 Robin Green <greenrd@greenrd.org> PR java/23230: * parse.y (maybe_use_access_method): Generalize check from java.lang.Object to any superclass of current_class Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1556.2.26&r2=1.1556.2.27 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.528.6.1&r2=1.528.6.2
Fixed in 4.0.2.