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

Diagnose synchronization on primitive wrappers



    • b13


      "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.


        Issue Links



              pchilanomate Patricio Chilano Mateo
              dsimms David Simms
              0 Vote for this issue
              9 Start watching this issue