The SpelCompiler is not currently handling all expression types but covers many of the common cases. The framework is extensible to cover more cases in the future. For absolute maximum speed there is *no checking* in the compiled code. The compiled version of the expression uses information learned during interpreted runs of the expression when it generates the byte code. For example if it knows that a particular property dereference always seems to return a Map then it will generate byte code that expects the result of the property dereference to be a Map. This ensures maximal performance but should the dereference result in something other than a map, the compiled expression will fail - like a ClassCastException would occur if passing data of an unexpected type in a regular Java program.
Due to the lack of checking there are likely some expressions that should never be
compiled, for example if an expression is continuously dealing with different types of
data. Due to these cases the compiler is something that must be selectively turned on
for an associated SpelExpressionParser (through the SpelParserConfiguration
object), it is not on by default.
Individual expressions can be compiled by calling SpelCompiler.compile(expression).
| Modifier and Type | Class and Description |
|---|---|
| private static class | SpelCompiler.ChildClassLoader
A ChildClassLoader will load the generated compiled expression classes. |
| private class | SpelCompiler.ExpressionClassWriter
An ASM ClassWriter extension bound to the SpelCompiler's ClassLoader. |
| Modifier and Type | Field and Description |
|---|---|
| private volatile SpelCompiler. | |
| private static final int | |
| private static final Map | |
| private static final Log | |
| private final AtomicInteger |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CompiledExpression | Returns: an instance of the class implementing the compiled expression, ornull if compilation is not possiblethe expression to compile expression)Attempt compilation of the supplied expression. |
| public static boolean | Returns: true if the expression was successfully compiled,
false otherwisethe expression to compile expression)Request that an attempt is made to compile the specified expression. |
| private Class | Returns: the expression call, ornull if the decision was to opt out of
compilation during code generationthe expression to be compiled expressionToCompile)Generate the class that encapsulates the compiled expression and define it. |
| public static SpelCompiler | Returns: a corresponding SpelCompiler instancethe ClassLoader to use as the basis for compilation classLoader)Factory method for compiler instances. |
| private int | |
| private Class | |
| public static void | revertToInterpreted(Expression
the expression expression)Request to revert to the interpreter for expression evaluation. |
| childClassLoader | back to summary |
|---|---|
| private volatile SpelCompiler. | |
| CLASSES_DEFINED_LIMIT | back to summary |
|---|---|
| private static final int CLASSES_DEFINED_LIMIT | |
| compilers | back to summary |
|---|---|
| private static final Map<ClassLoader, SpelCompiler> compilers | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| suffixId | back to summary |
|---|---|
| private final AtomicInteger suffixId | |
| SpelCompiler | back to summary |
|---|---|
| private SpelCompiler(ClassLoader classloader) | |
| compile | back to summary |
|---|---|
| public CompiledExpression compile(SpelNodeImpl expression) Attempt compilation of the supplied expression. A check is made to see if it is compilable before compilation proceeds. The check involves visiting all the nodes in the expression AST and ensuring enough state is known about them that bytecode can be generated for them.
| |
| compile | back to summary |
|---|---|
| public static boolean compile(Expression expression) Request that an attempt is made to compile the specified expression. It may fail if components of the expression are not suitable for compilation or the data types involved are not suitable for compilation. Used for testing.
| |
| createExpressionClass | back to summary |
|---|---|
| private Class Generate the class that encapsulates the compiled expression and define it. The generated class will be a subtype of CompiledExpression.
| |
| getCompiler | back to summary |
|---|---|
| public static SpelCompiler getCompiler(ClassLoader classLoader) Factory method for compiler instances. The returned SpelCompiler will attach a class loader as the child of the given class loader and this child will be used to load compiled expressions.
| |
| getNextSuffix | back to summary |
|---|---|
| private int getNextSuffix() | |
| loadClass | back to summary |
|---|---|
| private Class Load a compiled expression class. Makes sure the classloaders aren't used too much because they anchor compiled classes in memory and prevent GC. If you have expressions continually recompiling over time then by replacing the classloader periodically at least some of the older variants can be garbage collected.
| |
| revertToInterpreted | back to summary |
|---|---|
| public static void revertToInterpreted(Expression expression) Request to revert to the interpreter for expression evaluation. Any compiled form is discarded but can be recreated by later recompiling again.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicInteger | |
| private static final URL[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Class | |
| public int |
| classesDefinedCount | back to summary |
|---|---|
| private final AtomicInteger classesDefinedCount | |
| NO_URLS | back to summary |
|---|---|
| private static final URL[] NO_URLS | |
| ChildClassLoader | back to summary |
|---|---|
| public ChildClassLoader(ClassLoader classLoader) | |
| defineClass | back to summary |
|---|---|
| public Class | |
| getClassesDefinedCount | back to summary |
|---|---|
| public int getClassesDefinedCount() | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ClassLoader | getClassLoader()
Overrides org. ClassLoader to be used by the default implementation of getCommonSuperClass(String, String), that of this ClassWriter's runtime type by
default.
|
| ExpressionClassWriter | back to summary |
|---|---|
| public ExpressionClassWriter() | |
| getClassLoader | back to summary |
|---|---|
| protected ClassLoader getClassLoader() Overrides org. Doc from org. Returns the
| |