changeset 288:6192759ee4c7

Runners: forked VMs should run with the same config that was used to get forked JVM args.
author shade
date Tue, 07 Jun 2016 15:02:35 +0300
parents 039eee0573fc
children 62c33527319f
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/infra/runners/TestConfig.java jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkClient.java jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkServer.java jcstress-core/src/main/java/org/openjdk/jcstress/link/JobRequestFrame.java
diffstat 6 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Tue Jun 07 15:02:35 2016 +0300
@@ -42,15 +42,16 @@
             // expected on JDK 7 and lower, parent should have printed the message for user
         }
 
-        if (args.length < 2) {
-            throw new IllegalStateException("Expected two arguments");
+        if (args.length < 3) {
+            throw new IllegalStateException("Expected three arguments");
         }
 
         String host = args[0];
         int port = Integer.valueOf(args[1]);
+        int token = Integer.valueOf(args[2]);
 
         BinaryLinkClient link = new BinaryLinkClient(host, port);
-        TestConfig config = link.nextJob();
+        TestConfig config = link.nextJob(token);
 
         new JCStress(null).runEmbedded(config, link);
         link.close();
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Tue Jun 07 15:02:35 2016 +0300
@@ -160,6 +160,8 @@
     }
 
     private List<TestConfig> prepareRunProgram(Set<String> tests) {
+        int tokenCounter = 0;
+
         List<TestConfig> configs = new ArrayList<>();
         if (opts.shouldFork()) {
             List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
@@ -169,7 +171,7 @@
                     fullArgs.addAll(inputArgs);
                     fullArgs.addAll(jvmArgs);
                     for (int f = 0; f < opts.getForks(); f++) {
-                        configs.add(new TestConfig(opts, TestList.getInfo(test), TestConfig.RunMode.FORKED, f, fullArgs));
+                        configs.add(new TestConfig(tokenCounter++, opts, TestList.getInfo(test), TestConfig.RunMode.FORKED, f, fullArgs));
                     }
                 }
             }
@@ -177,7 +179,7 @@
             for (String test : tests) {
                 TestInfo info = TestList.getInfo(test);
                 TestConfig.RunMode mode = info.requiresFork() ? TestConfig.RunMode.FORKED : TestConfig.RunMode.EMBEDDED;
-                configs.add(new TestConfig(opts, info, mode, -1, Collections.emptyList()));
+                configs.add(new TestConfig(tokenCounter++, opts, info, mode, -1, Collections.emptyList()));
             }
         }
 
@@ -202,6 +204,9 @@
             command.add(server.getHost());
             command.add(String.valueOf(server.getPort()));
 
+            // which config should the forked VM pull?
+            command.add(String.valueOf(config.uniqueToken));
+
             ProcessBuilder pb = new ProcessBuilder(command);
             Process p = pb.start();
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/TestConfig.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/TestConfig.java	Tue Jun 07 15:02:35 2016 +0300
@@ -35,6 +35,7 @@
 
     public static final Comparator<TestConfig> COMPARATOR_NAME = Comparator.comparing((c) -> c.name);
 
+    public final int uniqueToken;
     public final SpinLoopStyle spinLoopStyle;
     public final boolean verbose;
     public final int minStride;
@@ -54,7 +55,8 @@
         FORKED,
     }
 
-    public TestConfig(Options opts, TestInfo info, RunMode runMode, int forkId, List<String> jvmArgs) {
+    public TestConfig(int uniqueToken, Options opts, TestInfo info, RunMode runMode, int forkId, List<String> jvmArgs) {
+        this.uniqueToken = uniqueToken;
         this.runMode = runMode;
         this.forkId = forkId;
         this.jvmArgs = jvmArgs;
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkClient.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkClient.java	Tue Jun 07 15:02:35 2016 +0300
@@ -106,9 +106,9 @@
         }
     }
 
-    public TestConfig nextJob() throws IOException, ClassNotFoundException {
+    public TestConfig nextJob(int token) throws IOException, ClassNotFoundException {
         synchronized (lock) {
-            pushFrame(new JobRequestFrame());
+            pushFrame(new JobRequestFrame(token));
 
             Object reply = readFrame();
             if (reply instanceof JobResponseFrame) {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkServer.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/link/BinaryLinkServer.java	Tue Jun 07 15:02:35 2016 +0300
@@ -32,8 +32,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * Accepts the binary data from the forked VM and pushes it to parent VM
@@ -47,11 +47,11 @@
     private final Acceptor acceptor;
     private final Collection<Handler> handlers;
     private final TestResultCollector out;
-    private final Queue<TestConfig> configs;
+    private final ConcurrentMap<Integer, TestConfig> configs;
 
     public BinaryLinkServer(TestResultCollector out) throws IOException {
         this.out = out;
-        this.configs = new ConcurrentLinkedDeque<>();
+        this.configs = new ConcurrentHashMap<>();
         acceptor = new Acceptor();
         acceptor.start();
 
@@ -99,7 +99,7 @@
     }
 
     public void addTask(TestConfig cfg) {
-        configs.add(cfg);
+        configs.put(cfg.uniqueToken, cfg);
     }
 
     private final class Acceptor extends Thread {
@@ -208,7 +208,7 @@
         }
 
         private void handleHandshake(JobRequestFrame obj) throws IOException {
-            TestConfig poll = configs.poll();
+            TestConfig poll = configs.remove(obj.getToken());
             if (poll == null) {
                 throw new IllegalStateException("No jobs left, this should not happen");
             }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/link/JobRequestFrame.java	Tue Jun 07 11:56:05 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/link/JobRequestFrame.java	Tue Jun 07 15:02:35 2016 +0300
@@ -28,4 +28,13 @@
 
 class JobRequestFrame implements Serializable {
     private static final long serialVersionUID = 2082214387637725282L;
+    private int token;
+
+    public JobRequestFrame(int token) {
+        this.token = token;
+    }
+
+    public int getToken() {
+        return token;
+    }
 }