changeset 366:f2c37dc9d086

Chapters 0.a, 1.a: Coherence tests for basic language and VarHandles.
author shade
date Thu, 23 Feb 2017 15:31:07 +0100
parents f4757f44c8b6
children 0400ed6dd6a6
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1aTestGenerator.java jcstress-test-gen/src/main/resources/coherence/X-ArrayCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-FieldCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-VarHandleArrayCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-VarHandleByteArrayViewCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-VarHandleDirectByteBufferViewCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-VarHandleFieldCoherenceTest.java.template jcstress-test-gen/src/main/resources/coherence/X-VarHandleHeapByteBufferViewCoherenceTest.java.template
diffstat 9 files changed, 534 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java	Thu Feb 23 11:12:53 2017 +0100
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java	Thu Feb 23 15:31:07 2017 +0100
@@ -118,6 +118,20 @@
                 "tearing.arrays.large",
                 new String[]{ "", "volatile" }
         );
+
+        makeTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-FieldCoherenceTest.java.template"),
+                "coherence.fields",
+                new String[]{ "", "volatile" }
+        );
+
+        makeTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-ArrayCoherenceTest.java.template"),
+                "coherence.arrays",
+                new String[]{ "", "volatile" }
+        );
     }
 
     private static void makeTests(String dest, String template, String label, String[] modifiers) throws IOException {
@@ -156,6 +170,9 @@
         if (alwaysAtomic(modifier, type, label)) {
             set.add("alwaysAtomic");
         }
+        if (coherent(modifier, type, label)) {
+            set.add("coherent");
+        }
         set.add(modifier);
         return set;
     }
@@ -165,6 +182,10 @@
                 !(type.equals("double") || type.equals("long"));
     }
 
+    private static boolean coherent(String modifier, String type, String label) {
+        return (modifier.equals("volatile") && !label.contains("array"));
+    }
+
     private static String testName(String type) {
         return StringUtils.upcaseFirst(type) + "Test";
     }
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1aTestGenerator.java	Thu Feb 23 11:12:53 2017 +0100
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1aTestGenerator.java	Thu Feb 23 15:31:07 2017 +0100
@@ -73,6 +73,36 @@
                 GeneratorUtils.readFromResource("/accessAtomic/X-VarHandleDirectByteBufferViewAtomicityTest.java.template"),
                 "accessAtomic.varHandles.byteBuffer.direct"
         );
+
+        makeTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-VarHandleFieldCoherenceTest.java.template"),
+                "coherence.varHandles.fields"
+        );
+
+        makeTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-VarHandleArrayCoherenceTest.java.template"),
+                "coherence.varHandles.arrays"
+        );
+
+        makeBufferTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-VarHandleByteArrayViewCoherenceTest.java.template"),
+                "coherence.varHandles.byteArray"
+        );
+
+        makeBufferTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-VarHandleHeapByteBufferViewCoherenceTest.java.template"),
+                "coherence.varHandles.byteBuffer.heap"
+        );
+
+        makeBufferTests(
+                dest,
+                GeneratorUtils.readFromResource("/coherence/X-VarHandleDirectByteBufferViewCoherenceTest.java.template"),
+                "coherence.varHandles.byteBuffer.direct"
+        );
     }
 
     private enum VarHandleMode {
@@ -170,6 +200,9 @@
         if (alwaysAtomic(type, mode)) {
             set.add("alwaysAtomic");
         }
+        if (coherent(type, mode)) {
+            set.add("coherent");
+        }
         return set;
     }
 
@@ -186,6 +219,19 @@
         }
     }
 
