8367731: G1: Make G1CollectionSet manage the young gen cset group

Reviewed-by: iwalulya, ayang
This commit is contained in:
Thomas Schatzl 2025-09-23 11:46:37 +00:00
parent dbf787c6b7
commit 02c78bb47e
8 changed files with 36 additions and 39 deletions

View File

@ -2517,13 +2517,7 @@ void G1CollectedHeap::update_perf_counter_cpu_time() {
}
void G1CollectedHeap::start_new_collection_set() {
// Clear current young cset group to allow adding.
// It is fine to clear it this late - evacuation does not add any remembered sets
// by itself, but only marks cards.
// The regions had their association to this group already removed earlier.
young_regions_cset_group()->clear();
collection_set()->start_incremental_building();
collection_set()->start();
clear_region_attr();
@ -2879,12 +2873,7 @@ void G1CollectedHeap::abandon_collection_set() {
G1AbandonCollectionSetClosure cl;
collection_set_iterate_all(&cl);
collection_set()->clear();
collection_set()->stop_incremental_building();
collection_set()->abandon_all_candidates();
young_regions_cset_group()->clear(true /* uninstall_group_cardset */);
collection_set()->abandon();
}
bool G1CollectedHeap::is_old_gc_alloc_region(G1HeapRegion* hr) {
@ -3247,9 +3236,3 @@ void G1CollectedHeap::finish_codecache_marking_cycle() {
CodeCache::on_gc_marking_cycle_finish();
CodeCache::arm_all_nmethods();
}
void G1CollectedHeap::prepare_group_cardsets_for_scan() {
young_regions_cardset()->reset_table_scanner_for_groups();
collection_set()->prepare_for_scan();
}

View File

@ -805,11 +805,6 @@ public:
G1CardSetConfiguration* card_set_config() { return &_card_set_config; }
G1CSetCandidateGroup* young_regions_cset_group() { return &_young_regions_cset_group; }
G1CardSet* young_regions_cardset() { return _young_regions_cset_group.card_set(); };
G1MonotonicArenaMemoryStats young_regions_card_set_memory_stats() { return _young_regions_cset_group.card_set_memory_stats(); }
void prepare_group_cardsets_for_scan();
// After a collection pause, reset eden and the collection set.
void clear_eden();

View File

@ -99,12 +99,21 @@ void G1CollectionSet::initialize(uint max_region_length) {
_candidates.initialize(max_region_length);
}
void G1CollectionSet::abandon() {
_g1h->young_regions_cset_group()->clear(true /* uninstall_cset_group */);
clear();
abandon_all_candidates();
stop_incremental_building();
}
void G1CollectionSet::abandon_all_candidates() {
_candidates.clear();
_initial_old_region_length = 0;
}
void G1CollectionSet::prepare_for_scan () {
_g1h->young_regions_cset_group()->card_set()->reset_table_scanner_for_groups();
_groups.prepare_for_scan();
}
@ -127,12 +136,15 @@ void G1CollectionSet::add_old_region(G1HeapRegion* hr) {
_g1h->old_set_remove(hr);
}
void G1CollectionSet::start_incremental_building() {
void G1CollectionSet::start() {
assert(_regions_cur_length == 0, "Collection set must be empty before starting a new collection set.");
assert(groups_cur_length() == 0, "Collection set groups must be empty before starting a new collection set.");
assert(_optional_groups.length() == 0, "Collection set optional gorups must be empty before starting a new collection set.");
continue_incremental_building();
G1CSetCandidateGroup* young_group = _g1h->young_regions_cset_group();
young_group->clear();
}
void G1CollectionSet::continue_incremental_building() {

View File

@ -227,6 +227,7 @@ class G1CollectionSet {
uint& num_optional_regions,
double& predicted_optional_time_ms,
double predicted_time_ms);
public:
G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy);
~G1CollectionSet();
@ -234,6 +235,8 @@ public:
// Initializes the collection set giving the maximum possible length of the collection set.
void initialize(uint max_region_length);
// Drop the collection set and collection set candidates.
void abandon();
// Drop all collection set candidates (only the candidates).
void abandon_all_candidates();
@ -261,13 +264,15 @@ public:
template <class CardOrRangeVisitor>
inline void merge_cardsets_for_collection_groups(CardOrRangeVisitor& cl, uint worker_id, uint num_workers);
uint groups_increment_length() const;
// Reset the contents of the collection set.
void clear();
// Incremental collection set support
// Initialize incremental collection set info.
void start_incremental_building();
// Start a new collection set for the next mutator phase.
void start();
// Start a new collection set increment, continuing the incremental building.
void continue_incremental_building();
// Stop adding regions to the current collection set increment.
@ -282,8 +287,6 @@ public:
// Returns the length of the whole current collection set in number of regions
size_t cur_length() const { return _regions_cur_length; }
uint groups_increment_length() const;
// Iterate over the entire collection set (all increments calculated so far), applying
// the given G1HeapRegionClosure on all of the regions.
void iterate(G1HeapRegionClosure* cl) const;

View File

@ -31,20 +31,24 @@
template <class CardOrRangeVisitor>
inline void G1CollectionSet::merge_cardsets_for_collection_groups(CardOrRangeVisitor& cl, uint worker_id, uint num_workers) {
uint length = groups_increment_length();
uint offset = _groups_inc_part_start;
if (length == 0) {
if (offset == 0) {
G1HeapRegionRemSet::iterate_for_merge(_g1h->young_regions_cset_group()->card_set(), cl);
}
uint next_increment_length = groups_increment_length();
if (next_increment_length == 0) {
return;
}
uint start_pos = (worker_id * length) / num_workers;
uint start_pos = (worker_id * next_increment_length) / num_workers;
uint cur_pos = start_pos;
uint count = 0;
do {
G1HeapRegionRemSet::iterate_for_merge(_groups.at(offset + cur_pos)->card_set(), cl);
cur_pos++;
count++;
if (cur_pos == length) {
if (cur_pos == next_increment_length) {
cur_pos = 0;
}
} while (cur_pos != start_pos);

View File

@ -122,6 +122,10 @@ public:
return _card_set_mm.memory_stats();
}
size_t cards_occupied() const {
return _card_set.occupied();
}
void clear(bool uninstall_group_cardset = false);
G1CSetCandidateGroupIterator begin() const {

View File

@ -1166,10 +1166,6 @@ public:
// 2. collection set
G1MergeCardSetClosure merge(_scan_state);
if (_initial_evacuation) {
G1HeapRegionRemSet::iterate_for_merge(g1h->young_regions_cardset(), merge);
}
g1h->collection_set()->merge_cardsets_for_collection_groups(merge, worker_id, _num_workers);
G1MergeCardSetStats stats = merge.stats();

View File

@ -506,7 +506,7 @@ void G1YoungCollector::pre_evacuate_collection_set(G1EvacInfo* evacuation_info)
Ticks start = Ticks::now();
rem_set()->prepare_for_scan_heap_roots();
_g1h->prepare_group_cardsets_for_scan();
_g1h->collection_set()->prepare_for_scan();
phase_times()->record_prepare_heap_roots_time_ms((Ticks::now() - start).seconds() * 1000.0);
}
@ -516,7 +516,7 @@ void G1YoungCollector::pre_evacuate_collection_set(G1EvacInfo* evacuation_info)
Tickspan task_time = run_task_timed(&g1_prep_task);
G1MonotonicArenaMemoryStats sampled_card_set_stats = g1_prep_task.all_card_set_stats();
sampled_card_set_stats.add(_g1h->young_regions_card_set_memory_stats());
sampled_card_set_stats.add(_g1h->young_regions_cset_group()->card_set_memory_stats());
_g1h->set_young_gen_card_set_stats(sampled_card_set_stats);
_g1h->set_humongous_stats(g1_prep_task.humongous_total(), g1_prep_task.humongous_candidates());