changeset 387:a5dc4bed3735

OptionBuilder.jvmArgs() to add JVM options, not overwrite them.
author shade
date Tue, 11 Feb 2014 20:05:51 +0400
parents ba51dff93e4b
children 4495c91bdaf4
files jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java
diffstat 4 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java	Tue Feb 11 19:54:50 2014 +0400
+++ b/jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java	Tue Feb 11 20:05:51 2014 +0400
@@ -47,6 +47,7 @@
                 .warmupTime(TimeValue.milliseconds(100))
                 .measurementTime(TimeValue.milliseconds(100))
                 .detectJvmArgs()
+                .jvmArgs("-XX:-DoEscapeAnalysis")
                 .forks(5)
                 .build();
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Tue Feb 11 19:54:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Tue Feb 11 20:05:51 2014 +0400
@@ -218,8 +218,9 @@
 
     /**
      * Forked JVM arguments.
+     * (can be used multiple times)
      *
-     * @param value arguments to override with
+     * @param value arguments to add to the run
      * @return builder
      */
     ChainedOptionsBuilder jvmArgs(String... value);
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Feb 11 19:54:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Feb 11 20:05:51 2014 +0400
@@ -521,10 +521,17 @@
 
     @Override
     public Optional<Collection<String>> getJvmArgs() {
+        Collection<String> result = new ArrayList<String>();
+
         if (otherOptions != null) {
-            return jvmArgs.orAnother(otherOptions.getJvmArgs());
+            result.addAll(otherOptions.getJvmArgs().orElse(Collections.<String>emptyList()));
+        }
+        result.addAll(jvmArgs.orElse(Collections.<String>emptyList()));
+
+        if (result.isEmpty()) {
+            return Optional.none();
         } else {
-            return jvmArgs;
+            return Optional.of(result);
         }
     }
 
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java	Tue Feb 11 19:54:50 2014 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java	Tue Feb 11 20:05:51 2014 +0400
@@ -202,7 +202,7 @@
     public void testJVMArgs_Merge() throws Exception {
         Options parent = new OptionsBuilder().jvmArgs("opt1", "opt2").build();
         Options builder = new OptionsBuilder().parent(parent).jvmArgs("opt3", "opt4").build();
-        Assert.assertEquals(Arrays.asList("opt3", "opt4"), builder.getJvmArgs().get());
+        Assert.assertEquals(Arrays.asList("opt1", "opt2", "opt3", "opt4"), builder.getJvmArgs().get());
     }
 
     @Test