< prev index next >

src/os/aix/vm/os_aix.cpp

Print this page




2701 
2702 //
2703 // Handler function invoked when a thread's execution is suspended or
2704 // resumed. We have to be careful that only async-safe functions are
2705 // called here (Note: most pthread functions are not async safe and
2706 // should be avoided.)
2707 //
2708 // Note: sigwait() is a more natural fit than sigsuspend() from an
2709 // interface point of view, but sigwait() prevents the signal hander
2710 // from being run. libpthread would get very confused by not having
2711 // its signal handlers run and prevents sigwait()'s use with the
2712 // mutex granting granting signal.
2713 //
2714 // Currently only ever called on the VMThread and JavaThreads (PC sampling).
2715 //
2716 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   // after sigsuspend.
2719   int old_errno = errno;
2720 
2721   Thread* thread = Thread::current();
2722   OSThread* osthread = thread->osthread();










2723   assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");


2724 
2725   os::SuspendResume::State current = osthread->sr.state();
2726   if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
2727     suspend_save_context(osthread, siginfo, context);
2728 
2729     // attempt to switch the state, we assume we had a SUSPEND_REQUEST
2730     os::SuspendResume::State state = osthread->sr.suspended();
2731     if (state == os::SuspendResume::SR_SUSPENDED) {
2732       sigset_t suspend_set;  // signals for sigsuspend()
2733 
2734       // get current set of blocked signals and unblock resume signal
2735       pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
2736       sigdelset(&suspend_set, SR_signum);
2737 
2738       // wait here until we are resumed
2739       while (1) {
2740         sigsuspend(&suspend_set);
2741 
2742         os::SuspendResume::State result = osthread->sr.running();
2743         if (result == os::SuspendResume::SR_RUNNING) {




2701 
2702 //
2703 // Handler function invoked when a thread's execution is suspended or
2704 // resumed. We have to be careful that only async-safe functions are
2705 // called here (Note: most pthread functions are not async safe and
2706 // should be avoided.)
2707 //
2708 // Note: sigwait() is a more natural fit than sigsuspend() from an
2709 // interface point of view, but sigwait() prevents the signal hander
2710 // from being run. libpthread would get very confused by not having
2711 // its signal handlers run and prevents sigwait()'s use with the
2712 // mutex granting granting signal.
2713 //
2714 // Currently only ever called on the VMThread and JavaThreads (PC sampling).
2715 //
2716 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   // after sigsuspend.
2719   int old_errno = errno;
2720 
2721   Thread* thread = Thread::current_or_null_safe();
2722   assert(thread != NULL, "Missing current thread in SR_handler");
2723 
2724   // On some systems we have seen signal delivery get "stuck" until the signal
2725   // mask is changed as part of thread termination. Check the current thread
2726   // has not already terminated (via SR_lock()) - else the following assertion
2727   // will fail because the thread is no longer a JavaThread as the ~JavaThread 
2728   // destructor has completed.
2729 
2730   if (thread->SR_lock() == NULL)
2731     return;
2732 
2733   assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
2734 
2735   OSThread* osthread = thread->osthread();
2736 
2737   os::SuspendResume::State current = osthread->sr.state();
2738   if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
2739     suspend_save_context(osthread, siginfo, context);
2740 
2741     // attempt to switch the state, we assume we had a SUSPEND_REQUEST
2742     os::SuspendResume::State state = osthread->sr.suspended();
2743     if (state == os::SuspendResume::SR_SUSPENDED) {
2744       sigset_t suspend_set;  // signals for sigsuspend()
2745 
2746       // get current set of blocked signals and unblock resume signal
2747       pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
2748       sigdelset(&suspend_set, SR_signum);
2749 
2750       // wait here until we are resumed
2751       while (1) {
2752         sigsuspend(&suspend_set);
2753 
2754         os::SuspendResume::State result = osthread->sr.running();
2755         if (result == os::SuspendResume::SR_RUNNING) {


< prev index next >