src/share/vm/gc_implementation/g1/heapRegionSeq.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hs-gc-g1-assert Sdiff src/share/vm/gc_implementation/g1

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

Print this page




 107     uint index = length();
 108 
 109     assert(index < _max_length, "otherwise we cannot expand further");
 110     if (index == 0) {
 111       // We have not allocated any regions so far
 112       assert(next_bottom == _heap_bottom, "invariant");
 113     } else {
 114       // next_bottom should match the end of the last/previous region
 115       assert(next_bottom == at(index - 1)->end(), "invariant");
 116     }
 117 
 118     if (index == _allocated_length) {
 119       // We have to allocate a new HeapRegion.
 120       HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom);
 121       if (new_hr == NULL) {
 122         // allocation failed, we bail out and return what we have done so far
 123         return MemRegion(old_end, next_bottom);
 124       }
 125       assert(_regions[index] == NULL, "invariant");
 126       _regions[index] = new_hr;
 127       increment_length(&_allocated_length);
 128     }
 129     // Have to increment the length first, otherwise we will get an
 130     // assert failure at(index) below.
 131     increment_length(&_length);
 132     HeapRegion* hr = at(index);
 133     list->add_as_tail(hr);
 134 
 135     next_bottom = hr->end();
 136   }
 137   assert(next_bottom == new_end, "post-condition");
 138   return MemRegion(old_end, next_bottom);
 139 }
 140 
 141 uint HeapRegionSeq::free_suffix() {
 142   uint res = 0;
 143   uint index = length();
 144   while (index > 0) {
 145     index -= 1;
 146     if (!at(index)->is_empty()) {
 147       break;
 148     }
 149     res += 1;
 150   }
 151   return res;


 184     hr_index = hr->hrs_index();
 185   }
 186 
 187   uint len = length();
 188   for (uint i = hr_index; i < len; i += 1) {
 189     bool res = blk->doHeapRegion(at(i));
 190     if (res) {
 191       blk->incomplete();
 192       return;
 193     }
 194   }
 195   for (uint i = 0; i < hr_index; i += 1) {
 196     bool res = blk->doHeapRegion(at(i));
 197     if (res) {
 198       blk->incomplete();
 199       return;
 200     }
 201   }
 202 }
 203 
 204 MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes,
 205                                    uint* num_regions_deleted) {
 206   // Reset this in case it's currently pointing into the regions that
 207   // we just removed.
 208   _next_search_index = 0;
 209 
 210   assert(shrink_bytes % os::vm_page_size() == 0, "unaligned");
 211   assert(shrink_bytes % HeapRegion::GrainBytes == 0, "unaligned");
 212   assert(length() > 0, "the region sequence should not be empty");
 213   assert(length() <= _allocated_length, "invariant");
 214   assert(_allocated_length > 0, "we should have at least one region committed");

 215 
 216   // around the loop, i will be the next region to be removed
 217   uint i = length() - 1;
 218   assert(i > 0, "we should never remove all regions");
 219   // [last_start, end) is the MemRegion that covers the regions we will remove.
 220   HeapWord* end = at(i)->end();
 221   HeapWord* last_start = end;
 222   *num_regions_deleted = 0;
 223   while (shrink_bytes > 0) {
 224     HeapRegion* cur = at(i);
 225     // We should leave the humongous regions where they are.
 226     if (cur->isHumongous()) break;
 227     // We should stop shrinking if we come across a non-empty region.
 228     if (!cur->is_empty()) break;
 229 
 230     i -= 1;
 231     *num_regions_deleted += 1;
 232     shrink_bytes -= cur->capacity();
 233     last_start = cur->bottom();
 234     decrement_length(&_length);
 235     // We will reclaim the HeapRegion. _allocated_length should be
 236     // covering this index. So, even though we removed the region from
 237     // the active set by decreasing _length, we still have it
 238     // available in the future if we need to re-use it.
 239     assert(i > 0, "we should never remove all regions");
 240     assert(length() > 0, "we should never remove all regions");
 241   }
 242   return MemRegion(last_start, end);
 243 }
 244 
 245 #ifndef PRODUCT
 246 void HeapRegionSeq::verify_optional() {
 247   guarantee(_length <= _allocated_length,
 248             err_msg("invariant: _length: %u _allocated_length: %u",
 249                     _length, _allocated_length));
 250   guarantee(_allocated_length <= _max_length,
 251             err_msg("invariant: _allocated_length: %u _max_length: %u",
 252                     _allocated_length, _max_length));
 253   guarantee(_next_search_index <= _length,
 254             err_msg("invariant: _next_search_index: %u _length: %u",
 255                     _next_search_index, _length));
 256 
 257   HeapWord* prev_end = _heap_bottom;
 258   for (uint i = 0; i < _allocated_length; i += 1) {
 259     HeapRegion* hr = _regions[i];
 260     guarantee(hr != NULL, err_msg("invariant: i: %u", i));
 261     guarantee(hr->bottom() == prev_end,
 262               err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,




 107     uint index = length();
 108 
 109     assert(index < _max_length, "otherwise we cannot expand further");
 110     if (index == 0) {
 111       // We have not allocated any regions so far
 112       assert(next_bottom == _heap_bottom, "invariant");
 113     } else {
 114       // next_bottom should match the end of the last/previous region
 115       assert(next_bottom == at(index - 1)->end(), "invariant");
 116     }
 117 
 118     if (index == _allocated_length) {
 119       // We have to allocate a new HeapRegion.
 120       HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom);
 121       if (new_hr == NULL) {
 122         // allocation failed, we bail out and return what we have done so far
 123         return MemRegion(old_end, next_bottom);
 124       }
 125       assert(_regions[index] == NULL, "invariant");
 126       _regions[index] = new_hr;
 127       increment_allocated_length();
 128     }
 129     // Have to increment the length first, otherwise we will get an
 130     // assert failure at(index) below.
 131     increment_length();
 132     HeapRegion* hr = at(index);
 133     list->add_as_tail(hr);
 134 
 135     next_bottom = hr->end();
 136   }
 137   assert(next_bottom == new_end, "post-condition");
 138   return MemRegion(old_end, next_bottom);
 139 }
 140 
 141 uint HeapRegionSeq::free_suffix() {
 142   uint res = 0;
 143   uint index = length();
 144   while (index > 0) {
 145     index -= 1;
 146     if (!at(index)->is_empty()) {
 147       break;
 148     }
 149     res += 1;
 150   }
 151   return res;


 184     hr_index = hr->hrs_index();
 185   }
 186 
 187   uint len = length();
 188   for (uint i = hr_index; i < len; i += 1) {
 189     bool res = blk->doHeapRegion(at(i));
 190     if (res) {
 191       blk->incomplete();
 192       return;
 193     }
 194   }
 195   for (uint i = 0; i < hr_index; i += 1) {
 196     bool res = blk->doHeapRegion(at(i));
 197     if (res) {
 198       blk->incomplete();
 199       return;
 200     }
 201   }
 202 }
 203 
 204 uint HeapRegionSeq::shrink_by(uint num_regions_to_remove) {

 205   // Reset this in case it's currently pointing into the regions that
 206   // we just removed.
 207   _next_search_index = 0;
 208 


 209   assert(length() > 0, "the region sequence should not be empty");
 210   assert(length() <= _allocated_length, "invariant");
 211   assert(_allocated_length > 0, "we should have at least one region committed");
 212   assert(num_regions_to_remove < length(), "We should never remove all regions");
 213 
 214   uint i = 0;
 215   for (; i < num_regions_to_remove; i++) {
 216     HeapRegion* cur = at(length() - 1);
 217 
 218     if (!cur->is_empty()) {
 219       // We have to give up if the region can not be moved
 220       break;
 221   }
 222     assert(!cur->isHumongous(), "Humongous regions should not be empty");
 223 
 224     decrement_length();














 225   }
 226   return i;
 227 }
 228 
 229 #ifndef PRODUCT
 230 void HeapRegionSeq::verify_optional() {
 231   guarantee(_length <= _allocated_length,
 232             err_msg("invariant: _length: %u _allocated_length: %u",
 233                     _length, _allocated_length));
 234   guarantee(_allocated_length <= _max_length,
 235             err_msg("invariant: _allocated_length: %u _max_length: %u",
 236                     _allocated_length, _max_length));
 237   guarantee(_next_search_index <= _length,
 238             err_msg("invariant: _next_search_index: %u _length: %u",
 239                     _next_search_index, _length));
 240 
 241   HeapWord* prev_end = _heap_bottom;
 242   for (uint i = 0; i < _allocated_length; i += 1) {
 243     HeapRegion* hr = _regions[i];
 244     guarantee(hr != NULL, err_msg("invariant: i: %u", i));
 245     guarantee(hr->bottom() == prev_end,
 246               err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,


src/share/vm/gc_implementation/g1/heapRegionSeq.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File