< prev index next >

src/hotspot/share/gc/g1/g1CollectionSet.hpp

Print this page
rev 52675 : 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
Reviewed-by:
Contributed-by: erik.helin@oracle.com, stefan.johansson@oracle.com
rev 52676 : imported patch AMGC-impl
rev 52677 : imported patch AMGC-tsch-rev1
rev 52678 : imported patch AMGC-tsch-rev1-optcset


  39 class G1CollectionSet {
  40   G1CollectedHeap* _g1h;
  41   G1Policy* _policy;
  42 
  43   CollectionSetChooser* _cset_chooser;
  44 
  45   uint _eden_region_length;
  46   uint _survivor_region_length;
  47   uint _old_region_length;
  48 
  49   // The actual collection set as a set of region indices.
  50   // All entries in _collection_set_regions below _collection_set_cur_length are
  51   // assumed to be valid entries.
  52   // We assume that at any time there is at most only one writer and (one or more)
  53   // concurrent readers. This means we are good with using storestore and loadload
  54   // barriers on the writer and reader respectively only.
  55   uint* _collection_set_regions;
  56   volatile size_t _collection_set_cur_length;
  57   size_t _collection_set_max_length;
  58 







  59   // The number of bytes in the collection set before the pause. Set from
  60   // the incrementally built collection set at the start of an evacuation
  61   // pause, and incremented in finalize_old_part() when adding old regions
  62   // (if any) to the collection set.
  63   size_t _bytes_used_before;
  64 
  65   size_t _recorded_rs_lengths;
  66 
  67   // The associated information that is maintained while the incremental
  68   // collection set is being built with young regions. Used to populate
  69   // the recorded info for the evacuation pause.
  70 
  71   enum CSetBuildType {
  72     Active,             // We are actively building the collection set
  73     Inactive            // We are not actively building the collection set
  74   };
  75 
  76   CSetBuildType _inc_build_state;
  77 
  78   // The number of bytes in the incrementally built collection set.


  89 
  90   // A concurrent refinement thread periodically samples the young
  91   // region RSets and needs to update _inc_recorded_rs_lengths as
  92   // the RSets grow. Instead of having to synchronize updates to that
  93   // field we accumulate them in this field and add it to
  94   // _inc_recorded_rs_lengths_diffs at the start of a GC.
  95   ssize_t _inc_recorded_rs_lengths_diffs;
  96 
  97   // The predicted elapsed time it will take to collect the regions in
  98   // the CSet. This is updated by the thread that adds a new region to
  99   // the CSet. See the comment for _inc_recorded_rs_lengths about
 100   // MT-safety assumptions.
 101   double _inc_predicted_elapsed_time_ms;
 102 
 103   // See the comment for _inc_recorded_rs_lengths_diffs.
 104   double _inc_predicted_elapsed_time_ms_diffs;
 105 
 106   G1CollectorState* collector_state();
 107   G1GCPhaseTimes* phase_times();
 108 
 109   double predict_region_elapsed_time_ms(HeapRegion* hr);
 110 
 111   void verify_young_cset_indices() const NOT_DEBUG_RETURN;




 112 public:
 113   G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy);
 114   ~G1CollectionSet();
 115 
 116   // Initializes the collection set giving the maximum possible length of the collection set.
 117   void initialize(uint max_region_length);


 118 
 119   CollectionSetChooser* cset_chooser();
 120 
 121   void init_region_lengths(uint eden_cset_region_length,
 122                            uint survivor_cset_region_length);
 123 
 124   void set_recorded_rs_lengths(size_t rs_lengths);
 125 
 126   uint region_length() const       { return young_region_length() +
 127                                             old_region_length(); }
 128   uint young_region_length() const { return eden_region_length() +
 129                                             survivor_region_length(); }
 130 
 131   uint eden_region_length() const     { return _eden_region_length;     }
 132   uint survivor_region_length() const { return _survivor_region_length; }
 133   uint old_region_length() const      { return _old_region_length;      }

 134 
 135   // Incremental collection set support
 136 
 137   // Initialize incremental collection set info.
 138   void start_incremental_building();
 139 
 140   // Perform any final calculations on the incremental collection set fields
 141   // before we can use them.
 142   void finalize_incremental_building();
 143 
 144   // Reset the contents of the collection set.
 145   void clear();
 146 
 147   // Iterate over the collection set, applying the given HeapRegionClosure on all of them.
 148   // If may_be_aborted is true, iteration may be aborted using the return value of the
 149   // called closure method.
 150   void iterate(HeapRegionClosure* cl) const;
 151 
 152   // Iterate over the collection set, applying the given HeapRegionClosure on all of them,
 153   // trying to optimally spread out starting position of total_workers workers given the


 158   void stop_incremental_building() { _inc_build_state = Inactive; }
 159 
 160   size_t recorded_rs_lengths() { return _recorded_rs_lengths; }
 161 
 162   size_t bytes_used_before() const {
 163     return _bytes_used_before;
 164   }
 165 
 166   void reset_bytes_used_before() {
 167     _bytes_used_before = 0;
 168   }
 169 
 170   // Choose a new collection set.  Marks the chosen regions as being
 171   // "in_collection_set".
 172   double finalize_young_part(double target_pause_time_ms, G1SurvivorRegions* survivors);
 173   void finalize_old_part(double time_remaining_ms);
 174 
 175   // Add old region "hr" to the collection set.
 176   void add_old_region(HeapRegion* hr);
 177 



 178   // Update information about hr in the aggregated information for
 179   // the incrementally built collection set.
 180   void update_young_region_prediction(HeapRegion* hr, size_t new_rs_length);
 181 
 182   // Add eden region to the collection set.
 183   void add_eden_region(HeapRegion* hr);
 184 
 185   // Add survivor region to the collection set.
 186   void add_survivor_regions(HeapRegion* hr);
 187 
 188 #ifndef PRODUCT
 189   bool verify_young_ages();
 190 
 191   void print(outputStream* st);
 192 #endif // !PRODUCT
 193 



















 194 private:
 195   // Update the incremental collection set information when adding a region.
 196   void add_young_region_common(HeapRegion* hr);










































 197 };
 198 
 199 #endif // SHARE_VM_GC_G1_G1COLLECTIONSET_HPP
 200 


  39 class G1CollectionSet {
  40   G1CollectedHeap* _g1h;
  41   G1Policy* _policy;
  42 
  43   CollectionSetChooser* _cset_chooser;
  44 
  45   uint _eden_region_length;
  46   uint _survivor_region_length;
  47   uint _old_region_length;
  48 
  49   // The actual collection set as a set of region indices.
  50   // All entries in _collection_set_regions below _collection_set_cur_length are
  51   // assumed to be valid entries.
  52   // We assume that at any time there is at most only one writer and (one or more)
  53   // concurrent readers. This means we are good with using storestore and loadload
  54   // barriers on the writer and reader respectively only.
  55   uint* _collection_set_regions;
  56   volatile size_t _collection_set_cur_length;
  57   size_t _collection_set_max_length;
  58 
  59   // When doing mixed collections we can add old regions to the collection, which
  60   // can be collected if there is enough time. We call these optional regions and
  61   // the pointer to these regions are stored in the array below.
  62   HeapRegion** _optional_regions;
  63   uint _optional_region_length;
  64   uint _optional_region_max_length;
  65 
  66   // The number of bytes in the collection set before the pause. Set from
  67   // the incrementally built collection set at the start of an evacuation
  68   // pause, and incremented in finalize_old_part() when adding old regions
  69   // (if any) to the collection set.
  70   size_t _bytes_used_before;
  71 
  72   size_t _recorded_rs_lengths;
  73 
  74   // The associated information that is maintained while the incremental
  75   // collection set is being built with young regions. Used to populate
  76   // the recorded info for the evacuation pause.
  77 
  78   enum CSetBuildType {
  79     Active,             // We are actively building the collection set
  80     Inactive            // We are not actively building the collection set
  81   };
  82 
  83   CSetBuildType _inc_build_state;
  84 
  85   // The number of bytes in the incrementally built collection set.


  96 
  97   // A concurrent refinement thread periodically samples the young
  98   // region RSets and needs to update _inc_recorded_rs_lengths as
  99   // the RSets grow. Instead of having to synchronize updates to that
 100   // field we accumulate them in this field and add it to
 101   // _inc_recorded_rs_lengths_diffs at the start of a GC.
 102   ssize_t _inc_recorded_rs_lengths_diffs;
 103 
 104   // The predicted elapsed time it will take to collect the regions in
 105   // the CSet. This is updated by the thread that adds a new region to
 106   // the CSet. See the comment for _inc_recorded_rs_lengths about
 107   // MT-safety assumptions.
 108   double _inc_predicted_elapsed_time_ms;
 109 
 110   // See the comment for _inc_recorded_rs_lengths_diffs.
 111   double _inc_predicted_elapsed_time_ms_diffs;
 112 
 113   G1CollectorState* collector_state();
 114   G1GCPhaseTimes* phase_times();
 115 


 116   void verify_young_cset_indices() const NOT_DEBUG_RETURN;
 117   void add_as_optional(HeapRegion* hr);
 118   void add_as_old(HeapRegion* hr);
 119   bool optional_is_full();
 120 
 121 public:
 122   G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy);
 123   ~G1CollectionSet();
 124 
 125   // Initializes the collection set giving the maximum possible length of the collection set.
 126   void initialize(uint max_region_length);
 127   void initialize_optional(uint max_length);
 128   void free_optional_regions();
 129 
 130   CollectionSetChooser* cset_chooser();
 131 
 132   void init_region_lengths(uint eden_cset_region_length,
 133                            uint survivor_cset_region_length);
 134 
 135   void set_recorded_rs_lengths(size_t rs_lengths);
 136 
 137   uint region_length() const       { return young_region_length() +
 138                                             old_region_length(); }
 139   uint young_region_length() const { return eden_region_length() +
 140                                             survivor_region_length(); }
 141 
 142   uint eden_region_length() const     { return _eden_region_length;     }
 143   uint survivor_region_length() const { return _survivor_region_length; }
 144   uint old_region_length() const      { return _old_region_length;      }
 145   uint optional_region_length() const { return _optional_region_length; }
 146 
 147   // Incremental collection set support
 148 
 149   // Initialize incremental collection set info.
 150   void start_incremental_building();
 151 
 152   // Perform any final calculations on the incremental collection set fields
 153   // before we can use them.
 154   void finalize_incremental_building();
 155 
 156   // Reset the contents of the collection set.
 157   void clear();
 158 
 159   // Iterate over the collection set, applying the given HeapRegionClosure on all of them.
 160   // If may_be_aborted is true, iteration may be aborted using the return value of the
 161   // called closure method.
 162   void iterate(HeapRegionClosure* cl) const;
 163 
 164   // Iterate over the collection set, applying the given HeapRegionClosure on all of them,
 165   // trying to optimally spread out starting position of total_workers workers given the


 170   void stop_incremental_building() { _inc_build_state = Inactive; }
 171 
 172   size_t recorded_rs_lengths() { return _recorded_rs_lengths; }
 173 
 174   size_t bytes_used_before() const {
 175     return _bytes_used_before;
 176   }
 177 
 178   void reset_bytes_used_before() {
 179     _bytes_used_before = 0;
 180   }
 181 
 182   // Choose a new collection set.  Marks the chosen regions as being
 183   // "in_collection_set".
 184   double finalize_young_part(double target_pause_time_ms, G1SurvivorRegions* survivors);
 185   void finalize_old_part(double time_remaining_ms);
 186 
 187   // Add old region "hr" to the collection set.
 188   void add_old_region(HeapRegion* hr);
 189 
 190   // Add old region "hr" to optional collection set.
 191   void add_optional_region(HeapRegion* hr);
 192 
 193   // Update information about hr in the aggregated information for
 194   // the incrementally built collection set.
 195   void update_young_region_prediction(HeapRegion* hr, size_t new_rs_length);
 196 
 197   // Add eden region to the collection set.
 198   void add_eden_region(HeapRegion* hr);
 199 
 200   // Add survivor region to the collection set.
 201   void add_survivor_regions(HeapRegion* hr);
 202 
 203 #ifndef PRODUCT
 204   bool verify_young_ages();
 205 
 206   void print(outputStream* st);
 207 #endif // !PRODUCT
 208 
 209   double predict_region_elapsed_time_ms(HeapRegion* hr);
 210 
 211   void clear_optional_region(const HeapRegion* hr);
 212 
 213   HeapRegion* optional_region_at(uint i) const {
 214     assert(_optional_regions != NULL, "Not yet initialized");
 215     assert(i < _optional_region_length, "index %u out of bounds (%u)", i, _optional_region_length);
 216     return _optional_regions[i];
 217   }
 218 
 219   HeapRegion* remove_last_optional_region() {
 220     assert(_optional_regions != NULL, "Not yet initialized");
 221     assert(_optional_region_length != 0, "No region to remove");
 222     _optional_region_length--;
 223     HeapRegion* removed = _optional_regions[_optional_region_length];
 224     _optional_regions[_optional_region_length] = NULL;
 225     return removed;
 226   }
 227 
 228 private:
 229   // Update the incremental collection set information when adding a region.
 230   void add_young_region_common(HeapRegion* hr);
 231 };
 232 
 233 // Helper class to manage the optional regions in a Mixed collection.
 234 class G1OptionalCSet : public StackObj {
 235 private:
 236   G1CollectionSet* _cset;
 237   uint _current_index;
 238   uint _current_limit;
 239   bool _prepare_failed;
 240   bool _evacuation_failed;
 241 
 242   void prepare_to_evacuate_optional_region(HeapRegion* hr);
 243 
 244 public:
 245   static const uint InvalidCSetIndex = UINT_MAX;
 246 
 247   G1OptionalCSet(G1CollectionSet* cset) :
 248     _cset(cset),
 249     _current_index(0),
 250     _current_limit(0),
 251     _prepare_failed(false),
 252     _evacuation_failed(false) { }
 253   // The destructor returns regions to the cset-chooser and
 254   // frees the optional structure in the cset.
 255   ~G1OptionalCSet();
 256 
 257   uint current_index() { return _current_index; }
 258   uint current_limit() { return _current_limit; }
 259 
 260   uint size();
 261   bool is_empty();
 262 
 263   HeapRegion* region_at(uint index);
 264 
 265   // Prepare a set of regions for optional evacuation.
 266   void prepare_evacuation(double time_left_ms);
 267   bool prepare_failed();
 268 
 269   // Complete the evacuation of the previously prepared
 270   // regions by updating their state and check for failures.
 271   void complete_evacuation();
 272   bool evacuation_failed();
 273 };
 274 
 275 #endif // SHARE_VM_GC_G1_G1COLLECTIONSET_HPP
 276 
< prev index next >