changeset 1056:73451bc77ee0

Additional @CompilerControl tests, probing the actual compiler output.
author shade
date Wed, 10 Dec 2014 16:08:49 +0300
parents 9d3ce623fb33
children 87eea88f9819
files jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineActualTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeActualTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineActualTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlUtils.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/LogConsumeProfiler.java
diffstat 5 files changed, 436 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineActualTest.java	Wed Dec 10 16:08:49 2014 +0300
@@ -0,0 +1,85 @@
+/*
+ * 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.it.ccontrol;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.it.Fixtures;
+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.TimeValue;
+
+public class CompilerControlDontInlineActualTest {
+
+    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
+    public void strawMethod() {
+
+    }
+
+    public void trampoline() {
+        strawMethod();
+    }
+
+    @Benchmark
+    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
+    public void compilerControlSpecimen() {
+        trampoline();
+    }
+
+    @Test
+    public void testGMB() throws RunnerException {
+        for (Mode mode : Mode.values()) {
+            if (mode == Mode.All) continue;
+
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .mode(mode)
+                    .shouldFailOnError(true)
+                    .addProfiler(LogConsumeProfiler.class)
+                    .measurementIterations(mode == Mode.SingleShotTime ? 100000 : 1)
+                    .measurementTime(TimeValue.seconds(5))
+                    .warmupIterations(0)
+                    .forks(1)
+                    .build();
+            RunResult runResult = new Runner(opts).runSingle();
+
+            if (CompilerControlUtils.check(runResult, "@", "callee")) { // Poor man's check -XX:+PrintInlining works
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::compilerControlSpecimen", "disallowed by"));
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::strawMethod", "disallowed by"));
+            }
+        }
+    }
+
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeActualTest.java	Wed Dec 10 16:08:49 2014 +0300
@@ -0,0 +1,85 @@
+/*
+ * 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.it.ccontrol;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.it.Fixtures;
+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.TimeValue;
+
+public class CompilerControlExcludeActualTest {
+
+    @CompilerControl(CompilerControl.Mode.EXCLUDE)
+    public void strawMethod() {
+
+    }
+
+    public void trampoline() {
+        strawMethod();
+    }
+
+    @Benchmark
+    @CompilerControl(CompilerControl.Mode.EXCLUDE)
+    public void compilerControlSpecimen() {
+        trampoline();
+    }
+
+    @Test
+    public void testGMB() throws RunnerException {
+        for (Mode mode : Mode.values()) {
+            if (mode == Mode.All) continue;
+
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .mode(mode)
+                    .shouldFailOnError(true)
+                    .addProfiler(LogConsumeProfiler.class)
+                    .measurementIterations(mode == Mode.SingleShotTime ? 100000 : 1)
+                    .measurementTime(TimeValue.seconds(5))
+                    .warmupIterations(0)
+                    .forks(1)
+                    .build();
+            RunResult runResult = new Runner(opts).runSingle();
+
+            if (CompilerControlUtils.check(runResult, "@", "callee")) { // Poor man's check -XX:+PrintInlining works
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::compilerControlSpecimen", "excluded by"));
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::strawMethod", "excluded by"));
+            }
+        }
+    }
+
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineActualTest.java	Wed Dec 10 16:08:49 2014 +0300
@@ -0,0 +1,85 @@
+/*
+ * 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.it.ccontrol;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.it.Fixtures;
+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.TimeValue;
+
+public class CompilerControlInlineActualTest {
+
+    @CompilerControl(CompilerControl.Mode.INLINE)
+    public void strawMethod() {
+
+    }
+
+    public void trampoline() {
+        strawMethod();
+    }
+
+    @Benchmark
+    @CompilerControl(CompilerControl.Mode.INLINE)
+    public void compilerControlSpecimen() {
+        trampoline();
+    }
+
+    @Test
+    public void testGMB() throws RunnerException {
+        for (Mode mode : Mode.values()) {
+            if (mode == Mode.All) continue;
+
+            Options opts = new OptionsBuilder()
+                    .include(Fixtures.getTestMask(this.getClass()))
+                    .mode(mode)
+                    .shouldFailOnError(true)
+                    .addProfiler(LogConsumeProfiler.class)
+                    .measurementIterations(mode == Mode.SingleShotTime ? 100000 : 1)
+                    .measurementTime(TimeValue.seconds(5))
+                    .warmupIterations(0)
+                    .forks(1)
+                    .build();
+            RunResult runResult = new Runner(opts).runSingle();
+
+            if (CompilerControlUtils.check(runResult, "@", "callee")) { // Poor man's check -XX:+PrintInlining works
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::compilerControlSpecimen", "force inline by"));
+                Assert.assertTrue("Failed with " + mode,
+                        CompilerControlUtils.check(runResult, this.getClass().getName() + "::strawMethod", "force inline by"));
+            }
+        }
+    }
+
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlUtils.java	Wed Dec 10 16:08:49 2014 +0300
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2014, 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.it.ccontrol;
+
+import org.openjdk.jmh.results.RunResult;
+
+import java.util.Collection;
+
+public class CompilerControlUtils {
+
+    public static boolean check(RunResult runResult, String... checkFor) {
+        LogConsumeProfiler.LogConsumeResult r = (LogConsumeProfiler.LogConsumeResult) runResult.getSecondaryResults().get("logout");
+        Collection<String> lines = r.getLines();
+
+        line: for (String line : lines) {
+            System.out.println(line);
+            for (String m : checkFor) {
+                if (!line.contains(m)) continue line;
+            }
+            return true;
+        }
+        return false;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/LogConsumeProfiler.java	Wed Dec 10 16:08:49 2014 +0300
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2014, 2014, 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.it.ccontrol;
+
+import org.openjdk.jmh.infra.BenchmarkParams;
+import org.openjdk.jmh.profile.ExternalProfiler;
+import org.openjdk.jmh.results.AggregationPolicy;
+import org.openjdk.jmh.results.Aggregator;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.ResultRole;
+import org.openjdk.jmh.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class LogConsumeProfiler implements ExternalProfiler {
+
+    @Override
+    public Collection<String> addJVMInvokeOptions(BenchmarkParams params) {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public Collection<String> addJVMOptions(BenchmarkParams params) {
+        return Arrays.asList("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintCompilation", "-XX:+PrintInlining");
+    }
+
+    @Override
+    public void beforeTrial(BenchmarkParams benchmarkParams) {
+
+    }
+
+    @Override
+    public Collection<? extends Result> afterTrial(BenchmarkParams benchmarkParams, File stdOut, File stdErr) {
+        try {
+            return Arrays.asList(
+                    new LogConsumeResult("out", FileUtils.readAllLines(stdOut)),
+                    new LogConsumeResult("err", FileUtils.readAllLines(stdErr))
+            );
+        } catch (IOException e) {
+            // skip
+        }
+        return Collections.emptyList();
+    }
+
+    @Override
+    public boolean allowPrintOut() {
+        return false;
+    }
+
+    @Override
+    public boolean allowPrintErr() {
+        return false;
+    }
+
+    @Override
+    public boolean checkSupport(List<String> msgs) {
+        return true;
+    }
+
+    @Override
+    public String label() {
+        return "logaggr";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Log aggregating profiler";
+    }
+
+    public static class LogConsumeResult extends Result<LogConsumeResult> {
+        private final Collection<String> lines;
+
+        public LogConsumeResult(String label, Collection<String> lines) {
+            super(ResultRole.SECONDARY, "log" + label, of(Double.NaN), "N/A", AggregationPolicy.MAX);
+            this.lines = lines;
+        }
+
+        public Collection<String> getLines() {
+            return lines;
+        }
+
+        @Override
+        protected Aggregator<LogConsumeResult> getThreadAggregator() {
+            return new LogAggregator();
+        }
+
+        @Override
+        protected Aggregator<LogConsumeResult> getIterationAggregator() {
+            return new LogAggregator();
+        }
+
+        public static class LogAggregator implements Aggregator<LogConsumeResult> {
+            @Override
+            public Result aggregate(Collection<LogConsumeResult> results) {
+                String label = null;
+                Collection<String> allLines = new ArrayList<String>();
+                for (LogConsumeResult r : results) {
+                    label = r.label;
+                    allLines.addAll(r.getLines());
+                }
+                return new LogConsumeResult(label, allLines);
+            }
+        }
+
+    }
+}