1356 assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required"); |
1356 assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required"); |
1357 _startable = true; |
1357 _startable = true; |
1358 } |
1358 } |
1359 |
1359 |
1360 void WatcherThread::stop() { |
1360 void WatcherThread::stop() { |
1361 { |
1361 // Get the PeriodicTask_lock if we can. If we cannot, then the |
1362 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
1362 // WatcherThread is using it and we don't want to block on that lock |
1363 _should_terminate = true; |
1363 // here because that might cause a safepoint deadlock depending on |
1364 OrderAccess::fence(); // ensure WatcherThread sees update in main loop |
1364 // what the current WatcherThread tasks are doing. |
1365 |
1365 bool have_lock = PeriodicTask_lock->try_lock(); |
|
1366 |
|
1367 _should_terminate = true; |
|
1368 OrderAccess::fence(); // ensure WatcherThread sees update in main loop |
|
1369 |
|
1370 if (have_lock) { |
1366 WatcherThread* watcher = watcher_thread(); |
1371 WatcherThread* watcher = watcher_thread(); |
1367 if (watcher != NULL) |
1372 if (watcher != NULL) { |
|
1373 // If we managed to get the lock, then we should unpark the |
|
1374 // WatcherThread so that it can see we want it to stop. |
1368 watcher->unpark(); |
1375 watcher->unpark(); |
|
1376 } |
|
1377 |
|
1378 PeriodicTask_lock->unlock(); |
1369 } |
1379 } |
1370 |
1380 |
1371 // it is ok to take late safepoints here, if needed |
1381 // it is ok to take late safepoints here, if needed |
1372 MutexLocker mu(Terminator_lock); |
1382 MutexLocker mu(Terminator_lock); |
1373 |
1383 |