changeset 1050:adb6047266d8

7901118: Internal sleeps limit the lower bound for time spent doing an iteration by 100ms Summary: Use the blocking flags to communicate the end of sync-iteration catchup loops.
author shade
date Thu, 04 Dec 2014 19:45:31 +0300
parents 7dc3604acf0d
children 2f9c7421ec8e
files jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java
diffstat 2 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java	Thu Nov 27 00:40:28 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java	Thu Dec 04 19:45:31 2014 +0300
@@ -49,6 +49,7 @@
         Utils.check(InfraControl.class, "lastIteration");
         Utils.check(InfraControl.class, "warmupVisited", "warmdownVisited");
         Utils.check(InfraControl.class, "warmupShouldWait", "warmdownShouldWait");
+        Utils.check(InfraControl.class, "warmupDone", "warmdownDone");
         Utils.check(InfraControl.class, "benchmarkParams", "iterationParams");
         Utils.check(InfraControl.class, "shouldSynchIterations", "threads");
     }
@@ -136,6 +137,7 @@
 
     public final AtomicInteger warmupVisited, warmdownVisited;
     public volatile boolean warmupShouldWait, warmdownShouldWait;
+    public final CountDownLatch warmupDone, warmdownDone;
 
     public final BenchmarkParams benchmarkParams;
     public final IterationParams iterationParams;
@@ -144,14 +146,22 @@
     private final int threads;
 
     public InfraControlL2(BenchmarkParams benchmarkParams, IterationParams iterationParams, CountDownLatch preSetup, CountDownLatch preTearDown, boolean lastIteration) {
-        this.warmupVisited = new AtomicInteger();
-        this.warmdownVisited = new AtomicInteger();
+        warmupVisited = new AtomicInteger();
+        warmdownVisited = new AtomicInteger();
+
+        warmupDone = new CountDownLatch(1);
+        warmdownDone = new CountDownLatch(1);
 
         shouldSynchIterations = benchmarkParams.shouldSynchIterations();
         threads = benchmarkParams.getThreads();
 
-        warmupShouldWait = shouldSynchIterations;
-        warmdownShouldWait = shouldSynchIterations;
+        if (!shouldSynchIterations) {
+            warmupShouldWait = false;
+            warmdownShouldWait = false;
+            warmupDone.countDown();
+            warmdownDone.countDown();
+        }
+
         this.preSetup = preSetup;
         this.preTearDown = preTearDown;
         this.lastIteration = lastIteration;
@@ -165,6 +175,7 @@
 
         if (v == threads) {
             warmupShouldWait = false;
+            warmupDone.countDown();
         }
 
         if (v > threads) {
@@ -177,6 +188,7 @@
         int v = warmdownVisited.incrementAndGet();
         if (v == threads) {
             warmdownShouldWait = false;
+            warmdownDone.countDown();
         }
 
         if (v > threads) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Thu Nov 27 00:40:28 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Thu Dec 04 19:45:31 2014 +0300
@@ -94,12 +94,10 @@
         }
 
         // wait for all workers to transit to measurement
-        while (control.warmupShouldWait) {
-            try {
-                TimeUnit.MILLISECONDS.sleep(100);
-            } catch (InterruptedException e) {
-                // ignore
-            }
+        try {
+            control.warmupDone.await();
+        } catch (InterruptedException e) {
+            // ignore
         }
 
         // wait for the iteration time to expire
@@ -119,12 +117,10 @@
         control.isDone = true;
 
         // wait for all workers to transit to teardown
-        while (control.warmdownShouldWait) {
-            try {
-                TimeUnit.MILLISECONDS.sleep(100);
-            } catch (InterruptedException e) {
-                // ignore
-            }
+        try {
+            control.warmdownDone.await();
+        } catch (InterruptedException e) {
+            // ignore
         }
 
         // Wait for the result, continuously polling the worker threads.