src/share/vm/runtime/globals.cpp

Fri, 08 Oct 2010 09:29:09 -0700

author
jcoomes
date
Fri, 08 Oct 2010 09:29:09 -0700
changeset 2198
0715f0cf171d
parent 2123
6ee479178066
child 2314
f95d63e2154a
permissions
-rw-r--r--

Merge

duke@435 1 /*
twisti@2047 2 * Copyright (c) 1997, 2010, 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
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_globals.cpp.incl"
duke@435 27
duke@435 28
duke@435 29 RUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
duke@435 30 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
ysr@785 31 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_EXPERIMENTAL_FLAG, \
ysr@785 32 MATERIALIZE_NOTPRODUCT_FLAG, \
coleenp@548 33 MATERIALIZE_MANAGEABLE_FLAG, MATERIALIZE_PRODUCT_RW_FLAG, \
coleenp@548 34 MATERIALIZE_LP64_PRODUCT_FLAG)
duke@435 35
duke@435 36 RUNTIME_OS_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
duke@435 37 MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
duke@435 38 MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
duke@435 39
duke@435 40 bool Flag::is_unlocker() const {
ysr@785 41 return strcmp(name, "UnlockDiagnosticVMOptions") == 0 ||
ysr@785 42 strcmp(name, "UnlockExperimentalVMOptions") == 0;
ysr@785 43
duke@435 44 }
duke@435 45
duke@435 46 bool Flag::is_unlocked() const {
duke@435 47 if (strcmp(kind, "{diagnostic}") == 0) {
duke@435 48 return UnlockDiagnosticVMOptions;
never@1515 49 } else if (strcmp(kind, "{experimental}") == 0 ||
never@1515 50 strcmp(kind, "{C2 experimental}") == 0) {
ysr@785 51 return UnlockExperimentalVMOptions;
duke@435 52 } else {
duke@435 53 return true;
duke@435 54 }
duke@435 55 }
duke@435 56
duke@435 57 bool Flag::is_writeable() const {
duke@435 58 return (strcmp(kind, "{manageable}") == 0 || strcmp(kind, "{product rw}") == 0);
duke@435 59 }
duke@435 60
duke@435 61 // All flags except "manageable" are assumed internal flags.
duke@435 62 // Long term, we need to define a mechanism to specify which flags
duke@435 63 // are external/stable and change this function accordingly.
duke@435 64 bool Flag::is_external() const {
duke@435 65 return (strcmp(kind, "{manageable}") == 0);
duke@435 66 }
duke@435 67
duke@435 68 // Length of format string (e.g. "%.1234s") for printing ccstr below
duke@435 69 #define FORMAT_BUFFER_LEN 16
duke@435 70
ikrylov@2123 71 void Flag::print_on(outputStream* st, bool withComments) {
ikrylov@2123 72 st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
phh@1502 73 if (is_bool()) st->print("%-16s", get_bool() ? "true" : "false");
phh@1502 74 if (is_intx()) st->print("%-16ld", get_intx());
phh@1502 75 if (is_uintx()) st->print("%-16lu", get_uintx());
phh@1502 76 if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
ikrylov@2123 77 if (is_double()) st->print("%-16f", get_double());
ikrylov@2123 78
duke@435 79 if (is_ccstr()) {
ikrylov@2123 80 const char* cp = get_ccstr();
ikrylov@2123 81 if (cp != NULL) {
ikrylov@2123 82 const char* eol;
ikrylov@2123 83 while ((eol = strchr(cp, '\n')) != NULL) {
ikrylov@2123 84 char format_buffer[FORMAT_BUFFER_LEN];
ikrylov@2123 85 size_t llen = pointer_delta(eol, cp, sizeof(char));
ikrylov@2123 86 jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
never@538 87 "%%." SIZE_FORMAT "s", llen);
ikrylov@2123 88 st->print(format_buffer, cp);
ikrylov@2123 89 st->cr();
ikrylov@2123 90 cp = eol+1;
ikrylov@2123 91 st->print("%5s %-35s += ", "", name);
ikrylov@2123 92 }
ikrylov@2123 93 st->print("%-16s", cp);
ikrylov@2123 94 }
ikrylov@2123 95 else st->print("%-16s", "");
duke@435 96 }
ikrylov@2123 97 st->print("%-20s", kind);
ikrylov@2123 98 if (withComments) {
ikrylov@2123 99 #ifndef PRODUCT
ikrylov@2123 100 st->print("%s", doc );
ikrylov@2123 101 #endif
ikrylov@2123 102 }
duke@435 103 st->cr();
duke@435 104 }
duke@435 105
duke@435 106 void Flag::print_as_flag(outputStream* st) {
duke@435 107 if (is_bool()) {
duke@435 108 st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
duke@435 109 } else if (is_intx()) {
duke@435 110 st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
duke@435 111 } else if (is_uintx()) {
duke@435 112 st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
phh@1502 113 } else if (is_uint64_t()) {
phh@1502 114 st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
duke@435 115 } else if (is_ccstr()) {
duke@435 116 st->print("-XX:%s=", name);
never@538 117 const char* cp = get_ccstr();
never@538 118 if (cp != NULL) {
never@538 119 // Need to turn embedded '\n's back into separate arguments
never@538 120 // Not so efficient to print one character at a time,
never@538 121 // but the choice is to do the transformation to a buffer
never@538 122 // and print that. And this need not be efficient.
never@538 123 for (; *cp != '\0'; cp += 1) {
never@538 124 switch (*cp) {
never@538 125 default:
never@538 126 st->print("%c", *cp);
never@538 127 break;
never@538 128 case '\n':
never@538 129 st->print(" -XX:%s=", name);
never@538 130 break;
never@538 131 }
duke@435 132 }
duke@435 133 }
duke@435 134 } else {
duke@435 135 ShouldNotReachHere();
duke@435 136 }
duke@435 137 }
duke@435 138
duke@435 139 // 4991491 do not "optimize out" the was_set false values: omitting them
duke@435 140 // tickles a Microsoft compiler bug causing flagTable to be malformed
duke@435 141
ikrylov@2123 142 #define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product}", DEFAULT },
ikrylov@2123 143 #define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{pd product}", DEFAULT },
ikrylov@2123 144 #define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{diagnostic}", DEFAULT },
ikrylov@2123 145 #define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{experimental}", DEFAULT },
ikrylov@2123 146 #define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{manageable}", DEFAULT },
ikrylov@2123 147 #define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product rw}", DEFAULT },
duke@435 148
duke@435 149 #ifdef PRODUCT
duke@435 150 #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
duke@435 151 #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
duke@435 152 #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
duke@435 153 #else
ikrylov@2123 154 #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "", DEFAULT },
ikrylov@2123 155 #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{pd}", DEFAULT },
ikrylov@2123 156 #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{notproduct}", DEFAULT },
duke@435 157 #endif
duke@435 158
coleenp@548 159 #ifdef _LP64
ikrylov@2123 160 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{lp64_product}", DEFAULT },
coleenp@548 161 #else
coleenp@548 162 #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
coleenp@548 163 #endif // _LP64
coleenp@548 164
ikrylov@2123 165 #define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 product}", DEFAULT },
ikrylov@2123 166 #define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 pd product}", DEFAULT },
duke@435 167 #ifdef PRODUCT
duke@435 168 #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
duke@435 169 #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
duke@435 170 #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
duke@435 171 #else
ikrylov@2123 172 #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1}", DEFAULT },
ikrylov@2123 173 #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C1 pd}", DEFAULT },
ikrylov@2123 174 #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1 notproduct}", DEFAULT },
duke@435 175 #endif
duke@435 176
duke@435 177
ikrylov@2123 178 #define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 product}", DEFAULT },
ikrylov@2123 179 #define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 pd product}", DEFAULT },
ikrylov@2123 180 #define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 diagnostic}", DEFAULT },
ikrylov@2123 181 #define C2_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 experimental}", DEFAULT },
duke@435 182 #ifdef PRODUCT
duke@435 183 #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
duke@435 184 #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
duke@435 185 #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
duke@435 186 #else
ikrylov@2123 187 #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2}", DEFAULT },
ikrylov@2123 188 #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C2 pd}", DEFAULT },
ikrylov@2123 189 #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2 notproduct}", DEFAULT },
duke@435 190 #endif
duke@435 191
ikrylov@2123 192 #define SHARK_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark product}", DEFAULT },
ikrylov@2123 193 #define SHARK_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark pd product}", DEFAULT },
ikrylov@2123 194 #define SHARK_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark diagnostic}", DEFAULT },
twisti@2047 195 #ifdef PRODUCT
twisti@2047 196 #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
twisti@2047 197 #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
twisti@2047 198 #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
twisti@2047 199 #else
ikrylov@2123 200 #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark}", DEFAULT },
ikrylov@2123 201 #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{Shark pd}", DEFAULT },
ikrylov@2123 202 #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark notproduct}", DEFAULT },
twisti@2047 203 #endif
duke@435 204
duke@435 205 static Flag flagTable[] = {
ysr@785 206 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 207 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)
ysr@777 208 #ifndef SERIALGC
ysr@785 209 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)
ysr@777 210 #endif // SERIALGC
duke@435 211 #ifdef COMPILER1
duke@435 212 C1_FLAGS(C1_DEVELOP_FLAG_STRUCT, C1_PD_DEVELOP_FLAG_STRUCT, C1_PRODUCT_FLAG_STRUCT, C1_PD_PRODUCT_FLAG_STRUCT, C1_NOTPRODUCT_FLAG_STRUCT)
duke@435 213 #endif
duke@435 214 #ifdef COMPILER2
never@1515 215 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 216 #endif
twisti@2047 217 #ifdef SHARK
twisti@2047 218 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 219 #endif
duke@435 220 {0, NULL, NULL}
duke@435 221 };
duke@435 222
duke@435 223 Flag* Flag::flags = flagTable;
duke@435 224 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
duke@435 225
duke@435 226 inline bool str_equal(const char* s, char* q, size_t len) {
duke@435 227 // s is null terminated, q is not!
duke@435 228 if (strlen(s) != (unsigned int) len) return false;
duke@435 229 return strncmp(s, q, len) == 0;
duke@435 230 }
duke@435 231
duke@435 232 Flag* Flag::find_flag(char* name, size_t length) {
duke@435 233 for (Flag* current = &flagTable[0]; current->name; current++) {
duke@435 234 if (str_equal(current->name, name, length)) {
duke@435 235 if (!(current->is_unlocked() || current->is_unlocker())) {
ysr@785 236 // disable use of diagnostic or experimental flags until they
ysr@785 237 // are explicitly unlocked
duke@435 238 return NULL;
duke@435 239 }
duke@435 240 return current;
duke@435 241 }
duke@435 242 }
duke@435 243 return NULL;
duke@435 244 }
duke@435 245
duke@435 246 // Returns the address of the index'th element
duke@435 247 static Flag* address_of_flag(CommandLineFlagWithType flag) {
duke@435 248 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 249 return &Flag::flags[flag];
duke@435 250 }
duke@435 251
duke@435 252 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
duke@435 253 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 254 Flag* f = &Flag::flags[flag];
duke@435 255 return (f->origin == DEFAULT);
duke@435 256 }
duke@435 257
jmasa@448 258 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
jmasa@448 259 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 260 Flag* f = &Flag::flags[flag];
jmasa@448 261 return (f->origin == ERGONOMIC);
jmasa@448 262 }
jmasa@448 263
jmasa@448 264 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
jmasa@448 265 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 266 Flag* f = &Flag::flags[flag];
jmasa@448 267 return (f->origin == COMMAND_LINE);
jmasa@448 268 }
jmasa@448 269
duke@435 270 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
duke@435 271 Flag* result = Flag::find_flag((char*)name, strlen(name));
duke@435 272 if (result == NULL) return false;
duke@435 273 *value = (result->origin == COMMAND_LINE);
duke@435 274 return true;
duke@435 275 }
duke@435 276
duke@435 277 bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
duke@435 278 Flag* result = Flag::find_flag(name, len);
duke@435 279 if (result == NULL) return false;
duke@435 280 if (!result->is_bool()) return false;
duke@435 281 *value = result->get_bool();
duke@435 282 return true;
duke@435 283 }
duke@435 284
duke@435 285 bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
duke@435 286 Flag* result = Flag::find_flag(name, len);
duke@435 287 if (result == NULL) return false;
duke@435 288 if (!result->is_bool()) return false;
duke@435 289 bool old_value = result->get_bool();
duke@435 290 result->set_bool(*value);
duke@435 291 *value = old_value;
duke@435 292 result->origin = origin;
duke@435 293 return true;
duke@435 294 }
duke@435 295
duke@435 296 void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
duke@435 297 Flag* faddr = address_of_flag(flag);
duke@435 298 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
duke@435 299 faddr->set_bool(value);
duke@435 300 faddr->origin = origin;
duke@435 301 }
duke@435 302
duke@435 303 bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
duke@435 304 Flag* result = Flag::find_flag(name, len);
duke@435 305 if (result == NULL) return false;
duke@435 306 if (!result->is_intx()) return false;
duke@435 307 *value = result->get_intx();
duke@435 308 return true;
duke@435 309 }
duke@435 310
duke@435 311 bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
duke@435 312 Flag* result = Flag::find_flag(name, len);
duke@435 313 if (result == NULL) return false;
duke@435 314 if (!result->is_intx()) return false;
duke@435 315 intx old_value = result->get_intx();
duke@435 316 result->set_intx(*value);
duke@435 317 *value = old_value;
duke@435 318 result->origin = origin;
duke@435 319 return true;
duke@435 320 }
duke@435 321
duke@435 322 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
duke@435 323 Flag* faddr = address_of_flag(flag);
duke@435 324 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
duke@435 325 faddr->set_intx(value);
duke@435 326 faddr->origin = origin;
duke@435 327 }
duke@435 328
duke@435 329 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
duke@435 330 Flag* result = Flag::find_flag(name, len);
duke@435 331 if (result == NULL) return false;
duke@435 332 if (!result->is_uintx()) return false;
duke@435 333 *value = result->get_uintx();
duke@435 334 return true;
duke@435 335 }
duke@435 336
duke@435 337 bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
duke@435 338 Flag* result = Flag::find_flag(name, len);
duke@435 339 if (result == NULL) return false;
duke@435 340 if (!result->is_uintx()) return false;
duke@435 341 uintx old_value = result->get_uintx();
duke@435 342 result->set_uintx(*value);
duke@435 343 *value = old_value;
duke@435 344 result->origin = origin;
duke@435 345 return true;
duke@435 346 }
duke@435 347
duke@435 348 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
duke@435 349 Flag* faddr = address_of_flag(flag);
duke@435 350 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
duke@435 351 faddr->set_uintx(value);
duke@435 352 faddr->origin = origin;
duke@435 353 }
duke@435 354
phh@1499 355 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
phh@1499 356 Flag* result = Flag::find_flag(name, len);
phh@1499 357 if (result == NULL) return false;
phh@1499 358 if (!result->is_uint64_t()) return false;
phh@1499 359 *value = result->get_uint64_t();
phh@1499 360 return true;
phh@1499 361 }
phh@1499 362
phh@1499 363 bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
phh@1499 364 Flag* result = Flag::find_flag(name, len);
phh@1499 365 if (result == NULL) return false;
phh@1499 366 if (!result->is_uint64_t()) return false;
phh@1499 367 uint64_t old_value = result->get_uint64_t();
phh@1499 368 result->set_uint64_t(*value);
phh@1499 369 *value = old_value;
phh@1499 370 result->origin = origin;
phh@1499 371 return true;
phh@1499 372 }
phh@1499 373
phh@1499 374 void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
phh@1499 375 Flag* faddr = address_of_flag(flag);
phh@1499 376 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
phh@1499 377 faddr->set_uint64_t(value);
phh@1499 378 faddr->origin = origin;
phh@1499 379 }
phh@1499 380
duke@435 381 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
duke@435 382 Flag* result = Flag::find_flag(name, len);
duke@435 383 if (result == NULL) return false;
duke@435 384 if (!result->is_double()) return false;
duke@435 385 *value = result->get_double();
duke@435 386 return true;
duke@435 387 }
duke@435 388
duke@435 389 bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
duke@435 390 Flag* result = Flag::find_flag(name, len);
duke@435 391 if (result == NULL) return false;
duke@435 392 if (!result->is_double()) return false;
duke@435 393 double old_value = result->get_double();
duke@435 394 result->set_double(*value);
duke@435 395 *value = old_value;
duke@435 396 result->origin = origin;
duke@435 397 return true;
duke@435 398 }
duke@435 399
duke@435 400 void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
duke@435 401 Flag* faddr = address_of_flag(flag);
duke@435 402 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
duke@435 403 faddr->set_double(value);
duke@435 404 faddr->origin = origin;
duke@435 405 }
duke@435 406
duke@435 407 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
duke@435 408 Flag* result = Flag::find_flag(name, len);
duke@435 409 if (result == NULL) return false;
duke@435 410 if (!result->is_ccstr()) return false;
duke@435 411 *value = result->get_ccstr();
duke@435 412 return true;
duke@435 413 }
duke@435 414
duke@435 415 // Contract: Flag will make private copy of the incoming value.
duke@435 416 // Outgoing value is always malloc-ed, and caller MUST call free.
duke@435 417 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
duke@435 418 Flag* result = Flag::find_flag(name, len);
duke@435 419 if (result == NULL) return false;
duke@435 420 if (!result->is_ccstr()) return false;
duke@435 421 ccstr old_value = result->get_ccstr();
never@805 422 char* new_value = NULL;
never@805 423 if (*value != NULL) {
never@805 424 new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1);
never@805 425 strcpy(new_value, *value);
never@805 426 }
duke@435 427 result->set_ccstr(new_value);
duke@435 428 if (result->origin == DEFAULT && old_value != NULL) {
duke@435 429 // Prior value is NOT heap allocated, but was a literal constant.
duke@435 430 char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1);
duke@435 431 strcpy(old_value_to_free, old_value);
duke@435 432 old_value = old_value_to_free;
duke@435 433 }
duke@435 434 *value = old_value;
duke@435 435 result->origin = origin;
duke@435 436 return true;
duke@435 437 }
duke@435 438
duke@435 439 // Contract: Flag will make private copy of the incoming value.
duke@435 440 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
duke@435 441 Flag* faddr = address_of_flag(flag);
duke@435 442 guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
duke@435 443 ccstr old_value = faddr->get_ccstr();
duke@435 444 char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1);
duke@435 445 strcpy(new_value, value);
duke@435 446 faddr->set_ccstr(new_value);
duke@435 447 if (faddr->origin != DEFAULT && old_value != NULL) {
duke@435 448 // Prior value is heap allocated so free it.
duke@435 449 FREE_C_HEAP_ARRAY(char, old_value);
duke@435 450 }
duke@435 451 faddr->origin = origin;
duke@435 452 }
duke@435 453
duke@435 454 extern "C" {
duke@435 455 static int compare_flags(const void* void_a, const void* void_b) {
duke@435 456 return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
duke@435 457 }
duke@435 458 }
duke@435 459
duke@435 460 void CommandLineFlags::printSetFlags() {
duke@435 461 // Print which flags were set on the command line
duke@435 462 // note: this method is called before the thread structure is in place
duke@435 463 // which means resource allocation cannot be used.
duke@435 464
duke@435 465 // Compute size
duke@435 466 int length= 0;
duke@435 467 while (flagTable[length].name != NULL) length++;
duke@435 468
duke@435 469 // Sort
duke@435 470 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
duke@435 471 for (int index = 0; index < length; index++) {
duke@435 472 array[index] = &flagTable[index];
duke@435 473 }
duke@435 474 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 475
duke@435 476 // Print
duke@435 477 for (int i = 0; i < length; i++) {
duke@435 478 if (array[i]->origin /* naked field! */) {
duke@435 479 array[i]->print_as_flag(tty);
duke@435 480 tty->print(" ");
duke@435 481 }
duke@435 482 }
duke@435 483 tty->cr();
duke@435 484 FREE_C_HEAP_ARRAY(Flag*, array);
duke@435 485 }
duke@435 486
duke@435 487 #ifndef PRODUCT
duke@435 488
duke@435 489
duke@435 490 void CommandLineFlags::verify() {
duke@435 491 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
duke@435 492 }
duke@435 493
kvn@1585 494 #endif // PRODUCT
kvn@1585 495
ikrylov@2123 496 void CommandLineFlags::printFlags(bool withComments) {
duke@435 497 // Print the flags sorted by name
duke@435 498 // note: this method is called before the thread structure is in place
duke@435 499 // which means resource allocation cannot be used.
duke@435 500
duke@435 501 // Compute size
duke@435 502 int length= 0;
duke@435 503 while (flagTable[length].name != NULL) length++;
duke@435 504
duke@435 505 // Sort
duke@435 506 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
duke@435 507 for (int index = 0; index < length; index++) {
duke@435 508 array[index] = &flagTable[index];
duke@435 509 }
duke@435 510 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 511
duke@435 512 // Print
duke@435 513 tty->print_cr("[Global flags]");
duke@435 514 for (int i = 0; i < length; i++) {
duke@435 515 if (array[i]->is_unlocked()) {
ikrylov@2123 516 array[i]->print_on(tty, withComments);
duke@435 517 }
duke@435 518 }
duke@435 519 FREE_C_HEAP_ARRAY(Flag*, array);
duke@435 520 }

mercurial