Top Banner
Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin
64

Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell: Bit-Encoding Online Memory Leak Detection

Michael D. Bond Kathryn S. McKinley

University of Texas at Austin

Page 2: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bugs in Deployed Software

Humans rely on software for critical tasks Bugs are costly & risky

Software more complex More bugs & harder to fix

Page 3: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bugs in Deployed Software

Humans rely on software for critical tasks Bugs are costly & risky

Software more complex More bugs & harder to fix

Bugs are a problem in deployed software In-house testing incomplete

Performance is critical Focus on space overhead

Page 4: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Why do bug tools want so much space?

Store lots of info about the program Correlate program locations (sites) & data

Ex: DirectedGraph.java:309 Tag each object with one or more sites

Last-use site Header Field 2 Field 3Field 1Alloc site

Page 5: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Why do bug tools want so much space?

Store lots of info about the program Correlate program locations (sites) & data

Ex: DirectedGraph.java:309 Tag each object with one or more sites

Bug detection applications AVIO tracks last-use site of each object Leak detection reports leaking objects’ sites

[JRockit, .NET Memory Profiler, Purify, SWAT, Valgrind]

High space overhead if many small objects

Last-use site Header Field 2 Field 3Field 1Alloc site

Page 6: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Why do bug tools want so much space?

Store lots of info about the program Correlate program locations (sites) & data

Ex: DirectedGraph.java:309 Tag each object with one or more sites

Bug detection applications AVIO tracks last-use site of each object Leak detection reports leaking objects’ sites

[JRockit, .NET Memory Profiler, Purify, SWAT, Valgrind]

High space overhead if many small objects

SWAT: 75% space overhead

on twolf

Last-use site Header Field 2 Field 3Field 1Alloc site

Page 7: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Site

How many bits do we need?

Header Field 2 Field 3Field 1

Page 8: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Site

How many bits do we need?

32 bits

Header Field 2 Field 3Field 1

Page 9: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Site

How many bits do we need?

32 bits 20 bits if # sites < 1,000,000 10 bits for common case (hot sites)

Header Field 2 Field 3Field 1

Page 10: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

How many bits do we need?

32 bits 20 bits if # sites < 1,000,000 10 bits for common case (hot sites) 1 bit?

Header Field 2 Field 3Field 1

Site

Page 11: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

How many bits do we need?

Header Field 2 Field 3Field 1

Site

32 bits 20 bits if # sites < 1,000,000 10 bits for common case (hot sites) 1 bit?

One bit loses info about site

Page 12: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

1 bit? One bit loses info about site But with many objects…

How many bits do we need?

?

1

0

1

1

0

1

1

0

0

Page 13: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell: Bit-Encoding Leak Location

Stores per-object sites in single bit Reconstructs sites by looking at

multiple objects’ bits

1

0

1

1

0

1

1

0

0

site

Page 14: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Outline

Introduction Memory leaks Bell encoding and decoding Leak detection using Bell Related work

Page 15: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Memory Leaks

Memory bugs Memory corruption: dangling refs, buffer

overflows Memory leaks

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

again

Page 16: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Memory Leaks

Memory bugs Memory corruption: dangling refs, buffer

overflows Memory leaks

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

againManaged Languages

80% of new software in Java or C# by 2010 [Gartner] Type safety & GC eliminate many bugs

Page 17: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Memory Leaks

Memory bugs Memory corruption: dangling refs, buffer

overflows Memory leaks

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

againManaged Languages

80% of new software in Java or C# by 2010 [Gartner] Type safety & GC eliminate many bugs

Page 18: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Memory Leaks

Memory bugs Memory corruption: dangling refs, buffer

overflows Memory leaks

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

againManaged Languages

80% of new software in Java or C# by 2010 [Gartner] Type safety & GC eliminate many bugs

Leaks occur in practice in managed languages [Cork, JRockit, JProbe, LeakBot, .NET

Memory Profiler]

Page 19: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Outline

Introduction Memory leaks Bell encoding and decoding Leak detection using Bell Related work

Page 20: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell’s Encoding Function

f ( , ) = 0 or 1site object

Page 21: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell’s Encoding Function

f ( , ) = 0 or 1site object

Color indicates site (ex:

allocation site)

Page 22: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell’s Encoding Function

site objectf ( , ) = 0 or 1f ( , ) = 0 or 1

site objectf ( , ) = 0 or 1

may

match

Page 23: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell’s Encoding Function

may

match

site objectf ( , ) = 0 or 1f ( , ) = 0 or 1

objectf ( , ) = 0 or 1

Probability of match is ½ unbiased function

site

Page 24: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

How do we find leaking sites?

Problem: leaking objects with unknown allocation

sites

Page 25: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

How do we find leaking sites?

site objectf ( , )

Solution: for each site, see how many objects it

matches

Page 26: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

yes

yes

yes

yes

How do we find leaking sites?

site objectf ( , )

Site matches all objects it allocated

Page 27: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

Site matches all objects it allocated

Site matches ~50% objects it didn’t

allocate

Page 28: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

Site matches all objects it allocated

Site matches ~50% objects it didn’t

allocate

yes

yes

yes

yes

matches ≈ allocObjs + ½ (leakingObjs - allocObjs)

Page 29: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

yes

yes

yes

yes

matches ≈ allocObjs + ½ (leakingObjs - allocObjs)

