|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.expression.spel;
|
18 | 18 |
|
19 | 19 | /**
|
20 |
| - * Captures the possible configuration settings for a compiler that can be |
21 |
| - * used when evaluating expressions. |
| 20 | + * Captures the possible configuration settings for a compiler that can be used |
| 21 | + * when evaluating expressions. |
| 22 | + * |
| 23 | + * <p>Spring provides a basic compiler for SpEL expressions. Expressions are usually |
| 24 | + * interpreted, which provides a lot of dynamic flexibility during evaluation but does |
| 25 | + * not provide optimum performance. For occasional expression usage, this is fine, but |
| 26 | + * when used by other components such as Spring Integration, performance can be very |
| 27 | + * important, and there is no real need for the dynamism. |
| 28 | + * |
| 29 | + * <p>The SpEL compiler is intended to address this need. During evaluation, the compiler |
| 30 | + * generates a Java class that embodies the expression behavior at runtime and uses that |
| 31 | + * class to achieve much faster expression evaluation. Due to the lack of typing around |
| 32 | + * expressions, the compiler uses information gathered during the interpreted evaluations |
| 33 | + * of an expression when performing compilation. For example, SpEL does not know the type |
| 34 | + * of a property reference purely from the expression, but during the first interpreted |
| 35 | + * evaluation, it finds out what it is. Of course, basing compilation on such derived |
| 36 | + * information can cause trouble later if the types of the various expression elements |
| 37 | + * change over time. For this reason, compilation is best suited to expressions whose |
| 38 | + * type information is not going to change on repeated evaluations. |
22 | 39 | *
|
23 | 40 | * @author Andy Clement
|
| 41 | + * @author Sam Brannen |
24 | 42 | * @since 4.1
|
25 | 43 | */
|
26 | 44 | public enum SpelCompilerMode {
|
27 | 45 |
|
28 | 46 | /**
|
29 |
| - * The compiler is switched off; this is the default. |
| 47 | + * The compiler is turned off, and all expressions will be evaluated in |
| 48 | + * <em>interpreted</em> mode. |
| 49 | + * <p>This is the default. |
30 | 50 | */
|
31 | 51 | OFF,
|
32 | 52 |
|
33 | 53 | /**
|
34 |
| - * In immediate mode, expressions are compiled as soon as possible (usually after 1 interpreted run). |
35 |
| - * If a compiled expression fails it will throw an exception to the caller. |
| 54 | + * In immediate mode, expressions are compiled as soon as possible, typically |
| 55 | + * after the first interpreted evaluation. |
| 56 | + * <p>If evaluation of the compiled expression fails (for example, due to a type |
| 57 | + * changing), the caller of the expression evaluation receives an exception. |
| 58 | + * <p>If the types of various expression elements change over time, consider |
| 59 | + * switching to {@link #MIXED} mode or turning {@linkplain #OFF off} the compiler. |
36 | 60 | */
|
37 | 61 | IMMEDIATE,
|
38 | 62 |
|
39 | 63 | /**
|
40 |
| - * In mixed mode, expression evaluation silently switches between interpreted and compiled over time. |
41 |
| - * After a number of runs the expression gets compiled. If it later fails (possibly due to inferred |
42 |
| - * type information changing) then that will be caught internally and the system switches back to |
43 |
| - * interpreted mode. It may subsequently compile it again later. |
| 64 | + * In mixed mode, expression evaluation silently switches between <em>interpreted</em> |
| 65 | + * and <em>compiled</em> over time. |
| 66 | + * <p>After some number of successful interpreted runs, the expression gets |
| 67 | + * compiled. If evaluation of the compiled expression fails (for example, due |
| 68 | + * to a type changing), that failure will be caught internally, and the system |
| 69 | + * will switch back to interpreted mode for the given expression. Basically, |
| 70 | + * the exception that the caller receives in {@link #IMMEDIATE} mode is instead |
| 71 | + * handled internally. Sometime later, the compiler may generate another compiled form and switch to it. |
| 72 | + * This cycle of switching between interpreted and compiled mode will continue |
| 73 | + * until the system determines that it does not make sense to continue trying |
| 74 | + * — for example, when a certain failure threshold has been reached — |
| 75 | + * at which point the system will permanently switch to interpreted mode for the |
| 76 | + * given expression. |
44 | 77 | */
|
45 | 78 | MIXED
|
46 | 79 |
|
|
0 commit comments