changeset 85:ea405a8caf24

Yak shaving: move array utils method to ArrayUtils.
author shade
date Thu, 13 Mar 2014 00:22:00 +0400
parents f0b05b6340d4
children b830f2a55505
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/ActorBase.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java jcstress-core/src/main/java/org/openjdk/jcstress/util/ArrayUtils.java
diffstat 3 files changed, 54 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/ActorBase.java	Thu Mar 13 00:17:16 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/ActorBase.java	Thu Mar 13 00:22:00 2014 +0400
@@ -26,6 +26,7 @@
 
 import org.openjdk.jcstress.infra.Result;
 import org.openjdk.jcstress.tests.ActorConcurrencyTest;
+import org.openjdk.jcstress.util.ArrayUtils;
 import org.openjdk.jcstress.util.Counter;
 
 import java.util.Arrays;
@@ -116,7 +117,7 @@
             // check if we need to refit our collections
             if (loops != lastLoops) {
                 lastLoops = loops;
-                indices = Runner.generatePermutation(loops);
+                indices = ArrayUtils.generatePermutation(loops);
             }
 
             holder.announceReady();
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Thu Mar 13 00:17:16 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Thu Mar 13 00:22:00 2014 +0400
@@ -69,27 +69,6 @@
         testLog.printf("Executing with %d threads\n", totalThreads);
     }
 
-    public static int[] generatePermutation(int len) {
-        int[] res = new int[len];
-        for (int i = 0; i < len; i++) {
-            res[i] = i;
-        }
-        return shuffle(res);
-    }
-
-    public static int[] shuffle(int[] arr) {
-        Random r = new Random();
-        int[] res = arr.clone();
-        for (int i = arr.length; i > 1; i--) {
-            int i1 = i - 1;
-            int i2 = r.nextInt(i);
-            int t = res[i1];
-            res[i1] = res[i2];
-            res[i2] = t;
-        }
-        return res;
-    }
-
     protected void dumpFailure(String testName, Status status) {
         TestResult result = new TestResult(testName, status);
         collector.add(result);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/ArrayUtils.java	Thu Mar 13 00:22:00 2014 +0400
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.util;
+
+import java.util.Random;
+
+public class ArrayUtils {
+
+    public static int[] generatePermutation(int len) {
+        int[] res = new int[len];
+        for (int i = 0; i < len; i++) {
+            res[i] = i;
+        }
+        return shuffle(res);
+    }
+
+    public static int[] shuffle(int[] arr) {
+        Random r = new Random();
+        int[] res = arr.clone();
+        for (int i = arr.length; i > 1; i--) {
+            int i1 = i - 1;
+            int i2 = r.nextInt(i);
+            int t = res[i1];
+            res[i1] = res[i2];
+            res[i2] = t;
+        }
+        return res;
+    }
+
+}