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

8289003: JavaThread::check_is_terminated() implementation should rely on Thread-SMR #9502

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/hotspot/share/runtime/javaThread.cpp
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
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
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