8231707: Improve Mutex inlining
authorredestad
Thu, 03 Oct 2019 13:45:08 +0200
changeset 58454 d873ce07465d
parent 58453 ca80b8395923
child 58456 9759972b4f1c
child 58457 7a4183b8062f
8231707: Improve Mutex inlining Reviewed-by: rehn, dholmes, coleenp
src/hotspot/share/runtime/mutex.cpp
src/hotspot/share/runtime/mutex.hpp
--- a/src/hotspot/share/runtime/mutex.cpp	Thu Oct 03 10:56:39 2019 +0200
+++ b/src/hotspot/share/runtime/mutex.cpp	Thu Oct 03 13:45:08 2019 +0200
@@ -70,22 +70,16 @@
 }
 #endif // ASSERT
 
-void Mutex::lock(Thread* self) {
-  check_safepoint_state(self);
-
-  assert(_owner != self, "invariant");
-
-  Mutex* in_flight_mutex = NULL;
+void Mutex::lock_contended(Thread* self) {
+  Mutex *in_flight_mutex = NULL;
   DEBUG_ONLY(int retry_cnt = 0;)
   bool is_active_Java_thread = self->is_active_Java_thread();
-  while (!_lock.try_lock()) {
-    // The lock is contended
-
-  #ifdef ASSERT
+  do {
+    #ifdef ASSERT
     if (retry_cnt++ > 3) {
       log_trace(vmmutex)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s", p2i(self), retry_cnt, _name);
     }
-  #endif // ASSERT
+    #endif // ASSERT
 
     // Is it a JavaThread participating in the safepoint protocol.
     if (is_active_Java_thread) {
@@ -102,6 +96,17 @@
       _lock.lock();
       break;
     }
+  } while (!_lock.try_lock());
+}
+
+void Mutex::lock(Thread* self) {
+  check_safepoint_state(self);
+
+  assert(_owner != self, "invariant");
+
+  if (!_lock.try_lock()) {
+    // The lock is contended, use contended slow-path function to lock
+    lock_contended(self);
   }
 
   assert_owner(NULL);
@@ -109,7 +114,7 @@
 }
 
 void Mutex::lock() {
-  this->lock(Thread::current());
+  lock(Thread::current());
 }
 
 // Lock without safepoint check - a degenerate variant of lock() for use by
--- a/src/hotspot/share/runtime/mutex.hpp	Thu Oct 03 10:56:39 2019 +0200
+++ b/src/hotspot/share/runtime/mutex.hpp	Thu Oct 03 13:45:08 2019 +0200
@@ -152,6 +152,9 @@
   bool is_locked() const                     { return _owner != NULL; }
 
   bool try_lock(); // Like lock(), but unblocking. It returns false instead
+ private:
+  void lock_contended(Thread *thread); // contended slow-path
+ public:
 
   void release_for_safepoint();