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+
4150G1CollectorState* 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
123131void 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
130152void G1CollectionSet::finalize_incremental_building () {
@@ -343,9 +365,6 @@ static int compare_region_idx(const uint a, const uint b) {
343365void 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
375389static 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
672686void 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
677697bool 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 ();
0 commit comments