Escape Analysis (EA) is a compiler analysis to answer the following questions for a given object O, method M, and thread T.
- Escapes(O, M): Does object O outlive the execution of method M? This may happen for instance if a reference to O is assigned to a global variable.
- Escapes(O, T): Does object O escape the current execution thread? This may happen for instance if a reference to O is copied to another thread.
Answers to these questions enable a compiler to perform a few highly effective optimizations, for instance, Stack Allocation (SA), Lock Elision (LE), and Scalar Replacement of Aggregates (SRA). Note that,