CSR :
|
|
Relates :
|
|
Relates :
|
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`.
|