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

changeset 7050
6701abbc4441
parent 6680
78bbf4d43a14
child 7051
1f1d373cd044
     1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionSet.cpp	Tue Aug 19 12:39:06 2014 +0200
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.cpp	Tue Aug 19 10:50:27 2014 +0200
     1.3 @@ -23,6 +23,7 @@
     1.4   */
     1.5  
     1.6  #include "precompiled.hpp"
     1.7 +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
     1.8  #include "gc_implementation/g1/heapRegionRemSet.hpp"
     1.9  #include "gc_implementation/g1/heapRegionSet.inline.hpp"
    1.10  
    1.11 @@ -67,7 +68,7 @@
    1.12    // Do the basic verification first before we do the checks over the regions.
    1.13    HeapRegionSetBase::verify();
    1.14  
    1.15 -  _verify_in_progress        = true;
    1.16 +  _verify_in_progress = true;
    1.17  }
    1.18  
    1.19  void HeapRegionSetBase::verify_end() {
    1.20 @@ -103,62 +104,7 @@
    1.21  }
    1.22  
    1.23  void FreeRegionList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
    1.24 -  msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, head(), tail());
    1.25 -}
    1.26 -
    1.27 -void FreeRegionList::add_as_head_or_tail(FreeRegionList* from_list, bool as_head) {
    1.28 -  check_mt_safety();
    1.29 -  from_list->check_mt_safety();
    1.30 -
    1.31 -  verify_optional();
    1.32 -  from_list->verify_optional();
    1.33 -
    1.34 -  if (from_list->is_empty()) {
    1.35 -    return;
    1.36 -  }
    1.37 -
    1.38 -#ifdef ASSERT
    1.39 -  FreeRegionListIterator iter(from_list);
    1.40 -  while (iter.more_available()) {
    1.41 -    HeapRegion* hr = iter.get_next();
    1.42 -    // In set_containing_set() we check that we either set the value
    1.43 -    // from NULL to non-NULL or vice versa to catch bugs. So, we have
    1.44 -    // to NULL it first before setting it to the value.
    1.45 -    hr->set_containing_set(NULL);
    1.46 -    hr->set_containing_set(this);
    1.47 -  }
    1.48 -#endif // ASSERT
    1.49 -
    1.50 -  if (_head == NULL) {
    1.51 -    assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant"));
    1.52 -    _head = from_list->_head;
    1.53 -    _tail = from_list->_tail;
    1.54 -  } else {
    1.55 -    assert(length() > 0 && _tail != NULL, hrs_ext_msg(this, "invariant"));
    1.56 -    if (as_head) {
    1.57 -      from_list->_tail->set_next(_head);
    1.58 -      _head->set_prev(from_list->_tail);
    1.59 -      _head = from_list->_head;
    1.60 -    } else {
    1.61 -      _tail->set_next(from_list->_head);
    1.62 -      from_list->_head->set_prev(_tail);
    1.63 -      _tail = from_list->_tail;
    1.64 -    }
    1.65 -  }
    1.66 -
    1.67 -  _count.increment(from_list->length(), from_list->total_capacity_bytes());
    1.68 -  from_list->clear();
    1.69 -
    1.70 -  verify_optional();
    1.71 -  from_list->verify_optional();
    1.72 -}
    1.73 -
    1.74 -void FreeRegionList::add_as_head(FreeRegionList* from_list) {
    1.75 -  add_as_head_or_tail(from_list, true /* as_head */);
    1.76 -}
    1.77 -
    1.78 -void FreeRegionList::add_as_tail(FreeRegionList* from_list) {
    1.79 -  add_as_head_or_tail(from_list, false /* as_head */);
    1.80 +  msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, _head, _tail);
    1.81  }
    1.82  
    1.83  void FreeRegionList::remove_all() {
    1.84 @@ -191,11 +137,6 @@
    1.85      return;
    1.86    }
    1.87  
    1.88 -  if (is_empty()) {
    1.89 -    add_as_head(from_list);
    1.90 -    return;
    1.91 -  }
    1.92 -
    1.93    #ifdef ASSERT
    1.94    FreeRegionListIterator iter(from_list);
    1.95    while (iter.more_available()) {
    1.96 @@ -208,39 +149,45 @@
    1.97    }
    1.98    #endif // ASSERT
    1.99  
   1.100 -  HeapRegion* curr_to = _head;
   1.101 -  HeapRegion* curr_from = from_list->_head;
   1.102 +  if (is_empty()) {
   1.103 +    assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant"));
   1.104 +    _head = from_list->_head;
   1.105 +    _tail = from_list->_tail;
   1.106 +  } else {
   1.107 +    HeapRegion* curr_to = _head;
   1.108 +    HeapRegion* curr_from = from_list->_head;
   1.109  
   1.110 -  while (curr_from != NULL) {
   1.111 -    while (curr_to != NULL && curr_to->hrs_index() < curr_from->hrs_index()) {
   1.112 -      curr_to = curr_to->next();
   1.113 +    while (curr_from != NULL) {
   1.114 +      while (curr_to != NULL && curr_to->hrs_index() < curr_from->hrs_index()) {
   1.115 +        curr_to = curr_to->next();
   1.116 +      }
   1.117 +
   1.118 +      if (curr_to == NULL) {
   1.119 +        // The rest of the from list should be added as tail
   1.120 +        _tail->set_next(curr_from);
   1.121 +        curr_from->set_prev(_tail);
   1.122 +        curr_from = NULL;
   1.123 +      } else {
   1.124 +        HeapRegion* next_from = curr_from->next();
   1.125 +
   1.126 +        curr_from->set_next(curr_to);
   1.127 +        curr_from->set_prev(curr_to->prev());
   1.128 +        if (curr_to->prev() == NULL) {
   1.129 +          _head = curr_from;
   1.130 +        } else {
   1.131 +          curr_to->prev()->set_next(curr_from);
   1.132 +        }
   1.133 +        curr_to->set_prev(curr_from);
   1.134 +
   1.135 +        curr_from = next_from;
   1.136 +      }
   1.137      }
   1.138  
   1.139 -    if (curr_to == NULL) {
   1.140 -      // The rest of the from list should be added as tail
   1.141 -      _tail->set_next(curr_from);
   1.142 -      curr_from->set_prev(_tail);
   1.143 -      curr_from = NULL;
   1.144 -    } else {
   1.145 -      HeapRegion* next_from = curr_from->next();
   1.146 -
   1.147 -      curr_from->set_next(curr_to);
   1.148 -      curr_from->set_prev(curr_to->prev());
   1.149 -      if (curr_to->prev() == NULL) {
   1.150 -        _head = curr_from;
   1.151 -      } else {
   1.152 -        curr_to->prev()->set_next(curr_from);
   1.153 -      }
   1.154 -      curr_to->set_prev(curr_from);
   1.155 -
   1.156 -      curr_from = next_from;
   1.157 +    if (_tail->hrs_index() < from_list->_tail->hrs_index()) {
   1.158 +      _tail = from_list->_tail;
   1.159      }
   1.160    }
   1.161  
   1.162 -  if (_tail->hrs_index() < from_list->_tail->hrs_index()) {
   1.163 -    _tail = from_list->_tail;
   1.164 -  }
   1.165 -
   1.166    _count.increment(from_list->length(), from_list->total_capacity_bytes());
   1.167    from_list->clear();
   1.168  
   1.169 @@ -248,68 +195,59 @@
   1.170    from_list->verify_optional();
   1.171  }
   1.172  
   1.173 -void FreeRegionList::remove_all_pending(uint target_count) {
   1.174 +void FreeRegionList::remove_starting_at(HeapRegion* first, uint num_regions) {
   1.175    check_mt_safety();
   1.176 -  assert(target_count > 1, hrs_ext_msg(this, "pre-condition"));
   1.177 +  assert(num_regions >= 1, hrs_ext_msg(this, "pre-condition"));
   1.178    assert(!is_empty(), hrs_ext_msg(this, "pre-condition"));
   1.179  
   1.180    verify_optional();
   1.181    DEBUG_ONLY(uint old_length = length();)
   1.182  
   1.183 -  HeapRegion* curr = _head;
   1.184 +  HeapRegion* curr = first;
   1.185    uint count = 0;
   1.186 -  while (curr != NULL) {
   1.187 +  while (count < num_regions) {
   1.188      verify_region(curr);
   1.189      HeapRegion* next = curr->next();
   1.190      HeapRegion* prev = curr->prev();
   1.191  
   1.192 -    if (curr->pending_removal()) {
   1.193 -      assert(count < target_count,
   1.194 -             hrs_err_msg("[%s] should not come across more regions "
   1.195 -                         "pending for removal than target_count: %u",
   1.196 -                         name(), target_count));
   1.197 +    assert(count < num_regions,
   1.198 +           hrs_err_msg("[%s] should not come across more regions "
   1.199 +                       "pending for removal than num_regions: %u",
   1.200 +                       name(), num_regions));
   1.201  
   1.202 -      if (prev == NULL) {
   1.203 -        assert(_head == curr, hrs_ext_msg(this, "invariant"));
   1.204 -        _head = next;
   1.205 -      } else {
   1.206 -        assert(_head != curr, hrs_ext_msg(this, "invariant"));
   1.207 -        prev->set_next(next);
   1.208 -      }
   1.209 -      if (next == NULL) {
   1.210 -        assert(_tail == curr, hrs_ext_msg(this, "invariant"));
   1.211 -        _tail = prev;
   1.212 -      } else {
   1.213 -        assert(_tail != curr, hrs_ext_msg(this, "invariant"));
   1.214 -        next->set_prev(prev);
   1.215 -      }
   1.216 -      if (_last = curr) {
   1.217 -        _last = NULL;
   1.218 -      }
   1.219 +    if (prev == NULL) {
   1.220 +      assert(_head == curr, hrs_ext_msg(this, "invariant"));
   1.221 +      _head = next;
   1.222 +    } else {
   1.223 +      assert(_head != curr, hrs_ext_msg(this, "invariant"));
   1.224 +      prev->set_next(next);
   1.225 +    }
   1.226 +    if (next == NULL) {
   1.227 +      assert(_tail == curr, hrs_ext_msg(this, "invariant"));
   1.228 +      _tail = prev;
   1.229 +    } else {
   1.230 +      assert(_tail != curr, hrs_ext_msg(this, "invariant"));
   1.231 +      next->set_prev(prev);
   1.232 +    }
   1.233 +    if (_last = curr) {
   1.234 +      _last = NULL;
   1.235 +    }
   1.236  
   1.237 -      curr->set_next(NULL);
   1.238 -      curr->set_prev(NULL);
   1.239 -      remove(curr);
   1.240 -      curr->set_pending_removal(false);
   1.241 +    curr->set_next(NULL);
   1.242 +    curr->set_prev(NULL);
   1.243 +    remove(curr);
   1.244  
   1.245 -      count += 1;
   1.246 -
   1.247 -      // If we have come across the target number of regions we can
   1.248 -      // just bail out. However, for debugging purposes, we can just
   1.249 -      // carry on iterating to make sure there are not more regions
   1.250 -      // tagged with pending removal.
   1.251 -      DEBUG_ONLY(if (count == target_count) break;)
   1.252 -    }
   1.253 +    count++;
   1.254      curr = next;
   1.255    }
   1.256  
   1.257 -  assert(count == target_count,
   1.258 -         hrs_err_msg("[%s] count: %u should be == target_count: %u",
   1.259 -                     name(), count, target_count));
   1.260 -  assert(length() + target_count == old_length,
   1.261 +  assert(count == num_regions,
   1.262 +         hrs_err_msg("[%s] count: %u should be == num_regions: %u",
   1.263 +                     name(), count, num_regions));
   1.264 +  assert(length() + num_regions == old_length,
   1.265           hrs_err_msg("[%s] new length should be consistent "
   1.266 -                     "new length: %u old length: %u target_count: %u",
   1.267 -                     name(), length(), old_length, target_count));
   1.268 +                     "new length: %u old length: %u num_regions: %u",
   1.269 +                     name(), length(), old_length, num_regions));
   1.270  
   1.271    verify_optional();
   1.272  }
   1.273 @@ -348,10 +286,12 @@
   1.274        hr->print_on(out);
   1.275      }
   1.276    }
   1.277 +
   1.278 +  out->cr();
   1.279  }
   1.280  
   1.281  void FreeRegionList::verify_list() {
   1.282 -  HeapRegion* curr = head();
   1.283 +  HeapRegion* curr = _head;
   1.284    HeapRegion* prev1 = NULL;
   1.285    HeapRegion* prev0 = NULL;
   1.286    uint count = 0;
   1.287 @@ -379,7 +319,7 @@
   1.288      curr = curr->next();
   1.289    }
   1.290  
   1.291 -  guarantee(tail() == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), tail()->hrs_index(), prev0->hrs_index()));
   1.292 +  guarantee(_tail == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), _tail->hrs_index(), prev0->hrs_index()));
   1.293    guarantee(_tail == NULL || _tail->next() == NULL, "_tail should not have a next");
   1.294    guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count));
   1.295    guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,

mercurial