changeset 301:525dec23062a

Track @AuxCounters for each method in @Group individually.
author shade
date Thu, 05 Dec 2013 00:24:54 +0400
parents 83b404ab30db
children 9fcdbe9fd36c
files jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java
diffstat 3 files changed, 39 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java	Wed Dec 04 22:16:09 2013 +0400
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java	Thu Dec 05 00:24:54 2013 +0400
@@ -41,13 +41,13 @@
     @AuxCounters
     @State(Scope.Group)
     public static class GroupState {
-        public int x;
+        public int y;
     }
 
     @AuxCounters
     @State(Scope.Thread)
     public static class ThreadState {
-        public int x;
+        public int z;
     }
 
     @GenerateMicroBenchmark
@@ -66,4 +66,16 @@
 
     }
 
+    @GenerateMicroBenchmark
+    @Group("test_gt")
+    public void testGroupThread_1(GroupState gs, ThreadState ts) {
+
+    }
+
+    @GenerateMicroBenchmark
+    @Group("test_gt")
+    public void testGroupThread_2(GroupState gs, ThreadState ts) {
+
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Dec 04 22:16:09 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Thu Dec 05 00:24:54 2013 +0400
@@ -803,8 +803,8 @@
             if (!isSingleMethod) {
                 writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.SECONDARY, \"" + method.getSimpleName() + "\", res.getOperations(), res.getTime(), tu));");
             }
-            for (String ops : states.getAuxResultNames()) {
-                writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.SECONDARY, \"" + ops + "\", " + states.getAuxResultAccessor(ops) + ", res.getTime(), tu));");
+            for (String ops : states.getAuxResultNames(method)) {
+                writer.println(ident(3) + "results.add(new ThroughputResult(ResultRole.SECONDARY, \"" + ops + "\", " + states.getAuxResultAccessor(method, ops) + ", res.getTime(), tu));");
             }
             writer.println(ident(3) + "return results;");
             writer.println(ident(2) + "} else");
@@ -899,8 +899,8 @@
             if (!isSingleMethod) {
                 writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.SECONDARY, \"" + method.getSimpleName() + "\", res.getOperations(), res.getTime(), tu));");
             }
-            for (String ops : states.getAuxResultNames()) {
-                writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.SECONDARY, \"" + ops + "\", " + states.getAuxResultAccessor(ops) + ", res.getTime(), tu));");
+            for (String ops : states.getAuxResultNames(method)) {
+                writer.println(ident(3) + "results.add(new AverageTimeResult(ResultRole.SECONDARY, \"" + ops + "\", " + states.getAuxResultAccessor(method, ops) + ", res.getTime(), tu));");
             }
             writer.println(ident(3) + "return results;");
             writer.println(ident(2) + "} else");
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Wed Dec 04 22:16:09 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Thu Dec 05 00:24:54 2013 +0400
@@ -69,7 +69,7 @@
     private int collapsedIndex = 0;
 
     private final HashMap<String, String> jmhTypes = new HashMap<String, String>();
-    private final Set<String> auxNames = new HashSet<String>();
+    private final Multimap<String, String> auxNames = new HashMultimap<String, String>();
     private final Map<String, String> auxAccessors = new HashMap<String, String>();
 
     public StateObjectHandler(ProcessingEnvironment processingEnv) {
@@ -160,8 +160,14 @@
                     String fieldType = sub.asType().toString();
                     if (fieldType.equals("int") || fieldType.equals("long")) {
                         String name = sub.getSimpleName().toString();
-                        auxNames.add(name);
-                        auxAccessors.put(name, so.localIdentifier + "." + name);
+                        String meth = execMethod.getSimpleName().toString();
+                        auxNames.put(meth, name);
+                        String prev = auxAccessors.put(meth + name, so.localIdentifier + "." + name);
+                        if (prev != null) {
+                            throw new GenerationException("Conflicting @" + AuxCounters.class.getSimpleName() +
+                                " counters. Make sure there are no @" + State.class.getSimpleName() + "-s with the same counter " +
+                                " injected into this method.", element);
+                        }
                     }
                 }
 
@@ -169,8 +175,14 @@
                     String returnType = ((ExecutableElement) sub).getReturnType().toString();
                     if (returnType.equals("int") || returnType.equals("long")) {
                         String name = sub.getSimpleName().toString();
-                        auxNames.add(name);
-                        auxAccessors.put(name, so.localIdentifier + "." + name + "()");
+                        String meth = execMethod.getSimpleName().toString();
+                        auxNames.put(meth, name);
+                        String prev = auxAccessors.put(meth + name, so.localIdentifier + "." + name + "()");
+                        if (prev != null) {
+                            throw new GenerationException("Conflicting @" + AuxCounters.class.getSimpleName() +
+                                    " counters. Make sure there are no @" + State.class.getSimpleName() + "-s with the same counter " +
+                                    " injected into this method.", element);
+                        }
                     }
                 }
             }
@@ -540,12 +552,12 @@
         return s;
     }
 
-    public Collection<String> getAuxResultNames() {
-        return auxNames;
+    public Collection<String> getAuxResultNames(Element method) {
+        return auxNames.get(method.getSimpleName().toString());
     }
 
-    public String getAuxResultAccessor(String name) {
-        return auxAccessors.get(name);
+    public String getAuxResultAccessor(Element method, String name) {
+        return auxAccessors.get(method.getSimpleName().toString() + name);
     }
 
 }