The CLOSER: Automating Resource Management in Java Isil Dillig - - PowerPoint PPT Presentation

the closer automating resource management in java
SMART_READER_LITE
LIVE PREVIEW

The CLOSER: Automating Resource Management in Java Isil Dillig - - PowerPoint PPT Presentation

The CLOSER: Automating Resource Management in Java The CLOSER: Automating Resource Management in Java Isil Dillig Thomas Dillig Eran Yahav Satish Chandra Computer Science Department IBM T.J. Watson Research Center Stanford University ISMM


slide-1
SLIDE 1

The CLOSER: Automating Resource Management in Java

The CLOSER: Automating Resource Management in Java

Isil Dillig Thomas Dillig Computer Science Department Stanford University Eran Yahav Satish Chandra IBM T.J. Watson Research Center ISMM 2008

slide-2
SLIDE 2

The CLOSER: Automating Resource Management in Java

Motivation

Automatic garbage collection in Java has relieved programmers from the burden of manual memory management.

slide-3
SLIDE 3

The CLOSER: Automating Resource Management in Java

Motivation

Automatic garbage collection in Java has relieved programmers from the burden of manual memory management. Unfortunately, memory is not the only resource.

slide-4
SLIDE 4

The CLOSER: Automating Resource Management in Java

Motivation

Automatic garbage collection in Java has relieved programmers from the burden of manual memory management. Unfortunately, memory is not the only resource. Operating system resources: Files, sockets, ...

slide-5
SLIDE 5

The CLOSER: Automating Resource Management in Java

Motivation

Operating System Resources public void transferData() { Socket s = new Socket(); s.connect(. . .); . . . s.close(); }

slide-6
SLIDE 6

The CLOSER: Automating Resource Management in Java

Motivation

Operating System Resources public void transferData() { Socket s = new Socket(); s.connect(. . .); . . . s.close(); }

slide-7
SLIDE 7

The CLOSER: Automating Resource Management in Java

Motivation

Automatic garbage collection in Java has relieved programmers from the burden of manual memory management. Unfortunately, memory is not the only resource. Operating system resources: Files, sockets, ... Window system resources: Fonts, colors, ...

slide-8
SLIDE 8

The CLOSER: Automating Resource Management in Java

Motivation

Window System Resources public void draw() { Font f = new Font(); . . . f.dispose(); }

slide-9
SLIDE 9

The CLOSER: Automating Resource Management in Java

Motivation

Window System Resources public void draw() { Font f = new Font(); . . . f.dispose(); }

slide-10
SLIDE 10

The CLOSER: Automating Resource Management in Java

Motivation

Automatic garbage collection in Java has relieved programmers from the burden of manual memory management. Unfortunately, memory is not the only resource. Operating system resources: Files, sockets, ... Window system resources: Fonts, colors, ... Application specific resources: Listeners, model view control pattern, ...

slide-11
SLIDE 11

The CLOSER: Automating Resource Management in Java

Motivation

Application Specific Resources public class SomeView { private SomeListener l; private WorkbenchWindow w; public void createPartControl(Composite parent) { l = new Listener(this); w.addPerspectiveListener(l); } public void dispose(){ w.removePerspectiveListener(l); } }

slide-12
SLIDE 12

The CLOSER: Automating Resource Management in Java

Motivation

Application Specific Resources public class SomeView { private SomeListener l; private WorkbenchWindow w; public void createPartControl(Composite parent) { l = new Listener(this); w.addPerspectiveListener(l); } public void dispose(){ w.removePerspectiveListener(l); } }

slide-13
SLIDE 13

The CLOSER: Automating Resource Management in Java

Generalized Definition of Resource

Definition of a Resource A resource r is an instance of any type C whose specification has the following requirement:

slide-14
SLIDE 14

The CLOSER: Automating Resource Management in Java

Generalized Definition of Resource

Definition of a Resource A resource r is an instance of any type C whose specification has the following requirement: If a method m is called with r as the receiver or parameter

slide-15
SLIDE 15

The CLOSER: Automating Resource Management in Java

Generalized Definition of Resource

Definition of a Resource A resource r is an instance of any type C whose specification has the following requirement: If a method m is called with r as the receiver or parameter Then a matching method m′ must be called after the last use of r.

slide-16
SLIDE 16

The CLOSER: Automating Resource Management in Java

Generalized Definition of Resource

Definition of a Resource A resource r is an instance of any type C whose specification has the following requirement: If a method m is called with r as the receiver or parameter Then a matching method m′ must be called after the last use of r. We call m the obligating method and m′ the fulfilling method.

slide-17
SLIDE 17

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management

slide-18
SLIDE 18

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ...

slide-19
SLIDE 19

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

slide-20
SLIDE 20

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ...

slide-21
SLIDE 21

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ... Finalization

slide-22
SLIDE 22

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ... Finalization In current JVM implementations, program might run out of non-memory resources before finalizers are called Asynchronous with respect to last use point

slide-23
SLIDE 23

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ... Finalization In current JVM implementations, program might run out of non-memory resources before finalizers are called Asynchronous with respect to last use point Language Based Solutions

slide-24
SLIDE 24

The CLOSER: Automating Resource Management in Java

Existing Approaches and Their Drawbacks

Manual Resource Management Same drawbacks as manual memory management: leaks, double disposes, ... Finalization In current JVM implementations, program might run out of non-memory resources before finalizers are called Asynchronous with respect to last use point Language Based Solutions e.g., weak references: works where premature disposal is not detrimental, but not a general solution

slide-25
SLIDE 25

The CLOSER: Automating Resource Management in Java

Goals of Our Approach

Impose minimal burden on the programmer.

slide-26
SLIDE 26

The CLOSER: Automating Resource Management in Java

Goals of Our Approach

Impose minimal burden on the programmer. Should not be limited to a fixed-class of resources.

slide-27
SLIDE 27

The CLOSER: Automating Resource Management in Java

Goals of Our Approach

Impose minimal burden on the programmer. Should not be limited to a fixed-class of resources. Should not restrict programming patterns.

slide-28
SLIDE 28

The CLOSER: Automating Resource Management in Java

Challenges

Resources may be shared.

slide-29
SLIDE 29

The CLOSER: Automating Resource Management in Java

Challenges

A Font object is shared between two Window objects:

font window1 window2

slide-30
SLIDE 30

The CLOSER: Automating Resource Management in Java

Challenges

Resources may be shared. Consequence: It is not always possible to determine the correct dispose point of the resource purely statically.

slide-31
SLIDE 31

The CLOSER: Automating Resource Management in Java

Challenges

Resources may be shared. Consequence: It is not always possible to determine the correct dispose point of the resource purely statically. Traditional notion of reachability is not adequate for reasoning about resource lifetimes.

slide-32
SLIDE 32

The CLOSER: Automating Resource Management in Java

Challenges

The reference from the Observed object to the Listener is a non-interest link:

Observer Listener Observed

slide-33
SLIDE 33

The CLOSER: Automating Resource Management in Java

Challenges

Resources may be shared. Consequence: It is not always possible to determine the correct dispose point

  • f the resource purely statically.

Traditional notion of reachability is not adequate for reasoning about resource lifetimes. Consequence: Refined notion of reachability = Interest Reachability

slide-34
SLIDE 34

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources

slide-35
SLIDE 35

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

class WorkbenchWindow { private Listener l; @Obligation(obligates = ‘‘removePerspectiveListener’’, resource=1) public void addPerspectiveListener(Listener l); . . . }

slide-36
SLIDE 36

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

class WorkbenchWindow { private Listener l; @Obligation(obligates = ‘‘removePerspectiveListener’’, resource=1) public void addPerspectiveListener(Listener l); . . . }

slide-37
SLIDE 37

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

class WorkbenchWindow { private Listener l; @Obligation(obligates = ‘‘removePerspectiveListener’’, resource=1) public void addPerspectiveListener(Listener l); . . . }

slide-38
SLIDE 38

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources the set of non-interest-links

slide-39
SLIDE 39

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

class WorkbenchWindow { @NonInterest private Listener l; @Obligation(obligates = ‘‘removePerspectiveListener’’, resource=1) public void addPerspectiveListener(Listener l); . . . }

slide-40
SLIDE 40

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources the set of non-interest-links CLOSER infers: the set of higher-level resources

slide-41
SLIDE 41

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources the set of non-interest-links CLOSER infers: the set of higher-level resources and later automatically synthesizes dispose methods.

slide-42
SLIDE 42

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources the set of non-interest-links CLOSER infers: the set of higher-level resources and later automatically synthesizes dispose methods. CLOSER statically analyzes resource lifetimes to identify how and where each resource should be disposed.

