equal
deleted
inserted
replaced
1817 lock.notify_all(thread); |
1817 lock.notify_all(thread); |
1818 // Ignore pending exception (ThreadDeath), since we are exiting anyway |
1818 // Ignore pending exception (ThreadDeath), since we are exiting anyway |
1819 thread->clear_pending_exception(); |
1819 thread->clear_pending_exception(); |
1820 } |
1820 } |
1821 |
1821 |
|
1822 static bool is_daemon(oop threadObj) { |
|
1823 return (threadObj != NULL && java_lang_Thread::is_daemon(threadObj)); |
|
1824 } |
1822 |
1825 |
1823 // For any new cleanup additions, please check to see if they need to be applied to |
1826 // For any new cleanup additions, please check to see if they need to be applied to |
1824 // cleanup_failed_attach_current_thread as well. |
1827 // cleanup_failed_attach_current_thread as well. |
1825 void JavaThread::exit(bool destroy_vm, ExitType exit_type) { |
1828 void JavaThread::exit(bool destroy_vm, ExitType exit_type) { |
1826 assert(this == JavaThread::current(), "thread consistency check"); |
1829 assert(this == JavaThread::current(), "thread consistency check"); |
1908 while (true) { |
1911 while (true) { |
1909 { |
1912 { |
1910 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); |
1913 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); |
1911 if (!is_external_suspend()) { |
1914 if (!is_external_suspend()) { |
1912 set_terminated(_thread_exiting); |
1915 set_terminated(_thread_exiting); |
1913 ThreadService::current_thread_exiting(this); |
1916 ThreadService::current_thread_exiting(this, is_daemon(threadObj())); |
1914 break; |
1917 break; |
1915 } |
1918 } |
1916 // Implied else: |
1919 // Implied else: |
1917 // Things get a little tricky here. We have a pending external |
1920 // Things get a little tricky here. We have a pending external |
1918 // suspend request, but we are holding the SR_lock so we |
1921 // suspend request, but we are holding the SR_lock so we |
1928 // external suspend request and will be able to mark ourselves as |
1931 // external suspend request and will be able to mark ourselves as |
1929 // exiting. |
1932 // exiting. |
1930 } |
1933 } |
1931 // no more external suspends are allowed at this point |
1934 // no more external suspends are allowed at this point |
1932 } else { |
1935 } else { |
|
1936 assert(!is_terminated() && !is_exiting(), "must not be exiting"); |
1933 // before_exit() has already posted JVMTI THREAD_END events |
1937 // before_exit() has already posted JVMTI THREAD_END events |
1934 } |
1938 } |
1935 |
1939 |
1936 if (log_is_enabled(Debug, os, thread, timer)) { |
1940 if (log_is_enabled(Debug, os, thread, timer)) { |
1937 _timer_exit_phase1.stop(); |
1941 _timer_exit_phase1.stop(); |
4330 } |
4334 } |
4331 |
4335 |
4332 |
4336 |
4333 void Threads::add(JavaThread* p, bool force_daemon) { |
4337 void Threads::add(JavaThread* p, bool force_daemon) { |
4334 // The threads lock must be owned at this point |
4338 // The threads lock must be owned at this point |
4335 assert_locked_or_safepoint(Threads_lock); |
4339 assert(Threads_lock->owned_by_self(), "must have threads lock"); |
4336 |
4340 |
4337 BarrierSet::barrier_set()->on_thread_attach(p); |
4341 BarrierSet::barrier_set()->on_thread_attach(p); |
4338 |
4342 |
4339 p->set_next(_thread_list); |
4343 p->set_next(_thread_list); |
4340 _thread_list = p; |
4344 _thread_list = p; |
4346 _number_of_threads++; |
4350 _number_of_threads++; |
4347 oop threadObj = p->threadObj(); |
4351 oop threadObj = p->threadObj(); |
4348 bool daemon = true; |
4352 bool daemon = true; |
4349 // Bootstrapping problem: threadObj can be null for initial |
4353 // Bootstrapping problem: threadObj can be null for initial |
4350 // JavaThread (or for threads attached via JNI) |
4354 // JavaThread (or for threads attached via JNI) |
4351 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { |
4355 if ((!force_daemon) && !is_daemon((threadObj))) { |
4352 _number_of_non_daemon_threads++; |
4356 _number_of_non_daemon_threads++; |
4353 daemon = false; |
4357 daemon = false; |
4354 } |
4358 } |
4355 |
4359 |
4356 ThreadService::add_thread(p, daemon); |
4360 ThreadService::add_thread(p, daemon); |
4391 } |
4395 } |
4392 |
4396 |
4393 _number_of_threads--; |
4397 _number_of_threads--; |
4394 oop threadObj = p->threadObj(); |
4398 oop threadObj = p->threadObj(); |
4395 bool daemon = true; |
4399 bool daemon = true; |
4396 if (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj)) { |
4400 if (!is_daemon(threadObj)) { |
4397 _number_of_non_daemon_threads--; |
4401 _number_of_non_daemon_threads--; |
4398 daemon = false; |
4402 daemon = false; |
4399 |
4403 |
4400 // Only one thread left, do a notify on the Threads_lock so a thread waiting |
4404 // Only one thread left, do a notify on the Threads_lock so a thread waiting |
4401 // on destroy_vm will wake up. |
4405 // on destroy_vm will wake up. |