Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion range) {
assert(!is_init_completed(), "Expect to be called at JVM init time");
MemRegion reserved = _hrm.reserved();
size_t size_used = 0;
uint shrink_count = 0;

// Free the G1 regions that are within the specified range.
MutexLocker x(Heap_lock);
Expand All @@ -559,21 +558,32 @@ void G1CollectedHeap::dealloc_archive_regions(MemRegion range) {
p2i(start_address), p2i(last_address));
size_used += range.byte_size();

uint max_shrink_count = 0;
if (capacity() > MinHeapSize) {
size_t max_shrink_bytes = capacity() - MinHeapSize;
max_shrink_count = (uint)(max_shrink_bytes / G1HeapRegion::GrainBytes);
}

uint shrink_count = 0;
// Free, empty and uncommit regions with CDS archive content.
auto dealloc_archive_region = [&] (G1HeapRegion* r, bool is_last) {
guarantee(r->is_old(), "Expected old region at index %u", r->hrm_index());
_old_set.remove(r);
r->set_free();
r->set_top(r->bottom());
_hrm.shrink_at(r->hrm_index(), 1);
shrink_count++;
if (shrink_count < max_shrink_count) {
_hrm.shrink_at(r->hrm_index(), 1);
shrink_count++;
} else {
_hrm.insert_into_free_list(r);
}
};

iterate_regions_in_range(range, dealloc_archive_region);

if (shrink_count != 0) {
log_debug(gc, ergo, heap)("Attempt heap shrinking (CDS archive regions). Total size: %zuB",
G1HeapRegion::GrainWords * HeapWordSize * shrink_count);
log_debug(gc, ergo, heap)("Attempt heap shrinking (CDS archive regions). Total size: %zuB (%u Regions)",
G1HeapRegion::GrainWords * HeapWordSize * shrink_count, shrink_count);
// Explicit uncommit.
uncommit_regions(shrink_count);
}
Expand Down