src/share/vm/runtime/globals.cpp

Thu, 07 Feb 2013 16:05:48 -0500

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

mercurial