changeset 341:0de8079ec104

Runners: make sure fat tasks are handled well in embedded mode, and return the actual number of tokens back.
author shade
date Wed, 04 Jan 2017 12:24:51 +0100
parents c16c2f7fa79b
children 50ec2fc74cd1
files jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java	Mon Dec 19 16:34:39 2016 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java	Wed Jan 04 12:24:51 2017 +0100
@@ -86,7 +86,7 @@
                 sink.add(result);
             }
         }) : null;
-        embeddedExecutor = new EmbeddedExecutor(sink, (cfg) -> semaphore.release(cfg.threads));
+        embeddedExecutor = new EmbeddedExecutor(sink, (cfg) -> release(cfg.threads));
     }
 
     public void runAll(List<TestConfig> configs) throws InterruptedException {
@@ -126,9 +126,7 @@
     }
 
     private void doSchedule(BatchKey batchKey, Collection<TestConfig> configs) {
-        // Make fat tasks bypass in exclusive mode:
-        final int threads = Math.min(batchKey.threads, maxThreads);
-        waitForMoreThreads(threads);
+        waitForMoreThreads(batchKey.threads);
 
         String token = "fork-token-" + ID.incrementAndGet();
         VM vm = new VM(server.getHost(), server.getPort(), batchKey, token, configs);
@@ -137,7 +135,7 @@
     }
 
     private void waitForMoreThreads(int threads) {
-        while (!semaphore.tryAcquire(threads)) {
+        while (!tryAcquire(threads)) {
             processReadyVMs();
             try {
                 Thread.sleep(SPIN_WAIT_DELAY_MS);
@@ -147,6 +145,18 @@
         }
     }
 
+    private boolean tryAcquire(int requested) {
+        // Make fat tasks bypass in exclusive mode:
+        final int threads = Math.min(requested, maxThreads);
+        return semaphore.tryAcquire(threads);
+    }
+
+    private void release(int requested) {
+        // If task was fat and bypassed, release only maxThreads:
+        final int threads = Math.min(requested, maxThreads);
+        semaphore.release(threads);
+    }
+
     private void processReadyVMs() {
         for (VM vm : vmByToken.values()) {
             try {
@@ -162,7 +172,7 @@
             }
 
             vmByToken.remove(vm.token, vm);
-            semaphore.release(vm.key.threads);
+            release(vm.key.threads);
 
             // Remaining tasks from the fork need to get back on queue
             List<TestConfig> pending = vm.getPendingTasks();