@@ -134,10 +134,7 @@ class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc,
134134void G1ConcurrentMarkThread::run_service () {
135135 _vtime_start = os::elapsedVTime ();
136136
137- while (!should_terminate ()) {
138- if (wait_for_next_cycle ()) {
139- break ;
140- }
137+ while (wait_for_next_cycle ()) {
141138
142139 GCIdMark gc_id_mark;
143140 GCTraceConcTime (Info, gc) tt (" Concurrent Cycle" );
@@ -168,13 +165,12 @@ bool G1ConcurrentMarkThread::wait_for_next_cycle() {
168165 set_in_progress ();
169166 }
170167
171- return should_terminate ();
168+ return ! should_terminate ();
172169}
173170
174- bool G1ConcurrentMarkThread::phase_clear_cld_claimed_marks () {
171+ void G1ConcurrentMarkThread::phase_clear_cld_claimed_marks () {
175172 G1ConcPhaseTimer p (_cm, " Concurrent Clear Claimed Marks" );
176173 ClassLoaderDataGraph::clear_claimed_marks ();
177- return _cm->has_aborted ();
178174}
179175
180176bool G1ConcurrentMarkThread::phase_scan_root_regions () {
@@ -185,10 +181,9 @@ bool G1ConcurrentMarkThread::phase_scan_root_regions() {
185181
186182bool G1ConcurrentMarkThread::phase_mark_loop () {
187183 Ticks mark_start = Ticks::now ();
188- log_info (gc, marking)(" Concurrent Mark (%.3fs) " , mark_start. seconds () );
184+ log_info (gc, marking)(" Concurrent Mark" );
189185
190- uint iter = 1 ;
191- while (true ) {
186+ for (uint iter = 1 ; true ; ++iter) {
192187 // Subphase 1: Mark From Roots.
193188 if (subphase_mark_from_roots ()) return true ;
194189
@@ -207,13 +202,11 @@ bool G1ConcurrentMarkThread::phase_mark_loop() {
207202 if (!mark_loop_needs_restart ()) break ;
208203
209204 log_info (gc, marking)(" Concurrent Mark Restart for Mark Stack Overflow (iteration #%u)" ,
210- iter++ );
205+ iter);
211206 }
212207
213- Ticks mark_end = Ticks::now ();
214- log_info (gc, marking)(" Concurrent Mark (%.3fs, %.3fs) %.3fms" ,
215- mark_start.seconds (), mark_end.seconds (),
216- (mark_end - mark_start).seconds () * 1000.0 );
208+ log_info (gc, marking)(" Concurrent Mark %.3fms" ,
209+ (Ticks::now () - mark_start).seconds () * 1000.0 );
217210
218211 return false ;
219212}
@@ -283,8 +276,19 @@ void G1ConcurrentMarkThread::full_concurrent_cycle_do() {
283276 // Phase 1: Clear CLD claimed marks.
284277 phase_clear_cld_claimed_marks ();
285278
286- // Do not return before the scan root regions phase as a GC waits for a
279+ // We have to ensure that we finish scanning the root regions
280+ // before the next GC takes place. To ensure this we have to
281+ // make sure that we do not join the STS until the root regions
282+ // have been scanned. If we did then it's possible that a
283+ // subsequent GC could block us from joining the STS and proceed
284+ // without the root regions have been scanned which would be a
285+ // correctness issue.
286+ //
287+ // So do not return before the scan root regions phase as a GC waits for a
287288 // notification from it.
289+ //
290+ // For the same reason ConcurrentGCBreakpoints (in the phase methods) before
291+ // here risk deadlock, because a young GC must wait for root region scanning.
288292
289293 // Phase 2: Scan root regions.
290294 if (phase_scan_root_regions ()) return ;
0 commit comments