changeset 392:9f21d933addf

Runners: jvmArgsPrepend command-line option to add JVM args to all configurations.
author shade
date Fri, 17 Mar 2017 11:23:01 +0100
parents 9849fb5331b5
children 97d6f5340387
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/vm/VMSupport.java
diffstat 3 files changed, 35 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Wed Mar 15 11:54:55 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Fri Mar 17 11:23:01 2017 +0100
@@ -54,7 +54,7 @@
     }
 
     public void run() throws Exception {
-        VMSupport.detectAvailableVMModes(opts.getJvmArgs());
+        VMSupport.detectAvailableVMModes(opts.getJvmArgs(), opts.getJvmArgsPrepend());
         if (VMSupport.getAvailableVMModes().isEmpty()) {
             out.println("FATAL: No JVM modes to run with.");
             return;
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Wed Mar 15 11:54:55 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Fri Mar 17 11:23:01 2017 +0100
@@ -66,6 +66,7 @@
     private String resultFile;
     private int deoptRatio;
     private Collection<String> jvmArgs;
+    private Collection<String> jvmArgsPrepend;
     private int batchSize;
 
     public Options(String[] args) {
@@ -138,6 +139,11 @@
                 "This option only affects forked runs.")
                 .withRequiredArg().ofType(String.class).describedAs("string");
 
+        OptionSpec<String> optJvmArgsPrepend = parser.accepts("jvmArgsPrepend", "Prepend given JVM arguments to auto-detected configurations. " +
+                "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.");
 
@@ -234,22 +240,27 @@
         this.batchSize = orDefault(set.valueOf(batchSize), this.batchSize);
         this.deoptRatio = orDefault(set.valueOf(deoptRatio), this.iters * 3);
 
-        if (set.hasArgument(optJvmArgs)) {
+        this.jvmArgs = processArgs(optJvmArgs, set);
+        this.jvmArgsPrepend = processArgs(optJvmArgsPrepend, set);
+
+        return true;
+    }
+
+    private Collection<String> processArgs(OptionSpec<String> op, OptionSet set) {
+        if (set.hasArgument(op)) {
             try {
-                List<String> vals = optJvmArgs.values(set);
+                List<String> vals = op.values(set);
                 if (vals.size() != 1) {
-                    jvmArgs = vals;
+                    return vals;
                 } else {
-                    jvmArgs = StringUtils.splitQuotedEscape(optJvmArgs.value(set));
+                    return StringUtils.splitQuotedEscape(op.value(set));
                 }
             } catch (OptionException e) {
-                jvmArgs = StringUtils.splitQuotedEscape(optJvmArgs.value(set));
+                return StringUtils.splitQuotedEscape(op.value(set));
             }
         } else {
-            jvmArgs = null;
+            return null;
         }
-
-        return true;
     }
 
     private <T> T orDefault(T t, T def) {
@@ -344,6 +355,10 @@
         return jvmArgs;
     }
 
+    public Collection<String> getJvmArgsPrepend() {
+        return jvmArgsPrepend;
+    }
+
     public int getMaxFootprintMb() {
         return maxFootprint;
     }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Wed Mar 15 11:54:55 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Fri Mar 17 11:23:01 2017 +0100
@@ -120,7 +120,7 @@
         }
     }
 
-    public static void detectAvailableVMModes(Collection<String> jvmArgs) {
+    public static void detectAvailableVMModes(Collection<String> jvmArgs, Collection<String> jvmArgsPrepend) {
         Collection<Collection<String>> modes;
 
         if (jvmArgs != null) {
@@ -142,6 +142,16 @@
                     Arrays.asList("-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"));
         }
 
+        // Mix in prepends, if available
+        if (jvmArgsPrepend != null) {
+            modes = modes.stream().map(c -> {
+                Collection<String> l = new ArrayList<>();
+                l.addAll(jvmArgsPrepend);
+                l.addAll(c);
+                return l;
+            }).collect(Collectors.toList());
+        }
+
         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();