Skip to content
Permalink
Browse files
8274282: Clarify special wait assert
Reviewed-by: dholmes, pchilanomate
  • Loading branch information
coleenp committed Oct 5, 2021
1 parent bb0bab5 commit 90a5ae802e6ef0a6d0a5096a595b0680069960c3
Showing 2 changed files with 29 additions and 15 deletions.
@@ -384,14 +384,21 @@ void Mutex::check_rank(Thread* thread) {
if (owned_by_self()) {
// wait() case
Mutex* least = get_least_ranked_lock_besides_this(locks_owned);
// We enforce not holding locks of rank nosafepoint or lower while waiting.
// For JavaThreads, we enforce not holding locks of rank nosafepoint or lower while waiting
// because the held lock has a NoSafepointVerifier so waiting on a lower ranked lock will not be
// able to check for safepoints first with a TBIVM.
// For all threads, we enforce not holding the tty lock or below, since this could block progress also.
// Also "this" should be the monitor with lowest rank owned by this thread.
if (least != NULL && (least->rank() <= nosafepoint || least->rank() <= this->rank())) {
if (least != NULL && ((least->rank() <= Mutex::nosafepoint && thread->is_Java_thread()) ||
least->rank() <= Mutex::tty ||
least->rank() <= this->rank())) {
assert(false, "Attempting to wait on monitor %s/%d while holding lock %s/%d -- "
"possible deadlock. %s", name(), rank(), least->name(), least->rank(),
least->rank() <= this->rank() ?
"Should wait on the least ranked monitor from all owned locks." :
"Should not block(wait) while holding a lock of rank nosafepoint or below.");
thread->is_Java_thread() ?
"Should not block(wait) while holding a lock of rank nosafepoint or below." :
"Should not block(wait) while holding a lock of rank tty or below.");
}
} else {
// lock()/lock_without_safepoint_check()/try_lock() case
@@ -220,20 +220,27 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_nosafepoint,
monitor_rank_nosafepoint->unlock();
}

// NonJavaThreads can't wait while holding tty lock or below.
class VM_MutexWaitTTY : public VM_GTestExecuteAtSafepoint {
public:
void doit() {
Monitor* monitor_rank_tty = new Monitor(Mutex::tty, "monitor_rank_tty", Mutex::_safepoint_check_never);
Monitor* monitor_rank_event = new Monitor(Mutex::event, "monitor_rank_event", Mutex::_safepoint_check_never);

monitor_rank_tty->lock_without_safepoint_check();
monitor_rank_event->lock_without_safepoint_check();
monitor_rank_event->wait_without_safepoint_check(1);
monitor_rank_event->unlock();
monitor_rank_tty->unlock();
}
};

TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_event_tty,
".* Attempting to wait on monitor monitor_rank_event/0 while holding lock monitor_rank_tty/.*"
"-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank nosafepoint or below.") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);

Monitor* monitor_rank_tty = new Monitor(Mutex::tty, "monitor_rank_tty", Mutex::_safepoint_check_never);
Monitor* monitor_rank_event = new Monitor(Mutex::event, "monitor_rank_event", Mutex::_safepoint_check_never);

monitor_rank_tty->lock_without_safepoint_check();
monitor_rank_event->lock_without_safepoint_check();
monitor_rank_event->wait_without_safepoint_check(1);
monitor_rank_event->unlock();
monitor_rank_tty->unlock();
"-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank tty or below.") {
VM_MutexWaitTTY op;
ThreadInVMfromNative invm(JavaThread::current());
VMThread::execute(&op);
}

TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_tty_nosafepoint,

1 comment on commit 90a5ae8

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 90a5ae8 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.