@@ -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
288287bool 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
294294HeapWord* 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};
0 commit comments