src/share/vm/runtime/globals.cpp

Wed, 02 Feb 2011 11:35:26 -0500

author
bobv
date
Wed, 02 Feb 2011 11:35:26 -0500
changeset 2508
b92c45f2bc75
parent 2314
f95d63e2154a
child 2742
ed69575596ac
permissions
-rw-r--r--

7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart

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

mercurial