leak pruning

35
Leak Pruning Michael Bond Kathryn McKinley The University of Texas at Austin Presented by Na Meng Most of the slides are from Mike’s original talk. Many thanks go to the authors.

Upload: abel

Post on 24-Feb-2016

34 views

Category:

Documents


0 download

DESCRIPTION

Michael Bond Kathryn McKinley The University of Texas at Austin. Leak Pruning. Presented by Na Meng. Most of the slides are from Mike ’s original talk. Many thanks go to the authors. Motivation. Memory bugs Memory corruption: dangling pointers, double frees, buffer overflows - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Leak Pruning

Leak PruningMichael Bond Kathryn McKinley

The University of Texas at Austin

Presented by Na Meng

Most of the slides are from Mike’s original talk. Many thanks go to the authors.

Page 2: Leak Pruning

Motivation

Memory bugs Memory corruption: dangling pointers,

double frees, buffer overflows Memory leaks

▪ Lost objects: unreachable but not freed▪ Useless objects: reachable but not used

2

Managed languages

Page 3: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them

3

Reachable

Unreach

able

Page 4: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them

4

Live

ReachableDead

Page 5: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them

5

Live

ReachableDead

Page 6: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them

6

Live

Reachable

Dead

Page 7: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them Slow & crash real programs

7

LiveDead

Page 8: Leak Pruning

Motivation

Memory leaks are a real problem Managed languages do not eliminate

them Slow & crash real programs

Fixing leaks is hard Leaks take time to materialize Failure far from cause

8

Leaks exist in production software

Page 9: Leak Pruning

Leak Pruning

Possible Solutions

Precisely determine liveness of objects Liveness is in general undecidable

Approximately treat stale objects as dead

9

Page 10: Leak Pruning

Leak Pruning

10

Live

Reachable

Dead

Page 11: Leak Pruning

Leak Pruning

11

Live

Reachable

Dead

Page 12: Leak Pruning

Leak Pruning

12

Live

Reachable

Dead

Page 13: Leak Pruning

Leak Pruning

13

Live

Dead Throw OOM error

Out of memor

y!

Reachable

Page 14: Leak Pruning

Leak Pruning

14

Live

Dead

Out of memor

y!

Throw OOM error

Reclaim some

objects

Reachable

Page 15: Leak Pruning

Leak Pruning

Reclaim predicted dead objects

15

Recla

imed

Live

Page 16: Leak Pruning

Leak Pruning

Reclaim predicted dead objects

16

Recla

imed

Live

ab

Page 17: Leak Pruning

Leak Pruning

Reclaim predicted dead objects Poison references to reclaimed objects

17

Live

a?

Page 18: Leak Pruning

Leak Pruning

Reclaim predicted dead objects Poison references to reclaimed objects

18

Live

a

Page 19: Leak Pruning

Leak Pruning

Reclaim predicted dead objects Poison references to reclaimed objects

19

Live

aXThrow InternalError with OOMError attached

Page 20: Leak Pruning

Leak Pruning

Reclaim predicted dead objects Poison references to reclaimed objects

20

Live

aXThrow InternalError with OOMError attached

Worst case: defers fatal

errorsBest case: keeps leaky programs

running indefinitely

Preserves semantics

Page 21: Leak Pruning

State Diagram for Leak Pruning

21

INACTIVE

OBSERVE

SELECT PRUNE

Heap not nearly full

<50% Heap filled

>50%

Heap not full

Heap nearly full

>90%

Heap still nearly full

Page 22: Leak Pruning

OBSERVE State

Tracking staleness o.staleCounter increments from k to k +

1 after 2k garbage collections

Read barrier

22

o.staleCounter

Header001

b = a.f; //Application codeif (b & 0x1){ // Read barrier //out-of-line code path t = b; // Save ref b &= ~0x1; // Clear lowest bit a.f = b;[iff a.f == t] // Atomic b.staleCounter = 0x0; //Atomic}

How does staleCounter’s increment work?

Page 23: Leak Pruning

OBSERVE State

Maintaining edge table

23

a0

b11

srcclass tgtclass

maxStaleUse

bytesUsed

b22

A B 20b = a.f; //Application codeif (b & 0x1){ // Read barrier //out-of-line code path

t = b; // Save ref b &= ~0x1; // Clear lowest bit a.f = b;[iff a.f == t] // Atomic b.staleCounter = 0x0; //Atomic}

if (b.staleCounter > 1){//set maxStaleUse edgeTable[a.class->b.class].maxStaleUse = max(edgeTable[a.class->b.class].maxStaleUse, b.staleCounter);}

Page 24: Leak Pruning

SELECT State

Transitive Closure Phase I: in-use

transitive closure

Phase II: stale transitive closure

24

srcclass tgtclass

maxStaleUse

bytesUsed

B C 0E C 2

a10

b10

c13

roots

e10

b20

c23

d13d23

b30

c33

▪ Enque candidate ref if tgt.staleCounter > 2 + ref.maxStaleUse

▪ Compute the bytes reachable from each stale candidate

6080

Page 25: Leak Pruning

PRUNE State

In-use transitive closure Collector

poisons each reference

25

a10

b10

c13

roots

e10

b20

c23

d13d23

b30

c33

srcclass tgtclass

maxStaleUse

bytesUsed

B C 0 80E C 2

?

?

?

Page 26: Leak Pruning

Intercepting Accesses to Pruned References

26

a10

b10

roots

e10

b20b30

c33

Read barrier checks for poisoned references

b = a.f; //Application codeif (b & 0x1){ // Read barrier //out-of-line code path

if (b.staleCounter > 1){ edgeTable[a.class->b.class].maxStaleUse = max(edgeTable[a.class->b.class].maxStaleUse, b.staleCounter);}

if (b & 0x2){//Check if poisoned InternalError error = new InternalError(); err.initCause(avertedOutofMemoryError); throw err;

XThrow InternalError

?

?

?

Page 27: Leak Pruning

Evaluation

27

Leaking pruning added to Jikes RVM 2.9.2 http://www.jikesrvm.org/Research+Archi

ve Generational Mark-Sweep in MMTk Performance stress test

Non-leaking programs: Dacapo & SPEC Replay compilation

Leak tolerance test Leaking programs

Page 28: Leak Pruning

Application + Collection Overhead

28

SELECT State

5% overhead on Pentium 4 3% overhead on Core 2

Why overhead is negative for some benchmarks ?

Page 29: Leak Pruning

Garbage Collection Overhead OBSERVE State

5% SELECT State 14%

29

Page 30: Leak Pruning

Compilation Overhead

Insert read barrier 17% on average, 34% at most Negligible compared with overall

execution time

30

Page 31: Leak Pruning

Tolerating Leaks

31

Leak Leak pruning’s effect

Eclipse “Diff” Tolerates until 24-hr limit (>200X longer)

ListLeak Tolerates until 24-hr limit (>25,000X longer)

SwapLeak Tolerates until 24-hr limit (>2,200X longer)

Eclipse “Copy-Paste” Most dead but some live (81X longer)

MySQL Most dead but some live (35X longer)

JbbMod All dead but pruning misses some (21X longer)

SPECjbb2000 Heap growth is mostly live (4.7X longer)

Mckoi Database Thread leak: extra support needed (1.6X longer)

DualLeak Heap growth is live (No help)

Page 32: Leak Pruning
Page 33: Leak Pruning
Page 34: Leak Pruning
Page 35: Leak Pruning

Discussion

What about the leaked memory grows too fast?

What are the character of data structures involved with memory leak?

In addition to staleness, what else can we use to determine objects responsible for memory leak?

35