Skip to content

Commit cd1751c

Browse files
author
Ivan Walulya
committedAug 11, 2021
8271884: G1CH::_expand_heap_after_alloc_failure is no longer needed
Reviewed-by: kbarrett, tschatzl
1 parent 3f723ca commit cd1751c

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed
 

‎src/hotspot/share/gc/g1/g1Allocator.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,16 @@ HeapWord* G1Allocator::survivor_attempt_allocation(size_t min_word_size,
248248
actual_word_size);
249249
if (result == NULL && !survivor_is_full()) {
250250
MutexLocker x(FreeList_lock, Mutex::_no_safepoint_check_flag);
251-
result = survivor_gc_alloc_region(node_index)->attempt_allocation_locked(min_word_size,
252-
desired_word_size,
253-
actual_word_size);
254-
if (result == NULL) {
255-
set_survivor_full();
251+
// Multiple threads may have queued at the FreeList_lock above after checking whether there
252+
// actually is still memory available. Redo the check under the lock to avoid unnecessary work;
253+
// the memory may have been used up as the threads waited to acquire the lock.
254+
if (!survivor_is_full()) {
255+
result = survivor_gc_alloc_region(node_index)->attempt_allocation_locked(min_word_size,
256+
desired_word_size,
257+
actual_word_size);
258+
if (result == NULL) {
259+
set_survivor_full();
260+
}
256261
}
257262
}
258263
if (result != NULL) {
@@ -272,11 +277,16 @@ HeapWord* G1Allocator::old_attempt_allocation(size_t min_word_size,
272277
actual_word_size);
273278
if (result == NULL && !old_is_full()) {
274279
MutexLocker x(FreeList_lock, Mutex::_no_safepoint_check_flag);
275-
result = old_gc_alloc_region()->attempt_allocation_locked(min_word_size,
276-
desired_word_size,
277-
actual_word_size);
278-
if (result == NULL) {
279-
set_old_full();
280+
// Multiple threads may have queued at the FreeList_lock above after checking whether there
281+
// actually is still memory available. Redo the check under the lock to avoid unnecessary work;
282+
// the memory may have been used up as the threads waited to acquire the lock.
283+
if (!old_is_full()) {
284+
result = old_gc_alloc_region()->attempt_allocation_locked(min_word_size,
285+
desired_word_size,
286+
actual_word_size);
287+
if (result == NULL) {
288+
set_old_full();
289+
}
280290
}
281291
}
282292
return result;

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ HeapRegion* G1CollectedHeap::new_region(size_t word_size,
164164

165165
HeapRegion* res = _hrm.allocate_free_region(type, node_index);
166166

167-
if (res == NULL && do_expand && _expand_heap_after_alloc_failure) {
167+
if (res == NULL && do_expand) {
168168
// Currently, only attempts to allocate GC alloc regions set
169169
// do_expand to true. So, we should only reach here during a
170-
// safepoint. If this assumption changes we might have to
171-
// reconsider the use of _expand_heap_after_alloc_failure.
170+
// safepoint.
172171
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
173172

174173
log_debug(gc, ergo, heap)("Attempt heap expansion (region allocation request failed). Allocation request: " SIZE_FORMAT "B",
@@ -183,8 +182,6 @@ HeapRegion* G1CollectedHeap::new_region(size_t word_size,
183182
// region size, the free list should in theory not be empty.
184183
// In either case allocate_free_region() will check for NULL.
185184
res = _hrm.allocate_free_region(type, node_index);
186-
} else {
187-
_expand_heap_after_alloc_failure = false;
188185
}
189186
}
190187
return res;
@@ -1456,7 +1453,6 @@ G1CollectedHeap::G1CollectedHeap() :
14561453
_archive_allocator(NULL),
14571454
_survivor_evac_stats("Young", YoungPLABSize, PLABWeight),
14581455
_old_evac_stats("Old", OldPLABSize, PLABWeight),
1459-
_expand_heap_after_alloc_failure(true),
14601456
_monitoring_support(nullptr),
14611457
_humongous_reclaim_candidates(),
14621458
_num_humongous_objects(0),
@@ -3518,7 +3514,6 @@ void G1CollectedHeap::pre_evacuate_collection_set(G1EvacuationInfo* evacuation_i
35183514

35193515
_bytes_used_during_gc = 0;
35203516

3521-
_expand_heap_after_alloc_failure = true;
35223517
Atomic::store(&_num_regions_failed_evacuation, 0u);
35233518

35243519
gc_prologue(false);

‎src/hotspot/share/gc/g1/g1CollectedHeap.hpp

-8
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,6 @@ class G1CollectedHeap : public CollectedHeap {
240240
// GC allocation statistics policy for tenured objects.
241241
G1EvacStats _old_evac_stats;
242242

243-
// It specifies whether we should attempt to expand the heap after a
244-
// region allocation failure. If heap expansion fails we set this to
245-
// false so that we don't re-attempt the heap expansion (it's likely
246-
// that subsequent expansion attempts will also fail if one fails).
247-
// Currently, it is only consulted during GC and it's reset at the
248-
// start of each GC.
249-
bool _expand_heap_after_alloc_failure;
250-
251243
// Helper for monitoring and management support.
252244
G1MonitoringSupport* _monitoring_support;
253245

0 commit comments

Comments
 (0)
Please sign in to comment.