88 : g1_policy->predict_cleanup_time_ms();
89 G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
90 jlong sleep_time_ms = mmu_tracker->when_ms(now, prediction_ms);
91 os::sleep(this, sleep_time_ms, false);
92 }
93 }
94
95 class GCConcPhaseTimer : StackObj {
96 G1ConcurrentMark* _cm;
97
98 public:
99 GCConcPhaseTimer(G1ConcurrentMark* cm, const char* title) : _cm(cm) {
100 _cm->register_concurrent_phase_start(title);
101 }
102
103 ~GCConcPhaseTimer() {
104 _cm->register_concurrent_phase_end();
105 }
106 };
107
108 void ConcurrentMarkThread::run() {
109 initialize_in_thread();
110 wait_for_universe_init();
111
112 run_service();
113
114 terminate();
115 }
116
117 void ConcurrentMarkThread::run_service() {
118 _vtime_start = os::elapsedVTime();
119
120 G1CollectedHeap* g1h = G1CollectedHeap::heap();
121 G1CollectorPolicy* g1_policy = g1h->g1_policy();
122
123 while (!_should_terminate) {
124 // wait until started is set.
125 sleepBeforeNextCycle();
126 if (_should_terminate) {
127 _cm->root_regions()->cancel_scan();
128 break;
129 }
130
131 assert(GCId::current() != GCId::undefined(), "GC id should have been set up by the initial mark GC.");
132 {
133 ResourceMark rm;
134 HandleMark hm;
135 double cycle_start = os::elapsedVTime();
136
272 // We now want to allow clearing of the marking bitmap to be
273 // suspended by a collection pause.
274 // We may have aborted just before the remark. Do not bother clearing the
275 // bitmap then, as it has been done during mark abort.
276 if (!cm()->has_aborted()) {
277 GCConcPhaseTimer(_cm, "Concurrent Bitmap Clearing");
278 _cm->clearNextBitmap();
279 } else {
280 assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear");
281 }
282 }
283
284 // Update the number of full collections that have been
285 // completed. This will also notify the FullGCCount_lock in case a
286 // Java thread is waiting for a full GC to happen (e.g., it
287 // called System.gc() with +ExplicitGCInvokesConcurrent).
288 {
289 SuspendibleThreadSetJoiner sts_join;
290 g1h->increment_old_marking_cycles_completed(true /* concurrent */);
291 g1h->register_concurrent_cycle_end();
292 }
293 }
294 }
295
296 void ConcurrentMarkThread::stop() {
297 {
298 MutexLockerEx ml(Terminator_lock);
299 _should_terminate = true;
300 }
301
302 stop_service();
303
304 {
305 MutexLockerEx ml(Terminator_lock);
306 while (!_has_terminated) {
307 Terminator_lock->wait();
308 }
309 }
310 }
311
312 void ConcurrentMarkThread::stop_service() {
313 MutexLockerEx ml(CGC_lock, Mutex::_no_safepoint_check_flag);
314 CGC_lock->notify_all();
315 }
316
317 void ConcurrentMarkThread::sleepBeforeNextCycle() {
318 // We join here because we don't want to do the "shouldConcurrentMark()"
319 // below while the world is otherwise stopped.
320 assert(!in_progress(), "should have been cleared");
321
322 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
323 while (!started() && !_should_terminate) {
324 CGC_lock->wait(Mutex::_no_safepoint_check_flag);
325 }
326
327 if (started()) {
|
88 : g1_policy->predict_cleanup_time_ms();
89 G1MMUTracker *mmu_tracker = g1_policy->mmu_tracker();
90 jlong sleep_time_ms = mmu_tracker->when_ms(now, prediction_ms);
91 os::sleep(this, sleep_time_ms, false);
92 }
93 }
94
95 class GCConcPhaseTimer : StackObj {
96 G1ConcurrentMark* _cm;
97
98 public:
99 GCConcPhaseTimer(G1ConcurrentMark* cm, const char* title) : _cm(cm) {
100 _cm->register_concurrent_phase_start(title);
101 }
102
103 ~GCConcPhaseTimer() {
104 _cm->register_concurrent_phase_end();
105 }
106 };
107
108 void ConcurrentMarkThread::run_service() {
109 _vtime_start = os::elapsedVTime();
110
111 G1CollectedHeap* g1h = G1CollectedHeap::heap();
112 G1CollectorPolicy* g1_policy = g1h->g1_policy();
113
114 while (!_should_terminate) {
115 // wait until started is set.
116 sleepBeforeNextCycle();
117 if (_should_terminate) {
118 _cm->root_regions()->cancel_scan();
119 break;
120 }
121
122 assert(GCId::current() != GCId::undefined(), "GC id should have been set up by the initial mark GC.");
123 {
124 ResourceMark rm;
125 HandleMark hm;
126 double cycle_start = os::elapsedVTime();
127
263 // We now want to allow clearing of the marking bitmap to be
264 // suspended by a collection pause.
265 // We may have aborted just before the remark. Do not bother clearing the
266 // bitmap then, as it has been done during mark abort.
267 if (!cm()->has_aborted()) {
268 GCConcPhaseTimer(_cm, "Concurrent Bitmap Clearing");
269 _cm->clearNextBitmap();
270 } else {
271 assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear");
272 }
273 }
274
275 // Update the number of full collections that have been
276 // completed. This will also notify the FullGCCount_lock in case a
277 // Java thread is waiting for a full GC to happen (e.g., it
278 // called System.gc() with +ExplicitGCInvokesConcurrent).
279 {
280 SuspendibleThreadSetJoiner sts_join;
281 g1h->increment_old_marking_cycles_completed(true /* concurrent */);
282 g1h->register_concurrent_cycle_end();
283 }
284 }
285 }
286
287 void ConcurrentMarkThread::stop_service() {
288 MutexLockerEx ml(CGC_lock, Mutex::_no_safepoint_check_flag);
289 CGC_lock->notify_all();
290 }
291
292 void ConcurrentMarkThread::sleepBeforeNextCycle() {
293 // We join here because we don't want to do the "shouldConcurrentMark()"
294 // below while the world is otherwise stopped.
295 assert(!in_progress(), "should have been cleared");
296
297 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
298 while (!started() && !_should_terminate) {
299 CGC_lock->wait(Mutex::_no_safepoint_check_flag);
300 }
301
302 if (started()) {
|