8060256: The loop in Arguments::parse() can be enhanced.
authorjiangli
Thu, 16 Oct 2014 14:11:53 -0400
changeset 27244 a2bd9d3112d4
parent 27169 59d46464ef22
child 27245 6d08a994e466
8060256: The loop in Arguments::parse() can be enhanced. Summary: Add continue statement for matching cases. Reviewed-by: dholmes, bdelsart
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/runtime/arguments_ext.hpp
hotspot/test/runtime/CommandLine/TestVMOptions.java
hotspot/test/runtime/CommandLine/flagfile.txt
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Wed Oct 15 05:55:44 2014 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu Oct 16 14:11:53 2014 -0400
@@ -3739,27 +3739,33 @@
   bool settings_file_specified = false;
   bool needs_hotspotrc_warning = false;
 
-  ArgumentsExt::process_options(args);
-
   const char* flags_file;
   int index;
   for (index = 0; index < args->nOptions; index++) {
     const JavaVMOption *option = args->options + index;
+    if (ArgumentsExt::process_options(option)) {
+      continue;
+    }
     if (match_option(option, "-XX:Flags=", &tail)) {
       flags_file = tail;
       settings_file_specified = true;
+      continue;
     }
     if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
       PrintVMOptions = true;
+      continue;
     }
     if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
       PrintVMOptions = false;
+      continue;
     }
     if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
       IgnoreUnrecognizedVMOptions = true;
+      continue;
     }
     if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
       IgnoreUnrecognizedVMOptions = false;
+      continue;
     }
     if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
       CommandLineFlags::printFlags(tty, false);
@@ -3781,6 +3787,7 @@
       } else {
         vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
       }
+      continue;
     }
 #endif
 
--- a/hotspot/src/share/vm/runtime/arguments_ext.hpp	Wed Oct 15 05:55:44 2014 -0700
+++ b/hotspot/src/share/vm/runtime/arguments_ext.hpp	Thu Oct 16 14:11:53 2014 -0400
@@ -34,7 +34,10 @@
   static inline bool check_gc_consistency_user();
   static inline bool check_gc_consistency_ergo();
   static inline bool check_vm_args_consistency();
-  static        void process_options(const JavaVMInitArgs* args) {}
+  // The argument processing extension. Returns true if there is
+  // no additional parsing needed in Arguments::parse() for the option.
+  // Otherwise returns false.
+  static inline bool process_options(const JavaVMOption *option) { return false; }
 };
 
 void ArgumentsExt::select_gc_ergonomically() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/CommandLine/TestVMOptions.java	Thu Oct 16 14:11:53 2014 -0400
@@ -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 8060256
+ * @summary Test various command line options
+ * @library /testlibrary
+ * @run main TestVMOptions
+ */
+
+import com.oracle.java.testlibrary.*;
+import java.io.File;
+
+public class TestVMOptions {
+  public static void main(String[] args) throws Exception {
+    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+        "-XX:bogus",
+        "-XX:+IgnoreUnrecognizedVMOptions",
+        "-XX:+PrintFlagsInitial");
+    OutputAnalyzer output = new OutputAnalyzer(pb.start());
+    output.shouldContain("bool PrintGCDetails");
+
+    pb = ProcessTools.createJavaProcessBuilder(
+        "-XX:-PrintVMOptions", "-version");
+    output = new OutputAnalyzer(pb.start());
+    output.shouldContain("java version");
+
+    File dir = new File(System.getProperty("test.src", "."));
+    File file = new File(dir, "flagfile.txt");
+    String s = file.getAbsolutePath();
+    pb = ProcessTools.createJavaProcessBuilder("-XX:Flags="+s);
+    output = new OutputAnalyzer(pb.start());
+    output.shouldContain("VM option '-IgnoreUnrecognizedVMOptions'");
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/CommandLine/flagfile.txt	Thu Oct 16 14:11:53 2014 -0400
@@ -0,0 +1,1 @@
++PrintVMOptions -IgnoreUnrecognizedVMOptions