7144328: Improper commandlines for -XX:+-UnlockCommercialFeatures require proper warning/error messages
Summary: Provide custom error messages for locked commercial feature options which are not first unlocked.
Reviewed-by: dcubed, jcoomes, kamg
Contributed-by: james.melvin@oracle.com
--- a/hotspot/src/share/vm/runtime/arguments.cpp Mon Mar 19 10:09:24 2012 +0100
+++ b/hotspot/src/share/vm/runtime/arguments.cpp Tue Mar 20 16:46:39 2012 -0400
@@ -816,8 +816,21 @@
return true;
}
- jio_fprintf(defaultStream::error_stream(),
- "Unrecognized VM option '%s'\n", argname);
+ // For locked flags, report a custom error message if available.
+ // Otherwise, report the standard unrecognized VM option.
+
+ Flag* locked_flag = Flag::find_flag((char*)argname, strlen(argname), true);
+ if (locked_flag != NULL) {
+ char locked_message_buf[BUFLEN];
+ locked_flag->get_locked_message(locked_message_buf, BUFLEN);
+ if (strlen(locked_message_buf) == 0) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Unrecognized VM option '%s'\n", argname);
+ } else {
+ jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
+ }
+ }
+
// allow for commandline "commenting out" options like -XX:#+Verbose
return arg[0] == '#';
}
--- a/hotspot/src/share/vm/runtime/globals.cpp Mon Mar 19 10:09:24 2012 +0100
+++ b/hotspot/src/share/vm/runtime/globals.cpp Tue Mar 20 16:46:39 2012 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, 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
@@ -81,6 +81,12 @@
}
}
+// Get custom message for this locked flag, or return NULL if
+// none is available.
+void Flag::get_locked_message(char* buf, int buflen) const {
+ get_locked_message_ext(buf, buflen);
+}
+
bool Flag::is_writeable() const {
return strcmp(kind, "{manageable}") == 0 ||
strcmp(kind, "{product rw}") == 0 ||
@@ -260,17 +266,22 @@
return strncmp(s, q, len) == 0;
}
-Flag* Flag::find_flag(char* name, size_t length) {
- for (Flag* current = &flagTable[0]; current->name; current++) {
+// Search the flag table for a named flag
+Flag* Flag::find_flag(char* name, size_t length, bool allow_locked) {
+ for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
if (str_equal(current->name, name, length)) {
+ // Found a matching entry. Report locked flags only if allowed.
if (!(current->is_unlocked() || current->is_unlocker())) {
- // disable use of diagnostic or experimental flags until they
- // are explicitly unlocked
- return NULL;
+ if (!allow_locked) {
+ // disable use of locked flags, e.g. diagnostic, experimental,
+ // commercial... until they are explicitly unlocked
+ return NULL;
+ }
}
return current;
}
}
+ // Flag name is not in the flag table
return NULL;
}
--- a/hotspot/src/share/vm/runtime/globals.hpp Mon Mar 19 10:09:24 2012 +0100
+++ b/hotspot/src/share/vm/runtime/globals.hpp Tue Mar 20 16:46:39 2012 -0400
@@ -222,7 +222,7 @@
// number of flags
static size_t numFlags;
- static Flag* find_flag(char* name, size_t length);
+ static Flag* find_flag(char* name, size_t length, bool allow_locked = false);
bool is_bool() const { return strcmp(type, "bool") == 0; }
bool get_bool() const { return *((bool*) addr); }
@@ -259,6 +259,9 @@
bool is_writeable_ext() const;
bool is_external_ext() const;
+ void get_locked_message(char*, int) const;
+ void get_locked_message_ext(char*, int) const;
+
void print_on(outputStream* st, bool withComments = false );
void print_as_flag(outputStream* st);
};
--- a/hotspot/src/share/vm/runtime/globals_ext.hpp Mon Mar 19 10:09:24 2012 +0100
+++ b/hotspot/src/share/vm/runtime/globals_ext.hpp Tue Mar 20 16:46:39 2012 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012, 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
@@ -61,4 +61,9 @@
return false;
}
+inline void Flag::get_locked_message_ext(char* buf, int buflen) const {
+ assert(buf != NULL, "Buffer cannot be NULL");
+ buf[0] = '\0';
+}
+
#endif // SHARE_VM_RUNTIME_GLOBALS_EXT_HPP