changeset 380:f8722f81ff14

Force inline @GMB methods. There are cases when inlining policy omits inlining the call because it was compiled early and resulted in moderately-sided method.
author shade
date Tue, 28 Jan 2014 20:00:57 +0400
parents f0b81d581219
children e8c286b68839
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/SubProcessor.java
diffstat 5 files changed, 78 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Tue Jan 28 17:18:35 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Tue Jan 28 20:00:57 2014 +0400
@@ -41,44 +41,26 @@
 public class CompilerControlProcessor implements SubProcessor {
 
     private final List<String> lines = new ArrayList<String>();
+    private final List<Element> forceInline = new ArrayList<Element>();
+
+    public void forceInline(Element element) {
+        forceInline.add(element);
+    }
 
     public void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
         try {
-            if (!roundEnv.processingOver()) {
-                for (Element element : roundEnv.getElementsAnnotatedWith(CompilerControl.class)) {
+            for (Element element : roundEnv.getElementsAnnotatedWith(CompilerControl.class)) {
+                CompilerControl ann = element.getAnnotation(CompilerControl.class);
+                if (ann == null) {
+                    throw new IllegalStateException("No annotation");
+                }
 
-                    CompilerControl ann = element.getAnnotation(CompilerControl.class);
-                    if (ann == null) {
-                        throw new IllegalStateException("No annotation");
-                    }
+                CompilerControl.Mode command = ann.value();
+                addLine(processingEnv, element, command);
+            }
 
-                    switch (element.getKind()) {
-                        case CLASS:
-                            lines.add(ann.value().command() + "," + element.toString().replaceAll("\\.", "/") + ".*");
-                            break;
-                        case METHOD:
-                            lines.add(ann.value().command() + "," + element.getEnclosingElement().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString());
-                            break;
-                        default:
-                            processingEnv.getMessager().printMessage(Kind.ERROR,
-                                    "@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
-                                            "unexpected target",
-                                    element);
-                    }
-
-                }
-            } else {
-                try {
-                    FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
-                            CompilerHints.LIST.substring(1));
-                    PrintWriter writer = new PrintWriter(file.openWriter());
-                    for (String line : lines) {
-                        writer.println(line);
-                    }
-                    writer.close();
-                } catch (IOException ex) {
-                    processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing compiler hint list " + ex);
-                }
+            for (Element element : forceInline) {
+                addLine(processingEnv, element, CompilerControl.Mode.INLINE);
             }
         } catch (Throwable t) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had thrown exception: " + t);
@@ -86,4 +68,38 @@
         }
     }
 
+    @Override
+    public void finish(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
+        try {
+            FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
+                    CompilerHints.LIST.substring(1));
+            PrintWriter writer = new PrintWriter(file.openWriter());
+            for (String line : lines) {
+                writer.println(line);
+            }
+            writer.close();
+        } catch (IOException ex) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing compiler hint list " + ex);
+        } catch (Throwable t) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had thrown exception: " + t);
+            t.printStackTrace(System.err);
+        }
+    }
+
+    private void addLine(ProcessingEnvironment processingEnv, Element element, CompilerControl.Mode command) {
+        switch (element.getKind()) {
+            case CLASS:
+                lines.add(command.command() + "," + element.toString().replaceAll("\\.", "/") + ".*");
+                break;
+            case METHOD:
+                lines.add(command.command() + "," + element.getEnclosingElement().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString());
+                break;
+            default:
+                processingEnv.getMessager().printMessage(Kind.ERROR,
+                        "@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
+                                "unexpected target",
+                        element);
+        }
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Jan 28 17:18:35 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Jan 28 20:00:57 2014 +0400
@@ -101,13 +101,17 @@
     private final Set<BenchmarkInfo> benchmarkInfos = new HashSet<BenchmarkInfo>();
 
     private final Collection<SubProcessor> subProcessors = new ArrayList<SubProcessor>();
+    private CompilerControlProcessor compilerControl;
 
     @Override
     public synchronized void init(ProcessingEnvironment processingEnv) {
         super.init(processingEnv);
-        subProcessors.add(new CompilerControlProcessor());
+
+        compilerControl = new CompilerControlProcessor();
+
         subProcessors.add(new HelperMethodValidationProcessor());
         subProcessors.add(new GroupValidationProcessor());
+        subProcessors.add(compilerControl);
     }
 
     @Override
@@ -134,6 +138,10 @@
                     }
                 }
             } else {
+                for (SubProcessor sub : subProcessors) {
+                    sub.finish(roundEnv, processingEnv);
+                }
+
                 // Processing completed, final round. Print all added methods to file
                 try {
                     FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
@@ -617,6 +625,8 @@
         boolean isSingleMethod = (methodGroup.methods().size() == 1);
         int subGroup = -1;
         for (Element method : methodGroup.methods()) {
+            compilerControl.forceInline(method);
+
             subGroup++;
 
             writer.println(ident(2) + "if (threadControl.subgroup == " + subGroup + ") {");
@@ -714,6 +724,8 @@
         boolean isSingleMethod = (methodGroup.methods().size() == 1);
         int subGroup = -1;
         for (Element method : methodGroup.methods()) {
+            compilerControl.forceInline(method);
+
             subGroup++;
 
             writer.println(ident(2) + "if (threadControl.subgroup == " + subGroup + ") {");
@@ -822,6 +834,8 @@
         boolean isSingleMethod = (methodGroup.methods().size() == 1);
         int subGroup = -1;
         for (Element method : methodGroup.methods()) {
+            compilerControl.forceInline(method);
+
             subGroup++;
 
             writer.println(ident(2) + "if (threadControl.subgroup == " + subGroup + ") {");
@@ -930,6 +944,8 @@
         boolean isSingleMethod = (methodGroup.methods().size() == 1);
         int subGroup = -1;
         for (Element method : methodGroup.methods()) {
+            compilerControl.forceInline(method);
+
             subGroup++;
 
             writer.println(ident(2) + "if (threadControl.subgroup == " + subGroup + ") {");
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java	Tue Jan 28 17:18:35 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java	Tue Jan 28 20:00:57 2014 +0400
@@ -54,4 +54,9 @@
         }
     }
 
+    @Override
+    public void finish(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
+        // do nothing
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java	Tue Jan 28 17:18:35 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java	Tue Jan 28 20:00:57 2014 +0400
@@ -73,4 +73,9 @@
         }
     }
 
+    @Override
+    public void finish(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
+        // do nothing
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/SubProcessor.java	Tue Jan 28 17:18:35 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/SubProcessor.java	Tue Jan 28 20:00:57 2014 +0400
@@ -31,4 +31,6 @@
 
     void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv);
 
+    void finish(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv);
+
 }