Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

R O O T S Field-Sensitive Points-to-Analysis Eda GÜNGÖR
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Pointer Analysis.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Programming Languages and Paradigms
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Demand-driven Alias Analysis Implementation Based on Open64 Xiaomi An
Flow insensitive pointer analysis: fixed S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Pointer Analysis.
Refinement-Based Context-Sensitive Points-To Analysis for JAVA Soonho Kong 17 January Work of Manu Sridharan and Rastislav Bodik, UC Berkeley.
Symbolic execution © Marcelo d’Amorim 2010.
Program Representations. Representing programs Goals.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Parameterized Object Sensitivity for Points-to Analysis for Java Presented By: - Anand Bahety Dan Bucatanschi.
Semi-Sparse Flow-Sensitive Pointer Analysis Ben Hardekopf Calvin Lin The University of Texas at Austin POPL ’09 Simplified by Eric Villasenor.
Interprocedural analysis © Marcelo d’Amorim 2010.
Pointer and Shape Analysis Seminar Context-sensitive points-to analysis: is it worth it? Article by Ondřej Lhoták & Laurie Hendren from McGill University.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Runtime Environments Source language issues Storage organization
Interprocedural pointer analysis for C We’ll look at Wilson & Lam PLDI 95, and focus on two problems solved by this paper: –how to represent pointer information.
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
Run time vs. Compile time
Intraprocedural Points-to Analysis Flow functions:
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Overview of program analysis Mooly Sagiv html://
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
Reps Horwitz and Sagiv 95 (RHS) Another approach to context-sensitive interprocedural analysis Express the problem as a graph reachability query Works.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Dagstuhl Seminar "Applied Deductive Verification" November Symbolically Computing Most-Precise Abstract Operations for Shape.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
Fast Points-to Analysis for Languages with Structured Types Michael Jung and Sorin A. Huss Integrated Circuits and Systems Lab. Department of Computer.
Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Mark Marron 1, Deepak Kapur 2, Manuel Hermenegildo 1 1 Imdea-Software (Spain) 2 University of New Mexico 1.
Mark Marron IMDEA-Software (Madrid, Spain) 1.
ESEC/FSE-99 1 Data-Flow Analysis of Program Fragments Atanas Rountev 1 Barbara G. Ryder 1 William Landi 2 1 Department of Computer Science, Rutgers University.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Pointer Analysis Survey. Rupesh Nasre. Aug 24, 2007.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Pointer Analysis – Part I CS Pointer Analysis Answers which pointers can point to which memory locations at run-time Central to many program optimization.
5/7/03ICSE Fragment Class Analysis for Testing of Polymorphism in Java Software Atanas (Nasko) Rountev Ohio State University Ana Milanova Barbara.
Sept 12ICSM'041 Precise Identification of Side-Effect-Free Methods in Java Atanas (Nasko) Rountev Ohio State University.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Inter-procedural analysis
Spring 2016 Program Analysis and Verification
Pointer Analysis Lecture 2
Ravi Mangal Mayur Naik Hongseok Yang
Topic 17: Memory Analysis
Amir Kamil and Katherine Yelick
Objective of This Course
Demand-Driven Context-Sensitive Alias Analysis for Java
Pointer Analysis Lecture 2
Pointer analysis.
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
Amir Kamil and Katherine Yelick
Pointer Analysis Jeff Da Silva Sept 20, 2004 CARG.
Pointer analysis John Rollinson & Kaiyuan Li
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009

Pointer Analysis Answers which pointers may point to which memory locations Lies at the heart of many program optimization and verification problems Problem is undecidable But many conservative approximations exist Continues to be active area of research

