Class CodeCompiler

java.lang.Object
org.apache.drill.exec.compile.CodeCompiler

public class CodeCompiler extends Object
Global code compiler mechanism shared by all threads and operators. Holds a single cache of generated code (keyed by code source) to prevent compiling identical code multiple times. Supports both the byte-code merging and plain-old Java methods of code generation and compilation.
  • Field Details

    • COMPILE_BASE

      public static final String COMPILE_BASE
      See Also:
    • MAX_LOADING_CACHE_SIZE_CONFIG

      public static final String MAX_LOADING_CACHE_SIZE_CONFIG
      Maximum size of the compiled class cache.
      See Also:
    • DISABLE_CACHE_CONFIG

      public static final String DISABLE_CACHE_CONFIG
      Disables the code cache. Primarily for testing.
      See Also:
    • ENABLE_SAVE_CODE_FOR_DEBUG_TOPN

      public static final String ENABLE_SAVE_CODE_FOR_DEBUG_TOPN
      Enables saving generated code for debugging
      See Also:
    • PREFER_POJ_CONFIG

      public static final String PREFER_POJ_CONFIG
      Prefer to generate code as plain Java when the code generator supports that mechanism.
      See Also:
  • Constructor Details

  • Method Details

    • createInstance

      public <T> T createInstance(CodeGenerator<?> cg) throws ClassTransformationException
      Create a single instance of the generated class.
      Parameters:
      cg - code generator for the class to be instantiated.
      Returns:
      an instance of the generated class
      Throws:
      ClassTransformationException - general "something is wrong" exception for the Drill compilation chain.
    • createInstances

      public <T> List<T> createInstances(CodeGenerator<?> cg, int count) throws ClassTransformationException
      Create multiple instances of the generated class.
      Parameters:
      cg - code generator for the class to be instantiated.
      count - the number of instances desired.
      Returns:
      a list of instances of the generated class.
      Throws:
      ClassTransformationException - general "something is wrong" exception for the Drill compilation chain.
    • flushCache

      public void flushCache()
      Flush the compiled classes from the cache.

      The cache has DrillbitContext lifetime, so the only way items go out of it now is by being aged out because of the maximum cache size.

      The intent of flushCache() is to make it possible to flush the cache for testing purposes, although this could be used by users in case issues arise. If that happens, remove the visible for testing annotation.

    • close

      public void close()
      Upon close, report the effectiveness of the code cache to the log.