This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New Miscompilation Into Bytecode Error


Ranjit Mathew wrote:
> 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< ----------------------------

One question:

For this testcase, the JDK creates the following class files:

  Hello.class
  Hello$1.class
  Hello$1Local.class

while GCJ creates:

  Hello.class
  Hello$1$Local.class
  Hello$Local$2.class

Is this divergence intentional and/or OK?

As an aside, the JDK produces the following code for the
offending method:
---------------------------- 8< ----------------------------
Hello$1Local(Hello,int,int);
  Code:
   0:   aload_0
   1:   aload_1
   2:   iload_3
   3:   invokespecial   #4; //Method "<init>":(LHello;I)V
   6:   return
---------------------------- 8< ----------------------------

in contrast to the following code produced by GCJ:
---------------------------- 8< ----------------------------
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
---------------------------- 8< ----------------------------

Thanks,
Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT gmail DOT com

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]