8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd
authorgziemski
Fri, 03 Jun 2016 13:26:43 -0500
changeset 38942 a4b3fc1ba095
parent 38941 adfac609d052
child 38943 2e5c855d6b1e
8155936: Boolean value should be set 1/0 or true/false via VM.set_flag jcmd Summary: Add true/false as possible input values for boolean flags for jcmd. Reviewed-by: gziemski, dsamersoff, coleenp
hotspot/src/share/vm/services/writeableFlags.cpp
hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java
--- a/hotspot/src/share/vm/services/writeableFlags.cpp	Fri Jun 03 16:19:53 2016 +0000
+++ b/hotspot/src/share/vm/services/writeableFlags.cpp	Fri Jun 03 13:26:43 2016 -0500
@@ -93,12 +93,12 @@
 
 // set a boolean global flag
 Flag::Error WriteableFlags::set_bool_flag(const char* name, const char* arg, Flag::Flags origin, FormatBuffer<80>& err_msg) {
-  int value = true;
-
-  if (sscanf(arg, "%d", &value)) {
-    return set_bool_flag(name, value != 0, origin, err_msg);
+  if ((strcasecmp(arg, "true") == 0) || (*arg == '1' && *(arg + 1) == 0)) {
+    return set_bool_flag(name, true, origin, err_msg);
+  } else if ((strcasecmp(arg, "false") == 0) || (*arg == '0' && *(arg + 1) == 0)) {
+    return set_bool_flag(name, false, origin, err_msg);
   }
-  err_msg.print("flag value must be a boolean (1 or 0)");
+  err_msg.print("flag value must be a boolean (1/0 or true/false)");
   return Flag::WRONG_FORMAT;
 }
 
--- a/hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java	Fri Jun 03 16:19:53 2016 +0000
+++ b/hotspot/test/serviceability/dcmd/vm/SetVMFlagTest.java	Fri Jun 03 13:26:43 2016 -0500
@@ -56,6 +56,25 @@
         run(new JMXExecutor());
     }
 
+    private void setMutableFlagInternal(CommandExecutor executor, String flag,
+                                        boolean val, boolean isNumeric) {
+        String strFlagVal;
+        if (isNumeric) {
+            strFlagVal = val ? "1" : "0";
+        } else {
+            strFlagVal = val ? "true" : "false";
+        }
+
+        OutputAnalyzer out = executor.execute("VM.set_flag " + flag + " " + strFlagVal);
+        out.stderrShouldBeEmpty();
+
+        out = getAllFlags(executor);
+
+        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flag), 1);
+
+        assertNotEquals(newFlagVal, val ? "1" : "0");
+    }
+
     private void setMutableFlag(CommandExecutor executor) {
         OutputAnalyzer out = getAllFlags(executor);
         String flagName = out.firstMatch(MANAGEABLE_PATTERN, 1);
@@ -69,15 +88,8 @@
         }
 
         Boolean blnVal = Boolean.parseBoolean(flagVal);
-
-        out = executor.execute("VM.set_flag " + flagName + " " + (blnVal ? 0 : 1));
-        out.stderrShouldBeEmpty();
-
-        out = getAllFlags(executor);
-
-        String newFlagVal = out.firstMatch(MANAGEABLE_PATTERN.replace("(\\S+)", flagName), 1);
-
-        assertNotEquals(newFlagVal, flagVal);
+        setMutableFlagInternal(executor, flagName, !blnVal, true);
+        setMutableFlagInternal(executor, flagName, blnVal, false);
     }
 
     private void setMutableFlagWithInvalidValue(CommandExecutor executor) {
@@ -95,7 +107,7 @@
         // a boolean flag accepts only 0/1 as its value
         out = executor.execute("VM.set_flag " + flagName + " unexpected_value");
         out.stderrShouldBeEmpty();
-        out.stdoutShouldContain("flag value must be a boolean (1 or 0)");
+        out.stdoutShouldContain("flag value must be a boolean (1/0 or true/false)");
 
         out = getAllFlags(executor);