src/share/vm/runtime/globals.cpp

Wed, 28 Dec 2011 12:15:57 -0500

author
jiangli
date
Wed, 28 Dec 2011 12:15:57 -0500
changeset 3373
cd5d8cafcc84
parent 3303
cd00eaeebef6
child 3342
6c995c08526c
permissions
-rw-r--r--

7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
Summary: Change instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count to u2 type.
Reviewed-by: never, bdelsart, dholmes
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>

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

mercurial