slide-43
SLIDE 43

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources the set of non-interest-links CLOSER infers: the set of higher-level resources and later automatically synthesizes dispose methods. CLOSER statically analyzes resource lifetimes to identify how and where each resource should be disposed. CLOSER automatically inserts any appropriate resource dispose calls into source code.

slide-44
SLIDE 44

The CLOSER: Automating Resource Management in Java

Resource Interest Graph

To effectively reason about resource lifetimes, CLOSER utilizes a novel flow-sensitive points-to graph, called the resource interest graph (RIG).

slide-45
SLIDE 45

The CLOSER: Automating Resource Management in Java

Resource Interest Graph

To effectively reason about resource lifetimes, CLOSER utilizes a novel flow-sensitive points-to graph, called the resource interest graph (RIG). Resource Interest Graph An RIG for a method m at a given point is a tuple V, E, σV , σE where: V is a finite set of abstract memory locations

slide-46
SLIDE 46

The CLOSER: Automating Resource Management in Java

Resource Interest Graph

To effectively reason about resource lifetimes, CLOSER utilizes a novel flow-sensitive points-to graph, called the resource interest graph (RIG). Resource Interest Graph An RIG for a method m at a given point is a tuple V, E, σV , σE where: V is a finite set of abstract memory locations E is a set of directed edges between these locations

slide-47
SLIDE 47

The CLOSER: Automating Resource Management in Java

Resource Interest Graph

To effectively reason about resource lifetimes, CLOSER utilizes a novel flow-sensitive points-to graph, called the resource interest graph (RIG). Resource Interest Graph An RIG for a method m at a given point is a tuple V, E, σV , σE where: V is a finite set of abstract memory locations E is a set of directed edges between these locations σV is a mapping from abstract memory locations to a value in 3-valued logic, identifying whether that location may, must, or must-not be a resource

slide-48
SLIDE 48

The CLOSER: Automating Resource Management in Java

Resource Interest Graph

To effectively reason about resource lifetimes, CLOSER utilizes a novel flow-sensitive points-to graph, called the resource interest graph (RIG). Resource Interest Graph An RIG for a method m at a given point is a tuple V, E, σV , σE where: V is a finite set of abstract memory locations E is a set of directed edges between these locations σV is a mapping from abstract memory locations to a value in 3-valued logic, identifying whether that location may, must, or must-not be a resource σE is a mapping from edges to a boolean value identifying whether that edge is an interest or non-interest edge

slide-49
SLIDE 49

The CLOSER: Automating Resource Management in Java

Example RIG

public class BufferPrinter { . . . public BufferPrinter(Buffer buf) { this.buf = buf; this.listener = new BufferListener(this); buf.addListener(listener); this.socket = new Socket(); socket.connect(); } }

A D B C

this socket listener buf

σv(A) =? 1 σv(B) = 1 1 σv(C) = 1 1 σv(D) =? 1 σE (e ) = 1 1 σE (e ) = 0 1

slide-50
SLIDE 50

The CLOSER: Automating Resource Management in Java

Example RIG

public class BufferPrinter { . . . public BufferPrinter(Buffer buf) { this.buf = buf; this.listener = new BufferListener(this); buf.addListener(listener); this.socket = new Socket(); socket.connect(); } }

A D B C

this socket listener buf

σv(A) =? 1 σv(B) = 1 1 σv(C) = 1 1 σv(D) =? 1 σE (e ) = 1 1 σE (e ) = 0 1

slide-51
SLIDE 51

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if:

slide-52
SLIDE 52

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T

slide-53
SLIDE 53

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T such that σV (lf) ⊒ 1

slide-54
SLIDE 54

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T such that σV (lf) ⊒ 1 σE(lT × f → lf) = true

slide-55
SLIDE 55

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T such that σV (lf) ⊒ 1 σE(lT × f → lf) = true If T is inferred to be a higher-level resource,

slide-56
SLIDE 56

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T such that σV (lf) ⊒ 1 σE(lT × f → lf) = true If T is inferred to be a higher-level resource, T ’s constructor becomes an obligating method

slide-57
SLIDE 57

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

Higher-Level Resource A class T is a higher-level resource if: there exists a field lf of some instance of T such that σV (lf) ⊒ 1 σE(lT × f → lf) = true If T is inferred to be a higher-level resource, T ’s constructor becomes an obligating method and the dispose method synthesized by CLOSER becomes the corresponding fulfilling method.

slide-58
SLIDE 58

The CLOSER: Automating Resource Management in Java

Higher-Level Resource Example

A D B C

this socket listener buf

σv(B) = 1 1 σv(C) = 1 1 σE (e ) = 1 1 σE (e ) = 0 1 σv(A) = 1 1 σv(D) = 0 1

slide-59
SLIDE 59

The CLOSER: Automating Resource Management in Java

Higher-Level Resource Example

A D B C

this socket listener buf

σv(B) = 1 1 σv(C) = 1 1 σE (e ) = 1 1 σE (e ) = 0 1 σv(A) = 1 1 σv(D) = 0 1

slide-60
SLIDE 60

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways:

slide-61
SLIDE 61

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose

slide-62
SLIDE 62

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose Dispose resource directly by calling fulfilling method No checks necessary

slide-63
SLIDE 63

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose Dispose resource directly by calling fulfilling method No checks necessary Weak (conditional) static dispose

slide-64
SLIDE 64

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose Dispose resource directly by calling fulfilling method No checks necessary Weak (conditional) static dispose Checks whether the resource’s obligating method was called before disposing it.

slide-65
SLIDE 65

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose Dispose resource directly by calling fulfilling method No checks necessary Weak (conditional) static dispose Checks whether the resource’s obligating method was called before disposing it. Dynamic dispose

slide-66
SLIDE 66

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways: Strong static dispose Dispose resource directly by calling fulfilling method No checks necessary Weak (conditional) static dispose Checks whether the resource’s obligating method was called before disposing it. Dynamic dispose Requires keeping a run-time “interest-count” Needed whenever CLOSER infers that resource may be shared.

slide-67
SLIDE 67

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it.

slide-68
SLIDE 68

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r.

slide-69
SLIDE 69

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r.

slide-70
SLIDE 70

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r.

slide-71
SLIDE 71

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r. CLOSER infers a solicitor by:

slide-72
SLIDE 72

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r. CLOSER infers a solicitor by: First computing a set of solicitor candidates from the resource interest graph for each point in the program

slide-73
SLIDE 73

The CLOSER: Automating Resource Management in Java

Solicitors

CLOSER proves a resource is unshared if it can identify a unique solicitor for it. If o is a solicitor for resource r, it has the unique responsibility to dispose r. CLOSER infers a solicitor by: First computing a set of solicitor candidates from the resource interest graph for each point in the program Then by doing data flow analysis to ensure that the inferred solicitor candidates “agree” at every program point.

slide-74
SLIDE 74

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r:

slide-75
SLIDE 75

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r: CLOSER first computes a set of paths P = l, f1 ◦ . . . ◦ fn, May/Must that reach r

slide-76
SLIDE 76

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r: CLOSER first computes a set of paths P = l, f1 ◦ . . . ◦ fn, May/Must that reach r It then applies a set of unification rules to determine the existence

  • f a canonical path l.f1...fn that may safely be used to dispose r
slide-77
SLIDE 77

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r: CLOSER first computes a set of paths P = l, f1 ◦ . . . ◦ fn, May/Must that reach r It then applies a set of unification rules to determine the existence

  • f a canonical path l.f1...fn that may safely be used to dispose r

If such a unique path exists, then l.f1...fn is designated as a solicitor candidate for r

slide-78
SLIDE 78

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r: CLOSER first computes a set of paths P = l, f1 ◦ . . . ◦ fn, May/Must that reach r It then applies a set of unification rules to determine the existence

  • f a canonical path l.f1...fn that may safely be used to dispose r

If such a unique path exists, then l.f1...fn is designated as a solicitor candidate for r If the inferred solicior candidates for r are consistent, then r is disposed through the cascading series of dispose calls initiated by l.dispose(), invoked after the last use point of l

slide-79
SLIDE 79

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

slide-80
SLIDE 80

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button

slide-81
SLIDE 81

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button ⊲ Image disposed via call chain:

slide-82
SLIDE 82

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button ⊲ Image disposed via call chain: toolBar.dispose()

slide-83
SLIDE 83

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button ⊲ Image disposed via call chain: toolBar.dispose() ↓ button.dispose()

slide-84
SLIDE 84

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button ⊲ Image disposed via call chain: toolBar.dispose() ↓ button.dispose() ↓ image.dispose()

slide-85
SLIDE 85

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code

slide-86
SLIDE 86

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code Source code transformation utilizes Eclipse JDT toolkit

slide-87
SLIDE 87

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code Source code transformation utilizes Eclipse JDT toolkit Dynamic Instrumentation: Does not rely on modifying the JVM

slide-88
SLIDE 88

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code Source code transformation utilizes Eclipse JDT toolkit Dynamic Instrumentation: Does not rely on modifying the JVM A Manager class keeps dynamic interest counts

slide-89
SLIDE 89

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code Source code transformation utilizes Eclipse JDT toolkit Dynamic Instrumentation: Does not rely on modifying the JVM A Manager class keeps dynamic interest counts The modified source code calls static methods of the Manager

slide-90
SLIDE 90

The CLOSER: Automating Resource Management in Java

Implementation

Static Analysis: Builds on IBM WALA framework for analysis of Java byte code Source code transformation utilizes Eclipse JDT toolkit Dynamic Instrumentation: Does not rely on modifying the JVM A Manager class keeps dynamic interest counts The modified source code calls static methods of the Manager CLOSER appears transparent to the programmer The programmer can inspect and change the code instrumented by CLOSER

slide-91
SLIDE 91

The CLOSER: Automating Resource Management in Java

Case Study

We applied CLOSER to automate resource management of an SWT Showcase Graphics Application

slide-92
SLIDE 92

The CLOSER: Automating Resource Management in Java

Case Study

We applied CLOSER to automate resource management of an SWT Showcase Graphics Application ∼ 7500 lines of code

slide-93
SLIDE 93

The CLOSER: Automating Resource Management in Java

Case Study

We applied CLOSER to automate resource management of an SWT Showcase Graphics Application ∼ 7500 lines of code Uses 67 different resources

slide-94
SLIDE 94

The CLOSER: Automating Resource Management in Java

Case Study

We applied CLOSER to automate resource management of an SWT Showcase Graphics Application ∼ 7500 lines of code Uses 67 different resources Reasonably complex resource management logic

slide-95
SLIDE 95

The CLOSER: Automating Resource Management in Java

Case Study

We applied CLOSER to automate resource management of an SWT Showcase Graphics Application ∼ 7500 lines of code Uses 67 different resources Reasonably complex resource management logic Manually removed all resource management code

slide-96
SLIDE 96

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

slide-97
SLIDE 97

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

User annotates only 5 resources. CLOSER infers all the remaining 62 resources.

slide-98
SLIDE 98

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

slide-99
SLIDE 99

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

Missing dispose call in the original code was a resource leak. Programmer forgot to dispose a Transpose (resource in SWT).

slide-100
SLIDE 100

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

More weak dispose calls because CLOSER is path-insensitive. Inserts redundant null-checks even though one already exists.

slide-101
SLIDE 101

The CLOSER: Automating Resource Management in Java

Case Study, Continued

private void paint() { if(image == null) { if(image!=null){ image.dispose(); } image = new Image(...); } }

slide-102
SLIDE 102

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

No shared resources in the application. CLOSER successfully identified all resources as unshared.

slide-103
SLIDE 103

The CLOSER: Automating Resource Management in Java

Case Study, Continued

Original Instrumented # Resources 67 67 # Strong Static Dispose 116 117 # Weak Static Dispose 14 63 # Dynamic Dispose # Number of Resource Bugs 1 # Lines of Resource Mgmt Code 316 356 Resource Mgmt Code to Application Size Ratio 4.2% 4.9%

CLOSER doesn’t cause code bloat or substantial runtime overhead. And it is correct by construction.

slide-104
SLIDE 104

The CLOSER: Automating Resource Management in Java

Related Work

DeLine, R., and Fahndrich, M. Enforcing high-level protocols in low-level software. In PLDI ’01: Proceedings of the ACM SIGPLAN 2001 conference on Programming language design and implementation (New York, NY, USA, 2001), ACM Press,

  • pp. 59–69.

Guyer, S., McKinley, K., and Frampton, D. Free-Me: a static analysis for automatic individual object reclamation. Proceedings of the 2006 ACM SIGPLAN conference on Programming language design and implementation (2006), 364–375. Heine, D. L., and Lam, M. S. A practical flow-sensitive and context-sensitive c and c++ memory leak detector. In PLDI ’03: Proceedings of the ACM SIGPLAN 2003 conference on Programming language design and implementation (New York, NY, USA, 2003), ACM, pp. 168–181. Blanchet, B. Escape analysis for object oriented languages. application to Javatm. In OOPSLA (Denver, 1998). Boehm, H. Destructors, finalizers, and synchronization. ACM SIGPLAN Notices 38, 1 (2003), 262–272.