< prev index next >
src/hotspot/share/runtime/mutex.cpp
Print this page
@@ -824,10 +824,22 @@
assert(ILocked(), "invariant");
return WasOnWaitSet != 0; // return true IFF timeout
}
+#ifndef PRODUCT
+void Monitor::check_safepoint_state(Thread* Self, bool do_safepoint_check) {
+ // If you check for safepoint, verify that the lock wasn't created with safepoint_check_never
+ // to allow safepoint_check_sometimes.
+ SafepointCheckRequired not_allowed = do_safepoint_check ?
+ Monitor::_safepoint_check_never :
+ Monitor::_safepoint_check_always;
+ assert(!Self->is_Java_thread() || _safepoint_check_required != not_allowed,
+ "This lock should %s have a safepoint check: %s",
+ _safepoint_check_required ? "always" : "never", name());
+}
+#endif
// ON THE VMTHREAD SNEAKING PAST HELD LOCKS:
// In particular, there are certain types of global lock that may be held
// by a Java thread while it is blocked at a safepoint but before it has
// written the _owner field. These locks may be sneakily acquired by the
@@ -862,12 +874,11 @@
// sneaking or dependence on any any clever invariants or subtle implementation properties
// of Mutex-Monitor and instead directly address the underlying design flaw.
void Monitor::lock(Thread * Self) {
// Ensure that the Monitor requires/allows safepoint checks.
- assert(_safepoint_check_required != Monitor::_safepoint_check_never,
- "This lock should never have a safepoint check: %s", name());
+ check_safepoint_state(Self, true);
#ifdef CHECK_UNHANDLED_OOPS
// Clear unhandled oops so we get a crash right away. Only clear for non-vm
// or GC threads.
if (Self->is_Java_thread()) {
@@ -924,12 +935,11 @@
// that is guaranteed not to block while running inside the VM. If this is called with
// thread state set to be in VM, the safepoint synchronization code will deadlock!
void Monitor::lock_without_safepoint_check(Thread * Self) {
// Ensure that the Monitor does not require or allow safepoint checks.
- assert(_safepoint_check_required != Monitor::_safepoint_check_always,
- "This lock should always have a safepoint check: %s", name());
+ check_safepoint_state(Self, false);
assert(_owner != Self, "invariant");
ILock(Self);
assert(_owner == NULL, "invariant");
set_owner(Self);
}
@@ -1055,17 +1065,14 @@
IUnlock(false);
}
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());
-
Thread * const Self = Thread::current();
+
+ // Make sure safepoint checking is used properly.
+ check_safepoint_state(Self, !no_safepoint_check);
assert(_owner == Self, "invariant");
assert(ILocked(), "invariant");
// as_suspend_equivalent logically implies !no_safepoint_check
guarantee(!as_suspend_equivalent || !no_safepoint_check, "invariant");
@@ -1085,11 +1092,11 @@
int wait_status;
// conceptually set the owner to NULL in anticipation of
// abdicating the lock in wait
set_owner(NULL);
- if (no_safepoint_check) {
+ if (no_safepoint_check || !Self->is_Java_thread()) {
wait_status = IWait(Self, timeout);
} else {
assert(Self->is_Java_thread(), "invariant");
JavaThread *jt = (JavaThread *)Self;
< prev index next >