src/hotspot/share/runtime/thread.cpp
changeset 54366 2b48cedce327
parent 54329 ddd60ad787d4
child 54385 9559ba212c18
equal deleted inserted replaced
54365:dd5c64326027 54366:2b48cedce327
  1289 }
  1289 }
  1290 
  1290 
  1291 NonJavaThread::~NonJavaThread() { }
  1291 NonJavaThread::~NonJavaThread() { }
  1292 
  1292 
  1293 void NonJavaThread::add_to_the_list() {
  1293 void NonJavaThread::add_to_the_list() {
  1294   MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1294   MutexLockerEx ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1295   _next = _the_list._head;
  1295   // Initialize BarrierSet-related data before adding to list.
       
  1296   BarrierSet::barrier_set()->on_thread_attach(this);
       
  1297   OrderAccess::release_store(&_next, _the_list._head);
  1296   OrderAccess::release_store(&_the_list._head, this);
  1298   OrderAccess::release_store(&_the_list._head, this);
  1297 }
  1299 }
  1298 
  1300 
  1299 void NonJavaThread::remove_from_the_list() {
  1301 void NonJavaThread::remove_from_the_list() {
  1300   MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1302   {
  1301   NonJavaThread* volatile* p = &_the_list._head;
  1303     MutexLockerEx ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
  1302   for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
  1304     // Cleanup BarrierSet-related data before removing from list.
  1303     if (t == this) {
  1305     BarrierSet::barrier_set()->on_thread_detach(this);
  1304       *p = this->_next;
  1306     NonJavaThread* volatile* p = &_the_list._head;
  1305       // Wait for any in-progress iterators.  Concurrent synchronize is
  1307     for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
  1306       // not allowed, so do it while holding the list lock.
  1308       if (t == this) {
  1307       _the_list._protect.synchronize();
  1309         *p = _next;
  1308       break;
  1310         break;
  1309     }
  1311       }
  1310   }
  1312     }
       
  1313   }
       
  1314   // Wait for any in-progress iterators.  Concurrent synchronize is not
       
  1315   // allowed, so do it while holding a dedicated lock.  Outside and distinct
       
  1316   // from NJTList_lock in case an iteration attempts to lock it.
       
  1317   MutexLockerEx ml(NonJavaThreadsListSync_lock, Mutex::_no_safepoint_check_flag);
       
  1318   _the_list._protect.synchronize();
       
  1319   _next = NULL;                 // Safe to drop the link now.
  1311 }
  1320 }
  1312 
  1321 
  1313 void NonJavaThread::pre_run() {
  1322 void NonJavaThread::pre_run() {
  1314   // Initialize BarrierSet-related data before adding to list.
       
  1315   assert(BarrierSet::barrier_set() != NULL, "invariant");
       
  1316   BarrierSet::barrier_set()->on_thread_attach(this);
       
  1317   add_to_the_list();
  1323   add_to_the_list();
  1318 
  1324 
  1319   // This is slightly odd in that NamedThread is a subclass, but
  1325   // This is slightly odd in that NamedThread is a subclass, but
  1320   // in fact name() is defined in Thread
  1326   // in fact name() is defined in Thread
  1321   assert(this->name() != NULL, "thread name was not set before it was started");
  1327   assert(this->name() != NULL, "thread name was not set before it was started");
  1322   this->set_native_thread_name(this->name());
  1328   this->set_native_thread_name(this->name());
  1323 }
  1329 }
  1324 
  1330 
  1325 void NonJavaThread::post_run() {
  1331 void NonJavaThread::post_run() {
  1326   JFR_ONLY(Jfr::on_thread_exit(this);)
  1332   JFR_ONLY(Jfr::on_thread_exit(this);)
  1327   // Clean up BarrierSet data before removing from list.
       
  1328   BarrierSet::barrier_set()->on_thread_detach(this);
       
  1329   remove_from_the_list();
  1333   remove_from_the_list();
  1330   // Ensure thread-local-storage is cleared before termination.
  1334   // Ensure thread-local-storage is cleared before termination.
  1331   Thread::clear_thread_current();
  1335   Thread::clear_thread_current();
  1332 }
  1336 }
  1333 
  1337