--- 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);