src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 6876
710a3c8b516e
child 9448
73d689add964
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP
aoqi@0 27
aoqi@0 28 #include "memory/allocation.hpp"
aoqi@0 29 #include "utilities/debug.hpp"
aoqi@0 30
aoqi@0 31 // The log of G1's heuristic decisions comprises of a series of
aoqi@0 32 // records which have a similar format in order to maintain
aoqi@0 33 // consistency across records and ultimately easier parsing of the
aoqi@0 34 // output, if we ever choose to do that. Each record consists of:
aoqi@0 35 // * A time stamp to be able to easily correlate each record with
aoqi@0 36 // other events.
aoqi@0 37 // * A unique string to allow us to easily identify such records.
aoqi@0 38 // * The name of the heuristic the record corresponds to.
aoqi@0 39 // * An action string which describes the action that G1 did or is
aoqi@0 40 // about to do.
aoqi@0 41 // * An optional reason string which describes the reason for the
aoqi@0 42 // action.
aoqi@0 43 // * An optional number of name/value pairs which contributed to the
aoqi@0 44 // decision to take the action described in the record.
aoqi@0 45 //
aoqi@0 46 // Each record is associated with a "tag" which is the combination of
aoqi@0 47 // the heuristic the record corresponds to, as well as the min level
aoqi@0 48 // of verboseness at which the record should be printed. The tag is
aoqi@0 49 // checked against the current settings to determine whether the record
aoqi@0 50 // should be printed or not.
aoqi@0 51
aoqi@0 52 // The available verboseness levels.
aoqi@0 53 typedef enum {
aoqi@0 54 // Determine which part of the tag is occupied by the level.
aoqi@0 55 ErgoLevelShift = 8,
aoqi@0 56 ErgoLevelMask = ~((1 << ErgoLevelShift) - 1),
aoqi@0 57
aoqi@0 58 // ErgoLow is 0 so that we don't have to explicitly or a heuristic
aoqi@0 59 // id with ErgoLow to keep its use simpler.
aoqi@0 60 ErgoLow = 0,
aoqi@0 61 ErgoHigh = 1 << ErgoLevelShift
aoqi@0 62 } ErgoLevel;
aoqi@0 63
aoqi@0 64 // The available heuristics.
aoqi@0 65 typedef enum {
aoqi@0 66 // Determines which part of the tag is occupied by the heuristic id.
aoqi@0 67 ErgoHeuristicMask = ~ErgoLevelMask,
aoqi@0 68
aoqi@0 69 ErgoHeapSizing = 0,
aoqi@0 70 ErgoCSetConstruction,
aoqi@0 71 ErgoConcCycles,
aoqi@0 72 ErgoMixedGCs,
aoqi@0 73
aoqi@0 74 ErgoHeuristicNum
aoqi@0 75 } ErgoHeuristic;
aoqi@0 76
aoqi@0 77 class G1ErgoVerbose : AllStatic {
aoqi@0 78 private:
aoqi@0 79 // Determines the minimum verboseness level at which records will be
aoqi@0 80 // printed.
aoqi@0 81 static ErgoLevel _level;
aoqi@0 82 // Determines which heuristics are currently enabled.
aoqi@0 83 static bool _enabled[ErgoHeuristicNum];
aoqi@0 84
aoqi@0 85 static ErgoLevel extract_level(int tag) {
aoqi@0 86 return (ErgoLevel) (tag & ErgoLevelMask);
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 static ErgoHeuristic extract_heuristic(int tag) {
aoqi@0 90 return (ErgoHeuristic) (tag & ErgoHeuristicMask);
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 public:
aoqi@0 94 // Needs to be explicitly called at GC initialization.
aoqi@0 95 static void initialize();
aoqi@0 96
aoqi@0 97 static void set_level(ErgoLevel level);
aoqi@0 98 static void set_enabled(ErgoHeuristic h, bool enabled);
aoqi@0 99 // It is applied to all heuristics.
aoqi@0 100 static void set_enabled(bool enabled);
aoqi@0 101
aoqi@0 102 static bool enabled(int tag) {
aoqi@0 103 ErgoLevel level = extract_level(tag);
aoqi@0 104 ErgoHeuristic n = extract_heuristic(tag);
aoqi@0 105 return level <= _level && _enabled[n];
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 // Extract the heuristic id from the tag and return a string with
aoqi@0 109 // its name.
aoqi@0 110 static const char* to_string(int tag);
aoqi@0 111 };
aoqi@0 112
aoqi@0 113 // The macros below generate the format string for values of different
aoqi@0 114 // types and/or metrics.
aoqi@0 115
aoqi@0 116 // The reason for the action is optional and is handled specially: the
aoqi@0 117 // reason string is concatenated here so it's not necessary to pass it
aoqi@0 118 // as a parameter.
aoqi@0 119 #define ergo_format_reason(_reason_) ", reason: " _reason_
aoqi@0 120
aoqi@0 121 // Single parameter format strings
aoqi@0 122 #define ergo_format_str(_name_) ", " _name_ ": %s"
aoqi@0 123 #define ergo_format_region(_name_) ", " _name_ ": %u regions"
aoqi@0 124 #define ergo_format_byte(_name_) ", " _name_ ": "SIZE_FORMAT" bytes"
aoqi@0 125 #define ergo_format_double(_name_) ", " _name_ ": %1.2f"
aoqi@0 126 #define ergo_format_perc(_name_) ", " _name_ ": %1.2f %%"
aoqi@0 127 #define ergo_format_ms(_name_) ", " _name_ ": %1.2f ms"
aoqi@0 128 #define ergo_format_size(_name_) ", " _name_ ": "SIZE_FORMAT
aoqi@0 129
aoqi@0 130 // Double parameter format strings
aoqi@0 131 #define ergo_format_byte_perc(_name_) \
aoqi@0 132 ", " _name_ ": "SIZE_FORMAT" bytes (%1.2f %%)"
aoqi@0 133
aoqi@0 134 // Generates the format string
aoqi@0 135 #define ergo_format(_extra_format_) \
aoqi@0 136 " %1.3f: [G1Ergonomics (%s) %s" _extra_format_ "]"
aoqi@0 137
aoqi@0 138 // Conditionally, prints an ergonomic decision record. _extra_format_
aoqi@0 139 // is the format string for the optional items we'd like to print
aoqi@0 140 // (i.e., the decision's reason and any associated values). This
aoqi@0 141 // string should be built up using the ergo_*_format macros (see
aoqi@0 142 // above) to ensure consistency.
aoqi@0 143 //
aoqi@0 144 // Since we cannot rely on the compiler supporting variable argument
aoqi@0 145 // macros, this macro accepts a fixed number of arguments and passes
aoqi@0 146 // them to the print method. For convenience, we have wrapper macros
aoqi@0 147 // below which take a specific number of arguments and set the rest to
aoqi@0 148 // a default value.
aoqi@0 149 #define ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 150 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \
aoqi@0 151 do { \
aoqi@0 152 if (G1ErgoVerbose::enabled((_tag_))) { \
aoqi@0 153 gclog_or_tty->print_cr(ergo_format(_extra_format_), \
aoqi@0 154 os::elapsedTime(), \
aoqi@0 155 G1ErgoVerbose::to_string((_tag_)), \
aoqi@0 156 (_action_), \
aoqi@0 157 (_arg0_), (_arg1_), (_arg2_), \
aoqi@0 158 (_arg3_), (_arg4_), (_arg5_)); \
aoqi@0 159 } \
aoqi@0 160 } while (0)
aoqi@0 161
aoqi@0 162
aoqi@0 163 #define ergo_verbose(_tag_, _action_) \
aoqi@0 164 ergo_verbose_common(_tag_, _action_, "", 0, 0, 0, 0, 0, 0)
aoqi@0 165
aoqi@0 166 #define ergo_verbose0(_tag_, _action_, _extra_format_) \
aoqi@0 167 ergo_verbose_common(_tag_, _action_, _extra_format_, 0, 0, 0, 0, 0, 0)
aoqi@0 168
aoqi@0 169 #define ergo_verbose1(_tag_, _action_, _extra_format_, \
aoqi@0 170 _arg0_) \
aoqi@0 171 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 172 _arg0_, 0, 0, 0, 0, 0)
aoqi@0 173
aoqi@0 174 #define ergo_verbose2(_tag_, _action_, _extra_format_, \
aoqi@0 175 _arg0_, _arg1_) \
aoqi@0 176 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 177 _arg0_, _arg1_, 0, 0, 0, 0)
aoqi@0 178
aoqi@0 179 #define ergo_verbose3(_tag_, _action_, _extra_format_, \
aoqi@0 180 _arg0_, _arg1_, _arg2_) \
aoqi@0 181 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 182 _arg0_, _arg1_, _arg2_, 0, 0, 0)
aoqi@0 183
aoqi@0 184 #define ergo_verbose4(_tag_, _action_, _extra_format_, \
aoqi@0 185 _arg0_, _arg1_, _arg2_, _arg3_) \
aoqi@0 186 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 187 _arg0_, _arg1_, _arg2_, _arg3_, 0, 0)
aoqi@0 188
aoqi@0 189 #define ergo_verbose5(_tag_, _action_, _extra_format_, \
aoqi@0 190 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_) \
aoqi@0 191 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 192 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, 0)
aoqi@0 193
aoqi@0 194 #define ergo_verbose6(_tag_, _action_, _extra_format_, \
aoqi@0 195 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \
aoqi@0 196 ergo_verbose_common(_tag_, _action_, _extra_format_, \
aoqi@0 197 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_)
aoqi@0 198
aoqi@0 199 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP

mercurial