JDK 14 record type representation in classfile format?

Remi Forax forax at univ-mlv.fr
Sun Mar 22 15:54:23 UTC 2020


----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Luke Hutchison" <luke.hutch at gmail.com>, "Vicente Romero" <vicente.romero at oracle.com>
> Cc: "amber-dev" <amber-dev at openjdk.java.net>, "compiler-dev" <compiler-dev at openjdk.java.net>
> Envoyé: Dimanche 22 Mars 2020 16:31:17
> Objet: Re: JDK 14 record type representation in classfile format?

> This does not appear to be specific to records at all; javac seems to
> generate an IC attribute whenever you _use_ a nested class.  For example:
> 
> import java.lang.invoke.*;
> public class Foo {
>     MethodHandles.Lookup lookup = null;
> }
> 
> has the following attribute in it:
> 
> InnerClasses:
>   public static final #7= #6 of #20;      // Lookup=class
> java/lang/invoke/MethodHandles$Lookup of class
> java/lang/invoke/MethodHandles


not exactly, here you are declaring lookup as a field.
If lookup is a local variable the attribute InnerClasses is not present.

public class Foo {
  public static void main(String[] args) {
    MethodHandles.Lookup lookup = null;
  }
}

> 
> 
> While this has nothing to do with records, it may still be worth
> discussing whether this attribute is necessary, incorrect, or harmful.
> (Note that Lookup is a _nested_ class of MethodHandles, but not an
> _inner_ one, since it is static.)
> 


Rémi

> 
> On 3/21/2020 7:42 PM, Luke Hutchison wrote:
>> In classes I have looked at in the past, if there is an InnerClasses class
>> attribute, then the listed inner class containment hierarchy always forms a
>> tree rooted at the defining class, and with the tree structure defined by
>> the outer_class_info and inner_class_info entries in the InnerClasses
>> attribute.
>>
>> In this case, the outer_class_info is for MethodHandle, and MethodHandle is
>> not actually an inner class of the record class, so it seems strange that
>> the record class would list MethodHandle$Lookup as an inner class, rather
>> than the MethodHandle class listing MethodHandle$Lookup as an inner class.
>>
>> (I admit I don't understand how bootstrap methods work at the deepest level
> > though, so maybe I'm missing something.)


More information about the compiler-dev mailing list