Package org.apache.drill.exec.compile
Class CodeCompiler
java.lang.Object
org.apache.drill.exec.compile.CodeCompiler
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Abstracts out the details of compiling code using the two available mechanisms. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
Disables the code cache.static final String
Enables saving generated code for debuggingstatic final String
Maximum size of the compiled class cache.static final String
Prefer to generate code as plain Java when the code generator supports that mechanism. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Upon close, report the effectiveness of the code cache to the log.<T> T
createInstance
(CodeGenerator<?> cg) Create a single instance of the generated class.<T> List<T>
createInstances
(CodeGenerator<?> cg, int count) Create multiple instances of the generated class.void
Flush the compiled classes from the cache.
-
Field Details
-
COMPILE_BASE
- See Also:
-
MAX_LOADING_CACHE_SIZE_CONFIG
Maximum size of the compiled class cache.- See Also:
-
DISABLE_CACHE_CONFIG
Disables the code cache. Primarily for testing.- See Also:
-
ENABLE_SAVE_CODE_FOR_DEBUG_TOPN
Enables saving generated code for debugging- See Also:
-
PREFER_POJ_CONFIG
Prefer to generate code as plain Java when the code generator supports that mechanism.- See Also:
-
-
Constructor Details
-
CodeCompiler
-
-
Method Details
-
createInstance
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.
-