changeset 153:d06fc63b369d

scratch: lazySet order test.
author shade
date Wed, 07 May 2014 18:11:44 +0400
parents 7a9f5f818d94
children a119fb6622e3
files tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/LazySetOrderTest.java tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml
diffstat 2 files changed, 127 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/LazySetOrderTest.java	Wed May 07 18:11:44 2014 +0400
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2014, 2014, 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.tests.scratch;
+
+import org.openjdk.jcstress.annotations.Actor;
+import org.openjdk.jcstress.annotations.JCStressTest;
+import org.openjdk.jcstress.annotations.State;
+import org.openjdk.jcstress.infra.results.IntResult2;
+import sun.misc.Contended;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class LazySetOrderTest {
+
+    @JCStressTest
+    @State
+    public static class Plain {
+
+        @Contended
+        private int x;
+        private int g;
+
+        @Actor
+        public void act1() {
+            x = 1;
+            g = 1;
+        }
+
+        @Actor
+        public void act2(IntResult2 r) {
+            r.r1 = g;
+            r.r2 = x;
+        }
+    }
+
+    @JCStressTest
+    @State
+    public static class Lazy {
+        @Contended
+        private int x;
+
+        private AtomicInteger g = new AtomicInteger();
+
+        @Actor
+        public void act1() {
+            x = 1;
+            g.lazySet(1);
+        }
+
+        @Actor
+        public void act2(IntResult2 r) {
+            r.r1 = g.get();
+            r.r2 = x;
+        }
+    }
+
+}
--- a/tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml	Wed May 07 17:11:41 2014 +0400
+++ b/tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml	Wed May 07 18:11:44 2014 +0400
@@ -128,4 +128,52 @@
         </unmatched>
     </test>
 
+    <test name="org.openjdk.jcstress.tests.scratch.LazySetOrderTest$Plain">
+        <contributed-by>Aleksey Shipilev</contributed-by>
+        <case>
+            <match>[0, 1]</match>
+            <match>[0, 0]</match>
+            <expect>ACCEPTABLE</expect>
+            <description>Seeing the unset $g, any value for $x is OK</description>
+        </case>
+        <case>
+            <match>[1, 1]</match>
+            <expect>ACCEPTABLE</expect>
+            <description>Seeing both updates.</description>
+        </case>
+        <case>
+            <match>[1, 0]</match>
+            <expect>ACCEPTABLE_INTERESTING</expect>
+            <description>Seeing the update to $g, but not to $x.</description>
+        </case>
+        <unmatched>
+            <expect>FORBIDDEN</expect>
+            <description>All other cases are unexpected and forbidden.</description>
+        </unmatched>
+    </test>
+
+    <test name="org.openjdk.jcstress.tests.scratch.LazySetOrderTest$Lazy">
+        <contributed-by>Aleksey Shipilev</contributed-by>
+        <case>
+            <match>[0, 1]</match>
+            <match>[0, 0]</match>
+            <expect>ACCEPTABLE</expect>
+            <description>Seeing the unset $g, any value for $x is OK</description>
+        </case>
+        <case>
+            <match>[1, 1]</match>
+            <expect>ACCEPTABLE</expect>
+            <description>Seeing both updates.</description>
+        </case>
+        <case>
+            <match>[1, 0]</match>
+            <expect>FORBIDDEN</expect>
+            <description>Seeing the update to $g, but not to $x.</description>
+        </case>
+        <unmatched>
+            <expect>FORBIDDEN</expect>
+            <description>All other cases are unexpected and forbidden.</description>
+        </unmatched>
+    </test>
+
 </testsuite>