Java Zero to All All questionsPractise free
Interview questions › Interview Rapid-Fire — Top Q&A › JVM Internals — Top Interview Q&A

What is Escape Analysis?

Level III · MidJVM Internals — Top Interview Q&A
Short answer

Escape analysis is a JIT optimization that determines whether an object's lifetime escapes the method or thread that created it.

Explanation

If an object does not escape, the JIT can allocate it on the stack (or eliminate it entirely via scalar replacement, keeping its fields in registers) instead of the heap, and can remove synchronization on it (lock elision). This reduces heap allocation and GC pressure. It is enabled by default (-XX:+DoEscapeAnalysis); note it is not a guarantee — it depends on the JIT actually compiling and proving non-escape.

Common mistakes
  • Saying escape analysis allocates objects on the stack literally.
  • Not mentioning scalar replacement and lock elision.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for JVM Internals — Top Interview Q&A.

Practise free

More on JVM Internals — Top Interview Q&A