Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/g1/heapRegionSeq.cpp @ 10242:b0d20fa374b4
8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
Summary: Refactored shrink_by() to only use region counts and not byte sizes
Reviewed-by: johnc, tschatzl
author | brutisso |
---|---|
date | Mon, 06 May 2013 21:30:34 +0200 |
parents | d2a62e0f25eb |
children | a19bea467577 |
comparison
equal
deleted
inserted
replaced
10241:d17700c82d7d | 10242:b0d20fa374b4 |
---|---|
122 // allocation failed, we bail out and return what we have done so far | 122 // allocation failed, we bail out and return what we have done so far |
123 return MemRegion(old_end, next_bottom); | 123 return MemRegion(old_end, next_bottom); |
124 } | 124 } |
125 assert(_regions[index] == NULL, "invariant"); | 125 assert(_regions[index] == NULL, "invariant"); |
126 _regions[index] = new_hr; | 126 _regions[index] = new_hr; |
127 increment_length(&_allocated_length); | 127 increment_allocated_length(); |
128 } | 128 } |
129 // Have to increment the length first, otherwise we will get an | 129 // Have to increment the length first, otherwise we will get an |
130 // assert failure at(index) below. | 130 // assert failure at(index) below. |
131 increment_length(&_length); | 131 increment_length(); |
132 HeapRegion* hr = at(index); | 132 HeapRegion* hr = at(index); |
133 list->add_as_tail(hr); | 133 list->add_as_tail(hr); |
134 | 134 |
135 next_bottom = hr->end(); | 135 next_bottom = hr->end(); |
136 } | 136 } |
199 return; | 199 return; |
200 } | 200 } |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes, | 204 uint HeapRegionSeq::shrink_by(uint num_regions_to_remove) { |
205 uint* num_regions_deleted) { | |
206 // Reset this in case it's currently pointing into the regions that | 205 // Reset this in case it's currently pointing into the regions that |
207 // we just removed. | 206 // we just removed. |
208 _next_search_index = 0; | 207 _next_search_index = 0; |
209 | 208 |
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"); | 209 assert(length() > 0, "the region sequence should not be empty"); |
213 assert(length() <= _allocated_length, "invariant"); | 210 assert(length() <= _allocated_length, "invariant"); |
214 assert(_allocated_length > 0, "we should have at least one region committed"); | 211 assert(_allocated_length > 0, "we should have at least one region committed"); |
215 | 212 assert(num_regions_to_remove < length(), "We should never remove all regions"); |
216 // around the loop, i will be the next region to be removed | 213 |
217 uint i = length() - 1; | 214 uint i = 0; |
218 assert(i > 0, "we should never remove all regions"); | 215 for (; i < num_regions_to_remove; i++) { |
219 // [last_start, end) is the MemRegion that covers the regions we will remove. | 216 HeapRegion* cur = at(length() - 1); |
220 HeapWord* end = at(i)->end(); | 217 |
221 HeapWord* last_start = end; | 218 if (!cur->is_empty()) { |
222 *num_regions_deleted = 0; | 219 // We have to give up if the region can not be moved |
223 while (shrink_bytes > 0) { | 220 break; |
224 HeapRegion* cur = at(i); | 221 } |
225 // We should leave the humongous regions where they are. | 222 assert(!cur->isHumongous(), "Humongous regions should not be empty"); |
226 if (cur->isHumongous()) break; | 223 |
227 // We should stop shrinking if we come across a non-empty region. | 224 decrement_length(); |
228 if (!cur->is_empty()) break; | 225 } |
229 | 226 return i; |
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 } | 227 } |
244 | 228 |
245 #ifndef PRODUCT | 229 #ifndef PRODUCT |
246 void HeapRegionSeq::verify_optional() { | 230 void HeapRegionSeq::verify_optional() { |
247 guarantee(_length <= _allocated_length, | 231 guarantee(_length <= _allocated_length, |