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
137 {
138 GCConcPhaseTimer(_cm, "Concurrent Clearing of Claimed Marks");
139 ClassLoaderDataGraph::clear_claimed_marks();
140 }
141
142 // We have to ensure that we finish scanning the root regions
143 // before the next GC takes place. To ensure this we have to
144 // make sure that we do not join the STS until the root regions
145 // have been scanned. If we did then it's possible that a
146 // subsequent GC could block us from joining the STS and proceed
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()) {
328 set_in_progress();
329 }
330 }
331
332 // Note: As is the case with CMS - this method, although exported
333 // by the ConcurrentMarkThread, which is a non-JavaThread, can only
334 // be called by a JavaThread. Currently this is done at vm creation
335 // time (post-vm-init) by the main/Primordial (Java)Thread.
336 // XXX Consider changing this in the future to allow the CM thread
337 // itself to create this thread?
338 void ConcurrentMarkThread::makeSurrogateLockerThread(TRAPS) {
339 assert(UseG1GC, "SLT thread needed only for concurrent GC");
340 assert(THREAD->is_Java_thread(), "must be a Java thread");
341 assert(_slt == NULL, "SLT already created");
342 _slt = SurrogateLockerThread::make(THREAD);
343 }
|
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
128 {
129 GCConcPhaseTimer(_cm, "Concurrent Clearing of Claimed Marks");
130 ClassLoaderDataGraph::clear_claimed_marks();
131 }
132
133 // We have to ensure that we finish scanning the root regions
134 // before the next GC takes place. To ensure this we have to
135 // make sure that we do not join the STS until the root regions
136 // have been scanned. If we did then it's possible that a
137 // subsequent GC could block us from joining the STS and proceed
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()) {
303 set_in_progress();
304 }
305 }
306
307 // Note: As is the case with CMS - this method, although exported
308 // by the ConcurrentMarkThread, which is a non-JavaThread, can only
309 // be called by a JavaThread. Currently this is done at vm creation
310 // time (post-vm-init) by the main/Primordial (Java)Thread.
311 // XXX Consider changing this in the future to allow the CM thread
312 // itself to create this thread?
313 void ConcurrentMarkThread::makeSurrogateLockerThread(TRAPS) {
314 assert(UseG1GC, "SLT thread needed only for concurrent GC");
315 assert(THREAD->is_Java_thread(), "must be a Java thread");
316 assert(_slt == NULL, "SLT already created");
317 _slt = SurrogateLockerThread::make(THREAD);
318 }
|