JDK-8231265 : Disable biased-locking and deprecate all flags related to biased-locking
  • Type: CSR
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 15
  • Submitted: 2019-09-19
  • Updated: 2020-03-19
  • Resolved: 2020-03-19
Related Reports
CSR :  
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")          \


Comments
Moving to Approved.
19-03-2020

Thanks Dan! Changing back to finalize.
18-03-2020

I re-affirm my Review of this CSR request.
18-03-2020

Great, thanks David!
18-03-2020

Thanks Patricio! I re-affirm my Review of this CSR request. Please ask [~dcubed] to re-affirm his review and then re-finalize the request. Thanks.
18-03-2020

Sorry, changed the description back to its prior format. I applied most of the text edition that was made on the JEP. Should I remove the reviewers from the "Reviewed By:" field and wait for a new review?
18-03-2020

Yes please restore this to the form it had before the "2020-03-07 03:38" changes. The reviewers of this CSR request did not review the current abridged version. Thanks.
18-03-2020

Pending the request. "See the JEP" is *not* adequate for a CSR. Per the JEP process, a JEP is a *living document*, in other words, it can and does change, including changing after the initial changeset for the JEP is pushed. A finalized CSR is a request to review a particular snapshot of a proposal and "see the JEP" is not compatible with that. Please update the CSR with current information about what is to be changed, including text like "deprecate all biased locking related options."
17-03-2020

Thanks [~dholmes]. By reading https://wiki.openjdk.java.net/display/HotSpot/Hotspot+Command-line+Flags%3A+Kinds%2C+Lifecycle+and+the+CSR+Process I see that we can skip the deprecation step for these flags.
16-03-2020

Diagnostic flags don't normally go through the deprecation process.
09-03-2020

Thanks [~kvn]. I changed the diff of c2_globals.hpp to match the format of changes of globals.hpp, and added both flags in arguments.cpp diff.
06-03-2020

2 additional C2 flags, UseOptoBiasInlining and PrintPreciseBiasedLockingStatistics, should be deprecated too . I added diff to description.
06-03-2020

[~pchilanomate], as this work now looks as it is going to go into 15, please make any necessary 14 -> 15 edits and refinalize the request when it is ready for considering. Moving the request back to Draft.
16-02-2020

This CSR was approved for 14, should it be withdraw or re-targeted to 15 to align with the actual change?
15-02-2020

Release note subtask created. And also sub-task for updating `java` command manpage.
15-11-2019

Voting to Approved contingent on a release note being written.
15-11-2019

I have done some judicious editing and formatting and added myself as reviewer.
13-11-2019