一键导入
escape-analysis
Determine if objects escape their defining scope to enable stack allocation and optimization.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Determine if objects escape their defining scope to enable stack allocation and optimization.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement abstract machines for defining and executing operational semantics of programming languages.
Implements alias and points-to analysis for pointer programs. Use for: (1) Optimizing compilers, (2) Verifying memory safety, (3) Program understanding, (4) Parallelization.
Define program meaning through logical assertions and proof rules (Hoare logic).
Transforms closures to explicit environments. Use when: (1) Implementing functional languages, (2) Building compilers, (3) Understanding closures.
Implements common subexpression elimination (CSE). Use when: (1) Building compilers, (2) Optimizing code, (3) Program analysis.
Implements general dataflow analysis framework. Use when: (1) Building compilers, (2) Static analysis tools, (3) Program verification.
| name | escape-analysis |
| description | Determine if objects escape their defining scope to enable stack allocation and optimization. |
| version | 1.0.0 |
| tags | ["analysis","optimization","memory","oopsla"] |
| difficulty | advanced |
| languages | ["java","rust","python"] |
| dependencies | ["alias-and-points-to-analysis","interprocedural-analysis"] |
Escape analysis determines whether objects allocated in a method can be accessed outside that method. This enables optimizations like stack allocation, lock elision, and scalar replacement.
| Concept | Description |
|---|---|
| Escape | Object accessible outside its creating method |
| No Escape | Object stays local, can be stack-allocated |
| Arg Escape | Object escapes via method parameter |
| Global Escape | Object escapes via return or static field |
| Scalar Replacement | Replace object with individual fields |
alias-and-points-to-analysis - Foundation for points-to and alias analysisinterprocedural-analysis - Method-level analysisgarbage-collector-implementer - Uses escape infoinline-expander - Exposes more escape opportunities| Reference | Why It Matters |
|---|---|
| Choi, Gupta, Serrano, Sreedhar, Midkiff, "Escape Analysis for Java" (OOPSLA 1999) | IBM connection graph approach |
| Blanchet, "Escape Analysis for Java: Theory and Practice" (TOPLAS 2003) | Formal correctness proof |
| Kotzmann et al., "Design of the Java HotSpot Client Compiler" (OOPSLA 2008) | Production implementation |
| Approach | Pros | Cons |
|---|---|---|
| Intraprocedural | Fast | Misses interprocedural escapes |
| Interprocedural | More precise | Expensive |
| Flow-sensitive | Most precise | Very expensive |
A high-quality implementation should have:
| Criterion | What to Look For |
|---|---|
| Soundness | Never miss an escape |
| Precision | Minimize false positives |
| Efficiency | Reasonable compile time |
| Optimization | Enable real speedups |
✅ Good: Catches all escapes, enables significant optimization ⚠️ Warning: Conservative (many false positives) ❌ Bad: Misses escapes, causes runtime errors
Real-world escape analysis implementations:
| Tool | Why It Matters |
|---|---|
| Java HotSpot | Production escape analysis in JVM |
| J9 JVM | IBM's JVM escape analysis |
| GraalVM | Truffle-based escape analysis |
| V8 | JavaScript escape analysis |
| CLR | .NET escape analysis |
Current escape analysis research:
| Direction | Key Papers | Challenge |
|---|---|---|
| Concurrency | "Escape Analysis for Concurrency" | Thread escape |
| Partial escape | "Partial Escape Analysis" | Some fields escape |
| Escape in ML | "Escape Analysis for ML" | Functional escape |
Common escape analysis bugs:
| Pitfall | Real Example | Prevention |
|---|---|---|
| Reflection | Class.forName escapes | Model reflection |
| Native | JNI causes escapes | Conservative |
| Threads | Thread.start escapes | Thread analysis |