src/share/vm/runtime/globals.cpp

Sun, 03 Feb 2013 22:43:57 +0100

author
ewendeli
date
Sun, 03 Feb 2013 22:43:57 +0100
changeset 4703
b5cb079ecaa4
parent 4020
a5dd6e3ef9f3
child 4542
db9981fd3124
permissions
-rw-r--r--

Merge

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

mercurial