changeset 291:354504c9a1c6

Chapter 1.b: Ditch Begin/End/Random array tests to shrink down complexity.
author shade
date Thu, 09 Jun 2016 21:41:43 +0300
parents e3d57d660c2b
children 1be98bc60f39
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java jcstress-test-gen/src/main/resources/chapter1b/arrays/AddAndGetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/CAETest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/CASTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndAddTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndSetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTestWeak.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2Weak.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASContendStrongTest.java.template jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/AddAndGetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/CAETest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/CASTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndAddTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndSetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTestWeak.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2Weak.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASContendStrongTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/AddAndGetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CAETest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CASTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndAddTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndSetTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTestWeak.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2Weak.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASContendStrongTest.java.template jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASTest.java.template
diffstat 46 files changed, 286 insertions(+), 445 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java	Thu Jun 09 21:41:43 2016 +0300
@@ -201,8 +201,10 @@
                 String pkg = BASE_PKG + "." + vhType + "." + templateName;
                 String testName = operation.method.name() + upcaseFirst(type.type);
 
-                result = Spp.spp(result, keys(type), vars(type, "this", pkg, testName));
-                writer.write(pkg, testName, result);
+                writer.write(pkg, testName, Spp.spp(result,
+                        keys(type),
+                        fieldVars(type, "this", pkg, testName)
+                ));
             }
         }
     }
@@ -215,23 +217,15 @@
                     break;
 
                 String result = generateConcreteOperation(template, target.target, operation.operation,
-                        "array[\\$index\\$]", "array[\\$index\\$] = $1;");
+                        "array[0]", "array[0] = $1;");
 
                 String pkg = BASE_PKG + "." + vhType + "." + templateName;
                 String testName = operation.method.name() + upcaseFirst(type.type);
-                int length = getArrayLength(type);
 
-                String currentResult = Spp.spp(result, keys(type),
-                        arrayVars(type, "array", pkg, testName + "Begin", String.valueOf(length), "0", ", 0"));
-                writer.write(pkg, testName + "Begin", currentResult);
-
-                currentResult = Spp.spp(result, keys(type),
-                        arrayVars(type, "array", pkg, testName + "End", String.valueOf(length), String.valueOf(length - 1), ", " + String.valueOf(length - 1)));
-                writer.write(pkg, testName + "End", currentResult);
-
-                currentResult = Spp.spp(result, keys(type),
-                        arrayVars(type, "array", pkg, testName + "Random", String.valueOf(length), "random", ", random"));
-                writer.write(pkg, testName + "Random", currentResult);
+                writer.write(pkg, testName, Spp.spp(result,
+                        keys(type),
+                        arrayVars(type, "array", pkg, testName)
+                ));
             }
         }
     }
@@ -250,22 +244,11 @@
 
                 String pkg = BASE_PKG + "." + vhType + bufferType.pkgAppendix() + "." + templateName;
                 String testName = operation.method.name() + upcaseFirst(type.type);
-                int length = getArrayLength(type);
 
-                String currentResult = Spp.spp(result, keys(type),
-                        viewVars(type, object, pkg, testName + "Begin", String.valueOf(length), "off",
-                                ", off", String.valueOf(type.sizeInArray), bufferType.allocateOp));
-                writer.write(pkg, testName + "Begin", currentResult);
-
-                currentResult = Spp.spp(result, keys(type),
-                        viewVars(type, object, pkg, testName + "End", String.valueOf(length), "end", ", end",
-                                String.valueOf(type.sizeInArray), bufferType.allocateOp));
-                writer.write(pkg, testName + "End", currentResult);
-
-                currentResult = Spp.spp(result,keys(type),
-                        viewVars(type, object, pkg, testName + "Random", String.valueOf(length), "random",
-                                ", random", String.valueOf(type.sizeInArray), bufferType.allocateOp));
-                writer.write(pkg, testName + "Random", currentResult);
+                writer.write(pkg, testName, Spp.spp(result,
+                        keys(type),
+                        viewVars(type, object, pkg, testName, bufferType.allocateOp)
+                ));
             }
         }
     }
@@ -285,7 +268,7 @@
             return of();
     }
 
-    private static Map<String, String> vars(Type type, String object, String pkg, String testName) {
+    private static Map<String, String> commonVars(Type type, String object, String pkg, String testName) {
         Map<String, String> map = new HashMap<>();
         map.put("type", type.type);
         map.put("Type", upcaseFirst(type.type));
@@ -298,38 +281,30 @@
             map.put("valueLiteral" + i, type.valueLiterals[i]);
         }
 
-        map.put("index", "");
-        map.put("index_para", "");
-
         return map;
     }
 
