changeset 1363:7a25c71b43bf

7901813: @AuxCounters method constraints conflict with @State ones Summary: Relax the requirement for "void" return type, implicitly allowing @Setup/@TearDown-s.
author shade
date Wed, 05 Oct 2016 19:21:18 +0200
parents 34407adf3d94
children d0821c7627fb
files jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/auxcounters/HelperConflictTest.java jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/auxcounters/counterTypes/publicMethods/VoidTest.java jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java
diffstat 4 files changed, 73 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/auxcounters/HelperConflictTest.java	Wed Oct 05 19:21:18 2016 +0200
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2016, Red Hat Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.ct.other.auxcounters;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.ct.CompileTest;
+
+public class HelperConflictTest {
+
+    @AuxCounters
+    @State(Scope.Thread)
+    public static class S {
+        @Setup(Level.Trial)
+        public void setupTrial() {}
+
+        @Setup(Level.Iteration)
+        public void setupIteration() {}
+
+        @Setup(Level.Invocation)
+        public void setupInvocation() {}
+
+        @TearDown(Level.Invocation)
+        public void tearDownInvocation() {}
+
+        @TearDown(Level.Iteration)
+        public void tearDownIteration() {}
+
+        @TearDown(Level.Trial)
+        public void tearDownTrial() {}
+    }
+
+    @Benchmark
+    public void benchmark(S s) {
+        // intentionally left blank
+    }
+
+    @Test
+    public void compileTest() {
+        CompileTest.assertOK(this.getClass());
+    }
+
+}
--- a/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/auxcounters/counterTypes/publicMethods/VoidTest.java	Fri Sep 30 16:20:46 2016 +0200
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/other/auxcounters/counterTypes/publicMethods/VoidTest.java	Wed Oct 05 19:21:18 2016 +0200
@@ -46,7 +46,7 @@
 
     @Test
     public void compileTest() {
-        CompileTest.assertFail(this.getClass(), "Illegal type for the return type of public method");
+        CompileTest.assertOK(this.getClass());
     }
 
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java	Fri Sep 30 16:20:46 2016 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/annotations/AuxCounters.java	Wed Oct 05 19:21:18 2016 +0200
@@ -51,7 +51,12 @@
  *
  *     <li>Only numeric fields and numeric-returning methods are considered as
  *     metrics. These include all primitives and their corresponding boxed counterTypes,
- *     except {@code boolean}/{@link Boolean} and {@code char}/{@link Character}</li>
+ *     except {@code boolean}/{@link Boolean} and {@code char}/{@link Character}.
+ *     It is a compile-time error to use the public field/method with incompatible type.</li>
+ *
+ *     <li>Methods with {@code void} return type are exempted from type checking.
+ *     This means helper {@link Setup} and {@link TearDown} methods are fine in
+ *     {@link AuxCounters}.</li>
  *
  *     <li>Public fields in {@link AuxCounters} instances would be reset before
  *     starting the iteration, and read back at the end of iteration. This allows
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Fri Sep 30 16:20:46 2016 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Wed Oct 05 19:21:18 2016 +0200
@@ -310,7 +310,7 @@
             }
 
             for (MethodInfo sub : ci.getMethods()) {
-                if (sub.isPublic()) {
+                if (sub.isPublic() && !sub.getReturnType().equals("void")) {
                     if (!isAuxCompatible(sub.getReturnType())) {
                         throw new GenerationException("Illegal type for the return type of public method in @" + AuxCounters.class.getSimpleName() + ".", sub);
                     }