escape.hpp revision 293
196N/A * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A// Adaptation for C2 of the escape analysis algorithm described in: 65N/A// [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano, 65N/A// Vugranam C. Sreedhar, Sam Midkiff, 65N/A// "Escape Analysis for Java", Procedings of ACM SIGPLAN 65N/A// OOPSLA Conference, November 1, 1999 0N/A// The flow-insensitive analysis described in the paper has been implemented. 65N/A// The analysis requires construction of a "connection graph" (CG) for 65N/A// the method being analyzed. The nodes of the connection graph are: 0N/A// - Java objects (JO) 0N/A// - Local variables (LV) 0N/A// - Fields of an object (OF), these also include array elements 0N/A// The CG contains 3 types of edges: 65N/A// - PointsTo (-P>) {LV, OF} to JO 65N/A// - Deferred (-D>) from {LV, OF} to {LV, OF} 0N/A// - Field (-F>) from JO to OF 0N/A// The following utility functions is used by the algorithm: 65N/A// PointsTo(n) - n is any CG node, it returns the set of JO that n could 65N/A// The algorithm describes how to construct the connection graph 65N/A// in the following 4 cases: 0N/A// Case Edges Created 65N/A// (1) p = new T() LV -P> JO 65N/A// (2) p = q LV -D> LV 65N/A// (3) p.f = q JO -F> OF, OF -D> LV 65N/A// (4) p = q.f JO -F> OF, LV -D> OF 65N/A// In all these cases, p and q are local variables. For static field 65N/A// references, we can construct a local variable containing a reference 65N/A// to the static memory. 0N/A// C2 does not have local variables. However for the purposes of constructing 0N/A// the connection graph, the following IR nodes are treated as local variables: 0N/A// Phi (pointer values) 65N/A// Proj#5 (value returned from callnodes including allocations) 65N/A// CheckCastPP, CastPP 65N/A// The LoadP, Proj and CheckCastPP behave like variables assigned to only once. 65N/A// Only a Phi can have multiple assignments. Each input to a Phi is treated 0N/A// as an assignment to it. 65N/A// The following node types are JavaObject: 0N/A// Parm (for incoming arguments) 65N/A// CastX2P ("unsafe" operations) 0N/A// AddP nodes are fields. 0N/A// After building the graph, a pass is made over the nodes, deleting deferred 0N/A// nodes and copying the edges from the target of the deferred edge to the 0N/A// source. This results in a graph with no deferred edges, only: 65N/A// OF -P> JO (the object whose oop is stored in the field) 0N/A// Then, for each node which is GlobalEscape, anything it could point to 0N/A// is marked GlobalEscape. Finally, for any node marked ArgEscape, anything 0N/A// it could point to is marked ArgEscape. 65N/A NoEscape =
1,
// A scalar replaceable object with unique type. 65N/A // argument (and not globally escape during call). 65N/A // which may return it creating a hidden alias. 0N/A // count of outgoing edges 0N/A // node index of target of outgoing edge "e" 0N/A // type of outgoing edge "e" 0N/A // add a edge of the specified type pointing to the specified target 0N/A // remove an edge of the specified type pointing to the specified target 65N/A // by ideal node index. 65N/A // the call build_connection_graph(). 65N/A // is still being collected. If false, 65N/A // no new nodes will be processed. 65N/A // that pointer values loaded from 65N/A // a field which has not been set 65N/A // are assumed to point to. 244N/A // Address of an element in _nodes. Used when the element is to be modified 244N/A // There should be no new ideal nodes during ConnectionGraph build, 244N/A // growableArray::adr_at() will throw assert otherwise. 65N/A // Add node to ConnectionGraph. 0N/A // offset of a field reference 0N/A // compute the escape state for arguments to a call 0N/A // compute the escape state for the return value of a call 65N/A // Populate Connection Graph with Ideal nodes. 65N/A // Build Connection Graph and set nodes escape state. 0N/A // walk the connection graph starting at the node corresponding to "n" and 0N/A // add the index of everything it could point to, to "ptset". This may cause 0N/A // Phi's encountered to get (re)processed (which requires "phase".) 0N/A // Edge manipulation. The "from_i" and "to_i" arguments are the 0N/A // node indices of the source and destination of the edge 0N/A // Add an edge to node given by "to_i" from any field of adr_i whose offset 0N/A // matches "offset" A deferred edge is added if to_i is a LocalVar, and 0N/A // a pointsto edge is added if it is a JavaObject 65N/A // Add a deferred edge from node given by "from_i" to any field 65N/A // of adr_i whose offset matches "offset" 0N/A // Remove outgoing deferred edges from the node referenced by "ni". 0N/A // Any outgoing edges from the target of the deferred edge are copied 0N/A // Used for the following purposes: 0N/A // Memory Phi - most recent unique Phi split out 0N/A // MemNode - new memory input for this node 0N/A // ChecCastPP - allocation that this is a cast of 0N/A // allocation - CheckCastPP of the allocation 0N/A // Propagate unique types created for unescaped allocated objects 0N/A // through the graph 0N/A // manage entries in _node_map 0N/A // Notify optimizer that a node has been modified 0N/A // Node: This assumes that escape analysis is run before 0N/A // PhaseIterGVN creation 0N/A // Set the escape state of a node 244N/A // Check for non-escaping candidates 65N/A // Compute the escape information 0N/A // escape state of a node 65N/A // other information we have collected