Example Java Program class Link { T data; Link next; } class List { T tail; void append(T c) { Link k = new Link (); k.data = c; Link t = this.tail; if ( t.next = k; this.tail = k; } t != null) static void main() { String[] a = new String[] { “a1”, “a2” }; String[] b = new String[] { “b1”, “b2” }; List l; l = new List (); for ( String v1 = a[i]; l.append(v1); } print(l); l = new List (); for ( String v2 = b[i]; l.append(v2); } print(l); } int i = 0; i < a.length; i++) { int i = 0; i < b.length; i++) {

Flow sensitivity –flow-insensitive: ignores intra-procedural control flow Heap abstraction Aggregate modeling Context sensitivity 0-CFA Pointer Analysis for Java

static void main() { String[] a = new String[] { “a1”, “a2” } String[] b = new String[] { “b1”, “b2” } List l l = new List () for ( String v1 = a[ ] l.append(v1) } l = new List () for ( String v2 = b[ ] l.append(v2) } } ; ; * int i = 0; i < a.length; i++) { int i = 0; i < b.length; i++) { Flow Insensitivity: Example class Link { T data; Link next; } class List { T tail; void append(T c) { Link k = new Link () k.data = c Link t = this.tail if ( t.next = k this.tail = k } } ; ; ; ; ; ; ; ; ; ; *) t != null)*) i i * ; ;

class List { T tail; void append(T c) { Link k = new Link () k.data = c Link t = this.tail t.next = k this.tail = k } static void main() { String[] a = new String[] { “a1”, “a2” } String[] b = new String[] { “b1”, “b2” } List l l = new List () String v1 = a[*] l.append(v1) l = new List () String v2 = b[*] l.append(v2) } Flow Insensitivity: Example

static void main() { String[] a = new String[] { “a1”, “a2” } String[] b = new String[] { “b1”, “b2” } List l l = new List () String v1 = a[*] l.append(v1) l = new List () String v2 = b[*] l.append(v2) } Call Graph (Base Case): Example Code deemed reachable so far … class List { T tail; void append(T c) { Link k = new Link () k.data = c Link t = this.tail t.next = k this.tail = k }

Flow sensitivity –flow-insensitive: ignores intra-procedural control flow Heap abstraction –object allocation sites: does not distinguish between objects allocated at same site Aggregate modeling Context sensitivity 0-CFA Pointer Analysis for Java

static void main() { String[] a = new String[] { “a1”, “a2” } String[] b = new String[] { “b1”, “b2” } List l l = new List () String v1 = a[*] l.append(v1) l = new List () String v2 = b[*] l.append(v2) } Heap Abstraction: Example class List { T tail; void append(T c) { Link k = new Link () k.data = c Link t = this.tail t.next = k this.tail = k }

static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } Heap Abstraction: Example class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k }

Heap Abstraction: Example class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } Note: Pointer analyses for Java typically do not distinguish between string literals (like “a1”, “a2”, “b1”, “b2” above), i.e., they use a single location to abstract them all static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) }

v = new i … Rule for Object Alloc. Sites Before: After: Note: This and each subsequent rule involving assignment is a “weak update” as opposed to a “strong update” (i.e. it accumulates as opposed to updates the points-to information for the l.h.s.), a hallmark of flow-insensitivity v new j … … v new i new j … …

Rule for Object Alloc. Sites: Example static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } l new 4 new 3 new 1 ba new 2

Flow sensitivity –flow-insensitive: ignores intra-procedural control flow Heap abstraction –object allocation sites: does not distinguish between objects allocated at same site Aggregate modeling –does not distinguish between elements of same array –field-sensitive for instance fields Context sensitivity 0-CFA Pointer Analysis for Java

v1.f = v2 v1 Rule for Heap Writes Before: After: new i … … v2 new j … … v2 new j … … new k new i … … f new j new k … … … … v1 new i … … f f f is instance field or [*] (array element)

Rule for Heap Writes: Example static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1”

v1 = v2.f v1 Rule for Heap Reads Before: After: new i v1 new k new i … … … … … … v2 new j … … v2 new j … … new k new j … … f new k new j … … f f is instance field or [*] (array element)

Rule for Heap Reads: Example static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1” v1v2

Flow sensitivity –flow-insensitive: ignores intra-procedural control flow Heap abstraction –object allocation sites: does not distinguish between objects allocated at same site Aggregate modeling –field-sensitive for instance fields –does not distinguish between elements of same array Context sensitivity –context-insensitive: ignores inter-procedural control flow, analyzing each function in a single context 0-CFA Pointer Analysis for Java

CHA(T j, foo) = T m ::foo() { …; return r; } v1 = v2.foo() Rule for Dynamically Dispatching Calls Before: After: v1 new l new i v1 new i … … … … … … v2 new j … … v2 new j … … this new k … … r new l … … TjTj TjTj r … … this new j new k … … { …; ; …; } T n ::bar() T m ::foo() c c T n ::bar() T m ::foo() { } …; return r;

