changeset 250:2657ea3f9bf5

Runners: don't run auto-detections when only parsing is requested.
author shade
date Fri, 13 May 2016 17:45:04 +0300
parents 82422038cf9d
children 83cda6745a5a
files jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java jcstress-core/src/main/java/org/openjdk/jcstress/Main.java jcstress-core/src/main/java/org/openjdk/jcstress/Options.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java jcstress-core/src/main/java/org/openjdk/jcstress/util/Promise.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java
diffstat 7 files changed, 161 insertions(+), 138 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Fri May 13 17:45:04 2016 +0300
@@ -52,7 +52,7 @@
         BinaryLinkClient link = new BinaryLinkClient(host, port);
         TestConfig config = link.nextJob();
 
-        new JCStress().runEmbedded(config, link);
+        new JCStress(null).runEmbedded(config, link);
         link.close();
     }
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Fri May 13 17:45:04 2016 +0300
@@ -59,8 +59,10 @@
 public class JCStress {
     final ExecutorService pool;
     final PrintStream out;
+    final Options opts;
 
-    public JCStress() {
+    public JCStress(Options opts) {
+        this.opts = opts;
         this.pool = Executors.newCachedThreadPool(new ThreadFactory() {
             private final AtomicInteger id = new AtomicInteger();
 
@@ -104,31 +106,36 @@
         }
     }
 
-    public void run(Options opts) throws Exception {
-        if (!opts.shouldParse()) {
-            opts.printSettingsOn(out);
+    public void run() throws Exception {
+        VMSupport.initSupport();
+        VMSupport.detectAvailableVMModes();
 
-            SortedSet<String> tests = getTests(opts.getTestFilter());
-            List<TestConfig> configs = prepareRunProgram(opts, tests);
+        opts.printSettingsOn(out);
 
-            ConsoleReportPrinter printer = new ConsoleReportPrinter(opts, new PrintWriter(out, true), tests.size(), configs.size());
-            DiskWriteCollector diskCollector = new DiskWriteCollector(opts.getResultFile());
-            TestResultCollector sink = MuxCollector.of(printer, diskCollector);
+        SortedSet<String> tests = getTests();
+        List<TestConfig> configs = prepareRunProgram(tests);
 
-            BinaryLinkServer server = new BinaryLinkServer(sink);
+        ConsoleReportPrinter printer = new ConsoleReportPrinter(opts, new PrintWriter(out, true), tests.size(), configs.size());
+        DiskWriteCollector diskCollector = new DiskWriteCollector(opts.getResultFile());
+        TestResultCollector sink = MuxCollector.of(printer, diskCollector);
 
-            Scheduler scheduler = new Scheduler(opts.getUserCPUs());
-            for (TestConfig cfg : configs) {
-                server.addTask(cfg);
-                scheduler.schedule(new TestCfgTask(cfg, server, sink));
-            }
-            scheduler.waitFinish();
+        BinaryLinkServer server = new BinaryLinkServer(sink);
 
-            server.terminate();
+        Scheduler scheduler = new Scheduler(opts.getUserCPUs());
+        for (TestConfig cfg : configs) {
+            server.addTask(cfg);
+            scheduler.schedule(new TestCfgTask(cfg, server, sink));
+        }
+        scheduler.waitFinish();
 
-            diskCollector.close();
-        }
+        server.terminate();
 
+        diskCollector.close();
+
+        parseResults();
+    }
+
+    public void parseResults() throws Exception {
         out.println();
         out.println("Reading the results back... ");
 
@@ -150,7 +157,7 @@
         out.println("Done.");
     }
 
-    private List<TestConfig> prepareRunProgram(Options opts, Set<String> tests) {
+    private List<TestConfig> prepareRunProgram(Set<String> tests) {
         List<TestConfig> configs = new ArrayList<>();
         if (opts.shouldFork()) {
             List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
@@ -227,7 +234,8 @@
         }
     }
 
-    static SortedSet<String> getTests(final String filter) {
+    public SortedSet<String> getTests() {
+        String filter = opts.getTestFilter();
         SortedSet<String> s = new TreeSet<>();
 
         Pattern pattern = Pattern.compile(filter);
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Main.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Main.java	Fri May 13 17:45:04 2016 +0300
@@ -24,8 +24,6 @@
  */
 package org.openjdk.jcstress;
 
-import org.openjdk.jcstress.vm.VMSupport;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
@@ -51,15 +49,15 @@
             System.exit(1);
         }
 
+        JCStress jcstress = new JCStress(opts);
         if (opts.shouldList()) {
-            for (String test : org.openjdk.jcstress.JCStress.getTests(opts.getTestFilter())) {
+            for (String test : jcstress.getTests()) {
                 System.out.println(test);
             }
+        } else if (opts.shouldParse()) {
+            jcstress.parseResults();
         } else {
-            VMSupport.initSupport();
-            VMSupport.detectAvailableVMModes();
-
-            new JCStress().run(opts);
+            jcstress.run();
         }
     }
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Fri May 13 17:45:04 2016 +0300
@@ -29,15 +29,11 @@
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 import org.openjdk.jcstress.util.OptionFormatter;
+import org.openjdk.jcstress.util.Promise;
+import org.openjdk.jcstress.vm.VMSupport;
 
 import java.io.IOException;
 import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 
 /**
  * Options.
@@ -51,17 +47,13 @@
     private int time;
     private int iters;
     private final String[] args;
-    private boolean shouldYield;
     private boolean parse;
     private boolean list;
     private boolean verbose;
-    private int systemCPUs;
-    private int userCPUs;
+    private Promise<Integer> systemCPUs;
+    private Promise<Integer> userCPUs;
     private int forks;
     private String mode;
-    private String hostName;
-    private Integer hostPort;
-    private boolean forceYield;
     private boolean userYield;
     private String resultFile;
     private int deoptRatio;
@@ -119,12 +111,6 @@
         OptionSpec<String> modeStr = parser.accepts("m", "Test mode preset: sanity, quick, default, tough, stress.")
                 .withRequiredArg().ofType(String.class).describedAs("mode");
 
-        OptionSpec<String> hostName = parser.accepts("hostName", "(internal) Host VM address")
-                .withRequiredArg().ofType(String.class);
-
-        OptionSpec<Integer> hostPort = parser.accepts("hostPort", "(internal) Host VM port")
-                .withRequiredArg().ofType(Integer.class);
-
         OptionSpec<Integer> deoptRatio = parser.accepts("deoptRatio", "De-optimize (roughly) every N-th iteration. Larger " +
                 "value improves test performance, but decreases the chance we hit unlucky compilation.")
                 .withRequiredArg().ofType(Integer.class).describedAs("N");
@@ -166,27 +152,19 @@
         this.list = orDefault(set.has(list), false);
         this.verbose = orDefault(set.has("v"), false);
 
-        this.hostName = set.valueOf(hostName);
-        this.hostPort = set.valueOf(hostPort);
-
         if (!set.hasArgument(sysCpus)) {
-            this.systemCPUs = figureOutHotCPUs();
+            this.systemCPUs = Promise.of(VMSupport::figureOutHotCPUs);
         } else {
-            this.systemCPUs = set.valueOf(sysCpus);
+            this.systemCPUs = Promise.of(set.valueOf(sysCpus));
         }
 
         if (!set.hasArgument(cpus)) {
             this.userCPUs = this.systemCPUs;
         } else {
-            this.userCPUs = set.valueOf(cpus);
-        }
-
-        if (userCPUs > systemCPUs) {
-            forceYield = true;
+            this.userCPUs = Promise.of(set.valueOf(cpus));
         }
 
         this.userYield = set.has(shouldYield);
-        this.shouldYield = orDefault(set.valueOf(shouldYield), forceYield);
 
         mode = orDefault(modeStr.value(set), "default");
         if (this.mode.equalsIgnoreCase("sanity")) {
@@ -227,78 +205,22 @@
         return (t != null) ? t : def;
     }
 
-    /**
-     * Warm up the CPU schedulers, bring all the CPUs online to get the
-     * reasonable estimate of the system capacity.
-     *
-     * @return online CPU count
-     */
-    private int figureOutHotCPUs() {
-        ExecutorService service = Executors.newCachedThreadPool();
-
-        System.out.print("Burning up to figure out the exact CPU count...");
-
-        int warmupTime = 1000;
-        long lastChange = System.currentTimeMillis();
-
-        List<Future<?>> futures = new ArrayList<>();
-        futures.add(service.submit(new BurningTask()));
-
-        System.out.print(".");
-
-        int max = 0;
-        while (System.currentTimeMillis() - lastChange < warmupTime) {
-            int cur = Runtime.getRuntime().availableProcessors();
-            if (cur > max) {
-                System.out.print(".");
-                max = cur;
-                lastChange = System.currentTimeMillis();
-                futures.add(service.submit(new BurningTask()));
-            }
-        }
-
-        for (Future<?> f : futures) {
-            System.out.print(".");
-            f.cancel(true);
-        }
-
-        service.shutdown();
-
-        System.out.println(" done!");
-        System.out.println();
-
-        return max;
-    }
-
     public int getForks() {
         return forks;
     }
 
     public void printSettingsOn(PrintStream out) {
-        if (forks > 0) {
-            out.println("FORKED MODE");
+        out.printf("  Hardware threads in use/available: %d/%d, ", getUserCPUs(), getSystemCPUs());
+        if (userYield) {
+            out.printf("user requested yielding in busy loops.\n");
         } else {
-            out.println("EMBEDDED MODE");
+            out.printf("no yielding in use.\n");
         }
         out.printf("  Test preset mode: \"%s\"\n", mode);
         out.printf("  Writing the test results to \"%s\"\n", resultFile);
         out.printf("  Parsing results to \"%s\"\n", resultDir);
         out.printf("  Running each test matching \"%s\" for %d forks, %d iterations, %d ms each\n", getTestFilter(), getForks(), getIterations(), getTime());
         out.printf("  Solo stride size will be autobalanced within [%d, %d] elements\n", getMinStride(), getMaxStride());
-        out.printf("  Hardware threads in use/available: %d/%d, ", getUserCPUs(), getSystemCPUs());
-        if (userYield) {
-            if (shouldYield) {
-                out.printf("user requested yielding in busy loops.\n");
-            } else {
-                out.printf("user disabled yielding in busy loops.\n");
-            }
-        } else {
-            if (shouldYield) {
-                out.printf("yielding was forced, more threads are requested than available.\n");
-            } else {
-                out.printf("no yielding in use.\n");
-            }
-        }
 
         out.println();
     }
@@ -307,14 +229,6 @@
         return deoptRatio;
     }
 
-    public static class BurningTask implements Runnable {
-
-        @Override
-        public void run() {
-            while (!Thread.interrupted()); // burn;
-        }
-    }
-
     public int getMinStride() {
         return minStride;
     }
@@ -332,7 +246,7 @@
     }
 
     public boolean shouldYield() {
-        return shouldYield;
+        return userYield;
     }
 
     public boolean shouldParse() {
@@ -360,19 +274,11 @@
     }
 
     public int getUserCPUs() {
-        return userCPUs;
+        return userCPUs.get();
     }
 
     public int getSystemCPUs() {
-        return systemCPUs;
-    }
-
-    public String getHostName() {
-        return hostName;
-    }
-
-    public int getHostPort() {
-        return hostPort;
+        return systemCPUs.get();
     }
 
     public String getResultFile() {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java	Fri May 13 17:45:04 2016 +0300
@@ -420,7 +420,7 @@
                     emitTestFailure(output, result, test);
                 }
 
-                PrintWriter local = new PrintWriter(resultDir + "/" + cfg + ".html");
+                PrintWriter local = new PrintWriter(resultDir + "/" + cfg.name + ".html");
                 parseTest(local, result, test);
                 local.close();
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/Promise.java	Fri May 13 17:45:04 2016 +0300
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014, 2015, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+package org.openjdk.jcstress.util;
+
+import java.util.function.Supplier;
+
+public class Promise<T> {
+
+    private final Supplier<T> sup;
+    private boolean created;
+    private T value;
+
+    public static <R> Promise<R> of(Supplier<R> sup) {
+        return new Promise<>(sup);
+    }
+
+    public static <R> Promise<R> of(R value) {
+        return new Promise<>(() -> value);
+    }
+
+    private Promise(Supplier<T> sup) {
+        this.sup = sup;
+
+    }
+
+    public T get() {
+        if (!created) {
+            value = sup.get();
+            created = true;
+        }
+        return value;
+    }
+
+}
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Fri May 13 03:18:31 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Fri May 13 17:45:04 2016 +0300
@@ -31,6 +31,9 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 
 public class VMSupport {
 
@@ -169,4 +172,56 @@
     public static List<List<String>> getAvailableVMModes() {
         return AVAIL_JVM_MODES;
     }
+
+    /**
+     * Warm up the CPU schedulers, bring all the CPUs online to get the
+     * reasonable estimate of the system capacity.
+     *
+     * @return online CPU count
+     */
+    public static int figureOutHotCPUs() {
+        ExecutorService service = Executors.newCachedThreadPool();
+
+        System.out.print("Burning up to figure out the exact CPU count...");
+
+        int warmupTime = 1000;
+        long lastChange = System.currentTimeMillis();
+
+        List<Future<?>> futures = new ArrayList<>();
+        futures.add(service.submit(new BurningTask()));
+
+        System.out.print(".");
+
+        int max = 0;
+        while (System.currentTimeMillis() - lastChange < warmupTime) {
+            int cur = Runtime.getRuntime().availableProcessors();
+            if (cur > max) {
+                System.out.print(".");
+                max = cur;
+                lastChange = System.currentTimeMillis();
+                futures.add(service.submit(new BurningTask()));
+            }
+        }
+
+        for (Future<?> f : futures) {
+            System.out.print(".");
+            f.cancel(true);
+        }
+
+        service.shutdown();
+
+        System.out.println(" done!");
+        System.out.println();
+
+        return max;
+    }
+
+    static class BurningTask implements Runnable {
+
+        @Override
+        public void run() {
+            while (!Thread.interrupted()); // burn;
+        }
+    }
+
 }