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

[JEP 390] Add 'lint' warning for synchronization attempts on value-based class instances

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      New warning.
    • Interface Kind:
      add/remove/modify command line option
    • Scope:
      JDK

      Description

      Summary

      Add a new lint option, synchronization, to javac to warn about usages of the synchronized statement with an operand that is an instance of a value-based class.

      Problem

      The Valhalla Project is pursuing a significant enhancement to the Java programming model in the form of primitive classes, that offer various performance optimization opportunities. Several classes in the Java Platform that have been informally designated as value-based classes in the API specifications are candidates for being migrated to primitive classes in a future release.

      Synchronization on instances of value-based classes is discouraged, because the classes' factories do not promise unique ownership of an object identity. After migrating to primitive classes, attempts to synchronize on instances of these classes will produce exceptions, since primitive class instances have no monitors associated with them that can be locked.

      Solution

      Enhance javac to detect synchronized statements that have operands that are instances of value-based classes and warn programmers that these synchronization operations are discouraged.

      These compile-time checks will be complemented by dynamic checks in the JVM, via JDK-8252182.

      Specification

      The new javac lint category synchronization is turned on by default and produces the following diagnostic message:

           warning: [synchronization] attempt to synchronize on an instance of a value-based class.

        Attachments

        1. diags
          27 kB
        2. sortedapplist
          2 kB
        3. sortedwerrorapplist
          24 kB

          Issue Links

            Activity

              People

              Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              dlsmith Dan Smith
              Reviewed By:
              Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: