diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp index 2d7c5851fad3f71d29c82e6f563ec2d7da9c887b..6bb3d9b5207d3c80fc84ff7495f587ee49dca2b1 100644 --- a/src/share/vm/runtime/arguments.cpp +++ b/src/share/vm/runtime/arguments.cpp @@ -878,7 +878,7 @@ bool Arguments::process_argument(const char* arg, arg_len = equal_sign - argname; } - Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true); + Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true); if (found_flag != NULL) { char locked_message_buf[BUFLEN]; found_flag->get_locked_message(locked_message_buf, BUFLEN); diff --git a/src/share/vm/runtime/globals.cpp b/src/share/vm/runtime/globals.cpp index de6fbf70856fe633998283c7f9d5fc12d4fa1ee9..fbfc08ed0dca6d7305847f01c6651a0a93d58a27 100644 --- a/src/share/vm/runtime/globals.cpp +++ b/src/share/vm/runtime/globals.cpp @@ -62,6 +62,14 @@ ARCH_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PRODUCT_FLAG, \ MATERIALIZE_FLAGS_EXT +static bool is_product_build() { +#ifdef PRODUCT + return true; +#else + return false; +#endif +} + void Flag::check_writable() { if (is_constant_in_binary()) { fatal(err_msg("flag is constant: %s", _name)); @@ -235,6 +243,27 @@ bool Flag::is_unlocked() const { // Get custom message for this locked flag, or return NULL if // none is available. void Flag::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", + _name); + return; + } + if (is_experimental() && !is_unlocked()) { + jio_snprintf(buf, buflen, "Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n", + _name); + return; + } + 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; + } + 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; + } get_locked_message_ext(buf, buflen); } @@ -464,13 +493,13 @@ inline bool str_equal(const char* s, const char* q, size_t len) { } // Search the flag table for a named flag -Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked) { +Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked, bool return_flag) { for (Flag* current = &flagTable[0]; current->_name != NULL; current++) { if (str_equal(current->_name, name, length)) { // Found a matching entry. // Don't report notproduct and develop flags in product builds. if (current->is_constant_in_binary()) { - return NULL; + return (return_flag == true ? current : NULL); } // Report locked flags only if allowed. if (!(current->is_unlocked() || current->is_unlocker())) { diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index 9d9ecacc4c692dfea738be0e9cc78c0133dbeed6..c99a2b7d8aafa52348da466b327b7a98edb0d2eb 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -241,7 +241,7 @@ struct Flag { // number of flags static size_t numFlags; - static Flag* find_flag(const char* name, size_t length, bool allow_locked = false); + static Flag* find_flag(const char* name, size_t length, bool allow_locked = false, bool return_flag = false); static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false); void check_writable(); diff --git a/test/runtime/CommandLine/CompilerConfigFileWarning.java b/test/runtime/CommandLine/CompilerConfigFileWarning.java index 1f1894419ab5255dd83b53e14a3d237341e9ad32..e5df0c9450b6bcc46ad3381fb8baeb54681d98ee 100644 --- a/test/runtime/CommandLine/CompilerConfigFileWarning.java +++ b/test/runtime/CommandLine/CompilerConfigFileWarning.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, 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 @@ -33,8 +33,7 @@ import com.oracle.java.testlibrary.*; public class CompilerConfigFileWarning { public static void main(String[] args) throws Exception { - String vmVersion = System.getProperty("java.vm.version"); - if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) { + if (Platform.isDebugBuild()) { System.out.println("Skip on debug builds since we'll always read the file there"); return; } diff --git a/test/runtime/CommandLine/ConfigFileWarning.java b/test/runtime/CommandLine/ConfigFileWarning.java index 470808eaff3fa5460486d1aa8f8e2a7a8f62d789..b81da5923fd5bdd0bf75bd6c35e830ee4b92a835 100644 --- a/test/runtime/CommandLine/ConfigFileWarning.java +++ b/test/runtime/CommandLine/ConfigFileWarning.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, 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 @@ -33,8 +33,7 @@ import com.oracle.java.testlibrary.*; public class ConfigFileWarning { public static void main(String[] args) throws Exception { - String vmVersion = System.getProperty("java.vm.version"); - if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) { + if (Platform.isDebugBuild()) { System.out.println("Skip on debug builds since we'll always read the file there"); return; } diff --git a/test/runtime/CommandLine/VMOptionWarning.java b/test/runtime/CommandLine/VMOptionWarning.java new file mode 100644 index 0000000000000000000000000000000000000000..164cec009755541e834e030a8104fe7ab0e2f977 --- /dev/null +++ b/test/runtime/CommandLine/VMOptionWarning.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, 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. + */ + +/* + * @test + * @bug 8027314 + * @summary Warn if diagnostic or experimental vm option is used and -XX:+UnlockDiagnosticVMOptions or -XX:+UnlockExperimentalVMOptions, respectively, isn't specified. Warn if develop or notproduct vm option is used with product version of VM. + * @library /testlibrary + */ + +import com.oracle.java.testlibrary.*; + +public class VMOptionWarning { + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PredictedLoadedClassCount", "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("Error: VM option 'PredictedLoadedClassCount' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions."); + + if (Platform.isDebugBuild()) { + System.out.println("Skip the rest of the tests on debug builds since diagnostic, develop, and notproduct options are available on debug builds."); + return; + } + + pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintInlining", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Error: VM option 'PrintInlining' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions."); + + pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceJNICalls", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Error: VM option 'TraceJNICalls' is develop and is available only in debug version of VM."); + + pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceJVMCalls", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Error: VM option 'TraceJVMCalls' is notproduct and is available only in debug version of VM."); + } +}