changeset 1295:eaec8520f145

7901524: Validation suite: add compiler hints test
author shade
date Fri, 02 Oct 2015 15:02:43 +0300
parents d08717869985
children bbf0d4be9468
files jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/CompilerHintsBench.java jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/Main.java jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/CompilerHintsTest.java
diffstat 3 files changed, 189 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/benchmarks/CompilerHintsBench.java	Fri Oct 02 15:02:43 2015 +0300
@@ -0,0 +1,100 @@
+/*
+ * 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.benchmarks;
+
+import org.openjdk.jmh.annotations.*;
+
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class CompilerHintsBench {
+
+    @Benchmark
+    public void baseI_baseline() {
+        do_Plain(Math.PI);
+    }
+
+    @Benchmark
+    @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"})
+    public void baseNI_baseline() {
+        do_Plain(Math.PI);
+    }
+
+    @Benchmark
+    public void baseI_inline() {
+        do_Inline(Math.PI);
+    }
+
+    @Benchmark
+    @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"})
+    public void baseNI_inline() {
+        do_Inline(Math.PI);
+    }
+
+    @Benchmark
+    public void baseI_dontInline() {
+        do_DontInline(Math.PI);
+    }
+
+    @Benchmark
+    @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"})
+    public void baseNI_dontInline() {
+        do_DontInline(Math.PI);
+    }
+
+    @Benchmark
+    public void baseI_exclude() {
+        do_Exclude(Math.PI);
+    }
+
+    @Benchmark
+    @Fork(jvmArgsPrepend = {"-XX:MaxInlineSize=0", "-XX:FreqInlineSize=0"})
+    public void baseNI_exclude() {
+        do_Exclude(Math.PI);
+    }
+
+    private double do_Plain(double x) {
+        return Math.log(x);
+    }
+
+    @CompilerControl(CompilerControl.Mode.INLINE)
+    private double do_Inline(double x) {
+        return Math.log(x);
+    }
+
+    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
+    private double do_DontInline(double x) {
+        return Math.log(x);
+    }
+
+    @CompilerControl(CompilerControl.Mode.EXCLUDE)
+    private double do_Exclude(double x) {
+        return Math.log(x);
+    }
+
+
+}
--- a/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/Main.java	Fri Sep 25 19:58:07 2015 +0300
+++ b/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/Main.java	Fri Oct 02 15:02:43 2015 +0300
@@ -161,6 +161,9 @@
                 case stability:
                     new ScoreStabilityTest().runWith(pw, opts);
                     break;
+                case compiler_hints:
+                    new CompilerHintsTest().runWith(pw, opts);
+                    break;
                 case thermal:
                     switch (mode) {
                         case flash:
@@ -215,6 +218,7 @@
 
     public static enum Test {
         timing,
+        compiler_hints,
         thermal,
         stability,
         thread_scale,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-benchmarks/src/main/java/org/openjdk/jmh/validation/tests/CompilerHintsTest.java	Fri Oct 02 15:02:43 2015 +0300
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2014, 2015, 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.validation.tests;
+
+import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.benchmarks.CompilerHintsBench;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.VerboseMode;
+import org.openjdk.jmh.validation.ValidationTest;
+
+import java.io.PrintWriter;
+
+public class CompilerHintsTest implements ValidationTest {
+    @Override
+    public void runWith(PrintWriter pw, Options parent) throws RunnerException {
+        pw.println("--------- COMPILER HINTS TEST");
+        pw.println();
+
+        org.openjdk.jmh.util.Utils.reflow(pw,
+                "This tests verifies compiler hints are working as expected. Two baseline tests run the workload " +
+                        "in inlined and non-inlined regiments. When the workload is inlined, the optimizations should "  +
+                        "kill the workload body. Compiler hints should successfully survive in both regiments: " +
+                        CompilerControl.Mode.INLINE + " should always inline, and " + CompilerControl.Mode.DONT_INLINE + " " +
+                        "should always break inlining. " + CompilerControl.Mode.EXCLUDE + " should be neutral to inlining " +
+                        "policy completely.",
+                80, 2);
+        pw.println();
+
+        doWith(parent, pw, "baseI_baseline",    "Default inline policy");
+        doWith(parent, pw, "baseI_inline",      "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.INLINE + ")");
+        doWith(parent, pw, "baseI_dontInline",  "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.DONT_INLINE + ")");
+        doWith(parent, pw, "baseI_exclude",     "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.EXCLUDE + ")");
+
+        pw.println();
+
+        doWith(parent, pw, "baseNI_baseline", "Default no inline policy");
+        doWith(parent, pw, "baseNI_inline",     "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.INLINE + ")");
+        doWith(parent, pw, "baseNI_dontInline", "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.DONT_INLINE + ")");
+        doWith(parent, pw, "baseNI_exclude",    "  + @" + CompilerControl.class.getSimpleName() + "(" + CompilerControl.Mode.EXCLUDE + ")");
+
+        pw.println();
+    }
+
+    private void doWith(Options parent, PrintWriter pw, String test, String descr) throws RunnerException {
+        Options opts = new OptionsBuilder()
+                .parent(parent)
+                .include(CompilerHintsBench.class.getCanonicalName() + "." + test + "$")
+                .verbosity(VerboseMode.SILENT)
+                .build();
+
+        RunResult result = new Runner(opts).runSingle();
+        Result r = result.getPrimaryResult();
+
+        pw.printf("%50s", descr + ": ");
+        pw.flush();
+        pw.printf("%.2f \u00b1 %.2f ns\n", r.getScore(), r.getScoreError());
+    }
+}