1294 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); 1295 _next = _the_list._head; 1296 OrderAccess::release_store(&_the_list._head, this); 1297 } 1298 1299 void NonJavaThread::remove_from_the_list() { 1300 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); 1301 NonJavaThread* volatile* p = &_the_list._head; 1302 for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) { 1303 if (t == this) { 1304 *p = this->_next; 1305 // Wait for any in-progress iterators. Concurrent synchronize is 1306 // not allowed, so do it while holding the list lock. 1307 _the_list._protect.synchronize(); 1308 break; 1309 } 1310 } 1311 } 1312 1313 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(); 1318 1319 // This is slightly odd in that NamedThread is a subclass, but 1320 // in fact name() is defined in Thread 1321 assert(this->name() != NULL, "thread name was not set before it was started"); 1322 this->set_native_thread_name(this->name()); 1323 } 1324 1325 void NonJavaThread::post_run() { 1326 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(); 1330 // Ensure thread-local-storage is cleared before termination. 1331 Thread::clear_thread_current(); 1332 } 1333 1334 // NamedThread -- non-JavaThread subclasses with multiple 1335 // uniquely named instances should derive from this. 1336 NamedThread::NamedThread() : 1337 NonJavaThread(), 1338 _name(NULL), 1339 _processed_thread(NULL), 1340 _gc_id(GCId::undefined()) 1341 {} 1342 1343 NamedThread::~NamedThread() { 1344 if (_name != NULL) { 1345 FREE_C_HEAP_ARRAY(char, _name); 1346 _name = NULL; 1347 } 1348 } 1349 | 1294 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); 1295 _next = _the_list._head; 1296 OrderAccess::release_store(&_the_list._head, this); 1297 } 1298 1299 void NonJavaThread::remove_from_the_list() { 1300 MutexLockerEx lock(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); 1301 NonJavaThread* volatile* p = &_the_list._head; 1302 for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) { 1303 if (t == this) { 1304 *p = this->_next; 1305 // Wait for any in-progress iterators. Concurrent synchronize is 1306 // not allowed, so do it while holding the list lock. 1307 _the_list._protect.synchronize(); 1308 break; 1309 } 1310 } 1311 } 1312 1313 void NonJavaThread::pre_run() { 1314 { 1315 SuspendibleThreadSetJoiner sts(!is_VM_thread() && !is_Worker_thread()); 1316 add_to_the_list(); 1317 1318 // Initialize BarrierSet-related data after adding to list. 1319 assert(BarrierSet::barrier_set() != NULL, "invariant"); 1320 BarrierSet::barrier_set()->on_thread_attach(this); 1321 } 1322 1323 // This is slightly odd in that NamedThread is a subclass, but 1324 // in fact name() is defined in Thread 1325 assert(this->name() != NULL, "thread name was not set before it was started"); 1326 this->set_native_thread_name(this->name()); 1327 } 1328 1329 void NonJavaThread::post_run() { 1330 JFR_ONLY(Jfr::on_thread_exit(this);) 1331 { 1332 SuspendibleThreadSetJoiner sts(!is_VM_thread() && !is_Worker_thread()); 1333 1334 // Clean up BarrierSet data before removing from list. 1335 BarrierSet::barrier_set()->on_thread_detach(this); 1336 1337 remove_from_the_list(); 1338 } 1339 // Ensure thread-local-storage is cleared before termination. 1340 Thread::clear_thread_current(); 1341 } 1342 1343 // NamedThread -- non-JavaThread subclasses with multiple 1344 // uniquely named instances should derive from this. 1345 NamedThread::NamedThread() : 1346 NonJavaThread(), 1347 _name(NULL), 1348 _processed_thread(NULL), 1349 _gc_id(GCId::undefined()) 1350 {} 1351 1352 NamedThread::~NamedThread() { 1353 if (_name != NULL) { 1354 FREE_C_HEAP_ARRAY(char, _name); 1355 _name = NULL; 1356 } 1357 } 1358 |