190 // a collection; the second arg, 0, below ensures that
191 // only the young gen is collected. XXX In the future,
192 // we'll probably need to have something in this interface
193 // to say do this only if we are sure we will not bail
194 // out to a full collection in this attempt, but that's
195 // for the future.
196 assert(SafepointSynchronize::is_at_safepoint(),
197 "We can only be executing this arm of if at a safepoint");
198 GCCauseSetter gccs(gch, _gc_cause);
199 gch->do_full_collection(gch->must_clear_all_soft_refs(),
200 0 /* collect only youngest gen */);
201 } // Else no need for a foreground young gc
202 assert((_gc_count_before < gch->total_collections()) ||
203 (GC_locker::is_active() /* gc may have been skipped */
204 && (_gc_count_before == gch->total_collections())),
205 "total_collections() should be monotonically increasing");
206
207 MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
208 assert(_full_gc_count_before <= gch->total_full_collections(), "Error");
209 if (gch->total_full_collections() == _full_gc_count_before) {
210 // Disable iCMS until the full collection is done, and
211 // remember that we did so.
212 CMSCollector::disable_icms();
213 _disabled_icms = true;
214 // In case CMS thread was in icms_wait(), wake it up.
215 CMSCollector::start_icms();
216 // Nudge the CMS thread to start a concurrent collection.
217 CMSCollector::request_full_gc(_full_gc_count_before, _gc_cause);
218 } else {
219 assert(_full_gc_count_before < gch->total_full_collections(), "Error");
220 FullGCCount_lock->notify_all(); // Inform the Java thread its work is done
221 }
222 }
223
224 bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const {
225 Thread* thr = Thread::current();
226 assert(thr != NULL, "Unexpected tid");
227 if (!thr->is_Java_thread()) {
228 assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
229 GenCollectedHeap* gch = GenCollectedHeap::heap();
230 if (_gc_count_before != gch->total_collections()) {
231 // No need to do a young gc, we'll just nudge the CMS thread
232 // in the doit() method above, to be executed soon.
233 assert(_gc_count_before < gch->total_collections(),
234 "total_collections() should be monotonically increasing");
235 return false; // no need for foreground young gc
258 if (_gc_cause != GCCause::_gc_locker &&
259 gch->total_full_collections_completed() <= _full_gc_count_before) {
260 // maybe we should change the condition to test _gc_cause ==
261 // GCCause::_java_lang_system_gc, instead of
262 // _gc_cause != GCCause::_gc_locker
263 assert(_gc_cause == GCCause::_java_lang_system_gc,
264 "the only way to get here if this was a System.gc()-induced GC");
265 assert(ExplicitGCInvokesConcurrent, "Error");
266 // Now, wait for witnessing concurrent gc cycle to complete,
267 // but do so in native mode, because we want to lock the
268 // FullGCEvent_lock, which may be needed by the VM thread
269 // or by the CMS thread, so we do not want to be suspended
270 // while holding that lock.
271 ThreadToNativeFromVM native(jt);
272 MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
273 // Either a concurrent or a stop-world full gc is sufficient
274 // witness to our request.
275 while (gch->total_full_collections_completed() <= _full_gc_count_before) {
276 FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
277 }
278 }
279 // Enable iCMS back if we disabled it earlier.
280 if (_disabled_icms) {
281 CMSCollector::enable_icms();
282 }
283 }
|
190 // a collection; the second arg, 0, below ensures that
191 // only the young gen is collected. XXX In the future,
192 // we'll probably need to have something in this interface
193 // to say do this only if we are sure we will not bail
194 // out to a full collection in this attempt, but that's
195 // for the future.
196 assert(SafepointSynchronize::is_at_safepoint(),
197 "We can only be executing this arm of if at a safepoint");
198 GCCauseSetter gccs(gch, _gc_cause);
199 gch->do_full_collection(gch->must_clear_all_soft_refs(),
200 0 /* collect only youngest gen */);
201 } // Else no need for a foreground young gc
202 assert((_gc_count_before < gch->total_collections()) ||
203 (GC_locker::is_active() /* gc may have been skipped */
204 && (_gc_count_before == gch->total_collections())),
205 "total_collections() should be monotonically increasing");
206
207 MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
208 assert(_full_gc_count_before <= gch->total_full_collections(), "Error");
209 if (gch->total_full_collections() == _full_gc_count_before) {
210 // Nudge the CMS thread to start a concurrent collection.
211 CMSCollector::request_full_gc(_full_gc_count_before, _gc_cause);
212 } else {
213 assert(_full_gc_count_before < gch->total_full_collections(), "Error");
214 FullGCCount_lock->notify_all(); // Inform the Java thread its work is done
215 }
216 }
217
218 bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const {
219 Thread* thr = Thread::current();
220 assert(thr != NULL, "Unexpected tid");
221 if (!thr->is_Java_thread()) {
222 assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
223 GenCollectedHeap* gch = GenCollectedHeap::heap();
224 if (_gc_count_before != gch->total_collections()) {
225 // No need to do a young gc, we'll just nudge the CMS thread
226 // in the doit() method above, to be executed soon.
227 assert(_gc_count_before < gch->total_collections(),
228 "total_collections() should be monotonically increasing");
229 return false; // no need for foreground young gc
252 if (_gc_cause != GCCause::_gc_locker &&
253 gch->total_full_collections_completed() <= _full_gc_count_before) {
254 // maybe we should change the condition to test _gc_cause ==
255 // GCCause::_java_lang_system_gc, instead of
256 // _gc_cause != GCCause::_gc_locker
257 assert(_gc_cause == GCCause::_java_lang_system_gc,
258 "the only way to get here if this was a System.gc()-induced GC");
259 assert(ExplicitGCInvokesConcurrent, "Error");
260 // Now, wait for witnessing concurrent gc cycle to complete,
261 // but do so in native mode, because we want to lock the
262 // FullGCEvent_lock, which may be needed by the VM thread
263 // or by the CMS thread, so we do not want to be suspended
264 // while holding that lock.
265 ThreadToNativeFromVM native(jt);
266 MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
267 // Either a concurrent or a stop-world full gc is sufficient
268 // witness to our request.
269 while (gch->total_full_collections_completed() <= _full_gc_count_before) {
270 FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
271 }
272 }
273 }
|