--- old/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2016-03-09 16:00:18.466985998 -0500 +++ new/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2016-03-09 16:00:18.321987811 -0500 @@ -1413,7 +1413,7 @@ if (_foregroundGCShouldWait) { // We are going to be waiting for action for the CMS thread; // it had better not be gone (for instance at shutdown)! - assert(ConcurrentMarkSweepThread::cmst() != NULL, + assert(ConcurrentMarkSweepThread::cmst() != NULL && !ConcurrentMarkSweepThread::cmst()->has_terminated(), "CMS thread must be running"); // Wait here until the background collector gives us the go-ahead ConcurrentMarkSweepThread::clear_CMS_flag( @@ -3650,7 +3650,7 @@ // XXX FIX ME!!! YSR size_t loops = 0, workdone = 0, cumworkdone = 0, waited = 0; while (!(should_abort_preclean() || - ConcurrentMarkSweepThread::should_terminate())) { + ConcurrentMarkSweepThread::cmst()->should_terminate())) { workdone = preclean_work(CMSPrecleanRefLists2, CMSPrecleanSurvivors2); cumworkdone += workdone; loops++; --- old/src/share/vm/gc/cms/concurrentMarkSweepThread.cpp 2016-03-09 16:00:19.566972246 -0500 +++ new/src/share/vm/gc/cms/concurrentMarkSweepThread.cpp 2016-03-09 16:00:19.148977472 -0500 @@ -94,16 +94,16 @@ // We cannot start the SLT thread ourselves since we need // to be a JavaThread to do so. CMSLoopCountWarn loopY("CMS::run", "waiting for SLT installation", 2); - while (_slt == NULL && !_should_terminate) { + while (_slt == NULL && !should_terminate()) { CGC_lock->wait(true, 200); loopY.tick(); } clear_CMS_flag(CMS_cms_wants_token); } - while (!_should_terminate) { + while (!should_terminate()) { sleepBeforeNextCycle(); - if (_should_terminate) break; + if (should_terminate()) break; GCIdMark gc_id_mark; GCCause::Cause cause = _collector->_full_gc_requested ? _collector->_full_gc_cause : GCCause::_cms_concurrent_mark; @@ -149,7 +149,7 @@ void ConcurrentMarkSweepThread::threads_do(ThreadClosure* tc) { assert(tc != NULL, "Null ThreadClosure"); - if (cmst() != NULL) { + if (cmst() != NULL && !cmst()->has_terminated()) { tc->do_thread(cmst()); } assert(Universe::is_fully_initialized(), @@ -163,7 +163,7 @@ } void ConcurrentMarkSweepThread::print_all_on(outputStream* st) { - if (cmst() != NULL) { + if (cmst() != NULL && !cmst()->has_terminated()) { cmst()->print_on(st); st->cr(); } @@ -239,7 +239,7 @@ void ConcurrentMarkSweepThread::wait_on_cms_lock(long t_millis) { MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); - if (_should_terminate || _collector->_full_gc_requested) { + if (should_terminate() || _collector->_full_gc_requested) { return; } set_CMS_flag(CMS_cms_wants_token); // to provoke notifies @@ -268,7 +268,7 @@ unsigned int loop_count = 0; - while(!_should_terminate) { + while(!should_terminate()) { double now_time = os::elapsedTime(); long wait_time_millis; @@ -288,7 +288,7 @@ { MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); - if (_should_terminate || _collector->_full_gc_requested) { + if (should_terminate() || _collector->_full_gc_requested) { return; } set_CMS_flag(CMS_cms_wants_token); // to provoke notifies @@ -325,7 +325,7 @@ } void ConcurrentMarkSweepThread::sleepBeforeNextCycle() { - while (!_should_terminate) { + while (!should_terminate()) { if(CMSWaitDuration >= 0) { // Wait until the next synchronous GC, a concurrent full gc // request or a timeout, whichever is earlier. --- old/src/share/vm/gc/cms/concurrentMarkSweepThread.hpp 2016-03-09 16:00:20.427961482 -0500 +++ new/src/share/vm/gc/cms/concurrentMarkSweepThread.hpp 2016-03-09 16:00:20.268963470 -0500 @@ -85,19 +85,12 @@ static void print_all() { print_all_on(tty); } // Returns the CMS Thread - inline static ConcurrentMarkSweepThread* cmst() { - if (_cmst != NULL && !_cmst->_has_terminated) { - return _cmst; - } - return NULL; - } - + static ConcurrentMarkSweepThread* cmst() { return _cmst; } static CMSCollector* collector() { return _collector; } // Create and start the CMS Thread, or stop it on shutdown static ConcurrentMarkSweepThread* start(CMSCollector* collector); static void stop_all(); - static bool should_terminate() { return _cmst != NULL && _cmst->_should_terminate; } // Synchronization using CMS token static void synchronize(bool is_cms_thread); --- old/src/share/vm/gc/g1/concurrentG1RefineThread.cpp 2016-03-09 16:00:21.344950018 -0500 +++ new/src/share/vm/gc/g1/concurrentG1RefineThread.cpp 2016-03-09 16:00:21.164952269 -0500 @@ -78,7 +78,7 @@ void ConcurrentG1RefineThread::wait_for_completed_buffers() { DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); - while (!_should_terminate && !is_active()) { + while (!should_terminate() && !is_active()) { _monitor->wait(Mutex::_no_safepoint_check_flag); } } @@ -112,10 +112,10 @@ void ConcurrentG1RefineThread::run_service() { _vtime_start = os::elapsedVTime(); - while (!_should_terminate) { + while (!should_terminate()) { // Wait for work wait_for_completed_buffers(); - if (_should_terminate) { + if (should_terminate()) { break; } --- old/src/share/vm/gc/g1/concurrentMarkThread.cpp 2016-03-09 16:00:22.303938029 -0500 +++ new/src/share/vm/gc/g1/concurrentMarkThread.cpp 2016-03-09 16:00:22.106940492 -0500 @@ -111,10 +111,10 @@ G1CollectedHeap* g1h = G1CollectedHeap::heap(); G1CollectorPolicy* g1_policy = g1h->g1_policy(); - while (!_should_terminate) { + while (!should_terminate()) { // wait until started is set. sleepBeforeNextCycle(); - if (_should_terminate) { + if (should_terminate()) { _cm->root_regions()->cancel_scan(); break; } @@ -295,7 +295,7 @@ assert(!in_progress(), "should have been cleared"); MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); - while (!started() && !_should_terminate) { + while (!started() && !should_terminate()) { CGC_lock->wait(Mutex::_no_safepoint_check_flag); } --- old/src/share/vm/gc/g1/g1StringDedupThread.cpp 2016-03-09 16:00:23.214926641 -0500 +++ new/src/share/vm/gc/g1/g1StringDedupThread.cpp 2016-03-09 16:00:23.066928491 -0500 @@ -94,7 +94,7 @@ // Wait for the queue to become non-empty G1StringDedupQueue::wait(); - if (_should_terminate) { + if (should_terminate()) { break; } --- old/src/share/vm/gc/g1/g1YoungRemSetSamplingThread.cpp 2016-03-09 16:00:24.098915589 -0500 +++ new/src/share/vm/gc/g1/g1YoungRemSetSamplingThread.cpp 2016-03-09 16:00:23.935917627 -0500 @@ -44,7 +44,7 @@ void G1YoungRemSetSamplingThread::sleep_before_next_cycle() { MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag); - if (!_should_terminate) { + if (!should_terminate()) { uintx waitms = G1ConcRefinementServiceIntervalMillis; // 300, really should be? _monitor.wait(Mutex::_no_safepoint_check_flag, waitms); } @@ -53,7 +53,7 @@ void G1YoungRemSetSamplingThread::run_service() { double vtime_start = os::elapsedVTime(); - while (!_should_terminate) { + while (!should_terminate()) { sample_young_list_rs_lengths(); if (os::supports_vtime()) { --- old/src/share/vm/gc/shared/concurrentGCThread.hpp 2016-03-09 16:00:24.878905838 -0500 +++ new/src/share/vm/gc/shared/concurrentGCThread.hpp 2016-03-09 16:00:24.735907626 -0500 @@ -30,11 +30,11 @@ class ConcurrentGCThread: public NamedThread { friend class VMStructs; - -protected: + bool volatile _should_terminate; bool _has_terminated; - + +protected: // Create and start the thread (setting it's priority.) void create_and_start(ThreadPriority prio = NearMaxPriority); @@ -65,6 +65,9 @@ // shutdown following termination protocol virtual void stop(); + + bool should_terminate() { return _should_terminate; } + bool has_terminated() { return _has_terminated; } }; // The SurrogateLockerThread is used by concurrent GC threads for