Top Banner
Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina International Symposium on Memory Management June, 2006
57

Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Dec 30, 2015

Download

Documents

hamilton-noble

Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina. International Symposium on Memory Management June, 2006. Motivation. Memory management challenges Effective reclamation of memory (precision) Transparent to users and applications - PowerPoint PPT Presentation
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: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Compile-Time Deallocation of Individual Objects

Sigmund Cherem and Radu Rugina

International Symposium on Memory Management

June, 2006

Page 2: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Motivation

• Memory management challenges• Effective reclamation of memory (precision)• Transparent to users and applications

• Eliminate memory errors (safety)• Minimize run-time overhead (efficiency)• Support real-time systems (predictability)

• Automatic memory management• Eliminate user’s responsibilities on MM

Page 3: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

Page 4: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

No MM

Page 5: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

Manual MM

Page 6: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

Dynamic MM

Page 7: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

Dynamic MM

Compile-Time MM

Page 8: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

SafetyPrecision

Overhead

Hybrid MM

Dynamic MM

Compile-Time MM

Page 9: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Compile-Time MM

• General Idea• Estimate object lifetimes

• Reachability: objects reachable from stack variables• Ref-counts: objects with some references into them

• Liveness: objects being used

• Transform programs to deallocate objects• Regions: deallocate entire group of heap objects• Stack allocation: place objects on stack frames• Free statements: deallocate individual objects

• Our Approach• Reference count based reachability • Reclaim individual objects using “free” statements

• Flexibility, simplicity and efficiency

Page 10: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Exampleclass L { D d; L n; }

class D { int val;}

L removeVal (L x, int v) { … L p = x, c = p.n; while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n; } … return x;}

Page 11: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Page 12: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

p cn n n

d d d… …

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Page 13: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

p cn

n

n

d d d… …

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Page 14: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

p cn

n

d d d… …

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Page 15: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Running Example

p cn

n

d d d… …

Page 16: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Running Example

pn

n

d d d… …

c

Page 17: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

Running Example

p cn

n

d d d… …

Page 18: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

pn

n

d d d… …

c

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … free(c); ? c = p.n;

}

Page 19: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

pn

n

d d d… …

c

p,cn n n

d d d… …

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … free(c); ? c = p.n;

}

Page 20: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

pn

n

d d d… …

c

p,cn n n

d d d… …

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) free(c); c = p.n;

}

Page 21: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

pn

n

d d d… …

c

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) free(c); c = p.n;

}

Page 22: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

pn

n

d d d… …

c

…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { free(c.d); free(c); } c = p.n;}

Page 23: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Jfree Compiler

ReferenceCount

Analysis

InsertFree

StatementsJava

BytecodeJava

Bytecode +

Free

Page 24: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

ReferenceCount

Analysis

InsertFree

StatementsJava

BytecodeJava

Bytecode +

Free

Page 25: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Reference Count Analysis

• Determines when objects become unreachable• Compute ref-counts for each object at each

program point• Track each object to determine its reference

counts: Tracked Object Analysis• Precision: able to distinguish between object

instances• Scalability at the inter-procedural level: large

reuse of information on method summaries

• Extends shape analysis with local reasoning [HR POPL’05]

• Taking advantage of type safety in Java• Modeling Java programming practices or idioms

Page 26: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x

y

Page 27: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x

y

y, n1

Page 28: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x n1

y

y, n1

Page 29: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x n1

y

y, n1

Page 30: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x n1 d1

y

y, n1

Page 31: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x n1 d1

y

y, n1

Page 32: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

• Example concrete memory

• Abstract representation• Use one unit (configuration) to represent

individual objects• Use heap reference counts, hit expressions, and

more information about the object

• Each unit tracked independently

Reference Count Analysis

x n n

d d d d

n

x n1 d1

y

y, n1 (x.n)

Page 33: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example

p c… …

…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; …

c = p.n;

c, n1 (p.n)

Page 34: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; …

c = p.n;

p c… …

c

c, n1 (p.n)

Page 35: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; …

c = p.n;

p c… …

c

c

c, n1 (p.n)

Page 36: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; …

c = p.n;

Running Example

p c… …

c

c

c

c, n1 (p.n)

Page 37: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; …

c = p.n;

Running Example

p c… …

c

c

c

c, n1 (p.n)

Page 38: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

…while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … /* free(c); */ c = p.n;

Running Example

c

p c… …

c

c

c, n1 (p.n)

Page 39: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Other Analysis Details (I)

Abstraction Elements• More than reference counts and hit expressions• Miss expressions: expressions that don’t

reference the object• Expression equivalences: alias information

about neighbors of tracked object

Intra-procedural Analysis• Dataflow analysis that starts at allocation sites• Updates configurations on assignments• Merges some configurations at merge points

Page 40: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Other Analysis Details (II)

Inter-procedural Analysis• Split configuration in halves• Filter non-accessed information

• No need to analyze a portion not used by the callee

• Skip call if accessed portion is empty

• Add extended parameters• Helps preserving precise information about

equivalences

• Analyze callee• Record and use method summaries• Summaries are independent of caller information

• Combine• Recover and merge non-accessed information

Page 41: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

ReferenceCount

Analysis

InsertFree

StatementsJava

BytecodeJava

Bytecode +

Free

Page 42: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Transformation

• Goal : automatically insert free statements to reclaim dead objects

• Technique• At points where tracked object becomes

unreachable • Extract expression from responsible statement

e = g; free(e);

• Determine conditions for deallocation (discriminants)

• Look for hit expressions in other configurations• Find a set of expressions that distinguishes them

Page 43: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … c = p.n;

}

c, n1 (p.n)

c c, p, n1

Page 44: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if ( ??? ) { free(c); } c = p.n;}

c, n1 (p.n)

c c, p, n1

Page 45: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { free(c); } c = p.n;}

c, n1 (p.n)

c c, p, n1

Page 46: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

ReferenceCount

Analysis

InsertFree

StatementsJava

BytecodeJava

Bytecode +

Free

Page 47: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Reiteration

• Model a cascade effect of deallocations• Deallocate multiple level structures

• Model the semantics of deallocation statements• Temporarily add nullifications into code

free(x) x.f = null;

• No need to reanalyze whole program• Cleanup and recompute affected part

• Limited to finite number of iterations• Can’t deallocate recursive structures

Page 48: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { c.d = null; free(c); } c = p.n;}

Page 49: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Running Example…L p = x, c = p.n;while (c != null) { if (c.d.val == v) { p.n = c.n; c.n = null; } else p = c; … if (p != c) { free(c.d); free(c); } c = p.n;}

Page 50: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Analysis Enhancements

• Variable Equality Analysis• Infer additional equivalences that exist prior to

analysis starting point

• Variable Liveness Analysis• Increases precision by reducing object lifetimes• Allows to deallocate objects earlier

• Variable Uniqueness Analysis• No need for conditional deallocation: decide

deallocation in isolation

• Escape/effect analysis• Accelerate inter-procedural analysis by improving

filtering of information and skipping of calls

Page 51: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Experimental Evaluation

Page 52: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Settings and Analysis Times

• Jfree Compiler System • Soot infrastructure 2.2.2 • SPECjvm98 Benchmarks• Parameters for tuning speed and precision

• E.g. time cut-off to limit analysis time

• Compile-time statistics• Average application size: 547 methods • Average analysis time: 1’37’’ (default

parameters)• Libraries code is analyzed, but not transformed

• JfreeVM Runtime System • JikesRVM 2.3.5, MMTk

Page 53: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Memory Freed%

of

tota

l allo

cate

d

mem

ory

0

20

40

60

80

100compress

jess

raytrace db

javac

mpegaudio

mtrt

jack

0

20

40

60

80

100compress

jess

raytrace db

javac

mpegaudio

mtrt

jack

Default parameters

Page 54: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Memory Freed%

of

tota

l allo

cate

d

mem

ory

0

20

40

60

80

100compress

jess

raytrace db

javac

mpegaudio

mtrt

jack

0

20

40

60

80

100compress

jess

raytrace db

javac

mpegaudio

mtrt

jack

0

20

40

60

80

100compress

jess

raytrace db

javac

mpegaudio

mtrt

jack

Best parameters

Page 55: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Integration with GC

1

2

3

4

5

1.25

1.5

1 2 3 4 51.16 1.33 1.66

Normalized Memory Size

Norm

aliz

ed A

pplic

ati

on

Tim

e

MSFree + MS

Page 56: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Related Work

• Stack Allocation• Blanchet OOPLSA’99, Choi et al. OOPSLA’99, Whaley and

Rinard OOPSLA’99, Bogda and Hoelzle OOPSLA’99, Gay/Steensgard CC’00

• Regions• Tofte and Talpin POPL’94, AFL PLDI’95, • Cherem and Rugina ISMM’04, Chin et al. PLDI’04

• Individual Object Deallocation• Three-valued logic: Shaham et al. SAS’03• Pointer analysis: Guyer et al. PLDI’06

• Shape Analysis• Sagiv et al. POPL’99, Hackett and Rugina POPL’05

Page 57: Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina

Conclusions

• Reference Count Analysis in Java• Extensions to Shape Analysis w/Local Reasoning

• Inserting free statements• Conditional deallocation• Reclaiming structures

• Compiler results • 50% of memory can be reclaimed statically

• Integration with GC • 31% faster for small heaps