changeset 267:e3e46feae474

Chapters 0.b/c: cleanup generator a bit.
author shade
date Fri, 20 May 2016 01:15:37 +0300
parents 73e599b8d13c
children 8cd6d3079aab
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/Op.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java
diffstat 2 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/Op.java	Fri May 20 01:11:51 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/Op.java	Fri May 20 01:15:37 2016 +0300
@@ -60,6 +60,14 @@
         return type;
     }
 
+    public boolean isLoad() {
+        return type == Type.LOAD;
+    }
+
+    public boolean isStore() {
+        return type == Type.STORE;
+    }
+
     public int getVarId() {
         return varId;
     }
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Fri May 20 01:11:51 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Fri May 20 01:15:37 2016 +0300
@@ -394,14 +394,14 @@
 
         public boolean hasLoads() {
             for (Op op : ops) {
-                if (op.getType() == Op.Type.LOAD) return true;
+                if (op.isLoad()) return true;
             }
             return false;
         }
 
         public boolean hasStores() {
             for (Op op : ops) {
-                if (op.getType() == Op.Type.STORE) return true;
+                if (op.isStore()) return true;
             }
             return false;
         }
@@ -409,7 +409,7 @@
         public int loadCount() {
             int count = 0;
             for (Op op : ops) {
-                if (op.getType() == Op.Type.LOAD) count++;
+                if (op.isLoad()) count++;
             }
             return count;
         }
@@ -417,7 +417,7 @@
         public int storeCount() {
             int count = 0;
             for (Op op : ops) {
-                if (op.getType() == Op.Type.STORE) count++;
+                if (op.isStore()) count++;
             }
             return count;
         }
@@ -491,11 +491,13 @@
             Set<Integer> loads = new HashSet<>();
             Set<Integer> stores = new HashSet<>();
             for (Op op : ops) {
-                if (op.getType() == Op.Type.STORE) {
-                    stores.add(op.getVarId());
-                }
-                if (op.getType() == Op.Type.LOAD) {
-                    loads.add(op.getVarId());
+                switch (op.getType()) {
+                    case STORE:
+                        stores.add(op.getVarId());
+                        break;
+                    case LOAD:
+                        loads.add(op.getVarId());
+                        break;
                 }
             }
 
@@ -660,7 +662,7 @@
         public Set<Result> allResults() {
             return threads.stream()
                     .flatMap(t -> t.ops.stream())
-                    .filter(op -> op.getType() == Op.Type.LOAD)
+                    .filter(Op::isLoad)
                     .map(Op::getResult)
                     .collect(Collectors.toSet());
         }
@@ -668,7 +670,7 @@
         public Set<Value> allValues() {
             return threads.stream()
                     .flatMap(t -> t.ops.stream())
-                    .filter(op -> op.getType() == Op.Type.STORE)
+                    .filter(Op::isStore)
                     .map(Op::getValue)
                     .collect(Collectors.toSet());
         }