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

Implement UseHeavyMonitors consistently

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 18
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      Somebody may use -XX:+UseHeavyMonitors in production with currently no impact, and observe failure because the flag is no longer in product builds.

      Optimized/develop builds may observe possible performance degradation, or, in unlikely worst case, failure to allocate monitors or failure to timely (concurrently) deflate monitors when running with +UseHeavyMonitors. That is because pressure on the monitor subsystem will be much higher than before. Many locks would normally only use stack-locks and never inflate to full monitors, while with this change, +UseHeavyMonitors would cause *all* locks to use full monitors instead.
      Show
      Somebody may use -XX:+UseHeavyMonitors in production with currently no impact, and observe failure because the flag is no longer in product builds. Optimized/develop builds may observe possible performance degradation, or, in unlikely worst case, failure to allocate monitors or failure to timely (concurrently) deflate monitors when running with +UseHeavyMonitors. That is because pressure on the monitor subsystem will be much higher than before. Many locks would normally only use stack-locks and never inflate to full monitors, while with this change, +UseHeavyMonitors would cause *all* locks to use full monitors instead.
    • Interface Kind:
      add/remove/modify command line option
    • Scope:
      Implementation

      Description

      Summary

      Deprecate the flag -XX:+/-UseHeavyMonitors in JDK 18, obsolete it in 19 and convert it to a develop flag in 19.

      Problem

      UseHeavyMonitors is supposed to be used to disable stack-locking (thin locks) and let the synchronization subsystem use only 'heavy' monitors. However, the current Hotspot only implements this in the interpreter. Even worse, even then it calls into the runtime when running with +UseHeavyMonitors, which would still use stack-locking. C1 has its own flag UseFastLocking to achieve the same, and C2 doesn't have a comparable mechanism at all, and would always emit code that attempts stack-locking.

      As such, the flag is pretty much useless in its current form. Users who use this in production would not see any noticeable effect. If it were implemented correctly, it would perhaps expose somewhat surprising behaviours, like potential failure to allocate or deflate monitors under much increased monitor pressure.

      Solution

      This change implements UseHeavyMonitors consistently (on x86_64), and deprecates the flag UseHeavyMonitors. The intention is to demote the flag to develop in JDK 19, at which time it becomes "obsolete" in a product build. It should really not be used in production, and is only really useful for experimentation by the Hotspot team. I also intend to remove the (develop) UseFastLocking flag of C1, and use UseHeavyMonitors there instead.

      Alternatively, we could get rid of UseHeavyMonitors altogether. However, I currently want to conduct some experiments with disabling stack-locking, so I think it's still useful. I am not alone with this. For example, the implementors of JEP 143 also used it for experiments (probably misguided, because the flag did not really work).

      See: https://openjdk.java.net/jeps/143

      As an aside, I intend to introduce a new develop flag VerifyHeavyMonitors to enable verification that the UseHeavyMonitors flag works correctly. I would prefer to unconditionally verify this using asserts, but this is currently not possible because the functionality is only implemented on x86_64.

      Specification

      diff --git a/src/hotspot/share/c1/c1_globals.hpp b/src/hotspot/share/c1/c1_globals.hpp
      index 2b5de079a0c..e90aaf6536d 100644
      --- a/src/hotspot/share/c1/c1_globals.hpp
      +++ b/src/hotspot/share/c1/c1_globals.hpp
      @@ -242,9 +242,6 @@
         develop(bool, UseFastNewObjectArray, true,                                \
                 "Use fast inlined object array allocation")                       \
                                                                                   \
      -  develop(bool, UseFastLocking, true,                                       \
      -          "Use fast inlined locking code")                                  \
      -                                                                            \
         develop(bool, UseSlowPath, false,                                         \
                 "For debugging: test slow cases by always using them")            \
                                                                                   \
          diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp
      index 81bfbaaf033..d547c4c6376 100644
      --- a/src/hotspot/share/runtime/globals.hpp
      +++ b/src/hotspot/share/runtime/globals.hpp
      @@ -1071,6 +1071,10 @@ const intx ObjectAlignmentInBytes = 8;
         product(bool, UseHeavyMonitors, false,                                    \
                 "use heavyweight instead of lightweight Java monitors")           \
                                                                                   \
      +  develop(bool, VerifyHeavyMonitors, false,                                 \
      +          "Checks that no stack locking happens when using "                \
      +          "+UseHeavyMonitors")                                              \
      +                                                                            \
         product(bool, PrintStringTableStatistics, false,                          \
                 "print statistics about the StringTable and SymbolTable")         \
      
      diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
      index 89352c1f95e..79d938939a4 100644
      --- a/src/hotspot/share/runtime/arguments.cpp
      +++ b/src/hotspot/share/runtime/arguments.cpp
      @@ -532,6 +532,9 @@ static SpecialFlag const special_jvm_flags[] = {
         { "DynamicDumpSharedSpaces",      JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
         { "RequireSharedSpaces",          JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
         { "UseSharedSpaces",              JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
      +#ifdef PRODUCT
      +  { "UseHeavyMonitors",             JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::jdk(20) },
      +#endif
      
         // --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
         { "DefaultMaxRAMFraction",        JDK_Version::jdk(8),  JDK_Version::undefined(), JDK_Version::undefined() },

      The complete change is: https://github.com/openjdk/jdk/pull/6320/files

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rkennke Roman Kennke
              Reporter:
              rkennke Roman Kennke
              Reviewed By:
              Coleen Phillimore, Daniel Daugherty, David Holmes
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: