changeset 302:9fcdbe9fd36c

Restrict @AuxCounters to @State(Thread).
author shade
date Thu, 05 Dec 2013 00:36:22 +0400
parents 525dec23062a
children 501b2f7a4ca2
files jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java
diffstat 3 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java	Thu Dec 05 00:24:54 2013 +0400
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/compile/AuxCountersTest.java	Thu Dec 05 00:36:22 2013 +0400
@@ -32,13 +32,11 @@
 
 public class AuxCountersTest {
 
-    @AuxCounters
     @State(Scope.Benchmark)
     public static class BenchmarkState {
         public int x;
     }
 
-    @AuxCounters
     @State(Scope.Group)
     public static class GroupState {
         public int y;
@@ -51,17 +49,6 @@
     }
 
     @GenerateMicroBenchmark
-    public void testBenchmark(BenchmarkState s) {
-
-    }
-
-    @GenerateMicroBenchmark
-    @Group("test")
-    public void testGroup(GroupState s) {
-
-    }
-
-    @GenerateMicroBenchmark
     public void testThread(ThreadState s) {
 
     }
@@ -78,4 +65,9 @@
 
     }
 
+    @GenerateMicroBenchmark
+    public void testBenchThread(BenchmarkState bs, ThreadState ts) {
+
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java	Thu Dec 05 00:24:54 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java	Thu Dec 05 00:36:22 2013 +0400
@@ -34,6 +34,9 @@
  * {int, long} values, and treat their values as the operation counts in current
  * iteration.
  * <p>
+ * Currently allowed only at {@link Scope#Thread} level, because JMH metric
+ * aggregator expects the distinct counters coming from every measurement thread.
+ * <p>
  * NOTE: You have to explicitly reset the state if you don't want the counters
  * to be shared across the iterations.
  * <p>
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Thu Dec 05 00:24:54 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Thu Dec 05 00:36:22 2013 +0400
@@ -155,6 +155,11 @@
 
         // auxiliary result, produce the accessors
         if (element.getAnnotation(AuxCounters.class) != null) {
+            if (scope != Scope.Thread) {
+                throw new GenerationException("@" + AuxCounters.class.getSimpleName() +
+                        " can only be used with " + Scope.class.getSimpleName() + "." + Scope.Thread + " states.", element);
+            }
+
             for (Element sub : element.getEnclosedElements()) {
                 if (sub.getKind() == ElementKind.FIELD && sub.getModifiers().contains(Modifier.PUBLIC)) {
                     String fieldType = sub.asType().toString();