Refining Abstract Locations Tachio Terauchi Jeff Foster Alex Aiken.

Slides:



Advertisements
Similar presentations
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Advertisements

PLDI’2005Page 1June 2005 Example (C code) int double(int x) { return 2 * x; } void test_me(int x, int y) { int z = double(x); if (z==y) { if (y == x+10)
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Structures Spring 2013Programming and Data Structure1.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Demand-driven Alias Analysis Implementation Based on Open64 Xiaomi An
Flow-Insensitive Points-to Analysis with Term and Set Constraints Presentation by Kaleem Travis Patrick.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
Compiler Construction
Checking and Inferring Local Non-Aliasing Alex AikenJeffrey S. Foster UC BerkeleyUMD College Park John KodumalTachio Terauchi UC Berkeley.
Aliases in a bug finding tool Benjamin Chelf Seth Hallem June 5 th, 2002.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
PSUCS322 HM 1 Languages and Compiler Design II Parameter Passing Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
A Type-Checked Restrict Qualifier Jeff Foster OSQ Retreat May 9-10, 2001.
Emergy Berger, Calvin Lin, Samuel Z. Guyer CSE 231 Presentation by Jennifer Grau.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
Overview Parameter passing modes.
May 9, 2001OSQ Retreat 1 Run-Time Type Checking for Pointers and Arrays in C Wes Weimer, George Necula Scott McPeak, S.P. Rahul, Raymond To.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
CQual: A Tool for Adding Type Qualifiers to C Jeff Foster et al UC Berkeley OSQ Retreat, May
Patrick M. Rondon, Ming Kawaguchi, Ranjit Jhala University of California, San Diego.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Type Inference II David Walker CS 510. ML-style Polymorphism 2 characteristics: prenex (let) polymorphism let f : all [a,b,c].t =... in e polymorphic.
1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
1 Automatic Refinement and Vacuity Detection for Symbolic Trajectory Evaluation Orna Grumberg Technion Haifa, Israel Joint work with Rachel Tzoref.
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Visibility, Accessibility, and Information Hiding.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
9-1 9 Variables and lifetime  Variables and storage  Simple vs composite variables  Lifetime: global, local, heap variables  Pointers  Commands 
1 A Comparative Study Of Language Support for Generic Programming Oopsla 2003 Roland Garcia Jaakko Jarvi Andrew Lumsdaine Jeremy Siek Jeremiah Wilcock.
Model construction and verification for dynamic programming languages Radu Iosif
CSE 332: C++ template examples Concepts and Models Templates impose requirements on type parameters –Types that are plugged in must meet those requirements.
Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.
Overview of C++ Templates
CS 343 presentation Concrete Type Inference Department of Computer Science Stanford University.
Type Systems CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Week 7 Part I Kyle Dewey. Overview Code from last time Array initialization Pointers vs. arrays Structs typedef Bubble sort (if time)
1/20 Arrays Changki PSWLAB Arrays Daniel Kroening and Ofer Strichman Decision Procedure.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Lesson 10 Type Reconstruction
Manuel Fahndrich Jakob Rehof Manuvir Das
Visibility, Accessibility, and Information Hiding
CS4450: Principles of Programming Languages
C Basics.
Data Types.
Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake.
Built-In (a.k.a. Native) Types in C++
Over-Approximating Boolean Programs with Unbounded Thread Creation
Type Systems CSE 340 – Principles of Programming Languages Fall 2016
Elided to examples only
Example (C code) int double(int x) { return 2 * x; }
Compiler Construction
A simple function.
Predicate Abstraction
Compiler Construction
Presentation transcript:

Refining Abstract Locations Tachio Terauchi Jeff Foster Alex Aiken

Using types to reason about state... spin_lock(f->lock);... spin_unlock(f->lock);... f->lock: unlocked spinlock_t f->lock: locked spinlock_t f->lock: unlocked spinlock_t

Handling aliases Solution – Abstract locations: set of concrete locations May alias analysis – Map states (types) to abstract locations. spin_lock(f->lock); spin_unlock(x); spin_unlock(f->lock);

Typing Judgement Abstract location –– Type –  := int |  | ref(  ) Store – C := C,    | ; C 1 ; Γ ` e :  ; C 2 – In environment Γ, e has type  and evaluating e changes the store from C 1 to C 2. C 1 ; Γ ` e : ref(  ) ; C 2 C 1 ; Γ ` spin_lock(e) : void; C 2 [   locked spinlock_t]

Problem: aliases Ideally – Single abstract location  single concrete location Reality – Single abstract location  many concrete locations typedef struct Foo { spinlock_t * lock; struct Foo * next; } * foo; void bar(foo f) { spin_lock(f->lock);... spin_unlock(f->next->lock)... spin_unlock(f->lock); }

Problem: aliases (continued) typedef struct Foo { spinlock_t * lock; struct Foo * next; } * foo; void bar(foo f) { spin_lock(f->lock) spin_unlock(f->lock) }

Ideas Obtain finer abstract locations with better alias analysis. – Subset-based alias analysis, one-level-flow alias analysis, cfl- reachability-based alias analysis, etc. – Work in progress… – But none of these will work on the list example. – More expensive analysis? This work: construct and study language features to allow programmers locally refine abstract locations.

The list example typedef struct Foo { spinlock_t * lock; struct Foo * next; } * foo; void bar(foo f) { spin_lock(f->lock) spin_unlock(f->lock) }

restrict restrict x = e 1 in e 2 – e 1 evaluates to a reference cell of the type ref(  ). – x has the type ref(  ’). –  must not be accessed in e 2. –  ’ must not be accessed outside of e 2. – Before and after the evaluation of e 2, the state of  ’ is equal to the state of . Intuition: separates the world of  ’ from the world of .

What can one do with restrict? Locally associate an abstract location with a single concrete location. void bar(spinlock_t * restrict lock) { spin_lock(lock);... spin_unlock(lock); }... bar(f->lock)...

What can one do with restrict? (2) Prevent local aliases from affecting the outside world. void bar(spinlock_t * restrict lock) { /* builds a local linked list of locks containing lock */ }... spinlock_t * newlock = new_lock(“a fresh lock”));... bar(newlock); spin_lock(newlock)...

Using restrict in existing programs Inferring restrict Extending restrict

Inferring restrict How often do programmers unknowingly declare “restrict” reference cells? Algorithm – Given a program annotated with standard reference cell types (e.g. ref int), – For each occurrence of “let x:ref  = e 1 in e 2 ”, check if it satisfies all of the restrict constraints. – If so, replace it with “restrict x:ref  = e 1 in e 2 ”.

Experience with inferring restrict C programs – Steensgaard’s alias analysis – Pointer declarations in function parameters. – Library functions Assume all abstract locations reachable from arguments and returns are accessed. – Mixed initial results 16 out of 60 in flex 40 out of 510 in sendmail 7 out of 387 in li

Limitation of restrict restrict needs a variable referring to the target location. – restrict x = e 1 in e 2

The list example typedef struct Foo { spinlock_t * lock; struct Foo * next; } * foo; void bar(foo f) { spin_lock(f->lock) spin_unlock(f->lock) }

Limitation of restrict restrict needs a variable referring to the target location. What to do when we want to “restrict” an arbitrary expression? –... spin_lock(f->lock)... –... spin_lock(xyz((abc+3)->d))...

Extending restrict restrict!! e 1 in e 2 – Outside of e 2, e 1 evaluates to a reference cell of the type ref(  ). – Within e 2, e 1 has the type ref(  ’). –  must not be accessed in e 2. –  ’ must not be accessed outside of e 2. – Before and after the evaluation of e 2, the state of  ’ is equal to the state of . – e 1 is referentially transparent in e 2.

Example typedef struct Foo { spinlock_t * lock; struct Foo * next; } * foo; void bar(foo f) { restrict!! f->lock in { spin_lock(f->lock) spin_unlock(f->lock) }

Further work More ways to locally refine abstract locations Relationship with other work on reasoning about states – Alias analysis, Existential Types, Dataflow analysis, model checking, Linear types, Monads