Skip to content

Commit 2902436

Browse files
committed
8371019: G1: Support heap expansion during startup
Reviewed-by: eosterlund, tschatzl
1 parent 2910032 commit 2902436

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,13 @@ G1HeapRegion* G1CollectedHeap::new_region(size_t word_size,
185185
G1HeapRegion* res = _hrm.allocate_free_region(type, node_index);
186186

187187
if (res == nullptr && do_expand) {
188-
// Currently, only attempts to allocate GC alloc regions set
189-
// do_expand to true. So, we should only reach here during a
190-
// safepoint.
191-
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
188+
// There are two situations where do_expand is set to true:
189+
// - for mutator regions during initialization
190+
// - for GC alloc regions during a safepoint
191+
// Make sure we only reach here before initialization is complete
192+
// or during a safepoint.
193+
assert(!is_init_completed() ||
194+
SafepointSynchronize::is_at_safepoint() , "invariant");
192195

193196
log_debug(gc, ergo, heap)("Attempt heap expansion (region allocation request failed). Allocation request: %zuB",
194197
word_size * HeapWordSize);
@@ -3101,7 +3104,7 @@ G1HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size,
31013104
if (should_allocate) {
31023105
G1HeapRegion* new_alloc_region = new_region(word_size,
31033106
G1HeapRegionType::Eden,
3104-
false /* do_expand */,
3107+
policy()->should_expand_on_mutator_allocation() /* do_expand */,
31053108
node_index);
31063109
if (new_alloc_region != nullptr) {
31073110
new_alloc_region->set_eden();

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,21 @@ double G1Policy::predict_region_code_root_scan_time(G1HeapRegion* hr, bool for_y
11871187
}
11881188

11891189
bool G1Policy::should_allocate_mutator_region() const {
1190-
uint young_list_length = _g1h->young_regions_count();
1191-
return young_list_length < young_list_target_length();
1190+
if (_g1h->young_regions_count() < young_list_target_length()) {
1191+
return true;
1192+
}
1193+
1194+
if (should_expand_on_mutator_allocation()) {
1195+
return true;
1196+
}
1197+
1198+
return false;
1199+
}
1200+
1201+
bool G1Policy::should_expand_on_mutator_allocation() const {
1202+
// We can't do a GC during init so allow additional mutator
1203+
// allocations until we can GC.
1204+
return !is_init_completed();
11921205
}
11931206

11941207
bool G1Policy::use_adaptive_young_list_length() const {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ class G1Policy: public CHeapObj<mtGC> {
367367
uint young_list_target_length() const { return AtomicAccess::load(&_young_list_target_length); }
368368

369369
bool should_allocate_mutator_region() const;
370+
bool should_expand_on_mutator_allocation() const;
370371

371372
bool use_adaptive_young_list_length() const;
372373

0 commit comments

Comments
 (0)