comparison src/share/vm/gc_implementation/g1/heapRegionSeq.cpp @ 12305:a19bea467577

7163191: G1: introduce a "heap spanning table" abstraction Summary: Add G1BiasedArray<T> that is an array where each element represents a fixed-sized subdivision of the heap. Use this abstraction to refactor the HeapRegionSeq class. Reviewed-by: brutisso
author tschatzl
date Wed, 25 Sep 2013 13:25:24 +0200
parents b0d20fa374b4
children de6a9e811145
comparison
equal deleted inserted replaced
12304:10cc3b624f8f 12305:a19bea467577
69 } 69 }
70 } 70 }
71 71
72 // Public 72 // Public
73 73
74 void HeapRegionSeq::initialize(HeapWord* bottom, HeapWord* end, 74 void HeapRegionSeq::initialize(HeapWord* bottom, HeapWord* end) {
75 uint max_length) {
76 assert((uintptr_t) bottom % HeapRegion::GrainBytes == 0, 75 assert((uintptr_t) bottom % HeapRegion::GrainBytes == 0,
77 "bottom should be heap region aligned"); 76 "bottom should be heap region aligned");
78 assert((uintptr_t) end % HeapRegion::GrainBytes == 0, 77 assert((uintptr_t) end % HeapRegion::GrainBytes == 0,
79 "end should be heap region aligned"); 78 "end should be heap region aligned");
80 79
81 _length = 0;
82 _heap_bottom = bottom;
83 _heap_end = end;
84 _region_shift = HeapRegion::LogOfHRGrainBytes;
85 _next_search_index = 0; 80 _next_search_index = 0;
86 _allocated_length = 0; 81 _allocated_length = 0;
87 _max_length = max_length; 82
88 83 _regions.initialize(bottom, end, HeapRegion::GrainBytes);
89 _regions = NEW_C_HEAP_ARRAY(HeapRegion*, max_length, mtGC);
90 memset(_regions, 0, (size_t) max_length * sizeof(HeapRegion*));
91 _regions_biased = _regions - ((uintx) bottom >> _region_shift);
92
93 assert(&_regions[0] == &_regions_biased[addr_to_index_biased(bottom)],
94 "bottom should be included in the region with index 0");
95 } 84 }
96 85
97 MemRegion HeapRegionSeq::expand_by(HeapWord* old_end, 86 MemRegion HeapRegionSeq::expand_by(HeapWord* old_end,
98 HeapWord* new_end, 87 HeapWord* new_end,
99 FreeRegionList* list) { 88 FreeRegionList* list) {
100 assert(old_end < new_end, "don't call it otherwise"); 89 assert(old_end < new_end, "don't call it otherwise");
101 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 90 G1CollectedHeap* g1h = G1CollectedHeap::heap();
102 91
103 HeapWord* next_bottom = old_end; 92 HeapWord* next_bottom = old_end;
104 assert(_heap_bottom <= next_bottom, "invariant"); 93 assert(heap_bottom() <= next_bottom, "invariant");
105 while (next_bottom < new_end) { 94 while (next_bottom < new_end) {
106 assert(next_bottom < _heap_end, "invariant"); 95 assert(next_bottom < heap_end(), "invariant");
107 uint index = length(); 96 uint index = length();
108 97
109 assert(index < _max_length, "otherwise we cannot expand further"); 98 assert(index < max_length(), "otherwise we cannot expand further");
110 if (index == 0) { 99 if (index == 0) {
111 // We have not allocated any regions so far 100 // We have not allocated any regions so far
112 assert(next_bottom == _heap_bottom, "invariant"); 101 assert(next_bottom == heap_bottom(), "invariant");
113 } else { 102 } else {
114 // next_bottom should match the end of the last/previous region 103 // next_bottom should match the end of the last/previous region
115 assert(next_bottom == at(index - 1)->end(), "invariant"); 104 assert(next_bottom == at(index - 1)->end(), "invariant");
116 } 105 }
117 106
120 HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom); 109 HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom);
121 if (new_hr == NULL) { 110 if (new_hr == NULL) {
122 // allocation failed, we bail out and return what we have done so far 111 // allocation failed, we bail out and return what we have done so far
123 return MemRegion(old_end, next_bottom); 112 return MemRegion(old_end, next_bottom);
124 } 113 }
125 assert(_regions[index] == NULL, "invariant"); 114 assert(_regions.get_by_index(index) == NULL, "invariant");
126 _regions[index] = new_hr; 115 _regions.set_by_index(index, new_hr);
127 increment_allocated_length(); 116 increment_allocated_length();
128 } 117 }
129 // Have to increment the length first, otherwise we will get an 118 // Have to increment the length first, otherwise we will get an
130 // assert failure at(index) below. 119 // assert failure at(index) below.
131 increment_length(); 120 increment_length();
226 return i; 215 return i;
227 } 216 }
228 217
229 #ifndef PRODUCT 218 #ifndef PRODUCT
230 void HeapRegionSeq::verify_optional() { 219 void HeapRegionSeq::verify_optional() {
231 guarantee(_length <= _allocated_length, 220 guarantee(length() <= _allocated_length,
232 err_msg("invariant: _length: %u _allocated_length: %u", 221 err_msg("invariant: _length: %u _allocated_length: %u",
233 _length, _allocated_length)); 222 length(), _allocated_length));
234 guarantee(_allocated_length <= _max_length, 223 guarantee(_allocated_length <= max_length(),
235 err_msg("invariant: _allocated_length: %u _max_length: %u", 224 err_msg("invariant: _allocated_length: %u _max_length: %u",
236 _allocated_length, _max_length)); 225 _allocated_length, max_length()));
237 guarantee(_next_search_index <= _length, 226 guarantee(_next_search_index <= length(),
238 err_msg("invariant: _next_search_index: %u _length: %u", 227 err_msg("invariant: _next_search_index: %u _length: %u",
239 _next_search_index, _length)); 228 _next_search_index, length()));
240 229
241 HeapWord* prev_end = _heap_bottom; 230 HeapWord* prev_end = heap_bottom();
242 for (uint i = 0; i < _allocated_length; i += 1) { 231 for (uint i = 0; i < _allocated_length; i += 1) {
243 HeapRegion* hr = _regions[i]; 232 HeapRegion* hr = _regions.get_by_index(i);
244 guarantee(hr != NULL, err_msg("invariant: i: %u", i)); 233 guarantee(hr != NULL, err_msg("invariant: i: %u", i));
245 guarantee(hr->bottom() == prev_end, 234 guarantee(hr->bottom() == prev_end,
246 err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT, 235 err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,
247 i, HR_FORMAT_PARAMS(hr), prev_end)); 236 i, HR_FORMAT_PARAMS(hr), prev_end));
248 guarantee(hr->hrs_index() == i, 237 guarantee(hr->hrs_index() == i,
249 err_msg("invariant: i: %u hrs_index(): %u", i, hr->hrs_index())); 238 err_msg("invariant: i: %u hrs_index(): %u", i, hr->hrs_index()));
250 if (i < _length) { 239 if (i < length()) {
251 // Asserts will fire if i is >= _length 240 // Asserts will fire if i is >= _length
252 HeapWord* addr = hr->bottom(); 241 HeapWord* addr = hr->bottom();
253 guarantee(addr_to_region(addr) == hr, "sanity"); 242 guarantee(addr_to_region(addr) == hr, "sanity");
254 guarantee(addr_to_region_unsafe(addr) == hr, "sanity"); 243 guarantee(addr_to_region_unsafe(addr) == hr, "sanity");
255 } else { 244 } else {
263 prev_end = hr->orig_end(); 252 prev_end = hr->orig_end();
264 } else { 253 } else {
265 prev_end = hr->end(); 254 prev_end = hr->end();
266 } 255 }
267 } 256 }
268 for (uint i = _allocated_length; i < _max_length; i += 1) { 257 for (uint i = _allocated_length; i < max_length(); i += 1) {
269 guarantee(_regions[i] == NULL, err_msg("invariant i: %u", i)); 258 guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i));
270 } 259 }
271 } 260 }
272 #endif // PRODUCT 261 #endif // PRODUCT