< prev index next >

src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp

Print this page




2891        "Was cleared in most recent final checkpoint phase"
2892        " or no bits are set in the gc_prologue before the start of the next "
2893        "subsequent marking phase.");
2894 
2895   assert(_ct->klass_rem_set()->mod_union_is_clear(), "Must be");
2896 
2897   // Save the end of the used_region of the constituent generations
2898   // to be used to limit the extent of sweep in each generation.
2899   save_sweep_limits();
2900   verify_overflow_empty();
2901 }
2902 
2903 bool CMSCollector::markFromRoots() {
2904   // we might be tempted to assert that:
2905   // assert(!SafepointSynchronize::is_at_safepoint(),
2906   //        "inconsistent argument?");
2907   // However that wouldn't be right, because it's possible that
2908   // a safepoint is indeed in progress as a young generation
2909   // stop-the-world GC happens even as we mark in this generation.
2910   assert(_collectorState == Marking, "inconsistent state?");

2911   check_correct_thread_executing();
2912   verify_overflow_empty();
2913 
2914   // Weak ref discovery note: We may be discovering weak
2915   // refs in this generation concurrent (but interleaved) with
2916   // weak ref discovery by the young generation collector.
2917 
2918   CMSTokenSyncWithLocks ts(true, bitMapLock());
2919   GCTraceCPUTime tcpu;
2920   CMSPhaseAccounting pa(this, "Concrurrent Mark");
2921   bool res = markFromRootsWork();
2922   if (res) {
2923     _collectorState = Precleaning;
2924   } else { // We failed and a foreground collection wants to take over
2925     assert(_foregroundGCIsActive, "internal state inconsistency");
2926     assert(_restart_addr == NULL,  "foreground will restart from scratch");
2927     log_debug(gc)("bailing out to foreground collection");
2928   }
2929   verify_overflow_empty();

2930   return res;
2931 }
2932 
2933 bool CMSCollector::markFromRootsWork() {
2934   // iterate over marked bits in bit map, doing a full scan and mark
2935   // from these roots using the following algorithm:
2936   // . if oop is to the right of the current scan pointer,
2937   //   mark corresponding bit (we'll process it later)
2938   // . else (oop is to left of current scan pointer)
2939   //   push oop on marking stack
2940   // . drain the marking stack
2941 
2942   // Note that when we do a marking step we need to hold the
2943   // bit map lock -- recall that direct allocation (by mutators)
2944   // and promotion (by the young generation collector) is also
2945   // marking the bit map. [the so-called allocate live policy.]
2946   // Because the implementation of bit map marking is not
2947   // robust wrt simultaneous marking of bits in the same word,
2948   // we need to make sure that there is no such interference
2949   // between concurrent such updates.


5276     assert(t->is_ConcurrentGC_thread(),
5277            "Should be CMS thread");
5278   } else {
5279     // We can be the CMS thread only if we are in a stop-world
5280     // phase of CMS collection.
5281     if (t->is_ConcurrentGC_thread()) {
5282       assert(_collectorState == InitialMarking ||
5283              _collectorState == FinalMarking,
5284              "Should be a stop-world phase");
5285       // The CMS thread should be holding the CMS_token.
5286       assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
5287              "Potential interference with concurrently "
5288              "executing VM thread");
5289     }
5290   }
5291 }
5292 #endif
5293 
5294 void CMSCollector::sweep() {
5295   assert(_collectorState == Sweeping, "just checking");

5296   check_correct_thread_executing();
5297   verify_work_stacks_empty();
5298   verify_overflow_empty();
5299   increment_sweep_count();
5300   TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause());
5301 
5302   _inter_sweep_timer.stop();
5303   _inter_sweep_estimate.sample(_inter_sweep_timer.seconds());
5304 
5305   assert(!_intra_sweep_timer.is_active(), "Should not be active");
5306   _intra_sweep_timer.reset();
5307   _intra_sweep_timer.start();
5308   {
5309     GCTraceCPUTime tcpu;
5310     CMSPhaseAccounting pa(this, "Concurrent Sweep");
5311     // First sweep the old gen
5312     {
5313       CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(),
5314                                bitMapLock());
5315       sweepWork(_cmsGen);


5356   // and out of the Sweeping state must be synchronously visible
5357   // globally to the mutators.
5358   // The transition into the Marking state happens with the world
5359   // stopped so the mutators will globally see it.  Sweeping is
5360   // done asynchronously by the background collector so the transition
5361   // from the Sweeping state to the Resizing state must be done
5362   // under the freelistLock (as is the check for whether to
5363   // allocate-live and whether to dirty the mod-union table).
5364   assert(_collectorState == Resizing, "Change of collector state to"
5365     " Resizing must be done under the freelistLocks (plural)");
5366 
5367   // Now that sweeping has been completed, we clear
5368   // the incremental_collection_failed flag,
5369   // thus inviting a younger gen collection to promote into
5370   // this generation. If such a promotion may still fail,
5371   // the flag will be set again when a young collection is
5372   // attempted.
5373   GenCollectedHeap* gch = GenCollectedHeap::heap();
5374   gch->clear_incremental_collection_failed();  // Worth retrying as fresh space may have been freed up
5375   gch->update_full_collections_completed(_collection_count_start);

5376 }
5377 
5378 // FIX ME!!! Looks like this belongs in CFLSpace, with
5379 // CMSGen merely delegating to it.
5380 void ConcurrentMarkSweepGeneration::setNearLargestChunk() {
5381   double nearLargestPercent = FLSLargestBlockCoalesceProximity;
5382   HeapWord*  minAddr        = _cmsSpace->bottom();
5383   HeapWord*  largestAddr    =
5384     (HeapWord*) _cmsSpace->dictionary()->find_largest_dict();
5385   if (largestAddr == NULL) {
5386     // The dictionary appears to be empty.  In this case
5387     // try to coalesce at the end of the heap.
5388     largestAddr = _cmsSpace->end();
5389   }
5390   size_t largestOffset     = pointer_delta(largestAddr, minAddr);
5391   size_t nearLargestOffset =
5392     (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize;
5393   log_debug(gc, freelist)("CMS: Large Block: " PTR_FORMAT "; Proximity: " PTR_FORMAT " -> " PTR_FORMAT,
5394                           p2i(largestAddr), p2i(_cmsSpace->nearLargestChunk()), p2i(minAddr + nearLargestOffset));
5395   _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset);




2891        "Was cleared in most recent final checkpoint phase"
2892        " or no bits are set in the gc_prologue before the start of the next "
2893        "subsequent marking phase.");
2894 
2895   assert(_ct->klass_rem_set()->mod_union_is_clear(), "Must be");
2896 
2897   // Save the end of the used_region of the constituent generations
2898   // to be used to limit the extent of sweep in each generation.
2899   save_sweep_limits();
2900   verify_overflow_empty();
2901 }
2902 
2903 bool CMSCollector::markFromRoots() {
2904   // we might be tempted to assert that:
2905   // assert(!SafepointSynchronize::is_at_safepoint(),
2906   //        "inconsistent argument?");
2907   // However that wouldn't be right, because it's possible that
2908   // a safepoint is indeed in progress as a young generation
2909   // stop-the-world GC happens even as we mark in this generation.
2910   assert(_collectorState == Marking, "inconsistent state?");
2911   _gc_timer_cm->register_gc_concurrent_start("Concurrent Mark");
2912   check_correct_thread_executing();
2913   verify_overflow_empty();
2914 
2915   // Weak ref discovery note: We may be discovering weak
2916   // refs in this generation concurrent (but interleaved) with
2917   // weak ref discovery by the young generation collector.
2918 
2919   CMSTokenSyncWithLocks ts(true, bitMapLock());
2920   GCTraceCPUTime tcpu;
2921   CMSPhaseAccounting pa(this, "Concrurrent Mark");
2922   bool res = markFromRootsWork();
2923   if (res) {
2924     _collectorState = Precleaning;
2925   } else { // We failed and a foreground collection wants to take over
2926     assert(_foregroundGCIsActive, "internal state inconsistency");
2927     assert(_restart_addr == NULL,  "foreground will restart from scratch");
2928     log_debug(gc)("bailing out to foreground collection");
2929   }
2930   verify_overflow_empty();
2931   _gc_timer_cm->register_gc_concurrent_end();
2932   return res;
2933 }
2934 
2935 bool CMSCollector::markFromRootsWork() {
2936   // iterate over marked bits in bit map, doing a full scan and mark
2937   // from these roots using the following algorithm:
2938   // . if oop is to the right of the current scan pointer,
2939   //   mark corresponding bit (we'll process it later)
2940   // . else (oop is to left of current scan pointer)
2941   //   push oop on marking stack
2942   // . drain the marking stack
2943 
2944   // Note that when we do a marking step we need to hold the
2945   // bit map lock -- recall that direct allocation (by mutators)
2946   // and promotion (by the young generation collector) is also
2947   // marking the bit map. [the so-called allocate live policy.]
2948   // Because the implementation of bit map marking is not
2949   // robust wrt simultaneous marking of bits in the same word,
2950   // we need to make sure that there is no such interference
2951   // between concurrent such updates.


5278     assert(t->is_ConcurrentGC_thread(),
5279            "Should be CMS thread");
5280   } else {
5281     // We can be the CMS thread only if we are in a stop-world
5282     // phase of CMS collection.
5283     if (t->is_ConcurrentGC_thread()) {
5284       assert(_collectorState == InitialMarking ||
5285              _collectorState == FinalMarking,
5286              "Should be a stop-world phase");
5287       // The CMS thread should be holding the CMS_token.
5288       assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
5289              "Potential interference with concurrently "
5290              "executing VM thread");
5291     }
5292   }
5293 }
5294 #endif
5295 
5296 void CMSCollector::sweep() {
5297   assert(_collectorState == Sweeping, "just checking");
5298   _gc_timer_cm->register_gc_concurrent_start("Concurrent Sweep");
5299   check_correct_thread_executing();
5300   verify_work_stacks_empty();
5301   verify_overflow_empty();
5302   increment_sweep_count();
5303   TraceCMSMemoryManagerStats tms(_collectorState,GenCollectedHeap::heap()->gc_cause());
5304 
5305   _inter_sweep_timer.stop();
5306   _inter_sweep_estimate.sample(_inter_sweep_timer.seconds());
5307 
5308   assert(!_intra_sweep_timer.is_active(), "Should not be active");
5309   _intra_sweep_timer.reset();
5310   _intra_sweep_timer.start();
5311   {
5312     GCTraceCPUTime tcpu;
5313     CMSPhaseAccounting pa(this, "Concurrent Sweep");
5314     // First sweep the old gen
5315     {
5316       CMSTokenSyncWithLocks ts(true, _cmsGen->freelistLock(),
5317                                bitMapLock());
5318       sweepWork(_cmsGen);


5359   // and out of the Sweeping state must be synchronously visible
5360   // globally to the mutators.
5361   // The transition into the Marking state happens with the world
5362   // stopped so the mutators will globally see it.  Sweeping is
5363   // done asynchronously by the background collector so the transition
5364   // from the Sweeping state to the Resizing state must be done
5365   // under the freelistLock (as is the check for whether to
5366   // allocate-live and whether to dirty the mod-union table).
5367   assert(_collectorState == Resizing, "Change of collector state to"
5368     " Resizing must be done under the freelistLocks (plural)");
5369 
5370   // Now that sweeping has been completed, we clear
5371   // the incremental_collection_failed flag,
5372   // thus inviting a younger gen collection to promote into
5373   // this generation. If such a promotion may still fail,
5374   // the flag will be set again when a young collection is
5375   // attempted.
5376   GenCollectedHeap* gch = GenCollectedHeap::heap();
5377   gch->clear_incremental_collection_failed();  // Worth retrying as fresh space may have been freed up
5378   gch->update_full_collections_completed(_collection_count_start);
5379   _gc_timer_cm->register_gc_concurrent_end();
5380 }
5381 
5382 // FIX ME!!! Looks like this belongs in CFLSpace, with
5383 // CMSGen merely delegating to it.
5384 void ConcurrentMarkSweepGeneration::setNearLargestChunk() {
5385   double nearLargestPercent = FLSLargestBlockCoalesceProximity;
5386   HeapWord*  minAddr        = _cmsSpace->bottom();
5387   HeapWord*  largestAddr    =
5388     (HeapWord*) _cmsSpace->dictionary()->find_largest_dict();
5389   if (largestAddr == NULL) {
5390     // The dictionary appears to be empty.  In this case
5391     // try to coalesce at the end of the heap.
5392     largestAddr = _cmsSpace->end();
5393   }
5394   size_t largestOffset     = pointer_delta(largestAddr, minAddr);
5395   size_t nearLargestOffset =
5396     (size_t)((double)largestOffset * nearLargestPercent) - MinChunkSize;
5397   log_debug(gc, freelist)("CMS: Large Block: " PTR_FORMAT "; Proximity: " PTR_FORMAT " -> " PTR_FORMAT,
5398                           p2i(largestAddr), p2i(_cmsSpace->nearLargestChunk()), p2i(minAddr + nearLargestOffset));
5399   _cmsSpace->set_nearLargestChunk(minAddr + nearLargestOffset);


< prev index next >