agentleFS
rainoftimerainoftime/pl-skills/escape-analysis/SKILL.md

escape-analysis

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Determine if objects escape their defining scope to enable stack allocation and optimization.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Lock Elision: Remove unnecessary synchronization

    line 28
  2. Distinctive:

    Run after inlining for best results

    line 43
  3. Distinctive:

    Use for lock elision in synchronized code

    line 45
  4. Distinctive:

    Consider object size for stack allocation

    line 47
  5. Distinctive:

    When allocation cost is negligible

    line 85

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Escape 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.

When to Use This Skill

  • Optimizing memory allocation
  • Eliminating unnecessary synchronization
  • Enabling scalar replacement
  • Building JIT compilers
  • Reducing GC pressure

What This Skill Does

  1. Escape Detection: Identify objects that escape their scope
  2. Interprocedural Analysis: Track escapes through method calls
  3. Stack Allocation: Allocate non-escaping objects on stack
  4. Lock Elision: Remove unnecessary synchronization
  5. Scalar Replacement: Replace objects with scalar variables

Key Concepts

ConceptDescription
EscapeObject accessible outside its creating method
No EscapeObject stays local, can be stack-allocated
Arg EscapeObject escapes via method parameter
Global EscapeObject escapes via return or static field
Scalar ReplacementReplace object with individual fields

Tips

  • Run after inlining for best results
  • Combine with points-to analysis for precision
  • Use for lock elision in synchronized code
  • Profile to identify optimization opportunities
  • Consider object size for stack allocation

Common Use Cases

  • Stack allocation optimization
  • Lock elision (remove unnecessary synchronized)
  • Scalar replacement of aggregates
  • Reducing GC pressure
  • JVM JIT optimization

Related Skills

  • alias-and-points-to-analysis - Foundation for points-to and alias analysis
  • interprocedural-analysis - Method-level analysis
  • garbage-collector-implementer - Uses escape info
  • inline-expander - Exposes more escape opportunities

Canonical References

ReferenceWhy 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

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
IntraproceduralFastMisses interprocedural escapes
InterproceduralMore preciseExpensive
Flow-sensitiveMost preciseVery expensive

When NOT to Use This Skill

  • Programs with minimal object allocation
  • When allocation cost is negligible
  • For single-use scripts

Limitations

  • Requires whole-program analysis for full precision
  • Reflection can cause unexpected escapes
  • Native code can cause unknown escapes

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
SoundnessNever miss an escape
PrecisionMinimize false positives
EfficiencyReasonable compile time
OptimizationEnable real speedups

Quality Indicators

✅ Good: Catches all escapes, enables significant optimization ⚠️ Warning: Conservative (many false positives) ❌ Bad: Misses escapes, causes runtime errors

Research Tools & Artifacts

Real-world escape analysis implementations:

ToolWhy It Matters
Java HotSpotProduction escape analysis in JVM
J9 JVMIBM's JVM escape analysis
GraalVMTruffle-based escape analysis
V8JavaScript escape analysis
CLR.NET escape analysis

Key Papers

  • Choi et al.: Original escape analysis paper
  • Blanchet: Escape analysis improvements

Research Frontiers

Current escape analysis research:

DirectionKey PapersChallenge
Concurrency"Escape Analysis for Concurrency"Thread escape
Partial escape"Partial Escape Analysis"Some fields escape
Escape in ML"Escape Analysis for ML"Functional escape

Hot Topics

  1. Escape for parallelism: Enabling parallelism
  2. Escape for memory: Stack allocation decisions

Implementation Pitfalls

Common escape analysis bugs:

PitfallReal ExamplePrevention
ReflectionClass.forName escapesModel reflection
NativeJNI causes escapesConservative
ThreadsThread.start escapesThread analysis

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.