8027314: Java should recognize Diagnostic options if -XX:+UnlockDiagnosticVMOptions is not specified and print an informative message
Clarifying the error messages associated with vm options of type diagnostic, experimental, develop, and notproduct Reviewed-by: kvn, twisti, ctornqvi
This commit is contained in:
parent
735887477f
commit
7f34fe7eee
@ -878,7 +878,7 @@ bool Arguments::process_argument(const char* arg,
|
|||||||
arg_len = equal_sign - argname;
|
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) {
|
if (found_flag != NULL) {
|
||||||
char locked_message_buf[BUFLEN];
|
char locked_message_buf[BUFLEN];
|
||||||
found_flag->get_locked_message(locked_message_buf, BUFLEN);
|
found_flag->get_locked_message(locked_message_buf, BUFLEN);
|
||||||
|
@ -62,6 +62,14 @@ ARCH_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PRODUCT_FLAG, \
|
|||||||
MATERIALIZE_FLAGS_EXT
|
MATERIALIZE_FLAGS_EXT
|
||||||
|
|
||||||
|
|
||||||
|
static bool is_product_build() {
|
||||||
|
#ifdef PRODUCT
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Flag::check_writable() {
|
void Flag::check_writable() {
|
||||||
if (is_constant_in_binary()) {
|
if (is_constant_in_binary()) {
|
||||||
fatal(err_msg("flag is constant: %s", _name));
|
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
|
// Get custom message for this locked flag, or return NULL if
|
||||||
// none is available.
|
// none is available.
|
||||||
void Flag::get_locked_message(char* buf, int buflen) const {
|
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);
|
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
|
// 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++) {
|
for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
|
||||||
if (str_equal(current->_name, name, length)) {
|
if (str_equal(current->_name, name, length)) {
|
||||||
// Found a matching entry.
|
// Found a matching entry.
|
||||||
// Don't report notproduct and develop flags in product builds.
|
// Don't report notproduct and develop flags in product builds.
|
||||||
if (current->is_constant_in_binary()) {
|
if (current->is_constant_in_binary()) {
|
||||||
return NULL;
|
return (return_flag == true ? current : NULL);
|
||||||
}
|
}
|
||||||
// Report locked flags only if allowed.
|
// Report locked flags only if allowed.
|
||||||
if (!(current->is_unlocked() || current->is_unlocker())) {
|
if (!(current->is_unlocked() || current->is_unlocker())) {
|
||||||
|
@ -241,7 +241,7 @@ struct Flag {
|
|||||||
// number of flags
|
// number of flags
|
||||||
static size_t numFlags;
|
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);
|
static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
|
||||||
|
|
||||||
void check_writable();
|
void check_writable();
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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 class CompilerConfigFileWarning {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String vmVersion = System.getProperty("java.vm.version");
|
if (Platform.isDebugBuild()) {
|
||||||
if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) {
|
|
||||||
System.out.println("Skip on debug builds since we'll always read the file there");
|
System.out.println("Skip on debug builds since we'll always read the file there");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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 class ConfigFileWarning {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
String vmVersion = System.getProperty("java.vm.version");
|
if (Platform.isDebugBuild()) {
|
||||||
if (vmVersion.toLowerCase().contains("debug") || vmVersion.toLowerCase().contains("jvmg")) {
|
|
||||||
System.out.println("Skip on debug builds since we'll always read the file there");
|
System.out.println("Skip on debug builds since we'll always read the file there");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
56
hotspot/test/runtime/CommandLine/VMOptionWarning.java
Normal file
56
hotspot/test/runtime/CommandLine/VMOptionWarning.java
Normal file
@ -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.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user