changeset 8479:f08536ebf811

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
author ysuenaga
date Wed, 03 Jun 2015 08:49:34 +0900
parents bf8bc7afe941
children 41e47efcd333
files src/share/vm/gc/cms/vmCMSOperations.cpp src/share/vm/gc/g1/g1CollectedHeap.cpp src/share/vm/gc/g1/g1CollectedHeap.hpp src/share/vm/gc/g1/vm_operations_g1.cpp src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp src/share/vm/gc/parallel/psMarkSweep.cpp src/share/vm/gc/parallel/psParallelCompact.cpp src/share/vm/gc/parallel/psScavenge.cpp src/share/vm/gc/serial/defNewGeneration.cpp src/share/vm/gc/shared/adaptiveSizePolicy.cpp src/share/vm/gc/shared/gcCause.cpp src/share/vm/gc/shared/gcCause.hpp src/share/vm/gc/shared/genCollectedHeap.cpp src/share/vm/services/diagnosticCommand.cpp test/serviceability/dcmd/gc/RunGCTest.java
diffstat 15 files changed, 34 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc/cms/vmCMSOperations.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/g1/g1CollectedHeap.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/g1/g1CollectedHeap.hpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/g1/vm_operations_g1.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/parallel/psMarkSweep.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/parallel/psParallelCompact.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/parallel/psScavenge.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/serial/defNewGeneration.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/shared/adaptiveSizePolicy.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/shared/gcCause.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/shared/gcCause.hpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/gc/shared/genCollectedHeap.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/src/share/vm/services/diagnosticCommand.cpp	Wed Jun 03 13:29:53 2015 +0200
+++ b/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/test/serviceability/dcmd/gc/RunGCTest.java	Wed Jun 03 13:29:53 2015 +0200
+++ b/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