767 |
767 |
768 // Check for a thread that is suspended. Note that thread resume tries |
768 // Check for a thread that is suspended. Note that thread resume tries |
769 // to grab the Threads_lock which we own here, so a thread cannot be |
769 // to grab the Threads_lock which we own here, so a thread cannot be |
770 // resumed during safepoint synchronization. |
770 // resumed during safepoint synchronization. |
771 |
771 |
772 // We check with locking because another thread that has not yet |
772 // We check to see if this thread is suspended without locking to |
773 // synchronized may be trying to suspend this one. |
773 // avoid deadlocking with a third thread that is waiting for this |
774 bool is_suspended = _thread->is_any_suspended_with_lock(); |
774 // thread to be suspended. The third thread can notice the safepoint |
|
775 // that we're trying to start at the beginning of its SR_lock->wait() |
|
776 // call. If that happens, then the third thread will block on the |
|
777 // safepoint while still holding the underlying SR_lock. We won't be |
|
778 // able to get the SR_lock and we'll deadlock. |
|
779 // |
|
780 // We don't need to grab the SR_lock here for two reasons: |
|
781 // 1) The suspend flags are both volatile and are set with an |
|
782 // Atomic::cmpxchg() call so we should see the suspended |
|
783 // state right away. |
|
784 // 2) We're being called from the safepoint polling loop; if |
|
785 // we don't see the suspended state on this iteration, then |
|
786 // we'll come around again. |
|
787 // |
|
788 bool is_suspended = _thread->is_ext_suspended(); |
775 if (is_suspended) { |
789 if (is_suspended) { |
776 roll_forward(_at_safepoint); |
790 roll_forward(_at_safepoint); |
777 return; |
791 return; |
778 } |
792 } |
779 |
793 |