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

    • CSR
    • Status: Closed
    • P3
    • Resolution: Approved
    • 16
    • tools
    • behavioral
    • minimal
    • New warning.
    • add/remove/modify command line option
    • 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
          Srikanth Adayapalam
        2. sortedapplist
          2 kB
          Srikanth Adayapalam
        3. sortedwerrorapplist
          24 kB
          Srikanth Adayapalam

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: