src/share/vm/opto/escape.hpp

Tue, 24 Jun 2008 10:43:29 -0700

author
kvn
date
Tue, 24 Jun 2008 10:43:29 -0700
changeset 656
1e026f8da827
parent 536
a6cb86dd209b
child 631
d1605aabd0a1
child 679
524eca34ea76
permissions
-rw-r--r--

6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
Summary: Remove DecodeNNode::decode() and EncodePNode::encode() methods.
Reviewed-by: rasbold, never

duke@435 1 /*
duke@435 2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 //
duke@435 26 // Adaptation for C2 of the escape analysis algorithm described in:
duke@435 27 //
kvn@500 28 // [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano,
kvn@500 29 // Vugranam C. Sreedhar, Sam Midkiff,
kvn@500 30 // "Escape Analysis for Java", Procedings of ACM SIGPLAN
kvn@500 31 // OOPSLA Conference, November 1, 1999
duke@435 32 //
duke@435 33 // The flow-insensitive analysis described in the paper has been implemented.
duke@435 34 //
kvn@500 35 // The analysis requires construction of a "connection graph" (CG) for
kvn@500 36 // the method being analyzed. The nodes of the connection graph are:
duke@435 37 //
duke@435 38 // - Java objects (JO)
duke@435 39 // - Local variables (LV)
duke@435 40 // - Fields of an object (OF), these also include array elements
duke@435 41 //
duke@435 42 // The CG contains 3 types of edges:
duke@435 43 //
kvn@500 44 // - PointsTo (-P>) {LV, OF} to JO
kvn@500 45 // - Deferred (-D>) from {LV, OF} to {LV, OF}
duke@435 46 // - Field (-F>) from JO to OF
duke@435 47 //
duke@435 48 // The following utility functions is used by the algorithm:
duke@435 49 //
kvn@500 50 // PointsTo(n) - n is any CG node, it returns the set of JO that n could
kvn@500 51 // point to.
duke@435 52 //
kvn@500 53 // The algorithm describes how to construct the connection graph
kvn@500 54 // in the following 4 cases:
duke@435 55 //
duke@435 56 // Case Edges Created
duke@435 57 //
kvn@500 58 // (1) p = new T() LV -P> JO
kvn@500 59 // (2) p = q LV -D> LV
kvn@500 60 // (3) p.f = q JO -F> OF, OF -D> LV
kvn@500 61 // (4) p = q.f JO -F> OF, LV -D> OF
duke@435 62 //
kvn@500 63 // In all these cases, p and q are local variables. For static field
kvn@500 64 // references, we can construct a local variable containing a reference
kvn@500 65 // to the static memory.
duke@435 66 //
duke@435 67 // C2 does not have local variables. However for the purposes of constructing
duke@435 68 // the connection graph, the following IR nodes are treated as local variables:
duke@435 69 // Phi (pointer values)
duke@435 70 // LoadP
kvn@500 71 // Proj#5 (value returned from callnodes including allocations)
kvn@500 72 // CheckCastPP, CastPP
duke@435 73 //
kvn@500 74 // The LoadP, Proj and CheckCastPP behave like variables assigned to only once.
kvn@500 75 // Only a Phi can have multiple assignments. Each input to a Phi is treated
duke@435 76 // as an assignment to it.
duke@435 77 //
kvn@500 78 // The following node types are JavaObject:
duke@435 79 //
duke@435 80 // top()
duke@435 81 // Allocate
duke@435 82 // AllocateArray
duke@435 83 // Parm (for incoming arguments)
kvn@500 84 // CastX2P ("unsafe" operations)
duke@435 85 // CreateEx
duke@435 86 // ConP
duke@435 87 // LoadKlass
kvn@500 88 // ThreadLocal
duke@435 89 //
duke@435 90 // AddP nodes are fields.
duke@435 91 //
duke@435 92 // After building the graph, a pass is made over the nodes, deleting deferred
duke@435 93 // nodes and copying the edges from the target of the deferred edge to the
duke@435 94 // source. This results in a graph with no deferred edges, only:
duke@435 95 //
duke@435 96 // LV -P> JO
kvn@500 97 // OF -P> JO (the object whose oop is stored in the field)
duke@435 98 // JO -F> OF
duke@435 99 //
duke@435 100 // Then, for each node which is GlobalEscape, anything it could point to
duke@435 101 // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
duke@435 102 // it could point to is marked ArgEscape.
duke@435 103 //
duke@435 104
duke@435 105 class Compile;
duke@435 106 class Node;
duke@435 107 class CallNode;
duke@435 108 class PhiNode;
duke@435 109 class PhaseTransform;
duke@435 110 class Type;
duke@435 111 class TypePtr;
duke@435 112 class VectorSet;
duke@435 113
duke@435 114 class PointsToNode {
duke@435 115 friend class ConnectionGraph;
duke@435 116 public:
duke@435 117 typedef enum {
kvn@500 118 UnknownType = 0,
kvn@500 119 JavaObject = 1,
kvn@500 120 LocalVar = 2,
kvn@500 121 Field = 3
duke@435 122 } NodeType;
duke@435 123
duke@435 124 typedef enum {
duke@435 125 UnknownEscape = 0,
kvn@500 126 NoEscape = 1, // A scalar replaceable object with unique type.
kvn@500 127 ArgEscape = 2, // An object passed as argument or referenced by
kvn@500 128 // argument (and not globally escape during call).
kvn@500 129 GlobalEscape = 3 // An object escapes the method and thread.
duke@435 130 } EscapeState;
duke@435 131
duke@435 132 typedef enum {
duke@435 133 UnknownEdge = 0,
duke@435 134 PointsToEdge = 1,
duke@435 135 DeferredEdge = 2,
duke@435 136 FieldEdge = 3
duke@435 137 } EdgeType;
duke@435 138
duke@435 139 private:
duke@435 140 enum {
duke@435 141 EdgeMask = 3,
duke@435 142 EdgeShift = 2,
duke@435 143
duke@435 144 INITIAL_EDGE_COUNT = 4
duke@435 145 };
duke@435 146
duke@435 147 NodeType _type;
duke@435 148 EscapeState _escape;
kvn@500 149 GrowableArray<uint>* _edges; // outgoing edges
duke@435 150
duke@435 151 public:
kvn@500 152 Node* _node; // Ideal node corresponding to this PointsTo node.
kvn@500 153 int _offset; // Object fields offsets.
kvn@500 154 bool _scalar_replaceable;// Not escaped object could be replaced with scalar
kvn@500 155 bool _hidden_alias; // This node is an argument to a function.
kvn@500 156 // which may return it creating a hidden alias.
duke@435 157
kvn@500 158 PointsToNode():
kvn@500 159 _type(UnknownType),
kvn@500 160 _escape(UnknownEscape),
kvn@500 161 _edges(NULL),
kvn@500 162 _node(NULL),
kvn@500 163 _offset(-1),
kvn@500 164 _scalar_replaceable(true),
kvn@500 165 _hidden_alias(false) {}
duke@435 166
duke@435 167
duke@435 168 EscapeState escape_state() const { return _escape; }
duke@435 169 NodeType node_type() const { return _type;}
duke@435 170 int offset() { return _offset;}
duke@435 171
duke@435 172 void set_offset(int offs) { _offset = offs;}
duke@435 173 void set_escape_state(EscapeState state) { _escape = state; }
duke@435 174 void set_node_type(NodeType ntype) {
duke@435 175 assert(_type == UnknownType || _type == ntype, "Can't change node type");
duke@435 176 _type = ntype;
duke@435 177 }
duke@435 178
duke@435 179 // count of outgoing edges
duke@435 180 uint edge_count() const { return (_edges == NULL) ? 0 : _edges->length(); }
duke@435 181 // node index of target of outgoing edge "e"
duke@435 182 uint edge_target(uint e) const;
duke@435 183 // type of outgoing edge "e"
duke@435 184 EdgeType edge_type(uint e) const;
duke@435 185 // add a edge of the specified type pointing to the specified target
duke@435 186 void add_edge(uint targIdx, EdgeType et);
duke@435 187 // remove an edge of the specified type pointing to the specified target
duke@435 188 void remove_edge(uint targIdx, EdgeType et);
duke@435 189 #ifndef PRODUCT
duke@435 190 void dump() const;
duke@435 191 #endif
duke@435 192
duke@435 193 };
duke@435 194
duke@435 195 class ConnectionGraph: public ResourceObj {
duke@435 196 private:
kvn@500 197 GrowableArray<PointsToNode>* _nodes; // Connection graph nodes indexed
kvn@500 198 // by ideal node index.
duke@435 199
kvn@500 200 Unique_Node_List _delayed_worklist; // Nodes to be processed before
kvn@500 201 // the call build_connection_graph().
duke@435 202
kvn@500 203 VectorSet _processed; // Records which nodes have been
kvn@500 204 // processed.
kvn@500 205
kvn@500 206 bool _collecting; // Indicates whether escape information
kvn@500 207 // is still being collected. If false,
kvn@500 208 // no new nodes will be processed.
kvn@500 209
kvn@500 210 bool _has_allocations; // Indicates whether method has any
kvn@500 211 // non-escaping allocations.
kvn@500 212
kvn@500 213 uint _phantom_object; // Index of globally escaping object
kvn@500 214 // that pointer values loaded from
kvn@500 215 // a field which has not been set
kvn@500 216 // are assumed to point to.
kvn@500 217
kvn@500 218 Compile * _compile; // Compile object for current compilation
duke@435 219
duke@435 220 // address of an element in _nodes. Used when the element is to be modified
duke@435 221 PointsToNode *ptnode_adr(uint idx) {
duke@435 222 if ((uint)_nodes->length() <= idx) {
duke@435 223 // expand _nodes array
duke@435 224 PointsToNode dummy = _nodes->at_grow(idx);
duke@435 225 }
duke@435 226 return _nodes->adr_at(idx);
duke@435 227 }
duke@435 228
kvn@500 229 // Add node to ConnectionGraph.
kvn@500 230 void add_node(Node *n, PointsToNode::NodeType nt, PointsToNode::EscapeState es, bool done);
kvn@500 231
duke@435 232 // offset of a field reference
kvn@500 233 int address_offset(Node* adr, PhaseTransform *phase);
duke@435 234
duke@435 235 // compute the escape state for arguments to a call
duke@435 236 void process_call_arguments(CallNode *call, PhaseTransform *phase);
duke@435 237
duke@435 238 // compute the escape state for the return value of a call
duke@435 239 void process_call_result(ProjNode *resproj, PhaseTransform *phase);
duke@435 240
kvn@500 241 // Populate Connection Graph with Ideal nodes.
kvn@500 242 void record_for_escape_analysis(Node *n, PhaseTransform *phase);
duke@435 243
kvn@500 244 // Build Connection Graph and set nodes escape state.
kvn@500 245 void build_connection_graph(Node *n, PhaseTransform *phase);
duke@435 246
duke@435 247 // walk the connection graph starting at the node corresponding to "n" and
duke@435 248 // add the index of everything it could point to, to "ptset". This may cause
duke@435 249 // Phi's encountered to get (re)processed (which requires "phase".)
duke@435 250 void PointsTo(VectorSet &ptset, Node * n, PhaseTransform *phase);
duke@435 251
duke@435 252 // Edge manipulation. The "from_i" and "to_i" arguments are the
duke@435 253 // node indices of the source and destination of the edge
duke@435 254 void add_pointsto_edge(uint from_i, uint to_i);
duke@435 255 void add_deferred_edge(uint from_i, uint to_i);
duke@435 256 void add_field_edge(uint from_i, uint to_i, int offs);
duke@435 257
duke@435 258
duke@435 259 // Add an edge to node given by "to_i" from any field of adr_i whose offset
duke@435 260 // matches "offset" A deferred edge is added if to_i is a LocalVar, and
duke@435 261 // a pointsto edge is added if it is a JavaObject
duke@435 262 void add_edge_from_fields(uint adr, uint to_i, int offs);
duke@435 263
kvn@500 264 // Add a deferred edge from node given by "from_i" to any field
kvn@500 265 // of adr_i whose offset matches "offset"
duke@435 266 void add_deferred_edge_to_fields(uint from_i, uint adr, int offs);
duke@435 267
duke@435 268
duke@435 269 // Remove outgoing deferred edges from the node referenced by "ni".
duke@435 270 // Any outgoing edges from the target of the deferred edge are copied
duke@435 271 // to "ni".
kvn@536 272 void remove_deferred(uint ni, GrowableArray<uint>* deferred_edges, VectorSet* visited);
duke@435 273
duke@435 274 Node_Array _node_map; // used for bookeeping during type splitting
duke@435 275 // Used for the following purposes:
duke@435 276 // Memory Phi - most recent unique Phi split out
duke@435 277 // from this Phi
duke@435 278 // MemNode - new memory input for this node
duke@435 279 // ChecCastPP - allocation that this is a cast of
duke@435 280 // allocation - CheckCastPP of the allocation
duke@435 281 void split_AddP(Node *addp, Node *base, PhaseGVN *igvn);
duke@435 282 PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created);
duke@435 283 PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn);
duke@435 284 Node *find_mem(Node *mem, int alias_idx, PhaseGVN *igvn);
kvn@500 285 Node *find_inst_mem(Node *mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn);
kvn@500 286
duke@435 287 // Propagate unique types created for unescaped allocated objects
duke@435 288 // through the graph
duke@435 289 void split_unique_types(GrowableArray<Node *> &alloc_worklist);
duke@435 290
duke@435 291 // manage entries in _node_map
duke@435 292 void set_map(int idx, Node *n) { _node_map.map(idx, n); }
duke@435 293 void set_map_phi(int idx, PhiNode *p) { _node_map.map(idx, (Node *) p); }
duke@435 294 Node *get_map(int idx) { return _node_map[idx]; }
duke@435 295 PhiNode *get_map_phi(int idx) {
duke@435 296 Node *phi = _node_map[idx];
duke@435 297 return (phi == NULL) ? NULL : phi->as_Phi();
duke@435 298 }
duke@435 299
duke@435 300 // Notify optimizer that a node has been modified
duke@435 301 // Node: This assumes that escape analysis is run before
duke@435 302 // PhaseIterGVN creation
duke@435 303 void record_for_optimizer(Node *n) {
duke@435 304 _compile->record_for_igvn(n);
duke@435 305 }
duke@435 306
duke@435 307 // Set the escape state of a node
duke@435 308 void set_escape_state(uint ni, PointsToNode::EscapeState es);
duke@435 309
duke@435 310 // Get Compile object for current compilation.
duke@435 311 Compile *C() const { return _compile; }
duke@435 312
duke@435 313 public:
duke@435 314 ConnectionGraph(Compile *C);
duke@435 315
kvn@500 316 // Compute the escape information
duke@435 317 void compute_escape();
duke@435 318
duke@435 319 // escape state of a node
duke@435 320 PointsToNode::EscapeState escape_state(Node *n, PhaseTransform *phase);
kvn@500 321 // other information we have collected
kvn@500 322 bool is_scalar_replaceable(Node *n) {
kvn@500 323 if (_collecting)
kvn@500 324 return false;
kvn@500 325 PointsToNode ptn = _nodes->at_grow(n->_idx);
kvn@500 326 return ptn.escape_state() == PointsToNode::NoEscape && ptn._scalar_replaceable;
kvn@500 327 }
duke@435 328
duke@435 329 bool hidden_alias(Node *n) {
duke@435 330 if (_collecting)
duke@435 331 return true;
duke@435 332 PointsToNode ptn = _nodes->at_grow(n->_idx);
duke@435 333 return (ptn.escape_state() != PointsToNode::NoEscape) || ptn._hidden_alias;
duke@435 334 }
duke@435 335
duke@435 336 #ifndef PRODUCT
duke@435 337 void dump();
duke@435 338 #endif
duke@435 339 };

mercurial