Skip to content

8357559: G1HeapRegionManager refactor rename functions related to the number of regions in different states #25408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
26 changes: 13 additions & 13 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ HeapWord* G1CollectedHeap::humongous_obj_allocate(size_t word_size) {
// We managed to find a region by expanding the heap.
log_debug(gc, ergo, heap)("Heap expansion (humongous allocation request). Allocation request: %zuB",
word_size * HeapWordSize);
policy()->record_new_heap_size(num_regions());
policy()->record_new_heap_size(num_committed_regions());
} else {
// Policy: Potentially trigger a defragmentation GC.
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ bool G1CollectedHeap::expand(size_t expand_bytes, WorkerThreads* pretouch_worker

size_t actual_expand_bytes = expanded_by * G1HeapRegion::GrainBytes;
assert(actual_expand_bytes <= aligned_expand_bytes, "post-condition");
policy()->record_new_heap_size(num_regions());
policy()->record_new_heap_size(num_committed_regions());

return true;
}
Expand All @@ -1040,12 +1040,12 @@ bool G1CollectedHeap::expand_single_region(uint node_index) {
uint expanded_by = _hrm.expand_on_preferred_node(node_index);

if (expanded_by == 0) {
assert(is_maximal_no_gc(), "Should be no regions left, available: %u", _hrm.available());
assert(is_maximal_no_gc(), "Should be no regions left, available: %u", _hrm.num_inactive_regions());
log_debug(gc, ergo, heap)("Did not expand the heap (heap already fully expanded)");
return false;
}

policy()->record_new_heap_size(num_regions());
policy()->record_new_heap_size(num_committed_regions());
return true;
}

Expand All @@ -1061,7 +1061,7 @@ void G1CollectedHeap::shrink_helper(size_t shrink_bytes) {
shrink_bytes, aligned_shrink_bytes, shrunk_bytes);
if (num_regions_removed > 0) {
log_debug(gc, heap)("Uncommittable regions after shrink: %u", num_regions_removed);
policy()->record_new_heap_size(num_regions());
policy()->record_new_heap_size(num_committed_regions());
} else {
log_debug(gc, ergo, heap)("Did not shrink the heap (heap shrinking operation failed)");
}
Expand Down Expand Up @@ -1373,15 +1373,15 @@ jint G1CollectedHeap::initialize() {
// 6843694 - ensure that the maximum region index can fit
// in the remembered set structures.
const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
guarantee((max_reserved_regions() - 1) <= max_region_idx, "too many regions");
guarantee((max_num_regions() - 1) <= max_region_idx, "too many regions");

// The G1FromCardCache reserves card with value 0 as "invalid", so the heap must not
// start within the first card.
guarantee((uintptr_t)(heap_rs.base()) >= G1CardTable::card_size(), "Java heap must not start within the first card.");
G1FromCardCache::initialize(max_reserved_regions());
G1FromCardCache::initialize(max_num_regions());
// Also create a G1 rem set.
_rem_set = new G1RemSet(this, _card_table);
_rem_set->initialize(max_reserved_regions());
_rem_set->initialize(max_num_regions());

size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
guarantee(G1HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
Expand All @@ -1390,7 +1390,7 @@ jint G1CollectedHeap::initialize() {

G1HeapRegionRemSet::initialize(_reserved);

G1FreeRegionList::set_unrealistically_long_length(max_regions() + 1);
G1FreeRegionList::set_unrealistically_long_length(max_num_regions() + 1);

_bot = new G1BlockOffsetTable(reserved(), bot_storage);

Expand Down Expand Up @@ -1458,7 +1458,7 @@ jint G1CollectedHeap::initialize() {
// values in the heap have been properly initialized.
_monitoring_support = new G1MonitoringSupport(this);

_collection_set.initialize(max_reserved_regions());
_collection_set.initialize(max_num_regions());

allocation_failure_injector()->reset();

Expand Down Expand Up @@ -1557,7 +1557,7 @@ void G1CollectedHeap::ref_processing_init() {
}

size_t G1CollectedHeap::capacity() const {
return _hrm.length() * G1HeapRegion::GrainBytes;
return _hrm.num_committed_regions() * G1HeapRegion::GrainBytes;
}

size_t G1CollectedHeap::unused_committed_regions_in_bytes() const {
Expand Down Expand Up @@ -2069,7 +2069,7 @@ size_t G1CollectedHeap::unsafe_max_tlab_alloc(Thread* ignored) const {
}

size_t G1CollectedHeap::max_capacity() const {
return max_regions() * G1HeapRegion::GrainBytes;
return max_num_regions() * G1HeapRegion::GrainBytes;
}

void G1CollectedHeap::prepare_for_verify() {
Expand Down Expand Up @@ -2217,7 +2217,7 @@ G1HeapSummary G1CollectedHeap::create_g1_heap_summary() {

VirtualSpaceSummary heap_summary = create_heap_space_summary();
return G1HeapSummary(heap_summary, heap_used, eden_used_bytes, eden_capacity_bytes,
survivor_used_bytes, old_gen_used_bytes, num_regions());
survivor_used_bytes, old_gen_used_bytes, num_committed_regions());
}

G1EvacSummary G1CollectedHeap::create_g1_evac_summary(G1EvacStats* stats) {
Expand Down
21 changes: 9 additions & 12 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WorkerThreads;
typedef OverflowTaskQueue<ScannerTask, mtGC> G1ScannerTasksQueue;
typedef GenericTaskQueueSet<G1ScannerTasksQueue, mtGC> G1ScannerTasksQueueSet;

typedef int RegionIdx_t; // needs to hold [ 0..max_reserved_regions() )
typedef int RegionIdx_t; // needs to hold [ 0..max_num_regions() )
typedef int CardIdx_t; // needs to hold [ 0..CardsPerRegion )

// The G1 STW is alive closure.
Expand Down Expand Up @@ -971,7 +971,7 @@ class G1CollectedHeap : public CollectedHeap {
// But G1CollectedHeap doesn't yet support this.

bool is_maximal_no_gc() const override {
return _hrm.available() == 0;
return _hrm.num_inactive_regions() == 0;
}

// Returns true if an incremental GC should be upgrade to a full gc. This
Expand All @@ -981,27 +981,24 @@ class G1CollectedHeap : public CollectedHeap {
}

// The current number of regions in the heap.
uint num_regions() const { return _hrm.length(); }
uint num_committed_regions() const { return _hrm.num_committed_regions(); }

// The max number of regions reserved for the heap. Except for static array
// sizing purposes you probably want to use max_regions().
uint max_reserved_regions() const { return _hrm.reserved_length(); }

// Max number of regions that can be committed.
uint max_regions() const { return _hrm.max_length(); }
// The max number of regions reserved for the heap.
uint max_num_regions() const { return _hrm.max_num_regions(); }

// The number of regions that are completely free.
uint num_free_regions() const { return _hrm.num_free_regions(); }

// The number of regions that are not completely free.
uint num_used_regions() const { return _hrm.num_used_regions(); }

// The number of regions that can be allocated into.
uint num_free_or_available_regions() const { return num_free_regions() + _hrm.available(); }
uint num_available_regions() const { return _hrm.num_available_regions(); }

MemoryUsage get_auxiliary_data_memory_usage() const {
return _hrm.get_auxiliary_data_memory_usage();
}

// The number of regions that are not completely free.
uint num_used_regions() const { return num_regions() - num_free_regions(); }

#ifdef ASSERT
bool is_on_master_free_list(G1HeapRegion* hr) {
Expand Down
26 changes: 13 additions & 13 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ G1ConcurrentMark::G1ConcurrentMark(G1CollectedHeap* g1h,

_heap(_g1h->reserved()),

_root_regions(_g1h->max_regions()),
_root_regions(_g1h->max_num_regions()),

_global_mark_stack(),

Expand Down Expand Up @@ -513,9 +513,9 @@ G1ConcurrentMark::G1ConcurrentMark(G1CollectedHeap* g1h,
_num_concurrent_workers(0),
_max_concurrent_workers(0),

_region_mark_stats(NEW_C_HEAP_ARRAY(G1RegionMarkStats, _g1h->max_reserved_regions(), mtGC)),
_top_at_mark_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_reserved_regions(), mtGC)),
_top_at_rebuild_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_reserved_regions(), mtGC)),
_region_mark_stats(NEW_C_HEAP_ARRAY(G1RegionMarkStats, _g1h->max_num_regions(), mtGC)),
_top_at_mark_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_num_regions(), mtGC)),
_top_at_rebuild_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_num_regions(), mtGC)),
_needs_remembered_set_rebuild(false)
{
assert(CGC_lock != nullptr, "CGC_lock must be initialized");
Expand Down Expand Up @@ -570,8 +570,8 @@ void G1ConcurrentMark::reset() {
_tasks[i]->reset(mark_bitmap());
}

uint max_reserved_regions = _g1h->max_reserved_regions();
for (uint i = 0; i < max_reserved_regions; i++) {
uint max_num_regions = _g1h->max_num_regions();
for (uint i = 0; i < max_num_regions; i++) {
_top_at_rebuild_starts[i] = nullptr;
_region_mark_stats[i].clear();
}
Expand Down Expand Up @@ -613,8 +613,8 @@ void G1ConcurrentMark::reset_marking_for_restart() {
if (has_overflown()) {
_global_mark_stack.expand();

uint max_reserved_regions = _g1h->max_reserved_regions();
for (uint i = 0; i < max_reserved_regions; i++) {
uint max_num_regions = _g1h->max_num_regions();
for (uint i = 0; i < max_num_regions; i++) {
_region_mark_stats[i].clear_during_overflow();
}
}
Expand Down Expand Up @@ -782,7 +782,7 @@ class G1ClearBitMapTask : public WorkerTask {
void G1ConcurrentMark::clear_bitmap(WorkerThreads* workers, bool may_yield) {
assert(may_yield || SafepointSynchronize::is_at_safepoint(), "Non-yielding bitmap clear only allowed at safepoint.");

size_t const num_bytes_to_clear = (G1HeapRegion::GrainBytes * _g1h->num_regions()) / G1CMBitMap::heap_map_factor();
size_t const num_bytes_to_clear = (G1HeapRegion::GrainBytes * _g1h->num_committed_regions()) / G1CMBitMap::heap_map_factor();
size_t const num_chunks = align_up(num_bytes_to_clear, G1ClearBitMapTask::chunk_size()) / G1ClearBitMapTask::chunk_size();

uint const num_workers = (uint)MIN2(num_chunks, (size_t)workers->active_workers());
Expand Down Expand Up @@ -1434,20 +1434,20 @@ void G1ConcurrentMark::remark() {
GCTraceTime(Debug, gc, phases) debug("Select For Rebuild and Reclaim Empty Regions", _gc_timer_cm);

G1UpdateRegionLivenessAndSelectForRebuildTask cl(_g1h, this, _g1h->workers()->active_workers());
uint const num_workers = MIN2(G1UpdateRegionLivenessAndSelectForRebuildTask::desired_num_workers(_g1h->num_regions()),
uint const num_workers = MIN2(G1UpdateRegionLivenessAndSelectForRebuildTask::desired_num_workers(_g1h->num_committed_regions()),
_g1h->workers()->active_workers());
log_debug(gc,ergo)("Running %s using %u workers for %u regions in heap", cl.name(), num_workers, _g1h->num_regions());
log_debug(gc,ergo)("Running %s using %u workers for %u regions in heap", cl.name(), num_workers, _g1h->num_committed_regions());
_g1h->workers()->run_task(&cl, num_workers);

log_debug(gc, remset, tracking)("Remembered Set Tracking update regions total %u, selected %u",
_g1h->num_regions(), cl.total_selected_for_rebuild());
_g1h->num_committed_regions(), cl.total_selected_for_rebuild());

_needs_remembered_set_rebuild = (cl.total_selected_for_rebuild() > 0);

if (_needs_remembered_set_rebuild) {
// Prune rebuild candidates based on G1HeapWastePercent.
// Improves rebuild time in addition to remembered set memory usage.
G1CollectionSetChooser::build(_g1h->workers(), _g1h->num_regions(), _g1h->policy()->candidates());
G1CollectionSetChooser::build(_g1h->workers(), _g1h->num_committed_regions(), _g1h->policy()->candidates());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ inline size_t G1CMTask::scan_objArray(objArrayOop obj, MemRegion mr) {

inline void G1ConcurrentMark::update_top_at_mark_start(G1HeapRegion* r) {
uint const region = r->hrm_index();
assert(region < _g1h->max_reserved_regions(), "Tried to access TAMS for region %u out of bounds", region);
assert(region < _g1h->max_num_regions(), "Tried to access TAMS for region %u out of bounds", region);
_top_at_mark_starts[region] = r->top();
}

Expand All @@ -199,13 +199,13 @@ inline HeapWord* G1ConcurrentMark::top_at_mark_start(const G1HeapRegion* r) cons
}

inline HeapWord* G1ConcurrentMark::top_at_mark_start(uint region) const {
assert(region < _g1h->max_reserved_regions(), "Tried to access TARS for region %u out of bounds", region);
assert(region < _g1h->max_num_regions(), "Tried to access TARS for region %u out of bounds", region);
return _top_at_mark_starts[region];
}

inline bool G1ConcurrentMark::obj_allocated_since_mark_start(oop obj) const {
uint const region = _g1h->addr_to_region(obj);
assert(region < _g1h->max_reserved_regions(), "obj " PTR_FORMAT " outside heap %u", p2i(obj), region);
assert(region < _g1h->max_num_regions(), "obj " PTR_FORMAT " outside heap %u", p2i(obj), region);
return cast_from_oop<HeapWord*>(obj) >= top_at_mark_start(region);
}

Expand All @@ -217,7 +217,7 @@ inline void G1ConcurrentMark::update_top_at_rebuild_start(G1HeapRegion* r) {
assert(r->is_old() || r->is_humongous(), "precondition");

uint const region = r->hrm_index();
assert(region < _g1h->max_reserved_regions(), "Tried to access TARS for region %u out of bounds", region);
assert(region < _g1h->max_num_regions(), "Tried to access TARS for region %u out of bounds", region);
assert(_top_at_rebuild_starts[region] == nullptr,
"TARS for region %u has already been set to " PTR_FORMAT " should be null",
region, p2i(_top_at_rebuild_starts[region]));
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/share/gc/g1/g1FullCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uint G1FullCollector::calc_active_workers() {

// Consider G1HeapWastePercent to decide max number of workers. Each worker
// will in average cause half a region waste.
uint max_wasted_regions_allowed = ((heap->num_regions() * G1HeapWastePercent) / 100);
uint max_wasted_regions_allowed = ((heap->num_committed_regions() * G1HeapWastePercent) / 100);
uint waste_worker_count = MAX2((max_wasted_regions_allowed * 2) , 1u);
uint heap_waste_worker_limit = MIN2(waste_worker_count, max_worker_count);

Expand Down Expand Up @@ -133,9 +133,9 @@ G1FullCollector::G1FullCollector(G1CollectedHeap* heap,
_markers = NEW_C_HEAP_ARRAY(G1FullGCMarker*, _num_workers, mtGC);
_compaction_points = NEW_C_HEAP_ARRAY(G1FullGCCompactionPoint*, _num_workers, mtGC);

_live_stats = NEW_C_HEAP_ARRAY(G1RegionMarkStats, _heap->max_regions(), mtGC);
_compaction_tops = NEW_C_HEAP_ARRAY(HeapWord*, _heap->max_regions(), mtGC);
for (uint j = 0; j < heap->max_regions(); j++) {
_live_stats = NEW_C_HEAP_ARRAY(G1RegionMarkStats, _heap->max_num_regions(), mtGC);
_compaction_tops = NEW_C_HEAP_ARRAY(HeapWord*, _heap->max_num_regions(), mtGC);
for (uint j = 0; j < heap->max_num_regions(); j++) {
_live_stats[j].clear();
_compaction_tops[j] = nullptr;
}
Expand Down Expand Up @@ -415,7 +415,7 @@ void G1FullCollector::phase2c_prepare_serial_compaction() {
// lowest and the highest region in the tails of the compaction points.

uint start_serial = truncate_parallel_cps();
assert(start_serial < _heap->max_reserved_regions(), "Called on empty parallel compaction queues");
assert(start_serial < _heap->max_num_regions(), "Called on empty parallel compaction queues");

G1FullGCCompactionPoint* serial_cp = serial_compaction_point();
assert(!serial_cp->is_initialized(), "sanity!");
Expand All @@ -427,7 +427,7 @@ void G1FullCollector::phase2c_prepare_serial_compaction() {
HeapWord* dense_prefix_top = compaction_top(start_hr);
G1SerialRePrepareClosure re_prepare(serial_cp, dense_prefix_top);

for (uint i = start_serial + 1; i < _heap->max_reserved_regions(); i++) {
for (uint i = start_serial + 1; i < _heap->max_num_regions(); i++) {
if (is_compaction_target(i)) {
G1HeapRegion* current = _heap->region_at(i);
set_compaction_top(current, current->bottom());
Expand All @@ -445,11 +445,11 @@ void G1FullCollector::phase2d_prepare_humongous_compaction() {

uint last_serial_target = serial_cp->current_region()->hrm_index();
uint region_index = last_serial_target + 1;
uint max_reserved_regions = _heap->max_reserved_regions();
uint max_num_regions = _heap->max_num_regions();

G1FullGCCompactionPoint* humongous_cp = humongous_compaction_point();

while (region_index < max_reserved_regions) {
while (region_index < max_num_regions) {
G1HeapRegion* hr = _heap->region_at_or_null(region_index);

if (hr == nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1FullCollector.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -121,7 +121,7 @@ class G1FullCollector : StackObj {
G1CMBitMap* mark_bitmap();
ReferenceProcessor* reference_processor();
size_t live_words(uint region_index) const {
assert(region_index < _heap->max_regions(), "sanity");
assert(region_index < _heap->max_num_regions(), "sanity");
return _live_stats[region_index]._live_words;
}

Expand Down
Loading