Mercurial > hg > graal-compiler
comparison src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp @ 3914:20213c8a3c40
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
Summary: It introduces ergonomic decision logging in G1 for the following heuristics: heap sizing, collection set construction, concurrent cycle initiation, and partially-young GC start/end. The code has a bit of refactoring in a few places to make the decision logging possible. It also replaces alternative ad-hoc logging that we have under different parameters and switches (G1_DEBUG, G1PolicyVerbose).
Reviewed-by: johnc, ysr
author | tonyp |
---|---|
date | Wed, 07 Sep 2011 12:21:23 -0400 |
parents | |
children | f1b4e0e0bdad |
comparison
equal
deleted
inserted
replaced
3913:27702f012017 | 3914:20213c8a3c40 |
---|---|
1 /* | |
2 * Copyright (c) 2011, 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP | |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP | |
27 | |
28 #include "memory/allocation.hpp" | |
29 #include "utilities/debug.hpp" | |
30 | |
31 // The log of G1's heuristic decisions comprises of a series of | |
32 // records which have a similar format in order to maintain | |
33 // consistency across records and ultimately easier parsing of the | |
34 // output, if we ever choose to do that. Each record consists of: | |
35 // * A time stamp to be able to easily correlate each record with | |
36 // other events. | |
37 // * A unique string to allow us to easily identify such records. | |
38 // * The name of the heuristic the record corresponds to. | |
39 // * An action string which describes the action that G1 did or is | |
40 // about to do. | |
41 // * An optional reason string which describes the reason for the | |
42 // action. | |
43 // * An optional number of name/value pairs which contributed to the | |
44 // decision to take the action described in the record. | |
45 // | |
46 // Each record is associated with a "tag" which is the combination of | |
47 // the heuristic the record corresponds to, as well as the min level | |
48 // of verboseness at which the record should be printed. The tag is | |
49 // checked against the current settings to determine whether the record | |
50 // should be printed or not. | |
51 | |
52 // The available verboseness levels. | |
53 typedef enum { | |
54 // Determine which part of the tag is occupied by the level. | |
55 ErgoLevelShift = 8, | |
56 ErgoLevelMask = ~((1 << ErgoLevelShift) - 1), | |
57 | |
58 // ErgoLow is 0 so that we don't have to explicitly or a heuristic | |
59 // id with ErgoLow to keep its use simpler. | |
60 ErgoLow = 0, | |
61 ErgoHigh = 1 << ErgoLevelShift, | |
62 } ErgoLevel; | |
63 | |
64 // The available heuristics. | |
65 typedef enum { | |
66 // Determines which part of the tag is occupied by the heuristic id. | |
67 ErgoHeuristicMask = ~ErgoLevelMask, | |
68 | |
69 ErgoHeapSizing = 0, | |
70 ErgoCSetConstruction, | |
71 ErgoConcCycles, | |
72 ErgoPartiallyYoungGCs, | |
73 | |
74 ErgoHeuristicNum | |
75 } ErgoHeuristic; | |
76 | |
77 class G1ErgoVerbose : AllStatic { | |
78 private: | |
79 // Determines the minimum verboseness level at which records will be | |
80 // printed. | |
81 static ErgoLevel _level; | |
82 // Determines which heuristics are currently enabled. | |
83 static bool _enabled[ErgoHeuristicNum]; | |
84 | |
85 static ErgoLevel extract_level(int tag) { | |
86 return (ErgoLevel) (tag & ErgoLevelMask); | |
87 } | |
88 | |
89 static ErgoHeuristic extract_heuristic(int tag) { | |
90 return (ErgoHeuristic) (tag & ErgoHeuristicMask); | |
91 } | |
92 | |
93 public: | |
94 // Needs to be explicitly called at GC initialization. | |
95 static void initialize(); | |
96 | |
97 static void set_level(ErgoLevel level); | |
98 static void set_enabled(ErgoHeuristic h, bool enabled); | |
99 // It is applied to all heuristics. | |
100 static void set_enabled(bool enabled); | |
101 | |
102 static bool enabled(int tag) { | |
103 ErgoLevel level = extract_level(tag); | |
104 ErgoHeuristic n = extract_heuristic(tag); | |
105 return level <= _level && _enabled[n]; | |
106 } | |
107 | |
108 // Extract the heuristic id from the tag and return a string with | |
109 // its name. | |
110 static const char* to_string(int tag); | |
111 }; | |
112 | |
113 // The macros below generate the format string for values of different | |
114 // types and/or metrics. | |
115 | |
116 // The reason for the action is optional and is handled specially: the | |
117 // reason string is concatenated here so it's not necessary to pass it | |
118 // as a parameter. | |
119 #define ergo_format_reason(_reason_) ", reason: " _reason_ | |
120 | |
121 // Single parameter format strings | |
122 #define ergo_format_str(_name_) ", " _name_ ": %s" | |
123 #define ergo_format_region(_name_) ", " _name_ ": "SIZE_FORMAT" regions" | |
124 #define ergo_format_byte(_name_) ", " _name_ ": "SIZE_FORMAT" bytes" | |
125 #define ergo_format_double(_name_) ", " _name_ ": %1.2f" | |
126 #define ergo_format_perc(_name_) ", " _name_ ": %1.2f %%" | |
127 #define ergo_format_ms(_name_) ", " _name_ ": %1.2f ms" | |
128 | |
129 // Double parameter format strings | |
130 #define ergo_format_byte_perc(_name_) \ | |
131 ", " _name_ ": "SIZE_FORMAT" bytes (%1.2f %%)" | |
132 | |
133 // Generates the format string | |
134 #define ergo_format(_action_, _extra_format_) \ | |
135 " %1.3f: [G1Ergonomics (%s) " _action_ _extra_format_ "]" | |
136 | |
137 // Conditionally, prints an ergonomic decision record. _extra_format_ | |
138 // is the format string for the optional items we'd like to print | |
139 // (i.e., the decision's reason and any associated values). This | |
140 // string should be built up using the ergo_*_format macros (see | |
141 // above) to ensure consistency. | |
142 // | |
143 // Since we cannot rely on the compiler supporting variable argument | |
144 // macros, this macro accepts a fixed number of arguments and passes | |
145 // them to the print method. For convenience, we have wrapper macros | |
146 // below which take a specific number of arguments and set the rest to | |
147 // a default value. | |
148 #define ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
149 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \ | |
150 do { \ | |
151 if (G1ErgoVerbose::enabled((_tag_))) { \ | |
152 gclog_or_tty->print_cr(ergo_format(_action_, _extra_format_), \ | |
153 os::elapsedTime(), \ | |
154 G1ErgoVerbose::to_string((_tag_)), \ | |
155 (_arg0_), (_arg1_), (_arg2_), \ | |
156 (_arg3_), (_arg4_), (_arg5_)); \ | |
157 } \ | |
158 } while (0) | |
159 | |
160 | |
161 #define ergo_verbose(_tag_, _action_) \ | |
162 ergo_verbose_common(_tag_, _action_, "", 0, 0, 0, 0, 0, 0) | |
163 | |
164 #define ergo_verbose0(_tag_, _action_, _extra_format_) \ | |
165 ergo_verbose_common(_tag_, _action_, _extra_format_, 0, 0, 0, 0, 0, 0) | |
166 | |
167 #define ergo_verbose1(_tag_, _action_, _extra_format_, \ | |
168 _arg0_) \ | |
169 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
170 _arg0_, 0, 0, 0, 0, 0) | |
171 | |
172 #define ergo_verbose2(_tag_, _action_, _extra_format_, \ | |
173 _arg0_, _arg1_) \ | |
174 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
175 _arg0_, _arg1_, 0, 0, 0, 0) | |
176 | |
177 #define ergo_verbose3(_tag_, _action_, _extra_format_, \ | |
178 _arg0_, _arg1_, _arg2_) \ | |
179 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
180 _arg0_, _arg1_, _arg2_, 0, 0, 0) | |
181 | |
182 #define ergo_verbose4(_tag_, _action_, _extra_format_, \ | |
183 _arg0_, _arg1_, _arg2_, _arg3_) \ | |
184 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
185 _arg0_, _arg1_, _arg2_, _arg3_, 0, 0) | |
186 | |
187 #define ergo_verbose5(_tag_, _action_, _extra_format_, \ | |
188 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_) \ | |
189 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
190 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, 0) | |
191 | |
192 #define ergo_verbose6(_tag_, _action_, _extra_format_, \ | |
193 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \ | |
194 ergo_verbose_common(_tag_, _action_, _extra_format_, \ | |
195 _arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) | |
196 | |
197 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP |