< prev index next >

src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp

Print this page




 110 double G1ConcurrentMarkThread::mmu_sleep_time(G1Policy* g1_policy, bool remark) {
 111   // There are 3 reasons to use SuspendibleThreadSetJoiner.
 112   // 1. To avoid concurrency problem.
 113   //    - G1MMUTracker::add_pause(), when_sec() and its variation(when_ms() etc..) can be called
 114   //      concurrently from ConcurrentMarkThread and VMThread.
 115   // 2. If currently a gc is running, but it has not yet updated the MMU,
 116   //    we will not forget to consider that pause in the MMU calculation.
 117   // 3. If currently a gc is running, ConcurrentMarkThread will wait it to be finished.
 118   //    And then sleep for predicted amount of time by delay_to_keep_mmu().
 119   SuspendibleThreadSetJoiner sts_join;
 120 
 121   const G1Analytics* analytics = g1_policy->analytics();
 122   double now = os::elapsedTime();
 123   double prediction_ms = remark ? analytics->predict_remark_time_ms()
 124                                 : analytics->predict_cleanup_time_ms();
 125   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
 126   return mmu_tracker->when_ms(now, prediction_ms);
 127 }
 128 
 129 void G1ConcurrentMarkThread::delay_to_keep_mmu(G1Policy* g1_policy, bool remark) {
 130   if (g1_policy->use_adaptive_young_list_length()) {
 131     jlong sleep_time_ms = mmu_sleep_time(g1_policy, remark);
 132     if (!_cm->has_aborted() && sleep_time_ms > 0) {
 133       os::sleep(this, sleep_time_ms, false);
 134     }
 135   }
 136 }
 137 
 138 class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc, marking)> {
 139   G1ConcurrentMark* _cm;
 140 
 141  public:
 142   G1ConcPhaseTimer(G1ConcurrentMark* cm, const char* title) :
 143     GCTraceConcTimeImpl<LogLevel::Info,  LogTag::_gc, LogTag::_marking>(title),
 144     _cm(cm)
 145   {
 146     _cm->gc_timer_cm()->register_gc_concurrent_start(title);
 147   }
 148 
 149   ~G1ConcPhaseTimer() {
 150     _cm->gc_timer_cm()->register_gc_concurrent_end();


 251     // wait until started is set.
 252     sleep_before_next_cycle();
 253     if (should_terminate()) {
 254       break;
 255     }
 256 
 257     cpmanager.set_phase(G1ConcurrentPhase::CONCURRENT_CYCLE, false /* force */);
 258 
 259     GCIdMark gc_id_mark;
 260 
 261     _cm->concurrent_cycle_start();
 262 
 263     GCTraceConcTime(Info, gc) tt("Concurrent Cycle");
 264     {
 265       ResourceMark rm;
 266       HandleMark   hm;
 267       double cycle_start = os::elapsedVTime();
 268 
 269       {
 270         G1ConcPhase p(G1ConcurrentPhase::CLEAR_CLAIMED_MARKS, this);
 271         MutexLocker ml(ClassLoaderDataGraph_lock);
 272         ClassLoaderDataGraph::clear_claimed_marks();
 273       }
 274 
 275       // We have to ensure that we finish scanning the root regions
 276       // before the next GC takes place. To ensure this we have to
 277       // make sure that we do not join the STS until the root regions
 278       // have been scanned. If we did then it's possible that a
 279       // subsequent GC could block us from joining the STS and proceed
 280       // without the root regions have been scanned which would be a
 281       // correctness issue.
 282 
 283       {
 284         G1ConcPhase p(G1ConcurrentPhase::SCAN_ROOT_REGIONS, this);
 285         _cm->scan_root_regions();
 286       }
 287 
 288       // It would be nice to use the G1ConcPhase class here but
 289       // the "end" logging is inside the loop and not at the end of
 290       // a scope. Also, the timer doesn't support nesting.
 291       // Mimicking the same log output instead.


 381       }
 382     }
 383 
 384     // Update the number of full collections that have been
 385     // completed. This will also notify the FullGCCount_lock in case a
 386     // Java thread is waiting for a full GC to happen (e.g., it
 387     // called System.gc() with +ExplicitGCInvokesConcurrent).
 388     {
 389       SuspendibleThreadSetJoiner sts_join;
 390       g1h->increment_old_marking_cycles_completed(true /* concurrent */);
 391 
 392       _cm->concurrent_cycle_end();
 393     }
 394 
 395     cpmanager.set_phase(G1ConcurrentPhase::IDLE, _cm->has_aborted() /* force */);
 396   }
 397   _cm->root_regions()->cancel_scan();
 398 }
 399 
 400 void G1ConcurrentMarkThread::stop_service() {
 401   MutexLocker ml(CGC_lock, Mutex::_no_safepoint_check_flag);
 402   CGC_lock->notify_all();
 403 }
 404 
 405 
 406 void G1ConcurrentMarkThread::sleep_before_next_cycle() {
 407   // We join here because we don't want to do the "shouldConcurrentMark()"
 408   // below while the world is otherwise stopped.
 409   assert(!in_progress(), "should have been cleared");
 410 
 411   MonitorLocker ml(CGC_lock, Mutex::_no_safepoint_check_flag);
 412   while (!started() && !should_terminate()) {
 413     ml.wait();
 414   }
 415 
 416   if (started()) {
 417     set_in_progress();
 418   }
 419 }


 110 double G1ConcurrentMarkThread::mmu_sleep_time(G1Policy* g1_policy, bool remark) {
 111   // There are 3 reasons to use SuspendibleThreadSetJoiner.
 112   // 1. To avoid concurrency problem.
 113   //    - G1MMUTracker::add_pause(), when_sec() and its variation(when_ms() etc..) can be called
 114   //      concurrently from ConcurrentMarkThread and VMThread.
 115   // 2. If currently a gc is running, but it has not yet updated the MMU,
 116   //    we will not forget to consider that pause in the MMU calculation.
 117   // 3. If currently a gc is running, ConcurrentMarkThread will wait it to be finished.
 118   //    And then sleep for predicted amount of time by delay_to_keep_mmu().
 119   SuspendibleThreadSetJoiner sts_join;
 120 
 121   const G1Analytics* analytics = g1_policy->analytics();
 122   double now = os::elapsedTime();
 123   double prediction_ms = remark ? analytics->predict_remark_time_ms()
 124                                 : analytics->predict_cleanup_time_ms();
 125   G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
 126   return mmu_tracker->when_ms(now, prediction_ms);
 127 }
 128 
 129 void G1ConcurrentMarkThread::delay_to_keep_mmu(G1Policy* g1_policy, bool remark) {
 130   if (g1_policy->adaptive_young_list_length()) {
 131     jlong sleep_time_ms = mmu_sleep_time(g1_policy, remark);
 132     if (!_cm->has_aborted() && sleep_time_ms > 0) {
 133       os::sleep(this, sleep_time_ms, false);
 134     }
 135   }
 136 }
 137 
 138 class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc, marking)> {
 139   G1ConcurrentMark* _cm;
 140 
 141  public:
 142   G1ConcPhaseTimer(G1ConcurrentMark* cm, const char* title) :
 143     GCTraceConcTimeImpl<LogLevel::Info,  LogTag::_gc, LogTag::_marking>(title),
 144     _cm(cm)
 145   {
 146     _cm->gc_timer_cm()->register_gc_concurrent_start(title);
 147   }
 148 
 149   ~G1ConcPhaseTimer() {
 150     _cm->gc_timer_cm()->register_gc_concurrent_end();


 251     // wait until started is set.
 252     sleep_before_next_cycle();
 253     if (should_terminate()) {
 254       break;
 255     }
 256 
 257     cpmanager.set_phase(G1ConcurrentPhase::CONCURRENT_CYCLE, false /* force */);
 258 
 259     GCIdMark gc_id_mark;
 260 
 261     _cm->concurrent_cycle_start();
 262 
 263     GCTraceConcTime(Info, gc) tt("Concurrent Cycle");
 264     {
 265       ResourceMark rm;
 266       HandleMark   hm;
 267       double cycle_start = os::elapsedVTime();
 268 
 269       {
 270         G1ConcPhase p(G1ConcurrentPhase::CLEAR_CLAIMED_MARKS, this);

 271         ClassLoaderDataGraph::clear_claimed_marks();
 272       }
 273 
 274       // We have to ensure that we finish scanning the root regions
 275       // before the next GC takes place. To ensure this we have to
 276       // make sure that we do not join the STS until the root regions
 277       // have been scanned. If we did then it's possible that a
 278       // subsequent GC could block us from joining the STS and proceed
 279       // without the root regions have been scanned which would be a
 280       // correctness issue.
 281 
 282       {
 283         G1ConcPhase p(G1ConcurrentPhase::SCAN_ROOT_REGIONS, this);
 284         _cm->scan_root_regions();
 285       }
 286 
 287       // It would be nice to use the G1ConcPhase class here but
 288       // the "end" logging is inside the loop and not at the end of
 289       // a scope. Also, the timer doesn't support nesting.
 290       // Mimicking the same log output instead.


 380       }
 381     }
 382 
 383     // Update the number of full collections that have been
 384     // completed. This will also notify the FullGCCount_lock in case a
 385     // Java thread is waiting for a full GC to happen (e.g., it
 386     // called System.gc() with +ExplicitGCInvokesConcurrent).
 387     {
 388       SuspendibleThreadSetJoiner sts_join;
 389       g1h->increment_old_marking_cycles_completed(true /* concurrent */);
 390 
 391       _cm->concurrent_cycle_end();
 392     }
 393 
 394     cpmanager.set_phase(G1ConcurrentPhase::IDLE, _cm->has_aborted() /* force */);
 395   }
 396   _cm->root_regions()->cancel_scan();
 397 }
 398 
 399 void G1ConcurrentMarkThread::stop_service() {
 400   MutexLockerEx ml(CGC_lock, Mutex::_no_safepoint_check_flag);
 401   CGC_lock->notify_all();
 402 }
 403 
 404 
 405 void G1ConcurrentMarkThread::sleep_before_next_cycle() {
 406   // We join here because we don't want to do the "shouldConcurrentMark()"
 407   // below while the world is otherwise stopped.
 408   assert(!in_progress(), "should have been cleared");
 409 
 410   MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
 411   while (!started() && !should_terminate()) {
 412     CGC_lock->wait(Mutex::_no_safepoint_check_flag);
 413   }
 414 
 415   if (started()) {
 416     set_in_progress();
 417   }
 418 }
< prev index next >