1041 |
1041 |
1042 // Prepare heap for normal collections. |
1042 // Prepare heap for normal collections. |
1043 assert(num_free_regions() == 0, "we should not have added any free regions"); |
1043 assert(num_free_regions() == 0, "we should not have added any free regions"); |
1044 rebuild_region_sets(false /* free_list_only */); |
1044 rebuild_region_sets(false /* free_list_only */); |
1045 abort_refinement(); |
1045 abort_refinement(); |
1046 resize_if_necessary_after_full_collection(); |
1046 resize_heap_if_necessary(); |
1047 |
1047 |
1048 // Rebuild the strong code root lists for each region |
1048 // Rebuild the strong code root lists for each region |
1049 rebuild_strong_code_roots(); |
1049 rebuild_strong_code_roots(); |
1050 |
1050 |
1051 // Purge code root memory |
1051 // Purge code root memory |
1147 // out by the GC locker). So, right now, we'll ignore the return value. |
1147 // out by the GC locker). So, right now, we'll ignore the return value. |
1148 bool dummy = do_full_collection(true, /* explicit_gc */ |
1148 bool dummy = do_full_collection(true, /* explicit_gc */ |
1149 clear_all_soft_refs); |
1149 clear_all_soft_refs); |
1150 } |
1150 } |
1151 |
1151 |
1152 void G1CollectedHeap::resize_if_necessary_after_full_collection() { |
1152 void G1CollectedHeap::resize_heap_if_necessary() { |
1153 // Capacity, free and used after the GC counted as full regions to |
1153 // Capacity, free and used after the GC counted as full regions to |
1154 // include the waste in the following calculations. |
1154 // include the waste in the following calculations. |
1155 const size_t capacity_after_gc = capacity(); |
1155 const size_t capacity_after_gc = capacity(); |
1156 const size_t used_after_gc = capacity_after_gc - unused_committed_regions_in_bytes(); |
1156 const size_t used_after_gc = capacity_after_gc - unused_committed_regions_in_bytes(); |
1157 |
1157 |
1204 |
1204 |
1205 if (capacity_after_gc < minimum_desired_capacity) { |
1205 if (capacity_after_gc < minimum_desired_capacity) { |
1206 // Don't expand unless it's significant |
1206 // Don't expand unless it's significant |
1207 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc; |
1207 size_t expand_bytes = minimum_desired_capacity - capacity_after_gc; |
1208 |
1208 |
1209 log_debug(gc, ergo, heap)("Attempt heap expansion (capacity lower than min desired capacity after Full GC). " |
1209 log_debug(gc, ergo, heap)("Attempt heap expansion (capacity lower than min desired capacity). " |
1210 "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B " |
1210 "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B " |
1211 "min_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)", |
1211 "min_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)", |
1212 capacity_after_gc, used_after_gc, used(), minimum_desired_capacity, MinHeapFreeRatio); |
1212 capacity_after_gc, used_after_gc, used(), minimum_desired_capacity, MinHeapFreeRatio); |
1213 |
1213 |
1214 expand(expand_bytes, _workers); |
1214 expand(expand_bytes, _workers); |
1216 // No expansion, now see if we want to shrink |
1216 // No expansion, now see if we want to shrink |
1217 } else if (capacity_after_gc > maximum_desired_capacity) { |
1217 } else if (capacity_after_gc > maximum_desired_capacity) { |
1218 // Capacity too large, compute shrinking size |
1218 // Capacity too large, compute shrinking size |
1219 size_t shrink_bytes = capacity_after_gc - maximum_desired_capacity; |
1219 size_t shrink_bytes = capacity_after_gc - maximum_desired_capacity; |
1220 |
1220 |
1221 log_debug(gc, ergo, heap)("Attempt heap shrinking (capacity higher than max desired capacity after Full GC). " |
1221 log_debug(gc, ergo, heap)("Attempt heap shrinking (capacity higher than max desired capacity). " |
1222 "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B " |
1222 "Capacity: " SIZE_FORMAT "B occupancy: " SIZE_FORMAT "B live: " SIZE_FORMAT "B " |
1223 "maximum_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)", |
1223 "maximum_desired_capacity: " SIZE_FORMAT "B (" UINTX_FORMAT " %%)", |
1224 capacity_after_gc, used_after_gc, used(), maximum_desired_capacity, MaxHeapFreeRatio); |
1224 capacity_after_gc, used_after_gc, used(), maximum_desired_capacity, MaxHeapFreeRatio); |
1225 |
1225 |
1226 shrink(shrink_bytes); |
1226 shrink(shrink_bytes); |
1392 } |
1392 } |
1393 |
1393 |
1394 void G1CollectedHeap::shrink(size_t shrink_bytes) { |
1394 void G1CollectedHeap::shrink(size_t shrink_bytes) { |
1395 _verifier->verify_region_sets_optional(); |
1395 _verifier->verify_region_sets_optional(); |
1396 |
1396 |
1397 // We should only reach here at the end of a Full GC which means we |
1397 // We should only reach here at the end of a Full GC or during Remark which |
1398 // should not not be holding to any GC alloc regions. The method |
1398 // means we should not not be holding to any GC alloc regions. The method |
1399 // below will make sure of that and do any remaining clean up. |
1399 // below will make sure of that and do any remaining clean up. |
1400 _allocator->abandon_gc_alloc_regions(); |
1400 _allocator->abandon_gc_alloc_regions(); |
1401 |
1401 |
1402 // Instead of tearing down / rebuilding the free lists here, we |
1402 // Instead of tearing down / rebuilding the free lists here, we |
1403 // could instead use the remove_all_pending() method on free_list to |
1403 // could instead use the remove_all_pending() method on free_list to |
4397 assert(_old_set->is_empty(), "pre-condition"); |
4397 assert(_old_set->is_empty(), "pre-condition"); |
4398 } |
4398 } |
4399 } |
4399 } |
4400 |
4400 |
4401 bool do_heap_region(HeapRegion* r) { |
4401 bool do_heap_region(HeapRegion* r) { |
4402 // After full GC, no region should have a remembered set. |
|
4403 r->rem_set()->clear(true); |
|
4404 if (r->is_empty()) { |
4402 if (r->is_empty()) { |
|
4403 assert(r->rem_set()->is_empty(), "Empty regions should have empty remembered sets."); |
4405 // Add free regions to the free list |
4404 // Add free regions to the free list |
4406 r->set_free(); |
4405 r->set_free(); |
4407 _hrm->insert_into_free_list(r); |
4406 _hrm->insert_into_free_list(r); |
4408 } else if (!_free_list_only) { |
4407 } else if (!_free_list_only) { |
|
4408 assert(r->rem_set()->is_empty(), "At this point remembered sets must have been cleared."); |
4409 |
4409 |
4410 if (r->is_archive() || r->is_humongous()) { |
4410 if (r->is_archive() || r->is_humongous()) { |
4411 // We ignore archive and humongous regions. We left these sets unchanged. |
4411 // We ignore archive and humongous regions. We left these sets unchanged. |
4412 } else { |
4412 } else { |
4413 assert(r->is_young() || r->is_free() || r->is_old(), "invariant"); |
4413 assert(r->is_young() || r->is_free() || r->is_old(), "invariant"); |
4441 set_used(cl.total_used()); |
4441 set_used(cl.total_used()); |
4442 if (_archive_allocator != NULL) { |
4442 if (_archive_allocator != NULL) { |
4443 _archive_allocator->clear_used(); |
4443 _archive_allocator->clear_used(); |
4444 } |
4444 } |
4445 } |
4445 } |
4446 assert(used_unlocked() == recalculate_used(), |
4446 assert(used() == recalculate_used(), |
4447 "inconsistent used_unlocked(), " |
4447 "inconsistent used(), value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT, |
4448 "value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT, |
4448 used(), recalculate_used()); |
4449 used_unlocked(), recalculate_used()); |
|
4450 } |
4449 } |
4451 |
4450 |
4452 bool G1CollectedHeap::is_in_closed_subset(const void* p) const { |
4451 bool G1CollectedHeap::is_in_closed_subset(const void* p) const { |
4453 HeapRegion* hr = heap_region_containing(p); |
4452 HeapRegion* hr = heap_region_containing(p); |
4454 return hr->is_in(p); |
4453 return hr->is_in(p); |