diff src/share/vm/runtime/globals.cpp @ 17667:cd7a42c7be06

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
author ccheung
date Thu, 16 Jan 2014 10:51:16 -0800
parents 396564992823
children d6c97434b745
line wrap: on
line diff
--- a/src/share/vm/runtime/globals.cpp	Wed Feb 05 15:14:47 2014 -0800
+++ b/src/share/vm/runtime/globals.cpp	Thu Jan 16 10:51:16 2014 -0800
@@ -62,6 +62,14 @@
 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 @@
 // 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 @@
 }
 
 // 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())) {