src/share/vm/opto/escape.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OPTO_ESCAPE_HPP
aoqi@0 26 #define SHARE_VM_OPTO_ESCAPE_HPP
aoqi@0 27
aoqi@0 28 #include "opto/addnode.hpp"
aoqi@0 29 #include "opto/node.hpp"
aoqi@0 30 #include "utilities/growableArray.hpp"
aoqi@0 31
aoqi@0 32 //
aoqi@0 33 // Adaptation for C2 of the escape analysis algorithm described in:
aoqi@0 34 //
aoqi@0 35 // [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano,
aoqi@0 36 // Vugranam C. Sreedhar, Sam Midkiff,
aoqi@0 37 // "Escape Analysis for Java", Procedings of ACM SIGPLAN
aoqi@0 38 // OOPSLA Conference, November 1, 1999
aoqi@0 39 //
aoqi@0 40 // The flow-insensitive analysis described in the paper has been implemented.
aoqi@0 41 //
aoqi@0 42 // The analysis requires construction of a "connection graph" (CG) for
aoqi@0 43 // the method being analyzed. The nodes of the connection graph are:
aoqi@0 44 //
aoqi@0 45 // - Java objects (JO)
aoqi@0 46 // - Local variables (LV)
aoqi@0 47 // - Fields of an object (OF), these also include array elements
aoqi@0 48 //
aoqi@0 49 // The CG contains 3 types of edges:
aoqi@0 50 //
aoqi@0 51 // - PointsTo (-P>) {LV, OF} to JO
aoqi@0 52 // - Deferred (-D>) from {LV, OF} to {LV, OF}
aoqi@0 53 // - Field (-F>) from JO to OF
aoqi@0 54 //
aoqi@0 55 // The following utility functions is used by the algorithm:
aoqi@0 56 //
aoqi@0 57 // PointsTo(n) - n is any CG node, it returns the set of JO that n could
aoqi@0 58 // point to.
aoqi@0 59 //
aoqi@0 60 // The algorithm describes how to construct the connection graph
aoqi@0 61 // in the following 4 cases:
aoqi@0 62 //
aoqi@0 63 // Case Edges Created
aoqi@0 64 //
aoqi@0 65 // (1) p = new T() LV -P> JO
aoqi@0 66 // (2) p = q LV -D> LV
aoqi@0 67 // (3) p.f = q JO -F> OF, OF -D> LV
aoqi@0 68 // (4) p = q.f JO -F> OF, LV -D> OF
aoqi@0 69 //
aoqi@0 70 // In all these cases, p and q are local variables. For static field
aoqi@0 71 // references, we can construct a local variable containing a reference
aoqi@0 72 // to the static memory.
aoqi@0 73 //
aoqi@0 74 // C2 does not have local variables. However for the purposes of constructing
aoqi@0 75 // the connection graph, the following IR nodes are treated as local variables:
aoqi@0 76 // Phi (pointer values)
aoqi@0 77 // LoadP, LoadN
aoqi@0 78 // Proj#5 (value returned from callnodes including allocations)
aoqi@0 79 // CheckCastPP, CastPP
aoqi@0 80 //
aoqi@0 81 // The LoadP, Proj and CheckCastPP behave like variables assigned to only once.
aoqi@0 82 // Only a Phi can have multiple assignments. Each input to a Phi is treated
aoqi@0 83 // as an assignment to it.
aoqi@0 84 //
aoqi@0 85 // The following node types are JavaObject:
aoqi@0 86 //
aoqi@0 87 // phantom_object (general globally escaped object)
aoqi@0 88 // Allocate
aoqi@0 89 // AllocateArray
aoqi@0 90 // Parm (for incoming arguments)
aoqi@0 91 // CastX2P ("unsafe" operations)
aoqi@0 92 // CreateEx
aoqi@0 93 // ConP
aoqi@0 94 // LoadKlass
aoqi@0 95 // ThreadLocal
aoqi@0 96 // CallStaticJava (which returns Object)
aoqi@0 97 //
aoqi@0 98 // AddP nodes are fields.
aoqi@0 99 //
aoqi@0 100 // After building the graph, a pass is made over the nodes, deleting deferred
aoqi@0 101 // nodes and copying the edges from the target of the deferred edge to the
aoqi@0 102 // source. This results in a graph with no deferred edges, only:
aoqi@0 103 //
aoqi@0 104 // LV -P> JO
aoqi@0 105 // OF -P> JO (the object whose oop is stored in the field)
aoqi@0 106 // JO -F> OF
aoqi@0 107 //
aoqi@0 108 // Then, for each node which is GlobalEscape, anything it could point to
aoqi@0 109 // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
aoqi@0 110 // it could point to is marked ArgEscape.
aoqi@0 111 //
aoqi@0 112
aoqi@0 113 class Compile;
aoqi@0 114 class Node;
aoqi@0 115 class CallNode;
aoqi@0 116 class PhiNode;
aoqi@0 117 class PhaseTransform;
aoqi@0 118 class PointsToNode;
aoqi@0 119 class Type;
aoqi@0 120 class TypePtr;
aoqi@0 121 class VectorSet;
aoqi@0 122
aoqi@0 123 class JavaObjectNode;
aoqi@0 124 class LocalVarNode;
aoqi@0 125 class FieldNode;
aoqi@0 126 class ArraycopyNode;
aoqi@0 127
aoqi@0 128 // ConnectionGraph nodes
aoqi@0 129 class PointsToNode : public ResourceObj {
aoqi@0 130 GrowableArray<PointsToNode*> _edges; // List of nodes this node points to
aoqi@0 131 GrowableArray<PointsToNode*> _uses; // List of nodes which point to this node
aoqi@0 132
aoqi@0 133 const u1 _type; // NodeType
aoqi@0 134 u1 _flags; // NodeFlags
aoqi@0 135 u1 _escape; // EscapeState of object
aoqi@0 136 u1 _fields_escape; // EscapeState of object's fields
aoqi@0 137
aoqi@0 138 Node* const _node; // Ideal node corresponding to this PointsTo node.
aoqi@0 139 const int _idx; // Cached ideal node's _idx
aoqi@0 140
aoqi@0 141 public:
aoqi@0 142 typedef enum {
aoqi@0 143 UnknownType = 0,
aoqi@0 144 JavaObject = 1,
aoqi@0 145 LocalVar = 2,
aoqi@0 146 Field = 3,
aoqi@0 147 Arraycopy = 4
aoqi@0 148 } NodeType;
aoqi@0 149
aoqi@0 150 typedef enum {
aoqi@0 151 UnknownEscape = 0,
aoqi@0 152 NoEscape = 1, // An object does not escape method or thread and it is
aoqi@0 153 // not passed to call. It could be replaced with scalar.
aoqi@0 154 ArgEscape = 2, // An object does not escape method or thread but it is
aoqi@0 155 // passed as argument to call or referenced by argument
aoqi@0 156 // and it does not escape during call.
aoqi@0 157 GlobalEscape = 3 // An object escapes the method or thread.
aoqi@0 158 } EscapeState;
aoqi@0 159
aoqi@0 160 typedef enum {
aoqi@0 161 ScalarReplaceable = 1, // Not escaped object could be replaced with scalar
aoqi@0 162 PointsToUnknown = 2, // Has edge to phantom_object
aoqi@0 163 ArraycopySrc = 4, // Has edge from Arraycopy node
aoqi@0 164 ArraycopyDst = 8 // Has edge to Arraycopy node
aoqi@0 165 } NodeFlags;
aoqi@0 166
aoqi@0 167
aoqi@0 168 PointsToNode(Compile *C, Node* n, EscapeState es, NodeType type):
aoqi@0 169 _edges(C->comp_arena(), 2, 0, NULL),
aoqi@0 170 _uses (C->comp_arena(), 2, 0, NULL),
aoqi@0 171 _node(n),
aoqi@0 172 _idx(n->_idx),
aoqi@0 173 _type((u1)type),
aoqi@0 174 _escape((u1)es),
aoqi@0 175 _fields_escape((u1)es),
aoqi@0 176 _flags(ScalarReplaceable) {
aoqi@0 177 assert(n != NULL && es != UnknownEscape, "sanity");
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 Node* ideal_node() const { return _node; }
aoqi@0 181 int idx() const { return _idx; }
aoqi@0 182
aoqi@0 183 bool is_JavaObject() const { return _type == (u1)JavaObject; }
aoqi@0 184 bool is_LocalVar() const { return _type == (u1)LocalVar; }
aoqi@0 185 bool is_Field() const { return _type == (u1)Field; }
aoqi@0 186 bool is_Arraycopy() const { return _type == (u1)Arraycopy; }
aoqi@0 187
aoqi@0 188 JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; }
aoqi@0 189 LocalVarNode* as_LocalVar() { assert(is_LocalVar(),""); return (LocalVarNode*)this; }
aoqi@0 190 FieldNode* as_Field() { assert(is_Field(),""); return (FieldNode*)this; }
aoqi@0 191 ArraycopyNode* as_Arraycopy() { assert(is_Arraycopy(),""); return (ArraycopyNode*)this; }
aoqi@0 192
aoqi@0 193 EscapeState escape_state() const { return (EscapeState)_escape; }
aoqi@0 194 void set_escape_state(EscapeState state) { _escape = (u1)state; }
aoqi@0 195
aoqi@0 196 EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; }
aoqi@0 197 void set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; }
aoqi@0 198
aoqi@0 199 bool has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; }
aoqi@0 200 void set_has_unknown_ptr() { _flags |= PointsToUnknown; }
aoqi@0 201
aoqi@0 202 bool arraycopy_src() const { return (_flags & ArraycopySrc) != 0; }
aoqi@0 203 void set_arraycopy_src() { _flags |= ArraycopySrc; }
aoqi@0 204 bool arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; }
aoqi@0 205 void set_arraycopy_dst() { _flags |= ArraycopyDst; }
aoqi@0 206
aoqi@0 207 bool scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;}
aoqi@0 208 void set_scalar_replaceable(bool v) {
aoqi@0 209 if (v)
aoqi@0 210 _flags |= ScalarReplaceable;
aoqi@0 211 else
aoqi@0 212 _flags &= ~ScalarReplaceable;
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 int edge_count() const { return _edges.length(); }
aoqi@0 216 PointsToNode* edge(int e) const { return _edges.at(e); }
aoqi@0 217 bool add_edge(PointsToNode* edge) { return _edges.append_if_missing(edge); }
aoqi@0 218
aoqi@0 219 int use_count() const { return _uses.length(); }
aoqi@0 220 PointsToNode* use(int e) const { return _uses.at(e); }
aoqi@0 221 bool add_use(PointsToNode* use) { return _uses.append_if_missing(use); }
aoqi@0 222
aoqi@0 223 // Mark base edge use to distinguish from stored value edge.
aoqi@0 224 bool add_base_use(FieldNode* use) { return _uses.append_if_missing((PointsToNode*)((intptr_t)use + 1)); }
aoqi@0 225 static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); }
aoqi@0 226 static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); }
aoqi@0 227
aoqi@0 228 // Return true if this node points to specified node or nodes it points to.
aoqi@0 229 bool points_to(JavaObjectNode* ptn) const;
aoqi@0 230
aoqi@0 231 // Return true if this node points only to non-escaping allocations.
aoqi@0 232 bool non_escaping_allocation();
aoqi@0 233
aoqi@0 234 // Return true if one node points to an other.
aoqi@0 235 bool meet(PointsToNode* ptn);
aoqi@0 236
aoqi@0 237 #ifndef PRODUCT
aoqi@0 238 NodeType node_type() const { return (NodeType)_type;}
aoqi@0 239 void dump(bool print_state=true) const;
aoqi@0 240 #endif
aoqi@0 241
aoqi@0 242 };
aoqi@0 243
aoqi@0 244 class LocalVarNode: public PointsToNode {
aoqi@0 245 public:
aoqi@0 246 LocalVarNode(Compile *C, Node* n, EscapeState es):
aoqi@0 247 PointsToNode(C, n, es, LocalVar) {}
aoqi@0 248 };
aoqi@0 249
aoqi@0 250 class JavaObjectNode: public PointsToNode {
aoqi@0 251 public:
aoqi@0 252 JavaObjectNode(Compile *C, Node* n, EscapeState es):
aoqi@0 253 PointsToNode(C, n, es, JavaObject) {
aoqi@0 254 if (es > NoEscape)
aoqi@0 255 set_scalar_replaceable(false);
aoqi@0 256 }
aoqi@0 257 };
aoqi@0 258
aoqi@0 259 class FieldNode: public PointsToNode {
aoqi@0 260 GrowableArray<PointsToNode*> _bases; // List of JavaObject nodes which point to this node
aoqi@0 261 const int _offset; // Field's offset.
aoqi@0 262 const bool _is_oop; // Field points to object
aoqi@0 263 bool _has_unknown_base; // Has phantom_object base
aoqi@0 264 public:
aoqi@0 265 FieldNode(Compile *C, Node* n, EscapeState es, int offs, bool is_oop):
aoqi@0 266 PointsToNode(C, n, es, Field),
aoqi@0 267 _offset(offs), _is_oop(is_oop),
aoqi@0 268 _has_unknown_base(false) {}
aoqi@0 269
aoqi@0 270 int offset() const { return _offset;}
aoqi@0 271 bool is_oop() const { return _is_oop;}
aoqi@0 272 bool has_unknown_base() const { return _has_unknown_base; }
aoqi@0 273 void set_has_unknown_base() { _has_unknown_base = true; }
aoqi@0 274
aoqi@0 275 int base_count() const { return _bases.length(); }
aoqi@0 276 PointsToNode* base(int e) const { return _bases.at(e); }
aoqi@0 277 bool add_base(PointsToNode* base) { return _bases.append_if_missing(base); }
aoqi@0 278 #ifdef ASSERT
aoqi@0 279 // Return true if bases points to this java object.
aoqi@0 280 bool has_base(JavaObjectNode* ptn) const;
aoqi@0 281 #endif
aoqi@0 282
aoqi@0 283 };
aoqi@0 284
aoqi@0 285 class ArraycopyNode: public PointsToNode {
aoqi@0 286 public:
aoqi@0 287 ArraycopyNode(Compile *C, Node* n, EscapeState es):
aoqi@0 288 PointsToNode(C, n, es, Arraycopy) {}
aoqi@0 289 };
aoqi@0 290
aoqi@0 291 // Iterators for PointsTo node's edges:
aoqi@0 292 // for (EdgeIterator i(n); i.has_next(); i.next()) {
aoqi@0 293 // PointsToNode* u = i.get();
aoqi@0 294 class PointsToIterator: public StackObj {
aoqi@0 295 protected:
aoqi@0 296 const PointsToNode* node;
aoqi@0 297 const int cnt;
aoqi@0 298 int i;
aoqi@0 299 public:
aoqi@0 300 inline PointsToIterator(const PointsToNode* n, int cnt) : node(n), cnt(cnt), i(0) { }
aoqi@0 301 inline bool has_next() const { return i < cnt; }
aoqi@0 302 inline void next() { i++; }
aoqi@0 303 PointsToNode* get() const { ShouldNotCallThis(); return NULL; }
aoqi@0 304 };
aoqi@0 305
aoqi@0 306 class EdgeIterator: public PointsToIterator {
aoqi@0 307 public:
aoqi@0 308 inline EdgeIterator(const PointsToNode* n) : PointsToIterator(n, n->edge_count()) { }
aoqi@0 309 inline PointsToNode* get() const { return node->edge(i); }
aoqi@0 310 };
aoqi@0 311
aoqi@0 312 class UseIterator: public PointsToIterator {
aoqi@0 313 public:
aoqi@0 314 inline UseIterator(const PointsToNode* n) : PointsToIterator(n, n->use_count()) { }
aoqi@0 315 inline PointsToNode* get() const { return node->use(i); }
aoqi@0 316 };
aoqi@0 317
aoqi@0 318 class BaseIterator: public PointsToIterator {
aoqi@0 319 public:
aoqi@0 320 inline BaseIterator(const FieldNode* n) : PointsToIterator(n, n->base_count()) { }
aoqi@0 321 inline PointsToNode* get() const { return ((PointsToNode*)node)->as_Field()->base(i); }
aoqi@0 322 };
aoqi@0 323
aoqi@0 324
aoqi@0 325 class ConnectionGraph: public ResourceObj {
aoqi@0 326 private:
aoqi@0 327 GrowableArray<PointsToNode*> _nodes; // Map from ideal nodes to
aoqi@0 328 // ConnectionGraph nodes.
aoqi@0 329
aoqi@0 330 GrowableArray<PointsToNode*> _worklist; // Nodes to be processed
aoqi@0 331
aoqi@0 332 bool _collecting; // Indicates whether escape information
aoqi@0 333 // is still being collected. If false,
aoqi@0 334 // no new nodes will be processed.
aoqi@0 335
aoqi@0 336 bool _verify; // verify graph
aoqi@0 337
aoqi@0 338 JavaObjectNode* phantom_obj; // Unknown object
aoqi@0 339 JavaObjectNode* null_obj;
aoqi@0 340 Node* _pcmp_neq; // ConI(#CC_GT)
aoqi@0 341 Node* _pcmp_eq; // ConI(#CC_EQ)
aoqi@0 342
aoqi@0 343 Compile* _compile; // Compile object for current compilation
aoqi@0 344 PhaseIterGVN* _igvn; // Value numbering
aoqi@0 345
aoqi@0 346 Unique_Node_List ideal_nodes; // Used by CG construction and types splitting.
aoqi@0 347
aoqi@0 348 // Address of an element in _nodes. Used when the element is to be modified
aoqi@0 349 PointsToNode* ptnode_adr(int idx) const {
aoqi@0 350 // There should be no new ideal nodes during ConnectionGraph build,
aoqi@0 351 // growableArray::at() will throw assert otherwise.
aoqi@0 352 return _nodes.at(idx);
aoqi@0 353 }
aoqi@0 354 uint nodes_size() const { return _nodes.length(); }
aoqi@0 355
aoqi@0 356 // Add nodes to ConnectionGraph.
aoqi@0 357 void add_local_var(Node* n, PointsToNode::EscapeState es);
aoqi@0 358 void add_java_object(Node* n, PointsToNode::EscapeState es);
aoqi@0 359 void add_field(Node* n, PointsToNode::EscapeState es, int offset);
aoqi@0 360 void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst);
aoqi@0 361
aoqi@0 362 // Compute the escape state for arguments to a call.
aoqi@0 363 void process_call_arguments(CallNode *call);
aoqi@0 364
aoqi@0 365 // Add PointsToNode node corresponding to a call
aoqi@0 366 void add_call_node(CallNode* call);
aoqi@0 367
aoqi@0 368 // Map ideal node to existing PointsTo node (usually phantom_object).
aoqi@0 369 void map_ideal_node(Node *n, PointsToNode* ptn) {
aoqi@0 370 assert(ptn != NULL, "only existing PointsTo node");
aoqi@0 371 _nodes.at_put(n->_idx, ptn);
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 // Utility function for nodes that load an object
aoqi@0 375 void add_objload_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist);
aoqi@0 376 // Create PointsToNode node and add it to Connection Graph.
aoqi@0 377 void add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist);
aoqi@0 378
aoqi@0 379 // Add final simple edges to graph.
aoqi@0 380 void add_final_edges(Node *n);
aoqi@0 381
aoqi@0 382 // Finish Graph construction.
aoqi@0 383 bool complete_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
aoqi@0 384 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
aoqi@0 385 GrowableArray<JavaObjectNode*>& java_objects_worklist,
aoqi@0 386 GrowableArray<FieldNode*>& oop_fields_worklist);
aoqi@0 387
aoqi@0 388 #ifdef ASSERT
aoqi@0 389 void verify_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
aoqi@0 390 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
aoqi@0 391 GrowableArray<JavaObjectNode*>& java_objects_worklist,
aoqi@0 392 GrowableArray<Node*>& addp_worklist);
aoqi@0 393 #endif
aoqi@0 394
aoqi@0 395 // Add all references to this JavaObject node.
aoqi@0 396 int add_java_object_edges(JavaObjectNode* jobj, bool populate_worklist);
aoqi@0 397
aoqi@0 398 // Put node on worklist if it is (or was) not there.
aoqi@0 399 void add_to_worklist(PointsToNode* pt) {
aoqi@0 400 _worklist.push(pt);
aoqi@0 401 return;
aoqi@0 402 }
aoqi@0 403
aoqi@0 404 // Put on worklist all uses of this node.
aoqi@0 405 void add_uses_to_worklist(PointsToNode* pt) {
aoqi@0 406 for (UseIterator i(pt); i.has_next(); i.next())
aoqi@0 407 _worklist.push(i.get());
aoqi@0 408 }
aoqi@0 409
aoqi@0 410 // Put on worklist all field's uses and related field nodes.
aoqi@0 411 void add_field_uses_to_worklist(FieldNode* field);
aoqi@0 412
aoqi@0 413 // Put on worklist all related field nodes.
aoqi@0 414 void add_fields_to_worklist(FieldNode* field, PointsToNode* base);
aoqi@0 415
aoqi@0 416 // Find fields which have unknown value.
aoqi@0 417 int find_field_value(FieldNode* field);
aoqi@0 418
aoqi@0 419 // Find fields initializing values for allocations.
aoqi@0 420 int find_init_values(JavaObjectNode* ptn, PointsToNode* init_val, PhaseTransform* phase);
aoqi@0 421
aoqi@0 422 // Set the escape state of an object and its fields.
aoqi@0 423 void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
aoqi@0 424 // Don't change non-escaping state of NULL pointer.
aoqi@0 425 if (ptn != null_obj) {
aoqi@0 426 if (ptn->escape_state() < esc)
aoqi@0 427 ptn->set_escape_state(esc);
aoqi@0 428 if (ptn->fields_escape_state() < esc)
aoqi@0 429 ptn->set_fields_escape_state(esc);
aoqi@0 430 }
aoqi@0 431 }
aoqi@0 432 void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
aoqi@0 433 // Don't change non-escaping state of NULL pointer.
aoqi@0 434 if (ptn != null_obj) {
aoqi@0 435 if (ptn->fields_escape_state() < esc)
aoqi@0 436 ptn->set_fields_escape_state(esc);
aoqi@0 437 }
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 // Propagate GlobalEscape and ArgEscape escape states to all nodes
aoqi@0 441 // and check that we still have non-escaping java objects.
aoqi@0 442 bool find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
aoqi@0 443 GrowableArray<JavaObjectNode*>& non_escaped_worklist);
aoqi@0 444
aoqi@0 445 // Adjust scalar_replaceable state after Connection Graph is built.
aoqi@0 446 void adjust_scalar_replaceable_state(JavaObjectNode* jobj);
aoqi@0 447
aoqi@0 448 // Optimize ideal graph.
aoqi@0 449 void optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklist,
aoqi@0 450 GrowableArray<Node*>& storestore_worklist);
aoqi@0 451 // Optimize objects compare.
aoqi@0 452 Node* optimize_ptr_compare(Node* n);
aoqi@0 453
aoqi@0 454 // Returns unique corresponding java object or NULL.
aoqi@0 455 JavaObjectNode* unique_java_object(Node *n);
aoqi@0 456
aoqi@0 457 // Add an edge of the specified type pointing to the specified target.
aoqi@0 458 bool add_edge(PointsToNode* from, PointsToNode* to) {
aoqi@0 459 assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity");
aoqi@0 460
aoqi@0 461 if (to == phantom_obj) {
aoqi@0 462 if (from->has_unknown_ptr()) {
aoqi@0 463 return false; // already points to phantom_obj
aoqi@0 464 }
aoqi@0 465 from->set_has_unknown_ptr();
aoqi@0 466 }
aoqi@0 467
aoqi@0 468 bool is_new = from->add_edge(to);
aoqi@0 469 assert(to != phantom_obj || is_new, "sanity");
aoqi@0 470 if (is_new) { // New edge?
aoqi@0 471 assert(!_verify, "graph is incomplete");
aoqi@0 472 is_new = to->add_use(from);
aoqi@0 473 assert(is_new, "use should be also new");
aoqi@0 474 }
aoqi@0 475 return is_new;
aoqi@0 476 }
aoqi@0 477
aoqi@0 478 // Add an edge from Field node to its base and back.
aoqi@0 479 bool add_base(FieldNode* from, PointsToNode* to) {
aoqi@0 480 assert(!to->is_Arraycopy(), "sanity");
aoqi@0 481 if (to == phantom_obj) {
aoqi@0 482 if (from->has_unknown_base()) {
aoqi@0 483 return false; // already has phantom_obj base
aoqi@0 484 }
aoqi@0 485 from->set_has_unknown_base();
aoqi@0 486 }
aoqi@0 487 bool is_new = from->add_base(to);
aoqi@0 488 assert(to != phantom_obj || is_new, "sanity");
aoqi@0 489 if (is_new) { // New edge?
aoqi@0 490 assert(!_verify, "graph is incomplete");
aoqi@0 491 if (to == null_obj)
aoqi@0 492 return is_new; // Don't add fields to NULL pointer.
aoqi@0 493 if (to->is_JavaObject()) {
aoqi@0 494 is_new = to->add_edge(from);
aoqi@0 495 } else {
aoqi@0 496 is_new = to->add_base_use(from);
aoqi@0 497 }
aoqi@0 498 assert(is_new, "use should be also new");
aoqi@0 499 }
aoqi@0 500 return is_new;
aoqi@0 501 }
aoqi@0 502
aoqi@0 503 // Add LocalVar node and edge if possible
aoqi@0 504 void add_local_var_and_edge(Node* n, PointsToNode::EscapeState es, Node* to,
aoqi@0 505 Unique_Node_List *delayed_worklist) {
aoqi@0 506 PointsToNode* ptn = ptnode_adr(to->_idx);
aoqi@0 507 if (delayed_worklist != NULL) { // First iteration of CG construction
aoqi@0 508 add_local_var(n, es);
aoqi@0 509 if (ptn == NULL) {
aoqi@0 510 delayed_worklist->push(n);
aoqi@0 511 return; // Process it later.
aoqi@0 512 }
aoqi@0 513 } else {
aoqi@0 514 assert(ptn != NULL, "node should be registered");
aoqi@0 515 }
aoqi@0 516 add_edge(ptnode_adr(n->_idx), ptn);
aoqi@0 517 }
aoqi@0 518 // Helper functions
aoqi@0 519 bool is_oop_field(Node* n, int offset, bool* unsafe);
aoqi@0 520 static Node* get_addp_base(Node *addp);
aoqi@0 521 static Node* find_second_addp(Node* addp, Node* n);
aoqi@0 522 // offset of a field reference
aoqi@0 523 int address_offset(Node* adr, PhaseTransform *phase);
aoqi@0 524
aoqi@0 525
aoqi@0 526 // Propagate unique types created for unescaped allocated objects
aoqi@0 527 // through the graph
aoqi@0 528 void split_unique_types(GrowableArray<Node *> &alloc_worklist);
aoqi@0 529
aoqi@0 530 // Helper methods for unique types split.
aoqi@0 531 bool split_AddP(Node *addp, Node *base);
aoqi@0 532
aoqi@0 533 PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created);
aoqi@0 534 PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist);
aoqi@0 535
aoqi@0 536 void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
aoqi@0 537 Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
aoqi@0 538 Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
aoqi@0 539
aoqi@0 540
aoqi@0 541 GrowableArray<MergeMemNode*> _mergemem_worklist; // List of all MergeMem nodes
aoqi@0 542
aoqi@0 543 Node_Array _node_map; // used for bookeeping during type splitting
aoqi@0 544 // Used for the following purposes:
aoqi@0 545 // Memory Phi - most recent unique Phi split out
aoqi@0 546 // from this Phi
aoqi@0 547 // MemNode - new memory input for this node
aoqi@0 548 // ChecCastPP - allocation that this is a cast of
aoqi@0 549 // allocation - CheckCastPP of the allocation
aoqi@0 550
aoqi@0 551 // manage entries in _node_map
aoqi@0 552
aoqi@0 553 void set_map(Node* from, Node* to) {
aoqi@0 554 ideal_nodes.push(from);
aoqi@0 555 _node_map.map(from->_idx, to);
aoqi@0 556 }
aoqi@0 557
aoqi@0 558 Node* get_map(int idx) { return _node_map[idx]; }
aoqi@0 559
aoqi@0 560 PhiNode* get_map_phi(int idx) {
aoqi@0 561 Node* phi = _node_map[idx];
aoqi@0 562 return (phi == NULL) ? NULL : phi->as_Phi();
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 // Notify optimizer that a node has been modified
aoqi@0 566 void record_for_optimizer(Node *n) {
aoqi@0 567 _igvn->_worklist.push(n);
aoqi@0 568 _igvn->add_users_to_worklist(n);
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 // Compute the escape information
aoqi@0 572 bool compute_escape();
aoqi@0 573
aoqi@0 574 public:
aoqi@0 575 ConnectionGraph(Compile *C, PhaseIterGVN *igvn);
aoqi@0 576
aoqi@0 577 // Check for non-escaping candidates
aoqi@0 578 static bool has_candidates(Compile *C);
aoqi@0 579
aoqi@0 580 // Perform escape analysis
aoqi@0 581 static void do_analysis(Compile *C, PhaseIterGVN *igvn);
aoqi@0 582
aoqi@0 583 bool not_global_escape(Node *n);
aoqi@0 584
aoqi@0 585 #ifndef PRODUCT
aoqi@0 586 void dump(GrowableArray<PointsToNode*>& ptnodes_worklist);
aoqi@0 587 #endif
aoqi@0 588 };
aoqi@0 589
aoqi@0 590 #endif // SHARE_VM_OPTO_ESCAPE_HPP

mercurial