854 } |
854 } |
855 |
855 |
856 return true; |
856 return true; |
857 } |
857 } |
858 |
858 |
859 void Thread::interrupt(Thread* thread) { |
|
860 debug_only(check_for_dangling_thread_pointer(thread);) |
|
861 os::interrupt(thread); |
|
862 } |
|
863 |
|
864 bool Thread::is_interrupted(Thread* thread, bool clear_interrupted) { |
|
865 debug_only(check_for_dangling_thread_pointer(thread);) |
|
866 // Note: If clear_interrupted==false, this simply fetches and |
|
867 // returns the value of the field osthread()->interrupted(). |
|
868 return os::is_interrupted(thread, clear_interrupted); |
|
869 } |
|
870 |
|
871 |
|
872 // GC Support |
859 // GC Support |
873 bool Thread::claim_par_threads_do(uintx claim_token) { |
860 bool Thread::claim_par_threads_do(uintx claim_token) { |
874 uintx token = _threads_do_token; |
861 uintx token = _threads_do_token; |
875 if (token != claim_token) { |
862 if (token != claim_token) { |
876 uintx res = Atomic::cmpxchg(claim_token, &_threads_do_token, token); |
863 uintx res = Atomic::cmpxchg(claim_token, &_threads_do_token, token); |
1724 _jni_attach_state = _not_attaching_via_jni; |
1711 _jni_attach_state = _not_attaching_via_jni; |
1725 } |
1712 } |
1726 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor"); |
1713 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor"); |
1727 } |
1714 } |
1728 |
1715 |
|
1716 |
|
1717 // interrupt support |
|
1718 |
|
1719 void JavaThread::interrupt() { |
|
1720 debug_only(check_for_dangling_thread_pointer(this);) |
|
1721 |
|
1722 if (!osthread()->interrupted()) { |
|
1723 osthread()->set_interrupted(true); |
|
1724 // More than one thread can get here with the same value of osthread, |
|
1725 // resulting in multiple notifications. We do, however, want the store |
|
1726 // to interrupted() to be visible to other threads before we execute unpark(). |
|
1727 OrderAccess::fence(); |
|
1728 |
|
1729 // For JavaThread::sleep. Historically we only unpark if changing to the interrupted |
|
1730 // state, in contrast to the other events below. Not clear exactly why. |
|
1731 _SleepEvent->unpark(); |
|
1732 } |
|
1733 |
|
1734 // For JSR166. Unpark even if interrupt status already was set. |
|
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 = osthread()->interrupted(); |
|
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 (in osThread) 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 if (interrupted && clear_interrupted) { |
|
1759 osthread()->set_interrupted(false); |
|
1760 // consider thread->_SleepEvent->reset() ... optional optimization |
|
1761 } |
|
1762 |
|
1763 return interrupted; |
|
1764 } |
|
1765 |
1729 bool JavaThread::reguard_stack(address cur_sp) { |
1766 bool JavaThread::reguard_stack(address cur_sp) { |
1730 if (_stack_guard_state != stack_guard_yellow_reserved_disabled |
1767 if (_stack_guard_state != stack_guard_yellow_reserved_disabled |
1731 && _stack_guard_state != stack_guard_reserved_disabled) { |
1768 && _stack_guard_state != stack_guard_reserved_disabled) { |
1732 return true; // Stack already guarded or guard pages not needed. |
1769 return true; // Stack already guarded or guard pages not needed. |
1733 } |
1770 } |
3387 jlong newtime = os::javaTimeNanos(); |
3424 jlong newtime = os::javaTimeNanos(); |
3388 if (newtime - prevtime < 0) { |
3425 if (newtime - prevtime < 0) { |
3389 // time moving backwards, should only happen if no monotonic clock |
3426 // time moving backwards, should only happen if no monotonic clock |
3390 // not a guarantee() because JVM should not abort on kernel/glibc bugs |
3427 // not a guarantee() because JVM should not abort on kernel/glibc bugs |
3391 assert(!os::supports_monotonic_clock(), |
3428 assert(!os::supports_monotonic_clock(), |
3392 "unexpected time moving backwards detected in os::sleep()"); |
3429 "unexpected time moving backwards detected in JavaThread::sleep()"); |
3393 } else { |
3430 } else { |
3394 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC; |
3431 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC; |
3395 } |
3432 } |
3396 prevtime = newtime; |
3433 prevtime = newtime; |
3397 } |
3434 } |