src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp

Print this page




 175   if (_gc_count_before == gch->total_collections()) {
 176     // The "full" of do_full_collection call below "forces"
 177     // a collection; the second arg, 0, below ensures that
 178     // only the young gen is collected. XXX In the future,
 179     // we'll probably need to have something in this interface
 180     // to say do this only if we are sure we will not bail
 181     // out to a full collection in this attempt, but that's
 182     // for the future.
 183     assert(SafepointSynchronize::is_at_safepoint(),
 184       "We can only be executing this arm of if at a safepoint");
 185     GCCauseSetter gccs(gch, _gc_cause);
 186     gch->do_full_collection(gch->must_clear_all_soft_refs(),
 187                             0 /* collect only youngest gen */);
 188   } // Else no need for a foreground young gc
 189   assert((_gc_count_before < gch->total_collections()) ||
 190          (GC_locker::is_active() /* gc may have been skipped */
 191           && (_gc_count_before == gch->total_collections())),
 192          "total_collections() should be monotonically increasing");
 193 
 194   MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);

 195   if (gch->total_full_collections() == _full_gc_count_before) {
 196     // Disable iCMS until the full collection is done.

 197     CMSCollector::disable_icms();

 198     // In case CMS thread was in icms_wait(), wake it up.
 199     CMSCollector::start_icms();
 200     // Nudge the CMS thread to start a concurrent collection.
 201     CMSCollector::request_full_gc(_full_gc_count_before);
 202   } else {

 203     FullGCCount_lock->notify_all();  // Inform the Java thread its work is done
 204   }
 205 }
 206 
 207 bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const {
 208   Thread* thr = Thread::current();
 209   assert(thr != NULL, "Unexpected tid");
 210   if (!thr->is_Java_thread()) {
 211     assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
 212     GenCollectedHeap* gch = GenCollectedHeap::heap();
 213     if (_gc_count_before != gch->total_collections()) {
 214       // No need to do a young gc, we'll just nudge the CMS thread
 215       // in the doit() method above, to be executed soon.
 216       assert(_gc_count_before < gch->total_collections(),
 217              "total_collections() should be monotnically increasing");
 218       return false;  // no need for foreground young gc
 219     }
 220   }
 221   return true;       // may still need foreground young gc
 222 }


 242       gch->total_full_collections_completed() <= _full_gc_count_before) {
 243     // maybe we should change the condition to test _gc_cause ==
 244     // GCCause::_java_lang_system_gc, instead of
 245     // _gc_cause != GCCause::_gc_locker
 246     assert(_gc_cause == GCCause::_java_lang_system_gc,
 247            "the only way to get here if this was a System.gc()-induced GC");
 248     assert(ExplicitGCInvokesConcurrent, "Error");
 249     // Now, wait for witnessing concurrent gc cycle to complete,
 250     // but do so in native mode, because we want to lock the
 251     // FullGCEvent_lock, which may be needed by the VM thread
 252     // or by the CMS thread, so we do not want to be suspended
 253     // while holding that lock.
 254     ThreadToNativeFromVM native(jt);
 255     MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
 256     // Either a concurrent or a stop-world full gc is sufficient
 257     // witness to our request.
 258     while (gch->total_full_collections_completed() <= _full_gc_count_before) {
 259       FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
 260     }
 261   }
 262   // Enable iCMS back.

 263   CMSCollector::enable_icms();

 264 }


 175   if (_gc_count_before == gch->total_collections()) {
 176     // The "full" of do_full_collection call below "forces"
 177     // a collection; the second arg, 0, below ensures that
 178     // only the young gen is collected. XXX In the future,
 179     // we'll probably need to have something in this interface
 180     // to say do this only if we are sure we will not bail
 181     // out to a full collection in this attempt, but that's
 182     // for the future.
 183     assert(SafepointSynchronize::is_at_safepoint(),
 184       "We can only be executing this arm of if at a safepoint");
 185     GCCauseSetter gccs(gch, _gc_cause);
 186     gch->do_full_collection(gch->must_clear_all_soft_refs(),
 187                             0 /* collect only youngest gen */);
 188   } // Else no need for a foreground young gc
 189   assert((_gc_count_before < gch->total_collections()) ||
 190          (GC_locker::is_active() /* gc may have been skipped */
 191           && (_gc_count_before == gch->total_collections())),
 192          "total_collections() should be monotonically increasing");
 193 
 194   MutexLockerEx x(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
 195   assert(_full_gc_count_before <= gch->total_full_collections(), "Error");
 196   if (gch->total_full_collections() == _full_gc_count_before) {
 197     // Disable iCMS until the full collection is done, and
 198     // remember that we did so.
 199     CMSCollector::disable_icms();
 200     _disabled_icms = true;
 201     // In case CMS thread was in icms_wait(), wake it up.
 202     CMSCollector::start_icms();
 203     // Nudge the CMS thread to start a concurrent collection.
 204     CMSCollector::request_full_gc(_full_gc_count_before);
 205   } else {
 206     assert(_full_gc_count_before < gch->total_full_collections(), "Error");
 207     FullGCCount_lock->notify_all();  // Inform the Java thread its work is done
 208   }
 209 }
 210 
 211 bool VM_GenCollectFullConcurrent::evaluate_at_safepoint() const {
 212   Thread* thr = Thread::current();
 213   assert(thr != NULL, "Unexpected tid");
 214   if (!thr->is_Java_thread()) {
 215     assert(thr->is_VM_thread(), "Expected to be evaluated by VM thread");
 216     GenCollectedHeap* gch = GenCollectedHeap::heap();
 217     if (_gc_count_before != gch->total_collections()) {
 218       // No need to do a young gc, we'll just nudge the CMS thread
 219       // in the doit() method above, to be executed soon.
 220       assert(_gc_count_before < gch->total_collections(),
 221              "total_collections() should be monotnically increasing");
 222       return false;  // no need for foreground young gc
 223     }
 224   }
 225   return true;       // may still need foreground young gc
 226 }


 246       gch->total_full_collections_completed() <= _full_gc_count_before) {
 247     // maybe we should change the condition to test _gc_cause ==
 248     // GCCause::_java_lang_system_gc, instead of
 249     // _gc_cause != GCCause::_gc_locker
 250     assert(_gc_cause == GCCause::_java_lang_system_gc,
 251            "the only way to get here if this was a System.gc()-induced GC");
 252     assert(ExplicitGCInvokesConcurrent, "Error");
 253     // Now, wait for witnessing concurrent gc cycle to complete,
 254     // but do so in native mode, because we want to lock the
 255     // FullGCEvent_lock, which may be needed by the VM thread
 256     // or by the CMS thread, so we do not want to be suspended
 257     // while holding that lock.
 258     ThreadToNativeFromVM native(jt);
 259     MutexLockerEx ml(FullGCCount_lock, Mutex::_no_safepoint_check_flag);
 260     // Either a concurrent or a stop-world full gc is sufficient
 261     // witness to our request.
 262     while (gch->total_full_collections_completed() <= _full_gc_count_before) {
 263       FullGCCount_lock->wait(Mutex::_no_safepoint_check_flag);
 264     }
 265   }
 266   // Enable iCMS back if we disabled it earlier.
 267   if (_disabled_icms) {
 268     CMSCollector::enable_icms();
 269   }
 270 }