ISMM 2008 1 Analyzing Memory Resource Bounds for Low-Level Programs Wei-Ngan Chin 1 Huu Hai Nguyen 1 Corneliu Popeea 1 Shengchao Qin 2 1 National Univ.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

1 Parametric Heap Usage Analysis for Functional Programs Leena Unnikrishnan Scott D. Stoller.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
De necessariis pre condiciones consequentia sine machina P. Consobrinus, R. Consobrinus M. Aquilifer, F. Oratio.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Semantics Static semantics Dynamic semantics attribute grammars
Programming Languages and Paradigms
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
1 PROPERTIES OF A TYPE ABSTRACT INTERPRETATER. 2 MOTIVATION OF THE EXPERIMENT § a well understood case l type inference in functional programming à la.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
Inferring Disjunctive Postconditions Corneliu Popeea and Wei-Ngan Chin School of Computing National University of Singapore - ASIAN
1 Symbolic Execution for Model Checking and Testing Corina Păsăreanu (Kestrel) Joint work with Sarfraz Khurshid (MIT) and Willem Visser (RIACS)
Names and Bindings.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Typed Assembly Languages COS 441, Fall 2004 Frances Spalding Based on slides from Dave Walker and Greg Morrisett.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Typed Memory Management in a Calculus of Capabilities David Walker (with Karl Crary and Greg Morrisett)
Runtime Environments Source language issues Storage organization
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
Encapsulation by Subprograms and Type Definitions
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina International Symposium on Memory Management June, 2006.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
1 Combining verification and analysis. 2 CONCLUSIONS ON VERIFICATION  denotational abstract interpreters have the extra-value of being easily transformed.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Symbol Table (  ) Contents Map identifiers to the symbol with relevant information about the identifier All information is derived from syntax tree -
Cristian Gherghina Joint work with: Wei-Ngan Chin, Razvan Voicu, Quang Loc Le Florin Craciun, Shengchao Qin TexPoint fonts used in EMF. Read the TexPoint.
A Review of Recursion Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Mark Marron IMDEA-Software (Madrid, Spain) 1.
Automatic Verification of Pointer Programs using Grammar-based Shape Analysis Hongseok Yang Seoul National University (Joint Work with Oukseh Lee and Kwangkeun.
1 Employing decision procedures for automatic analysis and verification of heap-manipulating programs Greta Yorsh under the supervision of Mooly Sagiv.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
Checking Reachability using Matching Logic Grigore Rosu and Andrei Stefanescu University of Illinois, USA.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
Cristian Gherghina 1, Cristina David 1, Shengchao Qin 2, Wei-Ngan Chin 1 1 National University of Singapore 2 University of Teesside Structured Specifications.
Mark Marron IMDEA-Software (Madrid, Spain) 1.
Verifying Safety Policies with Size Properties and Alias Controls Wei Ngan Chin 1,2, Siau-Cheng Khoo 1, Shengchao Qin 3, Corneliu Popeea 1, Huu Hai Nguyen.
Convergence of Model Checking & Program Analysis Philippe Giabbanelli CMPT 894 – Spring 2008.
Symbolic Execution with Abstract Subsumption Checking Saswat Anand College of Computing, Georgia Institute of Technology Corina Păsăreanu QSS, NASA Ames.
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
11th Nov 2004PLDI Region Inference for an Object-Oriented Language Wei Ngan Chin 1,2 Joint work with Florin Craciun 1, Shengchao Qin 1,2, Martin.
Lightweight Support for Magic Wands in an Automatic Verifier Malte Schwerhoff and Alexander J. Summers 10 th July 2015, ECOOP, Prague.
CS 343 presentation Concrete Type Inference Department of Computer Science Stanford University.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
CSE 5317/4305 L12: Higher-Order Functions1 Functional Languages and Higher-Order Functions Leonidas Fegaras.
1 Combining Abstract Interpreters Mooly Sagiv Tel Aviv University
D A C U C P Speculative Alias Analysis for Executable Code Manel Fernández and Roger Espasa Computer Architecture Department Universitat Politècnica de.
Quantified Data Automata on Skinny Trees: an Abstract Domain for Lists Pranav Garg 1, P. Madhusudan 1 and Gennaro Parlato 2 1 University of Illinois at.
1 Numeric Abstract Domains Mooly Sagiv Tel Aviv University Adapted from Antoine Mine.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
Putting Static Analysis to Work for Verification A Case Study Tal Lev-Ami Thomas Reps Mooly Sagiv Reinhard Wilhelm.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Memory Management in Java Mr. Gerb Computer Science 4.
Design issues for Object-Oriented Languages
Compositional Pointer and Escape Analysis for Java Programs
Closures and Streams cs784(Prasad) L11Clos
Symbolic Implementation of the Best Transformer
창 병 모 숙명여대 전산학과 자바 언어를 위한 정적 분석 틀 (A Framework for SBA for Java) KAIST 프로그램 분석시스템 연구단 세미나 창 병 모 숙명여대 전산학과.
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
UNIT V Run Time Environments.
Course Overview PART I: overview material PART II: inside a compiler
Presentation transcript:

ISMM Analyzing Memory Resource Bounds for Low-Level Programs Wei-Ngan Chin 1 Huu Hai Nguyen 1 Corneliu Popeea 1 Shengchao Qin 2 1 National Univ. of Singapore 2 Durham University, UK

ISMM Motivation: Memory Bounds Analysis  Given a piece of program code, how much memory will it require for safe execution? Can we know the answer before execution? Applications: Resource constrained embedded devices (limited memory footprint) Safety critical systems

ISMM Simple Example Given a method: int foo (int n) { if (n <= 0) { return 1; } else { c x = new c(); c y = new c(); int v = 2+foo(n-1); dispose(x); return v; } } Derive an upper-bound for the use of: stack memory heap memory

ISMM Three design decisions: low level programs: more accurate bounds analysis. structured control flow: recovered if not available. how to model heap recovery? (next slide) P ::= M 1, …, M n M ::= t m(t 1,..., t n ) { E } E ::= Cmd | E 1 ; E 2 | if E 1 E 2 | while E Cmd ::= load i | store i | invoke m | const k | new c | dispose c What Programs to Analzye? method invocation method definition object deallocation

ISMM Heap Recovery Possible solutions for analyzing heap recovery: use explicit memory disposal. use region-based memory management. Both solutions over-approximate the recovery that can be achieved via GC. Rely on an analysis that inserts dispose commands (Chin-et-al:SAS05) alias annotations for object fields and methods not for cyclic data structures May achieve finer-grained heap recovery.

ISMM Highlights of Our Work Derive both stack and heap bounds with similar apparatus. Automatic and sound analysis of recursion. Precision and efficiency: relational analysis for low-level code. disjunctive invariants for “bounds analysis”.

ISMM Overview of Our Solution A multi-pass analysis automatically infers memory bounds in a modular way 4. heap usage + heap bound 1.frame bound 3.stack bound 2.abstract state t m(t 1,.., t n ) F ; Á ; S ; H ; M {..}

ISMM Frame Bound Inference Stack Frames Simple analysis: l, ¡ ` F E Ã A, ¡ 1, p Embed the current top frame pointer p at each program point:

ISMM Abstract State Inference The abstract states expressed as Presburger formula over values on the stack [  p,..,  1 ] : The inference rule: Abstract states inserted at each program point: Presburger formula Boolean expression arithmetic expression State before State after

ISMM Abstract State Inference: Some Rules make use of top frame pointer p Á po - postcondition of callee m ½ - substitution from formals to actual arguments derive state after call

ISMM Stack Bound Inference Problem: infer stack bound for each method. each elem. denotes a bound s when g is true S - stack bound from method body F - minimum stack bound fixpoint computation

ISMM Stack Bound Inference: Some Rules the position where new frame is built incorporate guarded formula w/ current state tail call optimization retrieve stack bound of callee m 1

ISMM Heap Inference H and M are guarded form: H / H 1 heap usage before/after execution of B M heap bound heap effect

ISMM Example: Fixpoint Analysis Simple example: int foo (int n) { if (n <= 0) { return 1; } else { c x = new c(); c y = new c(); int v = 2+foo(n-1); dispose(x); return v; } } First step: build a constraint abstraction rec(n,r) = (n · 0 Æ r=1) Ç ( 9 r 1 ¢ n>0 Æ rec(n-1,r 1 ) Æ r=2+r 1 ) Next step: derive approximation for its fixpoint.

ISMM Fixpoint Analysis for Abstract State Use disjunctive polyhedron abstract domain: selective hulling: combines related disjuncts. widening: ensures termination of fixpoint analysis. rec 1 (n,r) = (n · 0 Æ r=1) Ç ( 9 r 1 ¢ n>0 Æ rec 0 (n-1,r 1 ) Æ r=2+r 1 ) = (n · 0 Æ r=1) rec 2 (n,r) = (n · 0 Æ r=1) Ç ( 9 r 1 ¢ n>0 Æ rec 1 (n-1,r 1 ) Æ r=2+r 1 ) = (n · 0 Æ r=1) Ç (0 < n · 1 Æ r=2+1) rec 3 (n,r) = (n · 0 Æ r=1) Ç (n=1 Æ r=3) Ç (n=2 Æ r=5) = h (n · 0 Æ r=1) Ç (0 < n · 2 Æ r=2n+1) = w (n · 0 Æ r=1) Ç (0 < n Æ r=2n+1) false

ISMM Fixpoint Analysis: Memory Bounds Constraint abstraction: rec M (n) = {n · 0  {(c,0)}} [ ({n>0  {(c,2)}} + rec M (n-1)) Derive fixpoint: rec M (n) = {n · 0  {(c,0)}} [ {n>0  {(c,2n)}} A similar analysis derives the stack bound.

ISMM Soundness Safety theorem: given memory resources equal to (or more than) its inferred bounds, each method always executes without error due to insufficient memory.

ISMM Experiments A prototype system built in Haskell language. Omega library + disjunctive fixpoint analyzer. Small numerical programs (upto 2kloc).

ISMM Related Work Hughes-Pareto:ICFP99, Hofmann-Jost:POPL03 for first-order functional languages. Cachera-et-al:FM05 - for Java bytecode certifies that memory is bounded (but not what bound) Albert-et-al:ESOP07 - for Java bytecode: derives (only) heap bounds. heap recovery via escape analysis. Braberman-et-al:ISMM08 - Java-like programs: expressive heap bounds (polynomial expressions). heap recovery via region-based memory management. loop invariants inferred dynamically + user annotations.

ISMM Conclusion A sound inference system to predict the amount of memory space needed: Can infer upper bounds for stack and heap spaces. Uses guarded formulae to track both usage and upper bounds in a path sensitive manner. Uses fixpoint analysis in the polyhedron domain to handle both recursion and loops. Prototype system used to infer memory bounds for a set of benchmark programs.

ISMM Thank you!

ISMM References J. Hughes and L. Pareto. Recursion and Dynamic Data-Structures in Bounded Space: Towards Embedded ML Programming [ICFP99] M. Hofmann and S. Jost. Static prediction of heap space usage for first order functional programs [POPL03] D. Cachera, T. Jensen, D. Pichardie, and G. Schneider. Certified Memory Usage Analysis [FM05] W.N. Chin, H.H. Nguyen, S.C. Qin, and M. Rinard. Memory Usage Verification for OO Programs [SAS05] C. Popeea and W.N. Chin. Inferring disjunctive postconditions [ASIAN06] E. Albert, P. Arenas, S. Genaim, G. Puebla, and D. Zanardini. Cost Analysis of Java Bytecode [ESOP07] V. Braberman, F. Fernandez, D. Garbervetsky, and S. Yovine. Parametric Prediction of Heap Memory Requirements [ISMM08]

ISMM Discussion: Abstract States for Objects Inference of abstract states for heap allocated objects not included in the paper Challenge: objects that are mutable & shareable We provided an alias type system which can identify two groups of trackable objects: Unique references whose abstract states may change Immutable references whose abstract states are immutable (but can be freely shared) In current work, abstract states are mainly size- related properties.

ISMM Abstract States for Objects: An Example No. of nodes Height of tree Analysis result for method height Analysis result for mehtod sum