JDK-8230501: Class data support for hidden classes

Mandy Chung mandy.chung at oracle.com
Fri Nov 13 19:12:11 UTC 2020



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


More information about the valhalla-dev mailing list