-    private static Map<String, String> arrayVars(Type type, String object, String pkg, String testName,
-            String length, String index, String indexPara) {
-        Map<String, String> map = vars(type, object, pkg, testName);
-        map.put("length", length);
-        map.put("index", index);
-        map.put("index_para", indexPara);
+    private static Map<String, String> fieldVars(Type type, String object, String pkg, String testName) {
+        Map<String, String> map = commonVars(type, object, pkg, testName);
+        map.put("index_para", "");
+        return map;
+    }
 
+    private static Map<String, String> arrayVars(Type type, String object, String pkg, String testName) {
+        Map<String, String> map = commonVars(type, object, pkg, testName);
+        map.put("index_para", ", 0");
         return map;
     }
 
     private static Map<String, String> viewVars(Type type, String object, String pkg, String testName,
-            String length, String index, String indexPara, String unitSize, String bufferAllocateOp) {
-        Map<String, String> map = arrayVars(type, object, pkg, testName, length, index, indexPara);
-        map.put("unit_size", unitSize);
+            String bufferAllocateOp) {
+        Map<String, String> map = commonVars(type, object, pkg, testName);
+        map.put("index_para", ", 0");
+        map.put("unit_size", String.valueOf(type.sizeInArray));
         map.put("buffer_allocate", bufferAllocateOp);
-
         return map;
     }
 
-    private static int getArrayLength(Type type) {
-        final int TOTAL_BYTES = 256; // to ensure 2 cache lines. If it's array
-                                     // and type is String, the real total bytes
-                                     // may be 512
-        return TOTAL_BYTES / type.sizeInArray;
-    }
-
     @FunctionalInterface
     private interface FileWriter {
         void write(String pkg, String testName, String result) throws IOException;
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/AddAndGetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/AddAndGetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,9 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -61,20 +59,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/CAETest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/CAETest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,9 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -76,7 +74,7 @@
 
     @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/CASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/CASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,9 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -63,20 +61,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %CAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndAddTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndAddTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,9 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -61,20 +59,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndSetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/GetAndSetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -49,9 +49,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -62,20 +60,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndSet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndSet<$valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -57,10 +57,8 @@
 public class $TestClassName$ {
 
     $type$ x;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -71,13 +69,13 @@
             throw new RuntimeException(e);
         }
     }
-    
-    
+
+
     @Actor
     public void actor1() {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        array[$index$] = $valueLiteral1$;
+        array[0] = $valueLiteral1$;
     }
 
     @Actor
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -55,10 +55,8 @@
 public class $TestClassName$ {
 
     $type$ x;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -70,17 +68,17 @@
         }
     }
 
-    
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = x;
         %LoadStoreFenceSet<$valueLiteral1$>%
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = array[$index$];
+        r.r1 = array[0];
         x = r.r1;
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/LoadStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -55,10 +55,8 @@
 public class $TestClassName$ {
 
     $type$ y;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -70,17 +68,17 @@
         }
     }
 
