1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/g1/g1HRPrinter.hpp"
  27 #include "gc_implementation/g1/heapRegion.hpp"
  28 #include "utilities/ostream.hpp"
  29 
  30 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  31 
  32 const char* G1HRPrinter::action_name(ActionType action) {
  33   switch(action) {
  34     case Alloc:          return "ALLOC";
  35     case AllocForce:     return "ALLOC-FORCE";
  36     case Retire:         return "RETIRE";
  37     case Reuse:          return "REUSE";
  38     case CSet:           return "CSET";
  39     case EvacFailure:    return "EVAC-FAILURE";
  40     case Cleanup:        return "CLEANUP";
  41     case PostCompaction: return "POST-COMPACTION";
  42     case Commit:         return "COMMIT";
  43     case Uncommit:       return "UNCOMMIT";
  44     default:             ShouldNotReachHere();
  45   }
  46   // trying to keep the Windows compiler happy
  47   return NULL;
  48 }
  49 
  50 const char* G1HRPrinter::region_type_name(RegionType type) {
  51   switch (type) {
  52     case Unset:              return NULL;
  53     case Eden:               return "Eden";
  54     case Survivor:           return "Survivor";
  55     case Old:                return "Old";
  56     case SingleHumongous:    return "SingleH";
  57     case StartsHumongous:    return "StartsH";
  58     case ContinuesHumongous: return "ContinuesH";
  59     default:                 ShouldNotReachHere();
  60   }
  61   // trying to keep the Windows compiler happy
  62   return NULL;
  63 }
  64 
  65 const char* G1HRPrinter::phase_name(PhaseType phase) {
  66   switch (phase) {
  67     case StartGC:     return "StartGC";
  68     case EndGC:       return "EndGC";
  69     case StartFullGC: return "StartFullGC";
  70     case EndFullGC:   return "EndFullGC";
  71     default:          ShouldNotReachHere();
  72   }
  73   // trying to keep the Windows compiler happy
  74   return NULL;
  75 }
  76 
  77 #define G1HR_PREFIX     " G1HR"
  78 
  79 void G1HRPrinter::print(ActionType action, RegionType type,
  80                         HeapRegion* hr, HeapWord* top) {
  81   const char* action_str = action_name(action);
  82   const char* type_str   = region_type_name(type);
  83   HeapWord* bottom = hr->bottom();
  84 
  85   if (type_str != NULL) {
  86     if (top != NULL) {
  87       gclog_or_tty->print_cr(G1HR_PREFIX" %s(%s) "PTR_FORMAT" "PTR_FORMAT,
  88                              action_str, type_str, bottom, top);
  89     } else {
  90       gclog_or_tty->print_cr(G1HR_PREFIX" %s(%s) "PTR_FORMAT,
  91                              action_str, type_str, bottom);
  92     }
  93   } else {
  94     if (top != NULL) {
  95       gclog_or_tty->print_cr(G1HR_PREFIX" %s "PTR_FORMAT" "PTR_FORMAT,
  96                              action_str, bottom, top);
  97     } else {
  98       gclog_or_tty->print_cr(G1HR_PREFIX" %s "PTR_FORMAT,
  99                              action_str, bottom);
 100     }
 101   }
 102 }
 103 
 104 void G1HRPrinter::print(ActionType action, HeapWord* bottom, HeapWord* end) {
 105   const char* action_str = action_name(action);
 106 
 107   gclog_or_tty->print_cr(G1HR_PREFIX" %s ["PTR_FORMAT","PTR_FORMAT"]",
 108                          action_str, bottom, end);
 109 }
 110 
 111 void G1HRPrinter::print(PhaseType phase, size_t phase_num) {
 112   const char* phase_str = phase_name(phase);
 113   gclog_or_tty->print_cr(G1HR_PREFIX" #%s "SIZE_FORMAT, phase_str, phase_num);
 114 }