src/share/vm/runtime/globals.cpp

Thu, 23 Jan 2014 08:12:12 +0100

author
sla
date
Thu, 23 Jan 2014 08:12:12 +0100
changeset 6333
d6c97434b745
parent 6309
cd7a42c7be06
child 6542
b257acb35d3e
permissions
-rw-r--r--

8032250: Add trace event for VM flag changes
Reviewed-by: coleenp, ehelin, egahlin, mgronlun

duke@435 1 /*
kmo@4586 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "memory/allocation.inline.hpp"
stefank@2314 27 #include "oops/oop.inline.hpp"
stefank@2314 28 #include "runtime/arguments.hpp"
stefank@2314 29 #include "runtime/globals.hpp"
stefank@2314 30 #include "runtime/globals_extension.hpp"
stefank@2314 31 #include "utilities/ostream.hpp"
jprovino@4542 32 #include "utilities/macros.hpp"
stefank@2314 33 #include "utilities/top.hpp"
sla@6333 34 #include "trace/tracing.hpp"
jprovino@4542 35 #if INCLUDE_ALL_GCS
stefank@2314 36 #include "gc_implementation/g1/g1_globals.hpp"
jprovino@4542 37 #endif // INCLUDE_ALL_GCS
stefank@2314 38 #ifdef COMPILER1
stefank@2314 39 #include "c1/c1_globals.hpp"
stefank@2314 40 #endif
stefank@2314 41 #ifdef COMPILER2
stefank@2314 42 #include "opto/c2_globals.hpp"
stefank@2314 43 #endif
stefank@2314 44 #ifdef SHARK
stefank@2314 45 #include "shark/shark_globals.hpp"
stefank@2314 46 #endif
duke@435 47
duke@435 48 RUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
duke@435 49 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
phh@3287 50 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_EXPERIMENTAL_FLAG, \
phh@3287 51 MATERIALIZE_NOTPRODUCT_FLAG, \
coleenp@548 52 MATERIALIZE_MANAGEABLE_FLAG, MATERIALIZE_PRODUCT_RW_FLAG, \
coleenp@548 53 MATERIALIZE_LP64_PRODUCT_FLAG)
duke@435 54
duke@435 55 RUNTIME_OS_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
duke@435 56 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
duke@435 57 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
duke@435 58
twisti@4020 59 ARCH_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PRODUCT_FLAG, \
twisti@4020 60 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_EXPERIMENTAL_FLAG, \
twisti@4020 61 MATERIALIZE_NOTPRODUCT_FLAG)
twisti@4020 62
phh@3303 63 MATERIALIZE_FLAGS_EXT
phh@3303 64
phh@3303 65
ccheung@6309 66 static bool is_product_build() {
ccheung@6309 67 #ifdef PRODUCT
ccheung@6309 68 return true;
ccheung@6309 69 #else
ccheung@6309 70 return false;
ccheung@6309 71 #endif
ccheung@6309 72 }
ccheung@6309 73
twisti@5790 74 void Flag::check_writable() {
twisti@5790 75 if (is_constant_in_binary()) {
twisti@5790 76 fatal(err_msg("flag is constant: %s", _name));
twisti@5790 77 }
twisti@5790 78 }
twisti@5790 79
twisti@5790 80 bool Flag::is_bool() const {
twisti@5790 81 return strcmp(_type, "bool") == 0;
twisti@5790 82 }
twisti@5790 83
twisti@5790 84 bool Flag::get_bool() const {
twisti@5790 85 return *((bool*) _addr);
twisti@5790 86 }
twisti@5790 87
twisti@5790 88 void Flag::set_bool(bool value) {
twisti@5790 89 check_writable();
twisti@5790 90 *((bool*) _addr) = value;
twisti@5790 91 }
twisti@5790 92
twisti@5790 93 bool Flag::is_intx() const {
twisti@5790 94 return strcmp(_type, "intx") == 0;
twisti@5790 95 }
twisti@5790 96
twisti@5790 97 intx Flag::get_intx() const {
twisti@5790 98 return *((intx*) _addr);
twisti@5790 99 }
twisti@5790 100
twisti@5790 101 void Flag::set_intx(intx value) {
twisti@5790 102 check_writable();
twisti@5790 103 *((intx*) _addr) = value;
twisti@5790 104 }
twisti@5790 105
twisti@5790 106 bool Flag::is_uintx() const {
twisti@5790 107 return strcmp(_type, "uintx") == 0;
twisti@5790 108 }
twisti@5790 109
twisti@5790 110 uintx Flag::get_uintx() const {
twisti@5790 111 return *((uintx*) _addr);
twisti@5790 112 }
twisti@5790 113
twisti@5790 114 void Flag::set_uintx(uintx value) {
twisti@5790 115 check_writable();
twisti@5790 116 *((uintx*) _addr) = value;
twisti@5790 117 }
twisti@5790 118
twisti@5790 119 bool Flag::is_uint64_t() const {
twisti@5790 120 return strcmp(_type, "uint64_t") == 0;
twisti@5790 121 }
twisti@5790 122
twisti@5790 123 uint64_t Flag::get_uint64_t() const {
twisti@5790 124 return *((uint64_t*) _addr);
twisti@5790 125 }
twisti@5790 126
twisti@5790 127 void Flag::set_uint64_t(uint64_t value) {
twisti@5790 128 check_writable();
twisti@5790 129 *((uint64_t*) _addr) = value;
twisti@5790 130 }
twisti@5790 131
twisti@5790 132 bool Flag::is_double() const {
twisti@5790 133 return strcmp(_type, "double") == 0;
twisti@5790 134 }
twisti@5790 135
twisti@5790 136 double Flag::get_double() const {
twisti@5790 137 return *((double*) _addr);
twisti@5790 138 }
twisti@5790 139
twisti@5790 140 void Flag::set_double(double value) {
twisti@5790 141 check_writable();
twisti@5790 142 *((double*) _addr) = value;
twisti@5790 143 }
twisti@5790 144
twisti@5790 145 bool Flag::is_ccstr() const {
twisti@5790 146 return strcmp(_type, "ccstr") == 0 || strcmp(_type, "ccstrlist") == 0;
twisti@5790 147 }
twisti@5790 148
twisti@5790 149 bool Flag::ccstr_accumulates() const {
twisti@5790 150 return strcmp(_type, "ccstrlist") == 0;
twisti@5790 151 }
twisti@5790 152
twisti@5790 153 ccstr Flag::get_ccstr() const {
twisti@5790 154 return *((ccstr*) _addr);
twisti@5790 155 }
twisti@5790 156
twisti@5790 157 void Flag::set_ccstr(ccstr value) {
twisti@5790 158 check_writable();
twisti@5790 159 *((ccstr*) _addr) = value;
twisti@5790 160 }
twisti@5790 161
twisti@5790 162
twisti@5790 163 Flag::Flags Flag::get_origin() {
twisti@5790 164 return Flags(_flags & VALUE_ORIGIN_MASK);
twisti@5790 165 }
twisti@5790 166
twisti@5790 167 void Flag::set_origin(Flags origin) {
twisti@5790 168 assert((origin & VALUE_ORIGIN_MASK) == origin, "sanity");
twisti@5790 169 _flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | origin);
twisti@5790 170 }
twisti@5790 171
twisti@5790 172 bool Flag::is_default() {
twisti@5790 173 return (get_origin() == DEFAULT);
twisti@5790 174 }
twisti@5790 175
twisti@5790 176 bool Flag::is_ergonomic() {
twisti@5790 177 return (get_origin() == ERGONOMIC);
twisti@5790 178 }
twisti@5790 179
twisti@5790 180 bool Flag::is_command_line() {
twisti@5790 181 return (get_origin() == COMMAND_LINE);
twisti@5790 182 }
twisti@5790 183
twisti@5790 184 bool Flag::is_product() const {
twisti@5790 185 return (_flags & KIND_PRODUCT) != 0;
twisti@5790 186 }
twisti@5790 187
twisti@5790 188 bool Flag::is_manageable() const {
twisti@5790 189 return (_flags & KIND_MANAGEABLE) != 0;
twisti@5790 190 }
twisti@5790 191
twisti@5790 192 bool Flag::is_diagnostic() const {
twisti@5790 193 return (_flags & KIND_DIAGNOSTIC) != 0;
twisti@5790 194 }
twisti@5790 195
twisti@5790 196 bool Flag::is_experimental() const {
twisti@5790 197 return (_flags & KIND_EXPERIMENTAL) != 0;
twisti@5790 198 }
twisti@5790 199
twisti@5790 200 bool Flag::is_notproduct() const {
twisti@5790 201 return (_flags & KIND_NOT_PRODUCT) != 0;
twisti@5790 202 }
twisti@5790 203
twisti@5790 204 bool Flag::is_develop() const {
twisti@5790 205 return (_flags & KIND_DEVELOP) != 0;
twisti@5790 206 }
twisti@5790 207
twisti@5790 208 bool Flag::is_read_write() const {
twisti@5790 209 return (_flags & KIND_READ_WRITE) != 0;
twisti@5790 210 }
twisti@5790 211
twisti@5790 212 bool Flag::is_commercial() const {
twisti@5790 213 return (_flags & KIND_COMMERCIAL) != 0;
twisti@5790 214 }
twisti@5790 215
twisti@5790 216 /**
twisti@5790 217 * Returns if this flag is a constant in the binary. Right now this is
twisti@5790 218 * true for notproduct and develop flags in product builds.
twisti@5790 219 */
twisti@5790 220 bool Flag::is_constant_in_binary() const {
twisti@5790 221 #ifdef PRODUCT
twisti@5790 222 return is_notproduct() || is_develop();
twisti@5790 223 #else
twisti@5790 224 return false;
twisti@5790 225 #endif
twisti@5790 226 }
twisti@5790 227
duke@435 228 bool Flag::is_unlocker() const {
twisti@5790 229 return strcmp(_name, "UnlockDiagnosticVMOptions") == 0 ||
twisti@5790 230 strcmp(_name, "UnlockExperimentalVMOptions") == 0 ||
phh@3303 231 is_unlocker_ext();
duke@435 232 }
duke@435 233
duke@435 234 bool Flag::is_unlocked() const {
twisti@5790 235 if (is_diagnostic()) {
duke@435 236 return UnlockDiagnosticVMOptions;
twisti@5790 237 }
twisti@5790 238 if (is_experimental()) {
ysr@785 239 return UnlockExperimentalVMOptions;
duke@435 240 }
twisti@5790 241 return is_unlocked_ext();
duke@435 242 }
duke@435 243
jmelvin@3650 244 // Get custom message for this locked flag, or return NULL if
jmelvin@3650 245 // none is available.
jmelvin@3650 246 void Flag::get_locked_message(char* buf, int buflen) const {
ccheung@6309 247 buf[0] = '\0';
ccheung@6309 248 if (is_diagnostic() && !is_unlocked()) {
ccheung@6309 249 jio_snprintf(buf, buflen, "Error: VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.\n",
ccheung@6309 250 _name);
ccheung@6309 251 return;
ccheung@6309 252 }
ccheung@6309 253 if (is_experimental() && !is_unlocked()) {
ccheung@6309 254 jio_snprintf(buf, buflen, "Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n",
ccheung@6309 255 _name);
ccheung@6309 256 return;
ccheung@6309 257 }
ccheung@6309 258 if (is_develop() && is_product_build()) {
ccheung@6309 259 jio_snprintf(buf, buflen, "Error: VM option '%s' is develop and is available only in debug version of VM.\n",
ccheung@6309 260 _name);
ccheung@6309 261 return;
ccheung@6309 262 }
ccheung@6309 263 if (is_notproduct() && is_product_build()) {
ccheung@6309 264 jio_snprintf(buf, buflen, "Error: VM option '%s' is notproduct and is available only in debug version of VM.\n",
ccheung@6309 265 _name);
ccheung@6309 266 return;
ccheung@6309 267 }
jmelvin@3650 268 get_locked_message_ext(buf, buflen);
jmelvin@3650 269 }
jmelvin@3650 270
duke@435 271 bool Flag::is_writeable() const {
twisti@5790 272 return is_manageable() || (is_product() && is_read_write()) || is_writeable_ext();
duke@435 273 }
duke@435 274
phh@3342 275 // All flags except "manageable" are assumed to be internal flags.
duke@435 276 // Long term, we need to define a mechanism to specify which flags
duke@435 277 // are external/stable and change this function accordingly.
duke@435 278 bool Flag::is_external() const {
twisti@5790 279 return is_manageable() || is_external_ext();
duke@435 280 }
duke@435 281
phh@3342 282
duke@435 283 // Length of format string (e.g. "%.1234s") for printing ccstr below
duke@435 284 #define FORMAT_BUFFER_LEN 16
duke@435 285
ikrylov@2123 286 void Flag::print_on(outputStream* st, bool withComments) {
twisti@5790 287 // Don't print notproduct and develop flags in a product build.
twisti@5790 288 if (is_constant_in_binary()) {
twisti@5790 289 return;
twisti@5790 290 }
ikrylov@2123 291
twisti@5790 292 st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' '));
twisti@5790 293
twisti@5790 294 if (is_bool()) {
twisti@5790 295 st->print("%-16s", get_bool() ? "true" : "false");
twisti@5790 296 }
twisti@5790 297 if (is_intx()) {
twisti@5790 298 st->print("%-16ld", get_intx());
twisti@5790 299 }
twisti@5790 300 if (is_uintx()) {
twisti@5790 301 st->print("%-16lu", get_uintx());
twisti@5790 302 }
twisti@5790 303 if (is_uint64_t()) {
twisti@5790 304 st->print("%-16lu", get_uint64_t());
twisti@5790 305 }
twisti@5790 306 if (is_double()) {
twisti@5790 307 st->print("%-16f", get_double());
twisti@5790 308 }
duke@435 309 if (is_ccstr()) {
twisti@5790 310 const char* cp = get_ccstr();
twisti@5790 311 if (cp != NULL) {
twisti@5790 312 const char* eol;
twisti@5790 313 while ((eol = strchr(cp, '\n')) != NULL) {
twisti@5790 314 char format_buffer[FORMAT_BUFFER_LEN];
twisti@5790 315 size_t llen = pointer_delta(eol, cp, sizeof(char));
twisti@5790 316 jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
twisti@5790 317 "%%." SIZE_FORMAT "s", llen);
twisti@5790 318 st->print(format_buffer, cp);
twisti@5790 319 st->cr();
twisti@5790 320 cp = eol+1;
twisti@5790 321 st->print("%5s %-35s += ", "", _name);
twisti@5790 322 }
twisti@5790 323 st->print("%-16s", cp);
twisti@5790 324 }
twisti@5790 325 else st->print("%-16s", "");
duke@435 326 }
twisti@5790 327
twisti@5790 328 st->print("%-20");
twisti@5790 329 print_kind(st);
twisti@5790 330
ikrylov@2123 331 if (withComments) {
ikrylov@2123 332 #ifndef PRODUCT
twisti@5790 333 st->print("%s", _doc);
ikrylov@2123 334 #endif
ikrylov@2123 335 }
duke@435 336 st->cr();
duke@435 337 }
duke@435 338
twisti@5790 339 void Flag::print_kind(outputStream* st) {
twisti@5790 340 struct Data {
twisti@5790 341 int flag;
twisti@5790 342 const char* name;
twisti@5790 343 };
twisti@5790 344
twisti@5790 345 Data data[] = {
twisti@5790 346 { KIND_C1, "C1" },
twisti@5790 347 { KIND_C2, "C2" },
twisti@5790 348 { KIND_ARCH, "ARCH" },
twisti@5790 349 { KIND_SHARK, "SHARK" },
twisti@5790 350 { KIND_PLATFORM_DEPENDENT, "pd" },
twisti@5790 351 { KIND_PRODUCT, "product" },
twisti@5790 352 { KIND_MANAGEABLE, "manageable" },
twisti@5790 353 { KIND_DIAGNOSTIC, "diagnostic" },
sgabdura@6123 354 { KIND_EXPERIMENTAL, "experimental" },
sgabdura@6123 355 { KIND_COMMERCIAL, "commercial" },
twisti@5790 356 { KIND_NOT_PRODUCT, "notproduct" },
twisti@5790 357 { KIND_DEVELOP, "develop" },
twisti@5790 358 { KIND_LP64_PRODUCT, "lp64_product" },
twisti@5790 359 { KIND_READ_WRITE, "rw" },
twisti@5790 360 { -1, "" }
twisti@5790 361 };
twisti@5790 362
twisti@5790 363 if ((_flags & KIND_MASK) != 0) {
twisti@5790 364 st->print("{");
twisti@5790 365 bool is_first = true;
twisti@5790 366
twisti@5790 367 for (int i = 0; data[i].flag != -1; i++) {
twisti@5790 368 Data d = data[i];
twisti@5790 369 if ((_flags & d.flag) != 0) {
twisti@5790 370 if (is_first) {
twisti@5790 371 is_first = false;
twisti@5790 372 } else {
twisti@5790 373 st->print(" ");
twisti@5790 374 }
twisti@5790 375 st->print(d.name);
twisti@5790 376 }
twisti@5790 377 }
twisti@5790 378
twisti@5790 379 st->print("}");
twisti@5790 380 }
twisti@5790 381 }
twisti@5790 382
duke@435 383 void Flag::print_as_flag(outputStream* st) {
duke@435 384 if (is_bool()) {
twisti@5790 385 st->print("-XX:%s%s", get_bool() ? "+" : "-", _name);
duke@435 386 } else if (is_intx()) {
twisti@5790 387 st->print("-XX:%s=" INTX_FORMAT, _name, get_intx());
duke@435 388 } else if (is_uintx()) {
twisti@5790 389 st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx());
phh@1502 390 } else if (is_uint64_t()) {
twisti@5790 391 st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t());
brutisso@3752 392 } else if (is_double()) {
twisti@5790 393 st->print("-XX:%s=%f", _name, get_double());
duke@435 394 } else if (is_ccstr()) {
twisti@5790 395 st->print("-XX:%s=", _name);
never@538 396 const char* cp = get_ccstr();
never@538 397 if (cp != NULL) {
never@538 398 // Need to turn embedded '\n's back into separate arguments
never@538 399 // Not so efficient to print one character at a time,
never@538 400 // but the choice is to do the transformation to a buffer
never@538 401 // and print that. And this need not be efficient.
never@538 402 for (; *cp != '\0'; cp += 1) {
never@538 403 switch (*cp) {
never@538 404 default:
never@538 405 st->print("%c", *cp);
never@538 406 break;
never@538 407 case '\n':
twisti@5790 408 st->print(" -XX:%s=", _name);
never@538 409 break;
never@538 410 }
duke@435 411 }
duke@435 412 }
duke@435 413 } else {
duke@435 414 ShouldNotReachHere();
duke@435 415 }
duke@435 416 }
duke@435 417
duke@435 418 // 4991491 do not "optimize out" the was_set false values: omitting them
duke@435 419 // tickles a Microsoft compiler bug causing flagTable to be malformed
duke@435 420
twisti@5790 421 #define NAME(name) NOT_PRODUCT(&name) PRODUCT_ONLY(&CONST_##name)
duke@435 422
twisti@5790 423 #define RUNTIME_PRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT) },
twisti@5790 424 #define RUNTIME_PD_PRODUCT_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 425 #define RUNTIME_DIAGNOSTIC_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DIAGNOSTIC) },
twisti@5790 426 #define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_EXPERIMENTAL) },
twisti@5790 427 #define RUNTIME_MANAGEABLE_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_MANAGEABLE) },
twisti@5790 428 #define RUNTIME_PRODUCT_RW_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT | Flag::KIND_READ_WRITE) },
twisti@5790 429 #define RUNTIME_DEVELOP_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DEVELOP) },
twisti@5790 430 #define RUNTIME_PD_DEVELOP_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 431 #define RUNTIME_NOTPRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_NOT_PRODUCT) },
duke@435 432
coleenp@548 433 #ifdef _LP64
twisti@5790 434 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_LP64_PRODUCT) },
coleenp@548 435 #else
twisti@5790 436 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
coleenp@548 437 #endif // _LP64
coleenp@548 438
twisti@5790 439 #define C1_PRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_PRODUCT) },
twisti@5790 440 #define C1_PD_PRODUCT_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 441 #define C1_DIAGNOSTIC_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DIAGNOSTIC) },
twisti@5790 442 #define C1_DEVELOP_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DEVELOP) },
twisti@5790 443 #define C1_PD_DEVELOP_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 444 #define C1_NOTPRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_NOT_PRODUCT) },
duke@435 445
twisti@5790 446 #define C2_PRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_PRODUCT) },
twisti@5790 447 #define C2_PD_PRODUCT_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 448 #define C2_DIAGNOSTIC_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DIAGNOSTIC) },
twisti@5790 449 #define C2_EXPERIMENTAL_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_EXPERIMENTAL) },
twisti@5790 450 #define C2_DEVELOP_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DEVELOP) },
twisti@5790 451 #define C2_PD_DEVELOP_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 452 #define C2_NOTPRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_NOT_PRODUCT) },
duke@435 453
twisti@5790 454 #define ARCH_PRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_PRODUCT) },
twisti@5790 455 #define ARCH_DIAGNOSTIC_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_DIAGNOSTIC) },
twisti@5790 456 #define ARCH_EXPERIMENTAL_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_EXPERIMENTAL) },
twisti@5790 457 #define ARCH_DEVELOP_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_DEVELOP) },
twisti@5790 458 #define ARCH_NOTPRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_NOT_PRODUCT) },
twisti@4020 459
twisti@5790 460 #define SHARK_PRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_PRODUCT) },
twisti@5790 461 #define SHARK_PD_PRODUCT_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 462 #define SHARK_DIAGNOSTIC_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DIAGNOSTIC) },
twisti@5790 463 #define SHARK_DEVELOP_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DEVELOP) },
twisti@5790 464 #define SHARK_PD_DEVELOP_FLAG_STRUCT( type, name, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
twisti@5790 465 #define SHARK_NOTPRODUCT_FLAG_STRUCT( type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_NOT_PRODUCT) },
duke@435 466
duke@435 467 static Flag flagTable[] = {
phh@3287 468 RUNTIME_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_EXPERIMENTAL_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT, RUNTIME_LP64_PRODUCT_FLAG_STRUCT)
duke@435 469 RUNTIME_OS_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT)
jprovino@4542 470 #if INCLUDE_ALL_GCS
ysr@785 471 G1_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_EXPERIMENTAL_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT)
jprovino@4542 472 #endif // INCLUDE_ALL_GCS
duke@435 473 #ifdef COMPILER1
roland@5628 474 C1_FLAGS(C1_DEVELOP_FLAG_STRUCT, C1_PD_DEVELOP_FLAG_STRUCT, C1_PRODUCT_FLAG_STRUCT, C1_PD_PRODUCT_FLAG_STRUCT, C1_DIAGNOSTIC_FLAG_STRUCT, C1_NOTPRODUCT_FLAG_STRUCT)
duke@435 475 #endif
duke@435 476 #ifdef COMPILER2
never@1515 477 C2_FLAGS(C2_DEVELOP_FLAG_STRUCT, C2_PD_DEVELOP_FLAG_STRUCT, C2_PRODUCT_FLAG_STRUCT, C2_PD_PRODUCT_FLAG_STRUCT, C2_DIAGNOSTIC_FLAG_STRUCT, C2_EXPERIMENTAL_FLAG_STRUCT, C2_NOTPRODUCT_FLAG_STRUCT)
duke@435 478 #endif
twisti@2047 479 #ifdef SHARK
twisti@2047 480 SHARK_FLAGS(SHARK_DEVELOP_FLAG_STRUCT, SHARK_PD_DEVELOP_FLAG_STRUCT, SHARK_PRODUCT_FLAG_STRUCT, SHARK_PD_PRODUCT_FLAG_STRUCT, SHARK_DIAGNOSTIC_FLAG_STRUCT, SHARK_NOTPRODUCT_FLAG_STRUCT)
twisti@2047 481 #endif
twisti@4020 482 ARCH_FLAGS(ARCH_DEVELOP_FLAG_STRUCT, ARCH_PRODUCT_FLAG_STRUCT, ARCH_DIAGNOSTIC_FLAG_STRUCT, ARCH_EXPERIMENTAL_FLAG_STRUCT, ARCH_NOTPRODUCT_FLAG_STRUCT)
phh@3303 483 FLAGTABLE_EXT
duke@435 484 {0, NULL, NULL}
duke@435 485 };
duke@435 486
duke@435 487 Flag* Flag::flags = flagTable;
duke@435 488 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
duke@435 489
tamao@5343 490 inline bool str_equal(const char* s, const char* q, size_t len) {
duke@435 491 // s is null terminated, q is not!
duke@435 492 if (strlen(s) != (unsigned int) len) return false;
duke@435 493 return strncmp(s, q, len) == 0;
duke@435 494 }
duke@435 495
jmelvin@3650 496 // Search the flag table for a named flag
ccheung@6309 497 Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked, bool return_flag) {
twisti@5790 498 for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
twisti@5790 499 if (str_equal(current->_name, name, length)) {
twisti@5790 500 // Found a matching entry.
twisti@5790 501 // Don't report notproduct and develop flags in product builds.
twisti@5790 502 if (current->is_constant_in_binary()) {
ccheung@6309 503 return (return_flag == true ? current : NULL);
twisti@5790 504 }
twisti@5790 505 // Report locked flags only if allowed.
duke@435 506 if (!(current->is_unlocked() || current->is_unlocker())) {
jmelvin@3650 507 if (!allow_locked) {
jmelvin@3650 508 // disable use of locked flags, e.g. diagnostic, experimental,
jmelvin@3650 509 // commercial... until they are explicitly unlocked
jmelvin@3650 510 return NULL;
jmelvin@3650 511 }
duke@435 512 }
duke@435 513 return current;
duke@435 514 }
duke@435 515 }
jmelvin@3650 516 // Flag name is not in the flag table
duke@435 517 return NULL;
duke@435 518 }
duke@435 519
tamao@5343 520 // Compute string similarity based on Dice's coefficient
tamao@5343 521 static float str_similar(const char* str1, const char* str2, size_t len2) {
tamao@5343 522 int len1 = (int) strlen(str1);
tamao@5343 523 int total = len1 + (int) len2;
tamao@5343 524
tamao@5343 525 int hit = 0;
tamao@5343 526
tamao@5343 527 for (int i = 0; i < len1 -1; ++i) {
tamao@5343 528 for (int j = 0; j < (int) len2 -1; ++j) {
tamao@5343 529 if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
tamao@5343 530 ++hit;
tamao@5343 531 break;
tamao@5343 532 }
tamao@5343 533 }
tamao@5343 534 }
tamao@5343 535
tamao@5343 536 return 2.0f * (float) hit / (float) total;
tamao@5343 537 }
tamao@5343 538
tamao@5343 539 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
tamao@5343 540 float VMOptionsFuzzyMatchSimilarity = 0.7f;
tamao@5343 541 Flag* match = NULL;
tamao@5343 542 float score;
tamao@5343 543 float max_score = -1;
tamao@5343 544
twisti@5790 545 for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
twisti@5790 546 score = str_similar(current->_name, name, length);
tamao@5343 547 if (score > max_score) {
tamao@5343 548 max_score = score;
tamao@5343 549 match = current;
tamao@5343 550 }
tamao@5343 551 }
tamao@5343 552
tamao@5343 553 if (!(match->is_unlocked() || match->is_unlocker())) {
tamao@5343 554 if (!allow_locked) {
tamao@5343 555 return NULL;
tamao@5343 556 }
tamao@5343 557 }
tamao@5343 558
tamao@5343 559 if (max_score < VMOptionsFuzzyMatchSimilarity) {
tamao@5343 560 return NULL;
tamao@5343 561 }
tamao@5343 562
tamao@5343 563 return match;
tamao@5343 564 }
tamao@5343 565
duke@435 566 // Returns the address of the index'th element
duke@435 567 static Flag* address_of_flag(CommandLineFlagWithType flag) {
duke@435 568 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 569 return &Flag::flags[flag];
duke@435 570 }
duke@435 571
duke@435 572 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
duke@435 573 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 574 Flag* f = &Flag::flags[flag];
twisti@5790 575 return f->is_default();
duke@435 576 }
duke@435 577
jmasa@448 578 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
jmasa@448 579 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 580 Flag* f = &Flag::flags[flag];
twisti@5790 581 return f->is_ergonomic();
jmasa@448 582 }
jmasa@448 583
jmasa@448 584 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
jmasa@448 585 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 586 Flag* f = &Flag::flags[flag];
twisti@5790 587 return f->is_command_line();
jmasa@448 588 }
jmasa@448 589
duke@435 590 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
duke@435 591 Flag* result = Flag::find_flag((char*)name, strlen(name));
duke@435 592 if (result == NULL) return false;
twisti@5790 593 *value = result->is_command_line();
duke@435 594 return true;
duke@435 595 }
duke@435 596
sla@6333 597 template<class E, class T>
sla@6333 598 static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin)
sla@6333 599 {
sla@6333 600 E e;
sla@6333 601 e.set_name(name);
sla@6333 602 e.set_old_value(old_value);
sla@6333 603 e.set_new_value(new_value);
sla@6333 604 e.set_origin(origin);
sla@6333 605 e.commit();
sla@6333 606 }
sla@6333 607
duke@435 608 bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
duke@435 609 Flag* result = Flag::find_flag(name, len);
duke@435 610 if (result == NULL) return false;
duke@435 611 if (!result->is_bool()) return false;
duke@435 612 *value = result->get_bool();
duke@435 613 return true;
duke@435 614 }
duke@435 615
twisti@5790 616 bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, Flag::Flags origin) {
duke@435 617 Flag* result = Flag::find_flag(name, len);
duke@435 618 if (result == NULL) return false;
duke@435 619 if (!result->is_bool()) return false;
duke@435 620 bool old_value = result->get_bool();
sla@6333 621 trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin);
duke@435 622 result->set_bool(*value);
duke@435 623 *value = old_value;
twisti@5790 624 result->set_origin(origin);
duke@435 625 return true;
duke@435 626 }
duke@435 627
twisti@5790 628 void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin) {
duke@435 629 Flag* faddr = address_of_flag(flag);
duke@435 630 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
sla@6333 631 trace_flag_changed<EventBooleanFlagChanged, bool>(faddr->_name, faddr->get_bool(), value, origin);
duke@435 632 faddr->set_bool(value);
twisti@5790 633 faddr->set_origin(origin);
duke@435 634 }
duke@435 635
duke@435 636 bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
duke@435 637 Flag* result = Flag::find_flag(name, len);
duke@435 638 if (result == NULL) return false;
duke@435 639 if (!result->is_intx()) return false;
duke@435 640 *value = result->get_intx();
duke@435 641 return true;
duke@435 642 }
duke@435 643
twisti@5790 644 bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, Flag::Flags origin) {
duke@435 645 Flag* result = Flag::find_flag(name, len);
duke@435 646 if (result == NULL) return false;
duke@435 647 if (!result->is_intx()) return false;
duke@435 648 intx old_value = result->get_intx();
sla@6333 649 trace_flag_changed<EventLongFlagChanged, s8>(name, old_value, *value, origin);
duke@435 650 result->set_intx(*value);
duke@435 651 *value = old_value;
twisti@5790 652 result->set_origin(origin);
duke@435 653 return true;
duke@435 654 }
duke@435 655
twisti@5790 656 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) {
duke@435 657 Flag* faddr = address_of_flag(flag);
duke@435 658 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
sla@6333 659 trace_flag_changed<EventLongFlagChanged, s8>(faddr->_name, faddr->get_intx(), value, origin);
duke@435 660 faddr->set_intx(value);
twisti@5790 661 faddr->set_origin(origin);
duke@435 662 }
duke@435 663
duke@435 664 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
duke@435 665 Flag* result = Flag::find_flag(name, len);
duke@435 666 if (result == NULL) return false;
duke@435 667 if (!result->is_uintx()) return false;
duke@435 668 *value = result->get_uintx();
duke@435 669 return true;
duke@435 670 }
duke@435 671
twisti@5790 672 bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, Flag::Flags origin) {
duke@435 673 Flag* result = Flag::find_flag(name, len);
duke@435 674 if (result == NULL) return false;
duke@435 675 if (!result->is_uintx()) return false;
duke@435 676 uintx old_value = result->get_uintx();
sla@6333 677 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
duke@435 678 result->set_uintx(*value);
duke@435 679 *value = old_value;
twisti@5790 680 result->set_origin(origin);
duke@435 681 return true;
duke@435 682 }
duke@435 683
twisti@5790 684 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) {
duke@435 685 Flag* faddr = address_of_flag(flag);
duke@435 686 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
sla@6333 687 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uintx(), value, origin);
duke@435 688 faddr->set_uintx(value);
twisti@5790 689 faddr->set_origin(origin);
duke@435 690 }
duke@435 691
phh@1499 692 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
phh@1499 693 Flag* result = Flag::find_flag(name, len);
phh@1499 694 if (result == NULL) return false;
phh@1499 695 if (!result->is_uint64_t()) return false;
phh@1499 696 *value = result->get_uint64_t();
phh@1499 697 return true;
phh@1499 698 }
phh@1499 699
twisti@5790 700 bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, Flag::Flags origin) {
phh@1499 701 Flag* result = Flag::find_flag(name, len);
phh@1499 702 if (result == NULL) return false;
phh@1499 703 if (!result->is_uint64_t()) return false;
phh@1499 704 uint64_t old_value = result->get_uint64_t();
sla@6333 705 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
phh@1499 706 result->set_uint64_t(*value);
phh@1499 707 *value = old_value;
twisti@5790 708 result->set_origin(origin);
phh@1499 709 return true;
phh@1499 710 }
phh@1499 711
twisti@5790 712 void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin) {
phh@1499 713 Flag* faddr = address_of_flag(flag);
phh@1499 714 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
sla@6333 715 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uint64_t(), value, origin);
phh@1499 716 faddr->set_uint64_t(value);
twisti@5790 717 faddr->set_origin(origin);
phh@1499 718 }
phh@1499 719
duke@435 720 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
duke@435 721 Flag* result = Flag::find_flag(name, len);
duke@435 722 if (result == NULL) return false;
duke@435 723 if (!result->is_double()) return false;
duke@435 724 *value = result->get_double();
duke@435 725 return true;
duke@435 726 }
duke@435 727
twisti@5790 728 bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, Flag::Flags origin) {
duke@435 729 Flag* result = Flag::find_flag(name, len);
duke@435 730 if (result == NULL) return false;
duke@435 731 if (!result->is_double()) return false;
duke@435 732 double old_value = result->get_double();
sla@6333 733 trace_flag_changed<EventDoubleFlagChanged, double>(name, old_value, *value, origin);
duke@435 734 result->set_double(*value);
duke@435 735 *value = old_value;
twisti@5790 736 result->set_origin(origin);
duke@435 737 return true;
duke@435 738 }
duke@435 739
twisti@5790 740 void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) {
duke@435 741 Flag* faddr = address_of_flag(flag);
duke@435 742 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
sla@6333 743 trace_flag_changed<EventDoubleFlagChanged, double>(faddr->_name, faddr->get_double(), value, origin);
duke@435 744 faddr->set_double(value);
twisti@5790 745 faddr->set_origin(origin);
duke@435 746 }
duke@435 747
duke@435 748 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
duke@435 749 Flag* result = Flag::find_flag(name, len);
duke@435 750 if (result == NULL) return false;
duke@435 751 if (!result->is_ccstr()) return false;
duke@435 752 *value = result->get_ccstr();
duke@435 753 return true;
duke@435 754 }
duke@435 755
duke@435 756 // Contract: Flag will make private copy of the incoming value.
duke@435 757 // Outgoing value is always malloc-ed, and caller MUST call free.
twisti@5790 758 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin) {
duke@435 759 Flag* result = Flag::find_flag(name, len);
duke@435 760 if (result == NULL) return false;
duke@435 761 if (!result->is_ccstr()) return false;
duke@435 762 ccstr old_value = result->get_ccstr();
sla@6333 763 trace_flag_changed<EventStringFlagChanged, const char*>(name, old_value, *value, origin);
never@805 764 char* new_value = NULL;
never@805 765 if (*value != NULL) {
zgu@3900 766 new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1, mtInternal);
never@805 767 strcpy(new_value, *value);
never@805 768 }
duke@435 769 result->set_ccstr(new_value);
twisti@5790 770 if (result->is_default() && old_value != NULL) {
duke@435 771 // Prior value is NOT heap allocated, but was a literal constant.
zgu@3900 772 char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1, mtInternal);
duke@435 773 strcpy(old_value_to_free, old_value);
duke@435 774 old_value = old_value_to_free;
duke@435 775 }
duke@435 776 *value = old_value;
twisti@5790 777 result->set_origin(origin);
duke@435 778 return true;
duke@435 779 }
duke@435 780
duke@435 781 // Contract: Flag will make private copy of the incoming value.
twisti@5790 782 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin) {
duke@435 783 Flag* faddr = address_of_flag(flag);
duke@435 784 guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
duke@435 785 ccstr old_value = faddr->get_ccstr();
sla@6333 786 trace_flag_changed<EventStringFlagChanged, const char*>(faddr->_name, old_value, value, origin);
zgu@3900 787 char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal);
duke@435 788 strcpy(new_value, value);
duke@435 789 faddr->set_ccstr(new_value);
twisti@5790 790 if (!faddr->is_default() && old_value != NULL) {
duke@435 791 // Prior value is heap allocated so free it.
zgu@3900 792 FREE_C_HEAP_ARRAY(char, old_value, mtInternal);
duke@435 793 }
twisti@5790 794 faddr->set_origin(origin);
duke@435 795 }
duke@435 796
duke@435 797 extern "C" {
duke@435 798 static int compare_flags(const void* void_a, const void* void_b) {
twisti@5790 799 return strcmp((*((Flag**) void_a))->_name, (*((Flag**) void_b))->_name);
duke@435 800 }
duke@435 801 }
duke@435 802
fparain@3402 803 void CommandLineFlags::printSetFlags(outputStream* out) {
duke@435 804 // Print which flags were set on the command line
duke@435 805 // note: this method is called before the thread structure is in place
duke@435 806 // which means resource allocation cannot be used.
duke@435 807
twisti@5790 808 // The last entry is the null entry.
twisti@5790 809 const size_t length = Flag::numFlags - 1;
duke@435 810
duke@435 811 // Sort
zgu@3900 812 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
twisti@5790 813 for (size_t i = 0; i < length; i++) {
twisti@5790 814 array[i] = &flagTable[i];
duke@435 815 }
duke@435 816 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 817
duke@435 818 // Print
twisti@5790 819 for (size_t i = 0; i < length; i++) {
twisti@5790 820 if (array[i]->get_origin() /* naked field! */) {
fparain@3402 821 array[i]->print_as_flag(out);
fparain@3402 822 out->print(" ");
duke@435 823 }
duke@435 824 }
fparain@3402 825 out->cr();
zgu@3900 826 FREE_C_HEAP_ARRAY(Flag*, array, mtInternal);
duke@435 827 }
duke@435 828
duke@435 829 #ifndef PRODUCT
duke@435 830
duke@435 831
duke@435 832 void CommandLineFlags::verify() {
duke@435 833 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
duke@435 834 }
duke@435 835
kvn@1585 836 #endif // PRODUCT
kvn@1585 837
fparain@3402 838 void CommandLineFlags::printFlags(outputStream* out, bool withComments) {
duke@435 839 // Print the flags sorted by name
duke@435 840 // note: this method is called before the thread structure is in place
duke@435 841 // which means resource allocation cannot be used.
duke@435 842
twisti@5790 843 // The last entry is the null entry.
twisti@5790 844 const size_t length = Flag::numFlags - 1;
duke@435 845
duke@435 846 // Sort
zgu@3900 847 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
twisti@5790 848 for (size_t i = 0; i < length; i++) {
twisti@5790 849 array[i] = &flagTable[i];
duke@435 850 }
duke@435 851 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 852
duke@435 853 // Print
fparain@3402 854 out->print_cr("[Global flags]");
twisti@5790 855 for (size_t i = 0; i < length; i++) {
duke@435 856 if (array[i]->is_unlocked()) {
fparain@3402 857 array[i]->print_on(out, withComments);
duke@435 858 }
duke@435 859 }
zgu@3900 860 FREE_C_HEAP_ARRAY(Flag*, array, mtInternal);
duke@435 861 }

mercurial