Skip to content

Commit ad01dfb

Browse files
committed
8346920: Serial: Support allocation in old generation when heap is almost full
Reviewed-by: tschatzl, gli, sjohanss
1 parent 1d8ccb8 commit ad01dfb

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/hotspot/share/gc/serial/serialHeap.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ SerialHeap::SerialHeap() :
9595
_gc_policy_counters(new GCPolicyCounters("Copy:MSC", 2, 2)),
9696
_young_manager(nullptr),
9797
_old_manager(nullptr),
98+
_is_heap_almost_full(false),
9899
_eden_pool(nullptr),
99100
_survivor_pool(nullptr),
100101
_old_pool(nullptr) {
@@ -282,13 +283,12 @@ size_t SerialHeap::max_capacity() const {
282283
// Return true if any of the following is true:
283284
// . the allocation won't fit into the current young gen heap
284285
// . gc locker is occupied (jni critical section)
285-
// . heap memory is tight -- the most recent previous collection
286-
// was a full collection because a partial collection (would
287-
// have) failed and is likely to fail again
286+
// . heap memory is tight
288287
bool SerialHeap::should_try_older_generation_allocation(size_t word_size) const {
289288
size_t young_capacity = _young_gen->capacity_before_gc();
290289
return (word_size > heap_word_size(young_capacity))
291-
|| GCLocker::is_active_and_needs_gc();
290+
|| GCLocker::is_active_and_needs_gc()
291+
|| _is_heap_almost_full;
292292
}
293293

294294
HeapWord* SerialHeap::expand_heap_and_allocate(size_t size, bool is_tlab) {
@@ -951,5 +951,18 @@ void SerialHeap::gc_epilogue(bool full) {
951951
_young_gen->gc_epilogue(full);
952952
_old_gen->gc_epilogue();
953953

954+
if (_is_heap_almost_full) {
955+
// Reset the emergency state if eden is empty after a young/full gc
956+
if (_young_gen->eden()->is_empty()) {
957+
_is_heap_almost_full = false;
958+
}
959+
} else {
960+
if (full && !_young_gen->eden()->is_empty()) {
961+
// Usually eden should be empty after a full GC, so heap is probably too
962+
// full now; entering emergency state.
963+
_is_heap_almost_full = true;
964+
}
965+
}
966+
954967
MetaspaceCounters::update_performance_counters();
955968
};

src/hotspot/share/gc/serial/serialHeap.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ class SerialHeap : public CollectedHeap {
9595
GCMemoryManager* _young_manager;
9696
GCMemoryManager* _old_manager;
9797

98+
// Indicate whether heap is almost or approaching full.
99+
// Usually, there is some memory headroom for application/gc to run properly.
100+
// However, in extreme cases, e.g. young-gen is non-empty after a full gc, we
101+
// will attempt some uncommon measures, e.g. alllocating small objs in
102+
// old-gen.
103+
bool _is_heap_almost_full;
104+
98105
// Helper functions for allocation
99106
HeapWord* attempt_allocation(size_t size,
100107
bool is_tlab,

0 commit comments

Comments
 (0)