escape.hpp revision 3932
1472N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 1010N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1010N/A * This code is free software; you can redistribute it and/or modify it 1010N/A * under the terms of the GNU General Public License version 2 only, as 1010N/A * published by the Free Software Foundation. 1010N/A * This code is distributed in the hope that it will be useful, but WITHOUT 1010N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1010N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1010N/A * version 2 for more details (a copy is included in the LICENSE file that 1010N/A * You should have received a copy of the GNU General Public License version 1010N/A * 2 along with this work; if not, write to the Free Software Foundation, 1010N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1010N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1010N/A// Adaptation for C2 of the escape analysis algorithm described in: 1010N/A// [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano, 1010N/A// Vugranam C. Sreedhar, Sam Midkiff, 1010N/A// "Escape Analysis for Java", Procedings of ACM SIGPLAN 1010N/A// OOPSLA Conference, November 1, 1999 1010N/A// The flow-insensitive analysis described in the paper has been implemented. 1010N/A// The analysis requires construction of a "connection graph" (CG) for 1010N/A// the method being analyzed. The nodes of the connection graph are: 1010N/A// - Fields of an object (OF), these also include array elements 1010N/A// The CG contains 3 types of edges: 1010N/A// - PointsTo (-P>) {LV, OF} to JO 1010N/A// - Deferred (-D>) from {LV, OF} to {LV, OF} 1010N/A// - Field (-F>) from JO to OF 1010N/A// The following utility functions is used by the algorithm: 1010N/A// PointsTo(n) - n is any CG node, it returns the set of JO that n could // The algorithm describes how to construct the connection graph // in the following 4 cases: // (1) p = new T() LV -P> JO // (3) p.f = q JO -F> OF, OF -D> LV // (4) p = q.f JO -F> OF, LV -D> OF // In all these cases, p and q are local variables. For static field // references, we can construct a local variable containing a reference // C2 does not have local variables. However for the purposes of constructing // the connection graph, the following IR nodes are treated as local variables: // Proj#5 (value returned from callnodes including allocations) // The LoadP, Proj and CheckCastPP behave like variables assigned to only once. // Only a Phi can have multiple assignments. Each input to a Phi is treated // as an assignment to it. // The following node types are JavaObject: // phantom_object (general globally escaped object) // Parm (for incoming arguments) // CastX2P ("unsafe" operations) // CallStaticJava (which returns Object) // AddP nodes are fields. // After building the graph, a pass is made over the nodes, deleting deferred // nodes and copying the edges from the target of the deferred edge to the // source. This results in a graph with no deferred edges, only: // OF -P> JO (the object whose oop is stored in the field) // Then, for each node which is GlobalEscape, anything it could point to // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything // it could point to is marked ArgEscape. Node*
const _node;
// Ideal node corresponding to this PointsTo node. const int _idx;
// Cached ideal node's _idx NoEscape =
1,
// An object does not escape method or thread and it is // not passed to call. It could be replaced with scalar. ArgEscape =
2,
// An object does not escape method or thread but it is // passed as argument to call or referenced by argument // and it does not escape during call. // Mark base edge use to distinguish from stored value edge. // Return true if this node points to specified node or nodes it points to. // Return true if this node points only to non-escaping allocations. // Return true if one node points to an other. const int _offset;
// Field's offset. const bool _is_oop;
// Field points to object // Return true if bases points to this java object. // Iterators for PointsTo node's edges: // for (EdgeIterator i(n); i.has_next(); i.next()) { // PointsToNode* u = i.get(); inline void next() { i++; }
// ConnectionGraph nodes. bool _collecting;
// Indicates whether escape information // is still being collected. If false, // no new nodes will be processed. // Address of an element in _nodes. Used when the element is to be modified // There should be no new ideal nodes during ConnectionGraph build, // growableArray::at() will throw assert otherwise. // Add nodes to ConnectionGraph. // Compute the escape state for arguments to a call. // Add PointsToNode node corresponding to a call // Map ideal node to existing PointsTo node (usually phantom_object). // Create PointsToNode node and add it to Connection Graph. // Add final simple edges to graph. // Finish Graph construction. // Add all references to this JavaObject node. // Put node on worklist if it is (or was) not there. // Put on worklist all uses of this node. // Put on worklist all field's uses and related field nodes. // Put on worklist all related field nodes. // Find fields which have unknown value. // Find fields initializing values for allocations. // Set the escape state of an object and its fields. // Don't change non-escaping state of NULL pointer. // Don't change non-escaping state of NULL pointer. // Propagate GlobalEscape and ArgEscape escape states to all nodes // and check that we still have non-escaping java objects. // Adjust scalar_replaceable state after Connection Graph is built. // Optimize objects compare. // Returns unique corresponding java object or NULL. // Add an edge of the specified type pointing to the specified target. return false;
// already points to phantom_obj // Add an edge from Field node to its base and back. return false;
// already has phantom_obj base return is_new;
// Don't add fields to NULL pointer. // Add LocalVar node and edge if possible return;
// Process it later. // offset of a field reference // Propagate unique types created for unescaped allocated objects // Helper methods for unique types split. // Used for the following purposes: // Memory Phi - most recent unique Phi split out // MemNode - new memory input for this node // ChecCastPP - allocation that this is a cast of // allocation - CheckCastPP of the allocation // manage entries in _node_map // Notify optimizer that a node has been modified // Compute the escape information // Check for non-escaping candidates // Perform escape analysis #
endif // SHARE_VM_OPTO_ESCAPE_HPP