JDK 14 record type representation in classfile format?

Remi Forax forax at univ-mlv.fr
Sun Mar 22 16:06:00 UTC 2020


To me, it seems to be needed for the separate compilation,
when javac reads the type of a class members that contains a '$', it has no idea if it's an inner class or not,
the attributes InnerClasses is there to disambiguate.

If i'm right,
this attributes is not needed in records equals/hashCode/toString or when doing a string concat because in both cases, those operations are inside the bytecode.

Rémi

----- Mail original -----
> De: "Remi Forax" <forax at univ-mlv.fr>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-dev" <amber-dev at openjdk.java.net>, "compiler-dev" <compiler-dev at openjdk.java.net>, "Luke Hutchison"
> <luke.hutch at gmail.com>
> Envoyé: Dimanche 22 Mars 2020 16:54:23
> Objet: Re: JDK 14 record type representation in classfile format?

> ----- 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