Escape Analysis - Optimizations

Optimizations

A compiler can use the results of escape analysis as a basis for optimizations:

  • Converting heap allocations to stack allocations. If an object is allocated in a subroutine, and a pointer to the object never escapes, the object may be a candidate for stack allocation instead of heap allocation.
  • Synchronization elision. If an object is found to be accessible from one thread only, operations on the object can be performed without synchronization.
  • Breaking up objects or scalar replacement. An object may be found to be accessed in ways that do not require the object to exist as a sequential memory structure. This may allow parts (or all) of the object to be stored in CPU registers instead of in memory.

Read more about this topic:  Escape Analysis