8211176: Initialize ObjectMonitor eagerly
authormikael
Fri, 28 Sep 2018 14:11:21 -0700
changeset 51960 bb1d5dd64897
parent 51959 db0c3952de52
child 51961 540c1a848dd8
8211176: Initialize ObjectMonitor eagerly Reviewed-by: dholmes, adinn, redestad
src/hotspot/share/runtime/objectMonitor.cpp
src/hotspot/share/runtime/objectMonitor.hpp
--- a/src/hotspot/share/runtime/objectMonitor.cpp	Fri Sep 28 16:07:39 2018 -0400
+++ b/src/hotspot/share/runtime/objectMonitor.cpp	Fri Sep 28 14:11:21 2018 -0700
@@ -110,7 +110,7 @@
 static int Knob_FixedSpin           = 0;
 static int Knob_PreSpin             = 10;      // 20-100 likely better
 
-static volatile int InitDone        = 0;
+DEBUG_ONLY(static volatile bool InitDone = false;)
 
 // -----------------------------------------------------------------------------
 // Theory of operations -- Monitors lists, thread residency, etc:
@@ -428,7 +428,7 @@
     return;
   }
 
-  DeferredInitialize();
+  assert(InitDone, "Unexpectedly not initialized");
 
   // We try one round of spinning *before* enqueueing Self.
   //
@@ -1102,7 +1102,7 @@
   assert(Self->is_Java_thread(), "Must be Java thread!");
   JavaThread *jt = (JavaThread *)THREAD;
 
-  DeferredInitialize();
+  assert(InitDone, "Unexpectedly not initialized");
 
   if (THREAD != _owner) {
     if (THREAD->is_lock_owned ((address)_owner)) {
@@ -1186,7 +1186,7 @@
   assert(Self->is_Java_thread(), "Must be Java thread!");
   JavaThread *jt = (JavaThread *)THREAD;
 
-  DeferredInitialize();
+  assert(InitDone, "Unexpectedly not initialized");
 
   // Throw IMSX or IEX.
   CHECK_OWNER();
@@ -1888,9 +1888,14 @@
 // be protected - like so many things - by the MonitorCache_lock.
 
 void ObjectMonitor::Initialize() {
-  static int InitializationCompleted = 0;
-  assert(InitializationCompleted == 0, "invariant");
-  InitializationCompleted = 1;
+  assert(!InitDone, "invariant");
+
+  if (!os::is_MP()) {
+    Knob_SpinLimit = 0;
+    Knob_PreSpin   = 0;
+    Knob_FixedSpin = -1;
+  }
+
   if (UsePerfData) {
     EXCEPTION_MARK;
 #define NEWPERFCOUNTER(n)                                                \
@@ -1913,26 +1918,6 @@
 #undef NEWPERFCOUNTER
 #undef NEWPERFVARIABLE
   }
+
+  DEBUG_ONLY(InitDone = true;)
 }
-
-void ObjectMonitor::DeferredInitialize() {
-  if (InitDone > 0) return;
-  if (Atomic::cmpxchg (-1, &InitDone, 0) != 0) {
-    while (InitDone != 1) /* empty */;
-    return;
-  }
-
-  // One-shot global initialization ...
-  // The initialization is idempotent, so we don't need locks.
-  // In the future consider doing this via os::init_2().
-
-  if (!os::is_MP()) {
-    Knob_SpinLimit = 0;
-    Knob_PreSpin   = 0;
-    Knob_FixedSpin = -1;
-  }
-
-  OrderAccess::fence();
-  InitDone = 1;
-}
-
--- a/src/hotspot/share/runtime/objectMonitor.hpp	Fri Sep 28 16:07:39 2018 -0400
+++ b/src/hotspot/share/runtime/objectMonitor.hpp	Fri Sep 28 14:11:21 2018 -0700
@@ -302,7 +302,6 @@
 
  private:
   void      AddWaiter(ObjectWaiter * waiter);
-  static    void DeferredInitialize();
   void      INotify(Thread * Self);
   ObjectWaiter * DequeueWaiter();
   void      DequeueSpecificWaiter(ObjectWaiter * waiter);