changeset 233:776ad81a60ca

Evade more methods from measurementLoop.
author shade
date Wed, 06 Nov 2013 20:58:29 +0100
parents f57a932c81b8
children e7be2971a45d
files jmh-core/src/main/java/org/openjdk/jmh/logic/results/RawResultPair.java jmh-core/src/main/java/org/openjdk/jmh/logic/results/RawResults.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java
diffstat 3 files changed, 72 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/results/RawResultPair.java	Wed Nov 06 15:05:17 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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.logic.results;
-
-public class RawResultPair {
-
-    public final long operations;
-    public final long time;
-
-    public RawResultPair(long operations, long time) {
-        this.operations = operations;
-        this.time = time;
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/results/RawResults.java	Wed Nov 06 20:58:29 2013 +0100
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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.logic.results;
+
+public class RawResults {
+
+    private final long opsPerInv;
+    public long operations;
+    public long realTime;
+    public long startTime;
+    public long stopTime;
+
+    public long getOperations() {
+        return opsPerInv * operations;
+    }
+
+    public long getTime() {
+        return (realTime > 0) ? realTime : (stopTime - startTime);
+    }
+
+    public RawResults(long opsPerInv) {
+        this.opsPerInv = opsPerInv;
+    }
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Nov 06 15:05:17 2013 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Nov 06 20:58:29 2013 +0100
@@ -40,7 +40,7 @@
 import org.openjdk.jmh.logic.InfraControl;
 import org.openjdk.jmh.logic.results.AverageTimePerOp;
 import org.openjdk.jmh.logic.results.OpsPerTimeUnit;
-import org.openjdk.jmh.logic.results.RawResultPair;
+import org.openjdk.jmh.logic.results.RawResults;
 import org.openjdk.jmh.logic.results.Result;
 import org.openjdk.jmh.logic.results.ResultRole;
 import org.openjdk.jmh.logic.results.SampleTimePerOp;
@@ -409,7 +409,7 @@
         writer.println("import " + Threads.class.getName() + ';');
         writer.println("import " + Warmup.class.getName() + ';');
         writer.println("import " + BenchmarkMode.class.getName() + ';');
-        writer.println("import " + RawResultPair.class.getName() + ';');
+        writer.println("import " + RawResults.class.getName() + ';');
         writer.println("import " + ResultRole.class.getName() + ';');
         writer.println();
     }
@@ -696,7 +696,8 @@
             }
 
             // measurement loop call
-            writer.println(ident(3) + "RawResultPair res = " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
+            writer.println(ident(3) + "RawResults res = new RawResults(" + opsPerInv + "L);");
+            writer.println(ident(3) + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, res, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
 
             // control objects get a special treatment
             for (StateObject so : states.getControls()) {
@@ -719,7 +720,7 @@
             iterationEpilog(writer, 3, method, states);
 
             ResultRole mode = isSingleMethod ? ResultRole.PRIMARY : ResultRole.BOTH;
-            writer.println(ident(3) + "return new OpsPerTimeUnit(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", res.operations, res.time, (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
+            writer.println(ident(3) + "return new OpsPerTimeUnit(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", res.getOperations(), res.getTime(), (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
             writer.println(ident(2) + "} else");
         }
         writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");");
@@ -729,10 +730,12 @@
 
         // measurement loop bodies
         for (Element method : methodGroup.methods()) {
-            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") + " RawResultPair " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
+            String methodName = method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop";
+            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") + " void " + methodName + "(InfraControl control, RawResults res, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
+            writer.println("        RawResults result = res;");
             writer.println("        long operations = 0;");
             writer.println("        long realTime = 0;");
-            writer.println("        long startTime = System.nanoTime();");
+            writer.println("        result.startTime = System.nanoTime();");
             writer.println("        do {");
 
             invocationProlog(writer, 3, method, states, true);
@@ -741,8 +744,9 @@
 
             writer.println("            operations++;");
             writer.println("        } while(!control.isDone);");
-            writer.println("        long stopTime = System.nanoTime();");
-            writer.println("        return new RawResultPair(operations * " + opsPerInv + "L,  (realTime > 0) ? realTime : (stopTime - startTime));");
+            writer.println("        result.stopTime = System.nanoTime();");
+            writer.println("        result.realTime = realTime;");
+            writer.println("        result.operations = operations;");
             writer.println("    }");
             writer.println();
         }
@@ -787,7 +791,8 @@
             }
 
             // measurement loop call
-            writer.println(ident(3) + "RawResultPair res = " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
+            writer.println(ident(3) + "RawResults res = new RawResults(" + opsPerInv + "L);");
+            writer.println(ident(3) + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, res, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
 
             // control objects get a special treatment
             for (StateObject so : states.getControls()) {
@@ -809,7 +814,7 @@
             iterationEpilog(writer, 3, method, states);
 
             ResultRole mode = isSingleMethod ? ResultRole.PRIMARY : ResultRole.BOTH;
-            writer.println(ident(3) + "return new AverageTimePerOp(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", res.operations, res.time, (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
+            writer.println(ident(3) + "return new AverageTimePerOp(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", res.getOperations(), res.getTime(), (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
             writer.println(ident(2) + "} else");
         }
         writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");");
@@ -819,10 +824,11 @@
 
         // measurement loop bodies
         for (Element method : methodGroup.methods()) {
-            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") +  " RawResultPair " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
+            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") +  " void " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, RawResults res, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
+            writer.println("        RawResults result = res;");
             writer.println("        long operations = 0;");
             writer.println("        long realTime = 0;");
-            writer.println("        long start = System.nanoTime();");
+            writer.println("        result.startTime = System.nanoTime();");
             writer.println("        do {");
 
             invocationProlog(writer, 3, method, states, true);
@@ -831,8 +837,9 @@
 
             writer.println("            operations++;");
             writer.println("        } while(!control.isDone);");
-            writer.println("        long end = System.nanoTime();");
-            writer.println("        return new RawResultPair(operations * " + opsPerInv + "L,  (realTime > 0) ? realTime : (end - start));");
+            writer.println("        result.stopTime = System.nanoTime();");
+            writer.println("        result.realTime = realTime;");
+            writer.println("        result.operations = operations;");
             writer.println("    }");
             writer.println();
         }
@@ -897,7 +904,8 @@
             }
 
             // measurement loop call
-            writer.println(ident(3) + "Result res = " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
+            writer.println(ident(3) + "SampleBuffer buffer = new SampleBuffer();");
+            writer.println(ident(3) + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(control, buffer, " + states.getImplicit("bench").toLocal() + ", " + states.getImplicit("blackhole").toLocal() + prefix(states.getArgList(method)) + ");");
 
             // control objects get a special treatment
             for (StateObject so : states.getControls()) {
@@ -919,7 +927,8 @@
 
             iterationEpilog(writer, 3, method, states);
 
-            writer.println(ident(3) + "return res;");
+            ResultRole mode = isSingleMethod ? ResultRole.PRIMARY : ResultRole.BOTH;
+            writer.println(ident(3) + "return new SampleTimePerOp(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", buffer, (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
             writer.println(ident(2) + "} else");
         }
         writer.println(ident(3) + "throw new IllegalStateException(\"Harness failed to distribute threads among groups properly\");");
@@ -928,8 +937,7 @@
 
         // measurement loop bodies
         for (Element method : methodGroup.methods()) {
-            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") + " Result " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
-            writer.println("        SampleBuffer buffer = new SampleBuffer();");
+            writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") + " void " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, SampleBuffer buffer, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
             writer.println("        long realTime = 0;");
             writer.println("        long rnd = System.nanoTime();");
             writer.println("        long rndMask = 0;");
@@ -958,8 +966,6 @@
 
             writer.println("        } while(!control.isDone);");
 
-            ResultRole mode = isSingleMethod ? ResultRole.PRIMARY : ResultRole.BOTH;
-            writer.println("        return new SampleTimePerOp(ResultRole." + mode + ", \"" + method.getSimpleName() + "\", buffer, (control.timeUnit != null) ? control.timeUnit : TimeUnit." + timeUnit + ");");
             writer.println("    }");
             writer.println();
         }