8042885: java does not take hexadecimal number as vm option
authorminqi
Thu, 15 May 2014 20:16:14 -0700
changeset 24458 f0d4da9b062a
parent 24457 0e20b36df5c4
child 24459 ebd373039673
8042885: java does not take hexadecimal number as vm option Summary: Java does not take number with hexadecimal format as options, fix enable hexadecimal format number can be used as vm option. Reviewed-by: coleenp, lfoltan, ctornqvi, hseigel, mseledtsov Contributed-by: yumin.qi@oracle.com
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/utilities/globalDefinitions.hpp
hotspot/test/runtime/CommandLine/TestHexArguments.java
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Thu May 15 18:23:26 2014 -0400
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu May 15 20:16:14 2014 -0700
@@ -583,11 +583,20 @@
 // Parses a memory size specification string.
 static bool atomull(const char *s, julong* result) {
   julong n = 0;
-  int args_read = sscanf(s, JULONG_FORMAT, &n);
+  int args_read = 0;
+  bool is_hex = false;
+  // Skip leading 0[xX] for hexadecimal
+  if (*s =='0' && (*(s+1) == 'x' || *(s+1) == 'X')) {
+    s += 2;
+    is_hex = true;
+    args_read = sscanf(s, JULONG_FORMAT_X, &n);
+  } else {
+    args_read = sscanf(s, JULONG_FORMAT, &n);
+  }
   if (args_read != 1) {
     return false;
   }
-  while (*s != '\0' && isdigit(*s)) {
+  while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) {
     s++;
   }
   // 4705540: illegal if more characters are found after the first non-digit
@@ -781,7 +790,7 @@
     }
   }
 
-#define VALUE_RANGE "[-kmgtKMGT0123456789]"
+#define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]"
   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
     return set_numeric_flag(name, value, origin);
   }
--- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Thu May 15 18:23:26 2014 -0400
+++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp	Thu May 15 20:16:14 2014 -0700
@@ -1346,6 +1346,9 @@
 #ifndef JULONG_FORMAT
 #define JULONG_FORMAT          UINT64_FORMAT
 #endif
+#ifndef JULONG_FORMAT_X
+#define JULONG_FORMAT_X        UINT64_FORMAT_X
+#endif
 
 // Format pointers which change size between 32- and 64-bit.
 #ifdef  _LP64
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/CommandLine/TestHexArguments.java	Thu May 15 20:16:14 2014 -0700
@@ -0,0 +1,49 @@
+/*
+ * 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 8042885
+ * @summary Make sure there is no error using hexadecimal format in vm options
+ * @author Yumin Qi
+ * @library /testlibrary
+ */
+
+import java.io.File;
+import com.oracle.java.testlibrary.*;
+
+public class TestHexArguments {
+    public static void main(String args[]) throws Exception {
+      String[] javaArgs = {"-XX:SharedBaseAddress=0x1D000000", "-version"};
+      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, javaArgs);
+
+      OutputAnalyzer output = new OutputAnalyzer(pb.start());
+      output.shouldNotContain("Could not create the Java Virtual Machine");
+      output.shouldHaveExitValue(0);
+
+      String[] javaArgs1 = {"-XX:SharedBaseAddress=1D000000", "-version"};
+      pb = ProcessTools.createJavaProcessBuilder(true, javaArgs1);
+      output = new OutputAnalyzer(pb.start());
+      output.shouldContain("Could not create the Java Virtual Machine");
+  }
+}