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

Print this page

        

@@ -1772,10 +1772,18 @@
   if (result != NULL) {
     assert(*succeeded, "sanity");
     return result;
   }
 
+  // We may shrink heap too much after full gc.
+  // Expand heap will help - JDK-8130265
+  result = expand_and_allocate(word_size, context);
+  if (result != NULL) {
+    assert(*succeeded, "sanity");
+    return result;
+  }
+
   // Then, try a Full GC that will collect all soft references.
   gc_succeeded = do_collection(false, /* explicit_gc */
                                true,  /* clear_all_soft_refs */
                                word_size);
   if (!gc_succeeded) {

@@ -1793,10 +1801,17 @@
   }
 
   assert(!collector_policy()->should_clear_all_soft_refs(),
          "Flag should have been handled and cleared prior to this point");
 
+  // Retry expand_and_allocate once more
+  result = expand_and_allocate(word_size, context);
+  if (result != NULL) {
+    assert(*succeeded, "sanity");
+    return result;
+  }
+
   // What else?  We might try synchronous finalization later.  If the total
   // space available is large enough for the allocation, then a more
   // complete compaction phase than we've tried so far might be
   // appropriate.
   assert(*succeeded, "sanity");