Program Analysis Last Lesson Mooly Sagiv. Goals u Show the significance of set constraints for CFA of Object Oriented Programs u Sketch advanced techniques.

Slides:



Advertisements
Similar presentations
Abstract Interpretation Part II
Advertisements

Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
Inferring Disjunctive Postconditions Corneliu Popeea and Wei-Ngan Chin School of Computing National University of Singapore - ASIAN
Tutorial on Widening (and Narrowing) Hongseok Yang Seoul National University.
Compiling Object Oriented Programs Mooly Sagiv Chapter
Review of topics Final exam : -May 2nd to May 7 th - Projects due on May 7th.
Foundations of Data-Flow Analysis. Basic Questions Under what circumstances is the iterative algorithm used in the data-flow analysis correct? How precise.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Program analysis Mooly Sagiv html://
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
From last time: live variables Set D = 2 Vars Lattice: (D, v, ?, >, t, u ) = (2 Vars, µ, ;,Vars, [, Å ) x := y op z in out F x := y op z (out) = out –
1 Iterative Program Analysis Part I Mooly Sagiv Tel Aviv University Textbook: Principles of Program.
Data Flow Analysis Compiler Design Nov. 3, 2005.
Program analysis Mooly Sagiv html://
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
1 Iterative Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
Interprocedural Analysis Noam Rinetzky Mooly Sagiv Tel Aviv University Textbook Chapter 2.5.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs, Data-flow Analysis Data-flow Frameworks --- today’s.
From last lecture x := y op z in out F x := y op z (in) = in [ x ! in(y) op in(z) ] where a op b =
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Overview of program analysis Mooly Sagiv html://
1 Program Analysis Systematic Domain Design Mooly Sagiv Tel Aviv University Textbook: Principles.
Prof. Aiken CS 294 Lecture 21 Abstract Interpretation Part 2.
From last lecture We want to find a fixed point of F, that is to say a map m such that m = F(m) Define ?, which is ? lifted to be a map: ? = e. ? Compute.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Overview of program analysis Mooly Sagiv html://
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
1 Tentative Schedule u Today: Theory of abstract interpretation u May 5 Procedures u May 15, Orna Grumberg u May 12 Yom Hatzamaut u May.
Example x := read() v := a + b x := x + 1 w := x + 1 a := w v := a + b z := x + 1 t := a + b.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 12: Abstract Interpretation IV Roman Manevich Ben-Gurion University.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 13: Abstract Interpretation V Roman Manevich Ben-Gurion University.
Compilation Lecture 8 Abstract Interpretation Noam Rinetzky 1.
Compiler Principles Fall Compiler Principles Lecture 11: Loop Optimizations Roman Manevich Ben-Gurion University.
1 Combining Abstract Interpreters Mooly Sagiv Tel Aviv University
Program Analysis and Verification
Program Analysis and Verification
1 Iterative Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
1 Numeric Abstract Domains Mooly Sagiv Tel Aviv University Adapted from Antoine Mine.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Iterative Program Analysis Part II Mathematical Background Mooly Sagiv Tel Aviv University
Chaotic Iterations Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Chaotic Iterations Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 8: Static Analysis II Roman Manevich Ben-Gurion University.
Spring 2016 Program Analysis and Verification
Textbook: Principles of Program Analysis
Combining Abstract Interpreters
Symbolic Implementation of the Best Transformer
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Iterative Program Analysis Abstract Interpretation
Another example: constant prop
Program Analysis and Verification
Flow Analysis Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM.
Data Flow Analysis Compiler Design
Pointer analysis.
Presentation transcript:

Program Analysis Last Lesson Mooly Sagiv

Goals u Show the significance of set constraints for CFA of Object Oriented Programs u Sketch advanced techniques u Summarize the course u Get some feedback

A Motivating Example class Vehicle Object { int position = 10; void move(x1 : int) { position = position + x1 ;}} class Car extends Vehicle { int passengers; void await(v : Vehicle) { if (v.position < position) then v.move(position - v.position); else self.move(10); }} class Truck extends Vehicle { void move(x2 : int) { if (x2 < 55) position = position + x2; }} void main { Car c; Truck t; Vehicle v1; new c; new t; v1 := c; c.passengers := 2; c.move(60); v1.move(70); c.await(t) ;}

A Motivating Example class Vehicle Object { int position = 10; void move(x1 : int) { position = position + x1 ;}} class Car extends Vehicle { int passengers; void await(v {Truck} : Vehicle) { if (v {Truck}.position < position) then v {Truck}.move(position - v.position); else self {Car}.move(10); }} class Truck extends Vehicle { void move(x2 : int) { if (x2 < 55) position = position + x2; }} void main { Car c; Truck t; Vehicle v1; new c {Car} ; new t {Truck} ; v1 {Car} := c {Car} ; c {Car}.passengers := 2; c {Car}.move(60); v1 {Car}.move(70); c {Car}.await(t {Truck} ) ;}

Flow Insensitive Class Analysis u Determine the set of potential classes of every variable at every program point u Compute a mapping  from variables into a set of class names u Combine values of variables at different points u Generate a set of constraints for every statement u Find a minimal solution

A Motivating Example class Vehicle Object { int position = 10; void move(x1 : int) { position = position + x1 ;}} class Car extends Vehicle { int passengers; void await(v1 : Vehicle) { if (v1.position < position) then v1.move(position - v1.position); else self.move(10); }} class Truck extends Vehicle { void move(x2 : int) { if (x2 < 55) position = position + x2; }} void main { Car c; Truck t; Vehicle v2; new c; new t; v2 := c; c.passengers := 2; c.move(60); v2.move(70); c.await(t) ; } {Car}   (c) {Truck}   (t)  (c)   (v2) {Car}   (c)   (t)   (v1)

Class Analysis Summary u Resolve called function u Can also perform type inference and checking u Can be used to warn against programmer errors at compile-time

Set Constraints Summary u Can be used to generate a flow sensitive solution u Can also handle sets of “terms” –Finite set of constructors C={b, c, …} –Finite set of variables –Set expressions E ::=  | variable | E 1  E 2 | E 1  E 2 | c(E 1, E 2,…, E k )| c -i (E) –Finite set of inequalities E 1  E 2 –Find the least solution (or a symbolic representation)

Advanced Abstract Interpretation Techniques u Origin [Cousot&Cousot POPL 1979] Download from the course homepage u Widening & Narrowing u Combining dataflow analysis problems u Semantic reductions u...

Widening u Accelerate the termination of Chaotic iterations by computing a more conservative solution u Can handle lattices of infinite heights

Example Interval Analysis u Find a lower and an upper bound of the value of a variable u Lattice L = (Z  Z, , , , ,  ) –[a, b]  [c, d] if c  a and d  b –[a, b]  [c, d] = [min(a, c), max(b, d)] –[a, b]  [c, d] = [max(a, c), min(b, d)] –  = –  = u Program x := 1 ; while x  1000 do x := x + 1;

Widening for Interval Analysis u   [c, d] = [c, d] u [a, b]  [c, d] = [ if a  c then a else if 0  c then 0 else minint, if b  d then b else if d  0 then 0 else maxint

Chaotic Iterations for forward problems+  for l  Lab * do DF entry (l) :=  DF exit (l) :=  DF entry (init(S * )) :=  WL= Lab * while WL !=  do Select and remove an arbitrary l  WL if (temp != DF exit (l)) DF exit (l) := DF exit (l)  temp for l' such that (l,l')  flow(S*) do DF entry (l') := DF entry (l')  DF exit (l) WL := WL  {l’}

Example [x := 1] 1 ; while [x  1000] 2 do [x := x + 1] 3 ;

Requirements on Widening u For all elements l 1  l 2  l 1  l 2 u For all ascending chains l 0  l 1  l 2  … the following sequence is finite –y 0 = l 0 –y i+1 = y i  l i+1

Narrowing u Improve the result of widening

Example [x := 1] 1 ; while [x  1000] 2 do [x := x + 1] 3 ;

Widening and Narrowing Summary u Very simple but produces impressive precision u The McCarthy 91 function u Also useful in the finite case u Can be used as a methodological tool u But not widely accepted int f(x) if x > 100 then return x -10 else return f(f(x+11))

Combining dataflow analysis problems u How to combine different analyses u The result can be more precise than both! u On some programs more efficient too u Many possibly ways to combine (4.4) u A simple example sign+parity analysis x := x - 1

Cartezian Products u Analysis 1 –Lattice (L 1,  1,  1,  1,  1,  1 ) –Galois connection  1 : P(States)  L 1  1 : L 1  P(States) –Transfer functions op 1 :L 1  L 1 u Analysis 2 –Lattice (L 2,  2,  2,  2,  2,  2 ) –Galois connection  2 : P(States)  L 2  1 : L 2  P(States) –Transfer functions op 2 :L 2  L 2 u Combined Analysis –L = (L 1  L 2,  ) where (l 1, l 2 )  (u 1, u 2 ) if l 1  1 u 1 and l 2  2 u 2 –Galois connection –Transfer functions

Course Summary u Techniques Studied –Operational Semantics –Dataflow Analysis and Monotone Frameworks (Imperative Programs) –Control Flow Analysis and Set Constraints (Functional Programs) u Techniques Sketched –Abstract interpretation –Interprocedural Analysis –Type and effect systems u Not Covered –Efficient algorithms –Applications in compilers –Logic programming

Course Summary u Able to understand advanced static analysis techniques u Find faults in existing algorithms u Be able to develop new algorithms u Gain a better understanding of programming languages –Functional Vs. Imperative –Operational Semantics

Feedback