--- old/src/os/aix/vm/os_aix.cpp 2016-08-02 20:56:46.161211866 -0400 +++ new/src/os/aix/vm/os_aix.cpp 2016-08-02 20:56:44.821136189 -0400 @@ -2718,10 +2718,22 @@ // after sigsuspend. int old_errno = errno; - Thread* thread = Thread::current(); - OSThread* osthread = thread->osthread(); + Thread* thread = Thread::current_or_null_safe(); + assert(thread != NULL, "Missing current thread in SR_handler"); + + // On some systems we have seen signal delivery get "stuck" until the signal + // mask is changed as part of thread termination. Check the current thread + // has not already terminated (via SR_lock()) - else the following assertion + // will fail because the thread is no longer a JavaThread as the ~JavaThread + // destructor has completed. + + if (thread->SR_lock() == NULL) + return; + assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); + OSThread* osthread = thread->osthread(); + os::SuspendResume::State current = osthread->sr.state(); if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { suspend_save_context(osthread, siginfo, context); --- old/src/os/bsd/vm/os_bsd.cpp 2016-08-02 20:56:50.357448837 -0400 +++ new/src/os/bsd/vm/os_bsd.cpp 2016-08-02 20:56:48.989371579 -0400 @@ -2746,10 +2746,22 @@ // after sigsuspend. int old_errno = errno; - Thread* thread = Thread::current(); - OSThread* osthread = thread->osthread(); + Thread* thread = Thread::current_or_null_safe(); + assert(thread != NULL, "Missing current thread in SR_handler"); + + // On some systems we have seen signal delivery get "stuck" until the signal + // mask is changed as part of thread termination. Check the current thread + // has not already terminated (via SR_lock()) - else the following assertion + // will fail because the thread is no longer a JavaThread as the ~JavaThread + // destructor has completed. + + if (thread->SR_lock() == NULL) + return; + assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); + OSThread* osthread = thread->osthread(); + os::SuspendResume::State current = osthread->sr.state(); if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { suspend_save_context(osthread, siginfo, context); --- old/src/os/linux/vm/os_linux.cpp 2016-08-02 20:56:54.541685131 -0400 +++ new/src/os/linux/vm/os_linux.cpp 2016-08-02 20:56:53.185608550 -0400 @@ -4004,9 +4004,20 @@ Thread* thread = Thread::current_or_null_safe(); assert(thread != NULL, "Missing current thread in SR_handler"); - OSThread* osthread = thread->osthread(); + + // On some systems we have seen signal delivery get "stuck" until the signal + // mask is changed as part of thread termination. Check the current thread + // has not already terminated (via SR_lock()) - else the following assertion + // will fail because the thread is no longer a JavaThread as the ~JavaThread + // destructor has completed. + + if (thread->SR_lock() == NULL) + return; + assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); + OSThread* osthread = thread->osthread(); + os::SuspendResume::State current = osthread->sr.state(); if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { suspend_save_context(osthread, siginfo, context); --- old/src/os/solaris/vm/os_solaris.cpp 2016-08-02 20:56:58.985936108 -0400 +++ new/src/os/solaris/vm/os_solaris.cpp 2016-08-02 20:56:57.637859979 -0400 @@ -3590,9 +3590,22 @@ // after sigsuspend. int old_errno = errno; - OSThread* osthread = thread->osthread(); + assert(thread == Thread::current_or_null_safe(), "Incorrect thread context"); + assert(thread != NULL, "Missing current thread in SR_handler"); + + // On some systems we have seen signal delivery get "stuck" until the signal + // mask is changed as part of thread termination. Check the current thread + // has not already terminated (via SR_lock()) - else the following assertion + // will fail because the thread is no longer a JavaThread as the ~JavaThread + // destructor has completed. + + if (thread->SR_lock() == NULL) + return; + assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); + OSThread* osthread = thread->osthread(); + os::SuspendResume::State current = osthread->sr.state(); if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { suspend_save_context(osthread, uc); --- old/src/share/vm/runtime/thread.cpp 2016-08-02 20:57:03.214174887 -0400 +++ new/src/share/vm/runtime/thread.cpp 2016-08-02 20:57:01.830096725 -0400 @@ -374,11 +374,14 @@ delete handle_area(); delete metadata_handles(); + // SR_handler uses this as a termination indicator - + // needs to happen before os::free_thread() + delete _SR_lock; + _SR_lock = NULL; + // osthread() can be NULL, if creation of thread failed. if (osthread() != NULL) os::free_thread(osthread()); - delete _SR_lock; - // clear Thread::current if thread is deleting itself. // Needed to ensure JNI correctly detects non-attached threads. if (this == Thread::current()) {