hotspot/src/share/vm/gc/g1/g1CollectionSet.cpp
changeset 38109 6503703df058
parent 37985 539c597ee0fa
child 38162 4e2c3433a3ae
equal deleted inserted replaced
38108:95c7e9d6747c 38109:6503703df058
    46 
    46 
    47 double G1CollectionSet::predict_region_elapsed_time_ms(HeapRegion* hr) {
    47 double G1CollectionSet::predict_region_elapsed_time_ms(HeapRegion* hr) {
    48   return _policy->predict_region_elapsed_time_ms(hr, collector_state()->gcs_are_young());
    48   return _policy->predict_region_elapsed_time_ms(hr, collector_state()->gcs_are_young());
    49 }
    49 }
    50 
    50 
    51 
       
    52 G1CollectionSet::G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy) :
    51 G1CollectionSet::G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy) :
    53   _g1(g1h),
    52   _g1(g1h),
    54   _policy(policy),
    53   _policy(policy),
    55   _cset_chooser(new CollectionSetChooser()),
    54   _cset_chooser(new CollectionSetChooser()),
    56   _eden_region_length(0),
    55   _eden_region_length(0),
    66   _inc_tail(NULL),
    65   _inc_tail(NULL),
    67   _inc_bytes_used_before(0),
    66   _inc_bytes_used_before(0),
    68   _inc_recorded_rs_lengths(0),
    67   _inc_recorded_rs_lengths(0),
    69   _inc_recorded_rs_lengths_diffs(0),
    68   _inc_recorded_rs_lengths_diffs(0),
    70   _inc_predicted_elapsed_time_ms(0.0),
    69   _inc_predicted_elapsed_time_ms(0.0),
    71   _inc_predicted_elapsed_time_ms_diffs(0.0) {}
    70   _inc_predicted_elapsed_time_ms_diffs(0.0),
       
    71   _inc_region_length(0) {}
    72 
    72 
    73 G1CollectionSet::~G1CollectionSet() {
    73 G1CollectionSet::~G1CollectionSet() {
    74   delete _cset_chooser;
    74   delete _cset_chooser;
    75 }
    75 }
    76 
    76 
    77 void G1CollectionSet::init_region_lengths(uint eden_cset_region_length,
    77 void G1CollectionSet::init_region_lengths(uint eden_cset_region_length,
    78                                           uint survivor_cset_region_length) {
    78                                           uint survivor_cset_region_length) {
    79   _eden_region_length     = eden_cset_region_length;
    79   _eden_region_length     = eden_cset_region_length;
    80   _survivor_region_length = survivor_cset_region_length;
    80   _survivor_region_length = survivor_cset_region_length;
       
    81 
       
    82   assert(young_region_length() == _inc_region_length, "should match %u == %u", young_region_length(), _inc_region_length);
       
    83 
    81   _old_region_length      = 0;
    84   _old_region_length      = 0;
    82 }
    85 }
    83 
    86 
    84 void G1CollectionSet::set_recorded_rs_lengths(size_t rs_lengths) {
    87 void G1CollectionSet::set_recorded_rs_lengths(size_t rs_lengths) {
    85   _recorded_rs_lengths = rs_lengths;
    88   _recorded_rs_lengths = rs_lengths;
   105   assert(_inc_build_state == Inactive, "Precondition");
   108   assert(_inc_build_state == Inactive, "Precondition");
   106 
   109 
   107   _inc_head = NULL;
   110   _inc_head = NULL;
   108   _inc_tail = NULL;
   111   _inc_tail = NULL;
   109   _inc_bytes_used_before = 0;
   112   _inc_bytes_used_before = 0;
       
   113   _inc_region_length = 0;
   110 
   114 
   111   _inc_recorded_rs_lengths = 0;
   115   _inc_recorded_rs_lengths = 0;
   112   _inc_recorded_rs_lengths_diffs = 0;
   116   _inc_recorded_rs_lengths_diffs = 0;
   113   _inc_predicted_elapsed_time_ms = 0.0;
   117   _inc_predicted_elapsed_time_ms = 0.0;
   114   _inc_predicted_elapsed_time_ms_diffs = 0.0;
   118   _inc_predicted_elapsed_time_ms_diffs = 0.0;
   175   hr->set_predicted_elapsed_time_ms(new_region_elapsed_time_ms);
   179   hr->set_predicted_elapsed_time_ms(new_region_elapsed_time_ms);
   176 }
   180 }
   177 
   181 
   178 void G1CollectionSet::add_young_region_common(HeapRegion* hr) {
   182 void G1CollectionSet::add_young_region_common(HeapRegion* hr) {
   179   assert(hr->is_young(), "invariant");
   183   assert(hr->is_young(), "invariant");
   180   assert(hr->young_index_in_cset() > -1, "should have already been set");
       
   181   assert(_inc_build_state == Active, "Precondition");
   184   assert(_inc_build_state == Active, "Precondition");
       
   185 
       
   186   hr->set_young_index_in_cset(_inc_region_length);
       
   187   _inc_region_length++;
   182 
   188 
   183   // This routine is used when:
   189   // This routine is used when:
   184   // * adding survivor regions to the incremental cset at the end of an
   190   // * adding survivor regions to the incremental cset at the end of an
   185   //   evacuation pause or
   191   //   evacuation pause or
   186   // * adding the current allocation region to the incremental cset
   192   // * adding the current allocation region to the incremental cset
   304     // region is free (which is not the case here).
   310     // region is free (which is not the case here).
   305     hr->set_eden_pre_gc();
   311     hr->set_eden_pre_gc();
   306     hr = hr->get_next_young_region();
   312     hr = hr->get_next_young_region();
   307   }
   313   }
   308 
   314 
       
   315   verify_young_cset_indices();
       
   316 
   309   // Clear the fields that point to the survivor list - they are all young now.
   317   // Clear the fields that point to the survivor list - they are all young now.
   310   young_list->clear_survivors();
   318   young_list->clear_survivors();
   311 
   319 
   312   _head = _inc_head;
   320   _head = _inc_head;
   313   _bytes_used_before = _inc_bytes_used_before;
   321   _bytes_used_before = _inc_bytes_used_before;
   422                             old_region_length(), predicted_old_time_ms, time_remaining_ms);
   430                             old_region_length(), predicted_old_time_ms, time_remaining_ms);
   423 
   431 
   424   double non_young_end_time_sec = os::elapsedTime();
   432   double non_young_end_time_sec = os::elapsedTime();
   425   phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
   433   phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
   426 }
   434 }
       
   435 
       
   436 #ifdef ASSERT
       
   437 void G1CollectionSet::verify_young_cset_indices() const {
       
   438   ResourceMark rm;
       
   439   uint* heap_region_indices = NEW_RESOURCE_ARRAY(uint, young_region_length());
       
   440   for (uint i = 0; i < young_region_length(); ++i) {
       
   441     heap_region_indices[i] = (uint)-1;
       
   442   }
       
   443 
       
   444   for (HeapRegion* hr = _inc_head; hr != NULL; hr = hr->next_in_collection_set()) {
       
   445     const int idx = hr->young_index_in_cset();
       
   446     assert(idx > -1, "must be set for all inc cset regions");
       
   447     assert((uint)idx < young_region_length(), "young cset index too large");
       
   448 
       
   449     assert(heap_region_indices[idx] == (uint)-1,
       
   450            "index %d used by multiple regions, first use by %u, second by %u",
       
   451            idx, heap_region_indices[idx], hr->hrm_index());
       
   452 
       
   453     heap_region_indices[idx] = hr->hrm_index();
       
   454   }
       
   455 }
       
   456 #endif