/* * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
void JVMFlag::set_origin(JVMFlagOrigin new_origin) { int old_flags = _flags; int origin = static_cast<int>(new_origin);
assert((origin & VALUE_ORIGIN_MASK) == origin, "sanity"); int was_in_cmdline = (new_origin == JVMFlagOrigin::COMMAND_LINE) ? WAS_SET_ON_COMMAND_LINE : 0;
_flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | origin | was_in_cmdline); if ((old_flags & WAS_SET_ON_COMMAND_LINE) != 0) {
assert((_flags & WAS_SET_ON_COMMAND_LINE) != 0, "once initialized, should never change");
}
}
/** * Returns if this flag is a constant in the binary. Right now this is * true for notproduct and develop flags in product builds.
*/ bool JVMFlag::is_constant_in_binary() const { #ifdef PRODUCT return is_notproduct() || is_develop(); #else returnfalse; #endif
}
// Get custom message for this locked flag, or NULL if // none is available. Returns message type produced.
JVMFlag::MsgType JVMFlag::get_locked_message(char* buf, int buflen) const {
buf[0] = '\0'; if (is_diagnostic() && !is_unlocked()) {
jio_snprintf(buf, buflen, "Error: VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.\n" "Error: The unlock option must precede '%s'.\n",
_name, _name); return JVMFlag::DIAGNOSTIC_FLAG_BUT_LOCKED;
} if (is_experimental() && !is_unlocked()) {
jio_snprintf(buf, buflen, "Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n" "Error: The unlock option must precede '%s'.\n",
_name, _name); return JVMFlag::EXPERIMENTAL_FLAG_BUT_LOCKED;
} if (is_develop() && is_product_build()) {
jio_snprintf(buf, buflen, "Error: VM option '%s' is develop and is available only in debug version of VM.\n",
_name); return JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD;
} if (is_notproduct() && is_product_build()) {
jio_snprintf(buf, buflen, "Error: VM option '%s' is notproduct and is available only in debug version of VM.\n",
_name); return JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD;
} return JVMFlag::NONE;
}
// Helper function for JVMFlag::print_on(). // Fills current line up to requested position. // Should the current position already be past the requested position, // one separator blank is enforced. void fill_to_pos(outputStream* st, unsignedint req_pos) { if ((unsignedint)st->position() < req_pos) {
st->fill_to(req_pos); // need to fill with blanks to reach req_pos
} else {
st->print(" "); // enforce blank separation. Previous field too long.
}
}
void JVMFlag::print_on(outputStream* st, bool withComments, bool printRanges) const { // Don't print notproduct and develop flags in a product build. if (is_constant_in_binary()) { return;
}
if (!printRanges) { // The command line options -XX:+PrintFlags* cause this function to be called // for each existing flag to print information pertinent to this flag. The data // is displayed in columnar form, with the following layout: // col1 - data type, right-justified // col2 - name, left-justified // col3 - ' =' double-char, leading space to align with possible '+=' // col4 - value left-justified // col5 - kind right-justified // col6 - origin left-justified // col7 - comments left-justified // // The column widths are fixed. They are defined such that, for most cases, // an eye-pleasing tabular output is created. // // Sample output: // bool ThreadPriorityVerbose = false {product} {default} // uintx ThresholdTolerance = 10 {product} {default} // size_t TLABSize = 0 {product} {default} // uintx SurvivorRatio = 8 {product} {default} // double InitialRAMPercentage = 1.562500 {product} {default} // ccstr CompileCommandFile = MyFile.cmd {product} {command line} // ccstrlist CompileOnly = Method1 // CompileOnly += Method2 {product} {command line} // | | | | | | | // | | | | | | +-- col7 // | | | | | +-- col6 // | | | | +-- col5 // | | | +-- col4 // | | +-- col3 // | +-- col2 // +-- col1
void JVMFlag::print_origin(outputStream* st, unsignedint width) const {
st->print("{"); switch(get_origin()) { case JVMFlagOrigin::DEFAULT:
st->print("default"); break; case JVMFlagOrigin::COMMAND_LINE:
st->print("command line"); break; case JVMFlagOrigin::ENVIRON_VAR:
st->print("environment"); break; case JVMFlagOrigin::CONFIG_FILE:
st->print("config file"); break; case JVMFlagOrigin::MANAGEMENT:
st->print("management"); break; case JVMFlagOrigin::ERGONOMIC: if (_flags & WAS_SET_ON_COMMAND_LINE) {
st->print("command line, ");
}
st->print("ergonomic"); break; case JVMFlagOrigin::ATTACH_ON_DEMAND:
st->print("attach"); break; case JVMFlagOrigin::INTERNAL:
st->print("internal"); break; case JVMFlagOrigin::JIMAGE_RESOURCE:
st->print("jimage"); break;
}
st->print("}");
}
void JVMFlag::print_as_flag(outputStream* st) const { if (is_bool()) {
st->print("-XX:%s%s", get_bool() ? "+" : "-", _name);
} elseif (is_int()) {
st->print("-XX:%s=%d", _name, get_int());
} elseif (is_uint()) {
st->print("-XX:%s=%u", _name, get_uint());
} elseif (is_intx()) {
st->print("-XX:%s=" INTX_FORMAT, _name, get_intx());
} elseif (is_uintx()) {
st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx());
} elseif (is_uint64_t()) {
st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t());
} elseif (is_size_t()) {
st->print("-XX:%s=" SIZE_FORMAT, _name, get_size_t());
} elseif (is_double()) {
st->print("-XX:%s=%f", _name, get_double());
} elseif (is_ccstr()) {
st->print("-XX:%s=", _name); constchar* cp = get_ccstr(); if (cp != NULL) { // Need to turn embedded '\n's back into separate arguments // Not so efficient to print one character at a time, // but the choice is to do the transformation to a buffer // and print that. And this need not be efficient. for (; *cp != '\0'; cp += 1) { switch (*cp) { default:
st->print("%c", *cp); break; case'\n':
st->print(" -XX:%s=", _name); break;
}
}
}
} else {
ShouldNotReachHere();
}
}
constchar* JVMFlag::flag_error_str(JVMFlag::Error error) { switch (error) { case JVMFlag::MISSING_NAME: return"MISSING_NAME"; case JVMFlag::MISSING_VALUE: return"MISSING_VALUE"; case JVMFlag::NON_WRITABLE: return"NON_WRITABLE"; case JVMFlag::OUT_OF_BOUNDS: return"OUT_OF_BOUNDS"; case JVMFlag::VIOLATES_CONSTRAINT: return"VIOLATES_CONSTRAINT"; case JVMFlag::INVALID_FLAG: return"INVALID_FLAG"; case JVMFlag::ERR_OTHER: return"ERR_OTHER"; case JVMFlag::SUCCESS: return"SUCCESS"; default: ShouldNotReachHere(); return"NULL";
}
}
// Handy aliases to match the symbols used in the flag specification macros. constint DIAGNOSTIC = JVMFlag::KIND_DIAGNOSTIC; constint MANAGEABLE = JVMFlag::KIND_MANAGEABLE; constint EXPERIMENTAL = JVMFlag::KIND_EXPERIMENTAL;
static JVMFlag flagTable[NUM_JVMFlagsEnum + 1] = {
MATERIALIZE_ALL_FLAGS
JVMFlag() // The iteration code wants a flag with a NULL name at the end of the table.
};
// We want flagTable[] to be completely initialized at C++ compilation time, which requires // that all arguments passed to JVMFlag() constructors be constexpr. The following line // checks for this -- if any non-constexpr arguments are passed, the C++ compiler will // generate an error. // // constexpr implies internal linkage. This means the flagTable_verify_constexpr[] variable // will not be included in jvmFlag.o, so there's no footprint cost for having this variable. // // Note that we cannot declare flagTable[] as constexpr because JVMFlag::_flags is modified // at runtime.
constexpr JVMFlag flagTable_verify_constexpr[] = { MATERIALIZE_ALL_FLAGS };
// Search the flag table for a named flag
JVMFlag* JVMFlag::find_flag(constchar* name, size_t length, bool allow_locked, bool return_flag) {
JVMFlag* flag = JVMFlagLookup::find(name, length); if (flag != NULL) { // Found a matching entry. // Don't report notproduct and develop flags in product builds. if (flag->is_constant_in_binary()) { return (return_flag ? flag : NULL);
} // Report locked flags only if allowed. if (!(flag->is_unlocked() || flag->is_unlocker())) { if (!allow_locked) { // disable use of locked flags, e.g. diagnostic, experimental, // etc. until they are explicitly unlocked return NULL;
}
} return flag;
} // JVMFlag name is not in the flag table return NULL;
}
void JVMFlag::printSetFlags(outputStream* out) { // Print which flags were set on the command line // note: this method is called before the thread structure is in place // which means resource allocation cannot be used.
// The last entry is the null entry. const size_t length = JVMFlag::numFlags - 1;
// Sort
JVMFlag** array = NEW_C_HEAP_ARRAY(JVMFlag*, length, mtArguments); for (size_t i = 0; i < length; i++) {
array[i] = &flagTable[i];
}
qsort(array, length, sizeof(JVMFlag*), compare_flags);
// Print for (size_t i = 0; i < length; i++) { if (array[i]->get_origin() != JVMFlagOrigin::DEFAULT) {
array[i]->print_as_flag(out);
out->print(" ");
}
}
out->cr();
FREE_C_HEAP_ARRAY(JVMFlag*, array);
}
#ifndef PRODUCT
void JVMFlag::verify() {
assert(Arguments::check_vm_args_consistency(), "Some flag settings conflict");
}
void JVMFlag::check_all_flag_declarations() { for (JVMFlag* current = &flagTable[0]; current->_name != NULL; current++) { int flags = static_cast<int>(current->_flags); // Backwards compatibility. This will be relaxed/removed in JDK-7123237. int mask = JVMFlag::KIND_DIAGNOSTIC | JVMFlag::KIND_MANAGEABLE | JVMFlag::KIND_EXPERIMENTAL; if ((flags & mask) != 0) {
assert((flags & mask) == JVMFlag::KIND_DIAGNOSTIC ||
(flags & mask) == JVMFlag::KIND_MANAGEABLE ||
(flags & mask) == JVMFlag::KIND_EXPERIMENTAL, "%s can be declared with at most one of " "DIAGNOSTIC, MANAGEABLE or EXPERIMENTAL", current->_name);
assert((flags & KIND_NOT_PRODUCT) == 0 &&
(flags & KIND_DEVELOP) == 0, "%s has an optional DIAGNOSTIC, MANAGEABLE or EXPERIMENTAL " "attribute; it must be declared as a product flag", current->_name);
}
}
}
#endif// ASSERT
void JVMFlag::printFlags(outputStream* out, bool withComments, bool printRanges, bool skipDefaults) { // Print the flags sorted by name // Note: This method may be called before the thread structure is in place // which means resource allocation cannot be used. Also, it may be // called as part of error reporting, so handle native OOMs gracefully.
// The last entry is the null entry. const size_t length = JVMFlag::numFlags - 1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.