< prev index next >

src/hotspot/share/runtime/mutex.cpp

Print this page

        

@@ -138,56 +138,64 @@
 void Monitor::notify_all() {
   assert_owner(Thread::current());
   _lock.notify_all();
 }
 
-bool Monitor::wait(bool no_safepoint_check, long timeout,
-                   bool as_suspend_equivalent) {
-  // Make sure safepoint checking is used properly.
-  assert(!(_safepoint_check_required == Monitor::_safepoint_check_never && no_safepoint_check == false),
-         "This lock should never have a safepoint check: %s", name());
-  assert(!(_safepoint_check_required == Monitor::_safepoint_check_always && no_safepoint_check == true),
-         "This lock should always have a safepoint check: %s", name());
-
-  // timeout is in milliseconds - with zero meaning never timeout
-  assert(timeout >= 0, "negative timeout");
-
-  Thread * const self = Thread::current();
-  assert_owner(self);
-
-  // as_suspend_equivalent logically implies !no_safepoint_check
-  guarantee(!as_suspend_equivalent || !no_safepoint_check, "invariant");
-  // !no_safepoint_check logically implies java_thread
-  guarantee(no_safepoint_check || self->is_Java_thread(), "invariant");
-
 #ifdef ASSERT
-  Monitor * least = get_least_ranked_lock_besides_this(self->owned_locks());
+void Monitor::assert_wait_lock_state(Thread* self) {
+  Monitor* 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());
     assert(false, "Shouldn't block(wait) while holding a lock of rank special");
   }
+}
 #endif // ASSERT
 
+bool Monitor::wait_without_safepoint_check(long timeout) {
+  // Make sure safepoint checking is used properly.
+  assert(_safepoint_check_required != Monitor::_safepoint_check_always,
+         "This lock should never have a safepoint check: %s", name());
+
+  Thread * const self = Thread::current();
+  assert_owner(self);
+  assert_wait_lock_state(self);
+
+  // conceptually set the owner to NULL in anticipation of
+  // abdicating the lock in wait
+  set_owner(NULL);
+  int wait_status = _lock.wait(timeout);
+  set_owner(self);
+  return wait_status != 0;          // return true IFF timeout
+}
+
+bool Monitor::wait(long timeout, bool as_suspend_equivalent) {
+  // Make sure safepoint checking is used properly.
+  assert(_safepoint_check_required != Monitor::_safepoint_check_never,
+         "This lock should always have a safepoint check: %s", name());
+
+  // timeout is in milliseconds - with zero meaning never timeout
+  assert(timeout >= 0, "negative timeout");
+
+  Thread* const self = Thread::current();
+  assert_owner(self);
+
+  // Safepoint checking logically implies java_thread
+  guarantee(self->is_Java_thread(), "invariant");
+  assert_wait_lock_state(self);
+
 #ifdef CHECK_UNHANDLED_OOPS
   // Clear unhandled oops in JavaThreads so we get a crash right away.
-  if (self->is_Java_thread() && !no_safepoint_check) {
     self->clear_unhandled_oops();
-  }
 #endif // CHECK_UNHANDLED_OOPS
 
   int wait_status;
   // conceptually set the owner to NULL in anticipation of
   // abdicating the lock in wait
   set_owner(NULL);
-  if (no_safepoint_check) {
-    wait_status = _lock.wait(timeout);
-    set_owner(self);
-  } else {
-    assert(self->is_Java_thread(), "invariant");
     JavaThread *jt = (JavaThread *)self;
     Monitor* in_flight_monitor = NULL;
 
     {
       ThreadBlockInVMWithDeadlockCheck tbivmdc(jt, &in_flight_monitor);

@@ -219,11 +227,11 @@
       // Conceptually reestablish ownership of the lock.
       set_owner(self);
     } else {
       lock(self);
     }
-  }
+
   return wait_status != 0;          // return true IFF timeout
 }
 
 
 // Temporary JVM_RawMonitor* support.
< prev index next >