escape.hpp revision 4015
3619N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 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: 2896N/A// phantom_object (general globally escaped object) 0N/A// Parm (for incoming arguments) 65N/A// CastX2P ("unsafe" operations) 2896N/A// CallStaticJava (which returns Object) 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. 2896N/A NoEscape =
1,
// An object does not escape method or thread and it is 2896N/A // not passed to call. It could be replaced with scalar. 2896N/A // passed as argument to call or referenced by argument 2896N/A // and it does not escape during call. 3619N/A // Mark base edge use to distinguish from stored value edge. 3619N/A // Return true if this node points to specified node or nodes it points to. 3619N/A // Return true if this node points only to non-escaping allocations. 3619N/A // Return true if one node points to an other. 3619N/A // Return true if bases points to this java object. 3619N/A// Iterators for PointsTo node's edges: 3619N/A// for (EdgeIterator i(n); i.has_next(); i.next()) { 3619N/A// PointsToNode* u = i.get(); 3619N/A // is still being collected. If false, 3619N/A // no new nodes will be processed. 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, 3619N/A // growableArray::at() will throw assert otherwise. 3619N/A // Add nodes to ConnectionGraph. 3619N/A // Compute the escape state for arguments to a call. 3619N/A // Add PointsToNode node corresponding to a call 3619N/A // Map ideal node to existing PointsTo node (usually phantom_object). 4015N/A // Utility function for nodes that load an object 3619N/A // Create PointsToNode node and add it to Connection Graph. 3619N/A // Add final simple edges to graph. 3619N/A // Finish Graph construction. 3619N/A // Add all references to this JavaObject node. 3619N/A // Put node on worklist if it is (or was) not there. 3619N/A // Put on worklist all uses of this node. 3619N/A // Put on worklist all field's uses and related field nodes. 3619N/A // Put on worklist all related field nodes. 3619N/A // Find fields which have unknown value. 3619N/A // Find fields initializing values for allocations. 3619N/A // Set the escape state of an object and its fields. 3619N/A // Don't change non-escaping state of NULL pointer. 3619N/A // Don't change non-escaping state of NULL pointer. 3619N/A // Propagate GlobalEscape and ArgEscape escape states to all nodes 3619N/A // and check that we still have non-escaping java objects. 3619N/A // Adjust scalar_replaceable state after Connection Graph is built. 3619N/A // Optimize objects compare. 3619N/A // Returns unique corresponding java object or NULL. 3619N/A // Add an edge of the specified type pointing to the specified target. 3619N/A return false;
// already points to phantom_obj 3619N/A // Add an edge from Field node to its base and back. 3619N/A return false;
// already has phantom_obj base 3619N/A // Add LocalVar node and edge if possible 3619N/A return;
// Process it later. 0N/A // offset of a field reference 3619N/A // Propagate unique types created for unescaped allocated objects 3619N/A // Helper methods for unique types split. 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 // manage entries in _node_map 0N/A // Notify optimizer that a node has been modified 2121N/A // Compute the escape information 244N/A // Check for non-escaping candidates 1879N/A#
endif // SHARE_VM_OPTO_ESCAPE_HPP