changeset 77:be430c14ada0

Phase out @Microbenchmark as the supported interface completely.
author shade
date Tue, 04 Jun 2013 14:04:46 +0400
parents 9965f7887601
children 9d9133e41e4c
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandlers.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/MicroBenchmarkParametersFactory.java jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestOptions.java
diffstat 7 files changed, 20 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Jun 04 14:04:46 2013 +0400
@@ -412,7 +412,6 @@
         writer.println("import " + SampleTimePerOp.class.getName() + ';');
         writer.println("import " + SingleShotTime.class.getName() + ';');
         writer.println("import " + SampleBuffer.class.getName() + ';');
-        writer.println("import " + MicroBenchmark.class.getName() + ';');
         writer.println("import " + Mode.class.getName() + ';');
         writer.println("import " + Fork.class.getName() + ';');
         writer.println("import " + Measurement.class.getName() + ';');
@@ -671,15 +670,6 @@
         return null;
     }
 
-    private static String generateMBAnnotation(Mode kind) {
-        StringBuilder sb = new StringBuilder();
-        sb.append("@").append(MicroBenchmark.class.getSimpleName());
-        if (kind != Mode.Throughput) {
-            sb.append("(Mode.").append(kind).append(')');
-        }
-        return sb.toString();
-    }
-
     private List<String> generateMethodAnnotations(Mode kind, MethodGroup methodGroup) {
         int totalThreads = 0;
         String warmupAnn = null;
@@ -694,7 +684,6 @@
         }
 
         List<String> annotations = new ArrayList<String>();
-        annotations.add(generateMBAnnotation(kind));
         annotations.add("@" + Threads.class.getSimpleName() + "(" + totalThreads + ")");
         annotations = CollectionUtils.addIfNotNull(annotations, warmupAnn);
         annotations = CollectionUtils.addIfNotNull(annotations, measurementAnn);
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Tue Jun 04 14:04:46 2013 +0400
@@ -70,7 +70,7 @@
             Class<?> clazz = ClassUtils.loadClass(benchmark.generatedClass());
             Method method = MicroBenchmarkHandlers.findBenchmarkMethod(clazz, benchmark.generatedMethod());
 
-            MicroBenchmarkParameters executionParams = MicroBenchmarkParametersFactory.makeParams(options, method);
+            MicroBenchmarkParameters executionParams = MicroBenchmarkParametersFactory.makeParams(options, benchmark, method);
             MicroBenchmarkHandler handler = MicroBenchmarkHandlers.getInstance(outputHandler, benchmark, clazz, method, executionParams, options);
 
             outputHandler.startBenchmark(handler.getBenchmark(), executionParams, this.options.isVerbose());
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkRecord.java	Tue Jun 04 14:04:46 2013 +0400
@@ -34,7 +34,7 @@
     private final String generatedName;
     private Mode mode;
 
