hotspot/src/share/vm/runtime/thread.cpp
changeset 14120 7d298141c258
parent 14083 103054a71a30
child 14289 aec758622b4b
equal deleted inserted replaced
14117:6e2e697e310f 14120:7d298141c258
   321   //
   321   //
   322   // set up any platform-specific state.
   322   // set up any platform-specific state.
   323   os::initialize_thread(this);
   323   os::initialize_thread(this);
   324 
   324 
   325 #if INCLUDE_NMT
   325 #if INCLUDE_NMT
   326    // record thread's native stack, stack grows downward
   326   // record thread's native stack, stack grows downward
   327   if (MemTracker::is_on()) {
   327   address stack_low_addr = stack_base() - stack_size();
   328     address stack_low_addr = stack_base() - stack_size();
   328   MemTracker::record_thread_stack(stack_low_addr, stack_size(), this,
   329     MemTracker::record_thread_stack(stack_low_addr, stack_size(), this,
       
   330       CURRENT_PC);
   329       CURRENT_PC);
   331   }
       
   332 #endif // INCLUDE_NMT
   330 #endif // INCLUDE_NMT
   333 }
   331 }
   334 
   332 
   335 
   333 
   336 Thread::~Thread() {
   334 Thread::~Thread() {
   343   // not proper way to enforce that.
   341   // not proper way to enforce that.
   344 #if INCLUDE_NMT
   342 #if INCLUDE_NMT
   345   if (_stack_base != NULL) {
   343   if (_stack_base != NULL) {
   346     address low_stack_addr = stack_base() - stack_size();
   344     address low_stack_addr = stack_base() - stack_size();
   347     MemTracker::release_thread_stack(low_stack_addr, stack_size(), this);
   345     MemTracker::release_thread_stack(low_stack_addr, stack_size(), this);
       
   346 #ifdef ASSERT
       
   347     set_stack_base(NULL);
       
   348 #endif
   348   }
   349   }
   349 #endif // INCLUDE_NMT
   350 #endif // INCLUDE_NMT
   350 
   351 
   351   // deallocate data structures
   352   // deallocate data structures
   352   delete resource_area();
   353   delete resource_area();
  1519 JavaThread::~JavaThread() {
  1520 JavaThread::~JavaThread() {
  1520   if (TraceThreadEvents) {
  1521   if (TraceThreadEvents) {
  1521       tty->print_cr("terminate thread %p", this);
  1522       tty->print_cr("terminate thread %p", this);
  1522   }
  1523   }
  1523 
  1524 
  1524   // Info NMT that this JavaThread is exiting, its memory
  1525   // By now, this thread should already be invisible to safepoint,
  1525   // recorder should be collected
  1526   // and its per-thread recorder also collected.
  1526   assert(!is_safepoint_visible(), "wrong state");
  1527   assert(!is_safepoint_visible(), "wrong state");
  1527   MemTracker::thread_exiting(this);
  1528 #if INCLUDE_NMT
       
  1529   assert(get_recorder() == NULL, "Already collected");
       
  1530 #endif // INCLUDE_NMT
  1528 
  1531 
  1529   // JSR166 -- return the parker to the free list
  1532   // JSR166 -- return the parker to the free list
  1530   Parker::Release(_parker);
  1533   Parker::Release(_parker);
  1531   _parker = NULL ;
  1534   _parker = NULL ;
  1532 
  1535 
  2423     }
  2426     }
  2424   }
  2427   }
  2425 }
  2428 }
  2426 
  2429 
  2427 void JavaThread::remove_stack_guard_pages() {
  2430 void JavaThread::remove_stack_guard_pages() {
       
  2431   assert(Thread::current() == this, "from different thread");
  2428   if (_stack_guard_state == stack_guard_unused) return;
  2432   if (_stack_guard_state == stack_guard_unused) return;
  2429   address low_addr = stack_base() - stack_size();
  2433   address low_addr = stack_base() - stack_size();
  2430   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
  2434   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
  2431 
  2435 
  2432   if (os::allocate_stack_guard_pages()) {
  2436   if (os::allocate_stack_guard_pages()) {
  4091     // of this thread since it is removed from the queue.
  4095     // of this thread since it is removed from the queue.
  4092     p->set_terminated_value();
  4096     p->set_terminated_value();
  4093 
  4097 
  4094     // Now, this thread is not visible to safepoint
  4098     // Now, this thread is not visible to safepoint
  4095     p->set_safepoint_visible(false);
  4099     p->set_safepoint_visible(false);
  4096 
  4100     // once the thread becomes safepoint invisible, we can not use its per-thread
       
  4101     // recorder. And Threads::do_threads() no longer walks this thread, so we have
       
  4102     // to release its per-thread recorder here.
       
  4103     MemTracker::thread_exiting(p);
  4097   } // unlock Threads_lock
  4104   } // unlock Threads_lock
  4098 
  4105 
  4099   // Since Events::log uses a lock, we grab it outside the Threads_lock
  4106   // Since Events::log uses a lock, we grab it outside the Threads_lock
  4100   Events::log(p, "Thread exited: " INTPTR_FORMAT, p);
  4107   Events::log(p, "Thread exited: " INTPTR_FORMAT, p);
  4101 }
  4108 }