Topic 17: Memory Analysis

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

Runtime Techniques for Efficient and Reliable Program Execution Harry Xu CS 295 Winter 2012.
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Course Outline Traditional Static Program Analysis Software Testing
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Interprocedural Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
Background for “KISS: Keep It Simple and Sequential” cs264 Ras Bodik spring 2005.
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Vertically Integrated Analysis and Transformation for Embedded Software John Regehr University of Utah.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
Program analysis Mooly Sagiv html://
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://
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Convergence of Model Checking & Program Analysis Philippe Giabbanelli CMPT 894 – Spring 2008.
Pointer Analysis – Part I CS Pointer Analysis Answers which pointers can point to which memory locations at run-time Central to many program optimization.
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.
Memory-Aware Compilation Philip Sweany 10/20/2011.
Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.
CS 412/413 Spring 2005Introduction to Compilers1 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 30: Loop Optimizations and Pointer Analysis.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Code Analysis and Optimization Pat Morin COMP 3002.
Memory Management.
Advanced Algorithms Analysis and Design
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
Topic: Classes and Objects
Introduction to Operating Systems
Code Optimization.
Data Flow Analysis Suman Jana
Processes and threads.
Names and Attributes Names are a key programming language feature
Simone Campanoni Dependences Simone Campanoni
Realizing Concurrency using the thread model
COMBINED PAGING AND SEGMENTATION
Pointer Analysis Lecture 2
Run-time organization
Interprocedural Analysis Chapter 19
This pointer, Dynamic memory allocation, Constructors and Destructor
Advanced Programming Behnam Hatami Fall 2017.
Princeton University Spring 2016
Princeton University Spring 2016
Instruction Scheduling for Instruction-Level Parallelism
Topic 10: Dataflow Analysis
University Of Virginia
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Compiler Back End Panel
Objective of This Course
CSC 533: Programming Languages Spring 2015
Compiler Back End Panel
Memory Allocation CS 217.
Realizing Concurrency using the thread model
Exam Topics Hal Perkins Autumn 2009
Pointer analysis.
Reference These slides, with minor modification and some deletion, come from U. of Delaware – and the web, of course. 4/4/2019 CPEG421-05S/Topic5.
Languages and Compilers (SProg og Oversættere) Compiler Optimizations
Data Structures & Algorithms
Foundations and Definitions
Lecture 4: Instruction Set Design/Pipelining
CSC 533: Programming Languages Spring 2018
Procedure Linkages Standard procedure linkage Procedure has
CSC 533: Programming Languages Spring 2019
Pointer analysis John Rollinson & Kaiyuan Li
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

Topic 17: Memory Analysis COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer

Motivation Is this string sanitized? Do pointers p and q alias? Can pointer x be NULL here? Can I eliminate this load instruction? Can I eliminate this store instruction? Can these three store instructions be scheduled for the same cycle? Does a pointer to my private key leak to code outside the crypto library? Can I swap the order of this load-store pair? Is my program memory-safe? Can we exploit the distinctness of pointers to improve precision of analyses and used for constant propagation, common subexpression elimination, etc.?

Flavors of memory analyses I Alias analyses concern potential /definitive (non-) equality of two items: Can x and y point to the same address? Or are they definitely separate? Are x.f1 and y.f2 always pointing to the same object? May versus must: May alias: is it possible that x and y point to the same address? Must alias: do x and y necessarily/always point to the same address?

Flavors of memory analyses I Alias analyses concern potential /definitive (non-) equality of two items: Can x and y point to the same address? Or are they definitely separate? Are x.f1 and y.f2 always pointing to the same object? May versus must: May alias: is it possible that x and y point to the same address? Must alias: do x and y necessarily/always point to the same address? Points-to analyses concern a single item: can x be NULL? what objects might this method m be invoked upon? again, both questions have may and must variants

Flavors of memory analyses I Alias analyses concern potential /definitive (non-) equality of two items: Can x and y point to the same address? Or are they definitely separate? Are x.f1 and y.f2 always pointing to the same object? May versus must: May alias: is it possible that x and y point to the same address? Must alias: do x and y necessarily/always point to the same address? Points-to analyses concern a single item: can x be NULL? what objects might this method m be invoked upon? again, both questions have may and must variants Can obtain alias information from points-to analysis: PtsTo(x) ∩ PtsTo(y) = Ø  x and y don’t alias PtsTo(x) ∩ PtsTo(y) ≠ Ø  x and y may alias PtsTo(x) = {a} = PtsTo(y)  x and y must alias, to location x

