90 jlong sleep_time_ms = mmu_tracker->when_ms(now, prediction_ms); |
90 jlong sleep_time_ms = mmu_tracker->when_ms(now, prediction_ms); |
91 os::sleep(this, sleep_time_ms, false); |
91 os::sleep(this, sleep_time_ms, false); |
92 } |
92 } |
93 } |
93 } |
94 |
94 |
95 class GCConcPhaseTimer : StackObj { |
95 class G1ConcPhaseTimer : public GCTraceConcTimeImpl<LogLevel::Info, LOG_TAGS(gc, marking)> { |
96 G1ConcurrentMark* _cm; |
96 G1ConcurrentMark* _cm; |
97 |
97 |
98 public: |
98 public: |
99 GCConcPhaseTimer(G1ConcurrentMark* cm, const char* title) : _cm(cm) { |
99 G1ConcPhaseTimer(G1ConcurrentMark* cm, const char* title) : |
|
100 GCTraceConcTimeImpl<LogLevel::Info, LogTag::_gc, LogTag::_marking>(title), |
|
101 _cm(cm) { |
100 _cm->register_concurrent_phase_start(title); |
102 _cm->register_concurrent_phase_start(title); |
101 } |
103 } |
102 |
104 |
103 ~GCConcPhaseTimer() { |
105 ~G1ConcPhaseTimer() { |
104 _cm->register_concurrent_phase_end(); |
106 _cm->register_concurrent_phase_end(); |
105 } |
107 } |
106 }; |
108 }; |
107 |
109 |
108 void ConcurrentMarkThread::run_service() { |
110 void ConcurrentMarkThread::run_service() { |
117 if (should_terminate()) { |
119 if (should_terminate()) { |
118 break; |
120 break; |
119 } |
121 } |
120 |
122 |
121 assert(GCId::current() != GCId::undefined(), "GC id should have been set up by the initial mark GC."); |
123 assert(GCId::current() != GCId::undefined(), "GC id should have been set up by the initial mark GC."); |
|
124 |
|
125 GCTraceConcTime(Info, gc) tt("Concurrent Cycle"); |
122 { |
126 { |
123 ResourceMark rm; |
127 ResourceMark rm; |
124 HandleMark hm; |
128 HandleMark hm; |
125 double cycle_start = os::elapsedVTime(); |
129 double cycle_start = os::elapsedVTime(); |
126 |
130 |
127 { |
131 { |
128 GCConcPhaseTimer(_cm, "Concurrent Clearing of Claimed Marks"); |
132 G1ConcPhaseTimer t(_cm, "Concurrent Clear Claimed Marks"); |
129 ClassLoaderDataGraph::clear_claimed_marks(); |
133 ClassLoaderDataGraph::clear_claimed_marks(); |
130 } |
134 } |
131 |
135 |
132 // We have to ensure that we finish scanning the root regions |
136 // We have to ensure that we finish scanning the root regions |
133 // before the next GC takes place. To ensure this we have to |
137 // before the next GC takes place. To ensure this we have to |
136 // subsequent GC could block us from joining the STS and proceed |
140 // subsequent GC could block us from joining the STS and proceed |
137 // without the root regions have been scanned which would be a |
141 // without the root regions have been scanned which would be a |
138 // correctness issue. |
142 // correctness issue. |
139 |
143 |
140 { |
144 { |
141 GCConcPhaseTimer(_cm, "Concurrent Root Region Scanning"); |
145 G1ConcPhaseTimer t(_cm, "Concurrent Scan Root Regions"); |
142 _cm->scanRootRegions(); |
146 _cm->scan_root_regions(); |
143 } |
147 } |
144 |
148 |
145 // It would be nice to use the GCTraceConcTime class here but |
149 // It would be nice to use the GCTraceConcTime class here but |
146 // the "end" logging is inside the loop and not at the end of |
150 // the "end" logging is inside the loop and not at the end of |
147 // a scope. Mimicking the same log output as GCTraceConcTime instead. |
151 // a scope. Mimicking the same log output as GCTraceConcTime instead. |
148 jlong mark_start = os::elapsed_counter(); |
152 jlong mark_start = os::elapsed_counter(); |
149 log_info(gc)("Concurrent Mark (%.3fs)", TimeHelper::counter_to_seconds(mark_start)); |
153 log_info(gc, marking)("Concurrent Mark (%.3fs)", TimeHelper::counter_to_seconds(mark_start)); |
150 |
154 |
151 int iter = 0; |
155 int iter = 0; |
152 do { |
156 do { |
153 iter++; |
157 iter++; |
154 if (!cm()->has_aborted()) { |
158 if (!cm()->has_aborted()) { |
155 GCConcPhaseTimer(_cm, "Concurrent Mark"); |
159 G1ConcPhaseTimer t(_cm, "Concurrent Mark From Roots"); |
156 _cm->markFromRoots(); |
160 _cm->mark_from_roots(); |
157 } |
161 } |
158 |
162 |
159 double mark_end_time = os::elapsedVTime(); |
163 double mark_end_time = os::elapsedVTime(); |
160 jlong mark_end = os::elapsed_counter(); |
164 jlong mark_end = os::elapsed_counter(); |
161 _vtime_mark_accum += (mark_end_time - cycle_start); |
165 _vtime_mark_accum += (mark_end_time - cycle_start); |
162 if (!cm()->has_aborted()) { |
166 if (!cm()->has_aborted()) { |
163 delay_to_keep_mmu(g1_policy, true /* remark */); |
167 delay_to_keep_mmu(g1_policy, true /* remark */); |
164 log_info(gc)("Concurrent Mark (%.3fs, %.3fs) %.3fms", |
168 log_info(gc, marking)("Concurrent Mark (%.3fs, %.3fs) %.3fms", |
165 TimeHelper::counter_to_seconds(mark_start), |
169 TimeHelper::counter_to_seconds(mark_start), |
166 TimeHelper::counter_to_seconds(mark_end), |
170 TimeHelper::counter_to_seconds(mark_end), |
167 TimeHelper::counter_to_millis(mark_end - mark_start)); |
171 TimeHelper::counter_to_millis(mark_end - mark_start)); |
168 |
172 |
169 CMCheckpointRootsFinalClosure final_cl(_cm); |
173 CMCheckpointRootsFinalClosure final_cl(_cm); |
170 VM_CGC_Operation op(&final_cl, "Pause Remark", true /* needs_pll */); |
174 VM_CGC_Operation op(&final_cl, "Pause Remark", true /* needs_pll */); |
171 VMThread::execute(&op); |
175 VMThread::execute(&op); |
172 } |
176 } |
173 if (cm()->restart_for_overflow()) { |
177 if (cm()->restart_for_overflow()) { |
174 log_debug(gc)("Restarting conc marking because of MS overflow in remark (restart #%d).", iter); |
178 log_debug(gc, marking)("Restarting Concurrent Marking because of Mark Stack Overflow in Remark (Iteration #%d).", iter); |
175 log_info(gc)("Concurrent Mark restart for overflow"); |
179 log_info(gc, marking)("Concurrent Mark Restart due to overflow"); |
176 } |
180 } |
177 } while (cm()->restart_for_overflow()); |
181 } while (cm()->restart_for_overflow()); |
178 |
182 |
179 double end_time = os::elapsedVTime(); |
183 double end_time = os::elapsedVTime(); |
180 // Update the total virtual time before doing this, since it will try |
184 // Update the total virtual time before doing this, since it will try |
204 // takes place, then we would carry on freeing regions in |
208 // takes place, then we would carry on freeing regions in |
205 // case they are needed by the pause. If a Full GC takes |
209 // case they are needed by the pause. If a Full GC takes |
206 // place, it would wait for us to process the regions |
210 // place, it would wait for us to process the regions |
207 // reclaimed by cleanup. |
211 // reclaimed by cleanup. |
208 |
212 |
209 GCTraceConcTime(Info, gc) tt("Concurrent Cleanup"); |
213 G1ConcPhaseTimer t(_cm, "Concurrent Complete Cleanup"); |
210 GCConcPhaseTimer(_cm, "Concurrent Cleanup"); |
|
211 |
|
212 // Now do the concurrent cleanup operation. |
214 // Now do the concurrent cleanup operation. |
213 _cm->completeCleanup(); |
215 _cm->complete_cleanup(); |
214 |
216 |
215 // Notify anyone who's waiting that there are no more free |
217 // Notify anyone who's waiting that there are no more free |
216 // regions coming. We have to do this before we join the STS |
218 // regions coming. We have to do this before we join the STS |
217 // (in fact, we should not attempt to join the STS in the |
219 // (in fact, we should not attempt to join the STS in the |
218 // interval between finishing the cleanup pause and clearing |
220 // interval between finishing the cleanup pause and clearing |
253 { |
255 { |
254 SuspendibleThreadSetJoiner sts_join; |
256 SuspendibleThreadSetJoiner sts_join; |
255 if (!cm()->has_aborted()) { |
257 if (!cm()->has_aborted()) { |
256 g1_policy->record_concurrent_mark_cleanup_completed(); |
258 g1_policy->record_concurrent_mark_cleanup_completed(); |
257 } else { |
259 } else { |
258 log_info(gc)("Concurrent Mark abort"); |
260 log_info(gc, marking)("Concurrent Mark Abort"); |
259 } |
261 } |
260 } |
262 } |
261 |
263 |
262 // We now want to allow clearing of the marking bitmap to be |
264 // We now want to allow clearing of the marking bitmap to be |
263 // suspended by a collection pause. |
265 // suspended by a collection pause. |
264 // We may have aborted just before the remark. Do not bother clearing the |
266 // We may have aborted just before the remark. Do not bother clearing the |
265 // bitmap then, as it has been done during mark abort. |
267 // bitmap then, as it has been done during mark abort. |
266 if (!cm()->has_aborted()) { |
268 if (!cm()->has_aborted()) { |
267 GCConcPhaseTimer(_cm, "Concurrent Bitmap Clearing"); |
269 G1ConcPhaseTimer t(_cm, "Concurrent Cleanup for Next Mark"); |
268 _cm->clearNextBitmap(); |
270 _cm->cleanup_for_next_mark(); |
269 } else { |
271 } else { |
270 assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear"); |
272 assert(!G1VerifyBitmaps || _cm->nextMarkBitmapIsClear(), "Next mark bitmap must be clear"); |
271 } |
273 } |
272 } |
274 } |
273 |
275 |