-    
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = %GetLoadStoreFence<>%
         y = $valueLiteral1$;
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         r.r1 = y;
-        array[$index$] = r.r1;
+        array[0] = r.r1;
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -59,10 +59,8 @@
 public class $TestClassName$ {
 
     $type$ x;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -73,17 +71,17 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1($Type$Result2 r) {
         %SetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = array[$index$];
+        r.r2 = array[0];
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTestWeak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreLoadFenceTestWeak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -66,10 +66,8 @@
 public class $TestClassName$ {
 
     $type$ x;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -80,18 +78,18 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = array[$index$];
+        r.r2 = array[0];
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -57,10 +57,8 @@
 public class $TestClassName$ {
 
     $type$ x;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -81,7 +79,7 @@
 
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = array[$index$];
+        r.r1 = array[0];
         VarHandle.fullFence();
         r.r2 = x;
     }
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -57,10 +57,8 @@
 public class $TestClassName$ {
 
     $type$ y;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -83,7 +81,7 @@
     public void actor2($Type$Result2 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = array[$index$];
+        r.r2 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -64,10 +64,8 @@
 public class $TestClassName$ {
 
     $type$ y;
-    
-    $type$[] array = new $type$[$length$];
 
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -84,7 +82,6 @@
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreStoreFence<$valueLiteral1$>%
         y = $valueLiteral1$;
-        
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
 
@@ -92,7 +89,7 @@
     public void actor2($Type$Result3 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = array[$index$];
+        r.r2 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASContendStrongTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASContendStrongTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,9 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -63,20 +61,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CompareAndSet<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/arrays/WeakCASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,9 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$[] array = new $type$[$length$];
-
-    static final int random = new Random().nextInt($length$ - 2) + 1;
+    $type$[] array = new $type$[1];
 
     static final VarHandle vh;
 
@@ -63,20 +61,20 @@
             throw new RuntimeException(e);
         }
     }
-    
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %WeakCAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = array[$index$];
+        r.r3 = array[0];
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/AddAndGetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/AddAndGetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,12 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -64,20 +59,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/CAETest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/CAETest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = %CAE<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = %CAE<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/CASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/CASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %CAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndAddTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndAddTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,12 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -64,20 +59,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndSetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/GetAndSetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -49,12 +49,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -65,20 +60,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndSet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndSet<$valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -74,13 +67,16 @@
             throw new RuntimeException(e);
         }
     }
-    
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ x;
+
     @Actor
     public void actor1() {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        vh.set(byteArray$index_para$, $valueLiteral1$);
+        vh.set(byteArray, OFF, $valueLiteral1$);
     }
 
     @Actor
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -54,14 +54,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -73,17 +66,20 @@
         }
     }
 
-    
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = x;
         %LoadStoreFenceSet<$valueLiteral1$>%
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = ($type$) vh.get(byteArray$index_para$);
+        r.r1 = ($type$) vh.get(byteArray, OFF);
         x = r.r1;
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/LoadStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -54,14 +54,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -73,17 +66,20 @@
         }
     }
 
-    
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ y;
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = %GetLoadStoreFence<>%
         y = $valueLiteral1$;
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         r.r1 = y;
-        vh.set(byteArray$index_para$, r.r1);
+        vh.set(byteArray, OFF, r.r1);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -58,14 +58,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -76,17 +69,21 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result2 r) {
         %SetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteArray$index_para$);
+        r.r2 = ($type$) vh.get(byteArray, OFF);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTestWeak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreLoadFenceTestWeak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -65,14 +65,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -83,18 +76,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteArray$index_para$);
+        r.r2 = ($type$) vh.get(byteArray, OFF);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -75,6 +68,9 @@
         }
     }
 
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ x;
 
     @Actor
     public void actor1() {
@@ -84,7 +80,7 @@
 
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = ($type$) vh.get(byteArray$index_para$);
+        r.r1 = ($type$) vh.get(byteArray, OFF);
         VarHandle.fullFence();
         r.r2 = x;
     }
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -75,6 +68,9 @@
         }
     }
 
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ y;
 
     @Actor
     public void actor1() {
@@ -86,7 +82,7 @@
     public void actor2($Type$Result2 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteArray$index_para$);
+        r.r2 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -63,14 +63,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -82,12 +75,14 @@
         }
     }
 
+    byte[] byteArray = new byte[OFF + 8];
+
+    $type$ y;
 
     @Actor
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreStoreFence<$valueLiteral1$>%
         y = $valueLiteral1$;
-        
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
 
@@ -95,7 +90,7 @@
     public void actor2($Type$Result3 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteArray$index_para$);
+        r.r2 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASContendStrongTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASContendStrongTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CompareAndSet<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteArray/WeakCASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-    
-    byte[] byteArray = new byte[$length$ * $unit_size$];
-    int off = ByteBuffer.wrap(byteArray).alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    byte[] byteArray = new byte[OFF + 8];
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %WeakCAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteArray$index_para$);
+        r.r3 = ($type$) vh.get(byteArray, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/AddAndGetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/AddAndGetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,12 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -64,20 +59,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %AddAndGet<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CAETest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CAETest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = %CAE<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = %CAE<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/CASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %CAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndAddTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndAddTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -48,12 +48,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -64,20 +59,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndAdd<$valueLiteral1$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndSetTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/GetAndSetTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -49,12 +49,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -65,20 +60,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1($Type$Result3 r) {
         r.r1 = ($type$) %GetAndSet<$valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         r.r2 = ($type$) %GetAndSet<$valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1($Type$Result3 r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -74,12 +67,16 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ x;
+
     @Actor
     public void actor1() {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        vh.set(byteBuffer$index_para$, $valueLiteral1$);
+        vh.set(byteBuffer, OFF, $valueLiteral1$);
     }
 
     @Actor
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -54,14 +54,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -73,17 +66,20 @@
         }
     }
 
-    
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = x;
         %LoadStoreFenceSet<$valueLiteral1$>%
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r1 = ($type$) vh.get(byteBuffer, OFF);
         x = r.r1;
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/LoadStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -54,14 +54,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -73,17 +66,20 @@
         }
     }
 