Flavors of memory analyses II Flow-insensitive points-to/alias information holds globally / in entire method simplifies analysis: order of instructions irrelevant, conditionals, loop conditions can be ignored + speeds up analysis - reduces precision Flow-sensitive points-to/alias information given for each program point order of instructions relevant; code traversal a la data flow analysis, with join operation at control flow merge points + more costly analysis - increased precision y = new A() x = y : y = new A() x and y must alias here, and so do x.f and y.f, for all (pointer-valued) fields f of A x and y definitely don’t alias here SSA disambiguates the 2 defs of y, but object references may have been copied elsewhere, and SSA doesn’t cover fields.

Flavors of memory analyses III Information can be collected for program variables: PtsTo(x) = {a, b, null} , MustAlias(x, y) = true fields: PtsTo(C.f) = {a, null}, MayAlias (C.f, D.g) = false access paths: items of the form b.f1.f2….fn where fi are field names and “base” b can again be a variable: MustAlias (x.f1.g2, y.g1.f3) a class name: MayAlias (C.f1.g2, D.g1.f3) a symbolic identifier of an object (specified by allocation site) captures the f fields of all (static? dynamic?) C-objects x = new A(…) : y = new B(..) if (z.f == v.g) … Fields f of A-objects allocated here and g-fields of B-objects allocated here definitely don’t alias here So need to know where the objects held in z and y were allocated…(next slide)

Flavors of memory analyses IV What information is associated with variables / fields / access paths? other variables / fields / access paths abstract locations (eg allocation sites) Presence of merge points and need for conservativeness / approximation suggests using sets of abstract locations etc, or other lattice structure

Flavors of memory analyses IV What information is associated with variables / fields / access paths? other variables / fields / access paths abstract locations (eg allocation sites) Presence of merge points and need for conservativeness / approximation suggests using sets of abstract locations etc, or other lattice structure How can different objects allocated at the same allocation site be distinguished? method A m () { return new A(…) } for (int i = 0; i < N; i++) { x = new A(…) myArray[i] =x } clearly, different calls to m yield different objects! clearly, this loop yields N different objects!

Flavors of memory analyses V Example: “k-CFA” One solution: (call) context abstraction: refine allocation site by adding a static approximation of the frame stack that is valid when the allocation is executed list of method names (reverse order, truncated) list of method names and the (abstractions of) the objects they were invoked upon (reverse order, truncated) list of method names and the (abstractions of) the objects they were invoked upon, and the (abstractions of) the arguments of these method calls (reverse order, truncated) Often, truncation necessary at length 2 or 3 ;-)

Challenges of memory analyses precision, precision, precision, precision! speed, speed, speed! Yes, but not blindly: need to balance precision and speed which code sections need to analyzed in detail? which transformations need /can exploit precision, and how much do these transformations speed up the code you are interested in is the application in a JIT compiler? Or are you compiling code running in a data center, on millions of VM’s? modularity: how are analysis results of methods / classes / libraries best communicated to the outside (procedure summaries, types, …) Indeed, memory analyses often inter-procedural: worst case-assumptions on (non-)aliasing of method parameters too approximate. M. Hind: Pointer Analysis: Haven‘t We Solved This Problem Yet? Proceedings of the 2001 ACM SIGPLAN-SIGSOFT Workshop on Program Analysis for Software Tools and Engineering (PASTE’01)}, pages = {54--61}, ACM 2001.

Compiler construction – done and dusted? New architectures: Multi-core: parallelization eg of array intensive scientific code (DSWP) Multi-core: coordination between threads on machines with weak memory models GPU, FPGA, … New applications Mobile (energy optimization) Data centers (energy) IoT / embedded systems New languages Domain specific, eg networking (SDN) General purpose (Go, Rust, …) New requirements: high-assurance Correctness: preservation of source language meaning – mathematically proven, mechanically checkable

Compiler construction – done and dusted? New architectures: Multi-core: parallelization eg of array intensive scientific code (DSWP) Multi-core: coordination between threads on machines with weak memory models GPU, FPGA, … Thanks! New applications Mobile (energy optimization) Data centers (energy) IoT / embedded systems New languages Domain specific, eg networking (SDN) General purpose (Go, Rust, …) New requirements: high-assurance Correctness: preservation of source language meaning – mathematically proven, mechanically checkable