1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp Wed Sep 07 12:21:23 2011 -0400 1.3 @@ -0,0 +1,197 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "utilities/debug.hpp" 1.33 + 1.34 +// The log of G1's heuristic decisions comprises of a series of 1.35 +// records which have a similar format in order to maintain 1.36 +// consistency across records and ultimately easier parsing of the 1.37 +// output, if we ever choose to do that. Each record consists of: 1.38 +// * A time stamp to be able to easily correlate each record with 1.39 +// other events. 1.40 +// * A unique string to allow us to easily identify such records. 1.41 +// * The name of the heuristic the record corresponds to. 1.42 +// * An action string which describes the action that G1 did or is 1.43 +// about to do. 1.44 +// * An optional reason string which describes the reason for the 1.45 +// action. 1.46 +// * An optional number of name/value pairs which contributed to the 1.47 +// decision to take the action described in the record. 1.48 +// 1.49 +// Each record is associated with a "tag" which is the combination of 1.50 +// the heuristic the record corresponds to, as well as the min level 1.51 +// of verboseness at which the record should be printed. The tag is 1.52 +// checked against the current settings to determine whether the record 1.53 +// should be printed or not. 1.54 + 1.55 +// The available verboseness levels. 1.56 +typedef enum { 1.57 + // Determine which part of the tag is occupied by the level. 1.58 + ErgoLevelShift = 8, 1.59 + ErgoLevelMask = ~((1 << ErgoLevelShift) - 1), 1.60 + 1.61 + // ErgoLow is 0 so that we don't have to explicitly or a heuristic 1.62 + // id with ErgoLow to keep its use simpler. 1.63 + ErgoLow = 0, 1.64 + ErgoHigh = 1 << ErgoLevelShift, 1.65 +} ErgoLevel; 1.66 + 1.67 +// The available heuristics. 1.68 +typedef enum { 1.69 + // Determines which part of the tag is occupied by the heuristic id. 1.70 + ErgoHeuristicMask = ~ErgoLevelMask, 1.71 + 1.72 + ErgoHeapSizing = 0, 1.73 + ErgoCSetConstruction, 1.74 + ErgoConcCycles, 1.75 + ErgoPartiallyYoungGCs, 1.76 + 1.77 + ErgoHeuristicNum 1.78 +} ErgoHeuristic; 1.79 + 1.80 +class G1ErgoVerbose : AllStatic { 1.81 +private: 1.82 + // Determines the minimum verboseness level at which records will be 1.83 + // printed. 1.84 + static ErgoLevel _level; 1.85 + // Determines which heuristics are currently enabled. 1.86 + static bool _enabled[ErgoHeuristicNum]; 1.87 + 1.88 + static ErgoLevel extract_level(int tag) { 1.89 + return (ErgoLevel) (tag & ErgoLevelMask); 1.90 + } 1.91 + 1.92 + static ErgoHeuristic extract_heuristic(int tag) { 1.93 + return (ErgoHeuristic) (tag & ErgoHeuristicMask); 1.94 + } 1.95 + 1.96 +public: 1.97 + // Needs to be explicitly called at GC initialization. 1.98 + static void initialize(); 1.99 + 1.100 + static void set_level(ErgoLevel level); 1.101 + static void set_enabled(ErgoHeuristic h, bool enabled); 1.102 + // It is applied to all heuristics. 1.103 + static void set_enabled(bool enabled); 1.104 + 1.105 + static bool enabled(int tag) { 1.106 + ErgoLevel level = extract_level(tag); 1.107 + ErgoHeuristic n = extract_heuristic(tag); 1.108 + return level <= _level && _enabled[n]; 1.109 + } 1.110 + 1.111 + // Extract the heuristic id from the tag and return a string with 1.112 + // its name. 1.113 + static const char* to_string(int tag); 1.114 +}; 1.115 + 1.116 +// The macros below generate the format string for values of different 1.117 +// types and/or metrics. 1.118 + 1.119 +// The reason for the action is optional and is handled specially: the 1.120 +// reason string is concatenated here so it's not necessary to pass it 1.121 +// as a parameter. 1.122 +#define ergo_format_reason(_reason_) ", reason: " _reason_ 1.123 + 1.124 +// Single parameter format strings 1.125 +#define ergo_format_str(_name_) ", " _name_ ": %s" 1.126 +#define ergo_format_region(_name_) ", " _name_ ": "SIZE_FORMAT" regions" 1.127 +#define ergo_format_byte(_name_) ", " _name_ ": "SIZE_FORMAT" bytes" 1.128 +#define ergo_format_double(_name_) ", " _name_ ": %1.2f" 1.129 +#define ergo_format_perc(_name_) ", " _name_ ": %1.2f %%" 1.130 +#define ergo_format_ms(_name_) ", " _name_ ": %1.2f ms" 1.131 + 1.132 +// Double parameter format strings 1.133 +#define ergo_format_byte_perc(_name_) \ 1.134 + ", " _name_ ": "SIZE_FORMAT" bytes (%1.2f %%)" 1.135 + 1.136 +// Generates the format string 1.137 +#define ergo_format(_action_, _extra_format_) \ 1.138 + " %1.3f: [G1Ergonomics (%s) " _action_ _extra_format_ "]" 1.139 + 1.140 +// Conditionally, prints an ergonomic decision record. _extra_format_ 1.141 +// is the format string for the optional items we'd like to print 1.142 +// (i.e., the decision's reason and any associated values). This 1.143 +// string should be built up using the ergo_*_format macros (see 1.144 +// above) to ensure consistency. 1.145 +// 1.146 +// Since we cannot rely on the compiler supporting variable argument 1.147 +// macros, this macro accepts a fixed number of arguments and passes 1.148 +// them to the print method. For convenience, we have wrapper macros 1.149 +// below which take a specific number of arguments and set the rest to 1.150 +// a default value. 1.151 +#define ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.152 + _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \ 1.153 + do { \ 1.154 + if (G1ErgoVerbose::enabled((_tag_))) { \ 1.155 + gclog_or_tty->print_cr(ergo_format(_action_, _extra_format_), \ 1.156 + os::elapsedTime(), \ 1.157 + G1ErgoVerbose::to_string((_tag_)), \ 1.158 + (_arg0_), (_arg1_), (_arg2_), \ 1.159 + (_arg3_), (_arg4_), (_arg5_)); \ 1.160 + } \ 1.161 + } while (0) 1.162 + 1.163 + 1.164 +#define ergo_verbose(_tag_, _action_) \ 1.165 + ergo_verbose_common(_tag_, _action_, "", 0, 0, 0, 0, 0, 0) 1.166 + 1.167 +#define ergo_verbose0(_tag_, _action_, _extra_format_) \ 1.168 + ergo_verbose_common(_tag_, _action_, _extra_format_, 0, 0, 0, 0, 0, 0) 1.169 + 1.170 +#define ergo_verbose1(_tag_, _action_, _extra_format_, \ 1.171 + _arg0_) \ 1.172 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.173 + _arg0_, 0, 0, 0, 0, 0) 1.174 + 1.175 +#define ergo_verbose2(_tag_, _action_, _extra_format_, \ 1.176 + _arg0_, _arg1_) \ 1.177 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.178 + _arg0_, _arg1_, 0, 0, 0, 0) 1.179 + 1.180 +#define ergo_verbose3(_tag_, _action_, _extra_format_, \ 1.181 + _arg0_, _arg1_, _arg2_) \ 1.182 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.183 + _arg0_, _arg1_, _arg2_, 0, 0, 0) 1.184 + 1.185 +#define ergo_verbose4(_tag_, _action_, _extra_format_, \ 1.186 + _arg0_, _arg1_, _arg2_, _arg3_) \ 1.187 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.188 + _arg0_, _arg1_, _arg2_, _arg3_, 0, 0) 1.189 + 1.190 +#define ergo_verbose5(_tag_, _action_, _extra_format_, \ 1.191 + _arg0_, _arg1_, _arg2_, _arg3_, _arg4_) \ 1.192 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.193 + _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, 0) 1.194 + 1.195 +#define ergo_verbose6(_tag_, _action_, _extra_format_, \ 1.196 + _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \ 1.197 + ergo_verbose_common(_tag_, _action_, _extra_format_, \ 1.198 + _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) 1.199 + 1.200 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP