113 void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() { |
113 void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() { |
114 return allocate(size, false); } |
114 return allocate(size, false); } |
115 void operator delete(void* p); |
115 void operator delete(void* p); |
116 |
116 |
117 protected: |
117 protected: |
118 static void* allocate(size_t size, bool throw_excpt, MEMFLAGS flags = mtThread); |
118 static void* allocate(size_t size, bool throw_excpt, MEMFLAGS flags = mtThread); |
119 private: |
119 private: |
120 |
120 |
121 // *************************************************************** |
121 // *************************************************************** |
122 // Suspend and resume support |
122 // Suspend and resume support |
123 // *************************************************************** |
123 // *************************************************************** |
223 |
223 |
224 // The parity of the last strong_roots iteration in which this thread was |
224 // The parity of the last strong_roots iteration in which this thread was |
225 // claimed as a task. |
225 // claimed as a task. |
226 jint _oops_do_parity; |
226 jint _oops_do_parity; |
227 |
227 |
228 public: |
228 public: |
229 void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; } |
229 void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; } |
230 HandleMark* last_handle_mark() const { return _last_handle_mark; } |
230 HandleMark* last_handle_mark() const { return _last_handle_mark; } |
231 private: |
231 private: |
232 |
232 |
233 // debug support for checking if code does allow safepoints or not |
233 // debug support for checking if code does allow safepoints or not |
234 // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on |
234 // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on |
235 // mutex, or blocking on an object synchronizer (Java locking). |
235 // mutex, or blocking on an object synchronizer (Java locking). |
236 // If !allow_safepoint(), then an assertion failure will happen in any of the above cases |
236 // If !allow_safepoint(), then an assertion failure will happen in any of the above cases |
443 // Used by JavaThread::oops_do. |
443 // Used by JavaThread::oops_do. |
444 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
444 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
445 virtual void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
445 virtual void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
446 |
446 |
447 // Handles the parallel case for the method below. |
447 // Handles the parallel case for the method below. |
448 private: |
448 private: |
449 bool claim_oops_do_par_case(int collection_parity); |
449 bool claim_oops_do_par_case(int collection_parity); |
450 public: |
450 public: |
451 // Requires that "collection_parity" is that of the current roots |
451 // Requires that "collection_parity" is that of the current roots |
452 // iteration. If "is_par" is false, sets the parity of "this" to |
452 // iteration. If "is_par" is false, sets the parity of "this" to |
453 // "collection_parity", and returns "true". If "is_par" is true, |
453 // "collection_parity", and returns "true". If "is_par" is true, |
454 // uses an atomic instruction to set the current threads parity to |
454 // uses an atomic instruction to set the current threads parity to |
455 // "collection_parity", if it is not already. Returns "true" iff the |
455 // "collection_parity", if it is not already. Returns "true" iff the |
662 virtual void print_on(outputStream* st) const; |
662 virtual void print_on(outputStream* st) const; |
663 }; |
663 }; |
664 |
664 |
665 // Worker threads are named and have an id of an assigned work. |
665 // Worker threads are named and have an id of an assigned work. |
666 class WorkerThread: public NamedThread { |
666 class WorkerThread: public NamedThread { |
667 private: |
667 private: |
668 uint _id; |
668 uint _id; |
669 public: |
669 public: |
670 WorkerThread() : _id(0) { } |
670 WorkerThread() : _id(0) { } |
671 virtual bool is_Worker_thread() const { return true; } |
671 virtual bool is_Worker_thread() const { return true; } |
672 |
672 |
673 virtual WorkerThread* as_Worker_thread() const { |
673 virtual WorkerThread* as_Worker_thread() const { |
674 assert(is_Worker_thread(), "Dubious cast to WorkerThread*?"); |
674 assert(is_Worker_thread(), "Dubious cast to WorkerThread*?"); |
842 volatile bool _suspend_equivalent; // Suspend equivalent condition |
842 volatile bool _suspend_equivalent; // Suspend equivalent condition |
843 jint _in_deopt_handler; // count of deoptimization |
843 jint _in_deopt_handler; // count of deoptimization |
844 // handlers thread is in |
844 // handlers thread is in |
845 volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access |
845 volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access |
846 bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was |
846 bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was |
847 // never locked) when throwing an exception. Used by interpreter only. |
847 // never locked) when throwing an exception. Used by interpreter only. |
848 |
848 |
849 // JNI attach states: |
849 // JNI attach states: |
850 enum JNIAttachStates { |
850 enum JNIAttachStates { |
851 _not_attaching_via_jni = 1, // thread is not attaching via JNI |
851 _not_attaching_via_jni = 1, // thread is not attaching via JNI |
852 _attaching_via_jni, // thread is attaching via JNI |
852 _attaching_via_jni, // thread is attaching via JNI |
1111 |
1111 |
1112 // Special method to handle a pending external suspend request |
1112 // Special method to handle a pending external suspend request |
1113 // when a suspend equivalent condition lifts. |
1113 // when a suspend equivalent condition lifts. |
1114 bool handle_special_suspend_equivalent_condition() { |
1114 bool handle_special_suspend_equivalent_condition() { |
1115 assert(is_suspend_equivalent(), |
1115 assert(is_suspend_equivalent(), |
1116 "should only be called in a suspend equivalence condition"); |
1116 "should only be called in a suspend equivalence condition"); |
1117 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); |
1117 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); |
1118 bool ret = is_external_suspend(); |
1118 bool ret = is_external_suspend(); |
1119 if (!ret) { |
1119 if (!ret) { |
1120 // not about to self-suspend so clear suspend equivalence |
1120 // not about to self-suspend so clear suspend equivalence |
1121 clear_suspend_equivalent(); |
1121 clear_suspend_equivalent(); |
1337 static JavaThread* thread_from_jni_environment(JNIEnv* env) { |
1337 static JavaThread* thread_from_jni_environment(JNIEnv* env) { |
1338 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset())); |
1338 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset())); |
1339 // Only return NULL if thread is off the thread list; starting to |
1339 // Only return NULL if thread is off the thread list; starting to |
1340 // exit should not return NULL. |
1340 // exit should not return NULL. |
1341 if (thread_from_jni_env->is_terminated()) { |
1341 if (thread_from_jni_env->is_terminated()) { |
1342 thread_from_jni_env->block_if_vm_exited(); |
1342 thread_from_jni_env->block_if_vm_exited(); |
1343 return NULL; |
1343 return NULL; |
1344 } else { |
1344 } else { |
1345 return thread_from_jni_env; |
1345 return thread_from_jni_env; |
1346 } |
1346 } |
1347 } |
1347 } |
1348 |
1348 |
1349 // JNI critical regions. These can nest. |
1349 // JNI critical regions. These can nest. |
1350 bool in_critical() { return _jni_active_critical > 0; } |
1350 bool in_critical() { return _jni_active_critical > 0; } |
1351 bool in_last_critical() { return _jni_active_critical == 1; } |
1351 bool in_last_critical() { return _jni_active_critical == 1; } |
1352 void enter_critical() { assert(Thread::current() == this || |
1352 void enter_critical() { assert(Thread::current() == this || |
1353 Thread::current()->is_VM_thread() && SafepointSynchronize::is_synchronizing(), |
1353 Thread::current()->is_VM_thread() && SafepointSynchronize::is_synchronizing(), |
1354 "this must be current thread or synchronizing"); |
1354 "this must be current thread or synchronizing"); |
1355 _jni_active_critical++; } |
1355 _jni_active_critical++; } |
1356 void exit_critical() { assert(Thread::current() == this, |
1356 void exit_critical() { assert(Thread::current() == this, |
1357 "this must be current thread"); |
1357 "this must be current thread"); |
1358 _jni_active_critical--; |
1358 _jni_active_critical--; |
1359 assert(_jni_active_critical >= 0, |
1359 assert(_jni_active_critical >= 0, |
1360 "JNI critical nesting problem?"); } |
1360 "JNI critical nesting problem?"); } |
1361 |
1361 |
1362 // Checked JNI, is the programmer required to check for exceptions, specify which function name |
1362 // Checked JNI, is the programmer required to check for exceptions, specify which function name |
1363 bool is_pending_jni_exception_check() const { return _pending_jni_exception_check_fn != NULL; } |
1363 bool is_pending_jni_exception_check() const { return _pending_jni_exception_check_fn != NULL; } |
1364 void clear_pending_jni_exception_check() { _pending_jni_exception_check_fn = NULL; } |
1364 void clear_pending_jni_exception_check() { _pending_jni_exception_check_fn = NULL; } |
1365 const char* get_pending_jni_exception_check() const { return _pending_jni_exception_check_fn; } |
1365 const char* get_pending_jni_exception_check() const { return _pending_jni_exception_check_fn; } |
1409 void print_thread_state_on(outputStream* ) const PRODUCT_RETURN; |
1409 void print_thread_state_on(outputStream* ) const PRODUCT_RETURN; |
1410 void print_thread_state() const PRODUCT_RETURN; |
1410 void print_thread_state() const PRODUCT_RETURN; |
1411 void print_on_error(outputStream* st, char* buf, int buflen) const; |
1411 void print_on_error(outputStream* st, char* buf, int buflen) const; |
1412 void verify(); |
1412 void verify(); |
1413 const char* get_thread_name() const; |
1413 const char* get_thread_name() const; |
1414 private: |
1414 private: |
1415 // factor out low-level mechanics for use in both normal and error cases |
1415 // factor out low-level mechanics for use in both normal and error cases |
1416 const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const; |
1416 const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const; |
1417 public: |
1417 public: |
1418 const char* get_threadgroup_name() const; |
1418 const char* get_threadgroup_name() const; |
1419 const char* get_parent_name() const; |
1419 const char* get_parent_name() const; |
1420 |
1420 |
1421 // Accessing frames |
1421 // Accessing frames |
1422 frame last_frame() { |
1422 frame last_frame() { |
1454 |
1454 |
1455 void deoptimized_wrt_marked_nmethods(); |
1455 void deoptimized_wrt_marked_nmethods(); |
1456 |
1456 |
1457 // Profiling operation (see fprofile.cpp) |
1457 // Profiling operation (see fprofile.cpp) |
1458 public: |
1458 public: |
1459 bool profile_last_Java_frame(frame* fr); |
1459 bool profile_last_Java_frame(frame* fr); |
1460 |
1460 |
1461 private: |
1461 private: |
1462 ThreadProfiler* _thread_profiler; |
1462 ThreadProfiler* _thread_profiler; |
1463 private: |
1463 private: |
1464 friend class FlatProfiler; // uses both [gs]et_thread_profiler. |
1464 friend class FlatProfiler; // uses both [gs]et_thread_profiler. |
1465 friend class FlatProfilerTask; // uses get_thread_profiler. |
1465 friend class FlatProfilerTask; // uses get_thread_profiler. |
1466 friend class ThreadProfilerMark; // uses get_thread_profiler. |
1466 friend class ThreadProfilerMark; // uses get_thread_profiler. |
1467 ThreadProfiler* get_thread_profiler() { return _thread_profiler; } |
1467 ThreadProfiler* get_thread_profiler() { return _thread_profiler; } |
1468 ThreadProfiler* set_thread_profiler(ThreadProfiler* tp) { |
1468 ThreadProfiler* set_thread_profiler(ThreadProfiler* tp) { |
1469 ThreadProfiler* result = _thread_profiler; |
1469 ThreadProfiler* result = _thread_profiler; |
1470 _thread_profiler = tp; |
1470 _thread_profiler = tp; |
1471 return result; |
1471 return result; |
1472 } |
1472 } |
1473 |
1473 |
1474 public: |
1474 public: |
1475 // Returns the running thread as a JavaThread |
1475 // Returns the running thread as a JavaThread |
1476 static inline JavaThread* current(); |
1476 static inline JavaThread* current(); |
1477 |
1477 |
1690 protected: |
1690 protected: |
1691 bool _blocked_on_compilation; |
1691 bool _blocked_on_compilation; |
1692 |
1692 |
1693 |
1693 |
1694 // JSR166 per-thread parker |
1694 // JSR166 per-thread parker |
1695 private: |
1695 private: |
1696 Parker* _parker; |
1696 Parker* _parker; |
1697 public: |
1697 public: |
1698 Parker* parker() { return _parker; } |
1698 Parker* parker() { return _parker; } |
1699 |
1699 |
1700 // Biased locking support |
1700 // Biased locking support |
1701 private: |
1701 private: |
1702 GrowableArray<MonitorInfo*>* _cached_monitor_info; |
1702 GrowableArray<MonitorInfo*>* _cached_monitor_info; |
1703 public: |
1703 public: |
1704 GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; } |
1704 GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; } |
1705 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; } |
1705 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; } |
1706 |
1706 |
1707 // clearing/querying jni attach status |
1707 // clearing/querying jni attach status |
1708 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; } |
1708 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; } |
1709 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; } |
1709 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; } |
1710 inline void set_done_attaching_via_jni(); |
1710 inline void set_done_attaching_via_jni(); |
1711 private: |
1711 private: |
1712 // This field is used to determine if a thread has claimed |
1712 // This field is used to determine if a thread has claimed |
1713 // a par_id: it is UINT_MAX if the thread has not claimed a par_id; |
1713 // a par_id: it is UINT_MAX if the thread has not claimed a par_id; |
1714 // otherwise its value is the par_id that has been claimed. |
1714 // otherwise its value is the par_id that has been claimed. |
1715 uint _claimed_par_id; |
1715 uint _claimed_par_id; |
1716 public: |
1716 public: |
1717 uint get_claimed_par_id() { return _claimed_par_id; } |
1717 uint get_claimed_par_id() { return _claimed_par_id; } |
1718 void set_claimed_par_id(uint id) { _claimed_par_id = id; } |
1718 void set_claimed_par_id(uint id) { _claimed_par_id = id; } |
1719 }; |
1719 }; |
1720 |
1720 |
1721 // Inline implementation of JavaThread::current |
1721 // Inline implementation of JavaThread::current |
1780 // Apply "f->do_oop" to all root oops in "this". |
1780 // Apply "f->do_oop" to all root oops in "this". |
1781 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
1781 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
1782 void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1782 void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1783 |
1783 |
1784 #ifndef PRODUCT |
1784 #ifndef PRODUCT |
1785 private: |
1785 private: |
1786 IdealGraphPrinter *_ideal_graph_printer; |
1786 IdealGraphPrinter *_ideal_graph_printer; |
1787 public: |
1787 public: |
1788 IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; } |
1788 IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; } |
1789 void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; } |
1789 void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; } |
1790 #endif |
1790 #endif |
1791 |
1791 |
1792 // Get/set the thread's current task |
1792 // Get/set the thread's current task |
1883 |
1883 |
1884 // Get Java threads that are waiting to enter a monitor. If doLock |
1884 // Get Java threads that are waiting to enter a monitor. If doLock |
1885 // is true, then Threads_lock is grabbed as needed. Otherwise, the |
1885 // is true, then Threads_lock is grabbed as needed. Otherwise, the |
1886 // VM needs to be at a safepoint. |
1886 // VM needs to be at a safepoint. |
1887 static GrowableArray<JavaThread*>* get_pending_threads(int count, |
1887 static GrowableArray<JavaThread*>* get_pending_threads(int count, |
1888 address monitor, bool doLock); |
1888 address monitor, bool doLock); |
1889 |
1889 |
1890 // Get owning Java thread from the monitor's owner field. If doLock |
1890 // Get owning Java thread from the monitor's owner field. If doLock |
1891 // is true, then Threads_lock is grabbed as needed. Otherwise, the |
1891 // is true, then Threads_lock is grabbed as needed. Otherwise, the |
1892 // VM needs to be at a safepoint. |
1892 // VM needs to be at a safepoint. |
1893 static JavaThread *owning_thread_from_monitor_owner(address owner, |
1893 static JavaThread *owning_thread_from_monitor_owner(address owner, |
1894 bool doLock); |
1894 bool doLock); |
1895 |
1895 |
1896 // Number of threads on the active threads list |
1896 // Number of threads on the active threads list |
1897 static int number_of_threads() { return _number_of_threads; } |
1897 static int number_of_threads() { return _number_of_threads; } |
1898 // Number of non-daemon threads on the active threads list |
1898 // Number of non-daemon threads on the active threads list |
1899 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; } |
1899 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; } |