changeset 113:7207923207ef

Migrate scratch.* tests to new API.
author shade
date Fri, 14 Mar 2014 15:58:10 +0400
parents a9b54ed917a8
children d2af72371f94
files tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/AQSTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/FailingCASTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/StaleReadTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/Unsafe_GetDoubleVolatileTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_1_Test.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_2_Test.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/SynchronizedTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/VolatileTest.java
diffstat 8 files changed, 127 insertions(+), 172 deletions(-) [+]
line wrap: on
line diff
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/AQSTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/AQSTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,37 +24,32 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.BooleanResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 
 import java.util.concurrent.locks.AbstractQueuedSynchronizer;
 
-public class AQSTest implements Actor2_Test<AQSTest.MyLock, BooleanResult2> {
+@ConcurrencyStressTest
+public class AQSTest {
 
-    @Override
+    @Actor
     public void actor1(MyLock l, BooleanResult2 r) {
         l.acquire(1);
         r.r1 = true;
         l.release(1);
     }
 
-    @Override
+    @Actor
     public void actor2(MyLock l, BooleanResult2 r) {
         l.acquire(1);
         r.r2 = true;
         l.release(1);
     }
 
-    @Override
-    public MyLock newState() {
-        return new MyLock();
-    }
-
-    @Override
-    public BooleanResult2 newResult() {
-        return new BooleanResult2();
-    }
-
+    @State
     public static class MyLock extends AbstractQueuedSynchronizer {
         @Override
         protected boolean tryAcquire(int _) {
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/FailingCASTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/FailingCASTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,43 +24,36 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.IntResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 import org.openjdk.jcstress.util.UnsafeHolder;
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-public class FailingCASTest implements Actor2_Test<FailingCASTest.State, IntResult2> {
+@ConcurrencyStressTest
+@State
+public class FailingCASTest {
 
-    @Override
-    public void actor1(State s, IntResult2 r) {
-        s.x = 1;
-        if (!s.y.compareAndSet(42, 43)) {
-            s.z = 1;
+    int x;
+    final AtomicInteger y = new AtomicInteger();
+    int z;
+
+    @Actor
+    public void actor1() {
+        x = 1;
+        if (!y.compareAndSet(42, 43)) {
+            z = 1;
         }
     }
 
-    @Override
-    public void actor2(State s, IntResult2 r) {
-        r.r1 = s.z;
+    @Actor
+    public void actor2(IntResult2 r) {
+        r.r1 = z;
         UnsafeHolder.U.fullFence();
-        r.r2 = s.x;
-    }
-
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public IntResult2 newResult() {
-        return new IntResult2();
-    }
-
-    public static class State {
-        int x;
-        final AtomicInteger y = new AtomicInteger();
-        int z;
+        r.r2 = x;
     }
 
 }
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/StaleReadTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/StaleReadTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,6 +24,8 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.tests.TerminationTest;
 
 public class StaleReadTest implements TerminationTest<StaleReadTest.State> {
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/Unsafe_GetDoubleVolatileTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/Unsafe_GetDoubleVolatileTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,44 +24,37 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.DoubleResult1;
 import org.openjdk.jcstress.tests.Actor2_Test;
 import org.openjdk.jcstress.util.UnsafeHolder;
 
-public class Unsafe_GetDoubleVolatileTest implements Actor2_Test<Unsafe_GetDoubleVolatileTest.State, DoubleResult1> {
+@ConcurrencyStressTest
+@State
+public class Unsafe_GetDoubleVolatileTest {
 
-    @Override
-    public void actor1(State s, DoubleResult1 r) {
-        UnsafeHolder.U.putDoubleVolatile(s, State.OFFSET, -1D);
+    static long OFFSET;
+
+    static {
+        try {
+            OFFSET = UnsafeHolder.U.objectFieldOffset(Unsafe_GetDoubleVolatileTest.class.getDeclaredField("x"));
+        } catch (NoSuchFieldException e) {
+            throw new IllegalStateException(e);
+        }
     }
 
-    @Override
-    public void actor2(State s, DoubleResult1 r) {
-        r.r1 = UnsafeHolder.U.getDoubleVolatile(s, State.OFFSET);
+    volatile double x;
+
+    @Actor
+    public void actor1() {
+        UnsafeHolder.U.putDoubleVolatile(this, OFFSET, -1D);
     }
 
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public DoubleResult1 newResult() {
-        return new DoubleResult1();
-    }
-
-    public static class State {
-        private static long OFFSET;
-
-        static {
-            try {
-                OFFSET = UnsafeHolder.U.objectFieldOffset(State.class.getDeclaredField("x"));
-            } catch (NoSuchFieldException e) {
-                throw new IllegalStateException(e);
-            }
-        }
-
-        public volatile double x;
+    @Actor
+    public void actor2(DoubleResult1 r) {
+        r.r1 = UnsafeHolder.U.getDoubleVolatile(this, OFFSET);
     }
 
 }
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_1_Test.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_1_Test.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,6 +24,9 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.IntResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 
@@ -31,36 +34,26 @@
  * Dummy test to check if volatile write's StoreLoad is erased by following biased lock
  * Run with -XX:BiasedLockingStartupDelay=0
  */
-public class VW_Sync_1_Test implements Actor2_Test<VW_Sync_1_Test.State, IntResult2> {
+@ConcurrencyStressTest
+@State
+public class VW_Sync_1_Test {
 
-    @Override
-    public void actor1(State s, IntResult2 r) {
-        synchronized (s.o) {} // bias first
-        s.x = 1;
-        s.v = 1;
-        synchronized (s.o) {}
+    int x;
+    volatile int v;
+    final Object o = new Object();
+
+    @Actor
+    public void actor1() {
+        synchronized (o) {} // bias first
+        x = 1;
+        v = 1;
+        synchronized (o) {}
     }
 
-    @Override
-    public void actor2(State s, IntResult2 r) {
-        r.r1 = s.v;
-        r.r2 = s.x;
-    }
-
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public IntResult2 newResult() {
-        return new IntResult2();
-    }
-
-    public static class State  {
-        public int x;
-        public volatile int v;
-        public final Object o = new Object();
+    @Actor
+    public void actor2(IntResult2 r) {
+        r.r1 = v;
+        r.r2 = x;
     }
 
 }
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_2_Test.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/VW_Sync_2_Test.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,6 +24,9 @@
  */
 package org.openjdk.jcstress.tests.scratch;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.IntResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 
@@ -31,36 +34,26 @@
  * Dummy test to check if volatile write's StoreLoad is erased by following biased lock
  * Run with -XX:BiasedLockingStartupDelay=0
  */
-public class VW_Sync_2_Test implements Actor2_Test<VW_Sync_2_Test.State, IntResult2> {
+@ConcurrencyStressTest
+@State
+public class VW_Sync_2_Test {
 
-    @Override
-    public void actor1(State s, IntResult2 r) {
-        synchronized (s.o) {
-            s.x = 1;
-            s.v = 1;
+    int x;
+    volatile int v;
+    final Object o = new Object();
+
+    @Actor
+    public void actor1() {
+        synchronized (o) {
+            x = 1;
+            v = 1;
         }
     }
 
-    @Override
-    public void actor2(State s, IntResult2 r) {
-        r.r1 = s.v;
-        r.r2 = s.x;
-    }
-
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public IntResult2 newResult() {
-        return new IntResult2();
-    }
-
-    public static class State  {
-        public int x;
-        public volatile int v;
-        public final Object o = new Object();
+    @Actor
+    public void actor2(IntResult2 r) {
+        r.r1 = v;
+        r.r2 = x;
     }
 
 }
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/SynchronizedTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/SynchronizedTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,41 +24,34 @@
  */
 package org.openjdk.jcstress.tests.scratch.basic;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.IntResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 
-public class SynchronizedTest implements Actor2_Test<SynchronizedTest.State, IntResult2> {
+@ConcurrencyStressTest
+@State
+public class SynchronizedTest {
 
-    @Override
-    public void actor1(State s, IntResult2 r) {
-        synchronized (s.g) {
-            s.g1 = 1;
-            s.a = 1;
+    int a;
+    volatile int g1;
+    final Object g = new Object();
+
+    @Actor
+    public void actor1() {
+        synchronized (g) {
+            g1 = 1;
+            a = 1;
         }
     }
 
-    @Override
-    public void actor2(State s, IntResult2 r) {
-        synchronized (s.g) {
-            r.r2 = s.a;
-            r.r1 = s.g1; // check the sync block had indeed executed
+    @Actor
+    public void actor2(IntResult2 r) {
+        synchronized (g) {
+            r.r2 = a;
+            r.r1 = g1; // check the sync block had indeed executed
         }
     }
 
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public IntResult2 newResult() {
-        return new IntResult2();
-    }
-
-    public static class State {
-        private volatile int g1;
-        private int a;
-        private final Object g = new Object();
-    }
-
 }
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/VolatileTest.java	Fri Mar 14 14:26:54 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/basic/VolatileTest.java	Fri Mar 14 15:58:10 2014 +0400
@@ -24,36 +24,29 @@
  */
 package org.openjdk.jcstress.tests.scratch.basic;
 
+import org.openjdk.jcstress.infra.annotations.Actor;
+import org.openjdk.jcstress.infra.annotations.ConcurrencyStressTest;
+import org.openjdk.jcstress.infra.annotations.State;
 import org.openjdk.jcstress.infra.results.IntResult2;
 import org.openjdk.jcstress.tests.Actor2_Test;
 
-public class VolatileTest implements Actor2_Test<VolatileTest.State, IntResult2> {
+@ConcurrencyStressTest
+@State
+public class VolatileTest {
 
-    @Override
-    public void actor1(State s, IntResult2 r) {
-        s.a = 1;
-        s.g = 1; // release
+    int a;
+    volatile int g;
+
+    @Actor
+    public void actor1() {
+        a = 1;
+        g = 1; // release
     }
 
-    @Override
-    public void actor2(State s, IntResult2 r) {
-        r.r1 = s.g; // acquire
-        r.r2 = s.a;
-    }
-
-    @Override
-    public State newState() {
-        return new State();
-    }
-
-    @Override
-    public IntResult2 newResult() {
-        return new IntResult2();
-    }
-
-    public static class State {
-        private int a;
-        private volatile int g;
+    @Actor
+    public void actor2(IntResult2 r) {
+        r.r1 = g; // acquire
+        r.r2 = a;
     }
 
 }