the closer automating resource management in java
play

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


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

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

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

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

  5. 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) .

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

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

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

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

  10. this σ E (e ) = 1 A σ E (e ) = 0 σ v (A) =? buf socket listener B C D σ v (B) = 1 σ v (C) = 1 σ v (D) =? 1 1 1 1 1 1 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(); } }

  11. The CLOSER: Automating Resource Management in Java Example RIG this σ E (e ) = 1 public class BufferPrinter { A σ E (e ) = 0 σ v (A) =? . . . public BufferPrinter(Buffer buf) { this.buf = buf; buf socket this.listener = listener new BufferListener(this); buf.addListener(listener); B C D this.socket = new Socket(); socket.connect(); σ v (B) = 1 } σ v (C) = 1 σ v (D) =? } 1 1 1 1 1 1

  12. The CLOSER: Automating Resource Management in Java Higher-Level Resource Higher-Level Resource A class T is a higher-level resource if:

  13. 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 l f of some instance of T

  14. 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 l f of some instance of T such that σ V ( l f ) ⊒ 1

  15. 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 l f of some instance of T such that σ V ( l f ) ⊒ 1 σ E ( l T × f → l f ) = true

  16. 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 l f of some instance of T such that σ V ( l f ) ⊒ 1 σ E ( l T × f → l f ) = true If T is inferred to be a higher-level resource,

  17. 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 l f of some instance of T such that σ V ( l f ) ⊒ 1 σ E ( l T × f → l f ) = true If T is inferred to be a higher-level resource, T ’s constructor becomes an obligating method

  18. 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 l f of some instance of T such that σ V ( l f ) ⊒ 1 σ E ( l T × f → l f ) = 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.

  19. The CLOSER: Automating Resource Management in Java Higher-Level Resource Example this σ E (e ) = 1 A σ E (e ) = 0 σ v (A) = 1 socket buf listener B C D σ v (B) = 1 σ v (C) = 1 σ v (D) = 0 1 1 1 1 1 1

  20. The CLOSER: Automating Resource Management in Java Higher-Level Resource Example this σ E (e ) = 1 A σ E (e ) = 0 σ v (A) = 1 socket buf listener B C D σ v (B) = 1 σ v (C) = 1 σ v (D) = 0 1 1 1 1 1 1

  21. The CLOSER: Automating Resource Management in Java Resource Disposal Strategies CLOSER disposes of a resource in one of three ways:

  22. The CLOSER: Automating Resource Management in Java Resource Disposal Strategies CLOSER disposes of a resource in one of three ways: Strong static dispose

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

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

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

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

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

  28. The CLOSER: Automating Resource Management in Java Solicitors CLOSER proves a resource is unshared if it can identify a unique solicitor for it.

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

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

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

  32. 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:

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

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

  35. The CLOSER: Automating Resource Management in Java Inference of Solicitors To compute a solicitor candidate for resource r :

  36. 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, f 1 ◦ . . . ◦ f n , May / Must � that reach r

  37. 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, f 1 ◦ . . . ◦ f n , May / Must � that reach r It then applies a set of unification rules to determine the existence of a canonical path l.f 1 ...f n that may safely be used to dispose r

  38. 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, f 1 ◦ . . . ◦ f n , May / Must � that reach r It then applies a set of unification rules to determine the existence of a canonical path l.f 1 ...f n that may safely be used to dispose r If such a unique path exists, then l.f 1 ...f n is designated as a solicitor candidate for r

  39. 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, f 1 ◦ . . . ◦ f n , May / Must � that reach r It then applies a set of unification rules to determine the existence of a canonical path l.f 1 ...f n that may safely be used to dispose r If such a unique path exists, then l.f 1 ...f n 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

  40. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar button button image image pic R

  41. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar ⊲ Inferred solicitor for R: toolBar.button button button image image pic R

  42. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar ⊲ Inferred solicitor for R: toolBar.button button button ⊲ Image disposed via call chain: image image pic R

  43. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar ⊲ Inferred solicitor for R: toolBar.button button button ⊲ Image disposed via call chain: toolBar.dispose() image image pic R

  44. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar ⊲ Inferred solicitor for R: toolBar.button button button ⊲ Image disposed via call chain: toolBar.dispose() ↓ button.dispose() image image pic R

  45. The CLOSER: Automating Resource Management in Java Solicitor Example toolBar ⊲ Inferred solicitor for R: toolBar.button button button ⊲ Image disposed via call chain: toolBar.dispose() ↓ button.dispose() image image ↓ image.dispose() pic R

  46. The CLOSER: Automating Resource Management in Java Implementation Static Analysis: Builds on IBM WALA framework for analysis of Java byte code

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

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

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

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

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

  52. The CLOSER: Automating Resource Management in Java Case Study We applied CLOSER to automate resource management of an SWT Showcase Graphics Application

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

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

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

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

  57. 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 0 0 # Number of Resource Bugs 1 0 # Lines of Resource 316 356 Mgmt Code Resource Mgmt Code 4.2% 4.9% to Application Size Ratio

  58. 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 0 0 # Number of Resource Bugs 1 0 # Lines of Resource 316 356 Mgmt Code Resource Mgmt Code 4.2% 4.9% to Application Size Ratio User annotates only 5 resources. CLOSER infers all the remaining 62 resources.

  59. 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 0 0 # Number of Resource Bugs 1 0 # Lines of Resource 316 356 Mgmt Code Resource Mgmt Code 4.2% 4.9% to Application Size Ratio

  60. 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 0 0 # Number of Resource Bugs 1 0 # Lines of Resource 316 356 Mgmt Code Resource Mgmt Code 4.2% 4.9% to Application Size Ratio Missing dispose call in the original code was a resource leak. Programmer forgot to dispose a Transpose (resource in SWT).

  61. 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 0 0 # Number of Resource Bugs 1 0 # Lines of Resource 316 356 Mgmt Code Resource Mgmt Code 4.2% 4.9% to Application Size Ratio More weak dispose calls because CLOSER is path-insensitive. Inserts redundant null-checks even though one already exists.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend