Beruflich Dokumente
Kultur Dokumente
variables are accessed using syntax of the form cl:f. correspond to thread creation sites. Since each thread
The algorithm represents the computation of each method corresponds to an object that inherits from the class
using a control
ow graph. The nodes of control
ow graphs Thread, thread creation sites are also object creation
are statements st 2 ST. The algorithm analyzes only those sites, and N N .
T I
statements that aect the points-to and escape information. There is the set N of outside nodes, which repre-
We assume the program has been preprocessed so that all O
sent objects created outside the current analysis scope
statements relevant to the analysis are in one of the following or accessed via references created outside the current
forms: analysis scope.
There is the set CL of class nodes. Conceptually, each Both O and I are graphs with edges labeled with a eld
class node represents a statically allocated object whose from F . We dene the following operations on nodes of the
elds are the static class variables for the correspond- graphs:
ing class.
edgesTo(O; n) = fhn ; ni 2 Og [ fhhn ; fi; ni 2 Og
0 0
P
parameter node for each formal parameter in the pro- O(n; f) = fn :hhn; fi; n i 2 Og
0 0
gram. Each parameter node represents the object that The following operation removes a set S of nodes from a
its parameter points to during the execution of the points-to escape graph. hO ; I ; e ; r i = remove(S; hO; I; e; ri),
0 0 0 0
current analysis scope, either by the caller, by a thread n is reachable from a node n in O if n = n or there exists a
0 0
running in parallel with the current thread, or by an sequence n0 n such that n = n0 , n = n , and for all
0
I (V [ (N F)) N is a set of inside edges. Inside exists a node n 2 S such that n is reachable from n in O.
0
edges represent references created inside the current We dene reachable(O; S; n) if n is reachable from S in O.
analysis scope. Given a points-to escape graph hO; I; e; ri, a node n di-
rectly escapes if n 2 N [ N [ N [ CL or e(n) 6= ;. We
e : N ! 2 is an escape function that records the
M
dene escaped(hO; I; e; ri; n) if n is reachable in O [ I from
P R T
set of unanalyzed method invocation sites that a node a node that directly escapes, and captured(hO; I; e; ri; n) if
escapes down into. not escaped(hO; I; e; ri; n).
r N is a return set that represents the set of ob-
jects that may be returned by the currently analyzed
method.
4 Intraprocedural Analysis then generating additional inside edges from l to all of the
nodes that v points to.
The algorithm uses a data
ow analysis to generate a points-
to escape graph at each point in the method. The analysis Kill = edges(I; l)
Gen = flg I (v)
I
of each method starts with the construction of the points-
to escape graph hO0 ; I0 ; e0 ; r0 i for the rst statement in the I = (I Kill ) [ Gen
I
0
I I
method. Given a method op with formal parameter list
p0 ; : : : ; p and accessed static class variables cl1 :f1 ; : : : ; cl :f , 4.2 Load Statements
the initial points-to escape graph hO0 ; I0 ; e0 ; r0 i is dened as
k j j
point to the same object, this object will be represented by escaped nodes to which l2 points. S is the set of nodes
I
multiple nodes during the analysis of the method. In this accessible via inside edges from l2 :f.
case, the mapping operation described below in Section 5 S = fn2 2 I (l2 ):escaped(hO; I; e; ri; n2 )g
will merge the corresponding outside objects when it maps S = [fI (n2 ; f):n2 2 I (l2 )g
E
the nal analysis result for the method into the calling con- I
text at the method invocation site. Because the mapping If S = ; (i.e., l2 does not point to an escaped node),
retains all of the edges from the merged objects, it conser- E
S = S and the transfer function simply kills all edges from
vatively models the actual eect of the method. I
l1 , then generates inside edges from l1 to all of the nodes
Once it has nished constructing the initial points-to es- in S .
cape graph, the analysis continues by propagating points- Kill = edges(I; l1 )
to escape graphs through the statements of the method's Gen = fl1 g S
I
the current points-to escape graph. Most of the statements If S 6= ; (i.e., l2 points to at least one escaped node), S =
S [fng, where n is the load node for the load statement. In
E
and outside edges. In this case, the transfer function has the addition to killing all edges from l1 , then generating inside
following general form: edges from l1 to all of the nodes in S , the transfer function
also generates outside edges from the escaped nodes to n.
I = (I Kill ) [ Gen
0
O = O [ Gen
I I
0
Kill = edges(I; l1 )
Gen = fl1 g S
O I
Figure 6 graphically presents the rules that determine the I = (I Kill ) [ Gen
I
0
sets of generated edges for the dierent kinds of statements. Gen = (S ffg) fng
I I
resentation of the existing edges plus the new edges that the 4.3 Store Statements
statement generates, and a set of side conditions. The inter-
pretation of each row is that whenever the points-to escape A store statement of the form l1 :f = l2 nds the object to
graph contains the existing edges and the side conditions are which l1 points, then makes the f eld of this object point
satised, the transfer function for the statement generates to same object as l2 . The analysis models the eect of this
the new edges. assignment by nding the set of nodes that l1 points to,
then generating inside edges from all of these nodes to the
4.1 Copy Statements nodes that l2 points to.
A copy statement of the form l = v makes l point to the Gen = (I (l1 ) ffg) I (l2 )
object that v points to. The transfer function updates I to I = I [ Gen
I
0
I
re
ect this change by killing the current set of edges from l,
Figure 6: Generated Edges for Basic Statements
4.4 Global Load Statements 4.9 Control-Flow Join Points
A global load statement of the form l = cl:f makes l point To analyze a statement, the algorithm rst computes the
to the same object that cl:f points to. The analysis models join of the points-to escape graphs
owing into the statement
this change by killing all edges from l and generating inside from all of its predecessors. It then applies the transfer
edges from l to all of the nodes that cl:f points to. function to obtain a new points-to escape graph at the point
Kill = edges(I; l) after the statement. The join operation is dened as follows.
Gen = flg (O [ I )(cl; f)
I
hO1 ; I1 ; e1 ; r1 ithO2 ; I2 ; e2 ; r2 i = hO; I; e; ri, where O = O1 [
I = (I Kill ) [ Gen
I
0 O2 , I = I1 [ I2 , 8n 2 N:e(n) = e1 (n) [ e2 (n), and r = r1 [ r2 .
I I
The corresponding partial order for points-to escape graphs
is hO1 ; I1 ; e1 ; r1 i v hO2 ; I2 ; e2 ; r2 i if O1 O2 , I1 I2 , 8n 2
4.5 Global Store Statements N:e1 (n) e2 (n), and r1 r2 . The bottom points-to escape
A global store statement of the form cl:f = l makes the graph is h;; ;; e ; ;i, where e (n) = ; for all n.
? ?
static class variable cl:f point to the same object as l. The The analysis of each method produces analysis results
analysis models this change by generating inside edges from (st) and (st) before and after each statement st in the
cl:f to all of the nodes that l points to. method's control
ow graph. The analysis result satises
the following equations:
Gen = fhcl; fig I (l)
I = I [ Gen
I
0
I (enterop ) = hO0 ; I0 ; e0 ; r0 i
(st) = tf(st ):st 2 pred(st)g
0 0
The analysis uses the reachability information at method store statement l1 :f = l2 . With this denition, the transfer
exit points to bound object lifetimes. If an inside node is function for store statements performs strong updates.
not reachable from the static class variables, the parameters, ( edgesFrom(n; f) if I (l ) = fng; n; f singular;
the return values, or a thread object, then all of the objects 1
it represents (i.e., all of the objects allocated at the corre- Kill = and captured(hI; O; e; ri; n)
;
I
this approach, the analysis would perform strong updates for The mapping algorithm produces the new graph
all inside nodes, and weak updates only for summary nodes. hO ; I ; e ; r i = map(m; hO; I; e; ri; op).
M M M M
In the absence of information about how parallel threads ac- nodes of the old graph. For each outside node n in the in-
cess static class variables, the extracted analysis information coming graph, (n) is the set of nodes from the old graph
imposes no limit on the lifetimes or points-to relationships that n represents during the analysis of the invoked method
of objects reachable from these variables. The implemented op. This initial value of maps global nodes, parameter
compiler therefore adopts a more compact representation nodes, and load nodes to their corresponding nodes in the
for the points-to relationships involving nodes that repre- new graph. It builds the mapping for load nodes by tracing
sent these objects. Instead of recording the specic set of correlated paths in the old graph and the incoming graph.
static class variables that may point to a node, the analysis Each path in the old graph consists of a sequence of inside
simply records that at least one does. This representation edges; the corresponding path in the incoming graph con-
reduces the size of the points-to escape graph without re- sists of the sequence of outside edges that represent the cor-
ducing the amount of useful information. responding inside edges during the analysis of the method.
The algorithm then builds the new points-to escape graph
5 Interprocedural Analysis hO ; I ; e ; r i = map(m; hO; I; e; ri; op). The algorithm
starts by initializing the new graph to the old graph hO; I; e; ri.
M M M M
At each method invocation site, the analysis has the option It then uses the mapping to map nodes and edges from the
of either skipping the site or analyzing the site. If it analyzes incoming graph into the new graph. The mapped nodes rep-
the site, it collects the nal analysis results from all of the resent objects allocated or accessed by the invoked method.
potentially invoked methods, maps each analysis result into The mapped edges represent references that the invoked
the points-to escape graph from the program point before method created or read. During the mapping process, edges
the method invocation site, then merges the mapped results are mapped from pairs of nodes in the incoming graph to
to derive the points-to escape graph at the point after the corresponding pairs of nodes in the new graph. In this case
method invocation site. If the analysis skips a method invo- we say that the nodes in the new graph acquire the edges
cation site, it marks all of the parameters as escaping down from the nodes in the incoming graph.
into the site. As part of the mapping process, the algorithm extends
so that if the algorithm maps a node n from the incoming
5.1 Skipped Method Invocation Sites graph into the new graph, n 2 (n). In this case we say
that n is present in the new graph.
The transfer function for a skipped method invocation site is We next describe the roles that the dierent kinds of
dened as follows. Given a skipped method invocation site nodes in the incoming graph play in the analysis, and discuss
m of the form l = l0 :op(l1 ; : : : ; l ) with return node n how these roles aect each node's presence in the new graph,
and a current points-to escape graph hO; I; e; ri, the points- its eect on the mapping , and the edges that are mapped
k R
[[m]](hO; I; e; ri) after the site is dened as follows: (n) is the set of nodes in the current graph that the
hO ; I ; e ; r i = tfmap(m; hO; I; e; ri; op):op 2 callees(m)g
0 0 0 0 corresponding static class variable points to. Note that
n 2 (n).
We next present the mapping algorithm for method in-
vocation sites. We assume a method invocation site m of the n 2 N : If n is a load node, all of the nodes that it rep-
L
form l = l0 :op(l1 ; : : : ; l ) and an invoked method op with resents should acquire its edges. If n may represent an
k
formal parameter list p0 ; : : : ; p and accessed static class object created outside the analysis scope of the caller
variables cl1 :f1 ; : : : ; cl :f . There are three points-to es-
j j
k
or an object accessed via a reference created outside
cape graphs involved in the algorithm:
that scope, it and its edges should also be mapped into mappings and edges. Figure 9 graphically presents the gen-
the new graph. erated mappings and edges for some of the crucial rules.
The basic idea is that n should be present in the new Each row in this gure contains four items: an inference
graph only if an escaped node would point to it | rule, a graphical representation of existing edges and map-
there should be no outside edges from captured nodes. pings, a graphical representation of the existing edges and
The analysis determines if n should be present by ex- mappings plus the new edges and mappings that the rule
amining all of the nodes in the incoming graph that generates, and a set of side conditions. The nodes on the
point to n. There are two cases: bottom row of each graphical representation are from the
incoming graph, while the nodes on the top row are from
{ If at least one of these nodes (say n ) is present
0
the new graph. The interpretation of each row is that if the
and escaped in the new graph, n should also be existing edges and mappings are present in the incoming
present, and there should be an outside edge in graph and new graph, and the side conditions are true, then
the new graph from n to n. 0
the inference rule generates the new edges and mappings.
{ If at least one of these nodes is mapped to an es- 0 i k; n 2 I (l )
caped node (say n ) from the old graph, n should
0 i
(1)
be present, and there should be an outside edge n 2 (np ) i
1ij
In both cases, n is escaped in the new graph. (n) cl 2 (cl )
i i
(2)
includes the set of nodes in the old graph that n rep-
resented during the analysis of the method. And n 2 hhn1 ; fi; n2 i 2 O ; hhn3 ; fi; n4 i 2 I;
n3 2 (n1 ); n1 62 N
R
n2 2 (n2 )
I R
(6)
{ If at least one of these nodes represents a node hhn1 ; fi; n2 i 2 O ; n 2 (n1 );
(say n ) in the old graph, n should be present,
0
escaped(hO ; I ; e ; r i; n)
R
m 2 e (n ) 0 (9)
escaped or captured in the new graph. M
ods invoked by the current analysis scope. In either case inside nodes into the new graph. All edges in this
the reference did not exist when the method was invoked. worklist are inside edges. To process an entry from
Because all inside edges in the old graph existed when the this worklist, the algorithm extracts the node n2 that
analyzed method was invoked, the outside edge in the in- the worklist edge points to, and maps n2 into the new
coming graph did not represent these edges. graph.
5.2.4 Remaining Rules The worklist W corresponds to Rule 7, which maps
O
outside nodes into the new graph. All edges in this
Rule 4 initializes the new graph to include the old graph. worklist are outside edges. To process an entry from
Rule 5 maps inside edges from the incoming graph into the this worklist, the algorithm inserts a corresponding
new graph. There is an inside edge between two nodes in outside edge hhn; fi; n2 i into the new graph and maps
the new graph if there is an inside edge between their two n2 into the new graph.
corresponding nodes in the incoming graph. There is a slight complication in the algorithm. As the
Rules 6 through 8 map nodes from the incoming graph algorithm executes, it periodically maps inside edges from
into the new graph. Rule 6 maps an inside or return node the incoming graph into the new graph. Whenever a node
into the new graph if it is reachable from a node that is n1 is mapped to n, the algorithm maps each inside edge
already mapped into the new graph. Rule 7 maps a load hhn1 ; fi; n2 i from the incoming graph into the new graph.
node into the new graph if it is reachable from an escaped This mapping process inserts a corresponding inside edge
node that is already mapped into the new graph. Finally, from n to each node that n2 maps to; i.e., to each node in
Rule 8 maps an inside or return node into the new graph if (n2 ). The algorithm must ensure that when it completes,
it is returned by the method. there is one such edge for each node in the nal set of nodes
Rule 9 ensures that all nodes passed into unanalyzed (n2 ). But when the algorithm rst maps hhn1 ; fi; n2 i into
methods are marked appropriately in the escape function. the new graph, (n2 ) may not be complete. In this case,
Rule 10 makes l (the local variable that is assigned to the the algorithm will eventually map n2 to more nodes, in-
value that the method returns) point to the nodes that rep- creasing the set of nodes in (n2 ). There should be edges
resent the return value of the method. from n to all of the nodes in the nal (n2 ), not just to
those node that were present in (n2 ) when the algorithm
5.2.5 Constraint Solution Algorithm mapped hhn1 ; fi; n2 i into the new graph.
Figures 10 and 11 present an algorithm for solving the con- The algorithm ensures that all of these edges are present
straint system in Figures 7 and 8. The algorithm directly in the nal graph by building a set (n2 ) of delayed actions.
re
ects the structure of the inference rules. At each step it Each delayed action consists of a node in the new graph and
detects an inference rule antecedent that becomes true, then a eld in that node. Whenever the node n2 is mapped to a
takes action to ensure that the consequent is also true. new node n (i.e., the algorithm sets (n2 ) = (n2 ) [ fn g),
0 0
The mapNode(n1 ; n) procedure is invoked whenever the the algorithm establishes a new inside edge for each delayed
algorithm maps a node n1 from the incoming graph to a action. The new edge goes from the node in the action to
node n in the new graph. It rst updates the escape func- the newly mapped node n . These edges ensure that the
0
R M M while (W 6= ;) do
Update I to satisfy Rule 5 Remove a statement from worklist
I = I [ ((n1 ) fng)
M
W = W fstg
for all hhn1 ; fi; n2 i 2 I do
M M
O O R if st exitop then
W = W [ callers(op)
for 1 i j do mapNode(cl ; cl ) i i methods, a bottom-up analysis of the program yields the full
Map return values to satisfy Rule 8 result with one analysis per method. For recursive methods,
for all n 2 r \ (N [ N ) do mapNode(n; n)
R I R the analysis results must be iteratively recomputed within
done = false each strongly connected component of the call graph us-
while not done do ing the current best result until the analysis reaches a xed
done = true point.
if choose hn3 ; hhn1 ; fi; n2 ii 2 W such that It is possible to extend the algorithm so that it initially
n1 62 N then
E
I I
Map inside node to satisfy Rule 6 6 Abstraction Relation
mapNode(n2 ; n2 ) In this section, we characterize the correspondence between
done = false points-to escape graphs and the objects and references cre-
else if choose hn; hhn1 ; fi; n2 ii 2 W0 such that ated during the execution of the program. A key property
escaped(hO ; I ; e ; r i; n) then of this correspondence is that a single concrete object in
W = W fhn; hhn1 ; fi; n2 iig
M M M M
O O
the execution of the program may be represented by multi-
Map outside edge and outside node ple nodes in the points-to escape graph. We therefore state
to satisfy Rule 7 the properties that characterize the correspondence using an
O = O [ fhhn; fi; n2 ig
M M abstraction relation, which relates each object to all of the
mapNode(n2 ; n2 ) nodes that represent it.
done = false As the program executes, it creates a set of concrete
Update I (l) to satisfy Rule 10 objects o 2 C and a set of references r 2 R (V C) [
I (l) = [f(n):n 2 r g
M
Figure 14: Number of Synchronization Operations Before Figure 16: Number of Heap-Allocated Objects Before and
and After Optimization After Optimization
100% 100%
80% 80%
60% 60%
40% 40%
20% 20%
0% 0%
javac javacup javalex pbob javac javacup javalex pbob
Figure 15: Percentage of Eliminated Synchronization Oper- Figure 17: Percentage of Objects Allocated on the Stack
ations
Size of Size of
8.3 Synchronization Elimination Heap-Allocated Heap-Allocated
Objects Objects
Figure 14 presents the dynamic number of synchronization Before After
operations for all of the applications both before and af- Benchmark Optimization Optimization
ter the synchronization elimination optimization. Figure 15 javac 81,573,448 60,843,884
plots the percentage of eliminated synchronization opera- javacup 54,089,120 43,038,640
tions. The analysis achieves reasonable results, eliminating javalex 107,347,648 8,887,836
between 24% to 64% of the synchronization operations. pbob 25,950,641,024 18,046,027,560
8.4 Stack Allocation
Figure 16 presents the dynamic number of heap allocated Figure 18: Total Size of Heap-Allocated Objects Before and
objects for all of the applications both before and after the After Optimization (bytes)
stack allocation optimization. Figure 17 plots the percent-
age of objects allocated on the stack. Once again, the anal-
ysis achieves reasonable results, allocating between 22% and 100%
95% of the objects on the stack.
Figure 18 presents the total size of the heap allocated
objects for all of the applications both before and after the 80%
stack allocation optimization. Figure 17 plots the percent-
age of memory allocated on the stack instead of in the heap. 60%
The relative amount of object memory allocated on the stack
is closely correlated with the number of objects allocated on 40%
the stack. 20%
6 The current version of the Jalape~no JVM does not support stack
allocation. All objects are therefore allocated on the heap. The com- 0%
piler does, however, generate all of the specialized methods necessary
to support stack allocation. The compiler fully implements the syn- javac javacup javalex pbob
chronization elimination optimization.
7 See the package sun.tools.javac in the standard Java distribution.
8 Available at www.cs.princeton.edu/ appel/modern/java/CUP/
9 Available at www.cs.princeton.edu/ appel/modern/java/JLex/ Figure 19: Percentage of Object Memory Allocated on the
Stack
9 Related Work 9.1.2 Pointer Analysis for Multithreaded Programs
In this section, we discuss several areas of related work: Rugina and Rinard recently developed a
ow-sensitive pointer
pointer analysis, escape analysis, and synchronization op- analysis algorithm for multithreaded programs [23]. The key
timizations. complication in this algorithm is characterizing the interac-
tion between multiple threads and how this interaction af-
9.1 Pointer Analysis fects the points-to relationship. The analysis presented in
this paper simply sidesteps this issue. It generates precise re-
Pointer analysis for sequential programs is a relatively ma- sults only for objects that do not escape. If an object escapes
ture eld. Flow-insensitive analyses, as the name suggests, to another thread, our algorithm is not designed to main-
do not take statement ordering into account, and typically tain precise information about its points-to relationships. It
use some form of constraint-based analysis to produce a is important to realize that this is a key design decision that
single points-to graph that is valid across the entire pro- allows us to obtain good escape analysis results with what
gram [2, 27, 26]. Flow-insensitive analyses extend trivially is essentially a local analysis.
from sequential programs to multithreaded programs. Be- Corbett describes a shape analysis algorithm for multi-
cause they are insensitive to the statement order, they triv- threaded Java programs [12]. The algorithm can be used
ially model all of the interleavings of the parallel executions. to nd objects that are accessible to a single thread or ob-
jects that are accessed by at most one thread at any given
9.1.1 Flow-Sensitive Analyses time. The goal is to use this information to reduce the size
of the state space explored by a model checker. The algo-
Flow-sensitive analyses take the statement ordering into ac- rithm is intraprocedural, and does not address the problem
count, typically using a data
ow analysis to produce a points- of analyzing programs with multiple procedures.
to graph or set of alias pairs for each program point [25, 22,
28, 18, 10, 20]. One approach analyzes the program in a top- 9.2 Escape Analysis
down fashion starting from the main procedure, reanalyzing
each potentially invoked procedure in each new calling con- There has been a fair amount of work on escape analysis
text [28, 18]. This approach exposes the compiler to the in the context of functional languages [4, 3, 29, 14, 15, 5,
possibility of spending signicant amounts of time reanalyz- 19]. The implementations of functional languages create
ing procedures. It also commits the compiler to an analysis many objects (for example, cons cells and closures) implic-
of the entire program and is impractical for situations in itly. These objects are usually allocated in the heap and
which the entire program is not available. reclaimed later by the garbage collector. It is often possible
Another approach analyzes the program in a bottom-up to use a lifetime or escape analysis to deduce bounds on the
fashion, extracting a single analysis result for each proce- lifetimes of these dynamically created objects, and to per-
dure. The analysis reuses the result at each call site that form optimizations to improve their memory management.
may invoke the procedure. Sathyanathan and Lam present Deutsch [14] describes a lifetime and sharing analysis for
an algorithm for programs with non-recursive pointer data higher-order functional languages. His analysis rst trans-
types [25]. This algorithm supports strong updates and ex- lates a higher-order functional program into a sequence of
tracts enough information to obtain fully context-sensitive operations in a low-level operational model, then performs
results in a compositional way. Chatterjee, Ryder, and an analysis on the translated program to determine the life-
Landi describe an approach that extracts multiple analysis times of dynamically created objects. The analysis is a
results; each result is indexed under the calling context for whole-program analysis. Park and Goldberg [3] also describe
which it is valid [9]. Our approach extracts a single analysis an escape analysis for higher-order functional languages.
result for calling contexts with no aliases, and merges nodes Their analysis is less precise than Deutsch's. It is, how-
for calling contexts with aliases. The disadvantage of this ever, conceptually simpler and more ecient. Their main
approach is that it may produce less precise results than contribution was to extend escape analysis to include lists.
approaches that maintain information for multiple calling Deutsch [15] later presented an analysis that extracts the
contexts. The advantage is that it leads to a simpler algo- same information but runs in almost linear time. Blanchet [5]
rithm and smaller analysis results. extended this algorithm to work in the presence of impera-
Many pointer and shape analysis algorithms are based tive features and polymorphism. He also provides a correct-
on the abstraction of points-to graphs [24, 18, 28]. The ness proof and some experimental results.
nodes in these graphs typically represent memory locations, Baker [4] describes an novel approach to higher-order
objects, or variables, and the edges represent references be- escape analysis of functional languages based on the type
tween the represented entities. A standard technique is to inference (unication) technique. The analysis provides es-
use invisible variables [20, 18, 28] to parameterize the anal- cape information for lists only. Hannan also describes a
ysis result so that it can be used at dierent call sites. Like type-based analysis in [19]. He uses annotated types to de-
outside objects, invisible variables represent entities from scribe the escape information. He only gives inference rules
outside the analysis context. But the relationships between and no algorithm to compute annotated types.
invisible variables are typically determined by the aliasing
relationships in the calling context or by the type system. 9.3 Synchronization Optimizations
In our approach, the relationships between outside objects
are determined by the structure of the analyzed method | Diniz and Rinard [16, 17] describe several algorithms for per-
each load statement corresponds to a single outside object. forming synchronization optimizations in parallel programs.
This approach leads to a simple and ecient treatment of The basic idea is to drive down the locking overhead by coa-
recursive data structures. Another dierence between the lescing multiple critical sections that acquire and release the
approach presented in this paper and other previously pre- same lock multiple times into a single critical section that
sented approaches is the explicit distinction between inside acquires and releases the lock only once. When possible, the
and outside edges. algorithm also coarsens the lock granularity by using locks
in enclosing objects to synchronize operations on nested ob- algorithm can distinguish where it does and does not have
jects. Plevyak and Chien describe similar algorithms for complete information. As developers continue to move to
reducing synchronization overhead in sequential executions a model of dynamically loaded, component-based software,
of concurrent object-oriented programs [21]. we believe this general approach will become increasingly
Several research groups have recently developed synchro- relevant and compelling.
nization optimization techniques for Java programs. Aldrich,
Chambers, Sirer, and Eggers describe several techniques for Acknowledgements
reducing synchronization overhead, including synchroniza-
tion elimination for thread-private objects and several opti- The authors would like to acknowledge discussions with Radu
mizations that eliminate synchronization from nested moni- Rugina and Darko Marinov regarding pointer and escape
tor calls [1]. Blanchet describes a pure escape analysis based analysis. The second author would like to acknowledge dis-
on an abstraction of a type-based analysis [6]. The imple- cussions with Mooly Sagiv regarding pointer, escape, and
mentation uses the results to eliminate synchronization for shape analysis. The rst author would like to acknowledge
thread-private objects and to allocate captured objects on Jong-Deok Choi for introducing him to the concept of using
the stack. Bogda and Hoelzle describe a
ow-insensitive es- escape information for synchronization elimination, while he
cape analysis based on global set inclusion constraints [7]. was an IBM employee in the summer of 1998. The authors
The implementation uses the results to eliminate synchro- would like to thank the developers of the IBM Jalape~no vir-
nization for thread-private objects. A limitation is that the tual machine and the MIT Flex project for providing the
analysis is not designed to nd captured objects that are compiler infrastructure in which this research was imple-
reachable via paths with more than two references. mented, and the anonymous reviewers for their comments.
Choi, Gupta, Serrano, Sreedhar, and Midki present a
compositional data
ow analysis for computing reachability References
information [11]. The analysis results are used for synchro-
nization elimination and stack allocation of objects. Like [1] J. Aldrich, C. Chambers, E. Sirer, and S. Eggers. Static
the analysis presented in this paper, it uses an extension analyses for eliminating unnecessary synchronization
of points-to graphs with abstract nodes that may represent from java programs. In Proceedings of the 6th Inter-
multiple objects. It does not distinguish between inside and national Static Analysis Symposium, September 1999.
outside edges, but does contain an optimization, deferred
edges, that is designed to improve the eciency of the anal- [2] Lars Ole Andersen. Program Analysis and Specializa-
ysis. The approach classies objects as globally escaping, tion for the C Programming Language. PhD thesis,
escaping via an argument, and not escaping. Because the DIKU, University of Copenhagen, May 1994.
primary goal was to compute escape information, the anal-
ysis collapses globally escaping subgraphs into a single node [3] B. Goldberg and Y. Park. Escape analysis on lists. In
instead of maintaining the extracted points-to information. Proceedings of the SIGPLAN '92 Conference on Pro-
Our analysis retains this information, in part because we gram Language Design and Implementation, pages 116{
anticipate further thread interaction analyses (for example, 127, July 1992.
extensions of existing pointer analysis algorithms for multi-
threaded programs [23]) that will use this information. [4] H. Baker. Unifying and conquer (garbage, updating,
aliasing ...) in functional languages. In Proceedings of
the ACM Conference on Lisp and Functional Program-
10 Conclusion ming, pages 218{226, 1990.
This paper presents a new combined pointer and escape [5] B. Blanchet. Escape analysis: Correctness proof, imple-
analysis algorithm for object-oriented programs. The al- mentation and experimental results. In Proceedings of
gorithm is designed to analyze arbitrary parts of complete the 25th Annual ACM Symposium on the Principles of
or incomplete programs, obtaining complete information for Programming Languages, Paris, France, January 1998.
objects that do not escape the analyzed parts. ACM, ACM, New York.
We have implemented the algorithm in the IBM Jalape~no
virtual machine, and applied the analysis information to [6] B. Blanchet. Escape analysis for object oriented lan-
two optimization problems: synchronization elimination and guages. application to java. In Proceedings of the 14th
stack allocation of objects. For our benchmark programs, Annual Conference on Object-Oriented Programming
our algorithms enable the stack allocation of between 22% Systems, Languages and Applications, Denver, CO,
and 95% of the objects. They also enable the elimination of November 1999.
between 24% and 67% of the synchronization operations. [7] J. Bodga and U. Hoelzle. Removing unnecessary syn-
In the long run, we believe the most important concept chronization in java. In Proceedings of the 14th Annual
in this research may turn out to be designing analysis algo- Conference on Object-Oriented Programming Systems,
rithms from the perspective of extracting and representing Languages and Applications, Denver, CO, November
interactions between analyzed and unanalyzed regions of the 1999.
program. This concept leads to representations, such as the
points-to escape graphs presented in this paper, that make a [8] M. Burke, J. Choi, S. Fink, D. Grove, M. Hind,
clean distinction between information created locally within V. Sarkar, M. Serrano, V. Sreedhar, H. Srinivasan, and
an analyzed region and information created in the rest of J. Whaley. The jalape~no dynamic optimizing compiler
the program outside the analyzed region. for java. In Proceedings of the ACM SIGPLAN 1999
These representations support
exible analyses that are Java Grande Conference, June 1999.
capable of analyzing arbitrary parts of the program, with
the analysis result becoming more precise as more of the
program is analyzed. At every stage of the analysis, the
[9] R. Chatterjee, B. Ryder, and W. Landi. Relevant [21] J. Plevyak, X. Zhang, and A. Chien. Obtaining sequen-
context inference. In Proceedings of the 26th Annual tial eciency for concurrent object-oriented languages.
ACM Symposium on the Principles of Programming In Proceedings of the 22nd Annual ACM Symposium on
Languages, San Antonio, TX, January 1999. the Principles of Programming Languages, San Fran-
[10] J. Choi, M. Burke, and P. Carini. Ecient cisco, CA, January 1995. ACM, New York.
ow-sensitive interprocedural computation of pointer- [22] E. Ruf. Context-insensitive alias analysis reconsidered.
induced aliases and side eects. In Conference Record of In Proceedings of the SIGPLAN '95 Conference on Pro-
the Twentieth Annual Symposium on Principles of Pro- gram Language Design and Implementation, La Jolla,
gramming Languages, Charleston, SC, January 1993. CA, June 1995.
ACM.
[23] R. Rugina and M. Rinard. Pointer analysis for mul-
[11] J. Choi, M. Gupta, M. Serrano, V. Sreedhar, and tithreaded programs. In Proceedings of the SIGPLAN
S. Midki. Escape analysis for java. In Proceedings '99 Conference on Program Language Design and Im-
of the 14th Annual Conference on Object-Oriented Pro- plementation, Atlanta, GA, May 1999.
gramming Systems, Languages and Applications, Den-
ver, CO, November 1999. [24] M. Sagiv, T. Reps, and R. Wilhelm. Solving shape-
[12] J. Corbett. Using shape analysis to reduce nite-state analysis problems in languages with destructive updat-
models of concurrent java programs. In Proceedings of ing. ACM Transactions on Programming Languages
and Systems, 20(1):1{50, January 1998.
the International Symposium on Software Testing and
Analysis, March 1998. [25] P. Sathyanathan and M. Lam. Context-sensitive in-
[13] J. Dean, D. Grove, and C. Chambers. Optimization terprocedural pointer analysis in the presence of dy-
of object-oriented programs using static class hierarchy namic aliasing. In Proceedings of the Ninth Workshop
analysis. In Proceedings of the 9th European Confer- on Languages and Compilers for Parallel Computing,
ence on Object-Oriented Programming, Aarhus, Den- San Jose, CA, August 1996. Springer-Verlag.
mark, August 1995. [26] M. Shapiro and S. Horwitz. Fast and accurate
ow-
[14] A. Deutsch. On determining lifetime and aliasing of insensitive points-to analysis. In Proceedings of the 24th
dynamically allocated data in higher-order functional Annual ACM Symposium on the Principles of Program-
specications. In Proceedings of the 17th Annual ACM ming Languages, Paris, France, January 1997.
Symposium on the Principles of Programming Lan- [27] Bjarne Steensgaard. Points-to analysis in almost linear
guages, pages 157{168, San Francisco, CA, January time. In Proceedings of the 23rd Annual ACM Sympo-
1990. ACM, ACM, New York. sium on the Principles of Programming Languages, St.
[15] A. Deutsch. On the complexity of escape analysis. In Petersburg Beach, FL, January 1996.
Proceedings of the 24th Annual ACM Symposium on the [28] R. Wilson and M. Lam. Ecient context-sensitive
Principles of Programming Languages, Paris, France, pointer analysis for C programs. In Proceedings of the
January 1997. ACM, ACM, New York. SIGPLAN '95 Conference on Program Language De-
[16] P. Diniz and M. Rinard. Lock coarsening: Eliminat- sign and Implementation, La Jolla, CA, June 1995.
ing lock overhead in automatically parallelized object- ACM, New York.
based programs. In Proceedings of the Ninth Workshop [29] Y. Tang and P. Jouvelot. Control-
ow eects for escape
on Languages and Compilers for Parallel Computing, analysis. In Workshop on Static Analysis, pages 313{
pages 285{299, San Jose, CA, August 1996. Springer- 321, September 1992.
Verlag.
[17] P. Diniz and M. Rinard. Synchronization transforma-
tions for parallel computing. In Proceedings of the 24th
Annual ACM Symposium on the Principles of Program-
ming Languages, pages 187{200, Paris, France, January
1997. ACM, New York.
[18] M. Emami, R. Ghiya, and L. Hendren. Context-
sensitive interprocedural points-to analysis in the pres-
ence of function pointers. In Proceedings of the SIG-
PLAN '94 Conference on Program Language Design
and Implementation, pages 242{256, Orlando, FL, June
1994. ACM, New York.
[19] J. Hannan. A type-based analysis for block allocation
in functional languages. In Proceedings of the Second
International Static Analysis Symposium. ACM, ACM,
New York, September 1995.
[20] W. Landi and B. Ryder. A safe approximation algo-
rithm for interprocedural pointer aliasing. In Proceed-
ings of the SIGPLAN '92 Conference on Program Lan-
guage Design and Implementation, San Francisco, CA,
June 1992.