JDK-8230501: Class data support for hidden classes

forax at univ-mlv.fr forax at univ-mlv.fr
Fri Nov 13 20:32:50 UTC 2020


> De: "mandy chung" <mandy.chung at oracle.com>
> À: "John Rose" <john.r.rose at oracle.com>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "valhalla-dev"
> <valhalla-dev at openjdk.java.net>
> Envoyé: Vendredi 13 Novembre 2020 20:12:11
> Objet: Re: JDK-8230501: Class data support for hidden classes

> On 11/11/20 3:28 PM, Mandy Chung wrote:

>> I do think the index-based convention with the specified type is right. What I
>> wasn't fully happy with `classDataAt` is why supporting List but not an array
>> or Map. We don't (and probably shouldn't) enforce the class data be an
>> immutable list and map. `classDataAt` taking a (frozen) array may probably be
>> more satisfying option although it's the user's error if they mutate the class
>> data.

> Talking with Paul, he inspires to take the `List<?> classData` argument that we
> always copy it to an unmodifable List. (It would be nice if this method can
> take a varargs of live objects but the options argument is already a varargs).
> This guarantees that the class data is immutable and can be trusted.
No, the list will be unmodifiable not immutable, a List<Date> is a valid argument but is not immutable because you can change the content of the each date whenever you want. 
Java only provides shallow unmodifiability not true immutability. 

Also, List.copyOf() doesn't allow null as element. 

And, it will also makes classData() pretty useless as a BSM of a condy. 

> So `classDataAt` returns an element from an unmodifable list.

> public Lookup defineHiddenClassWithClassData(byte[] bytes, List<?> classData,
> boolean initialize, ClassOption... options);

> public static <T> List<T> classData(Lookup caller, String name, Class<T> type)
> throws IllegalAccessException

> public static <T> T classDataAt(Lookup caller, String name, Class<T> type, int
> index)
> throws IllegalAccessException

> Otherwise, if a class data can be modifiable, we would warn the developers to do
> the right thing.

> I like making `classData` argument as a List<?>. Feedback?

> Mandy

Rémi 


More information about the valhalla-dev mailing list