src/share/vm/runtime/globals.cpp

Thu, 14 Aug 2014 15:16:07 +0200

author
dsimms
date
Thu, 14 Aug 2014 15:16:07 +0200
changeset 7032
fa62fb12cdca
parent 6963
0c48231c5c84
child 7282
46140919bf90
permissions
-rw-r--r--

6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
Summary: Wrapped memory with standard bounds checking "GuardedMemory".
Reviewed-by: zgu, fparain, dcubed

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

mercurial