-    private BenchmarkRecord(String userName, String generatedName, Mode mode) {
+    public BenchmarkRecord(String userName, String generatedName, Mode mode) {
         this.userName = userName;
         this.generatedName = generatedName;
         this.mode = mode;
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandlers.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/MicroBenchmarkHandlers.java	Tue Jun 04 14:04:46 2013 +0400
@@ -52,7 +52,7 @@
     public static Method findBenchmarkMethod(Class<?> clazz, String methodName) {
         Method method = null;
         for (Method m : ClassUtils.enumerateMethods(clazz)) {
-            if (m.getName().equals(methodName) && (m.getAnnotation(MicroBenchmark.class) != null)) {
+            if (m.getName().equals(methodName)) {
                 if (isValidBenchmarkSignature(m)) {
                     if (method != null) {
                         throw new IllegalArgumentException("Ambiguous methods: \n" + method + "\n and \n" + m + "\n, which one to execute?");
@@ -70,8 +70,7 @@
     }
 
     public static MicroBenchmarkHandler getInstance(OutputFormat outputHandler, BenchmarkRecord microbenchmark, Class<?> clazz, Method method, MicroBenchmarkParameters executionParams, BaseOptions options) {
-        MicroBenchmark mb = method.getAnnotation(MicroBenchmark.class);
-        if(mb.value() == Mode.SingleShotTime) {
+        if(microbenchmark.getMode() == Mode.SingleShotTime) {
             return new ShotMicroBenchmarkHandler(outputHandler, microbenchmark, clazz, method, options, executionParams);
         } else {
             return new LoopMicroBenchmarkHandler(outputHandler, microbenchmark, clazz, method, options, executionParams);
@@ -85,10 +84,6 @@
      * @return
      */
     private static boolean isValidBenchmarkSignature(Method m) {
-        MicroBenchmark mb = m.getAnnotation(MicroBenchmark.class);
-        if (mb == null) {
-            return false;
-        }
         if (m.getReturnType() != Result.class) {
             return false;
         }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Tue Jun 04 14:04:46 2013 +0400
@@ -435,7 +435,7 @@
             Class<?> clazz = ClassUtils.loadClass(className);
             Method method = MicroBenchmarkHandlers.findBenchmarkMethod(clazz, methodName);
 
-            MicroBenchmarkParameters executionParams = MicroBenchmarkParametersFactory.makeParams(options, method);
+            MicroBenchmarkParameters executionParams = MicroBenchmarkParametersFactory.makeParams(options, benchmark, method);
             MicroBenchmarkHandler handler = MicroBenchmarkHandlers.getInstance(outputHandler, benchmark, clazz, method, executionParams, options);
             if (warmup) {
                 executionParams = executionParams.warmupToIteration();
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/MicroBenchmarkParametersFactory.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/MicroBenchmarkParametersFactory.java	Tue Jun 04 14:04:46 2013 +0400
@@ -29,6 +29,7 @@
 import org.openjdk.jmh.annotations.MicroBenchmark;
 import org.openjdk.jmh.annotations.Threads;
 import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.options.BaseOptions;
 
 import java.io.Serializable;
@@ -43,10 +44,10 @@
     private MicroBenchmarkParametersFactory() {
     }
 
-    public static MicroBenchmarkParameters makeParams(BaseOptions options, Method method) {
+    public static MicroBenchmarkParameters makeParams(BaseOptions options, BenchmarkRecord benchmark, Method method) {
         boolean shouldSynchIterations = getBoolean(options.getSynchIterations(), Defaults.SHOULD_SYNCH_ITERATIONS);
-        IterationParams measurement = getMeasurement(options, method);
-        IterationParams warmup = getWarmup(options, method);
+        IterationParams measurement = getMeasurement(options, benchmark, method);
+        IterationParams warmup = getWarmup(options, benchmark, method);
 
         List<Integer> threadCount = options.getThreadCounts();
         if (!threadCount.isEmpty()) {
@@ -85,8 +86,8 @@
         }
     }
 
-    private static IterationParams getWarmup(BaseOptions options, Method method) {
-        boolean isSingleShot = method.getAnnotation(MicroBenchmark.class).value() == Mode.SingleShotTime;
+    private static IterationParams getWarmup(BaseOptions options, BenchmarkRecord benchmark, Method method) {
+        boolean isSingleShot = (benchmark.getMode() == Mode.SingleShotTime);
         Warmup warAnn = method.getAnnotation(Warmup.class);
         int iters = (warAnn == null) ? -1 : warAnn.iterations();
         if (isSingleShot) {
@@ -106,8 +107,8 @@
         }
     }
 
-    private static IterationParams getMeasurement(BaseOptions options, Method method) {
-        boolean isSingleShot = method.getAnnotation(MicroBenchmark.class).value() == Mode.SingleShotTime;
+    private static IterationParams getMeasurement(BaseOptions options, BenchmarkRecord benchmark, Method method) {
+        boolean isSingleShot = (benchmark.getMode() == Mode.SingleShotTime);
         Measurement meAnn = method.getAnnotation(Measurement.class);
         int iters = (meAnn == null) ? -1 : meAnn.iterations();
         if (isSingleShot) {
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestOptions.java	Tue Jun 04 13:49:40 2013 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestOptions.java	Tue Jun 04 14:04:46 2013 +0400
@@ -29,7 +29,9 @@
 import org.openjdk.jmh.annotations.Fork;
 import org.openjdk.jmh.annotations.Measurement;
 import org.openjdk.jmh.annotations.MicroBenchmark;
+import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.parameters.MicroBenchmarkParameters;
 import org.openjdk.jmh.runner.parameters.MicroBenchmarkParametersFactory;
 import org.openjdk.jmh.runner.parameters.TimeValue;
@@ -112,7 +114,8 @@
         String[] argv = {".*Hash.*", "-e", ".*Apa.*", "-f", "-e", ".*a.*", "-v", "-i", "11", "-r", "100s", "-t", "2", "-sc", "false"};
         HarnessOptions options = getOptions(argv);
 
-        MicroBenchmarkParameters mbp = MicroBenchmarkParametersFactory.makeParams(options, this.getClass().getMethod("dummyMethod"));
+        BenchmarkRecord br = new BenchmarkRecord(this.getClass().getName() + "dummyMethod2", this.getClass().getName() + "dummyMethod2", Mode.Throughput);
+        MicroBenchmarkParameters mbp = MicroBenchmarkParametersFactory.makeParams(options, br, this.getClass().getMethod("dummyMethod"));
 
         assertEquals(options.getIterations(), mbp.getIteration().getCount());
         assertFalse(options.shouldScale());
@@ -122,7 +125,7 @@
         String[] argv2 = {".*Hash.*", "-e", ".*Apa.*", "-f", "-e", ".*a.*", "-v"};
         options = getOptions(argv2);
 
-        mbp = MicroBenchmarkParametersFactory.makeParams(options, this.getClass().getMethod("dummyMethod"));
+        mbp = MicroBenchmarkParametersFactory.makeParams(options, br, this.getClass().getMethod("dummyMethod"));
 
         assertTrue(options.getIterations() != mbp.getIteration().getCount());
         assertTrue(options.getThreads() != mbp.getMaxThreads());
@@ -134,7 +137,8 @@
         String[] argv = {".*Hash.*", "-e", ".*Apa.*", "-f", "-e", ".*a.*", "-v", "-i", "11", "-r", "100s", "-sc"};
         HarnessOptions options = getOptions(argv);
 
-        MicroBenchmarkParameters mbp = MicroBenchmarkParametersFactory.makeParams(options, this.getClass().getMethod("dummyMethod2"));
+        BenchmarkRecord br = new BenchmarkRecord(this.getClass().getName() + "dummyMethod2", this.getClass().getName() + "dummyMethod2", Mode.Throughput);
+        MicroBenchmarkParameters mbp = MicroBenchmarkParametersFactory.makeParams(options, br, this.getClass().getMethod("dummyMethod2"));
 
         assertEquals(Runtime.getRuntime().availableProcessors(), mbp.getMaxThreads());
     }
@@ -185,13 +189,11 @@
     @Threads(100)
     @Measurement(iterations = 100, time = 3)
     @Fork(jvmArgs = "apa")
-    @MicroBenchmark
     public void dummyMethod() {
     }
 
     @Measurement(iterations = 100, time = 3)
     @Fork(jvmArgs = "apa")
-    @MicroBenchmark
     public void dummyMethod2() {
     }