2684 // and blocks in sigsuspend until continued |
2684 // and blocks in sigsuspend until continued |
2685 // - resume: |
2685 // - resume: |
2686 // - sets target osthread state to continue |
2686 // - sets target osthread state to continue |
2687 // - sends signal to end the sigsuspend loop in the SR_handler |
2687 // - sends signal to end the sigsuspend loop in the SR_handler |
2688 // |
2688 // |
2689 // Note that the SR_lock plays no role in this suspend/resume protocol. |
2689 // Note that the SR_lock plays no role in this suspend/resume protocol, |
|
2690 // but is checked for NULL in SR_handler as a thread termination indicator. |
2690 // |
2691 // |
2691 |
2692 |
2692 static void resume_clear_context(OSThread *osthread) { |
2693 static void resume_clear_context(OSThread *osthread) { |
2693 osthread->set_ucontext(NULL); |
2694 osthread->set_ucontext(NULL); |
2694 osthread->set_siginfo(NULL); |
2695 osthread->set_siginfo(NULL); |
2716 static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) { |
2717 static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) { |
2717 // Save and restore errno to avoid confusing native code with EINTR |
2718 // Save and restore errno to avoid confusing native code with EINTR |
2718 // after sigsuspend. |
2719 // after sigsuspend. |
2719 int old_errno = errno; |
2720 int old_errno = errno; |
2720 |
2721 |
2721 Thread* thread = Thread::current(); |
2722 Thread* thread = Thread::current_or_null_safe(); |
|
2723 assert(thread != NULL, "Missing current thread in SR_handler"); |
|
2724 |
|
2725 // On some systems we have seen signal delivery get "stuck" until the signal |
|
2726 // mask is changed as part of thread termination. Check that the current thread |
|
2727 // has not already terminated (via SR_lock()) - else the following assertion |
|
2728 // will fail because the thread is no longer a JavaThread as the ~JavaThread |
|
2729 // destructor has completed. |
|
2730 |
|
2731 if (thread->SR_lock() == NULL) { |
|
2732 return; |
|
2733 } |
|
2734 |
|
2735 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); |
|
2736 |
2722 OSThread* osthread = thread->osthread(); |
2737 OSThread* osthread = thread->osthread(); |
2723 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread"); |
|
2724 |
2738 |
2725 os::SuspendResume::State current = osthread->sr.state(); |
2739 os::SuspendResume::State current = osthread->sr.state(); |
2726 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { |
2740 if (current == os::SuspendResume::SR_SUSPEND_REQUEST) { |
2727 suspend_save_context(osthread, siginfo, context); |
2741 suspend_save_context(osthread, siginfo, context); |
2728 |
2742 |