@@ -95,6 +95,7 @@ SerialHeap::SerialHeap() :
95
95
_gc_policy_counters(new GCPolicyCounters(" Copy:MSC" , 2 , 2 )),
96
96
_young_manager(nullptr ),
97
97
_old_manager(nullptr ),
98
+ _is_heap_almost_full(false ),
98
99
_eden_pool(nullptr ),
99
100
_survivor_pool(nullptr ),
100
101
_old_pool(nullptr ) {
@@ -282,13 +283,12 @@ size_t SerialHeap::max_capacity() const {
282
283
// Return true if any of the following is true:
283
284
// . the allocation won't fit into the current young gen heap
284
285
// . 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
288
287
bool SerialHeap::should_try_older_generation_allocation (size_t word_size) const {
289
288
size_t young_capacity = _young_gen->capacity_before_gc ();
290
289
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;
292
292
}
293
293
294
294
HeapWord* SerialHeap::expand_heap_and_allocate (size_t size, bool is_tlab) {
@@ -951,5 +951,18 @@ void SerialHeap::gc_epilogue(bool full) {
951
951
_young_gen->gc_epilogue (full);
952
952
_old_gen->gc_epilogue ();
953
953
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
+
954
967
MetaspaceCounters::update_performance_counters ();
955
968
};
0 commit comments