Skip to content

Commit 4cc655a

Browse files
author
Thomas Schatzl
committed
8371791: G1: Improve accuracy of G1CollectedHeap::non_young_occupancy_after_allocation()
Reviewed-by: ayang, iwalulya
1 parent ff851de commit 4cc655a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/hotspot/share/gc/g1/g1Allocator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ void G1Allocator::reuse_retained_old_region(G1EvacInfo* evacuation_info,
123123
}
124124
}
125125

126+
size_t G1Allocator::free_bytes_in_retained_old_region() const {
127+
if (_retained_old_gc_alloc_region == nullptr) {
128+
return 0;
129+
} else {
130+
return _retained_old_gc_alloc_region->free();
131+
}
132+
}
133+
126134
void G1Allocator::init_gc_alloc_regions(G1EvacInfo* evacuation_info) {
127135
assert_at_safepoint_on_vm_thread();
128136

src/hotspot/share/gc/g1/g1Allocator.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class G1Allocator : public CHeapObj<mtGC> {
103103
void init_gc_alloc_regions(G1EvacInfo* evacuation_info);
104104
void release_gc_alloc_regions(G1EvacInfo* evacuation_info);
105105
void abandon_gc_alloc_regions();
106+
106107
bool is_retained_old_region(G1HeapRegion* hr);
108+
// Return the amount of free bytes in the current retained old region.
109+
size_t free_bytes_in_retained_old_region() const;
107110

108111
// Node index of current thread.
109112
inline uint current_node_index() const;

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,8 +2964,8 @@ void G1CollectedHeap::abandon_collection_set() {
29642964
}
29652965

29662966
size_t G1CollectedHeap::non_young_occupancy_after_allocation(size_t allocation_word_size) {
2967-
// For simplicity, just count whole regions.
2968-
const size_t cur_occupancy = (old_regions_count() + humongous_regions_count()) * G1HeapRegion::GrainBytes;
2967+
const size_t cur_occupancy = (old_regions_count() + humongous_regions_count()) * G1HeapRegion::GrainBytes -
2968+
_allocator->free_bytes_in_retained_old_region();
29692969
// Humongous allocations will always be assigned to non-young heap, so consider
29702970
// that allocation in the result as well. Otherwise the allocation will always
29712971
// be in young gen, so there is no need to account it here.

0 commit comments

Comments
 (0)