cs711 advanced programming languages shape analysis with
play

CS711 Advanced Programming Languages Shape Analysis With Tracked - PowerPoint PPT Presentation

CS711 Advanced Programming Languages Shape Analysis With Tracked Locations Radu Rugina 22 Sep 2005 Shape Analysis with Local Reasoning All previous abstractions: Describe the entire heap at once Makes inter-procedural analysis


  1. CS711 Advanced Programming Languages Shape Analysis With Tracked Locations Radu Rugina 22 Sep 2005

  2. Shape Analysis with Local Reasoning • All previous abstractions: – Describe the entire heap at once Makes inter-procedural analysis difficult – • This approach: – Idea 1: build shape analysis on top of an underlying pointer analysis – Idea 2: Reason locally about one heap cell at a time.

  3. New Memory Abstraction • Decompose memory abstraction Heap Abstraction

  4. New Memory Abstraction • Decompose memory abstraction – run pointer analysis, then shape analysis Shape analysis Shape Abstraction Pointer Region Abstraction analysis

  5. New Memory Abstraction • Decompose memory abstraction – Build shape abstraction using independent pieces Shape analysis Pointer Region Abstraction analysis

  6. New Memory Abstraction • Decompose memory abstraction – Build shape abstraction using independent pieces Shape analysis Pointer Region Abstraction analysis

  7. Configurations Configuration: Configuration: - Talk about one location: the “ tracked location ” Shape - No knowledge about analysis other locations Pointer Region Abstraction analysis

  8. Configurations Configuration: Configuration: - Reference counts from each region Shape - Hit expressions analysis - Miss expressions Pointer Region Abstraction analysis

  9. Example Abstraction Concrete Memory: x y Region Abstraction Shape Abstraction X Y L

  10. Example Abstraction Concrete Memory: x y Region Abstraction Shape Abstraction (X 1 , {x}, ø) X (L 1 Y 1 , {x->n,y}, ø) Y L (L 1 , ø, {x->n})

  11. Cyclic Structures Concrete Memory: x y Region Abstraction Shape Abstraction (X 1 , {x}, ø) X (L 1 Y 1 , {x->n,y}, ø) Y L (L 1 , ø, {x->n}) (L 2 , ø, {x->n})

  12. Analysis Example: List Reversal List *reverse(List *x) { List *t, *y; y = NULL; while (x != NULL) { t = x->n; x->n = y; y = x; Given acyclic list x : x = t; is returned list y acyclic? } return y; }

  13. List Reversal X • Region abstraction: Y L T • Acyclic list x , two configurations: – (X 1 ,{x},ø) describes list head – (L 1 , ø, ø) describes tail

  14. Loop Body Analysis X 1 ,{x} ,ø t = x->n; X 1 ,{x} ,ø x->n = y; X 1 ,{x} ,ø y = x; X 1 Y 1 ,{x,y} ,ø x = t; Y 1 ,{y} ,ø

  15. Loop Body Analysis L 1 ,ø,ø t = x->n; L 1 T 1 L 1 {t,x->n},ø ø,{x->n} x->n = y; L 1 T 1 ø,{x->n} {t},ø y = x; T 1 L 1 {t},ø ø,{x->n} x = t; T 1 X 1 L 1 {t,x},ø ø,ø

  16. Analysis Result List *reverse(List *x) { List *t, *y; X 1 L 1 y = NULL; while (x != NULL) { X 1 T 1 X 1 L 1 Y 1 t = x->next; X 1 L 1 T 1 L 1 Y 1 x->next = y; X 1 T 1 L 1 Y 1 L 1 y = x; X 1 Y 1 T 1 L 1 x = t; } Y 1 T 1 X 1 L 1 return y; } Y 1 L 1

  17. Analysis Result List *reverse(List *x) { List *t, *y; X 1 L 1 y = NULL; while (x != NULL) { X 1 T 1 X 1 L 1 Y 1 t = x->next; X 1 L 1 T 1 L 1 Y 1 x->next = y; X 1 T 1 L 1 Y 1 L 1 y = x; X 1 Y 1 T 1 L 1 x = t; } Y 1 T 1 X 1 L 1 return y; } Y 1 L 1

  18. Property Verified List *reverse(List *x) { List *t, *y; Acyclic input X 1 L 1 y = NULL; while (x != NULL) { X 1 T 1 X 1 L 1 Y 1 t = x->next; X 1 L 1 T 1 L 1 Y 1 x->next = y; X 1 T 1 L 1 Y 1 L 1 y = x; X 1 Y 1 T 1 L 1 x = t; } Y 1 T 1 X 1 L 1 return y; } Y 1 L 1 Acyclic output

  19. Cyclic Input x reverse y

  20. Cyclic Input x reverse y

  21. Cyclic Input Analysis: x X 1 L 1 L 2 reverse y Y 1 L 1 L 2

  22. Analysis Algorithm • Phase 1: Pointer Analysis – Flow-insensitive, unification-based – Context-sensitive • Phase 2: Shape Analysis – Intra and inter-procedural – Flow-sensitive, context-sensitive – Granularity of configurations

  23. Inter-Procedural Shape Analysis • Context-sensitive analysis • Summary input = a configuration • Summary output = set of configurations that correspond to the input foo() input output • Tag configurations with the input they originated from – Output = retrieve configurations with the desired tag

  24. Inter-Procedural Shape Analysis • Efficient: reuse previous analyses of functions – Match individual configurations! • Not entire heap abstractions – Works even if there is only partial redundancy Abstraction at Abstraction at a call site a different site Reuse!

  25. Detecting Memory Errors • For languages with explicit de-allocation – free( e ) de-allocates cell referenced by e Reference counts • Extend configurations with one bit: Hit expressions has the tracked cell been de-allocated? Miss expressions – malloc() sets bit to false Freed flag – free() sets bit to true – Keep tracking cells even after de-allocation

  26. Detecting Memory Errors • Dereference * e may be unsafe if: – Expression e may reference the tracked locations – And tracked location is marked as de-allocated – Catches double frees: free( e ) checked as * e • A potential memory leak occurs if: – The tracked location has all reference counts zero – And not marked as de-allocated – Allocated in the current function

  27. Implementation • Implementation for C programs in SUIF • Singly linked lists – Handles standard list manipulations: insert, append, swap, reverse, quicksort, insertionsort . • Doubly linked lists – Does not identify structural invariants

  28. Implementation • Tested tool on three larger programs: SSH SSL binutils Lines 18.6 KLOC 25.6 KLOC 24.4 KLOC Reported 26 13 58 Bugs 10 4 24 Total Time 45 sec 22 sec 44 sec Points-to 16 sec 13 sec 6 sec Shape 29 sec 9 sec 38 sec

  29. Comparison Analysis/Year Implemented? Inter-Procedural? size(LOC), time(sec) Jones, Muchnick / 1979 no Chase, Wegman,Zadeck / no 1990 Ghiya, Hendren /1996 YES YES 3.3 K, n/a Sagiv, Reps,Wilhelm /1996 no Sagiv, Reps,Wilhelm /1999 no < 30, 295 Lev-Ami, Reps, Sagiv, YES no Wilhelm/2000 < 30, 2 Dor, Rodeh, Sagiv/2000 YES no < 30, 1028 Rinetzky, Sagiv /2001 YES YES < 30, 222 Jeannet, Loginov, Reps, YES YES Sagiv /2004 Yahav, Ramalingam /2004 YES YES 1.3K, 12881 Hackett/Rugina /2005 YES YES 25 K, 45

  30. Summary • Shape analysis: – Needed for precise analysis of heap structures – Necessarily flow-sensitive – Not scalable until recently

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