src/share/vm/gc_implementation/g1/heapRegionSet.hpp

changeset 6385
58fc1b1523dc
parent 3957
a2f7274eb6ef
child 6422
8ee855b4e667
     1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionSet.hpp	Thu Mar 06 11:11:04 2014 +0100
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.hpp	Fri Mar 14 10:15:46 2014 +0100
     1.3 @@ -38,135 +38,108 @@
     1.4  #define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
     1.5  #endif // HEAP_REGION_SET_FORCE_VERIFY
     1.6  
     1.7 -//////////////////// HeapRegionSetBase ////////////////////
     1.8 +class hrs_ext_msg;
     1.9 +
    1.10 +class HRSMtSafeChecker : public CHeapObj<mtGC> {
    1.11 +public:
    1.12 +  virtual void check() = 0;
    1.13 +};
    1.14 +
    1.15 +class MasterFreeRegionListMtSafeChecker    : public HRSMtSafeChecker { public: void check(); };
    1.16 +class SecondaryFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
    1.17 +class HumongousRegionSetMtSafeChecker      : public HRSMtSafeChecker { public: void check(); };
    1.18 +class OldRegionSetMtSafeChecker            : public HRSMtSafeChecker { public: void check(); };
    1.19 +
    1.20 +class HeapRegionSetCount VALUE_OBJ_CLASS_SPEC {
    1.21 +  friend class VMStructs;
    1.22 +  uint   _length;
    1.23 +  size_t _capacity;
    1.24 +
    1.25 +public:
    1.26 +  HeapRegionSetCount() : _length(0), _capacity(0) { }
    1.27 +
    1.28 +  const uint   length()   const { return _length;   }
    1.29 +  const size_t capacity() const { return _capacity; }
    1.30 +
    1.31 +  void increment(uint length_to_add, size_t capacity_to_add) {
    1.32 +    _length += length_to_add;
    1.33 +    _capacity += capacity_to_add;
    1.34 +  }
    1.35 +
    1.36 +  void decrement(const uint length_to_remove, const size_t capacity_to_remove) {
    1.37 +    _length -= length_to_remove;
    1.38 +    _capacity -= capacity_to_remove;
    1.39 +  }
    1.40 +};
    1.41  
    1.42  // Base class for all the classes that represent heap region sets. It
    1.43  // contains the basic attributes that each set needs to maintain
    1.44  // (e.g., length, region num, used bytes sum) plus any shared
    1.45  // functionality (e.g., verification).
    1.46  
    1.47 -class hrs_ext_msg;
    1.48 -
    1.49 -typedef enum {
    1.50 -  HRSPhaseNone,
    1.51 -  HRSPhaseEvacuation,
    1.52 -  HRSPhaseCleanup,
    1.53 -  HRSPhaseFullGC
    1.54 -} HRSPhase;
    1.55 -
    1.56 -class HRSPhaseSetter;
    1.57 -
    1.58  class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
    1.59 -  friend class hrs_ext_msg;
    1.60 -  friend class HRSPhaseSetter;
    1.61    friend class VMStructs;
    1.62 +private:
    1.63 +  bool _is_humongous;
    1.64 +  bool _is_empty;
    1.65 +  HRSMtSafeChecker* _mt_safety_checker;
    1.66  
    1.67  protected:
    1.68 -  static uint _unrealistically_long_length;
    1.69 -
    1.70    // The number of regions added to the set. If the set contains
    1.71    // only humongous regions, this reflects only 'starts humongous'
    1.72    // regions and does not include 'continues humongous' ones.
    1.73 -  uint _length;
    1.74 -
    1.75 -  // The total number of regions represented by the set. If the set
    1.76 -  // does not contain humongous regions, this should be the same as
    1.77 -  // _length. If the set contains only humongous regions, this will
    1.78 -  // include the 'continues humongous' regions.
    1.79 -  uint _region_num;
    1.80 -
    1.81 -  // We don't keep track of the total capacity explicitly, we instead
    1.82 -  // recalculate it based on _region_num and the heap region size.
    1.83 -
    1.84 -  // The sum of used bytes in the all the regions in the set.
    1.85 -  size_t _total_used_bytes;
    1.86 +  HeapRegionSetCount _count;
    1.87  
    1.88    const char* _name;
    1.89  
    1.90 -  bool        _verify_in_progress;
    1.91 -  uint        _calc_length;
    1.92 -  uint        _calc_region_num;
    1.93 -  size_t      _calc_total_capacity_bytes;
    1.94 -  size_t      _calc_total_used_bytes;
    1.95 -
    1.96 -  // This is here so that it can be used in the subclasses to assert
    1.97 -  // something different depending on which phase the GC is in. This
    1.98 -  // can be particularly helpful in the check_mt_safety() methods.
    1.99 -  static HRSPhase _phase;
   1.100 -
   1.101 -  // Only used by HRSPhaseSetter.
   1.102 -  static void clear_phase();
   1.103 -  static void set_phase(HRSPhase phase);
   1.104 +  bool _verify_in_progress;
   1.105  
   1.106    // verify_region() is used to ensure that the contents of a region
   1.107 -  // added to / removed from a set are consistent. Different sets
   1.108 -  // make different assumptions about the regions added to them. So
   1.109 -  // each set can override verify_region_extra(), which is called
   1.110 -  // from verify_region(), and do any extra verification it needs to
   1.111 -  // perform in that.
   1.112 -  virtual const char* verify_region_extra(HeapRegion* hr) { return NULL; }
   1.113 -  bool verify_region(HeapRegion* hr,
   1.114 -                     HeapRegionSetBase* expected_containing_set);
   1.115 +  // added to / removed from a set are consistent.
   1.116 +  void verify_region(HeapRegion* hr) PRODUCT_RETURN;
   1.117  
   1.118    // Indicates whether all regions in the set should be humongous or
   1.119    // not. Only used during verification.
   1.120 -  virtual bool regions_humongous() = 0;
   1.121 +  bool regions_humongous() { return _is_humongous; }
   1.122  
   1.123    // Indicates whether all regions in the set should be empty or
   1.124    // not. Only used during verification.
   1.125 -  virtual bool regions_empty() = 0;
   1.126 +  bool regions_empty() { return _is_empty; }
   1.127  
   1.128 -  // Subclasses can optionally override this to do MT safety protocol
   1.129 -  // checks. It is called in an assert from all methods that perform
   1.130 -  // updates on the set (and subclasses should also call it too).
   1.131 -  virtual bool check_mt_safety() { return true; }
   1.132 +  void check_mt_safety() {
   1.133 +    if (_mt_safety_checker != NULL) {
   1.134 +      _mt_safety_checker->check();
   1.135 +    }
   1.136 +  }
   1.137 +
   1.138 +  virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { }
   1.139 +
   1.140 +  HeapRegionSetBase(const char* name, bool humongous, bool empty, HRSMtSafeChecker* mt_safety_checker);
   1.141 +
   1.142 +public:
   1.143 +  const char* name() { return _name; }
   1.144 +
   1.145 +  uint length() { return _count.length(); }
   1.146 +
   1.147 +  bool is_empty() { return _count.length() == 0; }
   1.148 +
   1.149 +  size_t total_capacity_bytes() {
   1.150 +    return _count.capacity();
   1.151 +  }
   1.152 +
   1.153 +  // It updates the fields of the set to reflect hr being added to
   1.154 +  // the set and tags the region appropriately.
   1.155 +  inline void add(HeapRegion* hr);
   1.156 +
   1.157 +  // It updates the fields of the set to reflect hr being removed
   1.158 +  // from the set and tags the region appropriately.
   1.159 +  inline void remove(HeapRegion* hr);
   1.160  
   1.161    // fill_in_ext_msg() writes the the values of the set's attributes
   1.162    // in the custom err_msg (hrs_ext_msg). fill_in_ext_msg_extra()
   1.163    // allows subclasses to append further information.
   1.164 -  virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { }
   1.165    void fill_in_ext_msg(hrs_ext_msg* msg, const char* message);
   1.166  
   1.167 -  // It updates the fields of the set to reflect hr being added to
   1.168 -  // the set.
   1.169 -  inline void update_for_addition(HeapRegion* hr);
   1.170 -
   1.171 -  // It updates the fields of the set to reflect hr being added to
   1.172 -  // the set and tags the region appropriately.
   1.173 -  inline void add_internal(HeapRegion* hr);
   1.174 -
   1.175 -  // It updates the fields of the set to reflect hr being removed
   1.176 -  // from the set.
   1.177 -  inline void update_for_removal(HeapRegion* hr);
   1.178 -
   1.179 -  // It updates the fields of the set to reflect hr being removed
   1.180 -  // from the set and tags the region appropriately.
   1.181 -  inline void remove_internal(HeapRegion* hr);
   1.182 -
   1.183 -  // It clears all the fields of the sets. Note: it will not iterate
   1.184 -  // over the set and remove regions from it. It assumes that the
   1.185 -  // caller has already done so. It will literally just clear the fields.
   1.186 -  virtual void clear();
   1.187 -
   1.188 -  HeapRegionSetBase(const char* name);
   1.189 -
   1.190 -public:
   1.191 -  static void set_unrealistically_long_length(uint len);
   1.192 -
   1.193 -  const char* name() { return _name; }
   1.194 -
   1.195 -  uint length() { return _length; }
   1.196 -
   1.197 -  bool is_empty() { return _length == 0; }
   1.198 -
   1.199 -  uint region_num() { return _region_num; }
   1.200 -
   1.201 -  size_t total_capacity_bytes() {
   1.202 -    return (size_t) region_num() << HeapRegion::LogOfHRGrainBytes;
   1.203 -  }
   1.204 -
   1.205 -  size_t total_used_bytes() { return _total_used_bytes; }
   1.206 -
   1.207    virtual void verify();
   1.208    void verify_start();
   1.209    void verify_next_region(HeapRegion* hr);
   1.210 @@ -187,7 +160,6 @@
   1.211  // assert/guarantee-specific message it also prints out the values of
   1.212  // the fields of the associated set. This can be very helpful in
   1.213  // diagnosing failures.
   1.214 -
   1.215  class hrs_ext_msg : public hrs_err_msg {
   1.216  public:
   1.217    hrs_ext_msg(HeapRegionSetBase* set, const char* message) : hrs_err_msg("") {
   1.218 @@ -195,32 +167,6 @@
   1.219    }
   1.220  };
   1.221  
   1.222 -class HRSPhaseSetter {
   1.223 -public:
   1.224 -  HRSPhaseSetter(HRSPhase phase) {
   1.225 -    HeapRegionSetBase::set_phase(phase);
   1.226 -  }
   1.227 -  ~HRSPhaseSetter() {
   1.228 -    HeapRegionSetBase::clear_phase();
   1.229 -  }
   1.230 -};
   1.231 -
   1.232 -// These two macros are provided for convenience, to keep the uses of
   1.233 -// these two asserts a bit more concise.
   1.234 -
   1.235 -#define hrs_assert_mt_safety_ok(_set_)                                        \
   1.236 -  do {                                                                        \
   1.237 -    assert((_set_)->check_mt_safety(), hrs_ext_msg((_set_), "MT safety"));    \
   1.238 -  } while (0)
   1.239 -
   1.240 -#define hrs_assert_region_ok(_set_, _hr_, _expected_)                         \
   1.241 -  do {                                                                        \
   1.242 -    assert((_set_)->verify_region((_hr_), (_expected_)),                      \
   1.243 -           hrs_ext_msg((_set_), "region verification"));                      \
   1.244 -  } while (0)
   1.245 -
   1.246 -//////////////////// HeapRegionSet ////////////////////
   1.247 -
   1.248  #define hrs_assert_sets_match(_set1_, _set2_)                                 \
   1.249    do {                                                                        \
   1.250      assert(((_set1_)->regions_humongous() ==                                  \
   1.251 @@ -236,63 +182,33 @@
   1.252  // the same interface (namely, the HeapRegionSetBase API).
   1.253  
   1.254  class HeapRegionSet : public HeapRegionSetBase {
   1.255 -protected:
   1.256 -  virtual const char* verify_region_extra(HeapRegion* hr) {
   1.257 -    if (hr->next() != NULL) {
   1.258 -      return "next() should always be NULL as we do not link the regions";
   1.259 -    }
   1.260 +public:
   1.261 +  HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker):
   1.262 +    HeapRegionSetBase(name, humongous, false /* empty */, mt_safety_checker) { }
   1.263  
   1.264 -    return HeapRegionSetBase::verify_region_extra(hr);
   1.265 +  void bulk_remove(const HeapRegionSetCount& removed) {
   1.266 +    _count.decrement(removed.length(), removed.capacity());
   1.267    }
   1.268 -
   1.269 -  HeapRegionSet(const char* name) : HeapRegionSetBase(name) {
   1.270 -    clear();
   1.271 -  }
   1.272 -
   1.273 -public:
   1.274 -  // It adds hr to the set. The region should not be a member of
   1.275 -  // another set.
   1.276 -  inline void add(HeapRegion* hr);
   1.277 -
   1.278 -  // It removes hr from the set. The region should be a member of
   1.279 -  // this set.
   1.280 -  inline void remove(HeapRegion* hr);
   1.281 -
   1.282 -  // It removes a region from the set. Instead of updating the fields
   1.283 -  // of the set to reflect this removal, it accumulates the updates
   1.284 -  // in proxy_set. The idea is that proxy_set is thread-local to
   1.285 -  // avoid multiple threads updating the fields of the set
   1.286 -  // concurrently and having to synchronize. The method
   1.287 -  // update_from_proxy() will update the fields of the set from the
   1.288 -  // proxy_set.
   1.289 -  inline void remove_with_proxy(HeapRegion* hr, HeapRegionSet* proxy_set);
   1.290 -
   1.291 -  // After multiple calls to remove_with_proxy() the updates to the
   1.292 -  // fields of the set are accumulated in proxy_set. This call
   1.293 -  // updates the fields of the set from proxy_set.
   1.294 -  void update_from_proxy(HeapRegionSet* proxy_set);
   1.295  };
   1.296  
   1.297 -//////////////////// HeapRegionLinkedList ////////////////////
   1.298 -
   1.299  // A set that links all the regions added to it in a singly-linked
   1.300  // list. We should try to avoid doing operations that iterate over
   1.301  // such lists in performance critical paths. Typically we should
   1.302  // add / remove one region at a time or concatenate two lists. All
   1.303  // those operations are done in constant time.
   1.304  
   1.305 -class HeapRegionLinkedListIterator;
   1.306 +class FreeRegionListIterator;
   1.307  
   1.308 -class HeapRegionLinkedList : public HeapRegionSetBase {
   1.309 -  friend class HeapRegionLinkedListIterator;
   1.310 +class FreeRegionList : public HeapRegionSetBase {
   1.311 +  friend class FreeRegionListIterator;
   1.312  
   1.313  private:
   1.314    HeapRegion* _head;
   1.315    HeapRegion* _tail;
   1.316  
   1.317 -  // These are provided for use by the friend classes.
   1.318 -  HeapRegion* head() { return _head; }
   1.319 -  HeapRegion* tail() { return _tail; }
   1.320 +  static uint _unrealistically_long_length;
   1.321 +
   1.322 +  void add_as_head_or_tail(FreeRegionList* from_list, bool as_head);
   1.323  
   1.324  protected:
   1.325    virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg);
   1.326 @@ -300,11 +216,19 @@
   1.327    // See the comment for HeapRegionSetBase::clear()
   1.328    virtual void clear();
   1.329  
   1.330 -  HeapRegionLinkedList(const char* name) : HeapRegionSetBase(name) {
   1.331 +public:
   1.332 +  FreeRegionList(const char* name, HRSMtSafeChecker* mt_safety_checker = NULL):
   1.333 +    HeapRegionSetBase(name, false /* humongous */, true /* empty */, mt_safety_checker) {
   1.334      clear();
   1.335    }
   1.336  
   1.337 -public:
   1.338 +  void verify_list();
   1.339 +
   1.340 +  HeapRegion* head() { return _head; }
   1.341 +  HeapRegion* tail() { return _tail; }
   1.342 +
   1.343 +  static void set_unrealistically_long_length(uint len);
   1.344 +
   1.345    // It adds hr to the list as the new head. The region should not be
   1.346    // a member of another set.
   1.347    inline void add_as_head(HeapRegion* hr);
   1.348 @@ -323,12 +247,12 @@
   1.349    // It moves the regions from from_list to this list and empties
   1.350    // from_list. The new regions will appear in the same order as they
   1.351    // were in from_list and be linked in the beginning of this list.
   1.352 -  void add_as_head(HeapRegionLinkedList* from_list);
   1.353 +  void add_as_head(FreeRegionList* from_list);
   1.354  
   1.355    // It moves the regions from from_list to this list and empties
   1.356    // from_list. The new regions will appear in the same order as they
   1.357    // were in from_list and be linked in the end of this list.
   1.358 -  void add_as_tail(HeapRegionLinkedList* from_list);
   1.359 +  void add_as_tail(FreeRegionList* from_list);
   1.360  
   1.361    // It empties the list by removing all regions from it.
   1.362    void remove_all();
   1.363 @@ -346,14 +270,12 @@
   1.364    virtual void print_on(outputStream* out, bool print_contents = false);
   1.365  };
   1.366  
   1.367 -//////////////////// HeapRegionLinkedListIterator ////////////////////
   1.368 -
   1.369  // Iterator class that provides a convenient way to iterate over the
   1.370  // regions of a HeapRegionLinkedList instance.
   1.371  
   1.372 -class HeapRegionLinkedListIterator : public StackObj {
   1.373 +class FreeRegionListIterator : public StackObj {
   1.374  private:
   1.375 -  HeapRegionLinkedList* _list;
   1.376 +  FreeRegionList* _list;
   1.377    HeapRegion*           _curr;
   1.378  
   1.379  public:
   1.380 @@ -369,12 +291,12 @@
   1.381      // do the "cycle" check.
   1.382  
   1.383      HeapRegion* hr = _curr;
   1.384 -    assert(_list->verify_region(hr, _list), "region verification");
   1.385 +    _list->verify_region(hr);
   1.386      _curr = hr->next();
   1.387      return hr;
   1.388    }
   1.389  
   1.390 -  HeapRegionLinkedListIterator(HeapRegionLinkedList* list)
   1.391 +  FreeRegionListIterator(FreeRegionList* list)
   1.392      : _curr(NULL), _list(list) {
   1.393      _curr = list->head();
   1.394    }

mercurial