JDK-8257596 : Clarify trusted final fields for record classes
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 16
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-12-02
  • Updated: 2021-01-04
  • Resolved: 2020-12-11
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.
JDK 16 JDK 17
16 b29Fixed 17Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
This issue has been filed to address the determination of TNSFF for "record classes" in the Hotspot VM.

Details below are copied from a comment in JDK-8255560 - which addresses the Core Reflection aspects of the issue.

---
RE: ���The Record Attribute - What does it mean to be a record at runtime��� 

In order to claim a non-static final field is trusted, such TNSFF must not be modifiable by reflection and method handle (VarHandle does not allow writing on a final field). Unsafe is a lessen concern because it���s unsafe anyway but we should stop what we can. We want records to benefit from TNSFF performance but not care so much normal classes with RecordComponents attribute. JIT optimization is implementation-specific. Checking if a class is a subclass of java.lang.Record should not be expensive. I would suggest to change JIT to check if a class must be final and a subclass of java.lang.Record in addition to the presence of a RecordComponents attribute. 

In HotSpot implementation term, the current implementation of InstanceKlass::is_record is misleading because it could return true on a normal class. The suggested fix is to change InstanceKlass::is_record to check if _record_components != NULL and it is final and a subclass of java.lang.Record. No change in JVM class file validation. 

[1] https://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-November/002630.html
Comments
Changeset: 2001da3d Author: Mandy Chung <mchung@openjdk.org> Date: 2020-12-11 22:44:48 +0000 URL: https://git.openjdk.java.net/jdk16/commit/2001da3d
11-12-2020

See also https://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-December/002670.html
09-12-2020