Questions tagged [escape-analysis]

Escape analysis determines all the places where a pointer can be stored and whether the lifetime of the pointer can be proven to be restricted only to the current procedure and/or thread.

In programming language compiler optimization theory, escape analysis is a method for determining the dynamic scope of pointers. It is related to pointer analysis and shape analysis.

When a variable (or an object) is allocated in a subroutine, a pointer to the variable can escape to other threads of execution, or to calling subroutines. If an implementation uses tail call optimization (usually required for functional languages), objects may also be seen as escaping to called subroutines. If a language supports first-class continuations (as do Scheme and Standard ML of New Jersey), portions of the call stack may also escape.

If a subroutine allocates an object and returns a pointer to it, the object can be accessed from undetermined places in the program — the pointer has "escaped". Pointers can also escape if they are stored in global variables or other data structures that, in turn, escape the current procedure.

Escape analysis determines all the places where a pointer can be stored and whether the lifetime of the pointer can be proven to be restricted only to the current procedure and/or thread.

More links:

36 questions
38
votes
3 answers

Escape analysis in Java

As far as I know the JVM uses escape analysis for some performance optimisations like lock coarsening and lock elision. I'm interested if there is a possibility for the JVM to decide that any particular object can be allocated on stack using escape…
Denis Bazhenov
  • 9,680
  • 8
  • 43
  • 65
17
votes
3 answers

Escape analysis in the .NET CLR VM

Is there any escape analysis performed by the CLR compiler/JIT? For example, in Java it appears that a loop variable an object allocated in a loop that doesn't escape the loop gets allocated on the stack rather than the heap (see Escape analysis in…
SimonC
  • 6,590
  • 1
  • 23
  • 40
12
votes
3 answers

Eligibility for escape analysis / stack allocation with Java 7

I am doing some tests with escape analysis in Java 7 in order to better understand what objects are eligible to stack allocation. Here is the code I wrote to test stack allocation: import java.util.ArrayList; import java.util.Iterator; public…
jpountz
  • 9,904
  • 1
  • 31
  • 39
9
votes
1 answer

Variadic functions causing unnecessary heap allocations in Go

I'm currently working on some performance sensitive code in Go. At one point I have a particularly tight inner loop which does three things in succession: Obtain several pointers to data. In the event of a rare error, one or more of these pointers…
8
votes
1 answer

What is the meaning of 'leak/leaking param' in Golang Escape Analysis

func main() { i1 := 1 A1(&i1) } func A1(i1 *int) *int { return i1 } And the result of escape analysis is ./main.go:18:9: parameter i1 leaks to \~r1 with derefs=0: ./main.go:18:9: flow: \~r1 = i1: ./main.go:18:9: from return…
MungBeanSoup
  • 99
  • 1
  • 5
8
votes
1 answer

Why getSum does not get inlined by hotspot jvm?

Here's the example I tried to reproduce from Java Performance: The Definitive Guide, Page 97 on the topic of Escape Analysis. This is probably what should happen: getSum() must get hot enough and with appropriate JVM parameters it must be inlined…
NiMa Thr
  • 458
  • 3
  • 12
8
votes
1 answer

Does the android dalvik vm use escape analysis optimization?

Any ideas about escape analysis in dalvik? Or when and if it's planned to be added? I consider escape analysis a very important feature in GC languages to avoid churning out objects every time a method is called, and currently I preallocate an…
user965980
  • 187
  • 7
7
votes
2 answers

static java bytecode optimizer (like proguard) with escape analysis?

Optimizations based on escape analysis is a planned feature for Proguard. In the meantime, are there any existing tools like proguard that already do optimizations which require escape analysis?
Jeremy Bell
  • 5,253
  • 5
  • 41
  • 63
7
votes
3 answers

Experiences with escape analysis enabled on the JVM

I've just tried the -XX:+DoEscapeAnalysis option enabled on a jdk6-u18 VM (on solaris) and had a rather disappointing experience. I'm running a scala application which has rather a lot of actors (20,000 of them). This is a recipe for…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
5
votes
1 answer

Escape analysis

In many languages, local variables are located in call stack In JavaScript/Python, only closure variables are located in heap, because they must live beyond the function calls, they are created. In GO, some GO types(like slice type []int) do…
overexchange
  • 15,768
  • 30
  • 152
  • 347
4
votes
2 answers

how fragile is escape analysis in Hotspot in simple cases such as iterator in for-each loop

Suppose I have a java.util.Collection that I want to loop over. Normally I'd do this: for(Thing thing : things) do_something_with(thing); But suppose that this is in some core utility method that is used all over the place, and in most places, the…
Mark VY
  • 1,489
  • 16
  • 31
4
votes
0 answers

Escape Analysis and stack allocation optimization improvements in JAVA 9 and beyond

Are the rules for stack allocation optimization less strict for HotSpot Java 9-13 ? In Java 7 & Java 8 HotSpot stack allocation of objects (due to JVM optimization known as scalar object replacement) is possible but to achieve garbage free…
4
votes
1 answer

Does Hotspot JVM perform Escape Analysis during On Stack Replacement compilation?

Consider the following code: void methodWithOSR() { Foo foo = new Foo(); // this object doesn't escape for (int i = 0; i < 1_000_000; i++) { // some code that uses `foo` } } Is Hotspot JVM able to scalarize foo on the stack,…
leventov
  • 14,760
  • 11
  • 69
  • 98
3
votes
1 answer

What is the meaning of the output from 'go run -gcflags -m xxx.go'

Trying to check whether a local variable is allocated on heap or stack in go program, and can't be sure the meaning of some output from go's gc. Code variable_heap_stack.go: // variable heap & stack learn, // run with: // go run -gcflags -m…
Eric
  • 22,183
  • 20
  • 145
  • 196
3
votes
2 answers

What is considered "small" object in Go regarding stack allocation?

The code: func MaxSmallSize() { a := make([]int64, 8191) b := make([]int64, 8192) _ = a _ = b } Then run go build -gcflags='-m' . 2>&1 to check memory allocation details. The result: ./mem.go:10: can inline MaxSmallSize ./mem.go:12:…
Bryce
  • 3,046
  • 2
  • 19
  • 25
1
2 3