changeset 297:2cb629dfc2be

Chapter 1.c: Further simplify Fences test generator.
author shade
date Fri, 10 Jun 2016 16:26:59 +0300
parents c47a1a95f97d
children 9dcd4ef5edf1
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1cTestGenerator.java jcstress-test-gen/src/main/resources/fences/X-LoadLoadFenceTest.java.template jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest2.java.template jcstress-test-gen/src/main/resources/fences/X-StoreLoadFenceTest.java.template jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest1.java.template jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest2.java.template
diffstat 8 files changed, 37 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1bTestGenerator.java	Fri Jun 10 16:26:59 2016 +0300
@@ -77,6 +77,8 @@
 import static org.openjdk.jcstress.chapters.GeneratorUtils.writeOut;
 
 public class Chapter1bTestGenerator {
+    private static final String BASE_PKG = "org.openjdk.jcstress.tests.atomicity.varHandles";
+
     public static void main(String[] args) throws Exception {
         if (args.length < 1) {
             throw new IllegalStateException("Need a destination argument");
@@ -681,6 +683,4 @@
             entry("X-WeakCASContendStrongTest", T_WEAKCAS)
     );
 
-    private static final String BASE_PKG = "org.openjdk.jcstress.tests.varHandles.atomicity";
-
 }
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1cTestGenerator.java	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter1cTestGenerator.java	Fri Jun 10 16:26:59 2016 +0300
@@ -31,10 +31,8 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 
-import static java.util.Map.entry;
 import static java.util.Set.of;
 import static org.openjdk.jcstress.chapters.Chapter1cTestGenerator.Method.*;
 import static org.openjdk.jcstress.chapters.Chapter1cTestGenerator.Target.Operation.*;
@@ -43,7 +41,8 @@
 
 public class Chapter1cTestGenerator {
 
-    public static final String[] TYPES = new String[]{"byte", "boolean", "char", "short", "int", "float", "long", "double", "String"};
+    private static final String BASE_PKG = "org.openjdk.jcstress.tests.fences.varHandles";
+    private static final String[] TYPES = new String[]{"byte", "boolean", "char", "short", "int", "float", "long", "double", "String"};
 
     public static void main(String[] args) throws Exception {
         if (args.length < 1) {
@@ -51,21 +50,17 @@
         }
         String dest = args[0];
 
-        for(Entry<String, Target> template : TEMPLATES.entrySet()) {
-            final String templateName = template.getKey();
-            final Target target = template.getValue();
-
+        for(Target target : Target.values()) {
+            final String templateName = target.template;
             makeFieldTests(dest, target, templateName,
                     readFromResource("/fences/" + templateName + ".java.template"));
-
         }
     }
 
     private static void makeFieldTests(String dest, Target target, String templateName, String template) throws IOException {
         for (String type : TYPES) {
             for (Operation operation : target.operations) {
-                String result = generateConcreteOperation(template, target.target, operation.operation,
-                        "field", "field = $1;");
+                String result = template.replaceAll(target.target, operation.operation);
 
                 String pkg = BASE_PKG + "." + templateName.replaceAll("^X-", "");
                 String testName = operation.method.name() + upcaseFirst(type);
@@ -78,14 +73,6 @@
         }
     }
 
-    private static String generateConcreteOperation(String result, String target, String concreteOp,
-            String getOp, String setOp) {
-        return result
-                .replaceAll(target, concreteOp)
-                .replaceAll("%GetVar%", getOp)
-                .replaceAll("%SetVar<(.+)>%", setOp);
-    }
-
     private static boolean alwaysAtomic(String type) {
         return !(type.equals("double") || type.equals("long"));
     }
@@ -124,88 +111,96 @@
 
     enum Target {
         T_GET_LOADLOADFENCE(
-                "%GetLoadLoadFence<>%",
+                "X-LoadLoadFenceTest",
+                "%GetLoadLoadFence%",
                 of(GET_ACQUIREFENCE, GET_LOADLOADFENCE, GET_FULLFENCE)
         ),
 
         T_LOADSTOREFENCE_SET(
-                "%LoadStoreFenceSet<(.+)>%",
+                "X-LoadStoreFenceTest1",
+                "%LoadStoreFenceSet%",
                 of(RELEASEFENCE_SET, FULLFENCE_SET)
         ),
 
         T_GET_LOADSTOREFENCE(
-                "%GetLoadStoreFence<>%",
+                "X-LoadStoreFenceTest2",
+                "%GetLoadStoreFence%",
                 of(GET_ACQUIREFENCE, GET_FULLFENCE)
         ),
 
         T_STORESTOREFENCE_SET(
-                "%StoreStoreFenceSet<(.+)>%",
+                "X-StoreStoreFenceTest1",
+                "%StoreStoreFenceSet%",
                 of(RELEASEFENCE_SET, STORESTOREFENCE_SET, FULLFENCE_SET)
         ),
 
         T_SET_STORESTOREFENCE(
-                "%SetStoreStoreFence<(.+)>%",
+                "X-StoreStoreFenceTest2",
+                "%SetStoreStoreFence%",
                 of(SET_RELEASEFENCE, SET_STORESTOREFENCE, SET_FULLFENCE)
         ),
 
         T_SET_STORELOADFENCE(
-                "%SetStoreLoadFence<(.+)>%",
+                "X-StoreLoadFenceTest",
+                "%SetStoreLoadFence%",
                 of(SET_FULLFENCE)
         ),
 
         ;
 
-        Target(String target, Set<Operation> operations) {
+        Target(String template, String target, Set<Operation> operations) {
+            this.template = template;
             this.target = target;
             this.operations = operations;
         }
 
+        String template;
         String target;
         Set<Operation> operations;
 
         enum Operation {
             GET_LOADLOADFENCE(
-                    "%GetVar%;" + LNSEP + "VarHandle.loadLoadFence();",
+                    "field;" + LNSEP + "VarHandle.loadLoadFence();",
                     LoadLoadFence
             ),
 
             STORESTOREFENCE_SET(
-                    "VarHandle.storeStoreFence();" + LNSEP + "%SetVar<$1>%",
+                    "VarHandle.storeStoreFence();" + LNSEP + "field = \\$valueLiteral1\\$;",
                     StoreStoreFence
             ),
 
             SET_STORESTOREFENCE(
-                    "%SetVar<$1>%" + LNSEP + "VarHandle.storeStoreFence();",
+                    "field = \\$valueLiteral1\\$;" + LNSEP + "VarHandle.storeStoreFence();",
                     StoreStoreFence
             ),
 
             GET_ACQUIREFENCE(
-                    "%GetVar%;" + LNSEP + "VarHandle.acquireFence();",
+                    "field;" + LNSEP + "VarHandle.acquireFence();",
                     AcquireFence
             ),
 
             RELEASEFENCE_SET(
-                    "VarHandle.releaseFence();" + LNSEP + "%SetVar<$1>%",
+                    "VarHandle.releaseFence();" + LNSEP + "field = \\$valueLiteral1\\$;",
                     ReleaseFence
             ),
 
             SET_RELEASEFENCE(
-                    "%SetVar<$1>%" + LNSEP + "VarHandle.releaseFence();",
+                    "field = \\$valueLiteral1\\$;" + LNSEP + "VarHandle.releaseFence();",
                     ReleaseFence
             ),
 
             SET_FULLFENCE(
-                    "%SetVar<$1>%" + LNSEP + "VarHandle.fullFence();",
+                    "field = \\$valueLiteral1\\$;" + LNSEP + "VarHandle.fullFence();",
                     FullFence
             ),
 
             FULLFENCE_SET(
-                    "VarHandle.fullFence();" + LNSEP + "%SetVar<$1>%",
+                    "VarHandle.fullFence();" + LNSEP + "field = \\$valueLiteral1\\$;",
                     FullFence
             ),
 
             GET_FULLFENCE(
-                    "%GetVar%;" + LNSEP + "VarHandle.fullFence();",
+                    "field;" + LNSEP + "VarHandle.fullFence();",
                     FullFence
             ),
 
@@ -221,16 +216,4 @@
         }
     }
 
-    private static final Map<String, Target> TEMPLATES = Map.ofEntries(
-            entry("X-LoadLoadFenceTest",    T_GET_LOADLOADFENCE),
-            entry("X-LoadStoreFenceTest1",  T_LOADSTOREFENCE_SET),
-            entry("X-LoadStoreFenceTest2",  T_GET_LOADSTOREFENCE),
-            entry("X-StoreLoadFenceTest",   T_SET_STORELOADFENCE),
-            entry("X-StoreStoreFenceTest1", T_STORESTOREFENCE_SET),
-            entry("X-StoreStoreFenceTest2", T_SET_STORESTOREFENCE)
-    );
-
-
-    private static final String BASE_PKG = "org.openjdk.jcstress.tests.varHandles.fences";
-
 }
--- a/jcstress-test-gen/src/main/resources/fences/X-LoadLoadFenceTest.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-LoadLoadFenceTest.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -58,7 +58,7 @@
 
     @Actor
     public void actor2($Type$Result2 r) {
-        r.r1 = %GetLoadLoadFence<>%
+        r.r1 = %GetLoadLoadFence%
         r.r2 = x;
     }
 
--- a/jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest1.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest1.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -51,7 +51,7 @@
     @Actor
     public void actor1($Type$Result2 r) {
         $type$ i = x;
-        %LoadStoreFenceSet<$valueLiteral1$>%
+        %LoadStoreFenceSet%
         r.r2 = i;
     }
 
--- a/jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest2.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-LoadStoreFenceTest2.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -50,7 +50,7 @@
 
     @Actor
     public void actor1($Type$Result2 r) {
-        $type$ i = %GetLoadStoreFence<>%
+        $type$ i = %GetLoadStoreFence%
         y = $valueLiteral1$;
         r.r2 = i;
     }
--- a/jcstress-test-gen/src/main/resources/fences/X-StoreLoadFenceTest.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-StoreLoadFenceTest.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -53,7 +53,7 @@
 
     @Actor
     public void actor1($Type$Result2 r) {
-        %SetStoreLoadFence<$valueLiteral1$>%
+        %SetStoreLoadFence%
         r.r1 = x;
     }
 
--- a/jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest1.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest1.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -53,7 +53,7 @@
     @Actor
     public void actor1() {
         x = $valueLiteral1$;
-        %StoreStoreFenceSet<$valueLiteral1$>%
+        %StoreStoreFenceSet%
     }
 
     @Actor
--- a/jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest2.java.template	Fri Jun 10 15:36:00 2016 +0300
+++ b/jcstress-test-gen/src/main/resources/fences/X-StoreStoreFenceTest2.java.template	Fri Jun 10 16:26:59 2016 +0300
@@ -52,7 +52,7 @@
 
     @Actor
     public void actor1() {
-        %SetStoreStoreFence<$valueLiteral1$>%
+        %SetStoreStoreFence%
         y = $valueLiteral1$;
     }