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