@@ -1999,6 +1999,10 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
19991999 _timer_exit_phase1.stop ();
20002000 _timer_exit_phase2.start ();
20012001 }
2002+
2003+ // Capture daemon status before the thread is marked as terminated.
2004+ bool daemon = is_daemon (threadObj ());
2005+
20022006 // Notify waiters on thread object. This has to be done after exit() is called
20032007 // on the thread (if the thread is the last thread in a daemon ThreadGroup the
20042008 // group should have the destroyed bit set before waiters are notified).
@@ -2072,7 +2076,7 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
20722076 _timer_exit_phase4.start ();
20732077 }
20742078 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2075- Threads::remove (this );
2079+ Threads::remove (this , daemon );
20762080
20772081 if (log_is_enabled (Debug, os, thread, timer)) {
20782082 _timer_exit_phase4.stop ();
@@ -2090,7 +2094,7 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
20902094 }
20912095}
20922096
2093- void JavaThread::cleanup_failed_attach_current_thread () {
2097+ void JavaThread::cleanup_failed_attach_current_thread (bool is_daemon ) {
20942098 if (active_handles () != NULL ) {
20952099 JNIHandleBlock* block = active_handles ();
20962100 set_active_handles (NULL );
@@ -2112,7 +2116,7 @@ void JavaThread::cleanup_failed_attach_current_thread() {
21122116
21132117 BarrierSet::barrier_set ()->on_thread_detach (this );
21142118
2115- Threads::remove (this );
2119+ Threads::remove (this , is_daemon );
21162120 this ->smr_delete ();
21172121}
21182122
@@ -4440,7 +4444,7 @@ void Threads::add(JavaThread* p, bool force_daemon) {
44404444 Events::log (p, " Thread added: " INTPTR_FORMAT, p2i (p));
44414445}
44424446
4443- void Threads::remove (JavaThread* p) {
4447+ void Threads::remove (JavaThread* p, bool is_daemon ) {
44444448
44454449 // Reclaim the objectmonitors from the omInUseList and omFreeList of the moribund thread.
44464450 ObjectSynchronizer::omFlush (p);
@@ -4469,19 +4473,16 @@ void Threads::remove(JavaThread* p) {
44694473 }
44704474
44714475 _number_of_threads--;
4472- oop threadObj = p->threadObj ();
4473- bool daemon = true ;
4474- if (!is_daemon (threadObj)) {
4476+ if (!is_daemon) {
44754477 _number_of_non_daemon_threads--;
4476- daemon = false ;
44774478
44784479 // Only one thread left, do a notify on the Threads_lock so a thread waiting
44794480 // on destroy_vm will wake up.
44804481 if (number_of_non_daemon_threads () == 1 ) {
44814482 Threads_lock->notify_all ();
44824483 }
44834484 }
4484- ThreadService::remove_thread (p, daemon );
4485+ ThreadService::remove_thread (p, is_daemon );
44854486
44864487 // Make sure that safepoint code disregard this thread. This is needed since
44874488 // the thread might mess around with locks after this point. This can cause it
0 commit comments