hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
changeset 11584 e1df4d08a1f4
parent 11583 83a7383de44c
child 11639 ff8cfc20d5cb
equal deleted inserted replaced
11583:83a7383de44c 11584:e1df4d08a1f4
   172     *card_ptr = CardTableModRefBS::dirty_card_val();
   172     *card_ptr = CardTableModRefBS::dirty_card_val();
   173     return true;
   173     return true;
   174   }
   174   }
   175 };
   175 };
   176 
   176 
   177 YoungList::YoungList(G1CollectedHeap* g1h)
   177 YoungList::YoungList(G1CollectedHeap* g1h) :
   178   : _g1h(g1h), _head(NULL),
   178     _g1h(g1h), _head(NULL), _length(0), _last_sampled_rs_lengths(0),
   179     _length(0),
   179     _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) {
   180     _last_sampled_rs_lengths(0),
   180   guarantee(check_list_empty(false), "just making sure...");
   181     _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0)
       
   182 {
       
   183   guarantee( check_list_empty(false), "just making sure..." );
       
   184 }
   181 }
   185 
   182 
   186 void YoungList::push_region(HeapRegion *hr) {
   183 void YoungList::push_region(HeapRegion *hr) {
   187   assert(!hr->is_young(), "should not already be young");
   184   assert(!hr->is_young(), "should not already be young");
   188   assert(hr->get_next_young_region() == NULL, "cause it should!");
   185   assert(hr->get_next_young_region() == NULL, "cause it should!");
  1268     TraceMemoryManagerStats tms(true /* fullGC */, gc_cause());
  1265     TraceMemoryManagerStats tms(true /* fullGC */, gc_cause());
  1269 
  1266 
  1270     double start = os::elapsedTime();
  1267     double start = os::elapsedTime();
  1271     g1_policy()->record_full_collection_start();
  1268     g1_policy()->record_full_collection_start();
  1272 
  1269 
       
  1270     // Note: When we have a more flexible GC logging framework that
       
  1271     // allows us to add optional attributes to a GC log record we
       
  1272     // could consider timing and reporting how long we wait in the
       
  1273     // following two methods.
  1273     wait_while_free_regions_coming();
  1274     wait_while_free_regions_coming();
       
  1275     // If we start the compaction before the CM threads finish
       
  1276     // scanning the root regions we might trip them over as we'll
       
  1277     // be moving objects / updating references. So let's wait until
       
  1278     // they are done. By telling them to abort, they should complete
       
  1279     // early.
       
  1280     _cm->root_regions()->abort();
       
  1281     _cm->root_regions()->wait_until_scan_finished();
  1274     append_secondary_free_list_if_not_empty_with_lock();
  1282     append_secondary_free_list_if_not_empty_with_lock();
  1275 
  1283 
  1276     gc_prologue(true);
  1284     gc_prologue(true);
  1277     increment_total_collections(true /* full gc */);
  1285     increment_total_collections(true /* full gc */);
  1278 
  1286 
  1297     ref_processor_cm()->disable_discovery();
  1305     ref_processor_cm()->disable_discovery();
  1298     ref_processor_cm()->abandon_partial_discovery();
  1306     ref_processor_cm()->abandon_partial_discovery();
  1299     ref_processor_cm()->verify_no_references_recorded();
  1307     ref_processor_cm()->verify_no_references_recorded();
  1300 
  1308 
  1301     // Abandon current iterations of concurrent marking and concurrent
  1309     // Abandon current iterations of concurrent marking and concurrent
  1302     // refinement, if any are in progress.
  1310     // refinement, if any are in progress. We have to do this before
       
  1311     // wait_until_scan_finished() below.
  1303     concurrent_mark()->abort();
  1312     concurrent_mark()->abort();
  1304 
  1313 
  1305     // Make sure we'll choose a new allocation region afterwards.
  1314     // Make sure we'll choose a new allocation region afterwards.
  1306     release_mutator_alloc_region();
  1315     release_mutator_alloc_region();
  1307     abandon_gc_alloc_regions();
  1316     abandon_gc_alloc_regions();
  3673 #endif // YOUNG_LIST_VERBOSE
  3682 #endif // YOUNG_LIST_VERBOSE
  3674 
  3683 
  3675         g1_policy()->record_collection_pause_start(start_time_sec,
  3684         g1_policy()->record_collection_pause_start(start_time_sec,
  3676                                                    start_used_bytes);
  3685                                                    start_used_bytes);
  3677 
  3686 
       
  3687         double scan_wait_start = os::elapsedTime();
       
  3688         // We have to wait until the CM threads finish scanning the
       
  3689         // root regions as it's the only way to ensure that all the
       
  3690         // objects on them have been correctly scanned before we start
       
  3691         // moving them during the GC.
       
  3692         bool waited = _cm->root_regions()->wait_until_scan_finished();
       
  3693         if (waited) {
       
  3694           double scan_wait_end = os::elapsedTime();
       
  3695           double wait_time_ms = (scan_wait_end - scan_wait_start) * 1000.0;
       
  3696           g1_policy()->record_root_region_scan_wait_time(wait_time_ms);
       
  3697         }
       
  3698 
  3678 #if YOUNG_LIST_VERBOSE
  3699 #if YOUNG_LIST_VERBOSE
  3679         gclog_or_tty->print_cr("\nAfter recording pause start.\nYoung_list:");
  3700         gclog_or_tty->print_cr("\nAfter recording pause start.\nYoung_list:");
  3680         _young_list->print();
  3701         _young_list->print();
  3681 #endif // YOUNG_LIST_VERBOSE
  3702 #endif // YOUNG_LIST_VERBOSE
  3682 
  3703 
  3782           // when they were freed.  Add in the bytes evacuated.
  3803           // when they were freed.  Add in the bytes evacuated.
  3783           _summary_bytes_used += g1_policy()->bytes_copied_during_gc();
  3804           _summary_bytes_used += g1_policy()->bytes_copied_during_gc();
  3784         }
  3805         }
  3785 
  3806 
  3786         if (g1_policy()->during_initial_mark_pause()) {
  3807         if (g1_policy()->during_initial_mark_pause()) {
       
  3808           // We have to do this before we notify the CM threads that
       
  3809           // they can start working to make sure that all the
       
  3810           // appropriate initialization is done on the CM object.
  3787           concurrent_mark()->checkpointRootsInitialPost();
  3811           concurrent_mark()->checkpointRootsInitialPost();
  3788           set_marking_started();
  3812           set_marking_started();
  3789           // Note that we don't actually trigger the CM thread at
  3813           // Note that we don't actually trigger the CM thread at
  3790           // this point. We do that later when we're sure that
  3814           // this point. We do that later when we're sure that
  3791           // the current thread has completed its logging output.
  3815           // the current thread has completed its logging output.
  5771   assert(!free_regions_coming(), "pre-condition");
  5795   assert(!free_regions_coming(), "pre-condition");
  5772   _free_regions_coming = true;
  5796   _free_regions_coming = true;
  5773 }
  5797 }
  5774 
  5798 
  5775 void G1CollectedHeap::reset_free_regions_coming() {
  5799 void G1CollectedHeap::reset_free_regions_coming() {
       
  5800   assert(free_regions_coming(), "pre-condition");
       
  5801 
  5776   {
  5802   {
  5777     assert(free_regions_coming(), "pre-condition");
       
  5778     MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
  5803     MutexLockerEx x(SecondaryFreeList_lock, Mutex::_no_safepoint_check_flag);
  5779     _free_regions_coming = false;
  5804     _free_regions_coming = false;
  5780     SecondaryFreeList_lock->notify_all();
  5805     SecondaryFreeList_lock->notify_all();
  5781   }
  5806   }
  5782 
  5807