1437 #if INCLUDE_NMT
1438 set_recorder(NULL);
1439 #endif
1440 _terminated = _not_terminated;
1441 _privileged_stack_top = NULL;
1442 _array_for_gc = NULL;
1443 _suspend_equivalent = false;
1444 _in_deopt_handler = 0;
1445 _doing_unsafe_access = false;
1446 _stack_guard_state = stack_guard_unused;
1447 _exception_oop = NULL;
1448 _exception_pc = 0;
1449 _exception_handler_pc = 0;
1450 _is_method_handle_return = 0;
1451 _jvmti_thread_state= NULL;
1452 _should_post_on_exceptions_flag = JNI_FALSE;
1453 _jvmti_get_loaded_classes_closure = NULL;
1454 _interp_only_mode = 0;
1455 _special_runtime_exit_condition = _no_async_condition;
1456 _pending_async_exception = NULL;
1457 _is_compiling = false;
1458 _thread_stat = NULL;
1459 _thread_stat = new ThreadStatistics();
1460 _blocked_on_compilation = false;
1461 _jni_active_critical = 0;
1462 _do_not_unlock_if_synchronized = false;
1463 _cached_monitor_info = NULL;
1464 _parker = Parker::Allocate(this) ;
1465
1466 #ifndef PRODUCT
1467 _jmp_ring_index = 0;
1468 for (int ji = 0 ; ji < jump_ring_buffer_size ; ji++ ) {
1469 record_jump(NULL, NULL, NULL, 0);
1470 }
1471 #endif /* PRODUCT */
1472
1473 set_thread_profiler(NULL);
1474 if (FlatProfiler::is_active()) {
1475 // This is where we would decide to either give each thread it's own profiler
1476 // or use one global one from FlatProfiler,
1477 // or up to some count of the number of profiled threads, etc.
1798 get_thread_name());
1799 CLEAR_PENDING_EXCEPTION;
1800 }
1801 }
1802 }
1803
1804 // Called before the java thread exit since we want to read info
1805 // from java_lang_Thread object
1806 EventThreadEnd event;
1807 if (event.should_commit()) {
1808 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj()));
1809 event.commit();
1810 }
1811
1812 // Call after last event on thread
1813 EVENT_THREAD_EXIT(this);
1814
1815 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
1816 // the execution of the method. If that is not enough, then we don't really care. Thread.stop
1817 // is deprecated anyhow.
1818 { int count = 3;
1819 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) {
1820 EXCEPTION_MARK;
1821 JavaValue result(T_VOID);
1822 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass());
1823 JavaCalls::call_virtual(&result,
1824 threadObj, thread_klass,
1825 vmSymbols::exit_method_name(),
1826 vmSymbols::void_method_signature(),
1827 THREAD);
1828 CLEAR_PENDING_EXCEPTION;
1829 }
1830 }
1831
1832 // notify JVMTI
1833 if (JvmtiExport::should_post_thread_life()) {
1834 JvmtiExport::post_thread_end(this);
1835 }
1836
1837 // We have notified the agents that we are exiting, before we go on,
1838 // we must check for a pending external suspend request and honor it
1839 // in order to not surprise the thread that made the suspend request.
1840 while (true) {
1841 {
1842 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1843 if (!is_external_suspend()) {
1844 set_terminated(_thread_exiting);
1845 ThreadService::current_thread_exiting(this);
1846 break;
1847 }
1848 // Implied else:
1849 // Things get a little tricky here. We have a pending external
1850 // suspend request, but we are holding the SR_lock so we
1851 // can't just self-suspend. So we temporarily drop the lock
3222 return vfst.method()->method_holder();
3223 }
3224 return NULL;
3225 }
3226
3227 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
3228 assert(thread->is_Compiler_thread(), "must be compiler thread");
3229 CompileBroker::compiler_thread_loop();
3230 }
3231
3232 // Create a CompilerThread
3233 CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
3234 : JavaThread(&compiler_thread_entry) {
3235 _env = NULL;
3236 _log = NULL;
3237 _task = NULL;
3238 _queue = queue;
3239 _counters = counters;
3240 _buffer_blob = NULL;
3241 _scanned_nmethod = NULL;
3242
3243 #ifndef PRODUCT
3244 _ideal_graph_printer = NULL;
3245 #endif
3246 }
3247
3248 void CompilerThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
3249 JavaThread::oops_do(f, cld_f, cf);
3250 if (_scanned_nmethod != NULL && cf != NULL) {
3251 // Safepoints can occur when the sweeper is scanning an nmethod so
3252 // process it here to make sure it isn't unloaded in the middle of
3253 // a scan.
3254 cf->do_code_blob(_scanned_nmethod);
3255 }
3256 }
3257
3258 // ======= Threads ========
3259
3260 // The Threads class links together all active threads, and provides
3261 // operations over all threads. It is protected by its own Mutex
3262 // lock, which is also used in other contexts to protect thread
3263 // operations from having the thread being operated on from exiting
3264 // and going away unexpectedly (e.g., safepoint synchronization)
3265
3266 JavaThread* Threads::_thread_list = NULL;
3267 int Threads::_number_of_threads = 0;
3268 int Threads::_number_of_non_daemon_threads = 0;
3269 int Threads::_return_code = 0;
3270 size_t JavaThread::_stack_size_at_create = 0;
3271 #ifdef ASSERT
3272 bool Threads::_vm_complete = false;
3273 #endif
3274
3275 // All JavaThreads
3276 #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
3277
3278 void os_stream();
3279
3280 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system)
3281 void Threads::threads_do(ThreadClosure* tc) {
3282 assert_locked_or_safepoint(Threads_lock);
3283 // ALL_JAVA_THREADS iterates through all JavaThreads
3284 ALL_JAVA_THREADS(p) {
3285 tc->do_thread(p);
3286 }
3287 // Someday we could have a table or list of all non-JavaThreads.
3288 // For now, just manually iterate through them.
3289 tc->do_thread(VMThread::vm_thread());
3290 Universe::heap()->gc_threads_do(tc);
3291 WatcherThread *wt = WatcherThread::watcher_thread();
3292 // Strictly speaking, the following NULL check isn't sufficient to make sure
3293 // the data for WatcherThread is still valid upon being examined. However,
3294 // considering that WatchThread terminates when the VM is on the way to
3295 // exit at safepoint, the chance of the above is extremely small. The right
3296 // way to prevent termination of WatcherThread would be to acquire
3297 // Terminator_lock, but we can't do that without violating the lock rank
3298 // checking in some cases.
|
1437 #if INCLUDE_NMT
1438 set_recorder(NULL);
1439 #endif
1440 _terminated = _not_terminated;
1441 _privileged_stack_top = NULL;
1442 _array_for_gc = NULL;
1443 _suspend_equivalent = false;
1444 _in_deopt_handler = 0;
1445 _doing_unsafe_access = false;
1446 _stack_guard_state = stack_guard_unused;
1447 _exception_oop = NULL;
1448 _exception_pc = 0;
1449 _exception_handler_pc = 0;
1450 _is_method_handle_return = 0;
1451 _jvmti_thread_state= NULL;
1452 _should_post_on_exceptions_flag = JNI_FALSE;
1453 _jvmti_get_loaded_classes_closure = NULL;
1454 _interp_only_mode = 0;
1455 _special_runtime_exit_condition = _no_async_condition;
1456 _pending_async_exception = NULL;
1457 _thread_stat = NULL;
1458 _thread_stat = new ThreadStatistics();
1459 _blocked_on_compilation = false;
1460 _jni_active_critical = 0;
1461 _do_not_unlock_if_synchronized = false;
1462 _cached_monitor_info = NULL;
1463 _parker = Parker::Allocate(this) ;
1464
1465 #ifndef PRODUCT
1466 _jmp_ring_index = 0;
1467 for (int ji = 0 ; ji < jump_ring_buffer_size ; ji++ ) {
1468 record_jump(NULL, NULL, NULL, 0);
1469 }
1470 #endif /* PRODUCT */
1471
1472 set_thread_profiler(NULL);
1473 if (FlatProfiler::is_active()) {
1474 // This is where we would decide to either give each thread it's own profiler
1475 // or use one global one from FlatProfiler,
1476 // or up to some count of the number of profiled threads, etc.
1797 get_thread_name());
1798 CLEAR_PENDING_EXCEPTION;
1799 }
1800 }
1801 }
1802
1803 // Called before the java thread exit since we want to read info
1804 // from java_lang_Thread object
1805 EventThreadEnd event;
1806 if (event.should_commit()) {
1807 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj()));
1808 event.commit();
1809 }
1810
1811 // Call after last event on thread
1812 EVENT_THREAD_EXIT(this);
1813
1814 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
1815 // the execution of the method. If that is not enough, then we don't really care. Thread.stop
1816 // is deprecated anyhow.
1817 if (!is_Compiler_thread()) {
1818 int count = 3;
1819 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) {
1820 EXCEPTION_MARK;
1821 JavaValue result(T_VOID);
1822 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass());
1823 JavaCalls::call_virtual(&result,
1824 threadObj, thread_klass,
1825 vmSymbols::exit_method_name(),
1826 vmSymbols::void_method_signature(),
1827 THREAD);
1828 CLEAR_PENDING_EXCEPTION;
1829 }
1830 }
1831 // notify JVMTI
1832 if (JvmtiExport::should_post_thread_life()) {
1833 JvmtiExport::post_thread_end(this);
1834 }
1835
1836 // We have notified the agents that we are exiting, before we go on,
1837 // we must check for a pending external suspend request and honor it
1838 // in order to not surprise the thread that made the suspend request.
1839 while (true) {
1840 {
1841 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1842 if (!is_external_suspend()) {
1843 set_terminated(_thread_exiting);
1844 ThreadService::current_thread_exiting(this);
1845 break;
1846 }
1847 // Implied else:
1848 // Things get a little tricky here. We have a pending external
1849 // suspend request, but we are holding the SR_lock so we
1850 // can't just self-suspend. So we temporarily drop the lock
3221 return vfst.method()->method_holder();
3222 }
3223 return NULL;
3224 }
3225
3226 static void compiler_thread_entry(JavaThread* thread, TRAPS) {
3227 assert(thread->is_Compiler_thread(), "must be compiler thread");
3228 CompileBroker::compiler_thread_loop();
3229 }
3230
3231 // Create a CompilerThread
3232 CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
3233 : JavaThread(&compiler_thread_entry) {
3234 _env = NULL;
3235 _log = NULL;
3236 _task = NULL;
3237 _queue = queue;
3238 _counters = counters;
3239 _buffer_blob = NULL;
3240 _scanned_nmethod = NULL;
3241 _compiler = NULL;
3242
3243 #ifndef PRODUCT
3244 _ideal_graph_printer = NULL;
3245 #endif
3246 }
3247
3248 void CompilerThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
3249 JavaThread::oops_do(f, cld_f, cf);
3250 if (_scanned_nmethod != NULL && cf != NULL) {
3251 // Safepoints can occur when the sweeper is scanning an nmethod so
3252 // process it here to make sure it isn't unloaded in the middle of
3253 // a scan.
3254 cf->do_code_blob(_scanned_nmethod);
3255 }
3256 }
3257
3258
3259 // ======= Threads ========
3260
3261 // The Threads class links together all active threads, and provides
3262 // operations over all threads. It is protected by its own Mutex
3263 // lock, which is also used in other contexts to protect thread
3264 // operations from having the thread being operated on from exiting
3265 // and going away unexpectedly (e.g., safepoint synchronization)
3266
3267 JavaThread* Threads::_thread_list = NULL;
3268 int Threads::_number_of_threads = 0;
3269 int Threads::_number_of_non_daemon_threads = 0;
3270 int Threads::_return_code = 0;
3271 size_t JavaThread::_stack_size_at_create = 0;
3272 #ifdef ASSERT
3273 bool Threads::_vm_complete = false;
3274 #endif
3275
3276 // All JavaThreads
3277 #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
3278
3279 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system)
3280 void Threads::threads_do(ThreadClosure* tc) {
3281 assert_locked_or_safepoint(Threads_lock);
3282 // ALL_JAVA_THREADS iterates through all JavaThreads
3283 ALL_JAVA_THREADS(p) {
3284 tc->do_thread(p);
3285 }
3286 // Someday we could have a table or list of all non-JavaThreads.
3287 // For now, just manually iterate through them.
3288 tc->do_thread(VMThread::vm_thread());
3289 Universe::heap()->gc_threads_do(tc);
3290 WatcherThread *wt = WatcherThread::watcher_thread();
3291 // Strictly speaking, the following NULL check isn't sufficient to make sure
3292 // the data for WatcherThread is still valid upon being examined. However,
3293 // considering that WatchThread terminates when the VM is on the way to
3294 // exit at safepoint, the chance of the above is extremely small. The right
3295 // way to prevent termination of WatcherThread would be to acquire
3296 // Terminator_lock, but we can't do that without violating the lock rank
3297 // checking in some cases.
|