< prev index next >

src/hotspot/share/runtime/mutex.cpp

Print this page

        

@@ -31,51 +31,51 @@
 #include "runtime/thread.inline.hpp"
 #include "utilities/events.hpp"
 #include "utilities/macros.hpp"
 
 #ifdef ASSERT
-void Monitor::check_safepoint_state(Thread* thread, bool do_safepoint_check) {
+void Mutex::check_safepoint_state(Thread* thread, bool do_safepoint_check) {
   // If the JavaThread checks for safepoint, verify that the lock wasn't created with safepoint_check_never.
-  SafepointCheckRequired not_allowed = do_safepoint_check ?  Monitor::_safepoint_check_never :
-                                                             Monitor::_safepoint_check_always;
+  SafepointCheckRequired not_allowed = do_safepoint_check ?  Mutex::_safepoint_check_never :
+                                                             Mutex::_safepoint_check_always;
   assert(!thread->is_active_Java_thread() || _safepoint_check_required != not_allowed,
          "This lock should %s have a safepoint check for Java threads: %s",
          _safepoint_check_required ? "always" : "never", name());
 
   // If defined with safepoint_check_never, a NonJavaThread should never ask to safepoint check either.
-  assert(thread->is_Java_thread() || !do_safepoint_check || _safepoint_check_required != Monitor::_safepoint_check_never,
+  assert(thread->is_Java_thread() || !do_safepoint_check || _safepoint_check_required != Mutex::_safepoint_check_never,
          "NonJavaThread should not check for safepoint");
 }
 #endif // ASSERT
 
-void Monitor::lock(Thread * self) {
+void Mutex::lock(Thread * self) {
   check_safepoint_state(self, true);
 
   DEBUG_ONLY(check_prelock_state(self, true));
   assert(_owner != self, "invariant");
 
-  Monitor* in_flight_monitor = NULL;
+  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
     check_block_state(self);
     if (retry_cnt++ > 3) {
-      log_trace(vmmonitor)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmonitor %s", p2i(self), retry_cnt, _name);
+      log_trace(vmmutex)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s", p2i(self), retry_cnt, _name);
     }
   #endif // ASSERT
 
     // Is it a JavaThread participating in the safepoint protocol.
     if (is_active_Java_thread) {
       assert(rank() > Mutex::special, "Potential deadlock with special or lesser rank mutex");
-      { ThreadBlockInVMWithDeadlockCheck tbivmdc((JavaThread *) self, &in_flight_monitor);
-        in_flight_monitor = this;  // save for ~ThreadBlockInVMWithDeadlockCheck
+      { ThreadBlockInVMWithDeadlockCheck tbivmdc((JavaThread *) self, &in_flight_mutex);
+        in_flight_mutex = this;  // save for ~ThreadBlockInVMWithDeadlockCheck
         _lock.lock();
       }
-      if (in_flight_monitor != NULL) {
+      if (in_flight_mutex != NULL) {
         // Not unlocked by ~ThreadBlockInVMWithDeadlockCheck
         break;
       }
     } else {
       _lock.lock();

@@ -85,36 +85,36 @@
 
   assert_owner(NULL);
   set_owner(self);
 }
 
-void Monitor::lock() {
+void Mutex::lock() {
   this->lock(Thread::current());
 }
 
 // Lock without safepoint check - a degenerate variant of lock() for use by
 // JavaThreads when it is known to be safe to not check for a safepoint when
 // acquiring this lock. If the thread blocks acquiring the lock it is not
 // safepoint-safe and so will prevent a safepoint from being reached. If used
 // in the wrong way this can lead to a deadlock with the safepoint code.
 
-void Monitor::lock_without_safepoint_check(Thread * self) {
+void Mutex::lock_without_safepoint_check(Thread * self) {
   check_safepoint_state(self, false);
   assert(_owner != self, "invariant");
   _lock.lock();
   assert_owner(NULL);
   set_owner(self);
 }
 
-void Monitor::lock_without_safepoint_check() {
+void Mutex::lock_without_safepoint_check() {
   lock_without_safepoint_check(Thread::current());
 }
 
 
 // Returns true if thread succeeds in grabbing the lock, otherwise false.
 
-bool Monitor::try_lock() {
+bool Mutex::try_lock() {
   Thread * const self = Thread::current();
   DEBUG_ONLY(check_prelock_state(self, false);)
 
   if (_lock.try_lock()) {
     assert_owner(NULL);

@@ -122,16 +122,16 @@
     return true;
   }
   return false;
 }
 
-void Monitor::release_for_safepoint() {
+void Mutex::release_for_safepoint() {
   assert_owner(NULL);
   _lock.unlock();
 }
 
-void Monitor::unlock() {
+void Mutex::unlock() {
   assert_owner(Thread::current());
   set_owner(NULL);
   _lock.unlock();
 }
 

@@ -145,11 +145,11 @@
   _lock.notify_all();
 }
 
 #ifdef ASSERT
 void Monitor::assert_wait_lock_state(Thread* self) {
-  Monitor* least = get_least_ranked_lock_besides_this(self->owned_locks());
+  Mutex* least = get_least_ranked_lock_besides_this(self->owned_locks());
   assert(least != this, "Specification of get_least_... call above");
   if (least != NULL && least->rank() <= special) {
     ::tty->print("Attempting to wait on monitor %s/%d while holding"
                " lock %s/%d -- possible deadlock",
                name(), rank(), least->name(), least->rank());

@@ -192,23 +192,23 @@
   int wait_status;
   // conceptually set the owner to NULL in anticipation of
   // abdicating the lock in wait
   set_owner(NULL);
   JavaThread *jt = (JavaThread *)self;
-  Monitor* in_flight_monitor = NULL;
+  Mutex* in_flight_mutex = NULL;
 
   {
-    ThreadBlockInVMWithDeadlockCheck tbivmdc(jt, &in_flight_monitor);
+    ThreadBlockInVMWithDeadlockCheck tbivmdc(jt, &in_flight_mutex);
     OSThreadWaitState osts(self->osthread(), false /* not Object.wait() */);
     if (as_suspend_equivalent) {
       jt->set_suspend_equivalent();
       // cleared by handle_special_suspend_equivalent_condition() or
       // java_suspend_self()
     }
 
     wait_status = _lock.wait(timeout);
-    in_flight_monitor = this;  // save for ~ThreadBlockInVMWithDeadlockCheck
+    in_flight_mutex = this;  // save for ~ThreadBlockInVMWithDeadlockCheck
 
     // were we externally suspended while we were waiting?
     if (as_suspend_equivalent && jt->handle_special_suspend_equivalent_condition()) {
       // Our event wait has finished and we own the lock, but
       // while we were waiting another thread suspended us. We don't

@@ -218,11 +218,11 @@
       jt->java_suspend_self();
       _lock.lock();
     }
   }
 
-  if (in_flight_monitor != NULL) {
+  if (in_flight_mutex != NULL) {
     // Not unlocked by ~ThreadBlockInVMWithDeadlockCheck
     assert_owner(NULL);
     // Conceptually reestablish ownership of the lock.
     set_owner(self);
   } else {

@@ -230,66 +230,66 @@
   }
 
   return wait_status != 0;          // return true IFF timeout
 }
 
-Monitor::~Monitor() {
+Mutex::~Mutex() {
   assert_owner(NULL);
 }
 
 // Only Threads_lock, Heap_lock and SR_lock may be safepoint_check_sometimes.
 bool is_sometimes_ok(const char* name) {
   return (strcmp(name, "Threads_lock") == 0 || strcmp(name, "Heap_lock") == 0 || strcmp(name, "SR_lock") == 0);
 }
 
-Monitor::Monitor(int Rank, const char * name, bool allow_vm_block,
+Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
                  SafepointCheckRequired safepoint_check_required) : _owner(NULL) {
   assert(os::mutex_init_done(), "Too early!");
   if (name == NULL) {
     strcpy(_name, "UNKNOWN");
   } else {
-    strncpy(_name, name, MONITOR_NAME_LEN - 1);
-    _name[MONITOR_NAME_LEN - 1] = '\0';
+    strncpy(_name, name, MUTEX_NAME_LEN - 1);
+    _name[MUTEX_NAME_LEN - 1] = '\0';
   }
 #ifdef ASSERT
   _allow_vm_block  = allow_vm_block;
   _rank            = Rank;
   _safepoint_check_required = safepoint_check_required;
 
-  assert(_safepoint_check_required != Monitor::_safepoint_check_sometimes || is_sometimes_ok(name),
+  assert(_safepoint_check_required != Mutex::_safepoint_check_sometimes || is_sometimes_ok(name),
          "Lock has _safepoint_check_sometimes %s", name);
 #endif
 }
 
-Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
+Monitor::Monitor(int Rank, const char * name, bool allow_vm_block,
              SafepointCheckRequired safepoint_check_required) :
-  Monitor(Rank, name, allow_vm_block, safepoint_check_required) {}
+  Mutex(Rank, name, allow_vm_block, safepoint_check_required) {}
 
-bool Monitor::owned_by_self() const {
+bool Mutex::owned_by_self() const {
   return _owner == Thread::current();
 }
 
-void Monitor::print_on_error(outputStream* st) const {
+void Mutex::print_on_error(outputStream* st) const {
   st->print("[" PTR_FORMAT, p2i(this));
   st->print("] %s", _name);
   st->print(" - owner thread: " PTR_FORMAT, p2i(_owner));
 }
 
 // ----------------------------------------------------------------------------------
 // Non-product code
 
 #ifndef PRODUCT
-void Monitor::print_on(outputStream* st) const {
+void Mutex::print_on(outputStream* st) const {
   st->print_cr("Mutex: [" PTR_FORMAT "] %s - owner: " PTR_FORMAT,
                p2i(this), _name, p2i(_owner));
 }
 #endif
 
 #ifndef PRODUCT
 #ifdef ASSERT
 
-void Monitor::assert_owner(Thread * expected) {
+void Mutex::assert_owner(Thread * expected) {
   const char* msg = "invalid owner";
   if (expected == NULL) {
     msg = "should be un-owned";
   }
   else if (expected == Thread::current()) {

@@ -298,12 +298,12 @@
   assert(_owner == expected,
          "%s: owner=" INTPTR_FORMAT ", should be=" INTPTR_FORMAT,
          msg, p2i(_owner), p2i(expected));
 }
 
-Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
-  Monitor *res, *tmp;
+Mutex* Mutex::get_least_ranked_lock(Mutex* locks) {
+  Mutex *res, *tmp;
   for (res = tmp = locks; tmp != NULL; tmp = tmp->next()) {
     if (tmp->rank() < res->rank()) {
       res = tmp;
     }
   }

@@ -318,12 +318,12 @@
     }
   }
   return res;
 }
 
-Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
-  Monitor *res, *tmp;
+Mutex* Mutex::get_least_ranked_lock_besides_this(Mutex* locks) {
+  Mutex *res, *tmp;
   for (res = NULL, tmp = locks; tmp != NULL; tmp = tmp->next()) {
     if (tmp != this && (res == NULL || tmp->rank() < res->rank())) {
       res = tmp;
     }
   }

@@ -339,11 +339,11 @@
   }
   return res;
 }
 
 
-bool Monitor::contains(Monitor* locks, Monitor * lock) {
+bool Mutex::contains(Mutex* locks, Mutex* lock) {
   for (; locks != NULL; locks = locks->next()) {
     if (locks == lock) {
       return true;
     }
   }

@@ -354,11 +354,11 @@
 // Called immediately after lock acquisition or release as a diagnostic
 // to track the lock-set of the thread and test for rank violations that
 // might indicate exposure to deadlock.
 // Rather like an EventListener for _owner (:>).
 
-void Monitor::set_owner_implementation(Thread *new_owner) {
+void Mutex::set_owner_implementation(Thread *new_owner) {
   // This function is solely responsible for maintaining
   // and checking the invariant that threads and locks
   // are in a 1/N relation, with some some locks unowned.
   // It uses the Mutex::_owner, Mutex::_next, and
   // Thread::_owned_locks fields, and no other function

@@ -375,11 +375,11 @@
     _owner = new_owner; // set the owner
 
     // link "this" into the owned locks list
 
 #ifdef ASSERT  // Thread::_owned_locks is under the same ifdef
-    Monitor* locks = get_least_ranked_lock(new_owner->owned_locks());
+    Mutex* locks = get_least_ranked_lock(new_owner->owned_locks());
     // Mutex::set_owner_implementation is a friend of Thread
 
     assert(this->rank() >= 0, "bad lock rank");
 
     // Deadlock avoidance rules require us to acquire Mutexes only in

@@ -413,15 +413,15 @@
     assert(old_owner == Thread::current(), "removing the owner thread of an unowned mutex");
 
     _owner = NULL; // set the owner
 
 #ifdef ASSERT
-    Monitor *locks = old_owner->owned_locks();
+    Mutex* locks = old_owner->owned_locks();
 
     // remove "this" from the owned locks list
 
-    Monitor *prev = NULL;
+    Mutex* prev = NULL;
     bool found = false;
     for (; locks != NULL; prev = locks, locks = locks->next()) {
       if (locks == this) {
         found = true;
         break;

@@ -438,11 +438,11 @@
   }
 }
 
 
 // Factored out common sanity checks for locking mutex'es. Used by lock() and try_lock()
-void Monitor::check_prelock_state(Thread *thread, bool safepoint_check) {
+void Mutex::check_prelock_state(Thread *thread, bool safepoint_check) {
   if (safepoint_check) {
     assert((!thread->is_active_Java_thread() || ((JavaThread *)thread)->thread_state() == _thread_in_vm)
            || rank() == Mutex::special, "wrong thread state for using locks");
     if (thread->is_VM_thread() && !allow_vm_block()) {
       fatal("VM thread using lock %s (not allowed to block on)", name());

@@ -452,11 +452,11 @@
   }
   assert(!os::ThreadCrashProtection::is_crash_protected(thread),
          "locking not allowed when crash protection is set");
 }
 
-void Monitor::check_block_state(Thread *thread) {
+void Mutex::check_block_state(Thread *thread) {
   if (!_allow_vm_block && thread->is_VM_thread()) {
     warning("VM thread blocked on lock");
     print();
     BREAKPOINT;
   }
< prev index next >