7163848: G1: Log GC Cause for a GC
authorbrutisso
Wed, 25 Apr 2012 12:36:37 +0200
changeset 12511 24c75d495b2f
parent 12510 c61257b7c7b6
child 12512 5898965fd407
7163848: G1: Log GC Cause for a GC Reviewed-by: johnc, jwilhelm, jmasa
hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Wed Apr 25 15:51:10 2012 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp	Wed Apr 25 12:36:37 2012 +0200
@@ -1248,12 +1248,13 @@
     IsGCActiveMark x;
 
     // Timing
-    bool system_gc = (gc_cause() == GCCause::_java_lang_system_gc);
-    assert(!system_gc || explicit_gc, "invariant");
+    assert(gc_cause() != GCCause::_java_lang_system_gc || explicit_gc, "invariant");
     gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps);
     TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty);
-    TraceTime t(system_gc ? "Full GC (System.gc())" : "Full GC",
-                G1Log::fine(), true, gclog_or_tty);
+
+    char verbose_str[128];
+    sprintf(verbose_str, "Full GC (%s)", GCCause::to_string(gc_cause()));
+    TraceTime t(verbose_str, G1Log::fine(), true, gclog_or_tty);
 
     TraceCollectorStats tcs(g1mm()->full_collection_counters());
     TraceMemoryManagerStats tms(true /* fullGC */, gc_cause());
@@ -3588,25 +3589,22 @@
 
   // Inner scope for scope based logging, timers, and stats collection
   {
-    char verbose_str[128];
-    sprintf(verbose_str, "GC pause ");
-    if (g1_policy()->gcs_are_young()) {
-      strcat(verbose_str, "(young)");
-    } else {
-      strcat(verbose_str, "(mixed)");
-    }
     if (g1_policy()->during_initial_mark_pause()) {
-      strcat(verbose_str, " (initial-mark)");
       // We are about to start a marking cycle, so we increment the
       // full collection counter.
       increment_total_full_collections();
     }
-
     // if the log level is "finer" is on, we'll print long statistics information
     // in the collector policy code, so let's not print this as the output
     // is messy if we do.
     gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps);
     TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty);
+
+    char verbose_str[128];
+    sprintf(verbose_str, "GC pause (%s) (%s)%s",
+      GCCause::to_string(gc_cause()),
+      g1_policy()->gcs_are_young() ? "young" : "mixed",
+      g1_policy()->during_initial_mark_pause() ? " (initial-mark)" : "");
     TraceTime t(verbose_str, G1Log::fine() && !G1Log::finer(), true, gclog_or_tty);
 
     TraceCollectorStats tcs(g1mm()->incremental_collection_counters());
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp	Wed Apr 25 15:51:10 2012 -0700
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp	Wed Apr 25 12:36:37 2012 +0200
@@ -886,8 +886,9 @@
                                                       size_t start_used) {
   if (G1Log::finer()) {
     gclog_or_tty->stamp(PrintGCTimeStamps);
-    gclog_or_tty->print("[GC pause");
-    gclog_or_tty->print(" (%s)", gcs_are_young() ? "young" : "mixed");
+    gclog_or_tty->print("[GC pause (%s) (%s)",
+      GCCause::to_string(_g1->gc_cause()),
+      gcs_are_young() ? "young" : "mixed");
   }
 
   // We only need to do this here as the policy will only be applied