Skip to content

Commit b735ef9

Browse files
author
Thomas Schatzl
committed
8364925: G1: Improve program flow around incremental collection set building
Reviewed-by: ayang, iwalulya
1 parent 5ede5b4 commit b735ef9

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
#include "utilities/globalDefinitions.hpp"
3939
#include "utilities/quickSort.hpp"
4040

41+
uint G1CollectionSet::selected_groups_cur_length() const {
42+
assert(_inc_build_state == CSetBuildType::Inactive, "must be");
43+
return _collection_set_groups.length();
44+
}
45+
46+
uint G1CollectionSet::collection_groups_increment_length() const {
47+
return selected_groups_cur_length() - _selected_groups_inc_part_start;
48+
}
49+
4150
G1CollectorState* G1CollectionSet::collector_state() const {
4251
return _g1h->collector_state();
4352
}
@@ -54,7 +63,6 @@ G1CollectionSet::G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy) :
5463
_collection_set_cur_length(0),
5564
_collection_set_max_length(0),
5665
_collection_set_groups(),
57-
_selected_groups_cur_length(0),
5866
_selected_groups_inc_part_start(0),
5967
_eden_region_length(0),
6068
_survivor_region_length(0),
@@ -122,9 +130,23 @@ void G1CollectionSet::add_old_region(G1HeapRegion* hr) {
122130

123131
void G1CollectionSet::start_incremental_building() {
124132
assert(_collection_set_cur_length == 0, "Collection set must be empty before starting a new collection set.");
133+
assert(selected_groups_cur_length() == 0, "Collection set groups must be empty before starting a new collection set.");
134+
assert(_optional_groups.length() == 0, "Collection set optional gorups must be empty before starting a new collection set.");
135+
136+
continue_incremental_building();
137+
}
138+
139+
void G1CollectionSet::continue_incremental_building() {
125140
assert(_inc_build_state == Inactive, "Precondition");
126141

127-
update_incremental_marker();
142+
_inc_part_start = _collection_set_cur_length;
143+
_selected_groups_inc_part_start = selected_groups_cur_length();
144+
145+
_inc_build_state = CSetBuildType::Active;
146+
}
147+
148+
void G1CollectionSet::stop_incremental_building() {
149+
_inc_build_state = Inactive;
128150
}
129151

130152
void G1CollectionSet::finalize_incremental_building() {
@@ -343,9 +365,6 @@ static int compare_region_idx(const uint a, const uint b) {
343365
void G1CollectionSet::finalize_old_part(double time_remaining_ms) {
344366
double non_young_start_time_sec = os::elapsedTime();
345367

346-
_selected_groups_cur_length = 0;
347-
_selected_groups_inc_part_start = 0;
348-
349368
if (!candidates()->is_empty()) {
350369
candidates()->verify();
351370

@@ -363,13 +382,8 @@ void G1CollectionSet::finalize_old_part(double time_remaining_ms) {
363382
log_debug(gc, ergo, cset)("No candidates to reclaim.");
364383
}
365384

366-
_selected_groups_cur_length = collection_set_groups()->length();
367-
stop_incremental_building();
368-
369385
double non_young_end_time_sec = os::elapsedTime();
370386
phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
371-
372-
QuickSort::sort(_collection_set_regions, _collection_set_cur_length, compare_region_idx);
373387
}
374388

375389
static void print_finish_message(const char* reason, bool from_marking) {
@@ -670,16 +684,21 @@ void G1CollectionSet::add_region_to_collection_set(G1HeapRegion* r) {
670684
}
671685

672686
void G1CollectionSet::finalize_initial_collection_set(double target_pause_time_ms, G1SurvivorRegions* survivor) {
687+
assert(_inc_part_start == 0, "must be");
688+
assert(_selected_groups_inc_part_start == 0, "must be");
689+
673690
double time_remaining_ms = finalize_young_part(target_pause_time_ms, survivor);
674691
finalize_old_part(time_remaining_ms);
692+
693+
stop_incremental_building();
694+
QuickSort::sort(_collection_set_regions, _collection_set_cur_length, compare_region_idx);
675695
}
676696

677697
bool G1CollectionSet::finalize_optional_for_evacuation(double remaining_pause_time) {
678-
update_incremental_marker();
698+
continue_incremental_building();
679699

680700
uint num_regions_selected = select_optional_collection_set_regions(remaining_pause_time);
681701

682-
_selected_groups_cur_length = collection_set_groups()->length();
683702
stop_incremental_building();
684703

685704
_g1h->verify_region_attr_remset_is_tracked();

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ class G1CollectionSet {
149149
// Old gen groups selected for evacuation.
150150
G1CSetCandidateGroupList _collection_set_groups;
151151

152-
// Groups are added to the collection set in increments when performing optional evacuations.
153-
// We use the value below to track these increments.
154-
uint _selected_groups_cur_length;
152+
uint selected_groups_cur_length() const;
155153
uint _selected_groups_inc_part_start;
156154

157155
uint _eden_region_length;
@@ -258,14 +256,10 @@ class G1CollectionSet {
258256

259257
// Initialize incremental collection set info.
260258
void start_incremental_building();
261-
// Start a new collection set increment.
262-
void update_incremental_marker() {
263-
_inc_build_state = Active;
264-
_inc_part_start = _collection_set_cur_length;
265-
_selected_groups_inc_part_start = _selected_groups_cur_length;
266-
}
259+
// Start a new collection set increment, continuing the incremental building.
260+
void continue_incremental_building();
267261
// Stop adding regions to the current collection set increment.
268-
void stop_incremental_building() { _inc_build_state = Inactive; }
262+
void stop_incremental_building();
269263

270264
// Iterate over the current collection set increment applying the given G1HeapRegionClosure
271265
// from a starting position determined by the given worker id.
@@ -276,7 +270,7 @@ class G1CollectionSet {
276270
// Returns the length of the whole current collection set in number of regions
277271
size_t cur_length() const { return _collection_set_cur_length; }
278272

279-
uint collection_groups_increment_length() const { return _selected_groups_cur_length - _selected_groups_inc_part_start; }
273+
uint collection_groups_increment_length() const;
280274

281275
// Iterate over the entire collection set (all increments calculated so far), applying
282276
// the given G1HeapRegionClosure on all of them.

0 commit comments

Comments
 (0)