changeset 1306:80b666fe8548

7901581: @CompilerControl(DONT_INLINE) on a class does not work for @Benchmark method
author shade
date Thu, 14 Jan 2016 21:47:25 +0300
parents 2290f828ce5c
children ce0559bf7731
files jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineClassTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeClassTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineClassTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlNestedTest.java jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlUtils.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/CompilerControlPlugin.java
diffstat 9 files changed, 218 insertions(+), 72 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/CompilerControlDontInlineClassTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -0,0 +1,53 @@
+/*
+ * 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.CompilerControl.Mode;
+import org.openjdk.jmh.runner.RunnerException;
+
+@CompilerControl(Mode.DONT_INLINE)
+public class CompilerControlDontInlineClassTest {
+
+    @Benchmark
+    public void compilerControlSpecimen() {}
+
+    @Test
+    public void test() throws RunnerException {
+        String className = this.getClass().getName().replace(".", "/");
+
+        Assert.assertTrue("Class hint should exist",
+                CompilerControlUtils.hasHint(Mode.DONT_INLINE.command(), className)
+        );
+
+        Assert.assertFalse("Method hint should not exist",
+                CompilerControlUtils.hasHint("", className, "compilerControlSpecimen")
+        );
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineTest.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlDontInlineTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -28,41 +28,33 @@
 import org.junit.Test;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.CompilerControl.Mode;
 import org.openjdk.jmh.it.Fixtures;
-import org.openjdk.jmh.runner.CompilerHints;
 import org.openjdk.jmh.runner.RunnerException;
 
 public class CompilerControlDontInlineTest {
 
-    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
+    @CompilerControl(Mode.DONT_INLINE)
     void sampleMethod() {}
 
     @Benchmark
-    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
+    @CompilerControl(Mode.DONT_INLINE)
     public void dummyTest() {
         Fixtures.work();
     }
 
     @Test
     public void testBenchmark() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("dummyTest")) {
-                exists |= s.startsWith("dontinline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on benchmark method",
+                CompilerControlUtils.hasHint(Mode.DONT_INLINE.command(), className, "dummyTest"));
     }
 
     @Test
     public void testStandalone() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("sampleMethod")) {
-                exists |= s.startsWith("dontinline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on standalone method",
+                CompilerControlUtils.hasHint(Mode.DONT_INLINE.command(), className, "sampleMethod"));
     }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeClassTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -0,0 +1,53 @@
+/*
+ * 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.CompilerControl.Mode;
+import org.openjdk.jmh.runner.RunnerException;
+
+@CompilerControl(Mode.EXCLUDE)
+public class CompilerControlExcludeClassTest {
+
+    @Benchmark
+    public void compilerControlSpecimen() {}
+
+    @Test
+    public void test() throws RunnerException {
+        String className = this.getClass().getName().replace(".", "/");
+
+        Assert.assertTrue("Class hint should exist",
+                CompilerControlUtils.hasHint(Mode.EXCLUDE.command(), className)
+        );
+
+        Assert.assertFalse("Method hint should not exist",
+                CompilerControlUtils.hasHint("", className, "compilerControlSpecimen")
+        );
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeTest.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlExcludeTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -28,41 +28,33 @@
 import org.junit.Test;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.CompilerControl.Mode;
 import org.openjdk.jmh.it.Fixtures;
-import org.openjdk.jmh.runner.CompilerHints;
 import org.openjdk.jmh.runner.RunnerException;
 
 public class CompilerControlExcludeTest {
 
-    @CompilerControl(CompilerControl.Mode.EXCLUDE)
+    @CompilerControl(Mode.EXCLUDE)
     void sampleMethod() {}
 
     @Benchmark
-    @CompilerControl(CompilerControl.Mode.EXCLUDE)
+    @CompilerControl(Mode.EXCLUDE)
     public void dummyTest() {
         Fixtures.work();
     }
 
     @Test
     public void testBenchmark() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("dummyTest")) {
-                exists |= s.startsWith("exclude");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on benchmark method",
+                CompilerControlUtils.hasHint(Mode.EXCLUDE.command(), className, "dummyTest"));
     }
 
     @Test
     public void testStandalone() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("sampleMethod")) {
-                exists |= s.startsWith("exclude");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on standalone method",
+                CompilerControlUtils.hasHint(Mode.EXCLUDE.command(), className, "sampleMethod"));
     }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineClassTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -0,0 +1,53 @@
+/*
+ * 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.CompilerControl.Mode;
+import org.openjdk.jmh.runner.RunnerException;
+
+@CompilerControl(Mode.INLINE)
+public class CompilerControlInlineClassTest {
+
+    @Benchmark
+    public void compilerControlSpecimen() {}
+
+    @Test
+    public void test() throws RunnerException {
+        String className = this.getClass().getName().replace(".", "/");
+
+        Assert.assertTrue("Class hint should exist",
+                CompilerControlUtils.hasHint(Mode.INLINE.command(), className)
+        );
+
+        Assert.assertFalse("Method hint should not exist",
+                CompilerControlUtils.hasHint("", className, "compilerControlSpecimen")
+        );
+    }
+
+}
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineTest.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlInlineTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -28,41 +28,33 @@
 import org.junit.Test;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.CompilerControl;
+import org.openjdk.jmh.annotations.CompilerControl.Mode;
 import org.openjdk.jmh.it.Fixtures;
-import org.openjdk.jmh.runner.CompilerHints;
 import org.openjdk.jmh.runner.RunnerException;
 
 public class CompilerControlInlineTest {
 
-    @CompilerControl(CompilerControl.Mode.INLINE)
+    @CompilerControl(Mode.INLINE)
     void sampleMethod() {}
 
     @Benchmark
-    @CompilerControl(CompilerControl.Mode.INLINE)
+    @CompilerControl(Mode.INLINE)
     public void dummyTest() {
         Fixtures.work();
     }
 
     @Test
     public void testBenchmark() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("dummyTest")) {
-                exists |= s.startsWith("inline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on benchmark method",
+                CompilerControlUtils.hasHint(Mode.INLINE.command(), className, "dummyTest"));
     }
 
     @Test
     public void testStandalone() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("sampleMethod")) {
-                exists |= s.startsWith("inline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on standalone method",
+                CompilerControlUtils.hasHint(Mode.INLINE.command(), className, "sampleMethod"));
     }
 
 }
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlNestedTest.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlNestedTest.java	Thu Jan 14 21:47:25 2016 +0300
@@ -26,22 +26,22 @@
 
 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.Benchmark;
+import org.openjdk.jmh.annotations.CompilerControl.Mode;
 import org.openjdk.jmh.it.Fixtures;
-import org.openjdk.jmh.runner.CompilerHints;
 import org.openjdk.jmh.runner.RunnerException;
 
 public class CompilerControlNestedTest {
 
-    @CompilerControl(CompilerControl.Mode.INLINE)
+    @CompilerControl(Mode.INLINE)
     public static class SpecimenClass {
         void sampleMethod() {}
     }
 
 
     public static class SpecimenMethod {
-        @CompilerControl(CompilerControl.Mode.INLINE)
+        @CompilerControl(Mode.INLINE)
         void sampleMethod() {}
     }
 
@@ -52,24 +52,16 @@
 
     @Test
     public void testClass() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("$SpecimenClass.*")) {
-                exists |= s.startsWith("inline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on nested class",
+                CompilerControlUtils.hasHint(Mode.INLINE.command(), className, "$SpecimenClass.*"));
     }
 
     @Test
     public void testMethod() throws RunnerException {
-        boolean exists = false;
-        for (String s : CompilerHints.defaultList().get()) {
-            if (s.contains(this.getClass().getName().replace(".", "/")) && s.contains("$SpecimenMethod") && s.contains("sampleMethod")) {
-                exists |= s.startsWith("inline");
-            }
-        }
-        Assert.assertTrue(exists);
+        String className = this.getClass().getName().replace(".", "/");
+        Assert.assertTrue("Has hint on nested class",
+                CompilerControlUtils.hasHint(Mode.INLINE.command(), className, "$SpecimenMethod", "sampleMethod"));
     }
 
 }
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlUtils.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/ccontrol/CompilerControlUtils.java	Thu Jan 14 21:47:25 2016 +0300
@@ -25,6 +25,7 @@
 package org.openjdk.jmh.it.ccontrol;
 
 import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.CompilerHints;
 
 import java.util.Collection;
 
@@ -44,4 +45,17 @@
         return false;
     }
 
+    public static boolean hasHint(String hint, String... filters) {
+        nextHint:
+        for (String s : CompilerHints.defaultList().get()) {
+            for (String f : filters) {
+                if (!s.contains(f)) continue nextHint;
+            }
+            if (s.startsWith(hint)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/CompilerControlPlugin.java	Thu Jan 14 18:23:30 2016 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/CompilerControlPlugin.java	Thu Jan 14 21:47:25 2016 +0300
@@ -45,14 +45,14 @@
         }
     });
 
-    private final Set<String> defaultDontInlineMethods = new TreeSet<String>();
+    private final Set<String> alwaysDontInlineMethods = new TreeSet<String>();
 
     public void defaultForceInline(MethodInfo methodInfo) {
         defaultForceInlineMethods.add(methodInfo);
     }
 
     public void alwaysDontInline(String className, String methodName) {
-        defaultDontInlineMethods.add(getName(className, methodName));
+        alwaysDontInlineMethods.add(getName(className, methodName));
     }
 
     public void process(GeneratorSource source, GeneratorDestination destination) {
@@ -68,11 +68,16 @@
             }
 
             for (MethodInfo element : defaultForceInlineMethods) {
+                // Skip methods annotated explicitly
                 if (element.getAnnotation(CompilerControl.class) != null) continue;
+
+                // Skip methods in classes that are annotated explicitly
+                if (element.getDeclaringClass().getAnnotation(CompilerControl.class) != null) continue;
+
                 lines.add(CompilerControl.Mode.INLINE.command() + "," + getName(element));
             }
 
-            for (String element : defaultDontInlineMethods) {
+            for (String element : alwaysDontInlineMethods) {
                 lines.add(CompilerControl.Mode.DONT_INLINE.command() + "," + element);
             }