1708 pd_initialize();
1709 }
1710
1711 JavaThread::JavaThread(bool is_attaching_via_jni) :
1712 Thread() {
1713 initialize();
1714 if (is_attaching_via_jni) {
1715 _jni_attach_state = _attaching_via_jni;
1716 } else {
1717 _jni_attach_state = _not_attaching_via_jni;
1718 }
1719 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1720 }
1721
1722
1723 // interrupt support
1724
1725 void JavaThread::interrupt() {
1726 debug_only(check_for_dangling_thread_pointer(this);)
1727
1728 if (!osthread()->interrupted()) {
1729 osthread()->set_interrupted(true);
1730 // More than one thread can get here with the same value of osthread,
1731 // resulting in multiple notifications. We do, however, want the store
1732 // to interrupted() to be visible to other threads before we execute unpark().
1733 OrderAccess::fence();
1734
1735 // For JavaThread::sleep. Historically we only unpark if changing to the interrupted
1736 // state, in contrast to the other events below. Not clear exactly why.
1737 _SleepEvent->unpark();
1738 }
1739
1740 // For JSR166. Unpark even if interrupt status already was set.
1741 parker()->unpark();
1742
1743 // For ObjectMonitor and JvmtiRawMonitor
1744 _ParkEvent->unpark();
1745 }
1746
1747
1748 bool JavaThread::is_interrupted(bool clear_interrupted) {
1749 debug_only(check_for_dangling_thread_pointer(this);)
1750 bool interrupted = osthread()->interrupted();
1751
1752 // NOTE that since there is no "lock" around the interrupt and
1753 // is_interrupted operations, there is the possibility that the
1754 // interrupted flag (in osThread) will be "false" but that the
1755 // low-level events will be in the signaled state. This is
1756 // intentional. The effect of this is that Object.wait() and
1757 // LockSupport.park() will appear to have a spurious wakeup, which
1758 // is allowed and not harmful, and the possibility is so rare that
1759 // it is not worth the added complexity to add yet another lock.
1760 // For the sleep event an explicit reset is performed on entry
1761 // to JavaThread::sleep, so there is no early return. It has also been
1762 // recommended not to put the interrupted flag into the "event"
1763 // structure because it hides the issue.
1764 if (interrupted && clear_interrupted) {
1765 osthread()->set_interrupted(false);
1766 // consider thread->_SleepEvent->reset() ... optional optimization
1767 }
1768
1769 return interrupted;
1770 }
1771
1772 bool JavaThread::reguard_stack(address cur_sp) {
1773 if (_stack_guard_state != stack_guard_yellow_reserved_disabled
1774 && _stack_guard_state != stack_guard_reserved_disabled) {
1775 return true; // Stack already guarded or guard pages not needed.
1776 }
1777
1778 if (register_stack_overflow()) {
1779 // For those architectures which have separate register and
1780 // memory stacks, we must check the register stack to see if
1781 // it has overflowed.
1782 return false;
1783 }
1784
1785 // Java code never executes within the yellow zone: the latter is only
1786 // there to provoke an exception during stack banging. If java code
2400 Deoptimization::deoptimize(this, compiled_frame, ®_map);
2401 }
2402 }
2403 }
2404
2405 // Set async. pending exception in thread.
2406 set_pending_async_exception(java_throwable);
2407
2408 if (log_is_enabled(Info, exceptions)) {
2409 ResourceMark rm;
2410 log_info(exceptions)("Pending Async. exception installed of type: %s",
2411 InstanceKlass::cast(_pending_async_exception->klass())->external_name());
2412 }
2413 // for AbortVMOnException flag
2414 Exceptions::debug_check_abort(_pending_async_exception->klass()->external_name());
2415 }
2416 }
2417
2418
2419 // Interrupt thread so it will wake up from a potential wait()/sleep()/park()
2420 this->interrupt();
2421 }
2422
2423 // External suspension mechanism.
2424 //
2425 // Tell the VM to suspend a thread when ever it knows that it does not hold on
2426 // to any VM_locks and it is at a transition
2427 // Self-suspension will happen on the transition out of the vm.
2428 // Catch "this" coming in from JNIEnv pointers when the thread has been freed
2429 //
2430 // Guarantees on return:
2431 // + Target thread will not execute any new bytecode (that's why we need to
2432 // force a safepoint)
2433 // + Target thread will not enter any new monitors
2434 //
2435 void JavaThread::java_suspend() {
2436 ThreadsListHandle tlh;
2437 if (!tlh.includes(this) || threadObj() == NULL || is_exiting()) {
2438 return;
2439 }
|
1708 pd_initialize();
1709 }
1710
1711 JavaThread::JavaThread(bool is_attaching_via_jni) :
1712 Thread() {
1713 initialize();
1714 if (is_attaching_via_jni) {
1715 _jni_attach_state = _attaching_via_jni;
1716 } else {
1717 _jni_attach_state = _not_attaching_via_jni;
1718 }
1719 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1720 }
1721
1722
1723 // interrupt support
1724
1725 void JavaThread::interrupt() {
1726 debug_only(check_for_dangling_thread_pointer(this);)
1727
1728 // For Windows _interrupt_event
1729 osthread()->set_interrupted(true);
1730
1731 // For Thread.sleep
1732 _SleepEvent->unpark();
1733
1734 // For JSR166 LockSupport.park
1735 parker()->unpark();
1736
1737 // For ObjectMonitor and JvmtiRawMonitor
1738 _ParkEvent->unpark();
1739 }
1740
1741
1742 bool JavaThread::is_interrupted(bool clear_interrupted) {
1743 debug_only(check_for_dangling_thread_pointer(this);)
1744 bool interrupted = java_lang_Thread::interrupted(threadObj());
1745
1746 // NOTE that since there is no "lock" around the interrupt and
1747 // is_interrupted operations, there is the possibility that the
1748 // interrupted flag will be "false" but that the
1749 // low-level events will be in the signaled state. This is
1750 // intentional. The effect of this is that Object.wait() and
1751 // LockSupport.park() will appear to have a spurious wakeup, which
1752 // is allowed and not harmful, and the possibility is so rare that
1753 // it is not worth the added complexity to add yet another lock.
1754 // For the sleep event an explicit reset is performed on entry
1755 // to JavaThread::sleep, so there is no early return. It has also been
1756 // recommended not to put the interrupted flag into the "event"
1757 // structure because it hides the issue.
1758 // Also, because there is no lock, we must only clear the interrupt
1759 // state if we are going to report that we were interrupted; otherwise
1760 // an interrupt that happens just after we read the field would be lost.
1761 if (interrupted && clear_interrupted) {
1762 java_lang_Thread::set_interrupted(threadObj(), false);
1763 osthread()->set_interrupted(false);
1764 }
1765
1766 return interrupted;
1767 }
1768
1769 bool JavaThread::reguard_stack(address cur_sp) {
1770 if (_stack_guard_state != stack_guard_yellow_reserved_disabled
1771 && _stack_guard_state != stack_guard_reserved_disabled) {
1772 return true; // Stack already guarded or guard pages not needed.
1773 }
1774
1775 if (register_stack_overflow()) {
1776 // For those architectures which have separate register and
1777 // memory stacks, we must check the register stack to see if
1778 // it has overflowed.
1779 return false;
1780 }
1781
1782 // Java code never executes within the yellow zone: the latter is only
1783 // there to provoke an exception during stack banging. If java code
2397 Deoptimization::deoptimize(this, compiled_frame, ®_map);
2398 }
2399 }
2400 }
2401
2402 // Set async. pending exception in thread.
2403 set_pending_async_exception(java_throwable);
2404
2405 if (log_is_enabled(Info, exceptions)) {
2406 ResourceMark rm;
2407 log_info(exceptions)("Pending Async. exception installed of type: %s",
2408 InstanceKlass::cast(_pending_async_exception->klass())->external_name());
2409 }
2410 // for AbortVMOnException flag
2411 Exceptions::debug_check_abort(_pending_async_exception->klass()->external_name());
2412 }
2413 }
2414
2415
2416 // Interrupt thread so it will wake up from a potential wait()/sleep()/park()
2417 java_lang_Thread::set_interrupted(threadObj(), true);
2418 this->interrupt();
2419 }
2420
2421 // External suspension mechanism.
2422 //
2423 // Tell the VM to suspend a thread when ever it knows that it does not hold on
2424 // to any VM_locks and it is at a transition
2425 // Self-suspension will happen on the transition out of the vm.
2426 // Catch "this" coming in from JNIEnv pointers when the thread has been freed
2427 //
2428 // Guarantees on return:
2429 // + Target thread will not execute any new bytecode (that's why we need to
2430 // force a safepoint)
2431 // + Target thread will not enter any new monitors
2432 //
2433 void JavaThread::java_suspend() {
2434 ThreadsListHandle tlh;
2435 if (!tlh.includes(this) || threadObj() == NULL || is_exiting()) {
2436 return;
2437 }
|