< prev index next >

src/share/vm/gc/g1/heapRegionManager.cpp

Print this page
rev 8825 : [mq]: rev2
rev 8826 : [mq]: rev3


 409 
 410 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
 411   assert(length() > 0, "the region sequence should not be empty");
 412   assert(length() <= _allocated_heapregions_length, "invariant");
 413   assert(_allocated_heapregions_length > 0, "we should have at least one region committed");
 414   assert(num_regions_to_remove < length(), "We should never remove all regions");
 415 
 416   if (num_regions_to_remove == 0) {
 417     return 0;
 418   }
 419 
 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   }




 409 
 410 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
 411   assert(length() > 0, "the region sequence should not be empty");
 412   assert(length() <= _allocated_heapregions_length, "invariant");
 413   assert(_allocated_heapregions_length > 0, "we should have at least one region committed");
 414   assert(num_regions_to_remove < length(), "We should never remove all regions");
 415 
 416   if (num_regions_to_remove == 0) {
 417     return 0;
 418   }
 419 
 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     shrink_at(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, size_t num_regions) {
 441 #ifdef ASSERT
 442   for (uint i = index; i < (index + num_regions); i++) {
 443     assert(is_available(i), err_msg("Expected available region at index %u", i));
 444     assert(at(i)->is_empty(), err_msg("Expected empty region at index %u", i));
 445     assert(at(i)->is_free(), err_msg("Expected free region at index %u", i));
 446   }
 447 #endif
 448   uncommit_regions(index, num_regions);
 449 }
 450 
 451 uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const {
 452   guarantee(start_idx < _allocated_heapregions_length, "checking");
 453   guarantee(res_idx != NULL, "checking");
 454 
 455   uint num_regions_found = 0;
 456 
 457   jlong cur = start_idx;
 458   while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) {
 459     cur--;
 460   }
 461   if (cur == -1) {
 462     return num_regions_found;
 463   }
 464   jlong old_cur = cur;
 465   // cur indexes the first empty region
 466   while (cur != -1 && is_available(cur) && at(cur)->is_empty()) {
 467     cur--;
 468   }


< prev index next >