314 virtual bool is_Java_thread() const { return false; }
315 virtual bool is_Compiler_thread() const { return false; }
316 virtual bool is_hidden_from_external_view() const { return false; }
317 virtual bool is_jvmti_agent_thread() const { return false; }
318 // True iff the thread can perform GC operations at a safepoint.
319 // Generally will be true only of VM thread and parallel GC WorkGang
320 // threads.
321 virtual bool is_GC_task_thread() const { return false; }
322 virtual bool is_Watcher_thread() const { return false; }
323 virtual bool is_ConcurrentGC_thread() const { return false; }
324 virtual bool is_Named_thread() const { return false; }
325 virtual bool is_Worker_thread() const { return false; }
326
327 // Casts
328 virtual WorkerThread* as_Worker_thread() const { return NULL; }
329
330 virtual char* name() const { return (char*)"Unknown thread"; }
331
332 // Returns the current thread
333 static inline Thread* current();
334
335 // Common thread operations
336 static void set_priority(Thread* thread, ThreadPriority priority);
337 static ThreadPriority get_priority(const Thread* const thread);
338 static void start(Thread* thread);
339 static void interrupt(Thread* thr);
340 static bool is_interrupted(Thread* thr, bool clear_interrupted);
341
342 void set_native_thread_name(const char *name) {
343 assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
344 os::set_native_thread_name(name);
345 }
346
347 ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
348 Monitor* SR_lock() const { return _SR_lock; }
349
350 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
351
352 void set_suspend_flag(SuspendFlags f) {
353 assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
661 static void muxRelease (volatile intptr_t * Lock) ;
662 };
663
664 // Inline implementation of Thread::current()
665 // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
666 // startup.
667 // ThreadLocalStorage::thread is warm -- it's called > 16K times in the same
668 // period. This is inlined in thread_<os_family>.inline.hpp.
669
670 inline Thread* Thread::current() {
671 #ifdef ASSERT
672 // This function is very high traffic. Define PARANOID to enable expensive
673 // asserts.
674 #ifdef PARANOID
675 // Signal handler should call ThreadLocalStorage::get_thread_slow()
676 Thread* t = ThreadLocalStorage::get_thread_slow();
677 assert(t != NULL && !t->is_inside_signal_handler(),
678 "Don't use Thread::current() inside signal handler");
679 #endif
680 #endif
681 Thread* thread = ThreadLocalStorage::thread();
682 assert(thread != NULL, "just checking");
683 return thread;
684 }
685
686 // Name support for threads. non-JavaThread subclasses with multiple
687 // uniquely named instances should derive from this.
688 class NamedThread: public Thread {
689 friend class VMStructs;
690 enum {
691 max_name_len = 64
692 };
693 private:
694 char* _name;
695 // log JavaThread being processed by oops_do
696 JavaThread* _processed_thread;
697
698 public:
699 NamedThread();
700 ~NamedThread();
701 // May only be called once per thread.
702 void set_name(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
703 virtual bool is_Named_thread() const { return true; }
1757 public:
1758 GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; }
1759 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; }
1760
1761 // clearing/querying jni attach status
1762 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
1763 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
1764 inline void set_done_attaching_via_jni();
1765 private:
1766 // This field is used to determine if a thread has claimed
1767 // a par_id: it is UINT_MAX if the thread has not claimed a par_id;
1768 // otherwise its value is the par_id that has been claimed.
1769 uint _claimed_par_id;
1770 public:
1771 uint get_claimed_par_id() { return _claimed_par_id; }
1772 void set_claimed_par_id(uint id) { _claimed_par_id = id;}
1773 };
1774
1775 // Inline implementation of JavaThread::current
1776 inline JavaThread* JavaThread::current() {
1777 Thread* thread = ThreadLocalStorage::thread();
1778 assert(thread != NULL && thread->is_Java_thread(), "just checking");
1779 return (JavaThread*)thread;
1780 }
1781
1782 inline CompilerThread* JavaThread::as_CompilerThread() {
1783 assert(is_Compiler_thread(), "just checking");
1784 return (CompilerThread*)this;
1785 }
1786
1787 inline bool JavaThread::stack_guard_zone_unused() {
1788 return _stack_guard_state == stack_guard_unused;
1789 }
1790
1791 inline bool JavaThread::stack_yellow_zone_disabled() {
1792 return _stack_guard_state == stack_guard_yellow_disabled;
1793 }
1794
1795 inline bool JavaThread::stack_yellow_zone_enabled() {
1796 #ifdef ASSERT
1797 if (os::uses_stack_guard_pages() &&
1798 !(DisablePrimordialThreadGuardPages && os::is_primordial_thread())) {
|
314 virtual bool is_Java_thread() const { return false; }
315 virtual bool is_Compiler_thread() const { return false; }
316 virtual bool is_hidden_from_external_view() const { return false; }
317 virtual bool is_jvmti_agent_thread() const { return false; }
318 // True iff the thread can perform GC operations at a safepoint.
319 // Generally will be true only of VM thread and parallel GC WorkGang
320 // threads.
321 virtual bool is_GC_task_thread() const { return false; }
322 virtual bool is_Watcher_thread() const { return false; }
323 virtual bool is_ConcurrentGC_thread() const { return false; }
324 virtual bool is_Named_thread() const { return false; }
325 virtual bool is_Worker_thread() const { return false; }
326
327 // Casts
328 virtual WorkerThread* as_Worker_thread() const { return NULL; }
329
330 virtual char* name() const { return (char*)"Unknown thread"; }
331
332 // Returns the current thread
333 static inline Thread* current();
334 static inline Thread* current_or_null();
335
336 // Common thread operations
337 static void set_priority(Thread* thread, ThreadPriority priority);
338 static ThreadPriority get_priority(const Thread* const thread);
339 static void start(Thread* thread);
340 static void interrupt(Thread* thr);
341 static bool is_interrupted(Thread* thr, bool clear_interrupted);
342
343 void set_native_thread_name(const char *name) {
344 assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
345 os::set_native_thread_name(name);
346 }
347
348 ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
349 Monitor* SR_lock() const { return _SR_lock; }
350
351 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
352
353 void set_suspend_flag(SuspendFlags f) {
354 assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
662 static void muxRelease (volatile intptr_t * Lock) ;
663 };
664
665 // Inline implementation of Thread::current()
666 // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
667 // startup.
668 // ThreadLocalStorage::thread is warm -- it's called > 16K times in the same
669 // period. This is inlined in thread_<os_family>.inline.hpp.
670
671 inline Thread* Thread::current() {
672 #ifdef ASSERT
673 // This function is very high traffic. Define PARANOID to enable expensive
674 // asserts.
675 #ifdef PARANOID
676 // Signal handler should call ThreadLocalStorage::get_thread_slow()
677 Thread* t = ThreadLocalStorage::get_thread_slow();
678 assert(t != NULL && !t->is_inside_signal_handler(),
679 "Don't use Thread::current() inside signal handler");
680 #endif
681 #endif
682 Thread* current = current_or_null();
683 assert(current != NULL, "Thread::current() called on detached thread");
684 return current;
685 }
686
687 inline Thread* Thread::current_or_null() {
688 if (ThreadLocalStorage::is_initialized()) {
689 return ThreadLocalStorage::thread();
690 }
691 return NULL;
692 }
693
694 // Name support for threads. non-JavaThread subclasses with multiple
695 // uniquely named instances should derive from this.
696 class NamedThread: public Thread {
697 friend class VMStructs;
698 enum {
699 max_name_len = 64
700 };
701 private:
702 char* _name;
703 // log JavaThread being processed by oops_do
704 JavaThread* _processed_thread;
705
706 public:
707 NamedThread();
708 ~NamedThread();
709 // May only be called once per thread.
710 void set_name(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
711 virtual bool is_Named_thread() const { return true; }
1765 public:
1766 GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; }
1767 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; }
1768
1769 // clearing/querying jni attach status
1770 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
1771 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
1772 inline void set_done_attaching_via_jni();
1773 private:
1774 // This field is used to determine if a thread has claimed
1775 // a par_id: it is UINT_MAX if the thread has not claimed a par_id;
1776 // otherwise its value is the par_id that has been claimed.
1777 uint _claimed_par_id;
1778 public:
1779 uint get_claimed_par_id() { return _claimed_par_id; }
1780 void set_claimed_par_id(uint id) { _claimed_par_id = id;}
1781 };
1782
1783 // Inline implementation of JavaThread::current
1784 inline JavaThread* JavaThread::current() {
1785 Thread* thread = Thread::current();
1786 assert(thread->is_Java_thread(), "just checking");
1787 return (JavaThread*)thread;
1788 }
1789
1790 inline CompilerThread* JavaThread::as_CompilerThread() {
1791 assert(is_Compiler_thread(), "just checking");
1792 return (CompilerThread*)this;
1793 }
1794
1795 inline bool JavaThread::stack_guard_zone_unused() {
1796 return _stack_guard_state == stack_guard_unused;
1797 }
1798
1799 inline bool JavaThread::stack_yellow_zone_disabled() {
1800 return _stack_guard_state == stack_guard_yellow_disabled;
1801 }
1802
1803 inline bool JavaThread::stack_yellow_zone_enabled() {
1804 #ifdef ASSERT
1805 if (os::uses_stack_guard_pages() &&
1806 !(DisablePrimordialThreadGuardPages && os::is_primordial_thread())) {
|