Upload
nicholas-little
View
216
Download
0
Embed Size (px)
DESCRIPTION
Reasons for Escape Analysis If an object does not escape the method it was created in, then that object can be allocated onto the stack instead of the heap, since heap allocation is (supposedly) time expensive. If an object does not escape the thread it was created in, then that object does not need to be synchronized. That means that lock() and unlock() do not need to be used on it. These synchronization methods are inherently time expensive.
Citation preview
Escape Analysis for JavaEscape Analysis for Java
Will von Rosenberg Will von Rosenberg Noah WallaceNoah Wallace
Points-to vs. Escape AnalysisPoints-to vs. Escape Analysis Points-toPoints-to
– Memory disambiguationMemory disambiguation– To determine if two pointers can be resolved to point at the same To determine if two pointers can be resolved to point at the same
locationlocation– Points-to graph should lead to the same location for correctness, Points-to graph should lead to the same location for correctness,
i.e. they may resolve to the same memory locationi.e. they may resolve to the same memory location Escape AnalysisEscape Analysis
– Identify objects that might escape a (dynamic) scope such as a Identify objects that might escape a (dynamic) scope such as a method invocation or a thread object.method invocation or a thread object.
– Connection graph may lead to different nodes, but could still be Connection graph may lead to different nodes, but could still be correctcorrect
– Can safely ignore the calling context for escape analysis.Can safely ignore the calling context for escape analysis.
Reasons for Escape AnalysisReasons for Escape Analysis If an object does not escape the method it was If an object does not escape the method it was
created in, then that object can be allocated onto created in, then that object can be allocated onto the stack instead of the heap, since heap the stack instead of the heap, since heap allocation is (supposedly) time expensive.allocation is (supposedly) time expensive.
If an object does not escape the thread it was If an object does not escape the thread it was created in, then that object does not need to be created in, then that object does not need to be synchronized. That means that lock() and unlock() synchronized. That means that lock() and unlock() do not need to be used on it. These do not need to be used on it. These synchronization methods are inherently time synchronization methods are inherently time expensive.expensive.
Escape Analysis Definitions and Escape Analysis Definitions and PropositionsPropositions
An object is said to escape a Method if the lifetime of the An object is said to escape a Method if the lifetime of the object is larger than the lifetime of the Method. That is to object is larger than the lifetime of the Method. That is to say that the scope of the object is greater than the scope of say that the scope of the object is greater than the scope of the Method it was created in. the Method it was created in.
An object is said to escape a Thread if another thread, not An object is said to escape a Thread if another thread, not equal to the first, uses (locks) that object.equal to the first, uses (locks) that object.
If an object does not escape the method, !Escapes(O, M), If an object does not escape the method, !Escapes(O, M), and that method was invoked in thread T, then it can be and that method was invoked in thread T, then it can be said that the object does not escape the thread, !said that the object does not escape the thread, !Escapes(O, T).Escapes(O, T).
(Proposition 2.3)(Proposition 2.3)
Escape LatticeEscape Lattice
GlobalEscapeGlobalEscape– Escapes all Methods and ThreadsEscapes all Methods and Threads
ArgEscapeArgEscape– Escapes the Methods in which it was created, Escapes the Methods in which it was created,
but not the thread invocationbut not the thread invocation NoEscapeNoEscape
– Does not escape either the Method and the Does not escape either the Method and the ThreadThread
Connection GraphConnection Graph
Capture the connectivity relationship among Capture the connectivity relationship among objectsobjects
Connection GraphConnection Graph Fid()Fid()
– A unique number that identifies a field within a class, A unique number that identifies a field within a class, this field identifier or offset, is unique within the class, this field identifier or offset, is unique within the class, and can be compared to instances of the same class.and can be compared to instances of the same class.
The notation refers to a reference node The notation refers to a reference node --------------- that contains an arbitrary number of --------------- that contains an arbitrary number of deferred edges, that lead to a points-to edge.deferred edges, that lead to a points-to edge.
The PointsTo() function refers to all nodes, such The PointsTo() function refers to all nodes, such as the above, where m, through a sequence of as the above, where m, through a sequence of deferred edges, points-to n. The function returns deferred edges, points-to n. The function returns the set of all n’s that m points-to.the set of all n’s that m points-to.
Intraprocedural AnalysisIntraprocedural Analysis
Flow-sensitive and Flow-insensitiveFlow-sensitive and Flow-insensitive Simplify presentation by Simplify presentation by
– splitting a multiple level reference expression splitting a multiple level reference expression into a two level reference. ()into a two level reference. ()
– Bypass() functionBypass() function Eliminates all edges to a node, either incoming, or Eliminates all edges to a node, either incoming, or
outgoing.outgoing. Redirects them to a more precise location for the Redirects them to a more precise location for the
purpose of flow-sensitive analysispurpose of flow-sensitive analysis
Intra (cont’d)Intra (cont’d) P=new r()P=new r()
– FS (Flow Sensitive) new object node is created and ByPass(p). FS (Flow Sensitive) new object node is created and ByPass(p). – FI new object node created with a points to edge from p to new node. FI new object node created with a points to edge from p to new node.
ByPass(p) is not called.ByPass(p) is not called. P=qP=q
– FS apply ByPass(p) and add the deferred edge to q.FS apply ByPass(p) and add the deferred edge to q.– FI ignore ByPass(p) and add the deferred edge to q.FI ignore ByPass(p) and add the deferred edge to q.
P.f=q P.f=q – FS and FI are treated the same. We ignore ByPass(p) and add the FS and FI are treated the same. We ignore ByPass(p) and add the
deferred edges from V-> q. Where V are the field nodes. Phantom nodes deferred edges from V-> q. Where V are the field nodes. Phantom nodes may be created if pointsto(p) = 0 and field nodes may be created if V is may be created if pointsto(p) = 0 and field nodes may be created if V is empty.empty.
P=q.fP=q.f– FS apply ByPass(p) and add the deferred edge to V. FS apply ByPass(p) and add the deferred edge to V. – FI ignore ByPass(p) and add the deferred edge to VFI ignore ByPass(p) and add the deferred edge to V. .
Interprocedural AnalysisInterprocedural Analysis
Method Entry Method Entry Method Exit Method Exit Immediately before method invocationImmediately before method invocation Immediately after method invocationImmediately after method invocation
Method EntryMethod Entry
Create Phantom reference nodes Create Phantom reference nodes – F1F1 a a
F1 is the phantom node and a is the formal F1 is the phantom node and a is the formal parameters.parameters.
– EscapeState[F1] = NoEscapeEscapeState[F1] = NoEscape Because it is a phantom node and created and Because it is a phantom node and created and
deleted in the Method. deleted in the Method. – EscapeState[a1] = ArgEscapeEscapeState[a1] = ArgEscape
a1 is created outside the method so it can leave the a1 is created outside the method so it can leave the method.method.
Method ExitMethod Exit
Partitions graph into three subgraphsPartitions graph into three subgraphs– Those nodes reachable by GlobalEscapeThose nodes reachable by GlobalEscape– Those nodes reachable by ArgEscapeThose nodes reachable by ArgEscape– Those nodes that are left are NoEscapeThose nodes that are left are NoEscape
The union of GlobalEscape and ArgEscape The union of GlobalEscape and ArgEscape graphs are deamed the NonLocalGraphgraphs are deamed the NonLocalGraph
The NoEscape graph is deamed the The NoEscape graph is deamed the LocalGraphLocalGraph
Immediately Before a MethodImmediately Before a Method
Each parameter (object node) of the caller will be Each parameter (object node) of the caller will be mapped to an object node in the calleemapped to an object node in the callee
Once inside, the Phantom reference nodes will be Once inside, the Phantom reference nodes will be created referring back to the parameter object created referring back to the parameter object node.node.
These correlations will be kept track of for both the These correlations will be kept track of for both the purpose of the return values of the nodes and the purpose of the return values of the nodes and the ability to reconstruct the connection graph in the ability to reconstruct the connection graph in the event of another call of the same function.event of another call of the same function.
Immediately After a MethodImmediately After a Method
The mapping from the Before, a1, a2…aN, The mapping from the Before, a1, a2…aN, will then get the escape status of the will then get the escape status of the phantom nodes in the callee.phantom nodes in the callee.
The edges will be updated as well, showing The edges will be updated as well, showing the new relationships that were effected by the new relationships that were effected by the callee.the callee.
Updating Caller NodesUpdating Caller Nodes
This ensures that the node ai, in the caller This ensures that the node ai, in the caller function, will map to the correlated a^I, in function, will map to the correlated a^I, in the callee function.the callee function.
Through recursion, we also ensure that the Through recursion, we also ensure that the set PointsTo(ai) will be equal to the set set PointsTo(ai) will be equal to the set PointsTo(a^I)PointsTo(a^I)
ResultsResults
Results (cont’d)Results (cont’d)
Results (cont’d)Results (cont’d)
Results (cont’d)Results (cont’d)
Results (cont’d)Results (cont’d)
Percentage of objects that may be allocated Percentage of objects that may be allocated on the stack exceeds 70% of all dynamically on the stack exceeds 70% of all dynamically created objects in three out of ten created objects in three out of ten benchmarks. benchmarks.
11% to 92% of all lock operations are 11% to 92% of all lock operations are eliminated in the ten programs.eliminated in the ten programs.
And execution time reduction ranges from And execution time reduction ranges from 2% to 23%. 2% to 23%.
Results FinalResults Final
We’re done!We’re done!
……but wait…but wait…
Congrats to Noah and Kaleem (Hopefully) Congrats to Noah and Kaleem (Hopefully) on their last day of class for a while on their last day of class for a while
Does anybody have anything to do for Does anybody have anything to do for tomorrow?tomorrow?– Who’s 21? (raise your hand!)Who’s 21? (raise your hand!)– Who wants to go to Flats? For Margarita’s? Who wants to go to Flats? For Margarita’s? – PhD’s allowed! PhD’s allowed!