src/hotspot/share/runtime/thread.cpp
changeset 54416 b788c494aa46
parent 54385 9559ba212c18
child 54439 d9b46b7de028
equal deleted inserted replaced
54415:00fda51e28cf 54416:b788c494aa46
  2019 
  2019 
  2020   if (log_is_enabled(Debug, os, thread, timer)) {
  2020   if (log_is_enabled(Debug, os, thread, timer)) {
  2021     _timer_exit_phase1.stop();
  2021     _timer_exit_phase1.stop();
  2022     _timer_exit_phase2.start();
  2022     _timer_exit_phase2.start();
  2023   }
  2023   }
       
  2024 
       
  2025   // Capture daemon status before the thread is marked as terminated.
       
  2026   bool daemon = is_daemon(threadObj());
       
  2027 
  2024   // Notify waiters on thread object. This has to be done after exit() is called
  2028   // Notify waiters on thread object. This has to be done after exit() is called
  2025   // on the thread (if the thread is the last thread in a daemon ThreadGroup the
  2029   // on the thread (if the thread is the last thread in a daemon ThreadGroup the
  2026   // group should have the destroyed bit set before waiters are notified).
  2030   // group should have the destroyed bit set before waiters are notified).
  2027   ensure_join(this);
  2031   ensure_join(this);
  2028   assert(!this->has_pending_exception(), "ensure_join should have cleared");
  2032   assert(!this->has_pending_exception(), "ensure_join should have cleared");
  2087   if (log_is_enabled(Debug, os, thread, timer)) {
  2091   if (log_is_enabled(Debug, os, thread, timer)) {
  2088     _timer_exit_phase3.stop();
  2092     _timer_exit_phase3.stop();
  2089     _timer_exit_phase4.start();
  2093     _timer_exit_phase4.start();
  2090   }
  2094   }
  2091   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
  2095   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
  2092   Threads::remove(this);
  2096   Threads::remove(this, daemon);
  2093 
  2097 
  2094   if (log_is_enabled(Debug, os, thread, timer)) {
  2098   if (log_is_enabled(Debug, os, thread, timer)) {
  2095     _timer_exit_phase4.stop();
  2099     _timer_exit_phase4.stop();
  2096     ResourceMark rm(this);
  2100     ResourceMark rm(this);
  2097     log_debug(os, thread, timer)("name='%s'"
  2101     log_debug(os, thread, timer)("name='%s'"
  2105                                  _timer_exit_phase3.milliseconds(),
  2109                                  _timer_exit_phase3.milliseconds(),
  2106                                  _timer_exit_phase4.milliseconds());
  2110                                  _timer_exit_phase4.milliseconds());
  2107   }
  2111   }
  2108 }
  2112 }
  2109 
  2113 
  2110 void JavaThread::cleanup_failed_attach_current_thread() {
  2114 void JavaThread::cleanup_failed_attach_current_thread(bool is_daemon) {
  2111   if (active_handles() != NULL) {
  2115   if (active_handles() != NULL) {
  2112     JNIHandleBlock* block = active_handles();
  2116     JNIHandleBlock* block = active_handles();
  2113     set_active_handles(NULL);
  2117     set_active_handles(NULL);
  2114     JNIHandleBlock::release_block(block);
  2118     JNIHandleBlock::release_block(block);
  2115   }
  2119   }
  2127     tlab().retire();
  2131     tlab().retire();
  2128   }
  2132   }
  2129 
  2133 
  2130   BarrierSet::barrier_set()->on_thread_detach(this);
  2134   BarrierSet::barrier_set()->on_thread_detach(this);
  2131 
  2135 
  2132   Threads::remove(this);
  2136   Threads::remove(this, is_daemon);
  2133   this->smr_delete();
  2137   this->smr_delete();
  2134 }
  2138 }
  2135 
  2139 
  2136 JavaThread* JavaThread::active() {
  2140 JavaThread* JavaThread::active() {
  2137   Thread* thread = Thread::current();
  2141   Thread* thread = Thread::current();
  4453 
  4457 
  4454   // Possible GC point.
  4458   // Possible GC point.
  4455   Events::log(p, "Thread added: " INTPTR_FORMAT, p2i(p));
  4459   Events::log(p, "Thread added: " INTPTR_FORMAT, p2i(p));
  4456 }
  4460 }
  4457 
  4461 
  4458 void Threads::remove(JavaThread* p) {
  4462 void Threads::remove(JavaThread* p, bool is_daemon) {
  4459 
  4463 
  4460   // Reclaim the ObjectMonitors from the omInUseList and omFreeList of the moribund thread.
  4464   // Reclaim the ObjectMonitors from the omInUseList and omFreeList of the moribund thread.
  4461   ObjectSynchronizer::omFlush(p);
  4465   ObjectSynchronizer::omFlush(p);
  4462 
  4466 
  4463   // Extra scope needed for Thread_lock, so we can check
  4467   // Extra scope needed for Thread_lock, so we can check
  4482     } else {
  4486     } else {
  4483       _thread_list = p->next();
  4487       _thread_list = p->next();
  4484     }
  4488     }
  4485 
  4489 
  4486     _number_of_threads--;
  4490     _number_of_threads--;
  4487     oop threadObj = p->threadObj();
  4491     if (!is_daemon) {
  4488     bool daemon = true;
       
  4489     if (!is_daemon(threadObj)) {
       
  4490       _number_of_non_daemon_threads--;
  4492       _number_of_non_daemon_threads--;
  4491       daemon = false;
       
  4492 
  4493 
  4493       // Only one thread left, do a notify on the Threads_lock so a thread waiting
  4494       // Only one thread left, do a notify on the Threads_lock so a thread waiting
  4494       // on destroy_vm will wake up.
  4495       // on destroy_vm will wake up.
  4495       if (number_of_non_daemon_threads() == 1) {
  4496       if (number_of_non_daemon_threads() == 1) {
  4496         Threads_lock->notify_all();
  4497         Threads_lock->notify_all();
  4497       }
  4498       }
  4498     }
  4499     }
  4499     ThreadService::remove_thread(p, daemon);
  4500     ThreadService::remove_thread(p, is_daemon);
  4500 
  4501 
  4501     // Make sure that safepoint code disregard this thread. This is needed since
  4502     // Make sure that safepoint code disregard this thread. This is needed since
  4502     // the thread might mess around with locks after this point. This can cause it
  4503     // the thread might mess around with locks after this point. This can cause it
  4503     // to do callbacks into the safepoint code. However, the safepoint code is not aware
  4504     // to do callbacks into the safepoint code. However, the safepoint code is not aware
  4504     // of this thread since it is removed from the queue.
  4505     // of this thread since it is removed from the queue.