Download presentation
Presentation is loading. Please wait.
Published byElisabeth Smith Modified over 6 years ago
1
Compositional Pointer and Escape Analysis for Java Programs
John Whaley, Martin Rinard
2
Intraprocedural Analysis
start with the initial points-to escape graph propagate points-to escape graphs through the statements of the method’s CFG
3
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
4
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
5
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.
6
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)}
7
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).
8
Mapping Algorithm build an initial mapping from nodes of incoming graph to nodes of old graph µ : N N 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
9
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
10
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.
11
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) .
12
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
13
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
14
Constraints for mapping algorithm
15
Constraints for mapping algorithm
16
Constraints for mapping algorithm
17
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)
18
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
19
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.
20
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.
21
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.
22
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’.
23
Constraint Solution Algorithm
24
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
25
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.
26
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.
27
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
28
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
29
Benchmark Set
30
Experimental Results
31
Experimental Results
32
Experimental Results
33
Experimental Results
34
Experimental Results
35
Experimental Results
36
Thank You!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.