JDK-8246550 : Add flag to diagnose synchronization on primitive wrappers
  • Type: CSR
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Status: Closed
  • Resolution: Withdrawn
  • Fix Versions: 15
  • Submitted: 2020-06-04
  • Updated: 2020-06-09
  • Resolved: 2020-06-09
Related Reports
CSR :  
Description
Summary
-------

Add -XX:DiagnoseSyncOnPrimitiveWrappers flag to detect and take action upon identifying synchronization on primitive wrappers.

Problem
-------

"5.1.7. Boxing Conversion" specifies all boxing conversions be identity equivalent for some primitive types in the range -128 to 127. In the Hotspot JVM this is implemented by way of a "primitive cache", whose size may actually be 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.


Solution
--------

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

1) Exit the process with a fatal error. 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 users 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.


Specification
-------------

       diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp
       index aa9b2dc830..4dd106f159 100644
       --- a/src/hotspot/share/runtime/globals.hpp
       +++ b/src/hotspot/share/runtime/globals.hpp
       @@ -806,6 +806,13 @@ const size_t minimumSymbolTableSize = 1024;
                  range(500, max_intx)                                              \
                  constraint(BiasedLockingDecayTimeFunc,AfterErgo)                  \
                                                                                    \
       +  product(intx, DiagnoseSyncOnPrimitiveWrappers, 0,                         \
       +          "Detect and take action upon identifying synchronization on "     \
       +          "primitive wrappers. Modes: "                                     \
       +          "0: off "                                                         \
       +          "1: exit process; "                                               \
       +          "2: print message to stdout; "                                    \
       +          "3: emit JFR event")                                              \
       +          range(0, 3)                                                       \
       +                                                                            \
          product(bool, ExitOnOutOfMemoryError, false,                              \
                  "JVM exits on the first occurrence of an out-of-memory error")    \
                                                                                    \


Comments
Ok, I moved it to "Withdrawn" since this is better suited to be a diagnostic flag.
09-06-2020

+1 on 'diagnostic' flag
09-06-2020

Why is this a 'product' flag instead of a 'diagnostic' flag?
08-06-2020