allocObjs ≈ 2 x matches - leakingObjs

Page 30: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

yes

yes

yes

yes

matches ≈ allocObjs + ½ (leakingObjs - allocObjs)

allocObjs ≈ 2 x matches - leakingObjs6

Page 31: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

yes

yes

yes

yes

matches ≈ allocObjs + ½ (leakingObjs - allocObjs)

allocObjs ≈ 2 x matches - leakingObjs6 9

Page 32: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

no

yes

no

yes

no

How do we find leaking sites?

site objectf ( , )

yes

yes

yes

yes

matches ≈ allocObjs + ½ (leakingObjs - allocObjs)

allocObjs ≈ 2 x matches - leakingObjs6 93

Page 33: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

Page 34: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

Page 35: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

Page 36: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

Threshold avoids reporting sites that allocated no

objects (false positives)

Page 37: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

Decoding misses sites that allocated few

objects(false negatives)

Threshold avoids reporting sites that allocated no

objects (false positives)

Page 38: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding

foreach possible matches 0 foreach potentially leaking where is possible if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

site object object

object

site

site

Dynamic type check narrows possible

objects

Page 39: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Outline

Introduction Memory leaks Bell encoding and decoding Leak detection using Bell Related work

Page 40: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Sleigh Bell encodes allocation and last-use sites Stale objects potential leaks [SWAT] Periodic decoding of highly stale objects

Leak Detection using Bell

Page 41: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Sleigh Bell encodes allocation and last-use sites Stale objects potential leaks [SWAT] Periodic decoding of highly stale objects

Implementation in Jikes RVM Find leaks in Eclipse and SPEC

JBB2000

Leak Detection using Bell

Page 42: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leak Detection using Bell

01 01

o.allocSite

o.lastUseSite

o.staleness

Page 43: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

01 01

o.allocSite

o.lastUseSite

o.staleness

Leak Detection using Bell

No space overhead since four free bits in object header

Page 44: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

01 01

Maintaining Sleigh’s Bits

o.allocSite

o.lastUseSite

o.staleness

// Object allocation:s1: o = new MyObject();

Page 45: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

01 01

Maintaining Sleigh’s Bits

o.allocSite

o.lastUseSite

o.staleness

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

Page 46: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

01 01

Maintaining Sleigh’s Bits

o.allocSite

o.lastUseSite

o.staleness

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f;

Page 47: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

01 01

Maintaining Sleigh’s Bits

o.allocSite

o.lastUseSite

o.staleness

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

Page 48: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

site site objectobject

The Encoding Function

f ( , ) := bit31 ( х )

Page 49: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

site site objectobject

The Encoding Function

f ( , ) := bit31 ( х х )object

Page 50: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

site site objectobject

Object Movement Restrictions

f ( , ) := bit31 ( х х )object

Objects may not move (Mostly) non-moving collector

Mark-sweep Generational mark-sweep

C and C++ do not move objects

Page 51: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

site site objectobject

Sleigh’s Time Overhead

f ( , ) := bit31 ( х х )object

DaCapo [Blackburn et al. ’06]

SPEC JBB2000SPEC JVM98

Page 52: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

// Object allocation:s1: o = new MyObject(); // Instrumentation: o.allocSite = f(s1, o);

// Object use:s2: tmp = o.f; // Instrumentation: o.lastUseSite = f(s2, o); o.staleness = 0;

site site objectobject

Sleigh’s Time Overhead

f ( , ) := bit31 ( х х )object

29% time overhead (11% with adaptive profiling)

DaCapo [Blackburn et al. ’06]

SPEC JBB2000SPEC JVM98

Page 53: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Finding and Fixing Leaks

Leaks in Eclipse and SPEC JBB2000

Page 54: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak

Finding and Fixing Leaks

Page 55: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak

Finding and Fixing Leaks

Page 56: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak Most interesting: stale roots

Finding and Fixing Leaks

Page 57: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak Most interesting: stale roots

many

Finding and Fixing Leaks

Page 58: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak Most interesting: stale roots

few

many

Finding and Fixing Leaks

Page 59: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak Most interesting: stale roots

Need significant number of stale data

structures

Finding and Fixing Leaks

Page 60: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leaks in Eclipse and SPEC JBB2000 Data structures leak Most interesting: stale roots Sleigh’s output directly useful for fixing

leaks

Finding and Fixing Leaks

Page 61: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Bell Decoding Again

foreach possible matches 0 foreach potentially leaking where is possible and is root of stale data structure if f ( , ) = ’s site bit matches matches + 1 allocObjs = 2 x matches – leakingObjs if allocObjs > threshold(leakingObjs) print is the site for allocObjs objects

site

object

site object object

site

site

object

Consider roots of stale data

structures only

Page 62: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Leak detectors store per-object sites [JRockit, .NET Memory Profiler, Purify, SWAT, Valgrind]

Sampling [Jump et al. ’04] Trades accuracy for lower overhead (like

Bell) Adds some overhead; requires conditional

instrumentation No encoding or decoding

Communication complexity & information theory

Related Work

Page 63: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Summary

Bell encodes sites in a single bit and decodes sites using multiple objects’ bits

Leak detection with low overhead

1

0

1

1

0

1

1

0

0

site

Page 64: Bell: Bit-Encoding Online Memory Leak Detection Michael D. Bond Kathryn S. McKinley University of Texas at Austin.

Thank You

Questions?