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

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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 16
    • tools
    • behavioral
    • minimal
    • New warning.
    • add/remove/modify command line option
    • JDK

      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.

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

            sadayapalam Srikanth Adayapalam (Inactive)
            dlsmith Dan Smith
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: