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

Disable biased-locking and deprecate all flags related to biased-locking

    XMLWordPrintable

    Details

    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      This change only potentially affects performance. For some applications it may improve performance, and for some it may worsen it. The aim of the change is to establish if there is any significant impact on users before removing the feature in a future release.
      Show
      This change only potentially affects performance. For some applications it may improve performance, and for some it may worsen it. The aim of the change is to establish if there is any significant impact on users before removing the feature in a future release.
    • Interface Kind:
      add/remove/modify command line option
    • Scope:
      Implementation

      Description

      Summary

      Disable biased locking by default, and deprecate all related command-line options.

      Problem

      Biased locking is an optimization technique used in the HotSpot Virtual Machine to reduce the overhead of uncontended locking. It aims to avoid executing a compare-and-swap atomic operation when acquiring a monitor by assuming that a monitor remains owned by a given thread until a different thread tries to acquire it. The initial lock of the monitor biases the monitor towards that thread, avoiding the need for atomic instructions in subsequent synchronized operations on the same object. When many threads perform many synchronized operations on objects used in a single-threaded fashion, biasing the locks has historically led to significant performance improvements over regular locking techniques.

      The performance gains seen in the past are far less evident today. The cost of executing atomic instructions has decreased on modern processors since the introduction of biased locking into HotSpot. Furthermore, many applications that benefited from biased locking are older, legacy applications that use the early Java collection APIs, which synchronize on every access (e.g., Hashtable and Vector). Newer applications generally use the non-synchronized collections (e.g., HashMap and ArrayList), introduced in Java 1.2 for single-threaded scenarios, or the even more-performant concurrent data structures, introduced in Java 5, for multi-threaded scenarios. Applications built around a thread-pool queue and worker threads generally perform better with biased locking disabled. (SPECjbb2015 was designed that way, e.g., while SPECjvm98 and SPECjbb2005 were not.)

      Biased locking introduced a lot of complex code into the synchronization subsystem and is invasive to other HotSpot components as well. This complexity is a barrier to understanding various parts of the code and an impediment to making significant design changes within the synchronization subsystem. To that end we would like to disable, deprecate, and eventually remove support for biased locking.

      Solution

      We will disable biased locking by default so that we can determine if it has any significant impact on current day applications, prior to its removal.

      We will deprecate the UseBiasedLocking option and all options related to the configuration and use of biased locking.

      • Product options: BiasedLockingStartupDelay, BiasedLockingBulkRebiasThreshold, BiasedLockingBulkRevokeThreshold, BiasedLockingDecayTime and UseOptoBiasInlining

      The options will still be accepted and acted upon but a deprecation warning will be issued.

      Specification

         diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
         --- a/src/hotspot/share/runtime/arguments.cpp
         +++ b/src/hotspot/share/runtime/arguments.cpp
         @@ -525,6 +525,14 @@
         { "MonitorBound",                 JDK_Version::jdk(14), JDK_Version::jdk(15), JDK_Version::jdk(16) },
         { "PrintVMQWaitTime",             JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
         { "UseNewFieldLayout",            JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "UseBiasedLocking",             JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "BiasedLockingStartupDelay",    JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "BiasedLockingBulkRebiasThreshold",    JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "BiasedLockingBulkRevokeThreshold",    JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "BiasedLockingDecayTime",              JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      +  { "UseOptoBiasInlining",                 JDK_Version::jdk(15), JDK_Version::jdk(16), JDK_Version::jdk(17) },
      
         // --- 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() },
      
      
          diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp
         --- a/src/hotspot/share/runtime/globals.hpp
         +++ b/src/hotspot/share/runtime/globals.hpp
         @@ -810,32 +810,34 @@
            product(bool, RestrictContended, true,                                    \
                    "Restrict @Contended to trusted classes")                         \
                                                                                      \
         -  product(bool, UseBiasedLocking, true,                                     \
         -          "Enable biased locking in JVM")                                   \
         +  product(bool, UseBiasedLocking, false,                                    \
         +          "(Deprecated) Enable biased locking in JVM")                      \
                                                                                      \
            product(intx, BiasedLockingStartupDelay, 0,                               \
         -          "Number of milliseconds to wait before enabling biased locking")  \
         +          "(Deprecated) Number of milliseconds to wait before enabling "    \
         +          "biased locking")                                                 \
                    range(0, (intx)(max_jint-(max_jint%PeriodicTask::interval_gran))) \
                    constraint(BiasedLockingStartupDelayFunc,AfterErgo)               \
                                                                                      \
            product(intx, BiasedLockingBulkRebiasThreshold, 20,                       \
         -          "Threshold of number of revocations per type to try to "          \
         -          "rebias all objects in the heap of that type")                    \
         +          "(Deprecated) Threshold of number of revocations per type to "    \
         +          "try to rebias all objects in the heap of that type")             \
                    range(0, max_intx)                                                \
                    constraint(BiasedLockingBulkRebiasThresholdFunc,AfterErgo)        \
                                                                                      \
            product(intx, BiasedLockingBulkRevokeThreshold, 40,                       \
         -          "Threshold of number of revocations per type to permanently "     \
         -          "revoke biases of all objects in the heap of that type")          \
         +          "(Deprecated) Threshold of number of revocations per type to "    \
         +          "permanently revoke biases of all objects in the heap of that "   \
         +          "type")                                                           \
                    range(0, max_intx)                                                \
                    constraint(BiasedLockingBulkRevokeThresholdFunc,AfterErgo)        \
                                                                                      \
            product(intx, BiasedLockingDecayTime, 25000,                              \
         -          "Decay time (in milliseconds) to re-enable bulk rebiasing of a "  \
         -          "type after previous bulk rebias")                                \
         +          "(Deprecated) Decay time (in milliseconds) to re-enable bulk "    \
         +          "rebiasing of a type after previous bulk rebias")                 \
                    range(500, max_intx)                                              \
                    constraint(BiasedLockingDecayTimeFunc,AfterErgo)                  \
                                                                                      \
      
         diff --git a/src/hotspot/share/opto/c2_globals.hpp b/src/hotspot/share/opto/c2_globals.hpp
         --- a/src/hotspot/share/opto/c2_globals.hpp
         +++ b/src/hotspot/share/opto/c2_globals.hpp
         @@ -548,7 +549,7 @@
                    "Verify Connection Graph construction in Escape Analysis")        \
                                                                               \
            product(bool, UseOptoBiasInlining, true,                                  \
         -          "Generate biased locking code in C2 ideal graph")                 \
         +          "(Deprecated) Generate biased locking code in C2 ideal graph")    \
                                                                               \
            product(bool, OptimizeStringConcat, true,                                 \
                    "Optimize the construction of Strings by StringBuilder")          \

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pchilanomate Patricio Chilano Mateo
              Reporter:
              pchilanomate Patricio Chilano Mateo
              Reviewed By:
              Daniel Daugherty, David Holmes
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: