< prev index next >

src/share/vm/runtime/thread.cpp

Print this page




1309         // Wake up 5 seconds later, the fatal handler may reset OnError or
1310         // ShowMessageBoxOnError when it is ready to abort.
1311         os::sleep(this, 5 * 1000, false);
1312       }
1313     }
1314 
1315     if (_should_terminate) {
1316       // check for termination before posting the next tick
1317       break;
1318     }
1319 
1320     PeriodicTask::real_time_tick(time_waited);
1321   }
1322 
1323   // Signal that it is terminated
1324   {
1325     MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
1326     _watcher_thread = NULL;
1327     Terminator_lock->notify();
1328   }









1329 }
1330 
1331 void WatcherThread::start() {
1332   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1333 
1334   if (watcher_thread() == NULL && _startable) {
1335     _should_terminate = false;
1336     // Create the single instance of WatcherThread
1337     new WatcherThread();
1338   }
1339 }
1340 
1341 void WatcherThread::make_startable() {
1342   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1343   _startable = true;
1344 }
1345 
1346 void WatcherThread::stop() {

1347   {
1348     // Follow normal safepoint aware lock enter protocol since the
1349     // WatcherThread is stopped by another JavaThread.
1350     MutexLocker ml(PeriodicTask_lock);
1351     _should_terminate = true;
1352 
1353     WatcherThread* watcher = watcher_thread();
1354     if (watcher != NULL) {
1355       // unpark the WatcherThread so it can see that it should terminate
1356       watcher->unpark();
1357     }
1358   }
1359 
1360   MutexLocker mu(Terminator_lock);
1361 
1362   while (watcher_thread() != NULL) {
1363     // This wait should make safepoint checks, wait without a timeout,
1364     // and wait as a suspend-equivalent condition.
1365     //
1366     // Note: If the FlatProfiler is running, then this thread is waiting
1367     // for the WatcherThread to terminate and the WatcherThread, via the
1368     // FlatProfiler task, is waiting for the external suspend request on
1369     // this thread to complete. wait_for_ext_suspend_completion() will
1370     // eventually timeout, but that takes time. Making this wait a
1371     // suspend-equivalent condition solves that timeout problem.
1372     //
1373     Terminator_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
1374                           Mutex::_as_suspend_equivalent_flag);
1375   }




1376 }
1377 
1378 void WatcherThread::unpark() {
1379   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1380   PeriodicTask_lock->notify();
1381 }
1382 
1383 void WatcherThread::print_on(outputStream* st) const {
1384   st->print("\"%s\" ", name());
1385   Thread::print_on(st);
1386   st->cr();
1387 }
1388 
1389 // ======= JavaThread ========
1390 
1391 #if INCLUDE_JVMCI
1392 
1393 jlong* JavaThread::_jvmci_old_thread_counters;
1394 
1395 bool jvmci_counters_include(JavaThread* thread) {




1309         // Wake up 5 seconds later, the fatal handler may reset OnError or
1310         // ShowMessageBoxOnError when it is ready to abort.
1311         os::sleep(this, 5 * 1000, false);
1312       }
1313     }
1314 
1315     if (_should_terminate) {
1316       // check for termination before posting the next tick
1317       break;
1318     }
1319 
1320     PeriodicTask::real_time_tick(time_waited);
1321   }
1322 
1323   // Signal that it is terminated
1324   {
1325     MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
1326     _watcher_thread = NULL;
1327     Terminator_lock->notify();
1328   }
1329 
1330   // Deletion is done synchronously by the thread terminating the VM
1331   // so that the WatcherThread deletion doesn't race with that thread as it
1332   // tears down VM resources. That means 'this' may already have been
1333   // deallocated so we can't reference it. However we must do some cleanup 
1334   // ourselves before allowing the native thread to terminate
1335 
1336   ThreadLocalStorage::set_thread(NULL);
1337 
1338 }
1339 
1340 void WatcherThread::start() {
1341   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1342 
1343   if (watcher_thread() == NULL && _startable) {
1344     _should_terminate = false;
1345     // Create the single instance of WatcherThread
1346     new WatcherThread();
1347   }
1348 }
1349 
1350 void WatcherThread::make_startable() {
1351   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1352   _startable = true;
1353 }
1354 
1355 void WatcherThread::stop() {
1356   WatcherThread* watcher = NULL;
1357   {
1358     // Follow normal safepoint aware lock enter protocol since the
1359     // WatcherThread is stopped by another JavaThread.
1360     MutexLocker ml(PeriodicTask_lock);
1361     _should_terminate = true;
1362 
1363     watcher = watcher_thread();
1364     if (watcher != NULL) {
1365       // unpark the WatcherThread so it can see that it should terminate
1366       watcher->unpark();
1367     }
1368   }
1369 
1370   MutexLocker mu(Terminator_lock);
1371 
1372   while (watcher_thread() != NULL) {
1373     // This wait should make safepoint checks, wait without a timeout,
1374     // and wait as a suspend-equivalent condition.
1375     //
1376     // Note: If the FlatProfiler is running, then this thread is waiting
1377     // for the WatcherThread to terminate and the WatcherThread, via the
1378     // FlatProfiler task, is waiting for the external suspend request on
1379     // this thread to complete. wait_for_ext_suspend_completion() will
1380     // eventually timeout, but that takes time. Making this wait a
1381     // suspend-equivalent condition solves that timeout problem.
1382     //
1383     Terminator_lock->wait(!Mutex::_no_safepoint_check_flag, 0,
1384                           Mutex::_as_suspend_equivalent_flag);
1385   }
1386 
1387   // can't get here till the WatcherThread has indicated it is terminating
1388   if (watcher != NULL)
1389     delete watcher;
1390 }
1391 
1392 void WatcherThread::unpark() {
1393   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
1394   PeriodicTask_lock->notify();
1395 }
1396 
1397 void WatcherThread::print_on(outputStream* st) const {
1398   st->print("\"%s\" ", name());
1399   Thread::print_on(st);
1400   st->cr();
1401 }
1402 
1403 // ======= JavaThread ========
1404 
1405 #if INCLUDE_JVMCI
1406 
1407 jlong* JavaThread::_jvmci_old_thread_counters;
1408 
1409 bool jvmci_counters_include(JavaThread* thread) {


< prev index next >