8027314: Java should recognize Diagnostic options if -XX:+UnlockDiagnosticVMOptions is not specified and print an informative message

Thu, 16 Jan 2014 10:51:16 -0800

author
ccheung
date
Thu, 16 Jan 2014 10:51:16 -0800
changeset 6309
cd7a42c7be06
parent 6308
a81bc2b2c4d3
child 6310
22b3b2f888bc

8027314: Java should recognize Diagnostic options if -XX:+UnlockDiagnosticVMOptions is not specified and print an informative message
Summary: clarifying the error messages associated with vm options of type diagnostic, experimental, develop, and notproduct
Reviewed-by: kvn, twisti, ctornqvi

src/share/vm/runtime/arguments.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/globals.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/globals.hpp file | annotate | diff | comparison | revisions
test/runtime/CommandLine/CompilerConfigFileWarning.java file | annotate | diff | comparison | revisions
test/runtime/CommandLine/ConfigFileWarning.java file | annotate | diff | comparison | revisions
test/runtime/CommandLine/VMOptionWarning.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/runtime/arguments.cpp	Wed Feb 05 15:14:47 2014 -0800
     1.2 +++ b/src/share/vm/runtime/arguments.cpp	Thu Jan 16 10:51:16 2014 -0800
     1.3 @@ -878,7 +878,7 @@
     1.4      arg_len = equal_sign - argname;
     1.5    }
     1.6  
     1.7 -  Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true);
     1.8 +  Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
     1.9    if (found_flag != NULL) {
    1.10      char locked_message_buf[BUFLEN];
    1.11      found_flag->get_locked_message(locked_message_buf, BUFLEN);
     2.1 --- a/src/share/vm/runtime/globals.cpp	Wed Feb 05 15:14:47 2014 -0800
     2.2 +++ b/src/share/vm/runtime/globals.cpp	Thu Jan 16 10:51:16 2014 -0800
     2.3 @@ -62,6 +62,14 @@
     2.4  MATERIALIZE_FLAGS_EXT
     2.5  
     2.6  
     2.7 +static bool is_product_build() {
     2.8 +#ifdef PRODUCT
     2.9 +  return true;
    2.10 +#else
    2.11 +  return false;
    2.12 +#endif
    2.13 +}
    2.14 +
    2.15  void Flag::check_writable() {
    2.16    if (is_constant_in_binary()) {
    2.17      fatal(err_msg("flag is constant: %s", _name));
    2.18 @@ -235,6 +243,27 @@
    2.19  // Get custom message for this locked flag, or return NULL if
    2.20  // none is available.
    2.21  void Flag::get_locked_message(char* buf, int buflen) const {
    2.22 +  buf[0] = '\0';
    2.23 +  if (is_diagnostic() && !is_unlocked()) {
    2.24 +    jio_snprintf(buf, buflen, "Error: VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.\n",
    2.25 +                 _name);
    2.26 +    return;
    2.27 +  }
    2.28 +  if (is_experimental() && !is_unlocked()) {
    2.29 +    jio_snprintf(buf, buflen, "Error: VM option '%s' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.\n",
    2.30 +                 _name);
    2.31 +    return;
    2.32 +  }
    2.33 +  if (is_develop() && is_product_build()) {
    2.34 +    jio_snprintf(buf, buflen, "Error: VM option '%s' is develop and is available only in debug version of VM.\n",
    2.35 +                 _name);
    2.36 +    return;
    2.37 +  }
    2.38 +  if (is_notproduct() && is_product_build()) {
    2.39 +    jio_snprintf(buf, buflen, "Error: VM option '%s' is notproduct and is available only in debug version of VM.\n",
    2.40 +                 _name);
    2.41 +    return;
    2.42 +  }
    2.43    get_locked_message_ext(buf, buflen);
    2.44  }
    2.45  
    2.46 @@ -464,13 +493,13 @@
    2.47  }
    2.48  
    2.49  // Search the flag table for a named flag
    2.50 -Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked) {
    2.51 +Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked, bool return_flag) {
    2.52    for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
    2.53      if (str_equal(current->_name, name, length)) {
    2.54        // Found a matching entry.
    2.55        // Don't report notproduct and develop flags in product builds.
    2.56        if (current->is_constant_in_binary()) {
    2.57 -        return NULL;
    2.58 +        return (return_flag == true ? current : NULL);
    2.59        }
    2.60        // Report locked flags only if allowed.
    2.61        if (!(current->is_unlocked() || current->is_unlocker())) {
     3.1 --- a/src/share/vm/runtime/globals.hpp	Wed Feb 05 15:14:47 2014 -0800
     3.2 +++ b/src/share/vm/runtime/globals.hpp	Thu Jan 16 10:51:16 2014 -0800
     3.3 @@ -241,7 +241,7 @@
     3.4    // number of flags
     3.5    static size_t numFlags;
     3.6  
     3.7 -  static Flag* find_flag(const char* name, size_t length, bool allow_locked = false);
     3.8 +  static Flag* find_flag(const char* name, size_t length, bool allow_locked = false, bool return_flag = false);
     3.9    static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
    3.10  
    3.11    void check_writable();
     4.1 --- a/test/runtime/CommandLine/CompilerConfigFileWarning.java	Wed Feb 05 15:14:47 2014 -0800
     4.2 +++ b/test/runtime/CommandLine/CompilerConfigFileWarning.java	Thu Jan 16 10:51:16 2014 -0800
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -33,8 +33,7 @@
    4.11  
    4.12  public class CompilerConfigFileWarning {
    4.13      public static void main(String[] args) throws Exception {
    4.14 -        String vmVersion = System.getProperty("java.vm.version");
    4.15 -        if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) {
    4.16 +        if (Platform.isDebugBuild()) {
    4.17              System.out.println("Skip on debug builds since we'll always read the file there");
    4.18              return;
    4.19          }
     5.1 --- a/test/runtime/CommandLine/ConfigFileWarning.java	Wed Feb 05 15:14:47 2014 -0800
     5.2 +++ b/test/runtime/CommandLine/ConfigFileWarning.java	Thu Jan 16 10:51:16 2014 -0800
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -33,8 +33,7 @@
    5.11  
    5.12  public class ConfigFileWarning {
    5.13      public static void main(String[] args) throws Exception {
    5.14 -        String vmVersion = System.getProperty("java.vm.version");
    5.15 -        if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) {
    5.16 +        if (Platform.isDebugBuild()) {
    5.17              System.out.println("Skip on debug builds since we'll always read the file there");
    5.18              return;
    5.19          }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/runtime/CommandLine/VMOptionWarning.java	Thu Jan 16 10:51:16 2014 -0800
     6.3 @@ -0,0 +1,56 @@
     6.4 +/*
     6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug 8027314
    6.30 + * @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.
    6.31 + * @library /testlibrary
    6.32 + */
    6.33 +
    6.34 +import com.oracle.java.testlibrary.*;
    6.35 +
    6.36 +public class VMOptionWarning {
    6.37 +    public static void main(String[] args) throws Exception {
    6.38 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PredictedLoadedClassCount", "-version");
    6.39 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
    6.40 +        output.shouldContain("Error: VM option 'PredictedLoadedClassCount' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.");
    6.41 +
    6.42 +        if (Platform.isDebugBuild()) {
    6.43 +            System.out.println("Skip the rest of the tests on debug builds since diagnostic, develop, and notproduct options are available on debug builds.");
    6.44 +            return;
    6.45 +        }
    6.46 +
    6.47 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintInlining", "-version");
    6.48 +        output = new OutputAnalyzer(pb.start());
    6.49 +        output.shouldContain("Error: VM option 'PrintInlining' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
    6.50 +
    6.51 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceJNICalls", "-version");
    6.52 +        output = new OutputAnalyzer(pb.start());
    6.53 +        output.shouldContain("Error: VM option 'TraceJNICalls' is develop and is available only in debug version of VM.");
    6.54 +
    6.55 +        pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceJVMCalls", "-version");
    6.56 +        output = new OutputAnalyzer(pb.start());
    6.57 +        output.shouldContain("Error: VM option 'TraceJVMCalls' is notproduct and is available only in debug version of VM.");
    6.58 +    }
    6.59 +}

mercurial