changeset 294:56522f915974

Prepare forked VM interface to accept multiple benchmarks per invocation.
author shade
date Tue, 03 Dec 2013 14:01:58 +0400
parents 0c762fb22905
children 6c41487eb634
files jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java jmh-core/src/main/java/org/openjdk/jmh/link/frames/InfraFrame.java jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 5 files changed, 42 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java	Mon Dec 02 20:13:22 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkClient.java	Tue Dec 03 14:01:58 2013 +0400
@@ -87,12 +87,28 @@
         oos.flush();
     }
 
-    public BenchmarkRecord requestNextBenchmark() throws IOException, ClassNotFoundException {
+    public BenchmarkRecord requestNextWarmup() throws IOException, ClassNotFoundException {
+        oos.writeObject(new InfraFrame(InfraFrame.Type.BULK_WARMUP_REQUEST));
+        oos.flush();
+
+        Object reply = ois.readObject();
+        if (reply == null) {
+            return null;
+        } else if (reply instanceof BenchmarkRecordFrame) {
+            return (((BenchmarkRecordFrame) reply).getBenchmark());
+        } else {
+            throw new IllegalStateException("Got the erroneous reply: " + reply);
+        }
+    }
+
+    public BenchmarkRecord requestNextMeasurement() throws IOException, ClassNotFoundException {
         oos.writeObject(new InfraFrame(InfraFrame.Type.BENCHMARK_REQUEST));
         oos.flush();
 
         Object reply = ois.readObject();
-        if (reply instanceof BenchmarkRecordFrame) {
+        if (reply == null) {
+            return null;
+        } else if (reply instanceof BenchmarkRecordFrame) {
             return (((BenchmarkRecordFrame) reply).getBenchmark());
         } else {
             throw new IllegalStateException("Got the erroneous reply: " + reply);
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Mon Dec 02 20:13:22 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/BinaryLinkServer.java	Tue Dec 03 14:01:58 2013 +0400
@@ -138,7 +138,9 @@
     }
 
     public void setCurrentBenchmark(BenchmarkRecord benchmark) {
-        this.benchmark.set(benchmark);
+        if (!this.benchmark.compareAndSet(null, benchmark)) {
+            throw new IllegalStateException("Benchmark is already set");
+        }
     }
 
     private final class Acceptor extends Thread {
@@ -264,7 +266,11 @@
                     oos.flush();
                     break;
                 case BENCHMARK_REQUEST:
-                    oos.writeObject(new BenchmarkRecordFrame(benchmark.get()));
+                    oos.writeObject(new BenchmarkRecordFrame(benchmark.getAndSet(null)));
+                    oos.flush();
+                    break;
+                case BULK_WARMUP_REQUEST:
+                    oos.writeObject(null);
                     oos.flush();
                     break;
                 default:
--- a/jmh-core/src/main/java/org/openjdk/jmh/link/frames/InfraFrame.java	Mon Dec 02 20:13:22 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/link/frames/InfraFrame.java	Tue Dec 03 14:01:58 2013 +0400
@@ -40,6 +40,7 @@
 
     public enum Type {
         OPTIONS_REQUEST,
+        BULK_WARMUP_REQUEST,
         BENCHMARK_REQUEST,
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Mon Dec 02 20:13:22 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Tue Dec 03 14:01:58 2013 +0400
@@ -46,9 +46,19 @@
     }
 
     public void run() throws IOException, ClassNotFoundException {
-        BenchmarkRecord benchmark = link.requestNextBenchmark();
-        BenchResult result = runBenchmark(benchmark, true, true);
-        link.pushResults(benchmark, result);
+        BenchmarkRecord benchmark;
+
+        // Bulk warmup benchmarks first
+        while ((benchmark = link.requestNextWarmup()) != null) {
+            BenchResult result = runBenchmark(benchmark, true, false);
+            link.pushResults(benchmark, result);
+        }
+
+        // Measurement then
+        while ((benchmark = link.requestNextMeasurement()) != null) {
+            BenchResult result = runBenchmark(benchmark, true, true);
+            link.pushResults(benchmark, result);
+        }
 
         out.flush();
         out.close();
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Dec 02 20:13:22 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Tue Dec 03 14:01:58 2013 +0400
@@ -313,8 +313,6 @@
             server = new BinaryLinkServer(options, out);
 
             for (BenchmarkRecord benchmark : benchmarks) {
-                server.setCurrentBenchmark(benchmark);
-
                 // Running microbenchmark in separate JVM requires to read some options from annotations.
                 final Method benchmarkMethod = MicroBenchmarkHandlers.findBenchmarkMethod(benchmark);
                 Fork forkAnnotation = benchmarkMethod.getAnnotation(Fork.class);
@@ -344,6 +342,7 @@
                     out.verbosePrintln("Warmup forking " + warmupForkCount + " times using command: " + Arrays.toString(commandString));
                     for (int i = 0; i < warmupForkCount; i++) {
                         out.println("# Warmup Fork: " + (i + 1) + " of " + forkCount);
+                        server.setCurrentBenchmark(benchmark);
                         doFork(server, commandString);
                     }
                 }
@@ -351,6 +350,7 @@
                 out.verbosePrintln("Forking " + forkCount + " times using command: " + Arrays.toString(commandString));
                 for (int i = 0; i < forkCount; i++) {
                     out.println("# Fork: " + (i + 1) + " of " + forkCount);
+                    server.setCurrentBenchmark(benchmark);
                     BenchResult result = doFork(server, commandString);
                     results.put(benchmark, result);
                 }