420 uint removed = 0;
421 uint cur = _allocated_heapregions_length - 1;
422 uint idx_last_found = 0;
423 uint num_last_found = 0;
424
425 while ((removed < num_regions_to_remove) &&
426 (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) {
427 uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found);
428
429 uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove);
430
431 cur -= num_last_found;
432 removed += to_remove;
433 }
434
435 verify_optional();
436
437 return removed;
438 }
439
440 uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const {
441 guarantee(start_idx < _allocated_heapregions_length, "checking");
442 guarantee(res_idx != NULL, "checking");
443
444 uint num_regions_found = 0;
445
446 jlong cur = start_idx;
447 while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) {
448 cur--;
449 }
450 if (cur == -1) {
451 return num_regions_found;
452 }
453 jlong old_cur = cur;
454 // cur indexes the first empty region
455 while (cur != -1 && is_available(cur) && at(cur)->is_empty()) {
456 cur--;
457 }
458 *res_idx = cur + 1;
459 num_regions_found = old_cur - cur;
|
420 uint removed = 0;
421 uint cur = _allocated_heapregions_length - 1;
422 uint idx_last_found = 0;
423 uint num_last_found = 0;
424
425 while ((removed < num_regions_to_remove) &&
426 (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) {
427 uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found);
428
429 uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove);
430
431 cur -= num_last_found;
432 removed += to_remove;
433 }
434
435 verify_optional();
436
437 return removed;
438 }
439
440 void HeapRegionManager::shrink_at(uint index) {
441 assert(is_available(index), err_msg("Expected available region at index %u", index));
442 HeapRegion* curr_region = _regions.get_by_index(index);
443 assert(curr_region->is_free(), err_msg("Expected free region at index %u", index));
444 uncommit_regions(index, 1);
445 }
446
447 uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const {
448 guarantee(start_idx < _allocated_heapregions_length, "checking");
449 guarantee(res_idx != NULL, "checking");
450
451 uint num_regions_found = 0;
452
453 jlong cur = start_idx;
454 while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) {
455 cur--;
456 }
457 if (cur == -1) {
458 return num_regions_found;
459 }
460 jlong old_cur = cur;
461 // cur indexes the first empty region
462 while (cur != -1 && is_available(cur) && at(cur)->is_empty()) {
463 cur--;
464 }
465 *res_idx = cur + 1;
466 num_regions_found = old_cur - cur;
|