105 #else |
105 #else |
106 #define CI_COMPILER_COUNT 1 |
106 #define CI_COMPILER_COUNT 1 |
107 #endif // COMPILER2_OR_JVMCI |
107 #endif // COMPILER2_OR_JVMCI |
108 |
108 |
109 #endif // no compilers |
109 #endif // no compilers |
|
110 |
|
111 // string type aliases used only in this file |
|
112 typedef const char* ccstr; |
|
113 typedef const char* ccstrlist; // represents string arguments which accumulate |
|
114 |
|
115 // function type that will construct default range string |
|
116 typedef const char* (*RangeStrFunc)(void); |
|
117 |
|
118 struct Flag { |
|
119 enum Flags { |
|
120 // latest value origin |
|
121 DEFAULT = 0, |
|
122 COMMAND_LINE = 1, |
|
123 ENVIRON_VAR = 2, |
|
124 CONFIG_FILE = 3, |
|
125 MANAGEMENT = 4, |
|
126 ERGONOMIC = 5, |
|
127 ATTACH_ON_DEMAND = 6, |
|
128 INTERNAL = 7, |
|
129 |
|
130 LAST_VALUE_ORIGIN = INTERNAL, |
|
131 VALUE_ORIGIN_BITS = 4, |
|
132 VALUE_ORIGIN_MASK = right_n_bits(VALUE_ORIGIN_BITS), |
|
133 |
|
134 // flag kind |
|
135 KIND_PRODUCT = 1 << 4, |
|
136 KIND_MANAGEABLE = 1 << 5, |
|
137 KIND_DIAGNOSTIC = 1 << 6, |
|
138 KIND_EXPERIMENTAL = 1 << 7, |
|
139 KIND_NOT_PRODUCT = 1 << 8, |
|
140 KIND_DEVELOP = 1 << 9, |
|
141 KIND_PLATFORM_DEPENDENT = 1 << 10, |
|
142 KIND_READ_WRITE = 1 << 11, |
|
143 KIND_C1 = 1 << 12, |
|
144 KIND_C2 = 1 << 13, |
|
145 KIND_ARCH = 1 << 14, |
|
146 KIND_LP64_PRODUCT = 1 << 15, |
|
147 KIND_COMMERCIAL = 1 << 16, |
|
148 KIND_JVMCI = 1 << 17, |
|
149 |
|
150 // set this bit if the flag was set on the command line |
|
151 ORIG_COMMAND_LINE = 1 << 18, |
|
152 |
|
153 KIND_MASK = ~(VALUE_ORIGIN_MASK | ORIG_COMMAND_LINE) |
|
154 }; |
|
155 |
|
156 enum Error { |
|
157 // no error |
|
158 SUCCESS = 0, |
|
159 // flag name is missing |
|
160 MISSING_NAME, |
|
161 // flag value is missing |
|
162 MISSING_VALUE, |
|
163 // error parsing the textual form of the value |
|
164 WRONG_FORMAT, |
|
165 // flag is not writable |
|
166 NON_WRITABLE, |
|
167 // flag value is outside of its bounds |
|
168 OUT_OF_BOUNDS, |
|
169 // flag value violates its constraint |
|
170 VIOLATES_CONSTRAINT, |
|
171 // there is no flag with the given name |
|
172 INVALID_FLAG, |
|
173 // the flag can only be set only on command line during invocation of the VM |
|
174 COMMAND_LINE_ONLY, |
|
175 // the flag may only be set once |
|
176 SET_ONLY_ONCE, |
|
177 // the flag is not writable in this combination of product/debug build |
|
178 CONSTANT, |
|
179 // other, unspecified error related to setting the flag |
|
180 ERR_OTHER |
|
181 }; |
|
182 |
|
183 enum MsgType { |
|
184 NONE = 0, |
|
185 DIAGNOSTIC_FLAG_BUT_LOCKED, |
|
186 EXPERIMENTAL_FLAG_BUT_LOCKED, |
|
187 DEVELOPER_FLAG_BUT_PRODUCT_BUILD, |
|
188 NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD, |
|
189 COMMERCIAL_FLAG_BUT_DISABLED, |
|
190 COMMERCIAL_FLAG_BUT_LOCKED |
|
191 }; |
|
192 |
|
193 const char* _type; |
|
194 const char* _name; |
|
195 void* _addr; |
|
196 NOT_PRODUCT(const char* _doc;) |
|
197 Flags _flags; |
|
198 size_t _name_len; |
|
199 |
|
200 // points to all Flags static array |
|
201 static Flag* flags; |
|
202 |
|
203 // number of flags |
|
204 static size_t numFlags; |
|
205 |
|
206 static Flag* find_flag(const char* name) { return find_flag(name, strlen(name), true, true); }; |
|
207 static Flag* find_flag(const char* name, size_t length, bool allow_locked = false, bool return_flag = false); |
|
208 static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false); |
|
209 |
|
210 static const char* get_int_default_range_str(); |
|
211 static const char* get_uint_default_range_str(); |
|
212 static const char* get_intx_default_range_str(); |
|
213 static const char* get_uintx_default_range_str(); |
|
214 static const char* get_uint64_t_default_range_str(); |
|
215 static const char* get_size_t_default_range_str(); |
|
216 static const char* get_double_default_range_str(); |
|
217 |
|
218 Flag::Error check_writable(bool changed); |
|
219 |
|
220 bool is_bool() const; |
|
221 bool get_bool() const; |
|
222 Flag::Error set_bool(bool value); |
|
223 |
|
224 bool is_int() const; |
|
225 int get_int() const; |
|
226 Flag::Error set_int(int value); |
|
227 |
|
228 bool is_uint() const; |
|
229 uint get_uint() const; |
|
230 Flag::Error set_uint(uint value); |
|
231 |
|
232 bool is_intx() const; |
|
233 intx get_intx() const; |
|
234 Flag::Error set_intx(intx value); |
|
235 |
|
236 bool is_uintx() const; |
|
237 uintx get_uintx() const; |
|
238 Flag::Error set_uintx(uintx value); |
|
239 |
|
240 bool is_uint64_t() const; |
|
241 uint64_t get_uint64_t() const; |
|
242 Flag::Error set_uint64_t(uint64_t value); |
|
243 |
|
244 bool is_size_t() const; |
|
245 size_t get_size_t() const; |
|
246 Flag::Error set_size_t(size_t value); |
|
247 |
|
248 bool is_double() const; |
|
249 double get_double() const; |
|
250 Flag::Error set_double(double value); |
|
251 |
|
252 bool is_ccstr() const; |
|
253 bool ccstr_accumulates() const; |
|
254 ccstr get_ccstr() const; |
|
255 Flag::Error set_ccstr(ccstr value); |
|
256 |
|
257 Flags get_origin(); |
|
258 void set_origin(Flags origin); |
|
259 |
|
260 size_t get_name_length(); |
|
261 |
|
262 bool is_default(); |
|
263 bool is_ergonomic(); |
|
264 bool is_command_line(); |
|
265 void set_command_line(); |
|
266 |
|
267 bool is_product() const; |
|
268 bool is_manageable() const; |
|
269 bool is_diagnostic() const; |
|
270 bool is_experimental() const; |
|
271 bool is_notproduct() const; |
|
272 bool is_develop() const; |
|
273 bool is_read_write() const; |
|
274 bool is_commercial() const; |
|
275 |
|
276 bool is_constant_in_binary() const; |
|
277 |
|
278 bool is_unlocker() const; |
|
279 bool is_unlocked() const; |
|
280 bool is_writeable() const; |
|
281 bool is_external() const; |
|
282 |
|
283 bool is_unlocker_ext() const; |
|
284 bool is_unlocked_ext() const; |
|
285 bool is_writeable_ext() const; |
|
286 bool is_external_ext() const; |
|
287 |
|
288 void clear_diagnostic(); |
|
289 |
|
290 Flag::MsgType get_locked_message(char*, int) const; |
|
291 Flag::MsgType get_locked_message_ext(char*, int) const; |
|
292 |
|
293 // printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges |
|
294 void print_on(outputStream* st, bool withComments = false, bool printRanges = false); |
|
295 void print_kind(outputStream* st, unsigned int width); |
|
296 void print_origin(outputStream* st, unsigned int width); |
|
297 void print_as_flag(outputStream* st); |
|
298 |
|
299 static const char* flag_error_str(Flag::Error error); |
|
300 }; |
|
301 |
|
302 // debug flags control various aspects of the VM and are global accessible |
|
303 |
|
304 // use FlagSetting to temporarily change some debug flag |
|
305 // e.g. FlagSetting fs(DebugThisAndThat, true); |
|
306 // restored to previous value upon leaving scope |
|
307 class FlagSetting { |
|
308 bool val; |
|
309 bool* flag; |
|
310 public: |
|
311 FlagSetting(bool& fl, bool newValue) { flag = &fl; val = fl; fl = newValue; } |
|
312 ~FlagSetting() { *flag = val; } |
|
313 }; |
|
314 |
|
315 |
|
316 class CounterSetting { |
|
317 intx* counter; |
|
318 public: |
|
319 CounterSetting(intx* cnt) { counter = cnt; (*counter)++; } |
|
320 ~CounterSetting() { (*counter)--; } |
|
321 }; |
|
322 |
|
323 class IntFlagSetting { |
|
324 int val; |
|
325 int* flag; |
|
326 public: |
|
327 IntFlagSetting(int& fl, int newValue) { flag = &fl; val = fl; fl = newValue; } |
|
328 ~IntFlagSetting() { *flag = val; } |
|
329 }; |
|
330 |
|
331 class UIntFlagSetting { |
|
332 uint val; |
|
333 uint* flag; |
|
334 public: |
|
335 UIntFlagSetting(uint& fl, uint newValue) { flag = &fl; val = fl; fl = newValue; } |
|
336 ~UIntFlagSetting() { *flag = val; } |
|
337 }; |
|
338 |
|
339 class UIntXFlagSetting { |
|
340 uintx val; |
|
341 uintx* flag; |
|
342 public: |
|
343 UIntXFlagSetting(uintx& fl, uintx newValue) { flag = &fl; val = fl; fl = newValue; } |
|
344 ~UIntXFlagSetting() { *flag = val; } |
|
345 }; |
|
346 |
|
347 class DoubleFlagSetting { |
|
348 double val; |
|
349 double* flag; |
|
350 public: |
|
351 DoubleFlagSetting(double& fl, double newValue) { flag = &fl; val = fl; fl = newValue; } |
|
352 ~DoubleFlagSetting() { *flag = val; } |
|
353 }; |
|
354 |
|
355 class SizeTFlagSetting { |
|
356 size_t val; |
|
357 size_t* flag; |
|
358 public: |
|
359 SizeTFlagSetting(size_t& fl, size_t newValue) { flag = &fl; val = fl; fl = newValue; } |
|
360 ~SizeTFlagSetting() { *flag = val; } |
|
361 }; |
|
362 |
|
363 // Helper class for temporarily saving the value of a flag during a scope. |
|
364 template <size_t SIZE> |
|
365 class FlagGuard { |
|
366 unsigned char _value[SIZE]; |
|
367 void* const _addr; |
|
368 |
|
369 // Hide operator new, this class should only be allocated on the stack. |
|
370 // NOTE: Cannot include memory/allocation.hpp here due to circular |
|
371 // dependencies. |
|
372 void* operator new(size_t size) throw(); |
|
373 void* operator new [](size_t size) throw(); |
|
374 |
|
375 public: |
|
376 FlagGuard(void* flag_addr) : _addr(flag_addr) { |
|
377 memcpy(_value, _addr, SIZE); |
|
378 } |
|
379 |
|
380 ~FlagGuard() { |
|
381 memcpy(_addr, _value, SIZE); |
|
382 } |
|
383 }; |
|
384 |
|
385 #define FLAG_GUARD(f) FlagGuard<sizeof(f)> f ## _guard(&f) |
|
386 |
|
387 class CommandLineFlags { |
|
388 public: |
|
389 static Flag::Error boolAt(const char* name, size_t len, bool* value, bool allow_locked = false, bool return_flag = false); |
|
390 static Flag::Error boolAt(const char* name, bool* value, bool allow_locked = false, bool return_flag = false) { return boolAt(name, strlen(name), value, allow_locked, return_flag); } |
|
391 static Flag::Error boolAtPut(Flag* flag, bool* value, Flag::Flags origin); |
|
392 static Flag::Error boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin); |
|
393 static Flag::Error boolAtPut(const char* name, bool* value, Flag::Flags origin) { return boolAtPut(name, strlen(name), value, origin); } |
|
394 |
|
395 static Flag::Error intAt(const char* name, size_t len, int* value, bool allow_locked = false, bool return_flag = false); |
|
396 static Flag::Error intAt(const char* name, int* value, bool allow_locked = false, bool return_flag = false) { return intAt(name, strlen(name), value, allow_locked, return_flag); } |
|
397 static Flag::Error intAtPut(Flag* flag, int* value, Flag::Flags origin); |
|
398 static Flag::Error intAtPut(const char* name, size_t len, int* value, Flag::Flags origin); |
|
399 static Flag::Error intAtPut(const char* name, int* value, Flag::Flags origin) { return intAtPut(name, strlen(name), value, origin); } |
|
400 |
|
401 static Flag::Error uintAt(const char* name, size_t len, uint* value, bool allow_locked = false, bool return_flag = false); |
|
402 static Flag::Error uintAt(const char* name, uint* value, bool allow_locked = false, bool return_flag = false) { return uintAt(name, strlen(name), value, allow_locked, return_flag); } |
|
403 static Flag::Error uintAtPut(Flag* flag, uint* value, Flag::Flags origin); |
|
404 static Flag::Error uintAtPut(const char* name, size_t len, uint* value, Flag::Flags origin); |
|
405 static Flag::Error uintAtPut(const char* name, uint* value, Flag::Flags origin) { return uintAtPut(name, strlen(name), value, origin); } |
|
406 |
|
407 static Flag::Error intxAt(const char* name, size_t len, intx* value, bool allow_locked = false, bool return_flag = false); |
|
408 static Flag::Error intxAt(const char* name, intx* value, bool allow_locked = false, bool return_flag = false) { return intxAt(name, strlen(name), value, allow_locked, return_flag); } |
|
409 static Flag::Error intxAtPut(Flag* flag, intx* value, Flag::Flags origin); |
|
410 static Flag::Error intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin); |
|
411 static Flag::Error intxAtPut(const char* name, intx* value, Flag::Flags origin) { return intxAtPut(name, strlen(name), value, origin); } |
|
412 |
|
413 static Flag::Error uintxAt(const char* name, size_t len, uintx* value, bool allow_locked = false, bool return_flag = false); |
|
414 static Flag::Error uintxAt(const char* name, uintx* value, bool allow_locked = false, bool return_flag = false) { return uintxAt(name, strlen(name), value, allow_locked, return_flag); } |
|
415 static Flag::Error uintxAtPut(Flag* flag, uintx* value, Flag::Flags origin); |
|
416 static Flag::Error uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin); |
|
417 static Flag::Error uintxAtPut(const char* name, uintx* value, Flag::Flags origin) { return uintxAtPut(name, strlen(name), value, origin); } |
|
418 |
|
419 static Flag::Error size_tAt(const char* name, size_t len, size_t* value, bool allow_locked = false, bool return_flag = false); |
|
420 static Flag::Error size_tAt(const char* name, size_t* value, bool allow_locked = false, bool return_flag = false) { return size_tAt(name, strlen(name), value, allow_locked, return_flag); } |
|
421 static Flag::Error size_tAtPut(Flag* flag, size_t* value, Flag::Flags origin); |
|
422 static Flag::Error size_tAtPut(const char* name, size_t len, size_t* value, Flag::Flags origin); |
|
423 static Flag::Error size_tAtPut(const char* name, size_t* value, Flag::Flags origin) { return size_tAtPut(name, strlen(name), value, origin); } |
|
424 |
|
425 static Flag::Error uint64_tAt(const char* name, size_t len, uint64_t* value, bool allow_locked = false, bool return_flag = false); |
|
426 static Flag::Error uint64_tAt(const char* name, uint64_t* value, bool allow_locked = false, bool return_flag = false) { return uint64_tAt(name, strlen(name), value, allow_locked, return_flag); } |
|
427 static Flag::Error uint64_tAtPut(Flag* flag, uint64_t* value, Flag::Flags origin); |
|
428 static Flag::Error uint64_tAtPut(const char* name, size_t len, uint64_t* value, Flag::Flags origin); |
|
429 static Flag::Error uint64_tAtPut(const char* name, uint64_t* value, Flag::Flags origin) { return uint64_tAtPut(name, strlen(name), value, origin); } |
|
430 |
|
431 static Flag::Error doubleAt(const char* name, size_t len, double* value, bool allow_locked = false, bool return_flag = false); |
|
432 static Flag::Error doubleAt(const char* name, double* value, bool allow_locked = false, bool return_flag = false) { return doubleAt(name, strlen(name), value, allow_locked, return_flag); } |
|
433 static Flag::Error doubleAtPut(Flag* flag, double* value, Flag::Flags origin); |
|
434 static Flag::Error doubleAtPut(const char* name, size_t len, double* value, Flag::Flags origin); |
|
435 static Flag::Error doubleAtPut(const char* name, double* value, Flag::Flags origin) { return doubleAtPut(name, strlen(name), value, origin); } |
|
436 |
|
437 static Flag::Error ccstrAt(const char* name, size_t len, ccstr* value, bool allow_locked = false, bool return_flag = false); |
|
438 static Flag::Error ccstrAt(const char* name, ccstr* value, bool allow_locked = false, bool return_flag = false) { return ccstrAt(name, strlen(name), value, allow_locked, return_flag); } |
|
439 // Contract: Flag will make private copy of the incoming value. |
|
440 // Outgoing value is always malloc-ed, and caller MUST call free. |
|
441 static Flag::Error ccstrAtPut(const char* name, size_t len, ccstr* value, Flag::Flags origin); |
|
442 static Flag::Error ccstrAtPut(const char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); } |
|
443 |
|
444 // Returns false if name is not a command line flag. |
|
445 static bool wasSetOnCmdline(const char* name, bool* value); |
|
446 static void printSetFlags(outputStream* out); |
|
447 |
|
448 // printRanges will print out flags type, name and range values as expected by -XX:+PrintFlagsRanges |
|
449 static void printFlags(outputStream* out, bool withComments, bool printRanges = false); |
|
450 |
|
451 static void verify() PRODUCT_RETURN; |
|
452 }; |
110 |
453 |
111 // use this for flags that are true by default in the debug version but |
454 // use this for flags that are true by default in the debug version but |
112 // false in the optimized version, and vice versa |
455 // false in the optimized version, and vice versa |
113 #ifdef ASSERT |
456 #ifdef ASSERT |
114 #define trueInDebug true |
457 #define trueInDebug true |