changeset 155:36090b701f77

Remove StateHolder.indices: useless to have the same traversal strategy for all workers.
author shade
date Thu, 31 Jul 2014 16:02:22 -0700
parents a119fb6622e3
children be0a7fa495e9
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java
diffstat 2 files changed, 7 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Thu May 15 22:06:21 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Thu Jul 31 16:02:22 2014 -0700
@@ -278,7 +278,7 @@
         pw.println("        Counter<" + r + "> counter = Counters.newCounter(" + r + ".class);");
         pw.println();
         pw.println("        final AtomicReference<StateHolder<" + s + "," + r + ">> version = new AtomicReference<StateHolder<" + s + ", " + r + ">>();");
-        pw.println("        version.set(new StateHolder<" + s + ", " + r + ">(new " + s + "[0], new " + r + "[0], new int[0], " + actorsCount + "));");
+        pw.println("        version.set(new StateHolder<" + s + ", " + r + ">(new " + s + "[0], new " + r + "[0], " + actorsCount + "));");
         pw.println();
         pw.println("        final AtomicInteger epoch = new AtomicInteger();");
         pw.println();
@@ -343,7 +343,7 @@
         pw.println();
         pw.println("            StateHolder<" + s + ", " + r + "> newHolder;");
         pw.println("            if (control.isStopped) {");
-        pw.println("                newHolder = new StateHolder<" + s + ", " + r + ">(poison, null, null, " + actorsCount + ");");
+        pw.println("                newHolder = new StateHolder<" + s + ", " + r + ">(poison, null, " + actorsCount + ");");
         pw.println("            } else {");
         pw.println("                int newLoops = holder.hasLaggedWorkers ? Math.max(control.minStride, Math.min(loops * 2, control.maxStride)) : loops;");
         pw.println();
@@ -370,21 +370,19 @@
         pw.println();
         pw.println("                " + s + "[] newStride = cur;");
         pw.println("                " + r + "[] newRes = res;");
-        pw.println("                int[] indices = holder.indices;");
         pw.println("                if (newLoops > loops) {");
         pw.println("                    newStride = Arrays.copyOf(cur, newLoops);");
         pw.println("                    newRes = Arrays.copyOf(res, newLoops);");
         pw.println("                    for (int c = loops; c < newLoops; c++) {");
         pw.println("                        newRes[c] = new " + r + "();");
         pw.println("                    }");
-        pw.println("                    indices = ArrayUtils.generatePermutation(newLoops);");
         pw.println("                }");
         pw.println();
         pw.println("                for (int c = 0; c < newLoops; c++) {");
         pw.println("                    newStride[c] = new " + s + "();");
         pw.println("                }");
         pw.println();
-        pw.println("                newHolder = new StateHolder<" + s + ", " + r + ">(newStride, newRes, indices, " + actorsCount + ");");
+        pw.println("                newHolder = new StateHolder<" + s + ", " + r + ">(newStride, newRes, " + actorsCount + ");");
         pw.println("            }");
         pw.println();
         pw.println("            version.set(newHolder);");
@@ -406,7 +404,6 @@
             pw.println("            while (true) {");
             pw.println("                StateHolder<" + s + ", " + r + "> holder = version.get();");
             pw.println("                int loops = holder.loops;");
-            pw.println("                int[] indices = holder.indices;");
             pw.println("                " + s + "[] cur = holder.s;");
             pw.println("                " + r + "[] res = holder.r;");
             pw.println();
@@ -416,13 +413,12 @@
             pw.println();
             pw.println("                holder.preRun(control.shouldYield);");
             pw.println();
-            pw.println("                for (int l = 0; l < loops; l++) {");
-            pw.println("                    int index = indices[l];");
+            pw.println("                for (int i = 0; i < loops; i++) {");
 
             if (info.getState().equals(info.getTest())) {
-                emitMethod(pw, a, "                    cur[index]." + a.getSimpleName(), "cur[index]", "res[index]");
+                emitMethod(pw, a, "                    cur[i]." + a.getSimpleName(), "cur[i]", "res[i]");
             } else {
-                emitMethod(pw, a, "                    lt." + a.getSimpleName(), "cur[index]", "res[index]");
+                emitMethod(pw, a, "                    lt." + a.getSimpleName(), "cur[i]", "res[i]");
             }
 
             pw.println("                }");
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java	Thu May 15 22:06:21 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/StateHolder.java	Thu Jul 31 16:02:22 2014 -0700
@@ -32,17 +32,15 @@
 public class StateHolder<S, R> {
     public volatile S[] s;
     public volatile R[] r;
-    public volatile int[] indices;
     public final int loops;
     public final int countWorkers;
     public final AtomicInteger started, ready, finished, consumed;
     public volatile boolean notAllStarted, notAllReady, notAllFinished, notAllConsumed;
     public volatile boolean hasLaggedWorkers;
 
-    public StateHolder(S[] s, R[] r, int[] indices, int expectedWorkers) {
+    public StateHolder(S[] s, R[] r, int expectedWorkers) {
         this.s = s;
         this.r = r;
-        this.indices = indices;
         this.loops = s.length;
         this.countWorkers = expectedWorkers;
         this.ready = new AtomicInteger(expectedWorkers);