8072913: [REDO] GCCause should distinguish jcmd GC.run from System.gc()
authorysuenaga
Wed, 03 Jun 2015 08:49:34 +0900
changeset 31032 8e72621ca186
parent 31031 d0b85f02898f
child 31033 5b6d0c94767a
8072913: [REDO] GCCause should distinguish jcmd GC.run from System.gc() Summary: GCCause which is caused by GC.run diagnostic command should be different from System.gc() . Reviewed-by: jmasa, jwilhelm
hotspot/src/share/vm/gc/cms/vmCMSOperations.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp
hotspot/src/share/vm/gc/g1/vm_operations_g1.cpp
hotspot/src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp
hotspot/src/share/vm/gc/parallel/psMarkSweep.cpp
hotspot/src/share/vm/gc/parallel/psParallelCompact.cpp
hotspot/src/share/vm/gc/parallel/psScavenge.cpp
hotspot/src/share/vm/gc/serial/defNewGeneration.cpp
hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.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/services/diagnosticCommand.cpp
hotspot/test/serviceability/dcmd/gc/RunGCTest.java
--- a/hotspot/src/share/vm/gc/cms/vmCMSOperations.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/cms/vmCMSOperations.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -254,9 +254,9 @@
   if (_gc_cause != GCCause::_gc_locker &&
       gch->total_full_collections_completed() <= _full_gc_count_before) {
     // maybe we should change the condition to test _gc_cause ==
-    // GCCause::_java_lang_system_gc, instead of
-    // _gc_cause != GCCause::_gc_locker
-    assert(_gc_cause == GCCause::_java_lang_system_gc,
+    // GCCause::_java_lang_system_gc or GCCause::_dcmd_gc_run,
+    // instead of _gc_cause != GCCause::_gc_locker
+    assert(GCCause::is_user_requested_gc(_gc_cause),
            "the only way to get here if this was a System.gc()-induced GC");
     assert(ExplicitGCInvokesConcurrent, "Error");
     // Now, wait for witnessing concurrent gc cycle to complete,
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -1183,7 +1183,7 @@
     IsGCActiveMark x;
 
     // Timing
-    assert(gc_cause() != GCCause::_java_lang_system_gc || explicit_gc, "invariant");
+    assert(!GCCause::is_user_requested_gc(gc_cause()) || explicit_gc, "invariant");
     TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty);
 
     {
@@ -2199,6 +2199,7 @@
   switch (cause) {
     case GCCause::_gc_locker:               return GCLockerInvokesConcurrent;
     case GCCause::_java_lang_system_gc:     return ExplicitGCInvokesConcurrent;
+    case GCCause::_dcmd_gc_run:             return ExplicitGCInvokesConcurrent;
     case GCCause::_g1_humongous_allocation: return true;
     case GCCause::_update_allocation_context_stats_inc: return true;
     case GCCause::_wb_conc_mark:            return true;
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Wed Jun 03 08:49:34 2015 +0900
@@ -324,7 +324,8 @@
   // explicitly started if:
   // (a) cause == _gc_locker and +GCLockerInvokesConcurrent, or
   // (b) cause == _java_lang_system_gc and +ExplicitGCInvokesConcurrent.
-  // (c) cause == _g1_humongous_allocation
+  // (c) cause == _dcmd_gc_run and +ExplicitGCInvokesConcurrent.
+  // (d) cause == _g1_humongous_allocation
   bool should_do_concurrent_full_gc(GCCause::Cause cause);
 
   // Keeps track of how many "old marking cycles" (i.e., Full GCs or
--- a/hotspot/src/share/vm/gc/g1/vm_operations_g1.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/vm_operations_g1.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -168,7 +168,7 @@
   // +ExplicitGCInvokesConcurrent, we have to wait here for the cycle
   // that just started (or maybe one that was already in progress) to
   // finish.
-  if (_gc_cause == GCCause::_java_lang_system_gc &&
+  if (GCCause::is_user_requested_gc(_gc_cause) &&
       _should_initiate_conc_mark) {
     assert(ExplicitGCInvokesConcurrent,
            "the only way to be here is if ExplicitGCInvokesConcurrent is set");
--- a/hotspot/src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -130,7 +130,7 @@
   // Update the pause time.
   _major_timer.stop();
 
-  if (gc_cause != GCCause::_java_lang_system_gc ||
+  if (!GCCause::is_user_requested_gc(gc_cause) ||
       UseAdaptiveSizePolicyWithSystemGC) {
     double major_pause_in_seconds = _major_timer.seconds();
     double major_pause_in_ms = major_pause_in_seconds * MILLIUNITS;
--- a/hotspot/src/share/vm/gc/parallel/psMarkSweep.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/parallel/psMarkSweep.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -272,7 +272,7 @@
       // Don't check if the size_policy is ready here.  Let
       // the size_policy check that internally.
       if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
-          ((gc_cause != GCCause::_java_lang_system_gc) ||
+          (!GCCause::is_user_requested_gc(gc_cause) ||
             UseAdaptiveSizePolicyWithSystemGC)) {
         // Swap the survivor spaces if from_space is empty. The
         // resize_young_gen() called below is normally used after
--- a/hotspot/src/share/vm/gc/parallel/psParallelCompact.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/parallel/psParallelCompact.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -2053,7 +2053,7 @@
     marking_phase(vmthread_cm, maximum_heap_compaction, &_gc_tracer);
 
     bool max_on_system_gc = UseMaximumCompactionOnSystemGC
-      && gc_cause == GCCause::_java_lang_system_gc;
+      && GCCause::is_user_requested_gc(gc_cause);
     summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc);
 
     COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity"));
@@ -2089,7 +2089,7 @@
       // Don't check if the size_policy is ready here.  Let
       // the size_policy check that internally.
       if (UseAdaptiveGenerationSizePolicyAtMajorCollection &&
-          ((gc_cause != GCCause::_java_lang_system_gc) ||
+          (!GCCause::is_user_requested_gc(gc_cause) ||
             UseAdaptiveSizePolicyWithSystemGC)) {
         // Swap the survivor spaces if from_space is empty. The
         // resize_young_gen() called below is normally used after
--- a/hotspot/src/share/vm/gc/parallel/psScavenge.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/parallel/psScavenge.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -290,7 +290,7 @@
 
   AdaptiveSizePolicyOutput(size_policy, heap->total_collections());
 
-  if ((gc_cause != GCCause::_java_lang_system_gc) ||
+  if (!GCCause::is_user_requested_gc(gc_cause) ||
        UseAdaptiveSizePolicyWithSystemGC) {
     // Gather the feedback data for eden occupancy.
     young_gen->eden_space()->accumulate_statistics();
--- a/hotspot/src/share/vm/gc/serial/defNewGeneration.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/serial/defNewGeneration.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -960,7 +960,7 @@
                             GCCause::to_string(gch->gc_cause()));
       }
       assert(gch->gc_cause() == GCCause::_scavenge_alot ||
-             (gch->gc_cause() == GCCause::_java_lang_system_gc && UseConcMarkSweepGC && ExplicitGCInvokesConcurrent) ||
+             (GCCause::is_user_requested_gc(gch->gc_cause()) && UseConcMarkSweepGC && ExplicitGCInvokesConcurrent) ||
              !gch->incremental_collection_failed(),
              "Twice in a row");
       seen_incremental_collection_failed = false;
--- a/hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/shared/adaptiveSizePolicy.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -244,7 +244,7 @@
   // Update the pause time.
   _minor_timer.stop();
 
-  if (gc_cause != GCCause::_java_lang_system_gc ||
+  if (!GCCause::is_user_requested_gc(gc_cause) ||
       UseAdaptiveSizePolicyWithSystemGC) {
     double minor_pause_in_seconds = _minor_timer.seconds();
     double minor_pause_in_ms = minor_pause_in_seconds * MILLIUNITS;
--- a/hotspot/src/share/vm/gc/shared/gcCause.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/shared/gcCause.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -103,6 +103,9 @@
     case _last_ditch_collection:
       return "Last ditch collection";
 
+    case _dcmd_gc_run:
+      return "Diagnostic Command";
+
     case _last_gc_cause:
       return "ILLEGAL VALUE - last gc cause - ILLEGAL VALUE";
 
--- a/hotspot/src/share/vm/gc/shared/gcCause.hpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/shared/gcCause.hpp	Wed Jun 03 08:49:34 2015 +0900
@@ -74,12 +74,15 @@
     _g1_humongous_allocation,
 
     _last_ditch_collection,
+
+    _dcmd_gc_run,
+
     _last_gc_cause
   };
 
   inline static bool is_user_requested_gc(GCCause::Cause cause) {
     return (cause == GCCause::_java_lang_system_gc ||
-            cause == GCCause::_jvmti_force_gc);
+            cause == GCCause::_dcmd_gc_run);
   }
 
   inline static bool is_serviceability_requested_gc(GCCause::Cause
--- a/hotspot/src/share/vm/gc/shared/genCollectedHeap.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/gc/shared/genCollectedHeap.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -304,9 +304,16 @@
 }
 
 bool GenCollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
-  return UseConcMarkSweepGC &&
-         ((cause == GCCause::_gc_locker && GCLockerInvokesConcurrent) ||
-          (cause == GCCause::_java_lang_system_gc && ExplicitGCInvokesConcurrent));
+  if (!UseConcMarkSweepGC) {
+    return false;
+  }
+
+  switch (cause) {
+    case GCCause::_gc_locker:           return GCLockerInvokesConcurrent;
+    case GCCause::_java_lang_system_gc:
+    case GCCause::_dcmd_gc_run:         return ExplicitGCInvokesConcurrent;
+    default:                            return false;
+  }
 }
 
 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
--- a/hotspot/src/share/vm/services/diagnosticCommand.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/src/share/vm/services/diagnosticCommand.cpp	Wed Jun 03 08:49:34 2015 +0900
@@ -315,7 +315,7 @@
 
 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
   if (!DisableExplicitGC) {
-    Universe::heap()->collect(GCCause::_java_lang_system_gc);
+    Universe::heap()->collect(GCCause::_dcmd_gc_run);
   } else {
     output()->print_cr("Explicit GC is disabled, no GC has been performed.");
   }
--- a/hotspot/test/serviceability/dcmd/gc/RunGCTest.java	Wed Jun 03 13:29:53 2015 +0200
+++ b/hotspot/test/serviceability/dcmd/gc/RunGCTest.java	Wed Jun 03 08:49:34 2015 +0900
@@ -59,7 +59,7 @@
         }
 
         OutputAnalyzer output = new OutputAnalyzer(gcLog, "");
-        output.shouldMatch(".*\\[Full GC \\(System(\\.gc\\(\\))?.*");
+        output.shouldContain("[Full GC (Diagnostic Command)");
     }
 
     @Test