-    
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ y;
+
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = %GetLoadStoreFence<>%
         y = $valueLiteral1$;
         r.r2 = i;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         r.r1 = y;
-        vh.set(byteBuffer$index_para$, r.r1);
+        vh.set(byteBuffer, OFF, r.r1);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -58,14 +58,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -76,17 +69,21 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result2 r) {
         %SetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
     }
-    
+
     @Actor
     public void actor2($Type$Result2 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r2 = ($type$) vh.get(byteBuffer, OFF);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTestWeak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreLoadFenceTestWeak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -65,14 +65,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -83,18 +76,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ x;
+
     @Actor
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreLoadFence<$valueLiteral1$>%
         r.r1 = x;
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
-    
+
     @Actor
     public void actor2($Type$Result3 r) {
         x = $valueLiteral1$;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r2 = ($type$) vh.get(byteBuffer, OFF);
     }
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest1.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest1.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ x;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -75,6 +68,9 @@
         }
     }
 
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ x;
 
     @Actor
     public void actor1() {
@@ -84,7 +80,7 @@
 
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r1 = ($type$) vh.get(byteBuffer, OFF);
         VarHandle.fullFence();
         r.r2 = x;
     }
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -56,14 +56,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -75,6 +68,9 @@
         }
     }
 
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ y;
 
     @Actor
     public void actor1() {
@@ -86,7 +82,7 @@
     public void actor2($Type$Result2 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r2 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/StoreStoreFenceTest2Weak.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -63,14 +63,7 @@
 @State
 public class $TestClassName$ {
 
-    $type$ y;
-    
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -82,12 +75,14 @@
         }
     }
 
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
+    $type$ y;
 
     @Actor
     public void actor1($Type$Result3 r) {
         boolean result = %WeakSetStoreStoreFence<$valueLiteral1$>%
         y = $valueLiteral1$;
-        
         r.r3 = result ? $valueLiteral1$ : $valueLiteral0$;
     }
 
@@ -95,7 +90,7 @@
     public void actor2($Type$Result3 r) {
         r.r1 = y;
         VarHandle.fullFence();
-        r.r2 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r2 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASContendStrongTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASContendStrongTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %CompareAndSet<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file
--- a/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASTest.java.template	Thu Jun 09 18:27:08 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/chapter1b/byteBuffer/WeakCASTest.java.template	Thu Jun 09 21:41:43 2016 +0300
@@ -50,12 +50,7 @@
 @State
 public class $TestClassName$ {
 
-    static final int unaligned_rand = (new Random().nextInt($length$ - 3) + 1) * $unit_size$;
-
-    ByteBuffer byteBuffer = $buffer_allocate$($length$ * $unit_size$);
-    int off = byteBuffer.alignmentOffset(0, $unit_size$);
-    int end = off == 0 ? ($length$ - 1) * $unit_size$ : ($length$ - 1) * $unit_size$ - off;
-    int random = off == 0 ? unaligned_rand + $unit_size$ : unaligned_rand + off;
+    static final int OFF = ByteBuffer.wrap(new byte[128]).alignmentOffset(0, 8);
 
     static final VarHandle vh;
 
@@ -66,20 +61,22 @@
             throw new RuntimeException(e);
         }
     }
-    
+
+    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);
+
     @Actor
     public void actor1(Bool2$Type$Result r) {
         r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%
     }
-    
+
     @Actor
     public void actor2(Bool2$Type$Result r) {
         r.r2 = %WeakCAS<$valueLiteral0$, $valueLiteral2$>%
     }
 
-    @Arbiter 
+    @Arbiter
     public void arbiter1(Bool2$Type$Result r) {
-        r.r3 = ($type$) vh.get(byteBuffer$index_para$);
+        r.r3 = ($type$) vh.get(byteBuffer, OFF);
     }
 
 }
\ No newline at end of file