src/share/vm/opto/escape.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7147744 Sdiff src/share/vm/opto

src/share/vm/opto/escape.hpp

Print this page


   1 /*
   2  * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  98 // AddP nodes are fields.
  99 //
 100 // After building the graph, a pass is made over the nodes, deleting deferred
 101 // nodes and copying the edges from the target of the deferred edge to the
 102 // source.  This results in a graph with no deferred edges, only:
 103 //
 104 //    LV -P> JO
 105 //    OF -P> JO (the object whose oop is stored in the field)
 106 //    JO -F> OF
 107 //
 108 // Then, for each node which is GlobalEscape, anything it could point to
 109 // is marked GlobalEscape.  Finally, for any node marked ArgEscape, anything
 110 // it could point to is marked ArgEscape.
 111 //
 112 
 113 class  Compile;
 114 class  Node;
 115 class  CallNode;
 116 class  PhiNode;
 117 class  PhaseTransform;

 118 class  Type;
 119 class  TypePtr;
 120 class  VectorSet;
 121 
 122 class PointsToNode {
 123 friend class ConnectionGraph;

 124 public:































 125   typedef enum {
 126     UnknownType = 0,
 127     JavaObject  = 1,
 128     LocalVar    = 2,
 129     Field       = 3

 130   } NodeType;
 131 
 132   typedef enum {
 133     UnknownEscape = 0,
 134     NoEscape      = 1, // An object does not escape method or thread and it is
 135                        // not passed to call. It could be replaced with scalar.
 136     ArgEscape     = 2, // An object does not escape method or thread but it is
 137                        // passed as argument to call or referenced by argument
 138                        // and it does not escape during call.
 139     GlobalEscape  = 3  // An object escapes the method or thread.
 140   } EscapeState;
 141 
 142   typedef enum {
 143     UnknownEdge   = 0,
 144     PointsToEdge  = 1,
 145     DeferredEdge  = 2,
 146     FieldEdge     = 3
 147   } EdgeType;
 148 
 149 private:
 150   enum {
 151     EdgeMask = 3,
 152     EdgeShift = 2,
 153 
 154     INITIAL_EDGE_COUNT = 4
 155   };







 156 
 157   NodeType             _type;
 158   EscapeState          _escape;
 159   GrowableArray<uint>* _edges; // outgoing edges
 160   Node* _node;                 // Ideal node corresponding to this PointsTo node.
 161   int   _offset;               // Object fields offsets.
 162   bool  _scalar_replaceable;   // Not escaped object could be replaced with scalar
 163   bool  _has_unknown_ptr;      // Has edge to phantom_object
 164 
 165 public:
 166   PointsToNode():
 167     _type(UnknownType),
 168     _escape(UnknownEscape),
 169     _edges(NULL),
 170     _node(NULL),
 171     _offset(-1),
 172     _has_unknown_ptr(false),
 173     _scalar_replaceable(true) {}
 174 




 175 
 176   EscapeState escape_state() const { return _escape; }
 177   NodeType node_type() const { return _type;}
 178   int offset() { return _offset;}
 179   bool scalar_replaceable() { return _scalar_replaceable;}
 180   bool has_unknown_ptr()    { return _has_unknown_ptr;}
 181 
 182   void set_offset(int offs) { _offset = offs;}
 183   void set_escape_state(EscapeState state) { _escape = state; }
 184   void set_node_type(NodeType ntype) {
 185     assert(_type == UnknownType || _type == ntype, "Can't change node type");
 186     _type = ntype;
 187   }
 188   void set_scalar_replaceable(bool v) { _scalar_replaceable = v; }
 189   void set_has_unknown_ptr()          { _has_unknown_ptr = true; }
 190 
 191   // count of outgoing edges
 192   uint edge_count() const { return (_edges == NULL) ? 0 : _edges->length(); }
 193 
 194   // node index of target of outgoing edge "e"
 195   uint edge_target(uint e) const {
 196     assert(_edges != NULL, "valid edge index");
 197     return (_edges->at(e) >> EdgeShift);







 198   }
 199   // type of outgoing edge "e"
 200   EdgeType edge_type(uint e) const {
 201     assert(_edges != NULL, "valid edge index");
 202     return (EdgeType) (_edges->at(e) & EdgeMask);
 203   }
 204 
 205   // add a edge of the specified type pointing to the specified target
 206   void add_edge(uint targIdx, EdgeType et);

 207 
 208   // remove an edge of the specified type pointing to the specified target
 209   void remove_edge(uint targIdx, EdgeType et);

 210 














 211 #ifndef PRODUCT

 212   void dump(bool print_state=true) const;
 213 #endif
 214 
 215 };
 216 
 217 class ConnectionGraph: public ResourceObj {
 218 private:
 219   GrowableArray<PointsToNode>  _nodes; // Connection graph nodes indexed
 220                                        // by ideal node index.

 221 
 222   Unique_Node_List  _delayed_worklist; // Nodes to be processed before
 223                                        // the call build_connection_graph().






 224 
 225   GrowableArray<MergeMemNode *>  _mergemem_worklist; // List of all MergeMem nodes









 226 
 227   VectorSet                _processed; // Records which nodes have been
 228                                        // processed.


 229 























 230   bool                    _collecting; // Indicates whether escape information
 231                                        // is still being collected. If false,
 232                                        // no new nodes will be processed.
 233 
 234   bool                    _progress;   // Indicates whether new Graph's edges
 235                                        // were created.
 236 
 237   uint                _phantom_object; // Index of globally escaping object
 238                                        // that pointer values loaded from
 239                                        // a field which has not been set
 240                                        // are assumed to point to.
 241   uint                      _oop_null; // ConP(#NULL)->_idx
 242   uint                     _noop_null; // ConN(#NULL)->_idx
 243   Node*                     _pcmp_neq; // ConI(#CC_GT)
 244   Node*                      _pcmp_eq; // ConI(#CC_EQ)
 245 
 246   Compile *                  _compile; // Compile object for current compilation
 247   PhaseIterGVN *                _igvn; // Value numbering
 248 


 249   // Address of an element in _nodes.  Used when the element is to be modified
 250   PointsToNode *ptnode_adr(uint idx) const {
 251     // There should be no new ideal nodes during ConnectionGraph build,
 252     // growableArray::adr_at() will throw assert otherwise.
 253     return _nodes.adr_at(idx);
 254   }
 255   uint nodes_size() const { return _nodes.length(); }
 256 
 257   bool is_null_ptr(uint idx) const { return (idx == _noop_null || idx == _oop_null); }




 258 
 259   // Add node to ConnectionGraph.
 260   void add_node(Node *n, PointsToNode::NodeType nt, PointsToNode::EscapeState es, bool done);



 261 
 262   // offset of a field reference
 263   int address_offset(Node* adr, PhaseTransform *phase);
 264 
 265   // compute the escape state for arguments to a call
 266   void process_call_arguments(CallNode *call, PhaseTransform *phase);
 267 
 268   // compute the escape state for the return value of a call
 269   void process_call_result(ProjNode *resproj, PhaseTransform *phase);
 270 
 271   // Populate Connection Graph with Ideal nodes.
 272   void record_for_escape_analysis(Node *n, PhaseTransform *phase);
 273 
 274   // Build Connection Graph and set nodes escape state.
 275   void build_connection_graph(Node *n, PhaseTransform *phase);
 276 
 277   // walk the connection graph starting at the node corresponding to "n" and
 278   // add the index of everything it could point to, to "ptset".  This may cause
 279   // Phi's encountered to get (re)processed  (which requires "phase".)
 280   VectorSet* PointsTo(Node * n);
 281 
 282   // Reused structures for PointsTo().
 283   VectorSet            pt_ptset;
 284   VectorSet            pt_visited;
 285   GrowableArray<uint>  pt_worklist;

 286 
 287   //  Edge manipulation.  The "from_i" and "to_i" arguments are the
 288   //  node indices of the source and destination of the edge
 289   void add_pointsto_edge(uint from_i, uint to_i);
 290   void add_deferred_edge(uint from_i, uint to_i);
 291   void add_field_edge(uint from_i, uint to_i, int offs);

 292 












































 293   // Add an edge of the specified type pointing to the specified target.
 294   // Set _progress if new edge is added.
 295   void add_edge(PointsToNode *f, uint to_i, PointsToNode::EdgeType et) {
 296     uint e_cnt = f->edge_count();
 297     f->add_edge(to_i, et);
 298     _progress |= (f->edge_count() != e_cnt);

 299   }


 300 
 301   // Add an edge to node given by "to_i" from any field of adr_i whose offset
 302   // matches "offset"  A deferred edge is added if to_i is a LocalVar, and
 303   // a pointsto edge is added if it is a JavaObject
 304   void add_edge_from_fields(uint adr, uint to_i, int offs);





 305 
 306   // Add a deferred  edge from node given by "from_i" to any field
 307   // of adr_i whose offset matches "offset"
 308   void add_deferred_edge_to_fields(uint from_i, uint adr, int offs);





















 309 















 310 
 311   // Remove outgoing deferred edges from the node referenced by "ni".
 312   // Any outgoing edges from the target of the deferred edge are copied
 313   // to "ni".
 314   void remove_deferred(uint ni, GrowableArray<uint>* deferred_edges, VectorSet* visited);
 315 





















 316   Node_Array _node_map; // used for bookeeping during type splitting
 317                         // Used for the following purposes:
 318                         // Memory Phi    - most recent unique Phi split out
 319                         //                 from this Phi
 320                         // MemNode       - new memory input for this node
 321                         // ChecCastPP    - allocation that this is a cast of
 322                         // allocation    - CheckCastPP of the allocation
 323   bool split_AddP(Node *addp, Node *base,  PhaseGVN  *igvn);
 324   PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *>  &orig_phi_worklist, PhaseGVN  *igvn, bool &new_created);
 325   PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *>  &orig_phi_worklist, PhaseGVN  *igvn);
 326   void  move_inst_mem(Node* n, GrowableArray<PhiNode *>  &orig_phis, PhaseGVN *igvn);
 327   Node *find_inst_mem(Node *mem, int alias_idx,GrowableArray<PhiNode *>  &orig_phi_worklist,  PhaseGVN  *igvn);
 328 
 329   // Propagate unique types created for unescaped allocated objects
 330   // through the graph
 331   void split_unique_types(GrowableArray<Node *>  &alloc_worklist);
 332 
 333   // manage entries in _node_map
 334   void  set_map(int idx, Node *n)        { _node_map.map(idx, n); }
 335   Node *get_map(int idx)                 { return _node_map[idx]; }
 336   PhiNode *get_map_phi(int idx) {
 337     Node *phi = _node_map[idx];






 338     return (phi == NULL) ? NULL : phi->as_Phi();
 339   }
 340 
 341   // Notify optimizer that a node has been modified
 342   void record_for_optimizer(Node *n) {
 343     _igvn->_worklist.push(n);
 344     _igvn->add_users_to_worklist(n);
 345   }
 346 
 347   // Set the escape state of a node
 348   void set_escape_state(uint ni, PointsToNode::EscapeState es);
 349 
 350   // Find fields initializing values for allocations.
 351   void find_init_values(Node* n, VectorSet* visited, PhaseTransform* phase);
 352 
 353   // Adjust escape state after Connection Graph is built.
 354   void adjust_escape_state(Node* n);
 355 
 356   // Propagate escape states to referenced nodes.
 357   bool propagate_escape_state(GrowableArray<int>* cg_worklist,
 358                               GrowableArray<uint>* worklist,
 359                               PointsToNode::EscapeState esc_state);
 360 
 361   // Optimize objects compare.
 362   Node* optimize_ptr_compare(Node* n);
 363 
 364   // Compute the escape information
 365   bool compute_escape();
 366 
 367 public:
 368   ConnectionGraph(Compile *C, PhaseIterGVN *igvn);
 369 
 370   // Check for non-escaping candidates
 371   static bool has_candidates(Compile *C);
 372 
 373   // Perform escape analysis
 374   static void do_analysis(Compile *C, PhaseIterGVN *igvn);
 375 
 376   // escape state of a node
 377   PointsToNode::EscapeState escape_state(Node *n);
 378 
 379 #ifndef PRODUCT
 380   void dump();
 381 #endif
 382 };
 383 
 384 #endif // SHARE_VM_OPTO_ESCAPE_HPP
   1 /*
   2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  98 // AddP nodes are fields.
  99 //
 100 // After building the graph, a pass is made over the nodes, deleting deferred
 101 // nodes and copying the edges from the target of the deferred edge to the
 102 // source.  This results in a graph with no deferred edges, only:
 103 //
 104 //    LV -P> JO
 105 //    OF -P> JO (the object whose oop is stored in the field)
 106 //    JO -F> OF
 107 //
 108 // Then, for each node which is GlobalEscape, anything it could point to
 109 // is marked GlobalEscape.  Finally, for any node marked ArgEscape, anything
 110 // it could point to is marked ArgEscape.
 111 //
 112 
 113 class  Compile;
 114 class  Node;
 115 class  CallNode;
 116 class  PhiNode;
 117 class  PhaseTransform;
 118 class  PointsToNode;
 119 class  Type;
 120 class  TypePtr;
 121 class  VectorSet;
 122 
 123 // Wrapper for GrowableArray
 124 class PointsToList {
 125   GrowableArray<PointsToNode*> _list; // List of nodes this node points to
 126 public:
 127   uint count() const { return _list.length(); }
 128   PointsToNode* element(uint e) const { return _list.at(e); }
 129 
 130   bool add(PointsToNode* elem) {
 131     // Returns TRUE if elem is added.
 132     bool missed = !_list.contains(elem);
 133     if (missed)
 134       _list.append(elem); // Add new element
 135     return missed;
 136   }
 137 };
 138 
 139 class JavaObjectNode;
 140 class LocalVarNode;
 141 class FieldNode;
 142 class ArraycopyNode;
 143 
 144 // ConnectionGraph nodes
 145 class PointsToNode : public ResourceObj {
 146   PointsToList _edges; // List of nodes this node points to
 147   PointsToList _uses;  // List of nodes which point to this node
 148 
 149   const u1           _type;  // NodeType
 150   u1                _flags;  // NodeFlags
 151   u1               _escape;  // EscapeState of object
 152   u1        _fields_escape;  // EscapeState of object's fields
 153 
 154   const Node*        _node;  // Ideal node corresponding to this PointsTo node.
 155   const uint          _idx;  // Cached ideal node's _idx
 156 
 157 public:
 158   typedef enum {
 159     UnknownType = 0,
 160     JavaObject  = 1,
 161     LocalVar    = 2,
 162     Field       = 3,
 163     Arraycopy   = 4
 164   } NodeType;
 165 
 166   typedef enum {
 167     UnknownEscape = 0,
 168     NoEscape      = 1, // An object does not escape method or thread and it is
 169                        // not passed to call. It could be replaced with scalar.
 170     ArgEscape     = 2, // An object does not escape method or thread but it is
 171                        // passed as argument to call or referenced by argument
 172                        // and it does not escape during call.
 173     GlobalEscape  = 3  // An object escapes the method or thread.
 174   } EscapeState;
 175 
 176   typedef enum {
 177     ScalarReplaceable = 1,  // Not escaped object could be replaced with scalar
 178     PointsToUnknown   = 2,  // Has edge to phantom_object
 179     ArraycopySrc      = 4,  // Has edge from Arraycopy node
 180     ArraycopyDst      = 8   // Has edge to Arraycopy node
 181   } NodeFlags;
 182 




 183 
 184   PointsToNode(Node* n, EscapeState es, NodeType type):
 185     _node(n),
 186     _idx(n->_idx),
 187     _type((u1)type),
 188     _escape((u1)es),
 189     _fields_escape((u1)es),
 190     _flags(ScalarReplaceable) {
 191     assert(n != NULL && es != UnknownEscape, "sanity");
 192   }
 193 
 194   Node* ideal_node()   const { return (Node*)_node; }
 195   int          idx()   const { return _idx; }





 196 
 197   bool is_JavaObject() const { return _type == (u1)JavaObject; }
 198   bool is_LocalVar()   const { return _type == (u1)LocalVar; }
 199   bool is_Field()      const { return _type == (u1)Field; }
 200   bool is_Arraycopy()  const { return _type == (u1)Arraycopy; }





 201 
 202   JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; }
 203   LocalVarNode*   as_LocalVar()   { assert(is_LocalVar(),"");   return (LocalVarNode*)this; }
 204   FieldNode*      as_Field()      { assert(is_Field(),"");      return (FieldNode*)this; }
 205   ArraycopyNode*  as_Arraycopy()  { assert(is_Arraycopy(),"");  return (ArraycopyNode*)this; }
 206 
 207   EscapeState escape_state() const { return (EscapeState)_escape; }
 208   void    set_escape_state(EscapeState state) { _escape = (u1)state; }



 209 
 210   EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; }
 211   void    set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; }






 212 
 213   bool     has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; }
 214   void set_has_unknown_ptr()       { _flags |= PointsToUnknown; }
 215 
 216   bool     arraycopy_src() const { return (_flags & ArraycopySrc) != 0; }
 217   void set_arraycopy_src()       { _flags |= ArraycopySrc; }
 218   bool     arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; }
 219   void set_arraycopy_dst()       { _flags |= ArraycopyDst; }
 220 
 221   bool     scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;}
 222   void set_scalar_replaceable(bool v) {
 223     if (v)
 224       _flags |= ScalarReplaceable;
 225     else
 226       _flags &= ~ScalarReplaceable;
 227   }





 228 
 229   uint edge_count()              const { return _edges.count(); }
 230   PointsToNode* edge(uint e)     const { return _edges.element(e); }
 231   bool add_edge(PointsToNode* edge)    { return _edges.add(edge); }
 232 
 233   uint use_count()             const { return _uses.count(); }
 234   PointsToNode* use(uint e)    const { return _uses.element(e); }
 235   bool add_use(PointsToNode* use)    { return _uses.add(use); }
 236 
 237   // Mark base edge use to distinguish from stored value edge.
 238   bool add_base_use(FieldNode* use) { return _uses.add((PointsToNode*)((intptr_t)use + 1)); }
 239   static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); }
 240   static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); }
 241 
 242   // Return true if this node points to specified node or nodes it points to.
 243   bool points_to(JavaObjectNode* ptn) const;
 244 
 245   // Return true if nodes points only to non-escaped allocations.
 246   bool not_escaped_allocation();
 247 
 248   // Return true if one node points to an other.
 249   bool meet(PointsToNode* ptn);
 250 
 251 #ifndef PRODUCT
 252   NodeType node_type() const { return (NodeType)_type;}
 253   void dump(bool print_state=true) const;
 254 #endif
 255 
 256 };
 257 
 258 class LocalVarNode: public PointsToNode {
 259 public:
 260   LocalVarNode(Node* n, EscapeState es):
 261     PointsToNode(n, es, LocalVar) {}
 262 };
 263 
 264 class JavaObjectNode: public PointsToNode {
 265 public:
 266   JavaObjectNode(Node* n, EscapeState es):
 267     PointsToNode(n, es, JavaObject) {
 268       if (es > NoEscape)
 269         set_scalar_replaceable(false);
 270     }
 271 };
 272 
 273 class FieldNode: public PointsToNode {
 274   PointsToList _bases; // List of JavaObject nodes which point to this node
 275   const int   _offset; // Field's offset.
 276   const bool  _is_oop; // Field points to object
 277         bool  _has_unknown_base; // Has phantom_object base
 278 public:
 279   FieldNode(Node* n, EscapeState es, int offs, bool is_oop):
 280     PointsToNode(n, es, Field),
 281     _offset(offs), _is_oop(is_oop),
 282     _has_unknown_base(false) {}
 283 
 284   int      offset()              const { return _offset;}
 285   bool     is_oop()              const { return _is_oop;}
 286   bool     has_unknown_base()    const { return _has_unknown_base; }
 287   void set_has_unknown_base()          { _has_unknown_base = true; }
 288 
 289   uint base_count()              const { return _bases.count(); }
 290   PointsToNode* base(uint e)     const { return _bases.element(e); }
 291   bool add_base(PointsToNode* base)    { return _bases.add(base); }
 292 #ifdef ASSERT
 293   // Return true if bases points to this java object.
 294   bool has_base(JavaObjectNode* ptn) const;
 295 #endif
 296 
 297 };
 298 
 299 class ArraycopyNode: public PointsToNode {
 300 public:
 301   ArraycopyNode(Node* n, EscapeState es):
 302     PointsToNode(n, es, Arraycopy) {}
 303 };
 304 
 305 class ConnectionGraph: public ResourceObj {
 306 private:
 307   GrowableArray<PointsToNode*>  _nodes; // Map from ideal nodes to
 308                                         // ConnectionGraph nodes.
 309 
 310   GrowableArray<PointsToNode*>  _worklist; // Nodes to be processed
 311 
 312   bool            _collecting; // Indicates whether escape information
 313                                // is still being collected. If false,
 314                                // no new nodes will be processed.
 315 
 316   bool               _verify;  // verify graph

 317 
 318   JavaObjectNode* phantom_obj; // Unknown object
 319   JavaObjectNode*    null_obj;




 320   Node*             _pcmp_neq; // ConI(#CC_GT)
 321   Node*              _pcmp_eq; // ConI(#CC_EQ)
 322 
 323   Compile*           _compile; // Compile object for current compilation
 324   PhaseIterGVN*         _igvn; // Value numbering
 325 
 326   Unique_Node_List ideal_nodes; // Used by CG construction and types splitting.
 327 
 328   // Address of an element in _nodes.  Used when the element is to be modified
 329   PointsToNode* ptnode_adr(uint idx) const {
 330     // There should be no new ideal nodes during ConnectionGraph build,
 331     // growableArray::at() will throw assert otherwise.
 332     return _nodes.at(idx);
 333   }
 334   uint nodes_size() const { return _nodes.length(); }
 335 
 336   // Add nodes to ConnectionGraph.
 337   void add_local_var(Node* n, PointsToNode::EscapeState es);
 338   void add_java_object(Node* n, PointsToNode::EscapeState es);
 339   void add_field(Node* n, PointsToNode::EscapeState es, int offset);
 340   void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst);
 341 
 342   // Map ideal node to existing PointsTo node (usually phantom_object).
 343   void map_ideal_node(Node *n, PointsToNode* ptn) {
 344     assert(ptn != NULL, "only existing PointsTo node");
 345     _nodes.at_put(n->_idx, ptn);
 346   }
 347 



 348   // compute the escape state for arguments to a call
 349   void process_call_arguments(CallNode *call, PhaseTransform *phase);
 350 
 351   // add PointsToNode node corresponding to a call
 352   void add_call_node(CallNode* call);
 353 



 354   // Build Connection Graph and set nodes escape state.
 355   void build_connection_graph(Node *n, Unique_Node_List *delayed_worklist, PhaseTransform *phase);
 356 
 357   // Add all references to this JavaObject node.
 358   int add_java_object_edges(JavaObjectNode* jobj, bool populate_worklist);


 359 
 360   // Put node on worklist if it is (or was) not there.
 361   void add_to_worklist(PointsToNode* pt) {
 362     _worklist.push(pt);
 363     return;
 364   }
 365 
 366   // Put on worklist all uses of this node.
 367   void add_uses_to_worklist(PointsToNode* pt) {
 368     uint count = pt->use_count();
 369     for (uint i = 0; i < count; i++)
 370       _worklist.push(pt->use(i));
 371   }
 372 
 373   // Put on worklist all field's uses and related field nodes.
 374   void add_field_uses_to_worklist(FieldNode* field);
 375 
 376   // Put on worklist all related field nodes.
 377   void add_fields_to_worklist(FieldNode* field, PointsToNode* base);
 378 
 379   // Find fields which have unknown value.
 380   int find_field_value(FieldNode* field);
 381 
 382   // Find fields initializing values for allocations.
 383   int find_init_values(JavaObjectNode* ptn, PointsToNode* init_val, PhaseTransform* phase);
 384 
 385   // Set the escape state of an object and its fields.
 386   void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
 387     // Don't change non-escaping state of NULL pointer.
 388     if (ptn != null_obj) {
 389       if (ptn->escape_state() < esc)
 390         ptn->set_escape_state(esc);
 391       if (ptn->fields_escape_state() < esc)
 392         ptn->set_fields_escape_state(esc);
 393     }
 394   }
 395   void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
 396     // Don't change non-escaping state of NULL pointer.
 397     if (ptn != null_obj) {
 398       if (ptn->fields_escape_state() < esc)
 399         ptn->set_fields_escape_state(esc);
 400     }
 401   }
 402 
 403   // Propagate GlobalEscape and ArgEscape escape states to all nodes
 404   // and check that we still have non escaped java objects.
 405   bool find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
 406                                 GrowableArray<JavaObjectNode*>& non_escaped_worklist);
 407 
 408   // Adjust scalar_replaceable state after Connection Graph is built.
 409   void adjust_scalar_replaceable_state(JavaObjectNode* jobj);
 410 
 411   // Optimize objects compare.
 412   Node* optimize_ptr_compare(Node* n);
 413 
 414   // Returns unique corresponding java object or NULL.
 415   JavaObjectNode* unique_java_object(Node *n);
 416 
 417   // Add an edge of the specified type pointing to the specified target.
 418   bool add_edge(PointsToNode* from, PointsToNode* to) {
 419     assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity");
 420 
 421     if (to == phantom_obj) {
 422       if (from->has_unknown_ptr()) {
 423         return false; // already points to phantom_obj
 424       }
 425       from->set_has_unknown_ptr();
 426     }
 427 
 428     bool is_new = from->add_edge(to);
 429     assert(to != phantom_obj || is_new, "sanity");
 430     if (is_new) { // New edge?
 431       assert(!_verify, "graph is incomplete");
 432       is_new = to->add_use(from);
 433       assert(is_new, "use should be also new");
 434     }
 435     return is_new;
 436   }
 437 
 438   // Add an edge from Field node to its base and back.
 439   bool add_base(FieldNode* from, PointsToNode* to) {
 440     assert(!to->is_Arraycopy(), "sanity");
 441     if (to == phantom_obj) {
 442       if (from->has_unknown_base()) {
 443         return false; // already has phantom_obj base
 444       }
 445       from->set_has_unknown_base();
 446     }
 447     bool is_new = from->add_base(to);
 448     assert(to != phantom_obj || is_new, "sanity");
 449     if (is_new) {      // New edge?
 450       assert(!_verify, "graph is incomplete");
 451       if (to == null_obj)
 452         return is_new; // Don't add fields to NULL pointer.
 453       if (to->is_JavaObject()) {
 454         is_new = to->add_edge(from);
 455       } else {
 456         is_new = to->add_base_use(from);
 457       }
 458       assert(is_new, "use should be also new");
 459     }
 460     return is_new;
 461   }
 462 
 463   // Add LocalVar node and edge if possible
 464   void add_local_var_and_edge(Node* n, PointsToNode::EscapeState es, Node* to,
 465                               Unique_Node_List *delayed_worklist) {
 466     PointsToNode* ptn = ptnode_adr(to->_idx);
 467     if (delayed_worklist != NULL) { // First iteration of CG construction
 468       add_local_var(n, es);
 469       if (ptn == NULL) {
 470         delayed_worklist->push(n);
 471         return; // Process it later.
 472       }
 473     } else {
 474       assert(ptn != NULL, "node should be registered");
 475     }
 476     add_edge(ptnode_adr(n->_idx), ptn);
 477   }
 478 
 479   // Helper functions
 480   bool   is_oop_field(Node* n, int offset);
 481   static Node* get_addp_base(Node *addp);
 482   static Node* find_second_addp(Node* addp, Node* n);
 483 
 484   // offset of a field reference
 485   int address_offset(Node* adr, PhaseTransform *phase);
 486 
 487 
 488   // Propagate unique types created for unescaped allocated objects
 489   // through the graph
 490   void split_unique_types(GrowableArray<Node *>  &alloc_worklist);
 491 
 492   // Helper methods for unique types split.
 493   bool split_AddP(Node *addp, Node *base,  PhaseGVN  *igvn);
 494 
 495   PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *>  &orig_phi_worklist, PhaseGVN  *igvn, bool &new_created);
 496   PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *>  &orig_phi_worklist, PhaseGVN  *igvn);
 497 
 498   void  move_inst_mem(Node* n, GrowableArray<PhiNode *>  &orig_phis, PhaseGVN *igvn);
 499   Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *>  &orig_phi_worklist,  PhaseGVN  *igvn);
 500   Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
 501 
 502 
 503   GrowableArray<MergeMemNode*>  _mergemem_worklist; // List of all MergeMem nodes
 504 
 505   Node_Array _node_map; // used for bookeeping during type splitting
 506                         // Used for the following purposes:
 507                         // Memory Phi    - most recent unique Phi split out
 508                         //                 from this Phi
 509                         // MemNode       - new memory input for this node
 510                         // ChecCastPP    - allocation that this is a cast of
 511                         // allocation    - CheckCastPP of the allocation





 512 




 513   // manage entries in _node_map
 514 
 515   void  set_map(Node* from, Node* to)  {
 516     ideal_nodes.push(from);
 517     _node_map.map(from->_idx, to);
 518   }
 519 
 520   Node* get_map(int idx) { return _node_map[idx]; }
 521 
 522   PhiNode* get_map_phi(int idx) {
 523     Node* phi = _node_map[idx];
 524     return (phi == NULL) ? NULL : phi->as_Phi();
 525   }
 526 
 527   // Notify optimizer that a node has been modified
 528   void record_for_optimizer(Node *n) {
 529     _igvn->_worklist.push(n);
 530     _igvn->add_users_to_worklist(n);
 531   }
 532 

















 533   // Compute the escape information
 534   bool compute_escape();
 535 
 536 public:
 537   ConnectionGraph(Compile *C, PhaseIterGVN *igvn);
 538 
 539   // Check for non-escaping candidates
 540   static bool has_candidates(Compile *C);
 541 
 542   // Perform escape analysis
 543   static void do_analysis(Compile *C, PhaseIterGVN *igvn);
 544 
 545   bool not_global_escape(Node *n);

 546 
 547 #ifndef PRODUCT
 548   void dump(GrowableArray<PointsToNode*>& ptnodes_worklist);
 549 #endif
 550 };
 551 
 552 #endif // SHARE_VM_OPTO_ESCAPE_HPP
src/share/vm/opto/escape.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File