Pointer and Escape Analysis for Multithreaded Programs Alexandru Salcianu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
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.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Commutativity Analysis: A New Analysis Technique for Parallelizing Compilers Martin C. Rinard Pedro C. Diniz April 7 th, 2010 Youngjoon Jo.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Trace-Based Automatic Parallelization in the Jikes RVM Borys Bradel University of Toronto.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
Laboratory for Computer Science Massachusetts Institute of Technology Ownership Types for Safe Region-Based Memory Management in Real-Time Java Chandrasekhar.
Compositional Pointer and Escape Analysis for Java Programs Martin Rinard Laboratory for Computer Science MIT John Whaley IBM Tokyo Research Laboratory.
Run time vs. Compile time
An Adaptive, Region-based Allocator for Java Feng Qian & Laurie Hendren 2002.
Compile-Time Deallocation of Individual Objects Sigmund Cherem and Radu Rugina International Symposium on Memory Management June, 2006.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Memory Management for Real-Time Java Wes Beebee and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Supported by: DARPA.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
P ARALLEL P ROCESSING I NSTITUTE · F UDAN U NIVERSITY 1.
Analyses and Optimizations for Multithreaded Programs Martin Rinard, Alex Salcianu, Brian Demsky MIT Laboratory for Computer Science John Whaley IBM Tokyo.
An Adaptive, Region-based Allocator for Java Feng Qian, Laurie Hendren {fqian, Sable Research Group School of Computer Science McGill.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
1 Evaluating the Impact of Thread Escape Analysis on Memory Consistency Optimizations Chi-Leung Wong, Zehra Sura, Xing Fang, Kyungwoo Lee, Samuel P. Midkiff,
Basic Semantics Associating meaning with language entities.
Component Composition for Embedded Systems Using Semantic Aspect-Oriented Programming Martin Rinard Laboratory for Computer Science Massachusetts Institute.
Finding Your Cronies: Static Analysis for Dynamic Object Colocation Samuel Z. Guyer Kathryn S. McKinley T H E U N I V E R S I T Y O F T E X A S A T A U.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
Speculative Region-based Memory Management for Big Data Systems Khanh Nguyen, Lu Fang, Harry Xu, Brian Demsky Donald Bren School of Information and Computer.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
COMP3190: Principle of Programming Languages
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta
Incrementalized Pointer and Escape Analysis Frédéric Vivien ICPS/LSIIT Université Louis Pasteur Strasbourg, France Martin Rinard Laboratory for Computer.
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.
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.
Incrementalized Pointer and Escape Analysis Martin Rinard MIT LCS.
Pointer Analysis for Multithreaded Programs Radu Rugina and Martin Rinard M I T Laboratory for Computer Science.
Data Flow Analysis for Software Prefetching Linked Data Structures in Java Brendon Cahoon Dept. of Computer Science University of Massachusetts Amherst,
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
Escape Analysis for Java Will von Rosenberg Noah Wallace.
Pointer and Escape Analysis for (Multithreaded) Programs Martin Rinard MIT Laboratory for Computer Science.
Recursion Unrolling for Divide and Conquer Programs Radu Rugina and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Chapter 10 Chapter 10 Implementing Subprograms. Implementing Subprograms  The subprogram call and return operations are together called subprogram linkage.
GC Assertions: Using the Garbage Collector To Check Heap Properties Samuel Z. Guyer Tufts University Edward Aftandilian Tufts University.
Abstract Interpretation and Future Program Analysis Problems Martin Rinard Alexandru Salcianu Laboratory for Computer Science Massachusetts Institute of.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter 4 – Thread Concepts
Object Lifetime and Pointers
Compositional Pointer and Escape Analysis for Java programs
Compositional Pointer and Escape Analysis for Java Programs
Chapter 4 – Thread Concepts
Martin Rinard Laboratory for Computer Science
Amir Kamil and Katherine Yelick
Incrementalized Pointer and Escape Analysis
Program Slicing Baishakhi Ray University of Virginia
Radu Rugina and Martin Rinard Laboratory for Computer Science
Inlining and Devirtualization Hal Perkins Autumn 2011
Pointer analysis.
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
Amir Kamil and Katherine Yelick
Presentation transcript:

Pointer and Escape Analysis for Multithreaded Programs Alexandru Salcianu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology {salcianu,

Goal Automatically extract precise points- to and escape information for multithreaded programs Analyze and optimize multithreaded programs which use region-based memory allocation Application

Outline Example Analysis Experimental Results Related Work Conclusions

Parallel Fibonacci Computation Fib(3)

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Spawn threads

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Fib(0) Spawn threads

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Fib(0) Join threads

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Fib(0) Join threads

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Fib(0) Final result

Fibonacci Code while(1) { int i = read_input(); Fib f = new Fib(i); Fib.run(); } class Fib implements Runnable { int source; Fib(int i) { source = i; } public void run() { Task t = new Task(new Integer(source)); t.start(); t.join(); System.out.println(t.target); } Class Task extends Thread { Integer source, target; Task(Integer s) { source=s;} public void run() { int v = source.intValue(); if(v<=1) { target = value; } else { Task t1 = new Task(new Integer(v-1)); Task t2 = new Task(new Integer(v-2)); t1.start(); t2.start(); t1.join(); t2.join(); int x = t1.target.intValue(); int y = t2.target.intValue(); target = new Integer(x+y); }

Parallel Fibonacci Computation Fib(3) Fib(2)Fib(1) Fib(0) Final result

Impact of Dynamic Object Allocation More garbage collection Execution time overhead The garbage collection cycles interfere with the application Real time constraints are difficult to meet Try to solve this by exploiting the strong correlation between lifetime of objects and lifetime of computation

Solution Execute each computation in its own memory region: computation allocates its objects in that region when computation ends, all objects are deallocated

Advantages of Regions Good news: no need for garbage collection ! More predictable programs Great for real time applications with hard time constraints

Advantages of Regions Good news: no need for garbage collection ! More predictable programs Great for real time applications with hard time constraints Adopted in the Real Time Specification for Java (Bollela et al., 2000)

Using Regions in Example while(1) { int i = read_input() ; Fib f = new Fib(i); Region r = new Region(); r.enter(f); } r.enter(f) will execute the run() method of f in the memory region r. Lifetime of region = lifetime of computation

Nested Regions Short-lived computations are embedded into bigger computations The nesting of regions corresponds to the nesting of computations Hierarchy of memory regions Lifetime of a child region is included in the lifetime of its parent region

Nested Regions Example Memory Region Object

Nested Regions Example Parent Memory Region Object Child Memory Region

Nested Regions Example Parent Memory Region Object Child Memory Region

Safety Problem Parent Memory Region Object Child Memory Region Dangling reference

Dynamic Check Approach Memory Region Object Referencing Down Regions Is NOT OK Referencing Up Regions Is OK Dynamic checks to make sure all references go up

Problems with Dynamic Check Approach Execution time overhead Programs have to cope with a new kind of runtime exception Detecting the error at runtime may not be that useful …

Our Goal Analyze the program and statically check that it never creates dangling references If no object is reachable from outside the computation that creates it, clearly no dangling references

Dynamic Check Approach Memory Region Object Referencing Down Regions Is NOT OK Referencing Up Regions Is OK Escaped object

Our Goal Analyze the program and statically check that it never creates dangling references If no object is reachable from outside the computation that creates it, clearly no dangling references Escape analysis: given a computation, find out which objects escape from the computation, i.e., are reachable from outside the computation

Region Safety Analysis 1.Identify all run() methods that might be called by Region.enter() Each such method + threads it starts represent one possible computation 2.Use pointer and escape analysis to check that for every computation, no object created inside it is reachable from outside 3.If so, no dangling references 4.Can remove all checks!

Why Do We Need a New Analysis? Existing analyses treat threads in a very conservative way: All objects reachable from a thread are considered to escape No attempt is done to recapture them But in Fib example, all objects escape into some thread, but none of them escape the whole computation

Key Contribution of Analysis Analyze interactions between threads Can recognize when objects do not escape a multithreaded computation Even when the objects are accessed by multiple threads within the computation

Outline Example Analysis Experimental Results Related Work Conclusions

Analysis Key Features Uses graphs to model heap Nodes represent objects Edges represent references Intra-procedural analysis is flow sensitive Inter-procedural analysis is bottom-up Compositional at both method and thread level: Analyzes a method / thread once, specializes the result for each use Records enough info to analyze the interactions between parallel threads

Nodes N I = inside nodes represent objects created within the analyzed part of the program one inside node for each object creation site; represents all objects created at site thread nodes represent thread objects N O = outside nodes placeholders for unknown nodes will be disambiguated in the inter-procedural/ inter-thread analysis key element for compositionality nInI nOnO

Outside node types N P = parameter nodes represent objects passed as incoming parameters N L = load nodes represent objects loaded from a node reachable from outside the analyzed part of the program one load node for each load statement in a method

Edges Used to model heap references Inside edges represent references created by the analyzed part of the program Outside edges represent heap references read from nodes reachable from outside the analyzed part of the program n1n1 n2n2 n3n3 n4n4 f f

Escape function A node escapes if it is reachable from outside the analyzed part of the program: Parameter nodes escape Nodes corresponding to unanalyzed started threads escape Nodes reachable from an escaped node escape too The escape function records how each node escapes: through a parameter, through an unanalyzed started thread etc.

Parallel Interaction Graph Models the result of the execution of the analyzed part of the program Contains: Inside edges Outside edges Escape function Started threads Action ordering Inherited from base algorithm for sequential programs Key extension for multithreaded programs Improves precision of analysis

Intra-procedural analysis Analysis scope = one method Initial state: formals point to parameter nodes each parameter n P escapes through itself: e(n P ) = { n P } no thread has been started yet Transfer functions for each type of instruction

void static foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; }

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 a

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 a 2 b

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 a 2 b f

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 is started 1 a 2 b f 12 and 1 escape into

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g

Inter-thread analysis Extends the scope of the analysis from a method to a method + threads it starts Given a program point P Find a parallel interaction graph that reflects the interaction of: Current method up to P Threads it [transitively] starts

Inter-thread analysis Suppose there is only one started thread First step: get the parallel interaction graph at the end of the run() method of that thread

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } Class SThread extends Thread { public void run() { x = this.f; y = new C(); x.g = y; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } Class SThread extends Thread { public void run() { x = this.f; y = new C(); x.g = y; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g 4 this y 5 f g x 6 45 and 4 escape through, 6

Inter-thread analysis We want to combine the two parallel interaction graphs in a single one Need to disambiguate the outside nodes Second step: map the outside nodes from one graph to nodes from the other graph Initial mappings Rules for extending them

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } Class SThread extends Thread { public void run() { x = this.f; y = new C(); x.g = y; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g 4 this y 5 f g x 6 45 and 4 escape through, 6 22

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } Class SThread extends Thread { public void run() { x = this.f; y = new C(); x.g = y; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g 4 this y 5 f g x 6 45 and 4 escape through, 6 22 22

void foo() { a = new SThread(); b = new C(); a.f = b; a.start(); c = b.g; } Class SThread extends Thread { public void run() { x = this.f; y = new C(); x.g = y; } 1 is started 12 and 1 escape into, 3 1 a 2 b f 3 c g 4 this y 5 f g x 6 45 and 4 escape through, 6 22 22 11

1 a 2 b f 3 c g 22 4 this y 5 f g x 6 22 11

1 a 2 b f 3 c g 22 4 y 5 f g x 6 22 11 1 a 2 b f 3 c g 5 6

1 a 2 b f 3 c g 22 4 y 5 f g x 6 22 11 1 a 2 b f 3 c g 5 6 Nothing escapes in the new graph ! has been analyzed; 1 Thread objects no longer escape through it !

1 a 2 b f 3 c g 22 4 this y 5 f g x 6 22 11 1 a 2 b f 3 c g 5 6 Load nodes 53 and can be removed

1 a 2 b f 3 c g 22 4 this y 5 f g x 6 22 11 1 a 2 b f c g 6 No node escapes from the scope represented by method foo() + the thread it starts.

Final look over the analysis What makes the inter-thread analysis possible? Analysis deals with unknown execution contexts by using placeholders (outside nodes) In the inter-thread analysis, the matching rules are able to disambiguate these placeholders

Final look over the analysis Features not presented in this talk: Inter-procedural analysis Recording actions and action ordering (useful for sync removal) Fixed points necessary in the case of: Loops Mutually recursive methods Recursively generated threads

Outline Example Analysis Experimental Results Related Work Conclusions

Analyzed applications Httpweb server Quotequote server Barnesscientific computation Waterscientific computation Treesynthetic benchmark Arraysynthetic benchmark

Use of regions in the applications Http and Quote use one region per each connection Barnes and Water: Sequence of computations Each computation spawns multiple threads and executes in its own memory region

Intra vs. Inter-thread HttpIntra-thread QuoteIntra-thread BarnesInter-thread WaterInter-thread TreeIntra-thread ArrayIntra-thread Analysis was able to check that regions are correctly used!

Experimental results Analysis required to remove checks Analysis time [s] Backend time [s] HttpIntra-thread QuoteIntra-thread BarnesInter-thread WaterInter-thread TreeIntra-thread ArrayIntra-thread

Analysis vs. Backend time

Execution time

Outline Motivation Analysis Experimental Results Related Work Conclusions

Related Work Standard escape/pointer analyses: Blanchet (OOPLSA99) Bogda and Hoelzle (OOPSLA99) Choi, Gupta, Serrano, Sreedhar and Midkiff (OOPSLA99) Whaley and Rinard (OOPSLA99) Treat threads very conservatively: Any object reachable from a thread is considered to escape forever

Related Work Rugina and Rinard (PLDI 99) go beyond this but deal only with structured parallelism: parbegin / parend blocks of code We are able to analyze general threads (POSIX style) Ruf (PLDI 00) is able to remove synchronizations on objects synced on by a single thread In some cases, we can do so even for objects synced on by multiple threads

Outline Motivation Analysis Experimental Results Related Work Conclusions

Inter-thread analysis is challenging but possible The main use of the analysis will be to check statically that programs use regions correctly Removing dynamic checks can also provide a modest performance improvement