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 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 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 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 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

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

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 And therefore almost never used in practice

slide-25
SLIDE 25

The CLOSER: Automating Resource Management in Java

What is Ideal Resource Management?

Dispose resource after its last use (read or write).

slide-26
SLIDE 26

The CLOSER: Automating Resource Management in Java

Is This Really ”Ideal Resource Management”?

Observer Listener Observed

slide-27
SLIDE 27

The CLOSER: Automating Resource Management in Java

Is This Really ”Ideal Resource Management”?

Observer Listener Observed

slide-28
SLIDE 28

The CLOSER: Automating Resource Management in Java

Is This Really ”Ideal Resource Management”?

Listener Observed listener.notify()

slide-29
SLIDE 29

The CLOSER: Automating Resource Management in Java

What is Ideal Resource Management?

Dispose resource after its last relevant use.

slide-30
SLIDE 30

The CLOSER: Automating Resource Management in Java

What is Ideal Resource Management?

Dispose resource after its last relevant use. Unfortunately, determining last use is impossible to do dynamically and difficult to approximate statically, especially in the case of open programs.

slide-31
SLIDE 31

The CLOSER: Automating Resource Management in Java

What is Ideal Resource Management?

Dispose resource after its last relevant use. Unfortunately, determining last use is impossible to do dynamically and difficult to approximate statically, especially in the case of open programs. Solution: Just as last use is approximated by traditional notion of reachability, we approximate last relevant use by interest reachability.

slide-32
SLIDE 32

The CLOSER: Automating Resource Management in Java

Interest Reachability

Differentiate between interest and non-interest links.

slide-33
SLIDE 33

The CLOSER: Automating Resource Management in Java

Interest Reachability

Differentiate between interest and non-interest links. If A references B through a non-interest link, then the relevant behavior of A does not depend on the existence of B.

slide-34
SLIDE 34

The CLOSER: Automating Resource Management in Java

Interest Reachability

Differentiate between interest and non-interest links. If A references B through a non-interest link, then the relevant behavior of A does not depend on the existence of B. Non-interest links must be annotated by the programmer since ”relevant” behavior defines application semantics.

slide-35
SLIDE 35

The CLOSER: Automating Resource Management in Java

Our Goal

We guarantee that a resource is disposed as soon as it becomes unreachable through interest links.

slide-36
SLIDE 36

The CLOSER: Automating Resource Management in Java

Our Goal

We guarantee that a resource is disposed as soon as it becomes unreachable through interest links.

Advantages:

slide-37
SLIDE 37

The CLOSER: Automating Resource Management in Java

Our Goal

We guarantee that a resource is disposed as soon as it becomes unreachable through interest links.

Advantages: Resource drag is much shorter compared to asynchronous approaches.

slide-38
SLIDE 38

The CLOSER: Automating Resource Management in Java

Our Goal

We guarantee that a resource is disposed as soon as it becomes unreachable through interest links.

Advantages: Resource drag is much shorter compared to asynchronous approaches. Works even if disposing the resource has visible side effect (e.g, disposal removes button from a window).

slide-39
SLIDE 39

The CLOSER: Automating Resource Management in Java

Interest Reachability

Observer Listener Observed

slide-40
SLIDE 40

The CLOSER: Automating Resource Management in Java

Interest Reachability

Observer Listener Observed

slide-41
SLIDE 41

The CLOSER: Automating Resource Management in Java

Interest Reachability

Listener Observed

slide-42
SLIDE 42

The CLOSER: Automating Resource Management in Java

Interest Reachability

Listener Observed

  • .removeListener(l)
slide-43
SLIDE 43

The CLOSER: Automating Resource Management in Java

Interest Reachability

Listener Observed

slide-44
SLIDE 44

The CLOSER: Automating Resource Management in Java

How to Achieve this Goal

Recall: We want to guarantee that a resource is disposed as soon as it becomes unreachable through interest links.

slide-45
SLIDE 45

The CLOSER: Automating Resource Management in Java

How to Achieve this Goal

To achieve this goal:

slide-46
SLIDE 46

The CLOSER: Automating Resource Management in Java

How to Achieve this Goal

To achieve this goal: Whenever possible, statically identify the first program point where resource becomes unreachable through interest links

slide-47
SLIDE 47

The CLOSER: Automating Resource Management in Java

How to Achieve this Goal

To achieve this goal: Whenever possible, statically identify the first program point where resource becomes unreachable through interest links When this is not possible, identify the correct dispose point using a variation of reference counting.

slide-48
SLIDE 48

The CLOSER: Automating Resource Management in Java

Problem: Resource Sharing

A Font object is shared between two Window objects and should be disposed when last window is closed by the user:

font window1 window2

slide-49
SLIDE 49

The CLOSER: Automating Resource Management in Java

Overview of Our Approach

The user annotates: the set of primitive resources

slide-50
SLIDE 50

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-51
SLIDE 51

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-52
SLIDE 52

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-53
SLIDE 53

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-54
SLIDE 54

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-55
SLIDE 55

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-56
SLIDE 56

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-57
SLIDE 57

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-58
SLIDE 58

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-59
SLIDE 59

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-60
SLIDE 60

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-61
SLIDE 61

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-62
SLIDE 62

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-63
SLIDE 63

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-64
SLIDE 64

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-65
SLIDE 65

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-66
SLIDE 66

The CLOSER: Automating Resource Management in Java

Higher-Level Resource

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

slide-67
SLIDE 67

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-68
SLIDE 68

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-69
SLIDE 69

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-70
SLIDE 70

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-71
SLIDE 71

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-72
SLIDE 72

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-73
SLIDE 73

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-74
SLIDE 74

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-75
SLIDE 75

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

CLOSER disposes of a resource in one of three ways:

slide-76
SLIDE 76

The CLOSER: Automating Resource Management in Java

Resource Disposal Strategies

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

slide-77
SLIDE 77

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-78
SLIDE 78

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-79
SLIDE 79

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-80
SLIDE 80

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-81
SLIDE 81

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-82
SLIDE 82

The CLOSER: Automating Resource Management in Java

Solicitors

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

slide-83
SLIDE 83

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-84
SLIDE 84

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-85
SLIDE 85

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-86
SLIDE 86

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-87
SLIDE 87

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-88
SLIDE 88

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-89
SLIDE 89

The CLOSER: Automating Resource Management in Java

Inference of Solicitors

To compute a solicitor candidate for resource r:

slide-90
SLIDE 90

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-91
SLIDE 91

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-92
SLIDE 92

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-93
SLIDE 93

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-94
SLIDE 94

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

slide-95
SLIDE 95

The CLOSER: Automating Resource Management in Java

Solicitor Example

toolBar button button image image pic

R

⊲ Inferred solicitor for R: toolBar.button

slide-96
SLIDE 96

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-97
SLIDE 97

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-98
SLIDE 98

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-99
SLIDE 99

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-100
SLIDE 100

The CLOSER: Automating Resource Management in Java

Implementation

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

slide-101
SLIDE 101

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-102
SLIDE 102

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-103
SLIDE 103

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-104
SLIDE 104

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-105
SLIDE 105

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 understand the code instrumented by CLOSER

slide-106
SLIDE 106

The CLOSER: Automating Resource Management in Java

Case Study

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

slide-107
SLIDE 107

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-108
SLIDE 108

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-109
SLIDE 109

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-110
SLIDE 110

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-111
SLIDE 111

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-112
SLIDE 112

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-113
SLIDE 113

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-114
SLIDE 114

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-115
SLIDE 115

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-116
SLIDE 116

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-117
SLIDE 117

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-118
SLIDE 118

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-119
SLIDE 119

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.