aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_OPTO_ESCAPE_HPP aoqi@0: #define SHARE_VM_OPTO_ESCAPE_HPP aoqi@0: aoqi@0: #include "opto/addnode.hpp" aoqi@0: #include "opto/node.hpp" aoqi@0: #include "utilities/growableArray.hpp" aoqi@0: aoqi@0: // aoqi@0: // Adaptation for C2 of the escape analysis algorithm described in: aoqi@0: // aoqi@0: // [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano, aoqi@0: // Vugranam C. Sreedhar, Sam Midkiff, aoqi@0: // "Escape Analysis for Java", Procedings of ACM SIGPLAN aoqi@0: // OOPSLA Conference, November 1, 1999 aoqi@0: // aoqi@0: // The flow-insensitive analysis described in the paper has been implemented. aoqi@0: // aoqi@0: // The analysis requires construction of a "connection graph" (CG) for aoqi@0: // the method being analyzed. The nodes of the connection graph are: aoqi@0: // aoqi@0: // - Java objects (JO) aoqi@0: // - Local variables (LV) aoqi@0: // - Fields of an object (OF), these also include array elements aoqi@0: // aoqi@0: // The CG contains 3 types of edges: aoqi@0: // aoqi@0: // - PointsTo (-P>) {LV, OF} to JO aoqi@0: // - Deferred (-D>) from {LV, OF} to {LV, OF} aoqi@0: // - Field (-F>) from JO to OF aoqi@0: // aoqi@0: // The following utility functions is used by the algorithm: aoqi@0: // aoqi@0: // PointsTo(n) - n is any CG node, it returns the set of JO that n could aoqi@0: // point to. aoqi@0: // aoqi@0: // The algorithm describes how to construct the connection graph aoqi@0: // in the following 4 cases: aoqi@0: // aoqi@0: // Case Edges Created aoqi@0: // aoqi@0: // (1) p = new T() LV -P> JO aoqi@0: // (2) p = q LV -D> LV aoqi@0: // (3) p.f = q JO -F> OF, OF -D> LV aoqi@0: // (4) p = q.f JO -F> OF, LV -D> OF aoqi@0: // aoqi@0: // In all these cases, p and q are local variables. For static field aoqi@0: // references, we can construct a local variable containing a reference aoqi@0: // to the static memory. aoqi@0: // aoqi@0: // C2 does not have local variables. However for the purposes of constructing aoqi@0: // the connection graph, the following IR nodes are treated as local variables: aoqi@0: // Phi (pointer values) aoqi@0: // LoadP, LoadN aoqi@0: // Proj#5 (value returned from callnodes including allocations) aoqi@0: // CheckCastPP, CastPP aoqi@0: // aoqi@0: // The LoadP, Proj and CheckCastPP behave like variables assigned to only once. aoqi@0: // Only a Phi can have multiple assignments. Each input to a Phi is treated aoqi@0: // as an assignment to it. aoqi@0: // aoqi@0: // The following node types are JavaObject: aoqi@0: // aoqi@0: // phantom_object (general globally escaped object) aoqi@0: // Allocate aoqi@0: // AllocateArray aoqi@0: // Parm (for incoming arguments) aoqi@0: // CastX2P ("unsafe" operations) aoqi@0: // CreateEx aoqi@0: // ConP aoqi@0: // LoadKlass aoqi@0: // ThreadLocal aoqi@0: // CallStaticJava (which returns Object) aoqi@0: // aoqi@0: // AddP nodes are fields. aoqi@0: // aoqi@0: // After building the graph, a pass is made over the nodes, deleting deferred aoqi@0: // nodes and copying the edges from the target of the deferred edge to the aoqi@0: // source. This results in a graph with no deferred edges, only: aoqi@0: // aoqi@0: // LV -P> JO aoqi@0: // OF -P> JO (the object whose oop is stored in the field) aoqi@0: // JO -F> OF aoqi@0: // aoqi@0: // Then, for each node which is GlobalEscape, anything it could point to aoqi@0: // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything aoqi@0: // it could point to is marked ArgEscape. aoqi@0: // aoqi@0: aoqi@0: class Compile; aoqi@0: class Node; aoqi@0: class CallNode; aoqi@0: class PhiNode; aoqi@0: class PhaseTransform; aoqi@0: class PointsToNode; aoqi@0: class Type; aoqi@0: class TypePtr; aoqi@0: class VectorSet; aoqi@0: aoqi@0: class JavaObjectNode; aoqi@0: class LocalVarNode; aoqi@0: class FieldNode; aoqi@0: class ArraycopyNode; aoqi@0: aoqi@0: // ConnectionGraph nodes aoqi@0: class PointsToNode : public ResourceObj { aoqi@0: GrowableArray _edges; // List of nodes this node points to aoqi@0: GrowableArray _uses; // List of nodes which point to this node aoqi@0: aoqi@0: const u1 _type; // NodeType aoqi@0: u1 _flags; // NodeFlags aoqi@0: u1 _escape; // EscapeState of object aoqi@0: u1 _fields_escape; // EscapeState of object's fields aoqi@0: aoqi@0: Node* const _node; // Ideal node corresponding to this PointsTo node. aoqi@0: const int _idx; // Cached ideal node's _idx aoqi@0: aoqi@0: public: aoqi@0: typedef enum { aoqi@0: UnknownType = 0, aoqi@0: JavaObject = 1, aoqi@0: LocalVar = 2, aoqi@0: Field = 3, aoqi@0: Arraycopy = 4 aoqi@0: } NodeType; aoqi@0: aoqi@0: typedef enum { aoqi@0: UnknownEscape = 0, aoqi@0: NoEscape = 1, // An object does not escape method or thread and it is aoqi@0: // not passed to call. It could be replaced with scalar. aoqi@0: ArgEscape = 2, // An object does not escape method or thread but it is aoqi@0: // passed as argument to call or referenced by argument aoqi@0: // and it does not escape during call. aoqi@0: GlobalEscape = 3 // An object escapes the method or thread. aoqi@0: } EscapeState; aoqi@0: aoqi@0: typedef enum { aoqi@0: ScalarReplaceable = 1, // Not escaped object could be replaced with scalar aoqi@0: PointsToUnknown = 2, // Has edge to phantom_object aoqi@0: ArraycopySrc = 4, // Has edge from Arraycopy node aoqi@0: ArraycopyDst = 8 // Has edge to Arraycopy node aoqi@0: } NodeFlags; aoqi@0: aoqi@0: aoqi@0: PointsToNode(Compile *C, Node* n, EscapeState es, NodeType type): aoqi@0: _edges(C->comp_arena(), 2, 0, NULL), aoqi@0: _uses (C->comp_arena(), 2, 0, NULL), aoqi@0: _node(n), aoqi@0: _idx(n->_idx), aoqi@0: _type((u1)type), aoqi@0: _escape((u1)es), aoqi@0: _fields_escape((u1)es), aoqi@0: _flags(ScalarReplaceable) { aoqi@0: assert(n != NULL && es != UnknownEscape, "sanity"); aoqi@0: } aoqi@0: aoqi@0: Node* ideal_node() const { return _node; } aoqi@0: int idx() const { return _idx; } aoqi@0: aoqi@0: bool is_JavaObject() const { return _type == (u1)JavaObject; } aoqi@0: bool is_LocalVar() const { return _type == (u1)LocalVar; } aoqi@0: bool is_Field() const { return _type == (u1)Field; } aoqi@0: bool is_Arraycopy() const { return _type == (u1)Arraycopy; } aoqi@0: aoqi@0: JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; } aoqi@0: LocalVarNode* as_LocalVar() { assert(is_LocalVar(),""); return (LocalVarNode*)this; } aoqi@0: FieldNode* as_Field() { assert(is_Field(),""); return (FieldNode*)this; } aoqi@0: ArraycopyNode* as_Arraycopy() { assert(is_Arraycopy(),""); return (ArraycopyNode*)this; } aoqi@0: aoqi@0: EscapeState escape_state() const { return (EscapeState)_escape; } aoqi@0: void set_escape_state(EscapeState state) { _escape = (u1)state; } aoqi@0: aoqi@0: EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; } aoqi@0: void set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; } aoqi@0: aoqi@0: bool has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; } aoqi@0: void set_has_unknown_ptr() { _flags |= PointsToUnknown; } aoqi@0: aoqi@0: bool arraycopy_src() const { return (_flags & ArraycopySrc) != 0; } aoqi@0: void set_arraycopy_src() { _flags |= ArraycopySrc; } aoqi@0: bool arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; } aoqi@0: void set_arraycopy_dst() { _flags |= ArraycopyDst; } aoqi@0: aoqi@0: bool scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;} aoqi@0: void set_scalar_replaceable(bool v) { aoqi@0: if (v) aoqi@0: _flags |= ScalarReplaceable; aoqi@0: else aoqi@0: _flags &= ~ScalarReplaceable; aoqi@0: } aoqi@0: aoqi@0: int edge_count() const { return _edges.length(); } aoqi@0: PointsToNode* edge(int e) const { return _edges.at(e); } aoqi@0: bool add_edge(PointsToNode* edge) { return _edges.append_if_missing(edge); } aoqi@0: aoqi@0: int use_count() const { return _uses.length(); } aoqi@0: PointsToNode* use(int e) const { return _uses.at(e); } aoqi@0: bool add_use(PointsToNode* use) { return _uses.append_if_missing(use); } aoqi@0: aoqi@0: // Mark base edge use to distinguish from stored value edge. aoqi@0: bool add_base_use(FieldNode* use) { return _uses.append_if_missing((PointsToNode*)((intptr_t)use + 1)); } aoqi@0: static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); } aoqi@0: static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); } aoqi@0: aoqi@0: // Return true if this node points to specified node or nodes it points to. aoqi@0: bool points_to(JavaObjectNode* ptn) const; aoqi@0: aoqi@0: // Return true if this node points only to non-escaping allocations. aoqi@0: bool non_escaping_allocation(); aoqi@0: aoqi@0: // Return true if one node points to an other. aoqi@0: bool meet(PointsToNode* ptn); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: NodeType node_type() const { return (NodeType)_type;} aoqi@0: void dump(bool print_state=true) const; aoqi@0: #endif aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: class LocalVarNode: public PointsToNode { aoqi@0: public: aoqi@0: LocalVarNode(Compile *C, Node* n, EscapeState es): aoqi@0: PointsToNode(C, n, es, LocalVar) {} aoqi@0: }; aoqi@0: aoqi@0: class JavaObjectNode: public PointsToNode { aoqi@0: public: aoqi@0: JavaObjectNode(Compile *C, Node* n, EscapeState es): aoqi@0: PointsToNode(C, n, es, JavaObject) { aoqi@0: if (es > NoEscape) aoqi@0: set_scalar_replaceable(false); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class FieldNode: public PointsToNode { aoqi@0: GrowableArray _bases; // List of JavaObject nodes which point to this node aoqi@0: const int _offset; // Field's offset. aoqi@0: const bool _is_oop; // Field points to object aoqi@0: bool _has_unknown_base; // Has phantom_object base aoqi@0: public: aoqi@0: FieldNode(Compile *C, Node* n, EscapeState es, int offs, bool is_oop): aoqi@0: PointsToNode(C, n, es, Field), aoqi@0: _offset(offs), _is_oop(is_oop), aoqi@0: _has_unknown_base(false) {} aoqi@0: aoqi@0: int offset() const { return _offset;} aoqi@0: bool is_oop() const { return _is_oop;} aoqi@0: bool has_unknown_base() const { return _has_unknown_base; } aoqi@0: void set_has_unknown_base() { _has_unknown_base = true; } aoqi@0: aoqi@0: int base_count() const { return _bases.length(); } aoqi@0: PointsToNode* base(int e) const { return _bases.at(e); } aoqi@0: bool add_base(PointsToNode* base) { return _bases.append_if_missing(base); } aoqi@0: #ifdef ASSERT aoqi@0: // Return true if bases points to this java object. aoqi@0: bool has_base(JavaObjectNode* ptn) const; aoqi@0: #endif aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: class ArraycopyNode: public PointsToNode { aoqi@0: public: aoqi@0: ArraycopyNode(Compile *C, Node* n, EscapeState es): aoqi@0: PointsToNode(C, n, es, Arraycopy) {} aoqi@0: }; aoqi@0: aoqi@0: // Iterators for PointsTo node's edges: aoqi@0: // for (EdgeIterator i(n); i.has_next(); i.next()) { aoqi@0: // PointsToNode* u = i.get(); aoqi@0: class PointsToIterator: public StackObj { aoqi@0: protected: aoqi@0: const PointsToNode* node; aoqi@0: const int cnt; aoqi@0: int i; aoqi@0: public: aoqi@0: inline PointsToIterator(const PointsToNode* n, int cnt) : node(n), cnt(cnt), i(0) { } aoqi@0: inline bool has_next() const { return i < cnt; } aoqi@0: inline void next() { i++; } aoqi@0: PointsToNode* get() const { ShouldNotCallThis(); return NULL; } aoqi@0: }; aoqi@0: aoqi@0: class EdgeIterator: public PointsToIterator { aoqi@0: public: aoqi@0: inline EdgeIterator(const PointsToNode* n) : PointsToIterator(n, n->edge_count()) { } aoqi@0: inline PointsToNode* get() const { return node->edge(i); } aoqi@0: }; aoqi@0: aoqi@0: class UseIterator: public PointsToIterator { aoqi@0: public: aoqi@0: inline UseIterator(const PointsToNode* n) : PointsToIterator(n, n->use_count()) { } aoqi@0: inline PointsToNode* get() const { return node->use(i); } aoqi@0: }; aoqi@0: aoqi@0: class BaseIterator: public PointsToIterator { aoqi@0: public: aoqi@0: inline BaseIterator(const FieldNode* n) : PointsToIterator(n, n->base_count()) { } aoqi@0: inline PointsToNode* get() const { return ((PointsToNode*)node)->as_Field()->base(i); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: class ConnectionGraph: public ResourceObj { aoqi@0: private: aoqi@0: GrowableArray _nodes; // Map from ideal nodes to aoqi@0: // ConnectionGraph nodes. aoqi@0: aoqi@0: GrowableArray _worklist; // Nodes to be processed aoqi@0: aoqi@0: bool _collecting; // Indicates whether escape information aoqi@0: // is still being collected. If false, aoqi@0: // no new nodes will be processed. aoqi@0: aoqi@0: bool _verify; // verify graph aoqi@0: aoqi@0: JavaObjectNode* phantom_obj; // Unknown object aoqi@0: JavaObjectNode* null_obj; aoqi@0: Node* _pcmp_neq; // ConI(#CC_GT) aoqi@0: Node* _pcmp_eq; // ConI(#CC_EQ) aoqi@0: aoqi@0: Compile* _compile; // Compile object for current compilation aoqi@0: PhaseIterGVN* _igvn; // Value numbering aoqi@0: aoqi@0: Unique_Node_List ideal_nodes; // Used by CG construction and types splitting. aoqi@0: aoqi@0: // Address of an element in _nodes. Used when the element is to be modified aoqi@0: PointsToNode* ptnode_adr(int idx) const { aoqi@0: // There should be no new ideal nodes during ConnectionGraph build, aoqi@0: // growableArray::at() will throw assert otherwise. aoqi@0: return _nodes.at(idx); aoqi@0: } aoqi@0: uint nodes_size() const { return _nodes.length(); } aoqi@0: aoqi@0: // Add nodes to ConnectionGraph. aoqi@0: void add_local_var(Node* n, PointsToNode::EscapeState es); aoqi@0: void add_java_object(Node* n, PointsToNode::EscapeState es); aoqi@0: void add_field(Node* n, PointsToNode::EscapeState es, int offset); aoqi@0: void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst); aoqi@0: aoqi@0: // Compute the escape state for arguments to a call. aoqi@0: void process_call_arguments(CallNode *call); aoqi@0: aoqi@0: // Add PointsToNode node corresponding to a call aoqi@0: void add_call_node(CallNode* call); aoqi@0: aoqi@0: // Map ideal node to existing PointsTo node (usually phantom_object). aoqi@0: void map_ideal_node(Node *n, PointsToNode* ptn) { aoqi@0: assert(ptn != NULL, "only existing PointsTo node"); aoqi@0: _nodes.at_put(n->_idx, ptn); aoqi@0: } aoqi@0: aoqi@0: // Utility function for nodes that load an object aoqi@0: void add_objload_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist); aoqi@0: // Create PointsToNode node and add it to Connection Graph. aoqi@0: void add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist); aoqi@0: aoqi@0: // Add final simple edges to graph. aoqi@0: void add_final_edges(Node *n); aoqi@0: aoqi@0: // Finish Graph construction. aoqi@0: bool complete_connection_graph(GrowableArray& ptnodes_worklist, aoqi@0: GrowableArray& non_escaped_worklist, aoqi@0: GrowableArray& java_objects_worklist, aoqi@0: GrowableArray& oop_fields_worklist); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: void verify_connection_graph(GrowableArray& ptnodes_worklist, aoqi@0: GrowableArray& non_escaped_worklist, aoqi@0: GrowableArray& java_objects_worklist, aoqi@0: GrowableArray& addp_worklist); aoqi@0: #endif aoqi@0: aoqi@0: // Add all references to this JavaObject node. aoqi@0: int add_java_object_edges(JavaObjectNode* jobj, bool populate_worklist); aoqi@0: aoqi@0: // Put node on worklist if it is (or was) not there. aoqi@0: void add_to_worklist(PointsToNode* pt) { aoqi@0: _worklist.push(pt); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Put on worklist all uses of this node. aoqi@0: void add_uses_to_worklist(PointsToNode* pt) { aoqi@0: for (UseIterator i(pt); i.has_next(); i.next()) aoqi@0: _worklist.push(i.get()); aoqi@0: } aoqi@0: aoqi@0: // Put on worklist all field's uses and related field nodes. aoqi@0: void add_field_uses_to_worklist(FieldNode* field); aoqi@0: aoqi@0: // Put on worklist all related field nodes. aoqi@0: void add_fields_to_worklist(FieldNode* field, PointsToNode* base); aoqi@0: aoqi@0: // Find fields which have unknown value. aoqi@0: int find_field_value(FieldNode* field); aoqi@0: aoqi@0: // Find fields initializing values for allocations. aoqi@0: int find_init_values(JavaObjectNode* ptn, PointsToNode* init_val, PhaseTransform* phase); aoqi@0: aoqi@0: // Set the escape state of an object and its fields. aoqi@0: void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) { aoqi@0: // Don't change non-escaping state of NULL pointer. aoqi@0: if (ptn != null_obj) { aoqi@0: if (ptn->escape_state() < esc) aoqi@0: ptn->set_escape_state(esc); aoqi@0: if (ptn->fields_escape_state() < esc) aoqi@0: ptn->set_fields_escape_state(esc); aoqi@0: } aoqi@0: } aoqi@0: void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) { aoqi@0: // Don't change non-escaping state of NULL pointer. aoqi@0: if (ptn != null_obj) { aoqi@0: if (ptn->fields_escape_state() < esc) aoqi@0: ptn->set_fields_escape_state(esc); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Propagate GlobalEscape and ArgEscape escape states to all nodes aoqi@0: // and check that we still have non-escaping java objects. aoqi@0: bool find_non_escaped_objects(GrowableArray& ptnodes_worklist, aoqi@0: GrowableArray& non_escaped_worklist); aoqi@0: aoqi@0: // Adjust scalar_replaceable state after Connection Graph is built. aoqi@0: void adjust_scalar_replaceable_state(JavaObjectNode* jobj); aoqi@0: aoqi@0: // Optimize ideal graph. aoqi@0: void optimize_ideal_graph(GrowableArray& ptr_cmp_worklist, aoqi@0: GrowableArray& storestore_worklist); aoqi@0: // Optimize objects compare. aoqi@0: Node* optimize_ptr_compare(Node* n); aoqi@0: aoqi@0: // Returns unique corresponding java object or NULL. aoqi@0: JavaObjectNode* unique_java_object(Node *n); aoqi@0: aoqi@0: // Add an edge of the specified type pointing to the specified target. aoqi@0: bool add_edge(PointsToNode* from, PointsToNode* to) { aoqi@0: assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity"); aoqi@0: aoqi@0: if (to == phantom_obj) { aoqi@0: if (from->has_unknown_ptr()) { aoqi@0: return false; // already points to phantom_obj aoqi@0: } aoqi@0: from->set_has_unknown_ptr(); aoqi@0: } aoqi@0: aoqi@0: bool is_new = from->add_edge(to); aoqi@0: assert(to != phantom_obj || is_new, "sanity"); aoqi@0: if (is_new) { // New edge? aoqi@0: assert(!_verify, "graph is incomplete"); aoqi@0: is_new = to->add_use(from); aoqi@0: assert(is_new, "use should be also new"); aoqi@0: } aoqi@0: return is_new; aoqi@0: } aoqi@0: aoqi@0: // Add an edge from Field node to its base and back. aoqi@0: bool add_base(FieldNode* from, PointsToNode* to) { aoqi@0: assert(!to->is_Arraycopy(), "sanity"); aoqi@0: if (to == phantom_obj) { aoqi@0: if (from->has_unknown_base()) { aoqi@0: return false; // already has phantom_obj base aoqi@0: } aoqi@0: from->set_has_unknown_base(); aoqi@0: } aoqi@0: bool is_new = from->add_base(to); aoqi@0: assert(to != phantom_obj || is_new, "sanity"); aoqi@0: if (is_new) { // New edge? aoqi@0: assert(!_verify, "graph is incomplete"); aoqi@0: if (to == null_obj) aoqi@0: return is_new; // Don't add fields to NULL pointer. aoqi@0: if (to->is_JavaObject()) { aoqi@0: is_new = to->add_edge(from); aoqi@0: } else { aoqi@0: is_new = to->add_base_use(from); aoqi@0: } aoqi@0: assert(is_new, "use should be also new"); aoqi@0: } aoqi@0: return is_new; aoqi@0: } aoqi@0: aoqi@0: // Add LocalVar node and edge if possible aoqi@0: void add_local_var_and_edge(Node* n, PointsToNode::EscapeState es, Node* to, aoqi@0: Unique_Node_List *delayed_worklist) { aoqi@0: PointsToNode* ptn = ptnode_adr(to->_idx); aoqi@0: if (delayed_worklist != NULL) { // First iteration of CG construction aoqi@0: add_local_var(n, es); aoqi@0: if (ptn == NULL) { aoqi@0: delayed_worklist->push(n); aoqi@0: return; // Process it later. aoqi@0: } aoqi@0: } else { aoqi@0: assert(ptn != NULL, "node should be registered"); aoqi@0: } aoqi@0: add_edge(ptnode_adr(n->_idx), ptn); aoqi@0: } aoqi@0: // Helper functions aoqi@0: bool is_oop_field(Node* n, int offset, bool* unsafe); aoqi@0: static Node* get_addp_base(Node *addp); aoqi@0: static Node* find_second_addp(Node* addp, Node* n); aoqi@0: // offset of a field reference aoqi@0: int address_offset(Node* adr, PhaseTransform *phase); aoqi@0: aoqi@0: aoqi@0: // Propagate unique types created for unescaped allocated objects aoqi@0: // through the graph aoqi@0: void split_unique_types(GrowableArray &alloc_worklist); aoqi@0: aoqi@0: // Helper methods for unique types split. aoqi@0: bool split_AddP(Node *addp, Node *base); aoqi@0: aoqi@0: PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray &orig_phi_worklist, bool &new_created); aoqi@0: PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray &orig_phi_worklist); aoqi@0: aoqi@0: void move_inst_mem(Node* n, GrowableArray &orig_phis); aoqi@0: Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray &orig_phi_worklist); aoqi@0: Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop); aoqi@0: aoqi@0: aoqi@0: GrowableArray _mergemem_worklist; // List of all MergeMem nodes aoqi@0: aoqi@0: Node_Array _node_map; // used for bookeeping during type splitting aoqi@0: // Used for the following purposes: aoqi@0: // Memory Phi - most recent unique Phi split out aoqi@0: // from this Phi aoqi@0: // MemNode - new memory input for this node aoqi@0: // ChecCastPP - allocation that this is a cast of aoqi@0: // allocation - CheckCastPP of the allocation aoqi@0: aoqi@0: // manage entries in _node_map aoqi@0: aoqi@0: void set_map(Node* from, Node* to) { aoqi@0: ideal_nodes.push(from); aoqi@0: _node_map.map(from->_idx, to); aoqi@0: } aoqi@0: aoqi@0: Node* get_map(int idx) { return _node_map[idx]; } aoqi@0: aoqi@0: PhiNode* get_map_phi(int idx) { aoqi@0: Node* phi = _node_map[idx]; aoqi@0: return (phi == NULL) ? NULL : phi->as_Phi(); aoqi@0: } aoqi@0: aoqi@0: // Notify optimizer that a node has been modified aoqi@0: void record_for_optimizer(Node *n) { aoqi@0: _igvn->_worklist.push(n); aoqi@0: _igvn->add_users_to_worklist(n); aoqi@0: } aoqi@0: aoqi@0: // Compute the escape information aoqi@0: bool compute_escape(); aoqi@0: aoqi@0: public: aoqi@0: ConnectionGraph(Compile *C, PhaseIterGVN *igvn); aoqi@0: aoqi@0: // Check for non-escaping candidates aoqi@0: static bool has_candidates(Compile *C); aoqi@0: aoqi@0: // Perform escape analysis aoqi@0: static void do_analysis(Compile *C, PhaseIterGVN *igvn); aoqi@0: aoqi@0: bool not_global_escape(Node *n); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void dump(GrowableArray& ptnodes_worklist); aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_OPTO_ESCAPE_HPP