90 |
90 |
91 _card_counts_mapper->commit_regions(index, num_regions); |
91 _card_counts_mapper->commit_regions(index, num_regions); |
92 } |
92 } |
93 |
93 |
94 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) { |
94 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) { |
95 guarantee(num_regions >= 1, err_msg("Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start)); |
95 guarantee(num_regions >= 1, "Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start); |
96 guarantee(_num_committed >= num_regions, "pre-condition"); |
96 guarantee(_num_committed >= num_regions, "pre-condition"); |
97 |
97 |
98 // Print before uncommitting. |
98 // Print before uncommitting. |
99 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
99 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
100 for (uint i = start; i < start + num_regions; i++) { |
100 for (uint i = start; i < start + num_regions; i++) { |
130 } |
130 } |
131 |
131 |
132 _available_map.par_set_range(start, start + num_regions, BitMap::unknown_range); |
132 _available_map.par_set_range(start, start + num_regions, BitMap::unknown_range); |
133 |
133 |
134 for (uint i = start; i < start + num_regions; i++) { |
134 for (uint i = start; i < start + num_regions; i++) { |
135 assert(is_available(i), err_msg("Just made region %u available but is apparently not.", i)); |
135 assert(is_available(i), "Just made region %u available but is apparently not.", i); |
136 HeapRegion* hr = at(i); |
136 HeapRegion* hr = at(i); |
137 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
137 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
138 G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end()); |
138 G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end()); |
139 } |
139 } |
140 HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i); |
140 HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i); |
211 if (length_found == num) { |
211 if (length_found == num) { |
212 for (uint i = found; i < (found + num); i++) { |
212 for (uint i = found; i < (found + num); i++) { |
213 HeapRegion* hr = _regions.get_by_index(i); |
213 HeapRegion* hr = _regions.get_by_index(i); |
214 // sanity check |
214 // sanity check |
215 guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()), |
215 guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()), |
216 err_msg("Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT |
216 "Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT |
217 " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr))); |
217 " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr)); |
218 } |
218 } |
219 return found; |
219 return found; |
220 } else { |
220 } else { |
221 return G1_NO_HRM_INDEX; |
221 return G1_NO_HRM_INDEX; |
222 } |
222 } |
223 } |
223 } |
224 |
224 |
225 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const { |
225 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const { |
226 guarantee(r != NULL, "Start region must be a valid region"); |
226 guarantee(r != NULL, "Start region must be a valid region"); |
227 guarantee(is_available(r->hrm_index()), err_msg("Trying to iterate starting from region %u which is not in the heap", r->hrm_index())); |
227 guarantee(is_available(r->hrm_index()), "Trying to iterate starting from region %u which is not in the heap", r->hrm_index()); |
228 for (uint i = r->hrm_index() + 1; i < _allocated_heapregions_length; i++) { |
228 for (uint i = r->hrm_index() + 1; i < _allocated_heapregions_length; i++) { |
229 HeapRegion* hr = _regions.get_by_index(i); |
229 HeapRegion* hr = _regions.get_by_index(i); |
230 if (is_available(i)) { |
230 if (is_available(i)) { |
231 return hr; |
231 return hr; |
232 } |
232 } |
239 |
239 |
240 for (uint i = 0; i < len; i++) { |
240 for (uint i = 0; i < len; i++) { |
241 if (!is_available(i)) { |
241 if (!is_available(i)) { |
242 continue; |
242 continue; |
243 } |
243 } |
244 guarantee(at(i) != NULL, err_msg("Tried to access region %u that has a NULL HeapRegion*", i)); |
244 guarantee(at(i) != NULL, "Tried to access region %u that has a NULL HeapRegion*", i); |
245 bool res = blk->doHeapRegion(at(i)); |
245 bool res = blk->doHeapRegion(at(i)); |
246 if (res) { |
246 if (res) { |
247 blk->incomplete(); |
247 blk->incomplete(); |
248 return; |
248 return; |
249 } |
249 } |
271 #ifdef ASSERT |
271 #ifdef ASSERT |
272 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) { |
272 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) { |
273 assert(!is_available(i), "just checking"); |
273 assert(!is_available(i), "just checking"); |
274 } |
274 } |
275 assert(cur == max_length() || num_regions == 0 || is_available(cur), |
275 assert(cur == max_length() || num_regions == 0 || is_available(cur), |
276 err_msg("The region at the current position %u must be available or at the end of the heap.", cur)); |
276 "The region at the current position %u must be available or at the end of the heap.", cur); |
277 #endif |
277 #endif |
278 return num_regions; |
278 return num_regions; |
279 } |
279 } |
280 |
280 |
281 uint HeapRegionManager::find_highest_free(bool* expanded) { |
281 uint HeapRegionManager::find_highest_free(bool* expanded) { |
372 for (uint ch_index = index + 1; ch_index < index + r->region_num(); ch_index++) { |
372 for (uint ch_index = index + 1; ch_index < index + r->region_num(); ch_index++) { |
373 HeapRegion* chr = _regions.get_by_index(ch_index); |
373 HeapRegion* chr = _regions.get_by_index(ch_index); |
374 |
374 |
375 assert(chr->is_continues_humongous(), "Must be humongous region"); |
375 assert(chr->is_continues_humongous(), "Must be humongous region"); |
376 assert(chr->humongous_start_region() == r, |
376 assert(chr->humongous_start_region() == r, |
377 err_msg("Must work on humongous continuation of the original start region " |
377 "Must work on humongous continuation of the original start region " |
378 PTR_FORMAT ", but is " PTR_FORMAT, p2i(r), p2i(chr))); |
378 PTR_FORMAT ", but is " PTR_FORMAT, p2i(r), p2i(chr)); |
379 assert(!hrclaimer->is_region_claimed(ch_index), |
379 assert(!hrclaimer->is_region_claimed(ch_index), |
380 "Must not have been claimed yet because claiming of humongous continuation first claims the start region"); |
380 "Must not have been claimed yet because claiming of humongous continuation first claims the start region"); |
381 |
381 |
382 // Claim the region so no other worker tries to process the region. When a worker processes a |
382 // Claim the region so no other worker tries to process the region. When a worker processes a |
383 // starts_humongous region it may also process the associated continues_humongous regions. |
383 // starts_humongous region it may also process the associated continues_humongous regions. |
438 } |
438 } |
439 |
439 |
440 void HeapRegionManager::shrink_at(uint index, size_t num_regions) { |
440 void HeapRegionManager::shrink_at(uint index, size_t num_regions) { |
441 #ifdef ASSERT |
441 #ifdef ASSERT |
442 for (uint i = index; i < (index + num_regions); i++) { |
442 for (uint i = index; i < (index + num_regions); i++) { |
443 assert(is_available(i), err_msg("Expected available region at index %u", i)); |
443 assert(is_available(i), "Expected available region at index %u", i); |
444 assert(at(i)->is_empty(), err_msg("Expected empty region at index %u", i)); |
444 assert(at(i)->is_empty(), "Expected empty region at index %u", i); |
445 assert(at(i)->is_free(), err_msg("Expected free region at index %u", i)); |
445 assert(at(i)->is_free(), "Expected free region at index %u", i); |
446 } |
446 } |
447 #endif |
447 #endif |
448 uncommit_regions(index, num_regions); |
448 uncommit_regions(index, num_regions); |
449 } |
449 } |
450 |
450 |
477 return num_regions_found; |
477 return num_regions_found; |
478 } |
478 } |
479 |
479 |
480 void HeapRegionManager::verify() { |
480 void HeapRegionManager::verify() { |
481 guarantee(length() <= _allocated_heapregions_length, |
481 guarantee(length() <= _allocated_heapregions_length, |
482 err_msg("invariant: _length: %u _allocated_length: %u", |
482 "invariant: _length: %u _allocated_length: %u", |
483 length(), _allocated_heapregions_length)); |
483 length(), _allocated_heapregions_length); |
484 guarantee(_allocated_heapregions_length <= max_length(), |
484 guarantee(_allocated_heapregions_length <= max_length(), |
485 err_msg("invariant: _allocated_length: %u _max_length: %u", |
485 "invariant: _allocated_length: %u _max_length: %u", |
486 _allocated_heapregions_length, max_length())); |
486 _allocated_heapregions_length, max_length()); |
487 |
487 |
488 bool prev_committed = true; |
488 bool prev_committed = true; |
489 uint num_committed = 0; |
489 uint num_committed = 0; |
490 HeapWord* prev_end = heap_bottom(); |
490 HeapWord* prev_end = heap_bottom(); |
491 for (uint i = 0; i < _allocated_heapregions_length; i++) { |
491 for (uint i = 0; i < _allocated_heapregions_length; i++) { |
493 prev_committed = false; |
493 prev_committed = false; |
494 continue; |
494 continue; |
495 } |
495 } |
496 num_committed++; |
496 num_committed++; |
497 HeapRegion* hr = _regions.get_by_index(i); |
497 HeapRegion* hr = _regions.get_by_index(i); |
498 guarantee(hr != NULL, err_msg("invariant: i: %u", i)); |
498 guarantee(hr != NULL, "invariant: i: %u", i); |
499 guarantee(!prev_committed || hr->bottom() == prev_end, |
499 guarantee(!prev_committed || hr->bottom() == prev_end, |
500 err_msg("invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT, |
500 "invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT, |
501 i, HR_FORMAT_PARAMS(hr), p2i(prev_end))); |
501 i, HR_FORMAT_PARAMS(hr), p2i(prev_end)); |
502 guarantee(hr->hrm_index() == i, |
502 guarantee(hr->hrm_index() == i, |
503 err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index())); |
503 "invariant: i: %u hrm_index(): %u", i, hr->hrm_index()); |
504 // Asserts will fire if i is >= _length |
504 // Asserts will fire if i is >= _length |
505 HeapWord* addr = hr->bottom(); |
505 HeapWord* addr = hr->bottom(); |
506 guarantee(addr_to_region(addr) == hr, "sanity"); |
506 guarantee(addr_to_region(addr) == hr, "sanity"); |
507 // We cannot check whether the region is part of a particular set: at the time |
507 // We cannot check whether the region is part of a particular set: at the time |
508 // this method may be called, we have only completed allocation of the regions, |
508 // this method may be called, we have only completed allocation of the regions, |
513 } else { |
513 } else { |
514 prev_end = hr->end(); |
514 prev_end = hr->end(); |
515 } |
515 } |
516 } |
516 } |
517 for (uint i = _allocated_heapregions_length; i < max_length(); i++) { |
517 for (uint i = _allocated_heapregions_length; i < max_length(); i++) { |
518 guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i)); |
518 guarantee(_regions.get_by_index(i) == NULL, "invariant i: %u", i); |
519 } |
519 } |
520 |
520 |
521 guarantee(num_committed == _num_committed, err_msg("Found %u committed regions, but should be %u", num_committed, _num_committed)); |
521 guarantee(num_committed == _num_committed, "Found %u committed regions, but should be %u", num_committed, _num_committed); |
522 _free_list.verify(); |
522 _free_list.verify(); |
523 } |
523 } |
524 |
524 |
525 #ifndef PRODUCT |
525 #ifndef PRODUCT |
526 void HeapRegionManager::verify_optional() { |
526 void HeapRegionManager::verify_optional() { |