src/share/vm/runtime/globals.cpp

Sat, 14 Sep 2013 20:40:34 +0100

author
chegar
date
Sat, 14 Sep 2013 20:40:34 +0100
changeset 6240
9b4ce069642e
parent 5628
f98f5d48f511
child 5790
72b7e96c1922
permissions
-rw-r--r--

Merge

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

mercurial