225 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const {
226 guarantee(r != NULL, "Start region must be a valid region");
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++) {
229 HeapRegion* hr = _regions.get_by_index(i);
230 if (is_available(i)) {
231 return hr;
232 }
233 }
234 return NULL;
235 }
236
237 void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
238 uint len = max_length();
239
240 for (uint i = 0; i < len; i++) {
241 if (!is_available(i)) {
242 continue;
243 }
244 guarantee(at(i) != NULL, "Tried to access region %u that has a NULL HeapRegion*", i);
245 bool res = blk->doHeapRegion(at(i));
246 if (res) {
247 blk->incomplete();
248 return;
249 }
250 }
251 }
252
253 uint HeapRegionManager::find_unavailable_from_idx(uint start_idx, uint* res_idx) const {
254 guarantee(res_idx != NULL, "checking");
255 guarantee(start_idx <= (max_length() + 1), "checking");
256
257 uint num_regions = 0;
258
259 uint cur = start_idx;
260 while (cur < max_length() && is_available(cur)) {
261 cur++;
262 }
263 if (cur == max_length()) {
264 return num_regions;
265 }
266 *res_idx = cur;
267 while (cur < max_length() && !is_available(cur)) {
336 for (uint count = 0; count < n_regions; count++) {
337 const uint index = (start_index + count) % n_regions;
338 assert(index < n_regions, "sanity");
339 // Skip over unavailable regions
340 if (!is_available(index)) {
341 continue;
342 }
343 HeapRegion* r = _regions.get_by_index(index);
344 // We'll ignore regions already claimed.
345 // However, if the iteration is specified as concurrent, the values for
346 // is_starts_humongous and is_continues_humongous can not be trusted,
347 // and we should just blindly iterate over regions regardless of their
348 // humongous status.
349 if (hrclaimer->is_region_claimed(index)) {
350 continue;
351 }
352 // OK, try to claim it
353 if (!hrclaimer->claim_region(index)) {
354 continue;
355 }
356 bool res = blk->doHeapRegion(r);
357 if (res) {
358 return;
359 }
360 }
361 }
362
363 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
364 assert(length() > 0, "the region sequence should not be empty");
365 assert(length() <= _allocated_heapregions_length, "invariant");
366 assert(_allocated_heapregions_length > 0, "we should have at least one region committed");
367 assert(num_regions_to_remove < length(), "We should never remove all regions");
368
369 if (num_regions_to_remove == 0) {
370 return 0;
371 }
372
373 uint removed = 0;
374 uint cur = _allocated_heapregions_length - 1;
375 uint idx_last_found = 0;
376 uint num_last_found = 0;
|
225 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const {
226 guarantee(r != NULL, "Start region must be a valid region");
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++) {
229 HeapRegion* hr = _regions.get_by_index(i);
230 if (is_available(i)) {
231 return hr;
232 }
233 }
234 return NULL;
235 }
236
237 void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
238 uint len = max_length();
239
240 for (uint i = 0; i < len; i++) {
241 if (!is_available(i)) {
242 continue;
243 }
244 guarantee(at(i) != NULL, "Tried to access region %u that has a NULL HeapRegion*", i);
245 bool res = blk->do_heap_region(at(i));
246 if (res) {
247 blk->set_incomplete();
248 return;
249 }
250 }
251 }
252
253 uint HeapRegionManager::find_unavailable_from_idx(uint start_idx, uint* res_idx) const {
254 guarantee(res_idx != NULL, "checking");
255 guarantee(start_idx <= (max_length() + 1), "checking");
256
257 uint num_regions = 0;
258
259 uint cur = start_idx;
260 while (cur < max_length() && is_available(cur)) {
261 cur++;
262 }
263 if (cur == max_length()) {
264 return num_regions;
265 }
266 *res_idx = cur;
267 while (cur < max_length() && !is_available(cur)) {
336 for (uint count = 0; count < n_regions; count++) {
337 const uint index = (start_index + count) % n_regions;
338 assert(index < n_regions, "sanity");
339 // Skip over unavailable regions
340 if (!is_available(index)) {
341 continue;
342 }
343 HeapRegion* r = _regions.get_by_index(index);
344 // We'll ignore regions already claimed.
345 // However, if the iteration is specified as concurrent, the values for
346 // is_starts_humongous and is_continues_humongous can not be trusted,
347 // and we should just blindly iterate over regions regardless of their
348 // humongous status.
349 if (hrclaimer->is_region_claimed(index)) {
350 continue;
351 }
352 // OK, try to claim it
353 if (!hrclaimer->claim_region(index)) {
354 continue;
355 }
356 bool res = blk->do_heap_region(r);
357 if (res) {
358 return;
359 }
360 }
361 }
362
363 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
364 assert(length() > 0, "the region sequence should not be empty");
365 assert(length() <= _allocated_heapregions_length, "invariant");
366 assert(_allocated_heapregions_length > 0, "we should have at least one region committed");
367 assert(num_regions_to_remove < length(), "We should never remove all regions");
368
369 if (num_regions_to_remove == 0) {
370 return 0;
371 }
372
373 uint removed = 0;
374 uint cur = _allocated_heapregions_length - 1;
375 uint idx_last_found = 0;
376 uint num_last_found = 0;
|