< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page




1252                           vmSymbols::add_method_name(),
1253                           vmSymbols::thread_void_signature(),
1254                           threadObj,          // Arg 1
1255                           THREAD);
1256 }
1257 
1258 // List of all NonJavaThreads and safe iteration over that list.
1259 
1260 class NonJavaThread::List {
1261 public:
1262   NonJavaThread* volatile _head;
1263   SingleWriterSynchronizer _protect;
1264 
1265   List() : _head(NULL), _protect() {}
1266 };
1267 
1268 NonJavaThread::List NonJavaThread::_the_list;
1269 
1270 NonJavaThread::Iterator::Iterator() :
1271   _protect_enter(_the_list._protect.enter()),
1272   _current(OrderAccess::load_acquire(&_the_list._head))
1273 {}
1274 
1275 NonJavaThread::Iterator::~Iterator() {
1276   _the_list._protect.exit(_protect_enter);
1277 }
1278 
1279 void NonJavaThread::Iterator::step() {
1280   assert(!end(), "precondition");
1281   _current = OrderAccess::load_acquire(&_current->_next);
1282 }
1283 
1284 NonJavaThread::NonJavaThread() : Thread(), _next(NULL) {
1285   assert(BarrierSet::barrier_set() != NULL, "NonJavaThread created too soon!");
1286 }
1287 
1288 NonJavaThread::~NonJavaThread() { }
1289 
1290 void NonJavaThread::add_to_the_list() {
1291   MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1292   // Initialize BarrierSet-related data before adding to list.
1293   BarrierSet::barrier_set()->on_thread_attach(this);
1294   OrderAccess::release_store(&_next, _the_list._head);
1295   OrderAccess::release_store(&_the_list._head, this);
1296 }
1297 
1298 void NonJavaThread::remove_from_the_list() {
1299   {
1300     MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1301     // Cleanup BarrierSet-related data before removing from list.
1302     BarrierSet::barrier_set()->on_thread_detach(this);
1303     NonJavaThread* volatile* p = &_the_list._head;
1304     for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
1305       if (t == this) {
1306         *p = _next;
1307         break;
1308       }
1309     }
1310   }
1311   // Wait for any in-progress iterators.  Concurrent synchronize is not
1312   // allowed, so do it while holding a dedicated lock.  Outside and distinct
1313   // from NJTList_lock in case an iteration attempts to lock it.
1314   MutexLocker ml(NonJavaThreadsListSync_lock, Mutex::_no_safepoint_check_flag);
1315   _the_list._protect.synchronize();




1252                           vmSymbols::add_method_name(),
1253                           vmSymbols::thread_void_signature(),
1254                           threadObj,          // Arg 1
1255                           THREAD);
1256 }
1257 
1258 // List of all NonJavaThreads and safe iteration over that list.
1259 
1260 class NonJavaThread::List {
1261 public:
1262   NonJavaThread* volatile _head;
1263   SingleWriterSynchronizer _protect;
1264 
1265   List() : _head(NULL), _protect() {}
1266 };
1267 
1268 NonJavaThread::List NonJavaThread::_the_list;
1269 
1270 NonJavaThread::Iterator::Iterator() :
1271   _protect_enter(_the_list._protect.enter()),
1272   _current(Atomic::load_acquire(&_the_list._head))
1273 {}
1274 
1275 NonJavaThread::Iterator::~Iterator() {
1276   _the_list._protect.exit(_protect_enter);
1277 }
1278 
1279 void NonJavaThread::Iterator::step() {
1280   assert(!end(), "precondition");
1281   _current = Atomic::load_acquire(&_current->_next);
1282 }
1283 
1284 NonJavaThread::NonJavaThread() : Thread(), _next(NULL) {
1285   assert(BarrierSet::barrier_set() != NULL, "NonJavaThread created too soon!");
1286 }
1287 
1288 NonJavaThread::~NonJavaThread() { }
1289 
1290 void NonJavaThread::add_to_the_list() {
1291   MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1292   // Initialize BarrierSet-related data before adding to list.
1293   BarrierSet::barrier_set()->on_thread_attach(this);
1294   Atomic::release_store(&_next, _the_list._head);
1295   Atomic::release_store(&_the_list._head, this);
1296 }
1297 
1298 void NonJavaThread::remove_from_the_list() {
1299   {
1300     MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag);
1301     // Cleanup BarrierSet-related data before removing from list.
1302     BarrierSet::barrier_set()->on_thread_detach(this);
1303     NonJavaThread* volatile* p = &_the_list._head;
1304     for (NonJavaThread* t = *p; t != NULL; p = &t->_next, t = *p) {
1305       if (t == this) {
1306         *p = _next;
1307         break;
1308       }
1309     }
1310   }
1311   // Wait for any in-progress iterators.  Concurrent synchronize is not
1312   // allowed, so do it while holding a dedicated lock.  Outside and distinct
1313   // from NJTList_lock in case an iteration attempts to lock it.
1314   MutexLocker ml(NonJavaThreadsListSync_lock, Mutex::_no_safepoint_check_flag);
1315   _the_list._protect.synchronize();


< prev index next >