Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8339130

JVM implementation of value classes and objects

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • hotspot
    • None
    • behavioral
    • high
    • All instances of value classes, including classes like Integer, Optional, and LocalDate, behave differently under the if_acmpeq, if_acmpne, and monitorenter opcodes
    • Class file construct
    • SE

      Summary

      Enhance the JVM with value classes and objects.

      Problem

      The JEP 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 description.

      Specification

      JVMS changes are included in the attached spec change document bundle. See the file specs/value-objects-jvms.html.

            dlsmith Dan Smith
            dlsmith Dan Smith
            Dan Heidinga, Frederic Parain
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: