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

Diagnose synchronization on primitive wrappers

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 16
    • Fix Version/s: 16
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b13

      Description

      "5.1.7. Boxing Conversion" specifies all boxing conversions be identity equivalent for some primitive types in the range -127 to 127. In the Hotspot JVM this is implemented by way of a "primitive cache", whose size may actually changed via an option making this range arbitrary.

      Programmers may be at times surprised when they discover synchronization on primitive wrappers deadlocks because of identity aliasing that may have been introduced at deployment time (via tuning cache size options), yet tested fine at development time.

      Proposed here, a diagnostic option(s) suitable for both development, testing and production environments. Said option should detect the use of the "synchronized" keyword on a primitive wrapper instance and take one of three actions:

      1) Exit the process with a fatal "VirtualMachineError". Suitable for development environments whereby the user wishes to inspect the site/call stack, amend, recompile and retest immediately.

      2) Log warning with stack trace. Suitable for coverage testing, whereby the user wishes to identify as many problems as possible over a test run.

      3) Emit a "Java Flight Recorder" (JFR) event. Suitable for production environments, given JFR's production-friendly low overhead. Also suitable for cases whereby option 2 (log warning) is extremely verbose.

      Said mechanism may be extended by way of further API and/or options to apply to other cases whereby unintended identity aliasing may cause correctness or deadlock problems.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pchilanomate Patricio Chilano Mateo
                Reporter:
                dsimms David Simms
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: