8145301: Improve and unify the printout format for the g1HRPrinter.
authordavid
Mon, 14 Dec 2015 13:47:35 +0100
changeset 35079 edab77f91231
parent 35078 c2e328a0171f
child 35080 b9dd459157f0
child 35171 cf7d5a1d0662
8145301: Improve and unify the printout format for the g1HRPrinter. Reviewed-by: brutisso, tschatzl
hotspot/src/share/vm/gc/g1/g1Allocator.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1HRPrinter.cpp
hotspot/src/share/vm/gc/g1/g1HRPrinter.hpp
hotspot/src/share/vm/gc/g1/heapRegionManager.cpp
--- a/hotspot/src/share/vm/gc/g1/g1Allocator.cpp	Mon Dec 14 10:04:31 2015 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1Allocator.cpp	Mon Dec 14 13:47:35 2015 +0100
@@ -353,7 +353,7 @@
   assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
   hr->set_archive();
   _g1h->old_set_add(hr);
-  _g1h->hr_printer()->alloc(hr, G1HRPrinter::Archive);
+  _g1h->hr_printer()->alloc(hr);
   _allocated_regions.append(hr);
   _allocation_region = hr;
 
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Mon Dec 14 10:04:31 2015 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Mon Dec 14 13:47:35 2015 +0100
@@ -410,11 +410,7 @@
   for (uint i = first; i <= last; ++i) {
     hr = region_at(i);
     _humongous_set.add(hr);
-    if (i == first) {
-      _hr_printer.alloc(G1HRPrinter::StartsHumongous, hr, hr->top());
-    } else {
-      _hr_printer.alloc(G1HRPrinter::ContinuesHumongous, hr, hr->top());
-    }
+    _hr_printer.alloc(hr);
   }
 
   return new_obj;
@@ -807,9 +803,9 @@
     while (curr_region != NULL) {
       assert(curr_region->is_empty() && !curr_region->is_pinned(),
              "Region already in use (index %u)", curr_region->hrm_index());
-      _hr_printer.alloc(curr_region, G1HRPrinter::Archive);
       curr_region->set_allocation_context(AllocationContext::system());
       curr_region->set_archive();
+      _hr_printer.alloc(curr_region);
       _old_set.add(curr_region);
       if (curr_region != last_region) {
         curr_region->set_top(curr_region->end());
@@ -1195,19 +1191,7 @@
 public:
   bool doHeapRegion(HeapRegion* hr) {
     assert(!hr->is_young(), "not expecting to find young regions");
-    if (hr->is_free()) {
-      // We only generate output for non-empty regions.
-    } else if (hr->is_starts_humongous()) {
-      _hr_printer->post_compaction(hr, G1HRPrinter::StartsHumongous);
-    } else if (hr->is_continues_humongous()) {
-      _hr_printer->post_compaction(hr, G1HRPrinter::ContinuesHumongous);
-    } else if (hr->is_archive()) {
-      _hr_printer->post_compaction(hr, G1HRPrinter::Archive);
-    } else if (hr->is_old()) {
-      _hr_printer->post_compaction(hr, G1HRPrinter::Old);
-    } else {
-      ShouldNotReachHere();
-    }
+    _hr_printer->post_compaction(hr);
     return false;
   }
 
@@ -5967,7 +5951,7 @@
                                               false /* do_expand */);
     if (new_alloc_region != NULL) {
       set_region_short_lived_locked(new_alloc_region);
-      _hr_printer.alloc(new_alloc_region, G1HRPrinter::Eden, young_list_full);
+      _hr_printer.alloc(new_alloc_region, young_list_full);
       check_bitmaps("Mutator Region Allocation", new_alloc_region);
       return new_alloc_region;
     }
@@ -6008,13 +5992,12 @@
       new_alloc_region->record_timestamp();
       if (is_survivor) {
         new_alloc_region->set_survivor();
-        _hr_printer.alloc(new_alloc_region, G1HRPrinter::Survivor);
         check_bitmaps("Survivor Region Allocation", new_alloc_region);
       } else {
         new_alloc_region->set_old();
-        _hr_printer.alloc(new_alloc_region, G1HRPrinter::Old);
         check_bitmaps("Old Region Allocation", new_alloc_region);
       }
+      _hr_printer.alloc(new_alloc_region);
       bool during_im = collector_state()->during_initial_mark_pause();
       new_alloc_region->note_start_of_copying(during_im);
       return new_alloc_region;
--- a/hotspot/src/share/vm/gc/g1/g1HRPrinter.cpp	Mon Dec 14 10:04:31 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "gc/g1/g1HRPrinter.hpp"
-#include "gc/g1/heapRegion.hpp"
-#include "utilities/ostream.hpp"
-
-const char* G1HRPrinter::action_name(ActionType action) {
-  switch(action) {
-    case Alloc:          return "ALLOC";
-    case AllocForce:     return "ALLOC-FORCE";
-    case Retire:         return "RETIRE";
-    case Reuse:          return "REUSE";
-    case CSet:           return "CSET";
-    case EvacFailure:    return "EVAC-FAILURE";
-    case Cleanup:        return "CLEANUP";
-    case PostCompaction: return "POST-COMPACTION";
-    case Commit:         return "COMMIT";
-    case Uncommit:       return "UNCOMMIT";
-    default:             ShouldNotReachHere();
-  }
-  // trying to keep the Windows compiler happy
-  return NULL;
-}
-
-const char* G1HRPrinter::region_type_name(RegionType type) {
-  switch (type) {
-    case Unset:              return NULL;
-    case Eden:               return "Eden";
-    case Survivor:           return "Survivor";
-    case Old:                return "Old";
-    case StartsHumongous:    return "StartsH";
-    case ContinuesHumongous: return "ContinuesH";
-    case Archive:            return "Archive";
-    default:                 ShouldNotReachHere();
-  }
-  // trying to keep the Windows compiler happy
-  return NULL;
-}
-
-#define G1HR_PREFIX     " G1HR"
-
-void G1HRPrinter::print(ActionType action, RegionType type,
-                        HeapRegion* hr, HeapWord* top) {
-  const char* action_str = action_name(action);
-  const char* type_str   = region_type_name(type);
-  HeapWord* bottom = hr->bottom();
-
-  if (type_str != NULL) {
-    if (top != NULL) {
-      log_trace(gc, region)(G1HR_PREFIX " %s(%s) " PTR_FORMAT " " PTR_FORMAT,
-                            action_str, type_str, p2i(bottom), p2i(top));
-    } else {
-      log_trace(gc, region)(G1HR_PREFIX " %s(%s) " PTR_FORMAT,
-                            action_str, type_str, p2i(bottom));
-    }
-  } else {
-    if (top != NULL) {
-      log_trace(gc, region)(G1HR_PREFIX " %s " PTR_FORMAT " " PTR_FORMAT,
-                            action_str, p2i(bottom), p2i(top));
-    } else {
-      log_trace(gc, region)(G1HR_PREFIX " %s " PTR_FORMAT,
-                            action_str, p2i(bottom));
-    }
-  }
-}
-
-void G1HRPrinter::print(ActionType action, HeapWord* bottom, HeapWord* end) {
-  const char* action_str = action_name(action);
-
-  log_trace(gc, region)(G1HR_PREFIX " %s [" PTR_FORMAT "," PTR_FORMAT "]",
-                        action_str, p2i(bottom), p2i(end));
-}
--- a/hotspot/src/share/vm/gc/g1/g1HRPrinter.hpp	Mon Dec 14 10:04:31 2015 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1HRPrinter.hpp	Mon Dec 14 13:47:35 2015 +0100
@@ -32,43 +32,14 @@
 #define SKIP_RETIRED_FULL_REGIONS 1
 
 class G1HRPrinter VALUE_OBJ_CLASS_SPEC {
-public:
-  typedef enum {
-    Alloc,
-    AllocForce,
-    Retire,
-    Reuse,
-    CSet,
-    EvacFailure,
-    Cleanup,
-    PostCompaction,
-    Commit,
-    Uncommit
-  } ActionType;
-
-  typedef enum {
-    Unset,
-    Eden,
-    Survivor,
-    Old,
-    StartsHumongous,
-    ContinuesHumongous,
-    Archive
-  } RegionType;
 
 private:
-  static const char* action_name(ActionType action);
-  static const char* region_type_name(RegionType type);
 
-  // Print an action event. This version is used in most scenarios and
-  // only prints the region's bottom. The parameters type and top are
-  // optional (the "not set" values are Unset and NULL).
-  static void print(ActionType action, RegionType type,
-                    HeapRegion* hr, HeapWord* top);
-
-  // Print an action event. This version prints both the region's
-  // bottom and end. Used for Commit / Uncommit events.
-  static void print(ActionType action, HeapWord* bottom, HeapWord* end);
+  // Print an action event.
+  static void print(const char* action, HeapRegion* hr) {
+    log_trace(gc, region)("G1HR %s(%s) [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT "]",
+                          action, hr->get_type_str(), p2i(hr->bottom()), p2i(hr->top()), p2i(hr->end()));
+  }
 
 public:
   // In some places we iterate over a list in order to generate output
@@ -76,67 +47,61 @@
   // iteration if the printer is not active.
   const bool is_active() { return log_is_enabled(Trace, gc, region); }
 
-  // The methods below are convenient wrappers for the print() methods.
+  // The methods below are convenient wrappers for the print() method.
 
-  void alloc(HeapRegion* hr, RegionType type, bool force = false) {
+  void alloc(HeapRegion* hr, bool force = false) {
     if (is_active()) {
-      print((!force) ? Alloc : AllocForce, type, hr, NULL);
-    }
-  }
-
-  void alloc(RegionType type, HeapRegion* hr, HeapWord* top) {
-    if (is_active()) {
-      print(Alloc, type, hr, top);
+      print((force) ? "ALLOC-FORCE" : "ALLOC", hr);
     }
   }
 
   void retire(HeapRegion* hr) {
     if (is_active()) {
       if (!SKIP_RETIRED_FULL_REGIONS || hr->top() < hr->end()) {
-        print(Retire, Unset, hr, hr->top());
+        print("RETIRE", hr);
       }
     }
   }
 
   void reuse(HeapRegion* hr) {
     if (is_active()) {
-      print(Reuse, Unset, hr, NULL);
+      print("REUSE", hr);
     }
   }
 
   void cset(HeapRegion* hr) {
     if (is_active()) {
-      print(CSet, Unset, hr, NULL);
+      print("CSET", hr);
     }
   }
 
   void evac_failure(HeapRegion* hr) {
     if (is_active()) {
-      print(EvacFailure, Unset, hr, NULL);
+      print("EVAC-FAILURE", hr);
     }
   }
 
   void cleanup(HeapRegion* hr) {
     if (is_active()) {
-      print(Cleanup, Unset, hr, NULL);
+      print("CLEANUP", hr);
     }
   }
 
-  void post_compaction(HeapRegion* hr, RegionType type) {
+  void post_compaction(HeapRegion* hr) {
     if (is_active()) {
-      print(PostCompaction, type, hr, hr->top());
+      print("POST-COMPACTION", hr);
     }
   }
 
-  void commit(HeapWord* bottom, HeapWord* end) {
+  void commit(HeapRegion* hr) {
     if (is_active()) {
-      print(Commit, bottom, end);
+      print("COMMIT", hr);
     }
   }
 
-  void uncommit(HeapWord* bottom, HeapWord* end) {
+  void uncommit(HeapRegion* hr) {
     if (is_active()) {
-      print(Uncommit, bottom, end);
+      print("UNCOMMIT", hr);
     }
   }
 };
--- a/hotspot/src/share/vm/gc/g1/heapRegionManager.cpp	Mon Dec 14 10:04:31 2015 +0100
+++ b/hotspot/src/share/vm/gc/g1/heapRegionManager.cpp	Mon Dec 14 13:47:35 2015 +0100
@@ -99,7 +99,7 @@
   if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
     for (uint i = start; i < start + num_regions; i++) {
       HeapRegion* hr = at(i);
-      G1CollectedHeap::heap()->hr_printer()->uncommit(hr->bottom(), hr->end());
+      G1CollectedHeap::heap()->hr_printer()->uncommit(hr);
     }
   }
 
@@ -135,7 +135,7 @@
     assert(is_available(i), "Just made region %u available but is apparently not.", i);
     HeapRegion* hr = at(i);
     if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
-      G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end());
+      G1CollectedHeap::heap()->hr_printer()->commit(hr);
     }
     HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
     MemRegion mr(bottom, bottom + HeapRegion::GrainWords);