Skip to content

Commit

Permalink
8289003: JavaThread::check_is_terminated() implementation should rely…
Browse files Browse the repository at this point in the history
… on Thread-SMR

Reviewed-by: dholmes, pchilanomate
  • Loading branch information
Daniel D. Daugherty committed Jul 16, 2022
1 parent 2342684 commit 441c33f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,10 @@ bool JavaThread::is_interrupted(bool clear_interrupted) {
void JavaThread::block_if_vm_exited() {
if (_terminated == _vm_exited) {
// _vm_exited is set at safepoint, and Threads_lock is never released
// we will block here forever.
// so we will block here forever.
// Here we can be doing a jump from a safe state to an unsafe state without
// proper transition, but it happens after the final safepoint has begun.
// proper transition, but it happens after the final safepoint has begun so
// this jump won't cause any safepoint problems.
set_thread_state(_thread_in_vm);
Threads_lock->lock();
ShouldNotReachHere();
Expand Down
8 changes: 3 additions & 5 deletions src/hotspot/share/runtime/javaThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,10 @@ class JavaThread: public Thread {
bool is_exiting() const;
// thread's GC barrier is NOT detached and thread is NOT terminated
bool is_oop_safe() const;
// thread is terminated (no longer on the threads list); we compare
// against the three non-terminated values so that a freed JavaThread
// will also be considered terminated.
// thread is terminated (no longer on the threads list); the thread must
// be protected by a ThreadsListHandle to avoid potential crashes.
bool check_is_terminated(TerminatedTypes l_terminated) const {
return l_terminated != _not_terminated && l_terminated != _thread_exiting &&
l_terminated != _thread_gc_barrier_detached;
return l_terminated == _thread_terminated || l_terminated == _vm_exited;
}
bool is_terminated() const;
void set_terminated(TerminatedTypes t);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/vmOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ int VM_Exit::set_vm_exited() {
_shutdown_thread = thr_cur;
_vm_exited = true; // global flag
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) {
if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
if (thr != thr_cur && thr->thread_state() == _thread_in_native) {
++num_active;
thr->set_terminated(JavaThread::_vm_exited); // per-thread flag
}
Expand Down Expand Up @@ -495,7 +495,7 @@ void VM_Exit::wait_if_vm_exited() {
if (_vm_exited &&
Thread::current_or_null() != _shutdown_thread) {
// _vm_exited is set at safepoint, and the Threads_lock is never released
// we will block here until the process dies
// so we will block here until the process dies.
Threads_lock->lock();
ShouldNotReachHere();
}
Expand Down

1 comment on commit 441c33f

@openjdk-notifier
Copy link

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.