src/hotspot/share/runtime/thread.cpp
changeset 49007 82d9d5744e5f
parent 49006 c6d1c4ad90f4
child 49036 bc92debe57e4
equal deleted inserted replaced
49006:c6d1c4ad90f4 49007:82d9d5744e5f
  1992 
  1992 
  1993   if (JvmtiEnv::environments_might_exist()) {
  1993   if (JvmtiEnv::environments_might_exist()) {
  1994     JvmtiExport::cleanup_thread(this);
  1994     JvmtiExport::cleanup_thread(this);
  1995   }
  1995   }
  1996 
  1996 
  1997   // We must flush any deferred card marks and other various GC barrier
  1997   BarrierSet::barrier_set()->on_thread_detach(this);
  1998   // related buffers (e.g. G1 SATB buffer and G1 dirty card queue buffer)
       
  1999   // before removing a thread from the list of active threads.
       
  2000   BarrierSet::barrier_set()->flush_deferred_barriers(this);
       
  2001 
  1998 
  2002   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
  1999   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
  2003     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
  2000     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
  2004     os::current_thread_id());
  2001     os::current_thread_id());
  2005 
  2002 
  2024                                  _timer_exit_phase3.milliseconds(),
  2021                                  _timer_exit_phase3.milliseconds(),
  2025                                  _timer_exit_phase4.milliseconds());
  2022                                  _timer_exit_phase4.milliseconds());
  2026   }
  2023   }
  2027 }
  2024 }
  2028 
  2025 
  2029 #if INCLUDE_ALL_GCS
       
  2030 void JavaThread::initialize_queues() {
       
  2031   assert(!SafepointSynchronize::is_at_safepoint(),
       
  2032          "we should not be at a safepoint");
       
  2033 
       
  2034   SATBMarkQueue& satb_queue = satb_mark_queue();
       
  2035   SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set();
       
  2036   // The SATB queue should have been constructed with its active
       
  2037   // field set to false.
       
  2038   assert(!satb_queue.is_active(), "SATB queue should not be active");
       
  2039   assert(satb_queue.is_empty(), "SATB queue should be empty");
       
  2040   // If we are creating the thread during a marking cycle, we should
       
  2041   // set the active field of the SATB queue to true.
       
  2042   if (satb_queue_set.is_active()) {
       
  2043     satb_queue.set_active(true);
       
  2044   }
       
  2045 
       
  2046   DirtyCardQueue& dirty_queue = dirty_card_queue();
       
  2047   // The dirty card queue should have been constructed with its
       
  2048   // active field set to true.
       
  2049   assert(dirty_queue.is_active(), "dirty card queue should be active");
       
  2050 }
       
  2051 #endif // INCLUDE_ALL_GCS
       
  2052 
       
  2053 void JavaThread::cleanup_failed_attach_current_thread() {
  2026 void JavaThread::cleanup_failed_attach_current_thread() {
  2054   if (active_handles() != NULL) {
  2027   if (active_handles() != NULL) {
  2055     JNIHandleBlock* block = active_handles();
  2028     JNIHandleBlock* block = active_handles();
  2056     set_active_handles(NULL);
  2029     set_active_handles(NULL);
  2057     JNIHandleBlock::release_block(block);
  2030     JNIHandleBlock::release_block(block);
  2068 
  2041 
  2069   if (UseTLAB) {
  2042   if (UseTLAB) {
  2070     tlab().make_parsable(true);  // retire TLAB, if any
  2043     tlab().make_parsable(true);  // retire TLAB, if any
  2071   }
  2044   }
  2072 
  2045 
  2073   BarrierSet::barrier_set()->flush_deferred_barriers(this);
  2046   BarrierSet::barrier_set()->on_thread_detach(this);
  2074 
  2047 
  2075   Threads::remove(this);
  2048   Threads::remove(this);
  2076   this->smr_delete();
  2049   this->smr_delete();
  2077 }
  2050 }
  2078 
       
  2079 
       
  2080 
       
  2081 
  2051 
  2082 JavaThread* JavaThread::active() {
  2052 JavaThread* JavaThread::active() {
  2083   Thread* thread = Thread::current();
  2053   Thread* thread = Thread::current();
  2084   if (thread->is_Java_thread()) {
  2054   if (thread->is_Java_thread()) {
  2085     return (JavaThread*) thread;
  2055     return (JavaThread*) thread;
  4330 
  4300 
  4331 void Threads::add(JavaThread* p, bool force_daemon) {
  4301 void Threads::add(JavaThread* p, bool force_daemon) {
  4332   // The threads lock must be owned at this point
  4302   // The threads lock must be owned at this point
  4333   assert_locked_or_safepoint(Threads_lock);
  4303   assert_locked_or_safepoint(Threads_lock);
  4334 
  4304 
  4335   // See the comment for this method in thread.hpp for its purpose and
  4305   BarrierSet::barrier_set()->on_thread_attach(p);
  4336   // why it is called here.
  4306 
  4337   p->initialize_queues();
       
  4338   p->set_next(_thread_list);
  4307   p->set_next(_thread_list);
  4339   _thread_list = p;
  4308   _thread_list = p;
  4340 
  4309 
  4341   // Once a JavaThread is added to the Threads list, smr_delete() has
  4310   // Once a JavaThread is added to the Threads list, smr_delete() has
  4342   // to be used to delete it. Otherwise we can just delete it directly.
  4311   // to be used to delete it. Otherwise we can just delete it directly.