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

changeset 5074
b0d20fa374b4
parent 3900
d2a62e0f25eb
child 5773
a19bea467577
     1.1 --- a/src/share/vm/gc_implementation/g1/heapRegionSeq.cpp	Mon May 06 17:19:42 2013 +0200
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSeq.cpp	Mon May 06 21:30:34 2013 +0200
     1.3 @@ -124,11 +124,11 @@
     1.4        }
     1.5        assert(_regions[index] == NULL, "invariant");
     1.6        _regions[index] = new_hr;
     1.7 -      increment_length(&_allocated_length);
     1.8 +      increment_allocated_length();
     1.9      }
    1.10      // Have to increment the length first, otherwise we will get an
    1.11      // assert failure at(index) below.
    1.12 -    increment_length(&_length);
    1.13 +    increment_length();
    1.14      HeapRegion* hr = at(index);
    1.15      list->add_as_tail(hr);
    1.16  
    1.17 @@ -201,45 +201,29 @@
    1.18    }
    1.19  }
    1.20  
    1.21 -MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes,
    1.22 -                                   uint* num_regions_deleted) {
    1.23 +uint HeapRegionSeq::shrink_by(uint num_regions_to_remove) {
    1.24    // Reset this in case it's currently pointing into the regions that
    1.25    // we just removed.
    1.26    _next_search_index = 0;
    1.27  
    1.28 -  assert(shrink_bytes % os::vm_page_size() == 0, "unaligned");
    1.29 -  assert(shrink_bytes % HeapRegion::GrainBytes == 0, "unaligned");
    1.30    assert(length() > 0, "the region sequence should not be empty");
    1.31    assert(length() <= _allocated_length, "invariant");
    1.32    assert(_allocated_length > 0, "we should have at least one region committed");
    1.33 +  assert(num_regions_to_remove < length(), "We should never remove all regions");
    1.34  
    1.35 -  // around the loop, i will be the next region to be removed
    1.36 -  uint i = length() - 1;
    1.37 -  assert(i > 0, "we should never remove all regions");
    1.38 -  // [last_start, end) is the MemRegion that covers the regions we will remove.
    1.39 -  HeapWord* end = at(i)->end();
    1.40 -  HeapWord* last_start = end;
    1.41 -  *num_regions_deleted = 0;
    1.42 -  while (shrink_bytes > 0) {
    1.43 -    HeapRegion* cur = at(i);
    1.44 -    // We should leave the humongous regions where they are.
    1.45 -    if (cur->isHumongous()) break;
    1.46 -    // We should stop shrinking if we come across a non-empty region.
    1.47 -    if (!cur->is_empty()) break;
    1.48 +  uint i = 0;
    1.49 +  for (; i < num_regions_to_remove; i++) {
    1.50 +    HeapRegion* cur = at(length() - 1);
    1.51  
    1.52 -    i -= 1;
    1.53 -    *num_regions_deleted += 1;
    1.54 -    shrink_bytes -= cur->capacity();
    1.55 -    last_start = cur->bottom();
    1.56 -    decrement_length(&_length);
    1.57 -    // We will reclaim the HeapRegion. _allocated_length should be
    1.58 -    // covering this index. So, even though we removed the region from
    1.59 -    // the active set by decreasing _length, we still have it
    1.60 -    // available in the future if we need to re-use it.
    1.61 -    assert(i > 0, "we should never remove all regions");
    1.62 -    assert(length() > 0, "we should never remove all regions");
    1.63 +    if (!cur->is_empty()) {
    1.64 +      // We have to give up if the region can not be moved
    1.65 +      break;
    1.66    }
    1.67 -  return MemRegion(last_start, end);
    1.68 +    assert(!cur->isHumongous(), "Humongous regions should not be empty");
    1.69 +
    1.70 +    decrement_length();
    1.71 +  }
    1.72 +  return i;
    1.73  }
    1.74  
    1.75  #ifndef PRODUCT

mercurial