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

changeset 6385
58fc1b1523dc
parent 3957
a2f7274eb6ef
child 6386
0d2ce7411240
     1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionSet.cpp	Thu Mar 06 11:11:04 2014 +0100
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.cpp	Fri Mar 14 10:15:46 2014 +0100
     1.3 @@ -23,171 +23,60 @@
     1.4   */
     1.5  
     1.6  #include "precompiled.hpp"
     1.7 +#include "gc_implementation/g1/heapRegionRemSet.hpp"
     1.8  #include "gc_implementation/g1/heapRegionSet.inline.hpp"
     1.9  
    1.10 -uint HeapRegionSetBase::_unrealistically_long_length = 0;
    1.11 -HRSPhase HeapRegionSetBase::_phase = HRSPhaseNone;
    1.12 -
    1.13 -//////////////////// HeapRegionSetBase ////////////////////
    1.14 -
    1.15 -void HeapRegionSetBase::set_unrealistically_long_length(uint len) {
    1.16 -  guarantee(_unrealistically_long_length == 0, "should only be set once");
    1.17 -  _unrealistically_long_length = len;
    1.18 -}
    1.19 +uint FreeRegionList::_unrealistically_long_length = 0;
    1.20  
    1.21  void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) {
    1.22 -  msg->append("[%s] %s ln: %u rn: %u cy: "SIZE_FORMAT" ud: "SIZE_FORMAT,
    1.23 -              name(), message, length(), region_num(),
    1.24 -              total_capacity_bytes(), total_used_bytes());
    1.25 +  msg->append("[%s] %s ln: %u cy: "SIZE_FORMAT,
    1.26 +              name(), message, length(), total_capacity_bytes());
    1.27    fill_in_ext_msg_extra(msg);
    1.28  }
    1.29  
    1.30 -bool HeapRegionSetBase::verify_region(HeapRegion* hr,
    1.31 -                                  HeapRegionSetBase* expected_containing_set) {
    1.32 -  const char* error_message = NULL;
    1.33 -
    1.34 -  if (!regions_humongous()) {
    1.35 -    if (hr->isHumongous()) {
    1.36 -      error_message = "the region should not be humongous";
    1.37 -    }
    1.38 -  } else {
    1.39 -    if (!hr->isHumongous() || !hr->startsHumongous()) {
    1.40 -      error_message = "the region should be 'starts humongous'";
    1.41 -    }
    1.42 -  }
    1.43 -
    1.44 -  if (!regions_empty()) {
    1.45 -    if (hr->is_empty()) {
    1.46 -      error_message = "the region should not be empty";
    1.47 -    }
    1.48 -  } else {
    1.49 -    if (!hr->is_empty()) {
    1.50 -      error_message = "the region should be empty";
    1.51 -    }
    1.52 -  }
    1.53 -
    1.54 -#ifdef ASSERT
    1.55 -  // The _containing_set field is only available when ASSERT is defined.
    1.56 -  if (hr->containing_set() != expected_containing_set) {
    1.57 -    error_message = "inconsistent containing set found";
    1.58 -  }
    1.59 -#endif // ASSERT
    1.60 -
    1.61 -  const char* extra_error_message = verify_region_extra(hr);
    1.62 -  if (extra_error_message != NULL) {
    1.63 -    error_message = extra_error_message;
    1.64 -  }
    1.65 -
    1.66 -  if (error_message != NULL) {
    1.67 -    outputStream* out = tty;
    1.68 -    out->cr();
    1.69 -    out->print_cr("## [%s] %s", name(), error_message);
    1.70 -    out->print_cr("## Offending Region: "PTR_FORMAT, hr);
    1.71 -    out->print_cr("   "HR_FORMAT, HR_FORMAT_PARAMS(hr));
    1.72 -#ifdef ASSERT
    1.73 -    out->print_cr("   containing set: "PTR_FORMAT, hr->containing_set());
    1.74 -#endif // ASSERT
    1.75 -    out->print_cr("## Offending Region Set: "PTR_FORMAT, this);
    1.76 -    print_on(out);
    1.77 -    return false;
    1.78 -  } else {
    1.79 -    return true;
    1.80 -  }
    1.81 +#ifndef PRODUCT
    1.82 +void HeapRegionSetBase::verify_region(HeapRegion* hr) {
    1.83 +  assert(hr->containing_set() == this, err_msg("Inconsistent containing set for %u", hr->hrs_index()));
    1.84 +  assert(!hr->is_young(), err_msg("Adding young region %u", hr->hrs_index())); // currently we don't use these sets for young regions
    1.85 +  assert(hr->isHumongous() == regions_humongous(), err_msg("Wrong humongous state for region %u and set %s", hr->hrs_index(), name()));
    1.86 +  assert(hr->is_empty() == regions_empty(), err_msg("Wrong empty state for region %u and set %s", hr->hrs_index(), name()));
    1.87 +  assert(hr->rem_set()->verify_ready_for_par_iteration(), err_msg("Wrong iteration state %u", hr->hrs_index()));
    1.88  }
    1.89 +#endif
    1.90  
    1.91  void HeapRegionSetBase::verify() {
    1.92    // It's important that we also observe the MT safety protocol even
    1.93    // for the verification calls. If we do verification without the
    1.94    // appropriate locks and the set changes underneath our feet
    1.95    // verification might fail and send us on a wild goose chase.
    1.96 -  hrs_assert_mt_safety_ok(this);
    1.97 +  check_mt_safety();
    1.98  
    1.99 -  guarantee(( is_empty() && length() == 0 && region_num() == 0 &&
   1.100 -              total_used_bytes() == 0 && total_capacity_bytes() == 0) ||
   1.101 -            (!is_empty() && length() >= 0 && region_num() >= 0 &&
   1.102 -              total_used_bytes() >= 0 && total_capacity_bytes() >= 0),
   1.103 -            hrs_ext_msg(this, "invariant"));
   1.104 -
   1.105 -  guarantee((!regions_humongous() && region_num() == length()) ||
   1.106 -            ( regions_humongous() && region_num() >= length()),
   1.107 -            hrs_ext_msg(this, "invariant"));
   1.108 -
   1.109 -  guarantee(!regions_empty() || total_used_bytes() == 0,
   1.110 -            hrs_ext_msg(this, "invariant"));
   1.111 -
   1.112 -  guarantee(total_used_bytes() <= total_capacity_bytes(),
   1.113 +  guarantee(( is_empty() && length() == 0 && total_capacity_bytes() == 0) ||
   1.114 +            (!is_empty() && length() >= 0 && total_capacity_bytes() >= 0),
   1.115              hrs_ext_msg(this, "invariant"));
   1.116  }
   1.117  
   1.118  void HeapRegionSetBase::verify_start() {
   1.119    // See comment in verify() about MT safety and verification.
   1.120 -  hrs_assert_mt_safety_ok(this);
   1.121 +  check_mt_safety();
   1.122    assert(!_verify_in_progress,
   1.123           hrs_ext_msg(this, "verification should not be in progress"));
   1.124  
   1.125    // Do the basic verification first before we do the checks over the regions.
   1.126    HeapRegionSetBase::verify();
   1.127  
   1.128 -  _calc_length               = 0;
   1.129 -  _calc_region_num           = 0;
   1.130 -  _calc_total_capacity_bytes = 0;
   1.131 -  _calc_total_used_bytes     = 0;
   1.132    _verify_in_progress        = true;
   1.133  }
   1.134  
   1.135 -void HeapRegionSetBase::verify_next_region(HeapRegion* hr) {
   1.136 -  // See comment in verify() about MT safety and verification.
   1.137 -  hrs_assert_mt_safety_ok(this);
   1.138 -  assert(_verify_in_progress,
   1.139 -         hrs_ext_msg(this, "verification should be in progress"));
   1.140 -
   1.141 -  guarantee(verify_region(hr, this), hrs_ext_msg(this, "region verification"));
   1.142 -
   1.143 -  _calc_length               += 1;
   1.144 -  _calc_region_num           += hr->region_num();
   1.145 -  _calc_total_capacity_bytes += hr->capacity();
   1.146 -  _calc_total_used_bytes     += hr->used();
   1.147 -}
   1.148 -
   1.149  void HeapRegionSetBase::verify_end() {
   1.150    // See comment in verify() about MT safety and verification.
   1.151 -  hrs_assert_mt_safety_ok(this);
   1.152 +  check_mt_safety();
   1.153    assert(_verify_in_progress,
   1.154           hrs_ext_msg(this, "verification should be in progress"));
   1.155  
   1.156 -  guarantee(length() == _calc_length,
   1.157 -            hrs_err_msg("[%s] length: %u should be == calc length: %u",
   1.158 -                        name(), length(), _calc_length));
   1.159 -
   1.160 -  guarantee(region_num() == _calc_region_num,
   1.161 -            hrs_err_msg("[%s] region num: %u should be == calc region num: %u",
   1.162 -                        name(), region_num(), _calc_region_num));
   1.163 -
   1.164 -  guarantee(total_capacity_bytes() == _calc_total_capacity_bytes,
   1.165 -            hrs_err_msg("[%s] capacity bytes: "SIZE_FORMAT" should be == "
   1.166 -                        "calc capacity bytes: "SIZE_FORMAT,
   1.167 -                        name(),
   1.168 -                        total_capacity_bytes(), _calc_total_capacity_bytes));
   1.169 -
   1.170 -  guarantee(total_used_bytes() == _calc_total_used_bytes,
   1.171 -            hrs_err_msg("[%s] used bytes: "SIZE_FORMAT" should be == "
   1.172 -                        "calc used bytes: "SIZE_FORMAT,
   1.173 -                        name(), total_used_bytes(), _calc_total_used_bytes));
   1.174 -
   1.175    _verify_in_progress = false;
   1.176  }
   1.177  
   1.178 -void HeapRegionSetBase::clear_phase() {
   1.179 -  assert(_phase != HRSPhaseNone, "pre-condition");
   1.180 -  _phase = HRSPhaseNone;
   1.181 -}
   1.182 -
   1.183 -void HeapRegionSetBase::set_phase(HRSPhase phase) {
   1.184 -  assert(_phase == HRSPhaseNone, "pre-condition");
   1.185 -  assert(phase != HRSPhaseNone, "pre-condition");
   1.186 -  _phase = phase;
   1.187 -}
   1.188 -
   1.189  void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) {
   1.190    out->cr();
   1.191    out->print_cr("Set: %s ("PTR_FORMAT")", name(), this);
   1.192 @@ -196,76 +85,38 @@
   1.193    out->print_cr("    empty             : %s", BOOL_TO_STR(regions_empty()));
   1.194    out->print_cr("  Attributes");
   1.195    out->print_cr("    length            : %14u", length());
   1.196 -  out->print_cr("    region num        : %14u", region_num());
   1.197    out->print_cr("    total capacity    : "SIZE_FORMAT_W(14)" bytes",
   1.198                  total_capacity_bytes());
   1.199 -  out->print_cr("    total used        : "SIZE_FORMAT_W(14)" bytes",
   1.200 -                total_used_bytes());
   1.201  }
   1.202  
   1.203 -void HeapRegionSetBase::clear() {
   1.204 -  _length           = 0;
   1.205 -  _region_num       = 0;
   1.206 -  _total_used_bytes = 0;
   1.207 +HeapRegionSetBase::HeapRegionSetBase(const char* name, bool humongous, bool empty, HRSMtSafeChecker* mt_safety_checker)
   1.208 +  : _name(name), _verify_in_progress(false),
   1.209 +    _is_humongous(humongous), _is_empty(empty), _mt_safety_checker(mt_safety_checker),
   1.210 +    _count()
   1.211 +{ }
   1.212 +
   1.213 +void FreeRegionList::set_unrealistically_long_length(uint len) {
   1.214 +  guarantee(_unrealistically_long_length == 0, "should only be set once");
   1.215 +  _unrealistically_long_length = len;
   1.216  }
   1.217  
   1.218 -HeapRegionSetBase::HeapRegionSetBase(const char* name)
   1.219 -  : _name(name), _verify_in_progress(false),
   1.220 -    _calc_length(0), _calc_region_num(0),
   1.221 -    _calc_total_capacity_bytes(0), _calc_total_used_bytes(0) { }
   1.222 -
   1.223 -//////////////////// HeapRegionSet ////////////////////
   1.224 -
   1.225 -void HeapRegionSet::update_from_proxy(HeapRegionSet* proxy_set) {
   1.226 -  hrs_assert_mt_safety_ok(this);
   1.227 -  hrs_assert_mt_safety_ok(proxy_set);
   1.228 -  hrs_assert_sets_match(this, proxy_set);
   1.229 -
   1.230 -  verify_optional();
   1.231 -  proxy_set->verify_optional();
   1.232 -
   1.233 -  if (proxy_set->is_empty()) return;
   1.234 -
   1.235 -  assert(proxy_set->length() <= _length,
   1.236 -         hrs_err_msg("[%s] proxy set length: %u should be <= length: %u",
   1.237 -                     name(), proxy_set->length(), _length));
   1.238 -  _length -= proxy_set->length();
   1.239 -
   1.240 -  assert(proxy_set->region_num() <= _region_num,
   1.241 -         hrs_err_msg("[%s] proxy set region num: %u should be <= region num: %u",
   1.242 -                     name(), proxy_set->region_num(), _region_num));
   1.243 -  _region_num -= proxy_set->region_num();
   1.244 -
   1.245 -  assert(proxy_set->total_used_bytes() <= _total_used_bytes,
   1.246 -         hrs_err_msg("[%s] proxy set used bytes: "SIZE_FORMAT" "
   1.247 -                     "should be <= used bytes: "SIZE_FORMAT,
   1.248 -                     name(), proxy_set->total_used_bytes(),
   1.249 -                     _total_used_bytes));
   1.250 -  _total_used_bytes -= proxy_set->total_used_bytes();
   1.251 -
   1.252 -  proxy_set->clear();
   1.253 -
   1.254 -  verify_optional();
   1.255 -  proxy_set->verify_optional();
   1.256 -}
   1.257 -
   1.258 -//////////////////// HeapRegionLinkedList ////////////////////
   1.259 -
   1.260 -void HeapRegionLinkedList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
   1.261 +void FreeRegionList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
   1.262    msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, head(), tail());
   1.263  }
   1.264  
   1.265 -void HeapRegionLinkedList::add_as_head(HeapRegionLinkedList* from_list) {
   1.266 -  hrs_assert_mt_safety_ok(this);
   1.267 -  hrs_assert_mt_safety_ok(from_list);
   1.268 +void FreeRegionList::add_as_head_or_tail(FreeRegionList* from_list, bool as_head) {
   1.269 +  check_mt_safety();
   1.270 +  from_list->check_mt_safety();
   1.271  
   1.272    verify_optional();
   1.273    from_list->verify_optional();
   1.274  
   1.275 -  if (from_list->is_empty()) return;
   1.276 +  if (from_list->is_empty()) {
   1.277 +    return;
   1.278 +  }
   1.279  
   1.280  #ifdef ASSERT
   1.281 -  HeapRegionLinkedListIterator iter(from_list);
   1.282 +  FreeRegionListIterator iter(from_list);
   1.283    while (iter.more_available()) {
   1.284      HeapRegion* hr = iter.get_next();
   1.285      // In set_containing_set() we check that we either set the value
   1.286 @@ -276,70 +127,43 @@
   1.287    }
   1.288  #endif // ASSERT
   1.289  
   1.290 -  if (_head != NULL) {
   1.291 -    assert(length() >  0 && _tail != NULL, hrs_ext_msg(this, "invariant"));
   1.292 -    from_list->_tail->set_next(_head);
   1.293 +  if (_head == NULL) {
   1.294 +    assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant"));
   1.295 +    _head = from_list->_head;
   1.296 +    _tail = from_list->_tail;
   1.297    } else {
   1.298 -    assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant"));
   1.299 -    _tail = from_list->_tail;
   1.300 +    assert(length() > 0 && _tail != NULL, hrs_ext_msg(this, "invariant"));
   1.301 +    if (as_head) {
   1.302 +      from_list->_tail->set_next(_head);
   1.303 +      _head = from_list->_head;
   1.304 +    } else {
   1.305 +      _tail->set_next(from_list->_head);
   1.306 +      _tail = from_list->_tail;
   1.307 +    }
   1.308    }
   1.309 -  _head = from_list->_head;
   1.310  
   1.311 -  _length           += from_list->length();
   1.312 -  _region_num       += from_list->region_num();
   1.313 -  _total_used_bytes += from_list->total_used_bytes();
   1.314 +  _count.increment(from_list->length(), from_list->total_capacity_bytes());
   1.315    from_list->clear();
   1.316  
   1.317    verify_optional();
   1.318    from_list->verify_optional();
   1.319  }
   1.320  
   1.321 -void HeapRegionLinkedList::add_as_tail(HeapRegionLinkedList* from_list) {
   1.322 -  hrs_assert_mt_safety_ok(this);
   1.323 -  hrs_assert_mt_safety_ok(from_list);
   1.324 -
   1.325 -  verify_optional();
   1.326 -  from_list->verify_optional();
   1.327 -
   1.328 -  if (from_list->is_empty()) return;
   1.329 -
   1.330 -#ifdef ASSERT
   1.331 -  HeapRegionLinkedListIterator iter(from_list);
   1.332 -  while (iter.more_available()) {
   1.333 -    HeapRegion* hr = iter.get_next();
   1.334 -    // In set_containing_set() we check that we either set the value
   1.335 -    // from NULL to non-NULL or vice versa to catch bugs. So, we have
   1.336 -    // to NULL it first before setting it to the value.
   1.337 -    hr->set_containing_set(NULL);
   1.338 -    hr->set_containing_set(this);
   1.339 -  }
   1.340 -#endif // ASSERT
   1.341 -
   1.342 -  if (_tail != NULL) {
   1.343 -    assert(length() >  0 && _head != NULL, hrs_ext_msg(this, "invariant"));
   1.344 -    _tail->set_next(from_list->_head);
   1.345 -  } else {
   1.346 -    assert(length() == 0 && _head == NULL, hrs_ext_msg(this, "invariant"));
   1.347 -    _head = from_list->_head;
   1.348 -  }
   1.349 -  _tail = from_list->_tail;
   1.350 -
   1.351 -  _length           += from_list->length();
   1.352 -  _region_num       += from_list->region_num();
   1.353 -  _total_used_bytes += from_list->total_used_bytes();
   1.354 -  from_list->clear();
   1.355 -
   1.356 -  verify_optional();
   1.357 -  from_list->verify_optional();
   1.358 +void FreeRegionList::add_as_head(FreeRegionList* from_list) {
   1.359 +  add_as_head_or_tail(from_list, true /* as_head */);
   1.360  }
   1.361  
   1.362 -void HeapRegionLinkedList::remove_all() {
   1.363 -  hrs_assert_mt_safety_ok(this);
   1.364 +void FreeRegionList::add_as_tail(FreeRegionList* from_list) {
   1.365 +  add_as_head_or_tail(from_list, false /* as_head */);
   1.366 +}
   1.367 +
   1.368 +void FreeRegionList::remove_all() {
   1.369 +  check_mt_safety();
   1.370    verify_optional();
   1.371  
   1.372    HeapRegion* curr = _head;
   1.373    while (curr != NULL) {
   1.374 -    hrs_assert_region_ok(this, curr, this);
   1.375 +    verify_region(curr);
   1.376  
   1.377      HeapRegion* next = curr->next();
   1.378      curr->set_next(NULL);
   1.379 @@ -351,8 +175,8 @@
   1.380    verify_optional();
   1.381  }
   1.382  
   1.383 -void HeapRegionLinkedList::remove_all_pending(uint target_count) {
   1.384 -  hrs_assert_mt_safety_ok(this);
   1.385 +void FreeRegionList::remove_all_pending(uint target_count) {
   1.386 +  check_mt_safety();
   1.387    assert(target_count > 1, hrs_ext_msg(this, "pre-condition"));
   1.388    assert(!is_empty(), hrs_ext_msg(this, "pre-condition"));
   1.389  
   1.390 @@ -363,7 +187,7 @@
   1.391    HeapRegion* prev = NULL;
   1.392    uint count = 0;
   1.393    while (curr != NULL) {
   1.394 -    hrs_assert_region_ok(this, curr, this);
   1.395 +    verify_region(curr);
   1.396      HeapRegion* next = curr->next();
   1.397  
   1.398      if (curr->pending_removal()) {
   1.399 @@ -387,7 +211,7 @@
   1.400        }
   1.401  
   1.402        curr->set_next(NULL);
   1.403 -      remove_internal(curr);
   1.404 +      remove(curr);
   1.405        curr->set_pending_removal(false);
   1.406  
   1.407        count += 1;
   1.408 @@ -414,46 +238,26 @@
   1.409    verify_optional();
   1.410  }
   1.411  
   1.412 -void HeapRegionLinkedList::verify() {
   1.413 +void FreeRegionList::verify() {
   1.414    // See comment in HeapRegionSetBase::verify() about MT safety and
   1.415    // verification.
   1.416 -  hrs_assert_mt_safety_ok(this);
   1.417 +  check_mt_safety();
   1.418  
   1.419    // This will also do the basic verification too.
   1.420    verify_start();
   1.421  
   1.422 -  HeapRegion* curr  = _head;
   1.423 -  HeapRegion* prev1 = NULL;
   1.424 -  HeapRegion* prev0 = NULL;
   1.425 -  uint        count = 0;
   1.426 -  while (curr != NULL) {
   1.427 -    verify_next_region(curr);
   1.428 -
   1.429 -    count += 1;
   1.430 -    guarantee(count < _unrealistically_long_length,
   1.431 -              hrs_err_msg("[%s] the calculated length: %u "
   1.432 -                          "seems very long, is there maybe a cycle? "
   1.433 -                          "curr: "PTR_FORMAT" prev0: "PTR_FORMAT" "
   1.434 -                          "prev1: "PTR_FORMAT" length: %u",
   1.435 -                          name(), count, curr, prev0, prev1, length()));
   1.436 -
   1.437 -    prev1 = prev0;
   1.438 -    prev0 = curr;
   1.439 -    curr  = curr->next();
   1.440 -  }
   1.441 -
   1.442 -  guarantee(_tail == prev0, hrs_ext_msg(this, "post-condition"));
   1.443 +  verify_list();
   1.444  
   1.445    verify_end();
   1.446  }
   1.447  
   1.448 -void HeapRegionLinkedList::clear() {
   1.449 -  HeapRegionSetBase::clear();
   1.450 +void FreeRegionList::clear() {
   1.451 +  _count = HeapRegionSetCount();
   1.452    _head = NULL;
   1.453    _tail = NULL;
   1.454  }
   1.455  
   1.456 -void HeapRegionLinkedList::print_on(outputStream* out, bool print_contents) {
   1.457 +void FreeRegionList::print_on(outputStream* out, bool print_contents) {
   1.458    HeapRegionSetBase::print_on(out, print_contents);
   1.459    out->print_cr("  Linking");
   1.460    out->print_cr("    head              : "PTR_FORMAT, _head);
   1.461 @@ -461,7 +265,7 @@
   1.462  
   1.463    if (print_contents) {
   1.464      out->print_cr("  Contents");
   1.465 -    HeapRegionLinkedListIterator iter(this);
   1.466 +    FreeRegionListIterator iter(this);
   1.467      while (iter.more_available()) {
   1.468        HeapRegion* hr = iter.get_next();
   1.469        hr->print_on(out);

mercurial