Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8274282: Clarify special wait assert #5684

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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,