globals.cpp revision 3053
869N/A/*
869N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869N/A * or visit www.oracle.com if you need additional information or have any
869N/A * questions.
869N/A *
5005N/A */
5299N/A
869N/A#include "precompiled.hpp"
869N/A#include "memory/allocation.inline.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A#include "runtime/arguments.hpp"
0N/A#include "runtime/globals.hpp"
0N/A#include "runtime/globals_extension.hpp"
869N/A#include "utilities/ostream.hpp"
0N/A#include "utilities/top.hpp"
0N/A#ifndef SERIALGC
0N/A#include "gc_implementation/g1/g1_globals.hpp"
869N/A#endif
0N/A#ifdef COMPILER1
869N/A#include "c1/c1_globals.hpp"
0N/A#endif
869N/A#ifdef COMPILER2
869N/A#include "opto/c2_globals.hpp"
869N/A#endif
2624N/A#ifdef SHARK
869N/A#include "shark/shark_globals.hpp"
48N/A#endif
869N/A
0N/A
869N/ARUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
716N/A MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
869N/A MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_EXPERIMENTAL_FLAG, \
1958N/A MATERIALIZE_NOTPRODUCT_FLAG, \
1963N/A MATERIALIZE_MANAGEABLE_FLAG, MATERIALIZE_PRODUCT_RW_FLAG, \
2340N/A MATERIALIZE_LP64_PRODUCT_FLAG)
3103N/A
3127N/ARUNTIME_OS_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
3679N/A MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
5244N/A MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
1954N/A
1954N/AMATERIALIZE_FLAGS_EXT
1954N/A
1954N/A
1954N/Abool Flag::is_unlocker() const {
1954N/A return strcmp(name, "UnlockDiagnosticVMOptions") == 0 ||
4306N/A strcmp(name, "UnlockExperimentalVMOptions") == 0 ||
4306N/A is_unlocker_ext();
4306N/A}
1954N/A
1954N/Abool Flag::is_unlocked() const {
1954N/A if (strcmp(kind, "{diagnostic}") == 0) {
1954N/A if (strcmp(name, "EnableInvokeDynamic") == 0 && UnlockExperimentalVMOptions && !UnlockDiagnosticVMOptions) {
5221N/A // transitional logic to allow tests to run until they are changed
0N/A static int warned;
0N/A if (++warned == 1) warning("Use -XX:+UnlockDiagnosticVMOptions before EnableInvokeDynamic flag");
869N/A return true;
868N/A }
2624N/A return UnlockDiagnosticVMOptions;
2693N/A } else if (strcmp(kind, "{experimental}") == 0 ||
2042N/A strcmp(kind, "{C2 experimental}") == 0) {
4563N/A return UnlockExperimentalVMOptions;
5299N/A } else {
4898N/A return is_unlocked_ext();
4898N/A }
2980N/A}
2963N/A
1503N/Abool Flag::is_writeable() const {
2915N/A return strcmp(kind, "{manageable}") == 0 ||
869N/A strcmp(kind, "{product rw}") == 0 ||
2624N/A is_writeable_ext();
2624N/A}
0N/A
2270N/A// All flags except "manageable" are assumed to be internal flags.
2270N/A// Long term, we need to define a mechanism to specify which flags
2270N/A// are external/stable and change this function accordingly.
2270N/Abool Flag::is_external() const {
2270N/A return strcmp(kind, "{manageable}") == 0 || is_external_ext();
2270N/A}
2270N/A
0N/A
869N/A// Length of format string (e.g. "%.1234s") for printing ccstr below
868N/A#define FORMAT_BUFFER_LEN 16
0N/A
0N/Avoid Flag::print_on(outputStream* st, bool withComments) {
65N/A st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
869N/A if (is_bool()) st->print("%-16s", get_bool() ? "true" : "false");
868N/A if (is_intx()) st->print("%-16ld", get_intx());
65N/A if (is_uintx()) st->print("%-16lu", get_uintx());
869N/A if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
2624N/A if (is_double()) st->print("%-16f", get_double());
2624N/A
65N/A if (is_ccstr()) {
65N/A const char* cp = get_ccstr();
65N/A if (cp != NULL) {
65N/A const char* eol;
65N/A while ((eol = strchr(cp, '\n')) != NULL) {
65N/A char format_buffer[FORMAT_BUFFER_LEN];
65N/A size_t llen = pointer_delta(eol, cp, sizeof(char));
65N/A jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
65N/A "%%." SIZE_FORMAT "s", llen);
65N/A st->print(format_buffer, cp);
65N/A st->cr();
65N/A cp = eol+1;
65N/A st->print("%5s %-35s += ", "", name);
2266N/A }
2266N/A st->print("%-16s", cp);
2266N/A }
2266N/A else st->print("%-16s", "");
2266N/A }
2624N/A st->print("%-20s", kind);
2624N/A if (withComments) {
2266N/A#ifndef PRODUCT
2266N/A st->print("%s", doc );
2624N/A#endif
2266N/A }
2266N/A st->cr();
2266N/A}
2266N/A
2266N/Avoid Flag::print_as_flag(outputStream* st) {
2266N/A if (is_bool()) {
2266N/A st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
2266N/A } else if (is_intx()) {
2266N/A st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
2266N/A } else if (is_uintx()) {
2266N/A st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
2266N/A } else if (is_uint64_t()) {
2266N/A st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
2266N/A } else if (is_ccstr()) {
2266N/A st->print("-XX:%s=", name);
2266N/A const char* cp = get_ccstr();
2266N/A if (cp != NULL) {
2266N/A // Need to turn embedded '\n's back into separate arguments
2266N/A // Not so efficient to print one character at a time,
2266N/A // but the choice is to do the transformation to a buffer
2266N/A // and print that. And this need not be efficient.
2266N/A for (; *cp != '\0'; cp += 1) {
2266N/A switch (*cp) {
2266N/A default:
2266N/A st->print("%c", *cp);
0N/A break;
869N/A case '\n':
868N/A st->print(" -XX:%s=", name);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A } else {
2334N/A ShouldNotReachHere();
0N/A }
2624N/A}
2624N/A
0N/A// 4991491 do not "optimize out" the was_set false values: omitting them
0N/A// tickles a Microsoft compiler bug causing flagTable to be malformed
869N/A
868N/A#define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product}", DEFAULT },
0N/A#define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{pd product}", DEFAULT },
0N/A#define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{diagnostic}", DEFAULT },
869N/A#define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{experimental}", DEFAULT },
0N/A#define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{manageable}", DEFAULT },
0N/A#define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product rw}", DEFAULT },
2624N/A
2624N/A#ifdef PRODUCT
2624N/A #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
869N/A #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
2624N/A #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
2624N/A#else
2624N/A #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "", DEFAULT },
2624N/A #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{pd}", DEFAULT },
2624N/A #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{notproduct}", DEFAULT },
2624N/A#endif
2624N/A
2624N/A#ifdef _LP64
2624N/A #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{lp64_product}", DEFAULT },
2624N/A#else
2624N/A #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
2624N/A#endif // _LP64
2624N/A
4457N/A#define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 product}", DEFAULT },
2624N/A#define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 pd product}", DEFAULT },
2624N/A#ifdef PRODUCT
5268N/A #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
5268N/A #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
5268N/A #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
5191N/A#else
2624N/A #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1}", DEFAULT },
2624N/A #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C1 pd}", DEFAULT },
5191N/A #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1 notproduct}", DEFAULT },
2624N/A#endif
5203N/A
5203N/A
0N/A#define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 product}", DEFAULT },
0N/A#define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 pd product}", DEFAULT },
869N/A#define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 diagnostic}", DEFAULT },
868N/A#define C2_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 experimental}", DEFAULT },
0N/A#ifdef PRODUCT
0N/A #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
2624N/A #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
848N/A #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
2624N/A#else
2624N/A #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2}", DEFAULT },
868N/A #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{C2 pd}", DEFAULT },
848N/A #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2 notproduct}", DEFAULT },
2624N/A#endif
0N/A
2624N/A#define SHARK_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark product}", DEFAULT },
2624N/A#define SHARK_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark pd product}", DEFAULT },
0N/A#define SHARK_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark diagnostic}", DEFAULT },
0N/A#ifdef PRODUCT
868N/A #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
2624N/A #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
2222N/A #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
2624N/A#else
2624N/A #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark}", DEFAULT },
2222N/A #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, doc, "{Shark pd}", DEFAULT },
2222N/A #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark notproduct}", DEFAULT },
5161N/A#endif
5161N/A
5161N/Astatic Flag flagTable[] = {
5161N/A 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)
5161N/A 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)
5161N/A#ifndef SERIALGC
2624N/A 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)
2222N/A#endif // SERIALGC
2624N/A#ifdef COMPILER1
2624N/A C1_FLAGS(C1_DEVELOP_FLAG_STRUCT, C1_PD_DEVELOP_FLAG_STRUCT, C1_PRODUCT_FLAG_STRUCT, C1_PD_PRODUCT_FLAG_STRUCT, C1_NOTPRODUCT_FLAG_STRUCT)
2222N/A#endif
2222N/A#ifdef COMPILER2
2624N/A 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)
868N/A#endif
2624N/A#ifdef SHARK
2624N/A 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)
115N/A#endif
868N/A FLAGTABLE_EXT
868N/A {0, NULL, NULL}
2624N/A};
868N/A
2624N/AFlag* Flag::flags = flagTable;
2624N/Asize_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
868N/A
868N/Ainline bool str_equal(const char* s, char* q, size_t len) {
868N/A // s is null terminated, q is not!
2624N/A if (strlen(s) != (unsigned int) len) return false;
868N/A return strncmp(s, q, len) == 0;
2624N/A}
2624N/A
868N/AFlag* Flag::find_flag(char* name, size_t length) {
868N/A for (Flag* current = &flagTable[0]; current->name; current++) {
2624N/A if (str_equal(current->name, name, length)) {
868N/A if (!(current->is_unlocked() || current->is_unlocker())) {
2624N/A // disable use of diagnostic or experimental flags until they
2624N/A // are explicitly unlocked
868N/A return NULL;
868N/A }
2624N/A return current;
868N/A }
2624N/A }
2624N/A return NULL;
868N/A}
868N/A
868N/A// Returns the address of the index'th element
2624N/Astatic Flag* address_of_flag(CommandLineFlagWithType flag) {
868N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
2624N/A return &Flag::flags[flag];
2624N/A}
868N/A
868N/Abool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
868N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
2624N/A Flag* f = &Flag::flags[flag];
868N/A return (f->origin == DEFAULT);
2624N/A}
2624N/A
868N/Abool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
0N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
2624N/A Flag* f = &Flag::flags[flag];
0N/A return (f->origin == ERGONOMIC);
2624N/A}
2624N/A
868N/Abool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
868N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
1948N/A Flag* f = &Flag::flags[flag];
1948N/A return (f->origin == COMMAND_LINE);
1948N/A}
1948N/A
1948N/Abool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
869N/A Flag* result = Flag::find_flag((char*)name, strlen(name));
869N/A if (result == NULL) return false;
869N/A *value = (result->origin == COMMAND_LINE);
869N/A return true;
2624N/A}
2624N/A
869N/Abool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
2624N/A Flag* result = Flag::find_flag(name, len);
2624N/A if (result == NULL) return false;
869N/A if (!result->is_bool()) return false;
869N/A *value = result->get_bool();
869N/A return true;
869N/A}
869N/A
2334N/Abool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
2624N/A Flag* result = Flag::find_flag(name, len);
2624N/A if (result == NULL) return false;
869N/A if (!result->is_bool()) return false;
2624N/A bool old_value = result->get_bool();
2624N/A result->set_bool(*value);
869N/A *value = old_value;
2270N/A result->origin = origin;
2270N/A return true;
2270N/A}
2270N/A
2270N/Avoid CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
2624N/A Flag* faddr = address_of_flag(flag);
2624N/A guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
2624N/A faddr->set_bool(value);
2624N/A faddr->origin = origin;
2270N/A}
2270N/A
2270N/Abool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
2270N/A Flag* result = Flag::find_flag(name, len);
869N/A if (result == NULL) return false;
869N/A if (!result->is_intx()) return false;
869N/A *value = result->get_intx();
2334N/A return true;
2624N/A}
2624N/A
869N/Abool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
2624N/A Flag* result = Flag::find_flag(name, len);
2624N/A if (result == NULL) return false;
869N/A if (!result->is_intx()) return false;
869N/A intx old_value = result->get_intx();
869N/A result->set_intx(*value);
869N/A *value = old_value;
869N/A result->origin = origin;
2624N/A return true;
2624N/A}
869N/A
2624N/Avoid CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
2624N/A Flag* faddr = address_of_flag(flag);
869N/A guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
869N/A faddr->set_intx(value);
869N/A faddr->origin = origin;
869N/A}
869N/A
869N/Abool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
2624N/A Flag* result = Flag::find_flag(name, len);
2624N/A if (result == NULL) return false;
869N/A if (!result->is_uintx()) return false;
2624N/A *value = result->get_uintx();
2624N/A return true;
869N/A}
869N/A
0N/Abool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
2615N/A Flag* result = Flag::find_flag(name, len);
2615N/A if (result == NULL) return false;
2615N/A if (!result->is_uintx()) return false;
2615N/A uintx old_value = result->get_uintx();
2615N/A result->set_uintx(*value);
2624N/A *value = old_value;
2624N/A result->origin = origin;
2624N/A return true;
2624N/A}
2615N/A
2622N/Avoid CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
2615N/A Flag* faddr = address_of_flag(flag);
824N/A guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
869N/A faddr->set_uintx(value);
868N/A faddr->origin = origin;
824N/A}
824N/A
824N/Abool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
824N/A Flag* result = Flag::find_flag(name, len);
824N/A if (result == NULL) return false;
2334N/A if (!result->is_uint64_t()) return false;
869N/A *value = result->get_uint64_t();
2624N/A return true;
2624N/A}
869N/A
869N/Abool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
869N/A Flag* result = Flag::find_flag(name, len);
869N/A if (result == NULL) return false;
869N/A if (!result->is_uint64_t()) return false;
869N/A uint64_t old_value = result->get_uint64_t();
2624N/A result->set_uint64_t(*value);
2624N/A *value = old_value;
2624N/A result->origin = origin;
869N/A return true;
869N/A}
869N/A
869N/Avoid CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
869N/A Flag* faddr = address_of_flag(flag);
869N/A guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
2624N/A faddr->set_uint64_t(value);
2624N/A faddr->origin = origin;
2624N/A}
2624N/A
869N/Abool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
869N/A Flag* result = Flag::find_flag(name, len);
869N/A if (result == NULL) return false;
869N/A if (!result->is_double()) return false;
869N/A *value = result->get_double();
869N/A return true;
2624N/A}
2624N/A
2624N/Abool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
2624N/A Flag* result = Flag::find_flag(name, len);
849N/A if (result == NULL) return false;
0N/A if (!result->is_double()) return false;
869N/A double old_value = result->get_double();
868N/A result->set_double(*value);
0N/A *value = old_value;
0N/A result->origin = origin;
0N/A return true;
0N/A}
0N/A
0N/Avoid CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
869N/A Flag* faddr = address_of_flag(flag);
2624N/A guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
2624N/A faddr->set_double(value);
869N/A faddr->origin = origin;
869N/A}
869N/A
2624N/Abool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
869N/A Flag* result = Flag::find_flag(name, len);
2624N/A if (result == NULL) return false;
2624N/A if (!result->is_ccstr()) return false;
0N/A *value = result->get_ccstr();
0N/A return true;
869N/A}
4814N/A
2366N/A// Contract: Flag will make private copy of the incoming value.
869N/A// Outgoing value is always malloc-ed, and caller MUST call free.
869N/Abool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
869N/A Flag* result = Flag::find_flag(name, len);
869N/A if (result == NULL) return false;
868N/A if (!result->is_ccstr()) return false;
0N/A ccstr old_value = result->get_ccstr();
824N/A char* new_value = NULL;
824N/A if (*value != NULL) {
824N/A new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1);
824N/A strcpy(new_value, *value);
869N/A }
2624N/A result->set_ccstr(new_value);
2624N/A if (result->origin == DEFAULT && old_value != NULL) {
869N/A // Prior value is NOT heap allocated, but was a literal constant.
869N/A char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1);
869N/A strcpy(old_value_to_free, old_value);
2624N/A old_value = old_value_to_free;
869N/A }
2624N/A *value = old_value;
2624N/A result->origin = origin;
824N/A return true;
868N/A}
869N/A
4814N/A// Contract: Flag will make private copy of the incoming value.
2366N/Avoid CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
869N/A Flag* faddr = address_of_flag(flag);
868N/A guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
869N/A ccstr old_value = faddr->get_ccstr();
869N/A char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1);
824N/A strcpy(new_value, value);
2624N/A faddr->set_ccstr(new_value);
2624N/A if (faddr->origin != DEFAULT && old_value != NULL) {
869N/A // Prior value is heap allocated so free it.
2390N/A FREE_C_HEAP_ARRAY(char, old_value);
2390N/A }
2390N/A faddr->origin = origin;
2390N/A}
2390N/A
2624N/Aextern "C" {
3702N/A static int compare_flags(const void* void_a, const void* void_b) {
2390N/A return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
2390N/A }
2390N/A}
869N/A
869N/Avoid CommandLineFlags::printSetFlags(outputStream* out) {
869N/A // Print which flags were set on the command line
869N/A // note: this method is called before the thread structure is in place
869N/A // which means resource allocation cannot be used.
2624N/A
2624N/A // Compute size
869N/A int length= 0;
869N/A while (flagTable[length].name != NULL) length++;
869N/A
0N/A // Sort
2917N/A Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
2917N/A for (int index = 0; index < length; index++) {
2917N/A array[index] = &flagTable[index];
2917N/A }
2917N/A qsort(array, length, sizeof(Flag*), compare_flags);
2942N/A
2942N/A // Print
2942N/A for (int i = 0; i < length; i++) {
2942N/A if (array[i]->origin /* naked field! */) {
2942N/A array[i]->print_as_flag(out);
2942N/A out->print(" ");
2942N/A }
2942N/A }
2942N/A out->cr();
2917N/A FREE_C_HEAP_ARRAY(Flag*, array);
869N/A}
0N/A
869N/A#ifndef PRODUCT
2917N/A
2917N/A
2942N/Avoid CommandLineFlags::verify() {
2624N/A assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
2917N/A}
2917N/A
2917N/A#endif // PRODUCT
2917N/A
2917N/Avoid CommandLineFlags::printFlags(outputStream* out, bool withComments) {
2917N/A // Print the flags sorted by name
2917N/A // note: this method is called before the thread structure is in place
2917N/A // which means resource allocation cannot be used.
2917N/A
0N/A // Compute size
0N/A int length= 0;
869N/A while (flagTable[length].name != NULL) length++;
868N/A
0N/A // Sort
0N/A Flag** array = NEW_C_HEAP_ARRAY(Flag*, length);
0N/A for (int index = 0; index < length; index++) {
0N/A array[index] = &flagTable[index];
0N/A }
2334N/A qsort(array, length, sizeof(Flag*), compare_flags);
869N/A
2624N/A // Print
2624N/A out->print_cr("[Global flags]");
0N/A for (int i = 0; i < length; i++) {
1952N/A if (array[i]->is_unlocked()) {
1952N/A array[i]->print_on(out, withComments);
1952N/A }
2334N/A }
2826N/A FREE_C_HEAP_ARRAY(Flag*, array);
2624N/A}
2624N/A