changeset 274:c496ad24fb3b

Runners: allow JVM options override with cmdline arguments.
author shade
date Mon, 30 May 2016 15:25:00 +0300
parents 9b6b671dd1e0
children bec06db416c7
files jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java jcstress-core/src/main/java/org/openjdk/jcstress/Options.java jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java
diffstat 4 files changed, 85 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Tue May 24 00:58:53 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Mon May 30 15:25:00 2016 +0300
@@ -108,7 +108,7 @@
 
     public void run() throws Exception {
         VMSupport.initSupport();
-        VMSupport.detectAvailableVMModes();
+        VMSupport.detectAvailableVMModes(opts.getJvmArgs());
 
         opts.printSettingsOn(out);
 
@@ -164,7 +164,7 @@
         if (opts.shouldFork()) {
             List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
             for (String test : tests) {
-                for (List<String> jvmArgs : VMSupport.getAvailableVMModes()) {
+                for (Collection<String> jvmArgs : VMSupport.getAvailableVMModes()) {
                     List<String> fullArgs = new ArrayList<>();
                     fullArgs.addAll(inputArgs);
                     fullArgs.addAll(jvmArgs);
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Tue May 24 00:58:53 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Mon May 30 15:25:00 2016 +0300
@@ -30,10 +30,13 @@
 import joptsimple.OptionSpec;
 import org.openjdk.jcstress.util.OptionFormatter;
 import org.openjdk.jcstress.util.Promise;
+import org.openjdk.jcstress.util.StringUtils;
 import org.openjdk.jcstress.vm.VMSupport;
 
 import java.io.IOException;
 import java.io.PrintStream;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * Options.
@@ -57,6 +60,7 @@
     private boolean userYield;
     private String resultFile;
     private int deoptRatio;
+    private Collection<String> jvmArgs;
 
     public Options(String[] args) {
         this.args = args;
@@ -115,6 +119,11 @@
                 "value improves test performance, but decreases the chance we hit unlucky compilation.")
                 .withRequiredArg().ofType(Integer.class).describedAs("N");
 
+        OptionSpec<String> optJvmArgs = parser.accepts("jvmArgs", "Use given JVM arguments. This disables JVM flags auto-detection, " +
+                "and runs only the single JVM mode. Either a single space-separated option line, or multiple options are accepted. " +
+                "This option only affects forked runs.")
+                .withRequiredArg().ofType(String.class).describedAs("string");
+
         parser.accepts("v", "Be extra verbose.");
         parser.accepts("h", "Print this help.");
 
@@ -198,6 +207,21 @@
             return false;
         }
 
+        if (set.hasArgument(optJvmArgs)) {
+            try {
+                List<String> vals = optJvmArgs.values(set);
+                if (vals.size() != 1) {
+                    jvmArgs = vals;
+                } else {
+                    jvmArgs = StringUtils.splitQuotedEscape(optJvmArgs.value(set));
+                }
+            } catch (OptionException e) {
+                jvmArgs = StringUtils.splitQuotedEscape(optJvmArgs.value(set));
+            }
+        } else {
+            jvmArgs = null;
+        }
+
         return true;
     }
 
@@ -284,4 +308,8 @@
     public String getResultFile() {
         return resultFile;
     }
+
+    public Collection<String> getJvmArgs() {
+        return jvmArgs;
+    }
 }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java	Tue May 24 00:58:53 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java	Mon May 30 15:25:00 2016 +0300
@@ -24,6 +24,10 @@
  */
 package org.openjdk.jcstress.util;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 public class StringUtils {
 
     public static String cutoff(String src, int len) {
@@ -43,6 +47,33 @@
         }
     }
 
+    public static Collection<String> splitQuotedEscape(String src) {
+        List<String> results = new ArrayList<>();
+
+        StringBuilder sb = new StringBuilder();
+        boolean escaped = false;
+        for (char ch : src.toCharArray()) {
+            if (ch == ' ' && !escaped) {
+                String s = sb.toString();
+                if (!s.isEmpty()) {
+                    results.add(s);
+                    sb = new StringBuilder();
+                }
+            } else if (ch == '\"') {
+                escaped ^= true;
+            } else {
+                sb.append(ch);
+            }
+        }
+
+        String s = sb.toString();
+        if (!s.isEmpty()) {
+            results.add(s);
+        }
+
+        return results;
+    }
+
     public static String chunkName(String name) {
         return name.replace("org.openjdk.jcstress.tests", "o.o.j.t");
     }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Tue May 24 00:58:53 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Mon May 30 15:25:00 2016 +0300
@@ -38,7 +38,7 @@
 public class VMSupport {
 
     private static final List<String> ADD_JVM_FLAGS = new ArrayList<>();
-    private static final List<List<String>> AVAIL_JVM_MODES = new ArrayList<>();
+    private static final Collection<Collection<String>> AVAIL_JVM_MODES = new ArrayList<>();
 
     public static void initSupport() {
         System.out.println("Initializing and probing the target VM: ");
@@ -78,31 +78,36 @@
         }
     }
 
-    public static void detectAvailableVMModes() {
-        List<List<String>> modes = Arrays.asList(
-                // Intepreted
-                Arrays.asList("-Xint"),
+    public static void detectAvailableVMModes(Collection<String> jvmArgs) {
+        Collection<Collection<String>> modes;
 
-                // Tiered C1
-                Arrays.asList("-XX:TieredStopAtLevel=1"),
+        if (jvmArgs != null) {
+            modes = Collections.singleton(jvmArgs);
+        } else {
+            modes = Arrays.asList(
+                    // Intepreted
+                    Arrays.asList("-Xint"),
 
-                // Non-tiered C1
-                Arrays.asList("-client"),
-                Arrays.asList("-client", "-XX:-TieredCompilation"),
+                    // Tiered C1
+                    Arrays.asList("-XX:TieredStopAtLevel=1"),
 
-                // Tiered C2
-                Arrays.asList("-server"),
-                Arrays.asList("-server", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"),
+                    // Non-tiered C1
+                    Arrays.asList("-client"),
+                    Arrays.asList("-client", "-XX:-TieredCompilation"),
 
-                // Non-tiered C2
-                Arrays.asList("-server", "-XX:-TieredCompilation"),
-                Arrays.asList("-server", "-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM")
-        );
+                    // Tiered C2
+                    Arrays.asList("-server"),
+                    Arrays.asList("-server", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"),
+
+                    // Non-tiered C2
+                    Arrays.asList("-server", "-XX:-TieredCompilation"),
+                    Arrays.asList("-server", "-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"));
+        }
 
         System.out.println("Probing what VM modes are available:");
         System.out.println(" (failures are non-fatal, but may miss some interesting cases)");
         System.out.println();
-        for (List<String> mode : modes) {
+        for (Collection<String> mode : modes) {
             try {
                 List<String> line = new ArrayList<>(mode);
                 line.add(SimpleTestMain.class.getName());
@@ -181,7 +186,7 @@
     }
 
 
-    public static List<List<String>> getAvailableVMModes() {
+    public static Collection<Collection<String>> getAvailableVMModes() {
         return AVAIL_JVM_MODES;
     }