src/share/vm/runtime/globals.cpp

Fri, 28 Jun 2013 20:18:04 -0700

author
tamao
date
Fri, 28 Jun 2013 20:18:04 -0700
changeset 5343
6e3634222155
parent 5301
b3cd8b58b798
child 5628
f98f5d48f511
permissions
-rw-r--r--

8017611: Auto corrector for mistyped vm options
Summary: The auto corrector for mistyped vm options fuzzy-matches existing flags based on string similarity (Dice's coefficient).
Reviewed-by: kvn, dsamersoff, hseigel, johnc

duke@435 1 /*
kmo@4586 2 * Copyright (c) 1997, 2013, 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 {
kmo@4586 72 if (strcmp(kind, "{diagnostic}") == 0 ||
kmo@4586 73 strcmp(kind, "{C2 diagnostic}") == 0 ||
kmo@4586 74 strcmp(kind, "{ARCH diagnostic}") == 0 ||
kmo@4586 75 strcmp(kind, "{Shark diagnostic}") == 0) {
duke@435 76 return UnlockDiagnosticVMOptions;
never@1515 77 } else if (strcmp(kind, "{experimental}") == 0 ||
kmo@4586 78 strcmp(kind, "{C2 experimental}") == 0 ||
kmo@4586 79 strcmp(kind, "{ARCH experimental}") == 0 ||
kmo@4586 80 strcmp(kind, "{Shark 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)
jprovino@4542 259 #if INCLUDE_ALL_GCS
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)
jprovino@4542 261 #endif // INCLUDE_ALL_GCS
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
tamao@5343 279 inline bool str_equal(const char* s, const 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
tamao@5343 286 Flag* Flag::find_flag(const 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
tamao@5343 304 // Compute string similarity based on Dice's coefficient
tamao@5343 305 static float str_similar(const char* str1, const char* str2, size_t len2) {
tamao@5343 306 int len1 = (int) strlen(str1);
tamao@5343 307 int total = len1 + (int) len2;
tamao@5343 308
tamao@5343 309 int hit = 0;
tamao@5343 310
tamao@5343 311 for (int i = 0; i < len1 -1; ++i) {
tamao@5343 312 for (int j = 0; j < (int) len2 -1; ++j) {
tamao@5343 313 if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
tamao@5343 314 ++hit;
tamao@5343 315 break;
tamao@5343 316 }
tamao@5343 317 }
tamao@5343 318 }
tamao@5343 319
tamao@5343 320 return 2.0f * (float) hit / (float) total;
tamao@5343 321 }
tamao@5343 322
tamao@5343 323 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
tamao@5343 324 float VMOptionsFuzzyMatchSimilarity = 0.7f;
tamao@5343 325 Flag* match = NULL;
tamao@5343 326 float score;
tamao@5343 327 float max_score = -1;
tamao@5343 328
tamao@5343 329 for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
tamao@5343 330 score = str_similar(current->name, name, length);
tamao@5343 331 if (score > max_score) {
tamao@5343 332 max_score = score;
tamao@5343 333 match = current;
tamao@5343 334 }
tamao@5343 335 }
tamao@5343 336
tamao@5343 337 if (!(match->is_unlocked() || match->is_unlocker())) {
tamao@5343 338 if (!allow_locked) {
tamao@5343 339 return NULL;
tamao@5343 340 }
tamao@5343 341 }
tamao@5343 342
tamao@5343 343 if (max_score < VMOptionsFuzzyMatchSimilarity) {
tamao@5343 344 return NULL;
tamao@5343 345 }
tamao@5343 346
tamao@5343 347 return match;
tamao@5343 348 }
tamao@5343 349
duke@435 350 // Returns the address of the index'th element
duke@435 351 static Flag* address_of_flag(CommandLineFlagWithType flag) {
duke@435 352 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 353 return &Flag::flags[flag];
duke@435 354 }
duke@435 355
duke@435 356 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
duke@435 357 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
duke@435 358 Flag* f = &Flag::flags[flag];
duke@435 359 return (f->origin == DEFAULT);
duke@435 360 }
duke@435 361
jmasa@448 362 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
jmasa@448 363 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 364 Flag* f = &Flag::flags[flag];
jmasa@448 365 return (f->origin == ERGONOMIC);
jmasa@448 366 }
jmasa@448 367
jmasa@448 368 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
jmasa@448 369 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
jmasa@448 370 Flag* f = &Flag::flags[flag];
jmasa@448 371 return (f->origin == COMMAND_LINE);
jmasa@448 372 }
jmasa@448 373
duke@435 374 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
duke@435 375 Flag* result = Flag::find_flag((char*)name, strlen(name));
duke@435 376 if (result == NULL) return false;
duke@435 377 *value = (result->origin == COMMAND_LINE);
duke@435 378 return true;
duke@435 379 }
duke@435 380
duke@435 381 bool CommandLineFlags::boolAt(char* name, size_t len, bool* 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_bool()) return false;
duke@435 385 *value = result->get_bool();
duke@435 386 return true;
duke@435 387 }
duke@435 388
duke@435 389 bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* 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_bool()) return false;
duke@435 393 bool old_value = result->get_bool();
duke@435 394 result->set_bool(*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::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
duke@435 401 Flag* faddr = address_of_flag(flag);
duke@435 402 guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
duke@435 403 faddr->set_bool(value);
duke@435 404 faddr->origin = origin;
duke@435 405 }
duke@435 406
duke@435 407 bool CommandLineFlags::intxAt(char* name, size_t len, intx* 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_intx()) return false;
duke@435 411 *value = result->get_intx();
duke@435 412 return true;
duke@435 413 }
duke@435 414
duke@435 415 bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
duke@435 416 Flag* result = Flag::find_flag(name, len);
duke@435 417 if (result == NULL) return false;
duke@435 418 if (!result->is_intx()) return false;
duke@435 419 intx old_value = result->get_intx();
duke@435 420 result->set_intx(*value);
duke@435 421 *value = old_value;
duke@435 422 result->origin = origin;
duke@435 423 return true;
duke@435 424 }
duke@435 425
duke@435 426 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
duke@435 427 Flag* faddr = address_of_flag(flag);
duke@435 428 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
duke@435 429 faddr->set_intx(value);
duke@435 430 faddr->origin = origin;
duke@435 431 }
duke@435 432
duke@435 433 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
duke@435 434 Flag* result = Flag::find_flag(name, len);
duke@435 435 if (result == NULL) return false;
duke@435 436 if (!result->is_uintx()) return false;
duke@435 437 *value = result->get_uintx();
duke@435 438 return true;
duke@435 439 }
duke@435 440
duke@435 441 bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
duke@435 442 Flag* result = Flag::find_flag(name, len);
duke@435 443 if (result == NULL) return false;
duke@435 444 if (!result->is_uintx()) return false;
duke@435 445 uintx old_value = result->get_uintx();
duke@435 446 result->set_uintx(*value);
duke@435 447 *value = old_value;
duke@435 448 result->origin = origin;
duke@435 449 return true;
duke@435 450 }
duke@435 451
duke@435 452 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
duke@435 453 Flag* faddr = address_of_flag(flag);
duke@435 454 guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
duke@435 455 faddr->set_uintx(value);
duke@435 456 faddr->origin = origin;
duke@435 457 }
duke@435 458
phh@1499 459 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
phh@1499 460 Flag* result = Flag::find_flag(name, len);
phh@1499 461 if (result == NULL) return false;
phh@1499 462 if (!result->is_uint64_t()) return false;
phh@1499 463 *value = result->get_uint64_t();
phh@1499 464 return true;
phh@1499 465 }
phh@1499 466
phh@1499 467 bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
phh@1499 468 Flag* result = Flag::find_flag(name, len);
phh@1499 469 if (result == NULL) return false;
phh@1499 470 if (!result->is_uint64_t()) return false;
phh@1499 471 uint64_t old_value = result->get_uint64_t();
phh@1499 472 result->set_uint64_t(*value);
phh@1499 473 *value = old_value;
phh@1499 474 result->origin = origin;
phh@1499 475 return true;
phh@1499 476 }
phh@1499 477
phh@1499 478 void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
phh@1499 479 Flag* faddr = address_of_flag(flag);
phh@1499 480 guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
phh@1499 481 faddr->set_uint64_t(value);
phh@1499 482 faddr->origin = origin;
phh@1499 483 }
phh@1499 484
duke@435 485 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
duke@435 486 Flag* result = Flag::find_flag(name, len);
duke@435 487 if (result == NULL) return false;
duke@435 488 if (!result->is_double()) return false;
duke@435 489 *value = result->get_double();
duke@435 490 return true;
duke@435 491 }
duke@435 492
duke@435 493 bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
duke@435 494 Flag* result = Flag::find_flag(name, len);
duke@435 495 if (result == NULL) return false;
duke@435 496 if (!result->is_double()) return false;
duke@435 497 double old_value = result->get_double();
duke@435 498 result->set_double(*value);
duke@435 499 *value = old_value;
duke@435 500 result->origin = origin;
duke@435 501 return true;
duke@435 502 }
duke@435 503
duke@435 504 void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
duke@435 505 Flag* faddr = address_of_flag(flag);
duke@435 506 guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
duke@435 507 faddr->set_double(value);
duke@435 508 faddr->origin = origin;
duke@435 509 }
duke@435 510
duke@435 511 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
duke@435 512 Flag* result = Flag::find_flag(name, len);
duke@435 513 if (result == NULL) return false;
duke@435 514 if (!result->is_ccstr()) return false;
duke@435 515 *value = result->get_ccstr();
duke@435 516 return true;
duke@435 517 }
duke@435 518
duke@435 519 // Contract: Flag will make private copy of the incoming value.
duke@435 520 // Outgoing value is always malloc-ed, and caller MUST call free.
duke@435 521 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
duke@435 522 Flag* result = Flag::find_flag(name, len);
duke@435 523 if (result == NULL) return false;
duke@435 524 if (!result->is_ccstr()) return false;
duke@435 525 ccstr old_value = result->get_ccstr();
never@805 526 char* new_value = NULL;
never@805 527 if (*value != NULL) {
zgu@3900 528 new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1, mtInternal);
never@805 529 strcpy(new_value, *value);
never@805 530 }
duke@435 531 result->set_ccstr(new_value);
duke@435 532 if (result->origin == DEFAULT && old_value != NULL) {
duke@435 533 // Prior value is NOT heap allocated, but was a literal constant.
zgu@3900 534 char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1, mtInternal);
duke@435 535 strcpy(old_value_to_free, old_value);
duke@435 536 old_value = old_value_to_free;
duke@435 537 }
duke@435 538 *value = old_value;
duke@435 539 result->origin = origin;
duke@435 540 return true;
duke@435 541 }
duke@435 542
duke@435 543 // Contract: Flag will make private copy of the incoming value.
duke@435 544 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
duke@435 545 Flag* faddr = address_of_flag(flag);
duke@435 546 guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
duke@435 547 ccstr old_value = faddr->get_ccstr();
zgu@3900 548 char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal);
duke@435 549 strcpy(new_value, value);
duke@435 550 faddr->set_ccstr(new_value);
duke@435 551 if (faddr->origin != DEFAULT && old_value != NULL) {
duke@435 552 // Prior value is heap allocated so free it.
zgu@3900 553 FREE_C_HEAP_ARRAY(char, old_value, mtInternal);
duke@435 554 }
duke@435 555 faddr->origin = origin;
duke@435 556 }
duke@435 557
duke@435 558 extern "C" {
duke@435 559 static int compare_flags(const void* void_a, const void* void_b) {
duke@435 560 return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
duke@435 561 }
duke@435 562 }
duke@435 563
fparain@3402 564 void CommandLineFlags::printSetFlags(outputStream* out) {
duke@435 565 // Print which flags were set on the command line
duke@435 566 // note: this method is called before the thread structure is in place
duke@435 567 // which means resource allocation cannot be used.
duke@435 568
duke@435 569 // Compute size
duke@435 570 int length= 0;
duke@435 571 while (flagTable[length].name != NULL) length++;
duke@435 572
duke@435 573 // Sort
zgu@3900 574 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
duke@435 575 for (int index = 0; index < length; index++) {
duke@435 576 array[index] = &flagTable[index];
duke@435 577 }
duke@435 578 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 579
duke@435 580 // Print
duke@435 581 for (int i = 0; i < length; i++) {
duke@435 582 if (array[i]->origin /* naked field! */) {
fparain@3402 583 array[i]->print_as_flag(out);
fparain@3402 584 out->print(" ");
duke@435 585 }
duke@435 586 }
fparain@3402 587 out->cr();
zgu@3900 588 FREE_C_HEAP_ARRAY(Flag*, array, mtInternal);
duke@435 589 }
duke@435 590
duke@435 591 #ifndef PRODUCT
duke@435 592
duke@435 593
duke@435 594 void CommandLineFlags::verify() {
duke@435 595 assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
duke@435 596 }
duke@435 597
kvn@1585 598 #endif // PRODUCT
kvn@1585 599
fparain@3402 600 void CommandLineFlags::printFlags(outputStream* out, bool withComments) {
duke@435 601 // Print the flags sorted by name
duke@435 602 // note: this method is called before the thread structure is in place
duke@435 603 // which means resource allocation cannot be used.
duke@435 604
duke@435 605 // Compute size
duke@435 606 int length= 0;
duke@435 607 while (flagTable[length].name != NULL) length++;
duke@435 608
duke@435 609 // Sort
zgu@3900 610 Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
duke@435 611 for (int index = 0; index < length; index++) {
duke@435 612 array[index] = &flagTable[index];
duke@435 613 }
duke@435 614 qsort(array, length, sizeof(Flag*), compare_flags);
duke@435 615
duke@435 616 // Print
fparain@3402 617 out->print_cr("[Global flags]");
duke@435 618 for (int i = 0; i < length; i++) {
duke@435 619 if (array[i]->is_unlocked()) {
fparain@3402 620 array[i]->print_on(out, withComments);
duke@435 621 }
duke@435 622 }
zgu@3900 623 FREE_C_HEAP_ARRAY(Flag*, array, mtInternal);
duke@435 624 }

mercurial