100 // - WatcherThread |
100 // - WatcherThread |
101 |
101 |
102 class Thread: public ThreadShadow { |
102 class Thread: public ThreadShadow { |
103 friend class VMStructs; |
103 friend class VMStructs; |
104 private: |
104 private: |
|
105 |
|
106 #ifndef USE_LIBRARY_BASED_TLS_ONLY |
|
107 // Current thread is maintained as a thread-local variable |
|
108 static THREAD_LOCAL_DECL Thread* _thr_current; |
|
109 #endif |
|
110 |
105 // Exception handling |
111 // Exception handling |
106 // (Note: _pending_exception and friends are in ThreadShadow) |
112 // (Note: _pending_exception and friends are in ThreadShadow) |
107 //oop _pending_exception; // pending exception for current thread |
113 //oop _pending_exception; // pending exception for current thread |
108 // const char* _exception_file; // file information for exception (debugging only) |
114 // const char* _exception_file; // file information for exception (debugging only) |
109 // int _exception_line; // line information for exception (debugging only) |
115 // int _exception_line; // line information for exception (debugging only) |
258 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot? |
264 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot? |
259 |
265 |
260 friend class No_Alloc_Verifier; |
266 friend class No_Alloc_Verifier; |
261 friend class No_Safepoint_Verifier; |
267 friend class No_Safepoint_Verifier; |
262 friend class Pause_No_Safepoint_Verifier; |
268 friend class Pause_No_Safepoint_Verifier; |
263 friend class ThreadLocalStorage; |
|
264 friend class GC_locker; |
269 friend class GC_locker; |
265 |
270 |
266 ThreadLocalAllocBuffer _tlab; // Thread-local eden |
271 ThreadLocalAllocBuffer _tlab; // Thread-local eden |
267 jlong _allocated_bytes; // Cumulative number of bytes allocated on |
272 jlong _allocated_bytes; // Cumulative number of bytes allocated on |
268 // the Java heap |
273 // the Java heap |
335 // Casts |
343 // Casts |
336 virtual WorkerThread* as_Worker_thread() const { return NULL; } |
344 virtual WorkerThread* as_Worker_thread() const { return NULL; } |
337 |
345 |
338 virtual char* name() const { return (char*)"Unknown thread"; } |
346 virtual char* name() const { return (char*)"Unknown thread"; } |
339 |
347 |
340 // Returns the current thread |
348 // Returns the current thread (ASSERTS if NULL) |
341 static inline Thread* current(); |
349 static inline Thread* current(); |
342 // ... without having to include thread.inline.hpp. |
350 // Returns the current thread, or NULL if not attached |
343 static Thread* current_noinline(); |
351 static inline Thread* current_or_null(); |
|
352 // Returns the current thread, or NULL if not attached, and is |
|
353 // safe for use from signal-handlers |
|
354 static inline Thread* current_or_null_safe(); |
344 |
355 |
345 // Common thread operations |
356 // Common thread operations |
346 static void set_priority(Thread* thread, ThreadPriority priority); |
357 static void set_priority(Thread* thread, ThreadPriority priority); |
347 static ThreadPriority get_priority(const Thread* const thread); |
358 static ThreadPriority get_priority(const Thread* const thread); |
348 static void start(Thread* thread); |
359 static void start(Thread* thread); |
647 static void muxAcquireW(volatile intptr_t * Lock, ParkEvent * ev); |
658 static void muxAcquireW(volatile intptr_t * Lock, ParkEvent * ev); |
648 static void muxRelease(volatile intptr_t * Lock); |
659 static void muxRelease(volatile intptr_t * Lock); |
649 }; |
660 }; |
650 |
661 |
651 // Inline implementation of Thread::current() |
662 // Inline implementation of Thread::current() |
652 // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of |
|
653 // startup. |
|
654 // ThreadLocalStorage::thread is warm -- it's called > 16K times in the same |
|
655 // period. This is inlined in thread_<os_family>.inline.hpp. |
|
656 |
|
657 inline Thread* Thread::current() { |
663 inline Thread* Thread::current() { |
658 #ifdef ASSERT |
664 Thread* current = current_or_null(); |
659 // This function is very high traffic. Define PARANOID to enable expensive |
665 assert(current != NULL, "Thread::current() called on detached thread"); |
660 // asserts. |
666 return current; |
661 #ifdef PARANOID |
667 } |
662 // Signal handler should call ThreadLocalStorage::get_thread_slow() |
668 |
663 Thread* t = ThreadLocalStorage::get_thread_slow(); |
669 inline Thread* Thread::current_or_null() { |
664 assert(t != NULL && !t->is_inside_signal_handler(), |
670 #ifndef USE_LIBRARY_BASED_TLS_ONLY |
665 "Don't use Thread::current() inside signal handler"); |
671 return _thr_current; |
666 #endif |
672 #else |
667 #endif |
673 return ThreadLocalStorage::thread(); |
668 Thread* thread = ThreadLocalStorage::thread(); |
674 #endif |
669 assert(thread != NULL, "just checking"); |
675 } |
670 return thread; |
676 |
|
677 inline Thread* Thread::current_or_null_safe() { |
|
678 return ThreadLocalStorage::thread(); |
671 } |
679 } |
672 |
680 |
673 // Name support for threads. non-JavaThread subclasses with multiple |
681 // Name support for threads. non-JavaThread subclasses with multiple |
674 // uniquely named instances should derive from this. |
682 // uniquely named instances should derive from this. |
675 class NamedThread: public Thread { |
683 class NamedThread: public Thread { |
1840 void set_claimed_par_id(uint id) { _claimed_par_id = id; } |
1848 void set_claimed_par_id(uint id) { _claimed_par_id = id; } |
1841 }; |
1849 }; |
1842 |
1850 |
1843 // Inline implementation of JavaThread::current |
1851 // Inline implementation of JavaThread::current |
1844 inline JavaThread* JavaThread::current() { |
1852 inline JavaThread* JavaThread::current() { |
1845 Thread* thread = ThreadLocalStorage::thread(); |
1853 Thread* thread = Thread::current(); |
1846 assert(thread != NULL && thread->is_Java_thread(), "just checking"); |
1854 assert(thread->is_Java_thread(), "just checking"); |
1847 return (JavaThread*)thread; |
1855 return (JavaThread*)thread; |
1848 } |
1856 } |
1849 |
1857 |
1850 inline CompilerThread* JavaThread::as_CompilerThread() { |
1858 inline CompilerThread* JavaThread::as_CompilerThread() { |
1851 assert(is_Compiler_thread(), "just checking"); |
1859 assert(is_Compiler_thread(), "just checking"); |