globals.cpp revision 370
0N/A/*
196N/A * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A# include "incls/_precompiled.incl"
0N/A# include "incls/_globals.cpp.incl"
0N/A
0N/A
0N/ARUNTIME_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
0N/A MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
0N/A MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG, \
113N/A MATERIALIZE_MANAGEABLE_FLAG, MATERIALIZE_PRODUCT_RW_FLAG, \
113N/A MATERIALIZE_LP64_PRODUCT_FLAG)
0N/A
0N/ARUNTIME_OS_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, \
0N/A MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, \
0N/A MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
0N/A
0N/Abool Flag::is_unlocker() const {
0N/A return strcmp(name, "UnlockDiagnosticVMOptions") == 0;
0N/A}
0N/A
0N/Abool Flag::is_unlocked() const {
0N/A if (strcmp(kind, "{diagnostic}") == 0) {
0N/A return UnlockDiagnosticVMOptions;
0N/A } else {
0N/A return true;
0N/A }
0N/A}
0N/A
0N/Abool Flag::is_writeable() const {
0N/A return (strcmp(kind, "{manageable}") == 0 || strcmp(kind, "{product rw}") == 0);
0N/A}
0N/A
0N/A// All flags except "manageable" are assumed internal flags.
0N/A// Long term, we need to define a mechanism to specify which flags
0N/A// are external/stable and change this function accordingly.
0N/Abool Flag::is_external() const {
0N/A return (strcmp(kind, "{manageable}") == 0);
0N/A}
0N/A
0N/A// Length of format string (e.g. "%.1234s") for printing ccstr below
0N/A#define FORMAT_BUFFER_LEN 16
0N/A
0N/Avoid Flag::print_on(outputStream* st) {
0N/A st->print("%5s %-35s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
0N/A if (is_bool()) st->print("%-16s", get_bool() ? "true" : "false");
0N/A if (is_intx()) st->print("%-16ld", get_intx());
0N/A if (is_uintx()) st->print("%-16lu", get_uintx());
0N/A if (is_ccstr()) {
0N/A const char* cp = get_ccstr();
103N/A if (cp != NULL) {
103N/A const char* eol;
103N/A while ((eol = strchr(cp, '\n')) != NULL) {
103N/A char format_buffer[FORMAT_BUFFER_LEN];
103N/A size_t llen = pointer_delta(eol, cp, sizeof(char));
103N/A jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
103N/A "%%." SIZE_FORMAT "s", llen);
103N/A st->print(format_buffer, cp);
103N/A st->cr();
103N/A cp = eol+1;
103N/A st->print("%5s %-35s += ", "", name);
103N/A }
103N/A st->print("%-16s", cp);
0N/A }
0N/A }
0N/A st->print(" %s", kind);
0N/A st->cr();
0N/A}
0N/A
0N/Avoid Flag::print_as_flag(outputStream* st) {
0N/A if (is_bool()) {
0N/A st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
0N/A } else if (is_intx()) {
0N/A st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
0N/A } else if (is_uintx()) {
0N/A st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
0N/A } else if (is_ccstr()) {
0N/A st->print("-XX:%s=", name);
103N/A const char* cp = get_ccstr();
103N/A if (cp != NULL) {
103N/A // Need to turn embedded '\n's back into separate arguments
103N/A // Not so efficient to print one character at a time,
103N/A // but the choice is to do the transformation to a buffer
103N/A // and print that. And this need not be efficient.
103N/A for (; *cp != '\0'; cp += 1) {
103N/A switch (*cp) {
103N/A default:
103N/A st->print("%c", *cp);
103N/A break;
103N/A case '\n':
103N/A st->print(" -XX:%s=", name);
103N/A break;
103N/A }
0N/A }
0N/A }
0N/A } else {
0N/A ShouldNotReachHere();
0N/A }
0N/A}
0N/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
0N/A
0N/A#define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{product}", DEFAULT },
0N/A#define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{pd product}", DEFAULT },
0N/A#define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{diagnostic}", DEFAULT },
0N/A#define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{manageable}", DEFAULT },
0N/A#define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{product rw}", DEFAULT },
0N/A
0N/A#ifdef PRODUCT
0N/A #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
0N/A #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
0N/A #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
0N/A#else
0N/A #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "", DEFAULT },
0N/A #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{pd}", DEFAULT },
0N/A #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{notproduct}", DEFAULT },
0N/A#endif
0N/A
113N/A#ifdef _LP64
113N/A #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{lp64_product}", DEFAULT },
113N/A#else
113N/A #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
113N/A#endif // _LP64
113N/A
0N/A#define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C1 product}", DEFAULT },
0N/A#define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{C1 pd product}", DEFAULT },
0N/A#ifdef PRODUCT
0N/A #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
0N/A #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
0N/A #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
0N/A#else
0N/A #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C1}", DEFAULT },
0N/A #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{C1 pd}", DEFAULT },
0N/A #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C1 notproduct}", DEFAULT },
0N/A#endif
0N/A
0N/A
0N/A#define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C2 product}", DEFAULT },
0N/A#define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{C2 pd product}", DEFAULT },
0N/A#define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C2 diagnostic}", DEFAULT },
0N/A#ifdef PRODUCT
0N/A #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
0N/A #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) /* flag is constant */
0N/A #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
0N/A#else
0N/A #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C2}", DEFAULT },
0N/A #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc) { #type, XSTR(name), &name, "{C2 pd}", DEFAULT },
0N/A #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, "{C2 notproduct}", DEFAULT },
0N/A#endif
0N/A
0N/A
0N/Astatic Flag flagTable[] = {
113N/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_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT, RUNTIME_LP64_PRODUCT_FLAG_STRUCT)
0N/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)
0N/A#ifdef COMPILER1
0N/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)
0N/A#endif
0N/A#ifdef COMPILER2
0N/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_NOTPRODUCT_FLAG_STRUCT)
0N/A#endif
0N/A {0, NULL, NULL}
0N/A};
0N/A
0N/AFlag* Flag::flags = flagTable;
0N/Asize_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
0N/A
0N/Ainline bool str_equal(const char* s, char* q, size_t len) {
0N/A // s is null terminated, q is not!
0N/A if (strlen(s) != (unsigned int) len) return false;
0N/A return strncmp(s, q, len) == 0;
0N/A}
0N/A
0N/AFlag* Flag::find_flag(char* name, size_t length) {
0N/A for (Flag* current = &flagTable[0]; current->name; current++) {
0N/A if (str_equal(current->name, name, length)) {
0N/A if (!(current->is_unlocked() || current->is_unlocker())) {
0N/A // disable use of diagnostic flags until they are unlocked
0N/A return NULL;
0N/A }
0N/A return current;
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A// Returns the address of the index'th element
0N/Astatic Flag* address_of_flag(CommandLineFlagWithType flag) {
0N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
0N/A return &Flag::flags[flag];
0N/A}
0N/A
0N/Abool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
0N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
0N/A Flag* f = &Flag::flags[flag];
0N/A return (f->origin == DEFAULT);
0N/A}
0N/A
13N/Abool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
13N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
13N/A Flag* f = &Flag::flags[flag];
13N/A return (f->origin == ERGONOMIC);
13N/A}
13N/A
13N/Abool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
13N/A assert((size_t)flag < Flag::numFlags, "bad command line flag index");
13N/A Flag* f = &Flag::flags[flag];
13N/A return (f->origin == COMMAND_LINE);
13N/A}
13N/A
0N/Abool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
0N/A Flag* result = Flag::find_flag((char*)name, strlen(name));
0N/A if (result == NULL) return false;
0N/A *value = (result->origin == COMMAND_LINE);
0N/A return true;
0N/A}
0N/A
0N/Abool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_bool()) return false;
0N/A *value = result->get_bool();
0N/A return true;
0N/A}
0N/A
0N/Abool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_bool()) return false;
0N/A bool old_value = result->get_bool();
0N/A result->set_bool(*value);
0N/A *value = old_value;
0N/A result->origin = origin;
0N/A return true;
0N/A}
0N/A
0N/Avoid CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
0N/A Flag* faddr = address_of_flag(flag);
0N/A guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
0N/A faddr->set_bool(value);
0N/A faddr->origin = origin;
0N/A}
0N/A
0N/Abool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_intx()) return false;
0N/A *value = result->get_intx();
0N/A return true;
0N/A}
0N/A
0N/Abool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_intx()) return false;
0N/A intx old_value = result->get_intx();
0N/A result->set_intx(*value);
0N/A *value = old_value;
0N/A result->origin = origin;
0N/A return true;
0N/A}
0N/A
0N/Avoid CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
0N/A Flag* faddr = address_of_flag(flag);
0N/A guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
0N/A faddr->set_intx(value);
0N/A faddr->origin = origin;
0N/A}
0N/A
0N/Abool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_uintx()) return false;
0N/A *value = result->get_uintx();
0N/A return true;
0N/A}
0N/A
0N/Abool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_uintx()) return false;
0N/A uintx old_value = result->get_uintx();
0N/A result->set_uintx(*value);
0N/A *value = old_value;
0N/A result->origin = origin;
0N/A return true;
0N/A}
0N/A
0N/Avoid CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
0N/A Flag* faddr = address_of_flag(flag);
0N/A guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
0N/A faddr->set_uintx(value);
0N/A faddr->origin = origin;
0N/A}
0N/A
0N/Abool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_double()) return false;
0N/A *value = result->get_double();
0N/A return true;
0N/A}
0N/A
0N/Abool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_double()) return false;
0N/A double old_value = result->get_double();
0N/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) {
0N/A Flag* faddr = address_of_flag(flag);
0N/A guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
0N/A faddr->set_double(value);
0N/A faddr->origin = origin;
0N/A}
0N/A
0N/Abool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_ccstr()) return false;
0N/A *value = result->get_ccstr();
0N/A return true;
0N/A}
0N/A
0N/A// Contract: Flag will make private copy of the incoming value.
0N/A// Outgoing value is always malloc-ed, and caller MUST call free.
0N/Abool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
0N/A Flag* result = Flag::find_flag(name, len);
0N/A if (result == NULL) return false;
0N/A if (!result->is_ccstr()) return false;
0N/A ccstr old_value = result->get_ccstr();
370N/A char* new_value = NULL;
370N/A if (*value != NULL) {
370N/A new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1);
370N/A strcpy(new_value, *value);
370N/A }
0N/A result->set_ccstr(new_value);
0N/A if (result->origin == DEFAULT && old_value != NULL) {
0N/A // Prior value is NOT heap allocated, but was a literal constant.
0N/A char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1);
0N/A strcpy(old_value_to_free, old_value);
0N/A old_value = old_value_to_free;
0N/A }
0N/A *value = old_value;
0N/A result->origin = origin;
0N/A return true;
0N/A}
0N/A
0N/A// Contract: Flag will make private copy of the incoming value.
0N/Avoid CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
0N/A Flag* faddr = address_of_flag(flag);
0N/A guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
0N/A ccstr old_value = faddr->get_ccstr();
0N/A char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1);
0N/A strcpy(new_value, value);
0N/A faddr->set_ccstr(new_value);
0N/A if (faddr->origin != DEFAULT && old_value != NULL) {
0N/A // Prior value is heap allocated so free it.
0N/A FREE_C_HEAP_ARRAY(char, old_value);
0N/A }
0N/A faddr->origin = origin;
0N/A}
0N/A
0N/Aextern "C" {
0N/A static int compare_flags(const void* void_a, const void* void_b) {
0N/A return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
0N/A }
0N/A}
0N/A
0N/Avoid CommandLineFlags::printSetFlags() {
0N/A // Print which flags were set on the command line
0N/A // note: this method is called before the thread structure is in place
0N/A // which means resource allocation cannot be used.
0N/A
0N/A // Compute size
0N/A int length= 0;
0N/A while (flagTable[length].name != NULL) length++;
0N/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 }
0N/A qsort(array, length, sizeof(Flag*), compare_flags);
0N/A
0N/A // Print
0N/A for (int i = 0; i < length; i++) {
0N/A if (array[i]->origin /* naked field! */) {
0N/A array[i]->print_as_flag(tty);
0N/A tty->print(" ");
0N/A }
0N/A }
0N/A tty->cr();
0N/A FREE_C_HEAP_ARRAY(Flag*, array);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/A
0N/A
0N/Avoid CommandLineFlags::verify() {
0N/A assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
0N/A}
0N/A
0N/Avoid CommandLineFlags::printFlags() {
0N/A // Print the flags sorted by name
0N/A // note: this method is called before the thread structure is in place
0N/A // which means resource allocation cannot be used.
0N/A
0N/A // Compute size
0N/A int length= 0;
0N/A while (flagTable[length].name != NULL) length++;
0N/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 }
0N/A qsort(array, length, sizeof(Flag*), compare_flags);
0N/A
0N/A // Print
0N/A tty->print_cr("[Global flags]");
0N/A for (int i = 0; i < length; i++) {
0N/A if (array[i]->is_unlocked()) {
0N/A array[i]->print_on(tty);
0N/A }
0N/A }
0N/A FREE_C_HEAP_ARRAY(Flag*, array);
0N/A}
0N/A
0N/A#endif