+    private static boolean coherent(String type, VarHandleMode mode) {
+        switch (mode) {
+            case NAKED:
+                return false;
+            case OPAQUE:
+            case ACQ_REL:
+            case VOLATILE:
+                return true;
+            default:
+                throw new IllegalStateException(mode.toString());
+        }
+    }
+
     private static String testName(String type) {
         return StringUtils.upcaseFirst(type) + "Test";
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-ArrayCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if arrays experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    $modifier$$type$[] a = new $type$[1];
+
+    @Actor
+    public void actor1() {
+        a[0] = $setLiteral$;
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = a[0];
+        r.r2 = a[0];
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-FieldCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if fields experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    $modifier$$type$ x;
+
+    @Actor
+    public void actor1() {
+        x = $setLiteral$;
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = x;
+        r.r2 = x;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-VarHandleArrayCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if array element accessors experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    static final VarHandle VH = MethodHandles.arrayElementVarHandle($type$[].class);
+
+    $type$[] xs = new $type$[1];
+
+    @Actor
+    public void actor1() {
+        VH.$setOp$(xs, 0, $setLiteral$);
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = ($type$)VH.$getOp$(xs, 0);
+        r.r2 = ($type$)VH.$getOp$(xs, 0);
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-VarHandleByteArrayViewCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if byte array views accessors experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
+    static final VarHandle VH = MethodHandles.byteArrayViewVarHandle($type$[].class, ByteOrder.$byteOrder$);
+
+    byte[] xs = new byte[OFF + 8];
+
+    @Actor
+    public void actor1() {
+        VH.$setOp$(xs, OFF, $setLiteral$);
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = ($type$)VH.$getOp$(xs, OFF);
+        r.r2 = ($type$)VH.$getOp$(xs, OFF);
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-VarHandleDirectByteBufferViewCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if byte array views accessors experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    static final VarHandle VH = MethodHandles.byteBufferViewVarHandle($type$[].class, ByteOrder.$byteOrder$);
+
+    ByteBuffer buf = ByteBuffer.allocateDirect(16);
+    int off = buf.alignmentOffset(0, 8);
+
+    @Actor
+    public void actor1() {
+        VH.$setOp$(buf, off, $setLiteral$);
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = ($type$)VH.$getOp$(buf, off);
+        r.r2 = ($type$)VH.$getOp$(buf, off);
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-VarHandleFieldCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if field accessors experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    $type$ x;
+
+    static final VarHandle VH;
+
+    static {
+        try {
+            VH = MethodHandles.lookup().findVarHandle($name$.class, "x", $type$.class);
+        } catch (NoSuchFieldException | IllegalAccessException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Actor
+    public void actor1() {
+        VH.$setOp$(this, $setLiteral$);
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = ($type$)VH.$getOp$(this);
+        r.r2 = ($type$)VH.$getOp$(this);
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-test-gen/src/main/resources/coherence/X-VarHandleHeapByteBufferViewCoherenceTest.java.template	Thu Feb 23 15:31:07 2017 +0100
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017, Red Hat Inc. 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 $package$;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.nio.ByteOrder;
+import java.nio.ByteBuffer;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.*;
+
+#warn
+
+/**
+ * Tests if byte array views accessors experience coherence failures.
+ */
+@JCStressTest
+@Outcome(id = "$default$, $default$", expect = Expect.ACCEPTABLE, desc = "Default value for the fields. Allowed to see this: data race.")
+@Outcome(id = "$default$, $set$", expect = Expect.ACCEPTABLE, desc = "Observe second read, but not first: sequential consistency.")
+@Outcome(id = "$set$, $set$", expect = Expect.ACCEPTABLE, desc = "Observers sees both read.")
+#if[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.FORBIDDEN, desc = "Seeing first read, but not second: coherence violation.")
+#else[coherent]
+@Outcome(id = "$set$, $default$", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Seeing first read, but not second: non-coherent.")
+#end[coherent]
+@State
+public class $name$ {
+
+    static final VarHandle VH = MethodHandles.byteBufferViewVarHandle($type$[].class, ByteOrder.$byteOrder$);
+
+    ByteBuffer buf = ByteBuffer.allocate(16);
+    int off = buf.alignmentOffset(0, 8);
+
+    @Actor
+    public void actor1() {
+        VH.$setOp$(buf, off, $setLiteral$);
+    }
+
+    @Actor
+    public void actor2($Type$Result2 r) {
+        r.r1 = ($type$)VH.$getOp$(buf, off);
+        r.r2 = ($type$)VH.$getOp$(buf, off);
+    }
+
+}
+