enhanced-metadata-spec-discuss Digest, Vol 12, Issue 4

Jesper Steen Møller jesper at selskabet.org
Tue Sep 3 15:38:58 PDT 2013


Hi Alex, Srikanth

Question is inline, below:

On 26/08/2013, at 22.07, Alex Buckley wrote:

> Hi Srikanth,
> 
> Many thanks for trying out javac in the JDK 8 builds. Answers below.
> 
> On 8/26/2013 11:56 AM, Srikanth S Adayapalam wrote:
>> 
>> 8b100's behavior is confusing on the following code:
>> 
>> // --
>> public class X {
>>     void foo() {
>>         new Y().new Z() {
>>         };
>>     }
>> }
>> class Y {
>>     class Z {}
>> }
>> // --
>> 
>>   final X this$0;
>>     descriptor: LX;
>>     flags: ACC_FINAL, ACC_SYNTHETIC
>> 
>>   X$1(X, Y);
>>     descriptor: (LX;LY;)V
>>     flags:
>>     Code:
>>       stack=3, locals=3, args_size=3
>>          0: aload_0
>>          1: aload_1
>>          2: putfield      #1                  // Field this$0:LX;
>>          5: aload_0
>>          6: aload_2
>>          7: dup
>>          8: invokevirtual #2                  // Method
>> java/lang/Object.getClas
>> s:()Ljava/lang/Class;
>>         11: pop
>>         12: invokespecial #3                  // Method
>> Y$Z."<init>":(LY;)V
>>         15: return
>>       LineNumberTable:
>>         line 3: 0
>>     MethodParameters:
>>       Name                           Flags
>>       this$0                         final mandated
>>       x0
>> 
>> Why would the anonymous class's own enclosing instances be mandated
>> while "x0" which I presume is the super classes enclosing instance
>> be flag less ?
> 
> There seem to be two javac (or maybe javap) bugs here:
> 
> - The this$0 field and the this$0 formal parameter which supplies it are concerned with the immediately enclosing instance of the anonymous class's instance. Transmitting this instance to the anonymous class's instance is covered by point 2 in 8.8.9. Basically, it's not specified. As such, the this$0 field has been ACC_SYNTHETIC since forever, and that's a big hint that the this$0 formal parameter should be ACC_SYNTHETIC too.
> 
> - The x0 formal parameter is implicitly declared by 15.9.5.1 as having type Y, because the direct superclass Z of the anonymous class is inner. So, x0 should be flagged and displayed as mandated.
> 
> Alex


According to 8.8.9 (3) and 15.9.5.1(second bullet), x0 would have to an INITIAL / "the first" implicitly declared argument, so shouldn't javac also change the order of this$0 and x0 (even if the sole purpose of doing so is to provide it to Y$Z(Y) constructor).

But the thing I don't understand is why the spec bothers with specifying implicitly declared parameters for constructors for constructors of anonymous constructors when they generally fall into the category of 8.8.9 (2). Why can't the compiler simply take the synthetic x0 argument and use it as (the mandated) constructor for Z, which may indeed be supplied by a different compiler. Doing that shouldn't make x0 mandated, since no other compiler may emit a call to the X$1(X, Y) constructor.

In short, I don't see any practical need for 8.8.9 (3) -- did I miss something crucial?

-Jesper



More information about the enhanced-metadata-spec-discuss mailing list