JDK-8209679 : JVM support for "classData"
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 12
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2018-08-20
  • Updated: 2020-05-12
  • Resolved: 2020-05-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Description
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. 
Comments
This work was implemented under JEP-371 - JDK-8238358.
12-05-2020

This work has been pushed to the valhalla repo but it is TBD when this work may be targeted for inclusion in mainline.
04-02-2020