Call Graph (Inductive Step): Example l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1” v1v2 static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } c this new 5 k data tail t next

Classifying Pointer Analyses Heap abstraction Alias representation Aggregate modeling Flow sensitivity Context sensitivity Compositionality Adaptivity

Heap Abstraction Single node for entire heap –Cannot distinguish between heap-directed pointers –Popular in stack-directed pointer analyses for C Object allocation sites (“0-CFA”) –Cannot distinguish between objects allocated at same site –Predominant pointer analysis for Java String of call sites (“k-CFA with heap specialization/cloning”) –Distinguishes between objects allocated at same site using finitely many strings of call sites –Predominant heap-directed pointer analysis for C Strings of object allocation sites in object-oriented languages (“k-object-sensitivity”) –Distinguishes between objects allocated at same site using finitely many strings of object allocation sites

Example l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1” v1v2 static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } c this new 5 k data tail t next

Alias Representation Points-to Analysis: Computes the set of memory locations that a pointer may point to –Points-to graph represented explicitly or symbolically (e.g. using Binary Decision Diagrams) –Predominant kind of pointer analysis Alias Analysis: Computes pairs of pointers that may point to the same memory location –Used primarily by older pointer analyses for C –Can be computed using a points-to analysis may-alias(v 1,v 2 ) if points-to(v 1 ) ∩ points-to(v 2 ) ≠ Ø

Aggregate Modeling Arrays –Single field ([*]) representing all array elements –Cannot distinguish between elements of same array –Array dependence analysis used in parallelizing compilers is capable of making such distinctions Records/Structs –Field-insensitive/field-independent: merge all fields of each abstract record object –Field-based: merge each field of all record objects –Field-sensitive: model each field of each abstract record object (most precise)

Flow Sensitivity Flow-insensitive –Ignores intra-procedural control-flow (i.e. order of statements within a function) –Computes one solution for whole program or per function –Usually combined with Static Single Assignment (SSA) transformation to get limited flow sensitivity –Two kinds: Steensgaard’s or equality-based: almost linear time Anderson’s or subset-based: cubic time Flow-sensitive –Computes one solution per program point –More precise but less scalable

Example l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1” v1v2 static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } c this new 5 k data tail t next

Context Sensitivity Context-insensitive –Ignores inter-procedural control-flow (i.e. does not match calls and returns) –Analyzes each function in a single abstract context Context-sensitive –Two kinds: Cloning-based (k-limited) –k-CFA or k-object-sensitive (for object-oriented languages) Summary-based –Top-down or bottom-up –Systematic (“∞ CFA”) but harder to understand –Analyzes each function in multiple abstract contexts (cloning- based or top-down summary-based) or in a single parametric context (bottom-up summary-based) –More precise but less scalable

Example l new 4 new 3 new 1 ba new 2 [*] “a1” “a2” [*] “b2” “b1” v1v2 static void main() { String[] a = new 1 String[] { “a1”, “a2” } String[] b = new 2 String[] { “b1”, “b2” } List l l = new 3 List () String v1 = a[*] l.append(v1) l = new 4 List () String v2 = b[*] l.append(v2) } class List { T tail; void append(T c) { Link k = new 5 Link () k.data = c Link t = this.tail t.next = k this.tail = k } c this new 5 k data tail t next

Compositionality Whole-program –Cannot analyze open programs (e.g. libraries) –Predominant kind of pointer analysis Compositional/modular –Can analyze program fragments Missing callers (does not need “harness”) Missing callees (does not need “stubs”) –Solution is parameterized to accommodate unknown facts from the missing parts –Solution is instantiated to yield less parameterized (or fully instantiated) solution when missing parts are encountered –Parameterization harder in presence of dynamic dispatching Existing approaches rely on call graph computed by a whole- program analysis but can be highly imprecise –Open problem

Adaptivity Non-adaptive –Computes exhaustive solution of fixed precision regardless of client Demand-driven –Computes partial solution, depending upon a query from a client, but of fixed precision Client-driven –Computes exhaustive solution but can use different precision in different parts of the solution, depending upon client Iterative/Refinement-based –Starts with an imprecise solution and refines it in successive iterations depending upon client