JDK-8339130 : JVM implementation of value classes and objects
  • Type: CSR
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: Proposed
  • Resolution: Unresolved
  • Fix Versions: tbd
  • Submitted: 2024-08-27
  • Updated: 2024-09-02
Related Reports
CSR :  
Relates :  
Relates :  
Description
Summary
-------

Enhance the JVM with value classes and objects.

Problem
-------

[The JEP](https://openjdk.org/jeps/401) provides a high-level discussion motivating the feature.

The JVM, in particular, needs enhancement in `--enable-preview` mode, doing all of the following:

- Distinguish between value classes (which do not require/assume identity) and identity classes (which do)
- Modify the instance creation mechanism to ensure that value objects are created with final fields that can never be observed to mutate
- Automatically configure loading of modified JDK classes when the `--enable-preview` flag is set
- Allow for and signal the loading of the value classes used by a particular class early enough to influence the class's layout and method calling conventions
- Provide identity-free semantics for the `if_acmpeq`, `if_acmpne`, and `monitorenter` instructions

Solution
--------

Our solution enhances the JVM as follows:

- Repurpose the `ACC_SUPER` flag to be interpreted (in preview class files) as `ACC_IDENTITY`; identity classes set this flag, while value classes and interfaces do not. Validate that value classes conform to various constraints: do not extend identity classes, do not declare inappropriate instance fields, do not declare synchronized methods
- Ensure that all instance fields of a value class are _strictly-initialized_: they must be marked with the `ACC_STRICT` flag (formerly used to express floating-point properties on methods), which instructs verification to prevent any `putfield` operations after the `super()` constructor call. Field initialization is only allowed before that point.
- Have the launcher reconfigure the `java.base` module to load special preview class files when preview features are enabled
- Introduce a new attribute, `LoadableDescriptors`, to indicate classes mentioned in descriptors that can be _speculatively loaded_ during class loading, and might be loaded earlier than usual during linking
- Update `if_acmpeq` and `if_acmpne` to compare instances of value classes in terms of their field values; update `monitorenter` to reject value class instances

A more comprehensive outline of the solution can be found in the [JDK-8317278](https://bugs.openjdk.org/browse/JDK-8317278) description.

Specification
-------------

JVMS changes are included in the attached spec change document bundle. See the file `specs/value-objects-jvms.html`.
Comments
Under what CSR are the strict-field changes being approved?
02-09-2024

I've reviewed the proposed JVMS changes and I consider them sufficient to implement the VM side of JEP 401.
30-08-2024

JVMS changes can also be reviewed at https://cr.openjdk.org/~dlsmith/jep401/jep401-20240624/specs/value-objects-jvms.html
29-08-2024

I've reviewed the JVMS details and believe them to sufficient to implement the JEP 401 VM changes.
28-08-2024