Class BenchmarkGenerator


  • public class BenchmarkGenerator
    extends java.lang.Object
    Benchmark generator.

    Benchmark generator is the agnostic piece of code which generates synthetic Java code for JMH benchmarks. GeneratorSource is used to feed the generator with the required metadata.

    • Field Detail

      • JMH_TESTCLASS_SUFFIX

        private static final java.lang.String JMH_TESTCLASS_SUFFIX
        See Also:
        Constant Field Values
      • JMH_GENERATED_SUBPACKAGE

        protected static final java.lang.String JMH_GENERATED_SUBPACKAGE
        See Also:
        Constant Field Values
      • benchmarkInfos

        private final java.util.Set<BenchmarkInfo> benchmarkInfos
      • processedBenchmarks

        private final java.util.Set<java.lang.String> processedBenchmarks
      • INDENTS

        static volatile java.lang.String[] INDENTS
      • INDENTS_LOCK

        static final java.lang.Object INDENTS_LOCK
    • Constructor Detail

      • BenchmarkGenerator

        public BenchmarkGenerator()
    • Method Detail

      • generate

        public void generate​(GeneratorSource source,
                             GeneratorDestination destination)
        Execute the next phase of benchmark generation. Multiple calls to this method are acceptable, even with the difference sources
        Parameters:
        source - generator source to get the metadata from
        destination - generator destination to write the results to
      • complete

        public void complete​(GeneratorSource source,
                             GeneratorDestination destination)
        Finish generating the benchmarks. Must be called at the end of generation.
        Parameters:
        source - source generator to use
        destination - generator destination to write the results to
      • buildAnnotatedSet

        private Multimap<ClassInfo,​MethodInfo> buildAnnotatedSet​(GeneratorSource source)
        Build a set of Classes which has annotated methods in them
        Returns:
        for all methods annotated with $annotation, returns Map>
      • validateBenchmark

        private void validateBenchmark​(ClassInfo clazz,
                                       java.util.Collection<MethodInfo> methods)
        Do basic benchmark validation.
      • validateBenchmarkInfo

        private void validateBenchmarkInfo​(BenchmarkInfo info)
        validate benchmark info
        Parameters:
        info - benchmark info to validate
      • makeBenchmarkInfo

        private java.util.Collection<BenchmarkInfo> makeBenchmarkInfo​(ClassInfo clazz,
                                                                      java.util.Collection<MethodInfo> methods)
        Generate BenchmarkInfo for given class. We will figure out method groups at this point.
        Parameters:
        clazz - holder class
        methods - annotated methods
        Returns:
        BenchmarkInfo
      • generateClass

        private void generateClass​(GeneratorDestination destination,
                                   ClassInfo classInfo,
                                   BenchmarkInfo info)
                            throws java.io.IOException
        Create and generate Java code for a class and it's methods
        Throws:
        java.io.IOException
      • generateImport

        private void generateImport​(java.io.PrintWriter writer)
      • generateMethod

        private void generateMethod​(Mode benchmarkKind,
                                    java.io.PrintWriter writer,
                                    MethodGroup methodGroup,
                                    StateObjectHandler states)
        Generate the method for a specific benchmark method
      • addAuxCounters

        private void addAuxCounters​(java.io.PrintWriter writer,
                                    java.lang.String resName,
                                    StateObjectHandler states,
                                    MethodInfo method)
      • getStubArgs

        private java.lang.String getStubArgs()
      • getStubTypeArgs

        private java.lang.String getStubTypeArgs()
      • methodProlog

        private void methodProlog​(java.io.PrintWriter writer)
      • methodEpilog

        private void methodEpilog​(java.io.PrintWriter writer)
      • prefix

        private java.lang.String prefix​(java.lang.String argList)
      • generateSingleShotTime

        private void generateSingleShotTime​(java.io.PrintWriter writer,
                                            Mode benchmarkKind,
                                            MethodGroup methodGroup,
                                            StateObjectHandler states)
      • invocationProlog

        private void invocationProlog​(java.io.PrintWriter writer,
                                      int prefix,
                                      MethodInfo method,
                                      StateObjectHandler states,
                                      boolean pauseMeasurement)
      • invocationEpilog

        private void invocationEpilog​(java.io.PrintWriter writer,
                                      int prefix,
                                      MethodInfo method,
                                      StateObjectHandler states,
                                      boolean pauseMeasurement)
      • iterationProlog

        private void iterationProlog​(java.io.PrintWriter writer,
                                     int prefix,
                                     MethodInfo method,
                                     StateObjectHandler states)
      • iterationEpilog

        private void iterationEpilog​(java.io.PrintWriter writer,
                                     int prefix,
                                     MethodInfo method,
                                     StateObjectHandler states)
      • ident

        static java.lang.String ident​(int tabs)