Compositional Pointer and Escape Analysis for Java Programs

Slides:



Advertisements
Similar presentations
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Advertisements

Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Program Representations. Representing programs Goals.
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.
CPSC 388 – Compiler Design and Construction
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Recap from last time We were trying to do Common Subexpression Elimination Compute expressions that are available at each program point.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Interprocedural analyses and optimizations. Costs of procedure calls Up until now, we treated calls conservatively: –make the flow function for call nodes.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Previous finals up on the web page use them as practice problems look at them early.
Compositional Pointer and Escape Analysis for Java Programs Martin Rinard Laboratory for Computer Science MIT John Whaley IBM Tokyo Research Laboratory.
Run-Time Storage Organization
Run time vs. Compile time
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
From last time: Inlining pros and cons Pros –eliminate overhead of call/return sequence –eliminate overhead of passing args & returning results –can optimize.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
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.
Schedule Midterm out tomorrow, due by next Monday Final during finals week Project updates next week.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
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.
Precision Going back to constant prop, in what cases would we lose precision?
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.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University STATIC ANALYSES FOR JAVA IN THE PRESENCE OF DISTRIBUTED COMPONENTS AND.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Lecture 10 : Introduction to Java Virtual Machine
1 Introduction to JVM Based on material produced by Bill Venners.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Incrementalized Pointer and Escape Analysis Frédéric Vivien ICPS/LSIIT Université Louis Pasteur Strasbourg, France Martin Rinard Laboratory for Computer.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Using Types to Analyze and Optimize Object-Oriented Programs By: Amer Diwan Presented By: Jess Martin, Noah Wallace, and Will von Rosenberg.
Incrementalized Pointer and Escape Analysis Martin Rinard MIT LCS.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
More Examples of Abstract Interpretation Register Allocation.
Escape Analysis for Java Will von Rosenberg Noah Wallace.
Pointer and Escape Analysis for (Multithreaded) Programs Martin Rinard MIT Laboratory for Computer Science.
Pointer and Escape Analysis for Multithreaded Programs Alexandru Salcianu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
RealTimeSystems Lab Jong-Koo, Lim
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Abstract Interpretation and Future Program Analysis Problems Martin Rinard Alexandru Salcianu Laboratory for Computer Science Massachusetts Institute of.
Compositional Pointer and Escape Analysis for Java programs
Chapter 8: Recursion Data Structures in Java: From Abstract Data Types to the Java Collections Framework by Simon Gray.
Static Analysis of Object References in RMI-based Java Software
Memory Management Functions
Run-Time Environments Chapter 7
Names and Attributes Names are a key programming language feature
Module 9: Memory and Resource Management
Martin Rinard Laboratory for Computer Science
Incrementalized Pointer and Escape Analysis
Program Slicing Baishakhi Ray University of Virginia
Code Generation.
Adaptive Code Unloading for Resource-Constrained JVMs
Inlining and Devirtualization Hal Perkins Autumn 2011
창 병 모 숙명여대 전산학과 자바 언어를 위한 정적 분석 틀 (A Framework for SBA for Java) KAIST 프로그램 분석시스템 연구단 세미나 창 병 모 숙명여대 전산학과.
자바 언어를 위한 정적 분석 (Static Analyses for Java) ‘99 한국정보과학회 가을학술발표회 튜토리얼
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
Intermediate Code Generation
Course Overview PART I: overview material PART II: inside a compiler
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
CSE 332: Concurrency and Locks
Presentation transcript:

Compositional Pointer and Escape Analysis for Java Programs John Whaley, Martin Rinard

Intraprocedural Analysis start with the initial points-to escape graph propagate points-to escape graphs through the statements of the method’s CFG

Points-to escape graph - Example class Rational { int numerator, denominator; Rational result; Rational(int n, int d) { numerator = n; denominator = d; } void abs() { int n = numerator; int d = denominator; if (n < 0) n = -n; if (d < 0) d = -d; if(d % n == 0) result = new Rational (n / d, 1); else result = new Rational (n, d); class client { public static void evaluate (int i, int j) { Rational r = new Rational (0.0, 0.0); r.abs(); Rational n = r.result; result 4 this 3 result 5 result r 1 2 n

Interprocedural Analysis At each method invocation site skip the site mark all parameters as escaping down into the site analyze the site collect analysis results from all potentially invoked methods map each analysis result into points-to graph at the program point before the site merge the mapped results

Skipped Method Invocation Sites m : l = l0.op(l1, l2, …, lk) return node : nR current points-to escape graph (O, I, e, r) the points-to escape graph (O’, I’, e, r’) = [m]((O, I, e, r)) after the site is defined as follows: I’ = (I – edges (I, l))  (l, nR) e’(n) = e(n)  {m}, if 0 <= i <= k, n  I(li) e(n), otherwise the return node nR is an outside node used to represent the return value of the invoked method.

Analyzed Method Invocation Sites m : l = l0.op(l1, l2, …, lk) current points-to escape graph (O, I, e, r) the new points-to escape graph (O’, I’, e, r’) = [m]((O, I, e, r)) after the site is defined as follows: (O’,I’,e’,r’) = {map(m, <O, I, e, r>, op) | op  callees(m)}

Mapping Algorithm site m : l = l0.op(l1,. . . , lk) invoked method op with formal parameter list p0, . . . , pk accessed static class variables cl1.f1, . . , clj.fj Three points-to escape graphs are involved in the algorithm: Old graph : (O, I, e, r ) at the point before the method invocation site. Incoming graph, for the invoked method. (OR, IR, eR, rR) = α (exitop*) New graph : (OM, IM, eM, rM) = map (m, (O, I, e, r), op).

Mapping Algorithm build an initial mapping from nodes of incoming graph to nodes of old graph µ : N 2N initialize the new graph to old graph (O, I, e, r) use µ to map nodes and edges from incoming graph into new graph edges are mapped from pairs of nodes in incoming graph to corresponding pair of nodes in the new graph nodes in new graph acquire the edges from nodes in incoming graph

Mapping Algorithm extend µ s.t. if node n from incoming graph is mapped into new graph, n µ(n) n is present in the new graph

Mapping Algorithm Roles played by different kinds of nodes in the incoming graph – n  NP represents the nodes that corresponding actual parameter points to these nodes acquire n’s edges n itself not present in the new graph µ(n) – set of nodes in the current graph that corresponding actual parameter points to.

Mapping Algorithm n  NG represents objects that corresponding static class variables points to. these nodes acquire n’s edges n itself present in the new graph n is escaped in the new graph µ(n) – set of nodes in the current graph that the corresponding static class variable points to, n  µ(n) .

Mapping Algorithm n  NL all the nodes that n represents acquire n’s edges n itself present in the new graph only if an escaped node would point to it n is escaped in the new graph µ(n) – set of nodes in the old graph that n represented during the analysis of the method n  µ(n), if n is present in the new graph

Mapping Algorithm n  NI n  NR n and its inside edges present in the new graph if objects that n represents are reachable in the caller if n is present in the new graph µ(n) = {n} otherwise µ(n) = Φ n  NR same as for inside nodes

Constraints for mapping algorithm

Constraints for mapping algorithm

Constraints for mapping algorithm

Constraint Solution Algorithm based on three worklists each worklist corresponds to one of the rules that map nodes from the incoming graph to the new graph. a worklist entry contains a node n from the new graph and an edge ((n1, f), n2) from the incoming graph. All worklist entries have the property, n  µ(n1)

Constraint Solution Algorithm When the algorithm processes the worklist entry, it checks to see if it should update the mapping for n2 Worklist WE corresponds to Rule 3 matches outside edges from the incoming graph against inside edges in the old graph. All edges in this worklist are outside edges. To process an entry from this worklist, match the edge ((n1, f), n2) from the worklist against all corresponding inside edges ((n, f), n4) in the old graph. For each corresponding edge map n2 to n4

Constraint Solution Algorithm Worklist WI corresponds to Rule 6 maps inside nodes into the new graph. All edges in this worklist are inside edges. To process an entry from this worklist extract the node n2 that the worklist edge points to map n2 into the new graph.

Constraint Solution Algorithm Worklist WO corresponds to Rule 7 maps outside nodes into the new graph. All edges in this worklist are outside edges. To process an entry from this worklist insert a corresponding outside edge ((n, f), n2) into the new graph map n2 into the new graph.

Constraint Solution Algorithm Whenever a node n1 is mapped to n, each inside edge ((n1, f), n2) from the incoming graph is mapped into the new graph. Insert a corresponding inside edge from n to each node that n2 maps to; i.e., to each node in µ(n2) There should be one such edge for each node in the final set of nodes µ(n2) When ((n1, f), n2) is first mapped into the new graph, µ(n2) may not be complete.

Constraint Solution Algorithm build a set δ(n2) of delayed actions Each delayed action consists of a node in the new graph and a field in that node. Whenever the node n2 is mapped to a new node n’ (i.e., the algorithm sets µ(n2) = µ(n2)  {n’}) establish a new inside edge for each delayed action. The new edge goes from the node in the action to the newly mapped node n’.

Constraint Solution Algorithm

Example r n result 4 this 3 5 result 1 2 class Rational { int numerator, denominator; Rational result; Rational(int n, int d) { numerator = n; denominator = d; } void abs() { int n = numerator; int d = denominator; if (n < 0) n = -n; if (d < 0) d = -d; if(d % n == 0) result = new Rational (n / d, 1); else result = new Rational (n, d); class client { public static void evaluate (int i, int j) { Rational r = new Rational (0.0, 0.0); r.abs(); Rational n = r.result; this 5 result 3 4 r result n 1 2

Optimizations For optimization purposes, the two most important properties are – absence of edges between captured nodes guarantees the absence of references between the represented objects captured objects are inaccessible when the method returns.

Optimizations Synchronization Elimination If an object does not escape a thread, it is legal to remove the lock acquire and release operations from synchronized methods that execute on that object. benefit is the elimination of synchronization overhead To apply the transformation the compiler generates a specialized, synchronization-free version of each synchronized method that may execute on a captured object. At each call site that invokes the method only on captured objects, the compiler generates code that invokes the synchronization free version.

Optimizations Stack Allocation of Objects If an object does not escape a method, it can be allocated on the stack instead of in the heap. Benefits – elimination of garbage collection overhead. Instead of being processed by the collector, the object will be implicitly collected when the object returns better memory locality stack frame will tend to be resident in the cache

Experimental Results analysis has been implemented in the compiler for the Jalapeno JVM a Java virtual machine written in Java with a few unsafe extensions for performing low-level system operations analysis is implemented as a separate phase of the jalapeno dynamic compiler operates on the intermediate representation

Benchmark Set

Experimental Results

Experimental Results

Experimental Results

Experimental Results

Experimental Results

Experimental Results

Thank You!