New Miscompilation Into Bytecode Error

Ranjit Mathew rmathew@gmail.com
Thu Jul 1 07:49:00 GMT 2004


Hi,

   Today we have a miscompilation into bytecode
error which essentially causes the Jacks testsuite to
hang because the GCJ interpreter hangs on a testcase.

This is the 8.1.2-runtime-1 testcase from Jacks ("Stress
test of accessing a final local variable through two
layers of nested local/anonymous classes"):
---------------------------- 8< ----------------------------
class Hello
{
    public static void main(String[] args) {
        new Hello().foo(1);
    }
    void foo(final int i) {
        class Local {
            Local() {}
            Local(int i) { this(); }
            int foo() {
                return new Local(0) {
                    int j = i;
                }.j;
            }
        }
        System.out.println(new Local().foo());
    }
}
---------------------------- 8< ----------------------------

The expected output of this testcase is "1".

However, a *compiled binary* produces the output "-1073758376"
(and is therefore XFAIL-ed as of now).

The bytecode causes the GCJ interpreter to hang!

With Sun's JDK 1.4.2_03 on Linux/x86, I get:
---------------------------- 8< ----------------------------
~/src/test/tmp > java Hello
Exception in thread "main" java.lang.VerifyError: (class: Hello$1$Local, method: <init> signature: (LHello;II)V) Expecting to find integer on stack
        at Hello.foo(Hello.java:16)
        at Hello.main(Hello.java:4)
---------------------------- 8< ----------------------------

Here's the disassembled output (via "javap -c") of
"Hello$1$Local.class":
---------------------------- 8< ----------------------------
~/src/test/tmp > javap -c Hello\$1\$Local
Compiled from "Hello.java"
class Hello$1$Local extends java.lang.Object{
static Hello access$0(Hello$1$Local);
  Code:
   0:   aload_0
   1:   getfield        #14; //Field this$0:LHello;
   4:   areturn

Hello$1$Local(Hello,int);
  Code:
   0:   aload_0
   1:   aload_1
   2:   putfield        #14; //Field this$0:LHello;
   5:   aload_0
   6:   invokespecial   #24; //Method java/lang/Object."<init>":()V
   9:   aload_0
   10:  iload_2
   11:  invokespecial   #26; //Method finit$:(I)V
   14:  return

Hello$1$Local(Hello,int,int);
  Code:
   0:   aload_0
   1:   aload_1
   2:   putfield        #14; //Field this$0:LHello;
   5:   aload_0
   6:   aload_1
   7:   invokespecial   #29; //Method "<init>":(LHello;I)V
   10:  return

int foo();
  Code:
   0:   new     #33; //class Hello$Local$2
   3:   dup
   4:   aload_0
   5:   iconst_0
   6:   invokespecial   #36; //Method Hello$Local$2."<init>":(LHello$1$Local;I)V
   9:   getfield        #39; //Field Hello$Local$2.j:I
   12:  ireturn

}
---------------------------- 8< ----------------------------

Any ideas?

Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT gmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/



More information about the Java mailing list