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