672 // self-suspend after the lock_without_safepoint_check() call
673 // below because we are often called during transitions while
674 // we hold different locks. That would leave us suspended while
675 // holding a resource which results in deadlocks.
676 thread->set_thread_state(_thread_blocked);
677
678 // It is not safe to suspend a thread if we discover it is in _thread_in_native_trans. Hence,
679 // the safepoint code might still be waiting for it to block. We need to change the state here,
680 // so it can see that it is at a safepoint.
681
682 // Block until the safepoint operation is completed.
683 Threads_lock->lock_without_safepoint_check();
684
685 // Restore state
686 thread->set_thread_state(state);
687
688 Threads_lock->unlock();
689 break;
690
691 default:
692 fatal(err_msg("Illegal threadstate encountered: %d", state));
693 }
694
695 // Check for pending. async. exceptions or suspends - except if the
696 // thread was blocked inside the VM. has_special_runtime_exit_condition()
697 // is called last since it grabs a lock and we only want to do that when
698 // we must.
699 //
700 // Note: we never deliver an async exception at a polling point as the
701 // compiler may not have an exception handler for it. The polling
702 // code will notice the async and deoptimize and the exception will
703 // be delivered. (Polling at a return point is ok though). Sure is
704 // a lot of bother for a deprecated feature...
705 //
706 // We don't deliver an async exception if the thread state is
707 // _thread_in_native_trans so JNI functions won't be called with
708 // a surprising pending exception. If the thread state is going back to java,
709 // async exception is checked in check_special_condition_for_native_trans().
710
711 if (state != _thread_blocked_trans &&
712 state != _thread_in_vm_trans &&
756 ThreadSafepointState *cur_state;
757 ResourceMark rm;
758 for(JavaThread *cur_thread = Threads::first(); cur_thread;
759 cur_thread = cur_thread->next()) {
760 cur_state = cur_thread->safepoint_state();
761
762 if (cur_thread->thread_state() != _thread_blocked &&
763 ((reason == _spinning_timeout && cur_state->is_running()) ||
764 (reason == _blocking_timeout && !cur_state->has_called_back()))) {
765 tty->print("# ");
766 cur_thread->print();
767 tty->cr();
768 }
769 }
770 tty->print_cr("# SafepointSynchronize::begin: (End of list)");
771 }
772
773 // To debug the long safepoint, specify both DieOnSafepointTimeout &
774 // ShowMessageBoxOnError.
775 if (DieOnSafepointTimeout) {
776 char msg[1024];
777 VM_Operation *op = VMThread::vm_operation();
778 sprintf(msg, "Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.",
779 SafepointTimeoutDelay,
780 op != NULL ? op->name() : "no vm operation");
781 fatal(msg);
782 }
783 }
784
785
786 // -------------------------------------------------------------------------------------------------------
787 // Implementation of ThreadSafepointState
788
789 ThreadSafepointState::ThreadSafepointState(JavaThread *thread) {
790 _thread = thread;
791 _type = _running;
792 _has_called_back = false;
793 _at_poll_safepoint = false;
794 }
795
796 void ThreadSafepointState::create(JavaThread *thread) {
797 ThreadSafepointState *state = new ThreadSafepointState(thread);
798 thread->set_safepoint_state(state);
799 }
800
801 void ThreadSafepointState::destroy(JavaThread *thread) {
|
672 // self-suspend after the lock_without_safepoint_check() call
673 // below because we are often called during transitions while
674 // we hold different locks. That would leave us suspended while
675 // holding a resource which results in deadlocks.
676 thread->set_thread_state(_thread_blocked);
677
678 // It is not safe to suspend a thread if we discover it is in _thread_in_native_trans. Hence,
679 // the safepoint code might still be waiting for it to block. We need to change the state here,
680 // so it can see that it is at a safepoint.
681
682 // Block until the safepoint operation is completed.
683 Threads_lock->lock_without_safepoint_check();
684
685 // Restore state
686 thread->set_thread_state(state);
687
688 Threads_lock->unlock();
689 break;
690
691 default:
692 fatal("Illegal threadstate encountered: %d", state);
693 }
694
695 // Check for pending. async. exceptions or suspends - except if the
696 // thread was blocked inside the VM. has_special_runtime_exit_condition()
697 // is called last since it grabs a lock and we only want to do that when
698 // we must.
699 //
700 // Note: we never deliver an async exception at a polling point as the
701 // compiler may not have an exception handler for it. The polling
702 // code will notice the async and deoptimize and the exception will
703 // be delivered. (Polling at a return point is ok though). Sure is
704 // a lot of bother for a deprecated feature...
705 //
706 // We don't deliver an async exception if the thread state is
707 // _thread_in_native_trans so JNI functions won't be called with
708 // a surprising pending exception. If the thread state is going back to java,
709 // async exception is checked in check_special_condition_for_native_trans().
710
711 if (state != _thread_blocked_trans &&
712 state != _thread_in_vm_trans &&
756 ThreadSafepointState *cur_state;
757 ResourceMark rm;
758 for(JavaThread *cur_thread = Threads::first(); cur_thread;
759 cur_thread = cur_thread->next()) {
760 cur_state = cur_thread->safepoint_state();
761
762 if (cur_thread->thread_state() != _thread_blocked &&
763 ((reason == _spinning_timeout && cur_state->is_running()) ||
764 (reason == _blocking_timeout && !cur_state->has_called_back()))) {
765 tty->print("# ");
766 cur_thread->print();
767 tty->cr();
768 }
769 }
770 tty->print_cr("# SafepointSynchronize::begin: (End of list)");
771 }
772
773 // To debug the long safepoint, specify both DieOnSafepointTimeout &
774 // ShowMessageBoxOnError.
775 if (DieOnSafepointTimeout) {
776 VM_Operation *op = VMThread::vm_operation();
777 fatal("Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.",
778 SafepointTimeoutDelay,
779 op != NULL ? op->name() : "no vm operation");
780 }
781 }
782
783
784 // -------------------------------------------------------------------------------------------------------
785 // Implementation of ThreadSafepointState
786
787 ThreadSafepointState::ThreadSafepointState(JavaThread *thread) {
788 _thread = thread;
789 _type = _running;
790 _has_called_back = false;
791 _at_poll_safepoint = false;
792 }
793
794 void ThreadSafepointState::create(JavaThread *thread) {
795 ThreadSafepointState *state = new ThreadSafepointState(thread);
796 thread->set_safepoint_state(state);
797 }
798
799 void ThreadSafepointState::destroy(JavaThread *thread) {
|