hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
changeset 31358 693058672cc6
parent 31330 77061bb01b18
child 31592 43f48e165466
equal deleted inserted replaced
31357:0cef600ba9b7 31358:693058672cc6
   188     promo.setSpace(cfls);
   188     promo.setSpace(cfls);
   189   }
   189   }
   190 };
   190 };
   191 
   191 
   192 ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration(
   192 ConcurrentMarkSweepGeneration::ConcurrentMarkSweepGeneration(
   193      ReservedSpace rs, size_t initial_byte_size, int level,
   193      ReservedSpace rs, size_t initial_byte_size,
   194      CardTableRS* ct, bool use_adaptive_freelists,
   194      CardTableRS* ct, bool use_adaptive_freelists,
   195      FreeBlockDictionary<FreeChunk>::DictionaryChoice dictionaryChoice) :
   195      FreeBlockDictionary<FreeChunk>::DictionaryChoice dictionaryChoice) :
   196   CardGeneration(rs, initial_byte_size, level, ct),
   196   CardGeneration(rs, initial_byte_size, ct),
   197   _dilatation_factor(((double)MinChunkSize)/((double)(CollectedHeap::min_fill_size()))),
   197   _dilatation_factor(((double)MinChunkSize)/((double)(CollectedHeap::min_fill_size()))),
   198   _did_compact(false)
   198   _did_compact(false)
   199 {
   199 {
   200   HeapWord* bottom = (HeapWord*) _virtual_space.low();
   200   HeapWord* bottom = (HeapWord*) _virtual_space.low();
   201   HeapWord* end    = (HeapWord*) _virtual_space.high();
   201   HeapWord* end    = (HeapWord*) _virtual_space.high();
   680 #endif
   680 #endif
   681 
   681 
   682 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) {
   682 void ConcurrentMarkSweepGeneration::printOccupancy(const char *s) {
   683   GenCollectedHeap* gch = GenCollectedHeap::heap();
   683   GenCollectedHeap* gch = GenCollectedHeap::heap();
   684   if (PrintGCDetails) {
   684   if (PrintGCDetails) {
       
   685     // I didn't want to change the logging when removing the level concept,
       
   686     // but I guess this logging could say "old" or something instead of "1".
       
   687     assert(gch->is_old_gen(this),
       
   688            "The CMS generation should be the old generation");
       
   689     uint level = 1;
   685     if (Verbose) {
   690     if (Verbose) {
   686       gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]",
   691       gclog_or_tty->print("[%u %s-%s: "SIZE_FORMAT"("SIZE_FORMAT")]",
   687         level(), short_name(), s, used(), capacity());
   692         level, short_name(), s, used(), capacity());
   688     } else {
   693     } else {
   689       gclog_or_tty->print("[%d %s-%s: "SIZE_FORMAT"K("SIZE_FORMAT"K)]",
   694       gclog_or_tty->print("[%u %s-%s: "SIZE_FORMAT"K("SIZE_FORMAT"K)]",
   690         level(), short_name(), s, used() / K, capacity() / K);
   695         level, short_name(), s, used() / K, capacity() / K);
   691     }
   696     }
   692   }
   697   }
   693   if (Verbose) {
   698   if (Verbose) {
   694     gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")",
   699     gclog_or_tty->print(" "SIZE_FORMAT"("SIZE_FORMAT")",
   695               gch->used(), gch->capacity());
   700               gch->used(), gch->capacity());
   795     if (PrintGCDetails && Verbose) {
   800     if (PrintGCDetails && Verbose) {
   796       size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
   801       size_t desired_capacity = (size_t)(used() / ((double) 1 - desired_free_percentage));
   797       gclog_or_tty->print_cr("\nFrom compute_new_size: ");
   802       gclog_or_tty->print_cr("\nFrom compute_new_size: ");
   798       gclog_or_tty->print_cr("  Free fraction %f", free_percentage);
   803       gclog_or_tty->print_cr("  Free fraction %f", free_percentage);
   799       gclog_or_tty->print_cr("  Desired free fraction %f",
   804       gclog_or_tty->print_cr("  Desired free fraction %f",
   800         desired_free_percentage);
   805               desired_free_percentage);
   801       gclog_or_tty->print_cr("  Maximum free fraction %f",
   806       gclog_or_tty->print_cr("  Maximum free fraction %f",
   802         maximum_free_percentage);
   807               maximum_free_percentage);
   803       gclog_or_tty->print_cr("  Capacity "SIZE_FORMAT, capacity()/1000);
   808       gclog_or_tty->print_cr("  Capacity "SIZE_FORMAT, capacity()/1000);
   804       gclog_or_tty->print_cr("  Desired capacity "SIZE_FORMAT,
   809       gclog_or_tty->print_cr("  Desired capacity "SIZE_FORMAT,
   805         desired_capacity/1000);
   810               desired_capacity/1000);
   806       int prev_level = level() - 1;
   811       GenCollectedHeap* gch = GenCollectedHeap::heap();
   807       if (prev_level >= 0) {
   812       assert(gch->is_old_gen(this), "The CMS generation should always be the old generation");
   808         size_t prev_size = 0;
   813       size_t young_size = gch->young_gen()->capacity();
   809         GenCollectedHeap* gch = GenCollectedHeap::heap();
   814       gclog_or_tty->print_cr("  Young gen size " SIZE_FORMAT, young_size / 1000);
   810         Generation* prev_gen = gch->young_gen();
       
   811         prev_size = prev_gen->capacity();
       
   812           gclog_or_tty->print_cr("  Younger gen size "SIZE_FORMAT,
       
   813                                  prev_size/1000);
       
   814       }
       
   815       gclog_or_tty->print_cr("  unsafe_max_alloc_nogc "SIZE_FORMAT,
   815       gclog_or_tty->print_cr("  unsafe_max_alloc_nogc "SIZE_FORMAT,
   816         unsafe_max_alloc_nogc()/1000);
   816               unsafe_max_alloc_nogc()/1000);
   817       gclog_or_tty->print_cr("  contiguous available "SIZE_FORMAT,
   817       gclog_or_tty->print_cr("  contiguous available "SIZE_FORMAT,
   818         contiguous_available()/1000);
   818               contiguous_available()/1000);
   819       gclog_or_tty->print_cr("  Expand by "SIZE_FORMAT" (bytes)",
   819       gclog_or_tty->print_cr("  Expand by "SIZE_FORMAT" (bytes)",
   820         expand_bytes);
   820               expand_bytes);
   821     }
   821     }
   822     // safe if expansion fails
   822     // safe if expansion fails
   823     expand_for_gc_cause(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio);
   823     expand_for_gc_cause(expand_bytes, 0, CMSExpansionCause::_satisfy_free_ratio);
   824     if (PrintGCDetails && Verbose) {
   824     if (PrintGCDetails && Verbose) {
   825       gclog_or_tty->print_cr("  Expanded free fraction %f",
   825       gclog_or_tty->print_cr("  Expanded free fraction %f",
  1648     _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()),
  1648     _cmsGen->cmsSpace()->beginSweepFLCensus((float)(_inter_sweep_timer.seconds()),
  1649                                             _inter_sweep_estimate.padded_average(),
  1649                                             _inter_sweep_estimate.padded_average(),
  1650                                             _intra_sweep_estimate.padded_average());
  1650                                             _intra_sweep_estimate.padded_average());
  1651   }
  1651   }
  1652 
  1652 
  1653   GenMarkSweep::invoke_at_safepoint(_cmsGen->level(),
  1653   GenMarkSweep::invoke_at_safepoint(ref_processor(), clear_all_soft_refs);
  1654     ref_processor(), clear_all_soft_refs);
       
  1655   #ifdef ASSERT
  1654   #ifdef ASSERT
  1656     CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace();
  1655     CompactibleFreeListSpace* cms_space = _cmsGen->cmsSpace();
  1657     size_t free_size = cms_space->free();
  1656     size_t free_size = cms_space->free();
  1658     assert(free_size ==
  1657     assert(free_size ==
  1659            pointer_delta(cms_space->end(), cms_space->compaction_top())
  1658            pointer_delta(cms_space->end(), cms_space->compaction_top())
  2430 
  2429 
  2431   {
  2430   {
  2432     StrongRootsScope srs(1);
  2431     StrongRootsScope srs(1);
  2433 
  2432 
  2434     gch->gen_process_roots(&srs,
  2433     gch->gen_process_roots(&srs,
  2435                            _cmsGen->level(),
  2434                            GenCollectedHeap::OldGen,
  2436                            true,   // younger gens are roots
  2435                            true,   // younger gens are roots
  2437                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  2436                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  2438                            should_unload_classes(),
  2437                            should_unload_classes(),
  2439                            &notOlder,
  2438                            &notOlder,
  2440                            NULL,
  2439                            NULL,
  2502 
  2501 
  2503   {
  2502   {
  2504     StrongRootsScope srs(1);
  2503     StrongRootsScope srs(1);
  2505 
  2504 
  2506     gch->gen_process_roots(&srs,
  2505     gch->gen_process_roots(&srs,
  2507                            _cmsGen->level(),
  2506                            GenCollectedHeap::OldGen,
  2508                            true,   // younger gens are roots
  2507                            true,   // younger gens are roots
  2509                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  2508                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  2510                            should_unload_classes(),
  2509                            should_unload_classes(),
  2511                            &notOlder,
  2510                            &notOlder,
  2512                            NULL,
  2511                            NULL,
  3029       gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
  3028       gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
  3030 
  3029 
  3031       StrongRootsScope srs(1);
  3030       StrongRootsScope srs(1);
  3032 
  3031 
  3033       gch->gen_process_roots(&srs,
  3032       gch->gen_process_roots(&srs,
  3034                              _cmsGen->level(),
  3033                              GenCollectedHeap::OldGen,
  3035                              true,   // younger gens are roots
  3034                              true,   // younger gens are roots
  3036                              GenCollectedHeap::ScanningOption(roots_scanning_options()),
  3035                              GenCollectedHeap::ScanningOption(roots_scanning_options()),
  3037                              should_unload_classes(),
  3036                              should_unload_classes(),
  3038                              &notOlder,
  3037                              &notOlder,
  3039                              NULL,
  3038                              NULL,
  4280       // Temporarily set flag to false, GCH->do_collection will
  4279       // Temporarily set flag to false, GCH->do_collection will
  4281       // expect it to be false and set to true
  4280       // expect it to be false and set to true
  4282       FlagSetting fl(gch->_is_gc_active, false);
  4281       FlagSetting fl(gch->_is_gc_active, false);
  4283       NOT_PRODUCT(GCTraceTime t("Scavenge-Before-Remark",
  4282       NOT_PRODUCT(GCTraceTime t("Scavenge-Before-Remark",
  4284         PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());)
  4283         PrintGCDetails && Verbose, true, _gc_timer_cm, _gc_tracer_cm->gc_id());)
  4285       int level = _cmsGen->level() - 1;
  4284       gch->do_collection(true,                      // full (i.e. force, see below)
  4286       if (level >= 0) {
  4285                          false,                     // !clear_all_soft_refs
  4287         gch->do_collection(true,        // full (i.e. force, see below)
  4286                          0,                         // size
  4288                            false,       // !clear_all_soft_refs
  4287                          false,                     // is_tlab
  4289                            0,           // size
  4288                          GenCollectedHeap::YoungGen // type
  4290                            false,       // is_tlab
  4289         );
  4291                            level        // max_level
       
  4292                           );
       
  4293       }
       
  4294     }
  4290     }
  4295     FreelistLocker x(this);
  4291     FreelistLocker x(this);
  4296     MutexLockerEx y(bitMapLock(),
  4292     MutexLockerEx y(bitMapLock(),
  4297                     Mutex::_no_safepoint_check_flag);
  4293                     Mutex::_no_safepoint_check_flag);
  4298     checkpointRootsFinalWork();
  4294     checkpointRootsFinalWork();
  4462   _timer.start();
  4458   _timer.start();
  4463 
  4459 
  4464   CLDToOopClosure cld_closure(&par_mri_cl, true);
  4460   CLDToOopClosure cld_closure(&par_mri_cl, true);
  4465 
  4461 
  4466   gch->gen_process_roots(_strong_roots_scope,
  4462   gch->gen_process_roots(_strong_roots_scope,
  4467                          _collector->_cmsGen->level(),
  4463                          GenCollectedHeap::OldGen,
  4468                          false,     // yg was scanned above
  4464                          false,     // yg was scanned above
  4469                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
  4465                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
  4470                          _collector->should_unload_classes(),
  4466                          _collector->should_unload_classes(),
  4471                          &par_mri_cl,
  4467                          &par_mri_cl,
  4472                          NULL,
  4468                          NULL,
  4601 
  4597 
  4602   // ---------- remaining roots --------------
  4598   // ---------- remaining roots --------------
  4603   _timer.reset();
  4599   _timer.reset();
  4604   _timer.start();
  4600   _timer.start();
  4605   gch->gen_process_roots(_strong_roots_scope,
  4601   gch->gen_process_roots(_strong_roots_scope,
  4606                          _collector->_cmsGen->level(),
  4602                          GenCollectedHeap::OldGen,
  4607                          false,     // yg was scanned above
  4603                          false,     // yg was scanned above
  4608                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
  4604                          GenCollectedHeap::ScanningOption(_collector->CMSCollector::roots_scanning_options()),
  4609                          _collector->should_unload_classes(),
  4605                          _collector->should_unload_classes(),
  4610                          &par_mrias_cl,
  4606                          &par_mrias_cl,
  4611                          NULL,
  4607                          NULL,
  5182 
  5178 
  5183     gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
  5179     gch->rem_set()->prepare_for_younger_refs_iterate(false); // Not parallel.
  5184     StrongRootsScope srs(1);
  5180     StrongRootsScope srs(1);
  5185 
  5181 
  5186     gch->gen_process_roots(&srs,
  5182     gch->gen_process_roots(&srs,
  5187                            _cmsGen->level(),
  5183                            GenCollectedHeap::OldGen,
  5188                            true,  // younger gens as roots
  5184                            true,  // younger gens as roots
  5189                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  5185                            GenCollectedHeap::ScanningOption(roots_scanning_options()),
  5190                            should_unload_classes(),
  5186                            should_unload_classes(),
  5191                            &mrias_cl,
  5187                            &mrias_cl,
  5192                            NULL,
  5188                            NULL,
  5646 
  5642 
  5647 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() {
  5643 FreeChunk* ConcurrentMarkSweepGeneration::find_chunk_at_end() {
  5648   return _cmsSpace->find_chunk_at_end();
  5644   return _cmsSpace->find_chunk_at_end();
  5649 }
  5645 }
  5650 
  5646 
  5651 void ConcurrentMarkSweepGeneration::update_gc_stats(int current_level,
  5647 void ConcurrentMarkSweepGeneration::update_gc_stats(Generation* current_generation,
  5652                                                     bool full) {
  5648                                                     bool full) {
  5653   // The next lower level has been collected.  Gather any statistics
  5649   // If the young generation has been collected, gather any statistics
  5654   // that are of interest at this point.
  5650   // that are of interest at this point.
  5655   if (!full && (current_level + 1) == level()) {
  5651   bool current_is_young = GenCollectedHeap::heap()->is_young_gen(current_generation);
       
  5652   if (!full && current_is_young) {
  5656     // Gather statistics on the young generation collection.
  5653     // Gather statistics on the young generation collection.
  5657     collector()->stats().record_gc0_end(used());
  5654     collector()->stats().record_gc0_end(used());
  5658   }
  5655   }
  5659 }
  5656 }
  5660 
  5657