134 int iter = 0; |
134 int iter = 0; |
135 do { |
135 do { |
136 iter++; |
136 iter++; |
137 if (!cm()->has_aborted()) { |
137 if (!cm()->has_aborted()) { |
138 _cm->markFromRoots(); |
138 _cm->markFromRoots(); |
139 } else { |
|
140 if (TraceConcurrentMark) |
|
141 gclog_or_tty->print_cr("CM-skip-mark-from-roots"); |
|
142 } |
139 } |
143 |
140 |
144 double mark_end_time = os::elapsedVTime(); |
141 double mark_end_time = os::elapsedVTime(); |
145 double mark_end_sec = os::elapsedTime(); |
142 double mark_end_sec = os::elapsedTime(); |
146 _vtime_mark_accum += (mark_end_time - cycle_start); |
143 _vtime_mark_accum += (mark_end_time - cycle_start); |
161 |
158 |
162 CMCheckpointRootsFinalClosure final_cl(_cm); |
159 CMCheckpointRootsFinalClosure final_cl(_cm); |
163 sprintf(verbose_str, "GC remark"); |
160 sprintf(verbose_str, "GC remark"); |
164 VM_CGC_Operation op(&final_cl, verbose_str); |
161 VM_CGC_Operation op(&final_cl, verbose_str); |
165 VMThread::execute(&op); |
162 VMThread::execute(&op); |
166 } else { |
|
167 if (TraceConcurrentMark) |
|
168 gclog_or_tty->print_cr("CM-skip-remark"); |
|
169 } |
163 } |
170 if (cm()->restart_for_overflow() && |
164 if (cm()->restart_for_overflow() && |
171 G1TraceMarkStackOverflow) { |
165 G1TraceMarkStackOverflow) { |
172 gclog_or_tty->print_cr("Restarting conc marking because of MS overflow " |
166 gclog_or_tty->print_cr("Restarting conc marking because of MS overflow " |
173 "in remark (restart #%d).", iter); |
167 "in remark (restart #%d).", iter); |
206 gclog_or_tty->stamp(PrintGCTimeStamps); |
200 gclog_or_tty->stamp(PrintGCTimeStamps); |
207 gclog_or_tty->print_cr("[GC concurrent-count-end, %1.7lf]", |
201 gclog_or_tty->print_cr("[GC concurrent-count-end, %1.7lf]", |
208 count_end_sec - count_start_sec); |
202 count_end_sec - count_start_sec); |
209 } |
203 } |
210 } |
204 } |
211 } else { |
|
212 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-skip-end-game"); |
|
213 } |
205 } |
214 double end_time = os::elapsedVTime(); |
206 double end_time = os::elapsedVTime(); |
215 _vtime_count_accum += (end_time - counting_start_time); |
207 _vtime_count_accum += (end_time - counting_start_time); |
216 // Update the total virtual time before doing this, since it will try |
208 // Update the total virtual time before doing this, since it will try |
217 // to measure it to get the vtime for this marking. We purposely |
209 // to measure it to get the vtime for this marking. We purposely |
228 CMCleanUp cl_cl(_cm); |
220 CMCleanUp cl_cl(_cm); |
229 sprintf(verbose_str, "GC cleanup"); |
221 sprintf(verbose_str, "GC cleanup"); |
230 VM_CGC_Operation op(&cl_cl, verbose_str); |
222 VM_CGC_Operation op(&cl_cl, verbose_str); |
231 VMThread::execute(&op); |
223 VMThread::execute(&op); |
232 } else { |
224 } else { |
233 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-skip-cleanup"); |
|
234 G1CollectedHeap::heap()->set_marking_complete(); |
225 G1CollectedHeap::heap()->set_marking_complete(); |
235 } |
226 } |
236 |
227 |
237 if (!cm()->has_aborted()) { |
228 if (!cm()->has_aborted()) { |
238 double cleanup_start_sec = os::elapsedTime(); |
229 double cleanup_start_sec = os::elapsedTime(); |
285 terminate(); |
276 terminate(); |
286 } |
277 } |
287 |
278 |
288 |
279 |
289 void ConcurrentMarkThread::yield() { |
280 void ConcurrentMarkThread::yield() { |
290 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-yield"); |
|
291 _sts.yield("Concurrent Mark"); |
281 _sts.yield("Concurrent Mark"); |
292 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-yield-end"); |
|
293 } |
282 } |
294 |
283 |
295 void ConcurrentMarkThread::stop() { |
284 void ConcurrentMarkThread::stop() { |
296 // it is ok to take late safepoints here, if needed |
285 // it is ok to take late safepoints here, if needed |
297 MutexLockerEx mu(Terminator_lock); |
286 MutexLockerEx mu(Terminator_lock); |
298 _should_terminate = true; |
287 _should_terminate = true; |
299 while (!_has_terminated) { |
288 while (!_has_terminated) { |
300 Terminator_lock->wait(); |
289 Terminator_lock->wait(); |
301 } |
290 } |
302 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-stop"); |
|
303 } |
291 } |
304 |
292 |
305 void ConcurrentMarkThread::print() { |
293 void ConcurrentMarkThread::print() { |
306 gclog_or_tty->print("\"Concurrent Mark GC Thread\" "); |
294 gclog_or_tty->print("\"Concurrent Mark GC Thread\" "); |
307 Thread::print(); |
295 Thread::print(); |
312 clear_in_progress(); |
300 clear_in_progress(); |
313 // We join here because we don't want to do the "shouldConcurrentMark()" |
301 // We join here because we don't want to do the "shouldConcurrentMark()" |
314 // below while the world is otherwise stopped. |
302 // below while the world is otherwise stopped. |
315 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
303 MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
316 while (!started()) { |
304 while (!started()) { |
317 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-sleeping"); |
|
318 CGC_lock->wait(Mutex::_no_safepoint_check_flag); |
305 CGC_lock->wait(Mutex::_no_safepoint_check_flag); |
319 } |
306 } |
320 set_in_progress(); |
307 set_in_progress(); |
321 clear_started(); |
308 clear_started(); |
322 if (TraceConcurrentMark) gclog_or_tty->print_cr("CM-starting"); |
|
323 } |
309 } |
324 |
310 |
325 // Note: this method, although exported by the ConcurrentMarkSweepThread, |
311 // Note: this method, although exported by the ConcurrentMarkSweepThread, |
326 // which is a non-JavaThread, can only be called by a JavaThread. |
312 // which is a non-JavaThread, can only be called by a JavaThread. |
327 // Currently this is done at vm creation time (post-vm-init) by the |
313 // Currently this is done at vm creation time (post-vm-init) by the |