-
Enhancement
-
Resolution: Duplicate
-
P3
-
12
As discussed in JDK-8171335:
The goal is to allow initialization of a conceptual single private static final field for the new class prior to execution of <clinit>, which is unnamed. The type of the conceptual field is java.lang.Object, so it can contain any Object instance.
There is NO constant pool which represents this field, so no way to directly access it via bytecodes or reflection, MethodHandles, VarHandles, etc. This field will not be represented in the ConstantValue attributes.
A <clinit> or any other method in the new class or in a nestmate can read this value only via Lookup.findclassData(), so via a condy BSM. There is no way to write this field, even via SetAccessible().
Eg. from an email from John
here is an example BSM:
public static <T> T classData(Lookup lookup, String ignore, Class<T> type) {
Object cd = lookup.findClassData(lookup.lookupClass());
return type.cast(cd);
}
Note: the Lookup here is created for the condy and is a Lookup for the class which is calling the BSM, i.e. the newly defined class, not the creator of the class.
The goal is to allow initialization of a conceptual single private static final field for the new class prior to execution of <clinit>, which is unnamed. The type of the conceptual field is java.lang.Object, so it can contain any Object instance.
There is NO constant pool which represents this field, so no way to directly access it via bytecodes or reflection, MethodHandles, VarHandles, etc. This field will not be represented in the ConstantValue attributes.
A <clinit> or any other method in the new class or in a nestmate can read this value only via Lookup.findclassData(), so via a condy BSM. There is no way to write this field, even via SetAccessible().
Eg. from an email from John
here is an example BSM:
public static <T> T classData(Lookup lookup, String ignore, Class<T> type) {
Object cd = lookup.findClassData(lookup.lookupClass());
return type.cast(cd);
}
Note: the Lookup here is created for the condy and is a Lookup for the class which is calling the BSM, i.e. the newly defined class, not the creator of the class.
- duplicates
-
JDK-8238358 Implementation of JEP 371: Hidden Classes
- Resolved
- relates to
-
JDK-8230501 Class data support for hidden classes
- Resolved