Skip to content

Commit 6808ba2

Browse files
author
William Kemper
committed
8378293: GenShen: Simplify selection of aged regions
Reviewed-by: kdnilsen, ysr
1 parent 6a061f9 commit 6808ba2

12 files changed

Lines changed: 160 additions & 265 deletions

src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp

Lines changed: 51 additions & 119 deletions
Large diffs are not rendered by default.

src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828

2929
#include "gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp"
30+
#include "gc/shenandoah/shenandoahInPlacePromoter.hpp"
3031

3132
class ShenandoahGeneration;
3233
class ShenandoahHeap;
@@ -53,7 +54,7 @@ class ShenandoahGenerationalHeuristics : public ShenandoahAdaptiveHeuristics {
5354

5455
private:
5556
// Compute evacuation budgets prior to choosing collection set.
56-
void compute_evacuation_budgets(ShenandoahHeap* const heap);
57+
void compute_evacuation_budgets(ShenandoahInPlacePromotionPlanner& in_place_promotions, ShenandoahHeap* const heap);
5758

5859
// Preselect for possible inclusion into the collection set exactly the most
5960
// garbage-dense regions, including those that satisfy criteria 1 & 2 below,
@@ -70,10 +71,10 @@ class ShenandoahGenerationalHeuristics : public ShenandoahAdaptiveHeuristics {
7071
// regions, which are marked in the preselected_regions() indicator
7172
// array of the heap's collection set, which should be initialized
7273
// to false.
73-
size_t select_aged_regions(const size_t old_promotion_reserve);
74+
size_t select_aged_regions(ShenandoahInPlacePromotionPlanner& in_place_promotions, const size_t old_promotion_reserve);
7475

7576
// Filter and sort remaining regions before adding to collection set.
76-
void filter_regions(ShenandoahCollectionSet* collection_set);
77+
void filter_regions(ShenandoahInPlacePromotionPlanner& in_place_promotions, ShenandoahCollectionSet* collection_set);
7778

7879
// Adjust evacuation budgets after choosing collection set. The argument regions_to_xfer
7980
// represents regions to be transferred to old based on decisions made in top_off_collection_set()
@@ -84,10 +85,6 @@ class ShenandoahGenerationalHeuristics : public ShenandoahAdaptiveHeuristics {
8485
ShenandoahGeneration* _generation;
8586

8687
size_t _add_regions_to_old;
87-
88-
size_t add_preselected_regions_to_collection_set(ShenandoahCollectionSet* cset,
89-
const RegionData* data,
90-
size_t size) const;
9188
};
9289

9390

src/hotspot/share/gc/shenandoah/heuristics/shenandoahGlobalHeuristics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void ShenandoahGlobalHeuristics::choose_global_collection_set(ShenandoahCollecti
127127
size_t cur_garbage = cur_young_garbage;
128128
for (size_t idx = 0; idx < size; idx++) {
129129
ShenandoahHeapRegion* r = data[idx].get_region();
130-
assert(!cset->is_preselected(r->index()), "There should be no preselected regions during GLOBAL GC");
130+
assert(!cset->is_in(r->index()), "Region (%zu) should not be in the collection set", r->index());
131131
bool add_region = false;
132132
size_t region_garbage = r->garbage();
133133
size_t new_garbage = cur_garbage + region_garbage;

src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,7 @@ void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collec
122122
}
123123
} else if (region->is_humongous_start()) {
124124
// Reclaim humongous regions here, and count them as the immediate garbage
125-
#ifdef ASSERT
126-
bool reg_live = region->has_live();
127-
bool bm_live = heap->global_generation()->complete_marking_context()->is_marked(cast_to_oop(region->bottom()));
128-
assert(reg_live == bm_live,
129-
"Humongous liveness and marks should agree. Region live: %s; Bitmap live: %s; Region Live Words: %zu",
130-
BOOL_TO_STR(reg_live), BOOL_TO_STR(bm_live), region->get_live_data_words());
131-
#endif
125+
DEBUG_ONLY(assert_humongous_mark_consistency(region));
132126
if (!region->has_live()) {
133127
heap->trash_humongous_region_at(region);
134128

@@ -137,21 +131,19 @@ void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collec
137131
immediate_garbage += garbage;
138132
}
139133
} else if (region->is_trash()) {
140-
// Count in just trashed collection set, during coalesced CM-with-UR
134+
// Count in just trashed humongous continuation regions
141135
immediate_regions++;
142136
immediate_garbage += garbage;
143137
}
144138
}
145139

146140
// Step 2. Look back at garbage statistics, and decide if we want to collect anything,
147141
// given the amount of immediately reclaimable garbage. If we do, figure out the collection set.
142+
assert(immediate_garbage <= total_garbage,
143+
"Cannot have more immediate garbage than total garbage: " PROPERFMT " vs " PROPERFMT,
144+
PROPERFMTARGS(immediate_garbage), PROPERFMTARGS(total_garbage));
148145

149-
assert (immediate_garbage <= total_garbage,
150-
"Cannot have more immediate garbage than total garbage: %zu%s vs %zu%s",
151-
byte_size_in_proper_unit(immediate_garbage), proper_unit_for_byte_size(immediate_garbage),
152-
byte_size_in_proper_unit(total_garbage), proper_unit_for_byte_size(total_garbage));
153-
154-
size_t immediate_percent = (total_garbage == 0) ? 0 : (immediate_garbage * 100 / total_garbage);
146+
const size_t immediate_percent = (total_garbage == 0) ? 0 : (immediate_garbage * 100 / total_garbage);
155147

156148
if (immediate_percent <= ShenandoahImmediateThreshold) {
157149
choose_collection_set_from_regiondata(collection_set, candidates, cand_idx, immediate_garbage + free);
@@ -303,3 +295,16 @@ double ShenandoahHeuristics::elapsed_degenerated_cycle_time() const {
303295
double now = os::elapsedTime();
304296
return now - _precursor_cycle_start;
305297
}
298+
299+
#ifdef ASSERT
300+
void ShenandoahHeuristics::assert_humongous_mark_consistency(ShenandoahHeapRegion* region) {
301+
assert(region->is_humongous(), "Region %zu must be humongous", region->index());
302+
const oop humongous_oop = cast_to_oop(region->bottom());
303+
ShenandoahGeneration* generation = ShenandoahHeap::heap()->generation_for(region->affiliation());
304+
const bool bm_live = generation->complete_marking_context()->is_marked(humongous_oop);
305+
const bool reg_live = region->has_live();
306+
assert(reg_live == bm_live,
307+
"Humongous liveness and marks should agree. Region live: %s; Bitmap live: %s; Region Live Words: %zu",
308+
BOOL_TO_STR(reg_live), BOOL_TO_STR(bm_live), region->get_live_data_words());
309+
}
310+
#endif

src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class ShenandoahHeuristics : public CHeapObj<mtGC> {
285285

286286
// Format prefix and emit log message indicating a GC cycle hs been triggered
287287
void log_trigger(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
288+
289+
DEBUG_ONLY(static void assert_humongous_mark_consistency(ShenandoahHeapRegion* region));
288290
};
289291

290292
#endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP

src/hotspot/share/gc/shenandoah/heuristics/shenandoahYoungHeuristics.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ void ShenandoahYoungHeuristics::choose_collection_set_from_regiondata(Shenandoah
5454
// Better select garbage-first regions
5555
QuickSort::sort<RegionData>(data, size, compare_by_garbage);
5656

57-
size_t cur_young_garbage = add_preselected_regions_to_collection_set(cset, data, size);
58-
59-
choose_young_collection_set(cset, data, size, actual_free, cur_young_garbage);
57+
choose_young_collection_set(cset, data, size, actual_free);
6058

6159
// Especially when young-gen trigger is expedited in order to finish mixed evacuations, there may not be
6260
// enough consolidated garbage to make effective use of young-gen evacuation reserve. If there is still
@@ -70,8 +68,7 @@ void ShenandoahYoungHeuristics::choose_collection_set_from_regiondata(Shenandoah
7068

7169
void ShenandoahYoungHeuristics::choose_young_collection_set(ShenandoahCollectionSet* cset,
7270
const RegionData* data,
73-
size_t size, size_t actual_free,
74-
size_t cur_young_garbage) const {
71+
size_t size, size_t actual_free) const {
7572

7673
const auto heap = ShenandoahGenerationalHeap::heap();
7774

@@ -82,23 +79,20 @@ void ShenandoahYoungHeuristics::choose_young_collection_set(ShenandoahCollection
8279
// This is young-gen collection or a mixed evacuation.
8380
// If this is mixed evacuation, the old-gen candidate regions have already been added.
8481
size_t cur_cset = 0;
82+
size_t cur_young_garbage = cset->garbage();
8583
const size_t max_cset = (size_t) (heap->young_generation()->get_evacuation_reserve() / ShenandoahEvacWaste);
8684
const size_t free_target = (capacity * ShenandoahMinFreeThreshold) / 100 + max_cset;
8785
const size_t min_garbage = (free_target > actual_free) ? (free_target - actual_free) : 0;
8886

89-
9087
log_info(gc, ergo)(
91-
"Adaptive CSet Selection for YOUNG. Max Evacuation: %zu%s, Actual Free: %zu%s.",
92-
byte_size_in_proper_unit(max_cset), proper_unit_for_byte_size(max_cset),
93-
byte_size_in_proper_unit(actual_free), proper_unit_for_byte_size(actual_free));
88+
"Adaptive CSet Selection for YOUNG. Max Evacuation: " PROPERFMT ", Actual Free: " PROPERFMT,
89+
PROPERFMTARGS(max_cset), PROPERFMTARGS(actual_free));
9490

9591
for (size_t idx = 0; idx < size; idx++) {
9692
ShenandoahHeapRegion* r = data[idx].get_region();
97-
if (cset->is_preselected(r->index())) {
98-
continue;
99-
}
93+
assert(!cset->is_in(r), "Region %zu should not already be in the collection set", idx);
10094

101-
// Note that we do not add tenurable regions if they were not pre-selected. They were not preselected
95+
// Note that we do not add tenurable regions if they were not pre-selected. They were not selected
10296
// because there is insufficient room in old-gen to hold their to-be-promoted live objects or because
10397
// they are to be promoted in place.
10498
if (!heap->is_tenurable(r)) {

src/hotspot/share/gc/shenandoah/heuristics/shenandoahYoungHeuristics.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class ShenandoahYoungHeuristics : public ShenandoahGenerationalHeuristics {
4949
private:
5050
void choose_young_collection_set(ShenandoahCollectionSet* cset,
5151
const RegionData* data,
52-
size_t size, size_t actual_free,
53-
size_t cur_young_garbage) const;
52+
size_t size, size_t actual_free) const;
5453

5554
};
5655

src/hotspot/share/gc/shenandoah/shenandoahCollectionSet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ ShenandoahCollectionSet::ShenandoahCollectionSet(ShenandoahHeap* heap, ReservedS
4949
_live(0),
5050
_region_count(0),
5151
_old_garbage(0),
52-
_preselected_regions(nullptr),
5352
_young_available_bytes_collected(0),
5453
_old_available_bytes_collected(0),
5554
_current_index(0) {

src/hotspot/share/gc/shenandoah/shenandoahCollectionSet.hpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@
3636

3737
class ShenandoahCollectionSet : public CHeapObj<mtGC> {
3838
friend class ShenandoahHeap;
39-
friend class ShenandoahCollectionSetPreselector;
40-
41-
void establish_preselected(bool *preselected) {
42-
assert(_preselected_regions == nullptr, "Over-writing");
43-
_preselected_regions = preselected;
44-
}
45-
void abandon_preselected() { _preselected_regions = nullptr; }
4639

4740
private:
4841
size_t const _map_size;
@@ -67,11 +60,6 @@ class ShenandoahCollectionSet : public CHeapObj<mtGC> {
6760
// How many bytes of old garbage are present in a mixed collection set?
6861
size_t _old_garbage;
6962

70-
// Points to array identifying which tenure-age regions have been preselected
71-
// for inclusion in collection set. This field is only valid during brief
72-
// spans of time while collection set is being constructed.
73-
bool* _preselected_regions;
74-
7563
// When a region having memory available to be allocated is added to the collection set, the region's available memory
7664
// should be subtracted from what's available.
7765
size_t _young_available_bytes_collected;
@@ -132,16 +120,6 @@ class ShenandoahCollectionSet : public CHeapObj<mtGC> {
132120
// Returns the amount of garbage in old regions in the collection set.
133121
inline size_t get_old_garbage() const;
134122

135-
bool is_preselected(size_t region_idx) {
136-
assert(_preselected_regions != nullptr, "Missing establish after abandon");
137-
return _preselected_regions[region_idx];
138-
}
139-
140-
bool* preselected_regions() {
141-
assert(_preselected_regions != nullptr, "Null ptr");
142-
return _preselected_regions;
143-
}
144-
145123
bool has_old_regions() const { return _has_old_regions; }
146124
size_t used() const { return _used; }
147125
size_t live() const { return _live; }

src/hotspot/share/gc/shenandoah/shenandoahCollectionSetPreselector.hpp

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)