8152113: Remove _last_ditch_collection GC-cause and avoid expanding heap on Metaspace OOM
authorsjohanss
Fri, 18 Mar 2016 13:18:58 +0100
changeset 37149 f025738bbada
parent 37148 042294ceef52
child 37150 c415c138fada
8152113: Remove _last_ditch_collection GC-cause and avoid expanding heap on Metaspace OOM Reviewed-by: brutisso, jwilhelm
hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GCCause.java
hotspot/src/share/vm/gc/shared/collectedHeap.cpp
hotspot/src/share/vm/gc/shared/gcCause.cpp
hotspot/src/share/vm/gc/shared/gcCause.hpp
hotspot/src/share/vm/gc/shared/genCollectedHeap.cpp
hotspot/src/share/vm/gc/shared/vmGCOperations.cpp
hotspot/src/share/vm/prims/whitebox.cpp
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GCCause.java	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/GCCause.java	Fri Mar 18 13:18:58 2016 +0100
@@ -37,6 +37,7 @@
   _heap_dump ("Heap Dump Initiated GC"),
   _wb_young_gc ("WhiteBox Initiated Young GC"),
   _wb_conc_mark ("WhiteBox Initiated Concurrent Mark"),
+  _wb_full_gc ("WhiteBox Initiated Full GC"),
   _update_allocation_context_stats_inc ("Update Allocation Context Stats"),
   _update_allocation_context_stats_full ("Update Allocation Context Stats"),
 
@@ -46,6 +47,7 @@
 
   _tenured_generation_full ("Tenured Generation Full"),
   _metadata_GC_threshold ("Metadata GC Threshold"),
+  _metadata_GC_clear_soft_refs ("Metadata GC Clear Soft References"),
 
   _cms_generation_full ("CMS Generation Full"),
   _cms_initial_mark ("CMS Initial Mark"),
@@ -59,8 +61,6 @@
   _g1_inc_collection_pause ("G1 Evacuation Pause"),
   _g1_humongous_allocation ("G1 Humongous Allocation"),
 
-  _last_ditch_collection ("Last ditch collection"),
-
   _dcmd_gc_run ("Diagnostic Command"),
 
   _last_gc_cause ("ILLEGAL VALUE - last gc cause - ILLEGAL VALUE");
--- a/hotspot/src/share/vm/gc/shared/collectedHeap.cpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/gc/shared/collectedHeap.cpp	Fri Mar 18 13:18:58 2016 +0100
@@ -213,7 +213,7 @@
       do_full_collection(false);        // don't clear all soft refs
       break;
     }
-    case GCCause::_last_ditch_collection: {
+    case GCCause::_metadata_GC_clear_soft_refs: {
       HandleMark hm;
       do_full_collection(true);         // do clear all soft refs
       break;
--- a/hotspot/src/share/vm/gc/shared/gcCause.cpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/gc/shared/gcCause.cpp	Fri Mar 18 13:18:58 2016 +0100
@@ -57,6 +57,9 @@
     case _wb_conc_mark:
       return "WhiteBox Initiated Concurrent Mark";
 
+    case _wb_full_gc:
+      return "WhiteBox Initiated Full GC";
+
     case _update_allocation_context_stats_inc:
     case _update_allocation_context_stats_full:
       return "Update Allocation Context Stats";
@@ -73,6 +76,9 @@
     case _metadata_GC_threshold:
       return "Metadata GC Threshold";
 
+    case _metadata_GC_clear_soft_refs:
+      return "Metadata GC Clear Soft References";
+
     case _cms_generation_full:
       return "CMS Generation Full";
 
@@ -100,9 +106,6 @@
     case _g1_humongous_allocation:
       return "G1 Humongous Allocation";
 
-    case _last_ditch_collection:
-      return "Last ditch collection";
-
     case _dcmd_gc_run:
       return "Diagnostic Command";
 
--- a/hotspot/src/share/vm/gc/shared/gcCause.hpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/gc/shared/gcCause.hpp	Fri Mar 18 13:18:58 2016 +0100
@@ -51,6 +51,7 @@
     _heap_dump,
     _wb_young_gc,
     _wb_conc_mark,
+    _wb_full_gc,
     _update_allocation_context_stats_inc,
     _update_allocation_context_stats_full,
 
@@ -63,6 +64,7 @@
 
     _tenured_generation_full,
     _metadata_GC_threshold,
+    _metadata_GC_clear_soft_refs,
 
     _cms_generation_full,
     _cms_initial_mark,
@@ -76,8 +78,6 @@
     _g1_inc_collection_pause,
     _g1_humongous_allocation,
 
-    _last_ditch_collection,
-
     _dcmd_gc_run,
 
     _last_gc_cause
@@ -106,22 +106,18 @@
     // _allocation_failure is the generic cause a collection which could result
     // in the collection of the tenured generation if there is not enough space
     // in the tenured generation to support a young GC.
-    // _last_ditch_collection is a collection done to include SoftReferences.
     return (cause == GCCause::_tenured_generation_full ||
             cause == GCCause::_cms_generation_full ||
             cause == GCCause::_adaptive_size_policy ||
-            cause == GCCause::_allocation_failure ||
-            cause == GCCause::_last_ditch_collection);
+            cause == GCCause::_allocation_failure);
   }
 
   // Causes for collection of the young generation
   inline static bool is_allocation_failure_gc(GCCause::Cause cause) {
     // _allocation_failure is the generic cause a collection for allocation failure
     // _adaptive_size_policy is for a collecton done before a full GC
-    // _last_ditch_collection is a collection done to include SoftReferences.
     return (cause == GCCause::_allocation_failure ||
-            cause == GCCause::_adaptive_size_policy ||
-            cause == GCCause::_last_ditch_collection);
+            cause == GCCause::_adaptive_size_policy);
   }
 
   // Return a string describing the GCCause.
--- a/hotspot/src/share/vm/gc/shared/genCollectedHeap.cpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/gc/shared/genCollectedHeap.cpp	Fri Mar 18 13:18:58 2016 +0100
@@ -295,7 +295,8 @@
 }
 
 bool GenCollectedHeap::must_clear_all_soft_refs() {
-  return _gc_cause == GCCause::_last_ditch_collection;
+  return _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
+         _gc_cause == GCCause::_wb_full_gc;
 }
 
 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
--- a/hotspot/src/share/vm/gc/shared/vmGCOperations.cpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/gc/shared/vmGCOperations.cpp	Fri Mar 18 13:18:58 2016 +0100
@@ -271,12 +271,8 @@
     return;
   }
 
-  // If expansion failed, do a last-ditch collection and try allocating
-  // again.  A last-ditch collection will clear softrefs.  This
-  // behavior is similar to the last-ditch collection done for perm
-  // gen when it was full and a collection for failed allocation
-  // did not free perm gen space.
-  heap->collect_as_vm_thread(GCCause::_last_ditch_collection);
+  // If expansion failed, do a collection clearing soft references.
+  heap->collect_as_vm_thread(GCCause::_metadata_GC_clear_soft_refs);
   _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
   if (_result != NULL) {
     return;
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Fri Mar 18 11:42:32 2016 +0100
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Fri Mar 18 13:18:58 2016 +0100
@@ -987,7 +987,7 @@
 
 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
-  Universe::heap()->collect(GCCause::_last_ditch_collection);
+  Universe::heap()->collect(GCCause::_wb_full_gc);
 #if INCLUDE_ALL_GCS
   if (UseG1GC) {
     // Needs to be cleared explicitly for G1