src/share/vm/opto/escape.hpp

Mon, 25 Feb 2008 15:05:44 -0800

author
kvn
date
Mon, 25 Feb 2008 15:05:44 -0800
changeset 464
d5fc211aea19
parent 435
a61af66fc99e
child 500
99269dbf4ba8
permissions
-rw-r--r--

6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
Summary: T_ADDRESS size is defined as 'int' size (4 bytes) but C2 use it for raw pointers and as memory type for StoreP and LoadP nodes.
Reviewed-by: jrose

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 //
duke@435 28 // [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano, Vugranam C. Sreedhar,
duke@435 29 // Sam Midkiff, "Escape Analysis for Java", Procedings of ACM SIGPLAN
duke@435 30 // OOPSLA Conference, November 1, 1999
duke@435 31 //
duke@435 32 // The flow-insensitive analysis described in the paper has been implemented.
duke@435 33 //
duke@435 34 // The analysis requires construction of a "connection graph" (CG) for the method being
duke@435 35 // analyzed. The nodes of the connection graph are:
duke@435 36 //
duke@435 37 // - Java objects (JO)
duke@435 38 // - Local variables (LV)
duke@435 39 // - Fields of an object (OF), these also include array elements
duke@435 40 //
duke@435 41 // The CG contains 3 types of edges:
duke@435 42 //
duke@435 43 // - PointsTo (-P>) {LV,OF} to JO
duke@435 44 // - Deferred (-D>) from {LV, OF} to {LV, OF}
duke@435 45 // - Field (-F>) from JO to OF
duke@435 46 //
duke@435 47 // The following utility functions is used by the algorithm:
duke@435 48 //
duke@435 49 // PointsTo(n) - n is any CG node, it returns the set of JO that n could
duke@435 50 // point to.
duke@435 51 //
duke@435 52 // The algorithm describes how to construct the connection graph in the following 4 cases:
duke@435 53 //
duke@435 54 // Case Edges Created
duke@435 55 //
duke@435 56 // (1) p = new T() LV -P> JO
duke@435 57 // (2) p = q LV -D> LV
duke@435 58 // (3) p.f = q JO -F> OF, OF -D> LV
duke@435 59 // (4) p = q.f JO -F> OF, LV -D> OF
duke@435 60 //
duke@435 61 // In all these cases, p and q are local variables. For static field references, we can
duke@435 62 // construct a local variable containing a reference to the static memory.
duke@435 63 //
duke@435 64 // C2 does not have local variables. However for the purposes of constructing
duke@435 65 // the connection graph, the following IR nodes are treated as local variables:
duke@435 66 // Phi (pointer values)
duke@435 67 // LoadP
duke@435 68 // Proj (value returned from callnodes including allocations)
duke@435 69 // CheckCastPP
duke@435 70 //
duke@435 71 // The LoadP, Proj and CheckCastPP behave like variables assigned to only once. Only
duke@435 72 // a Phi can have multiple assignments. Each input to a Phi is treated
duke@435 73 // as an assignment to it.
duke@435 74 //
duke@435 75 // The following note types are JavaObject:
duke@435 76 //
duke@435 77 // top()
duke@435 78 // Allocate
duke@435 79 // AllocateArray
duke@435 80 // Parm (for incoming arguments)
duke@435 81 // CreateEx
duke@435 82 // ConP
duke@435 83 // LoadKlass
duke@435 84 //
duke@435 85 // AddP nodes are fields.
duke@435 86 //
duke@435 87 // After building the graph, a pass is made over the nodes, deleting deferred
duke@435 88 // nodes and copying the edges from the target of the deferred edge to the
duke@435 89 // source. This results in a graph with no deferred edges, only:
duke@435 90 //
duke@435 91 // LV -P> JO
duke@435 92 // OF -P> JO
duke@435 93 // JO -F> OF
duke@435 94 //
duke@435 95 // Then, for each node which is GlobalEscape, anything it could point to
duke@435 96 // is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
duke@435 97 // it could point to is marked ArgEscape.
duke@435 98 //
duke@435 99
duke@435 100 class Compile;
duke@435 101 class Node;
duke@435 102 class CallNode;
duke@435 103 class PhiNode;
duke@435 104 class PhaseTransform;
duke@435 105 class Type;
duke@435 106 class TypePtr;
duke@435 107 class VectorSet;
duke@435 108
duke@435 109 class PointsToNode {
duke@435 110 friend class ConnectionGraph;
duke@435 111 public:
duke@435 112 typedef enum {
duke@435 113 UnknownType = 0,
duke@435 114 JavaObject = 1,
duke@435 115 LocalVar = 2,
duke@435 116 Field = 3
duke@435 117 } NodeType;
duke@435 118
duke@435 119 typedef enum {
duke@435 120 UnknownEscape = 0,
duke@435 121 NoEscape = 1,
duke@435 122 ArgEscape = 2,
duke@435 123 GlobalEscape = 3
duke@435 124 } EscapeState;
duke@435 125
duke@435 126 typedef enum {
duke@435 127 UnknownEdge = 0,
duke@435 128 PointsToEdge = 1,
duke@435 129 DeferredEdge = 2,
duke@435 130 FieldEdge = 3
duke@435 131 } EdgeType;
duke@435 132
duke@435 133 private:
duke@435 134 enum {
duke@435 135 EdgeMask = 3,
duke@435 136 EdgeShift = 2,
duke@435 137
duke@435 138 INITIAL_EDGE_COUNT = 4
duke@435 139 };
duke@435 140
duke@435 141 NodeType _type;
duke@435 142 EscapeState _escape;
duke@435 143 GrowableArray<uint>* _edges; // outgoing edges
duke@435 144 int _offset; // for fields
duke@435 145
duke@435 146 bool _unique_type; // For allocated objects, this node may be a unique type
duke@435 147 public:
duke@435 148 Node* _node; // Ideal node corresponding to this PointsTo node
duke@435 149 int _inputs_processed; // the number of Phi inputs that have been processed so far
duke@435 150 bool _hidden_alias; // this node is an argument to a function which may return it
duke@435 151 // creating a hidden alias
duke@435 152
duke@435 153
duke@435 154 PointsToNode(): _offset(-1), _type(UnknownType), _escape(UnknownEscape), _edges(NULL), _node(NULL), _inputs_processed(0), _hidden_alias(false), _unique_type(true) {}
duke@435 155
duke@435 156 EscapeState escape_state() const { return _escape; }
duke@435 157 NodeType node_type() const { return _type;}
duke@435 158 int offset() { return _offset;}
duke@435 159
duke@435 160 void set_offset(int offs) { _offset = offs;}
duke@435 161 void set_escape_state(EscapeState state) { _escape = state; }
duke@435 162 void set_node_type(NodeType ntype) {
duke@435 163 assert(_type == UnknownType || _type == ntype, "Can't change node type");
duke@435 164 _type = ntype;
duke@435 165 }
duke@435 166
duke@435 167 // count of outgoing edges
duke@435 168 uint edge_count() const { return (_edges == NULL) ? 0 : _edges->length(); }
duke@435 169 // node index of target of outgoing edge "e"
duke@435 170 uint edge_target(uint e) const;
duke@435 171 // type of outgoing edge "e"
duke@435 172 EdgeType edge_type(uint e) const;
duke@435 173 // add a edge of the specified type pointing to the specified target
duke@435 174 void add_edge(uint targIdx, EdgeType et);
duke@435 175 // remove an edge of the specified type pointing to the specified target
duke@435 176 void remove_edge(uint targIdx, EdgeType et);
duke@435 177 #ifndef PRODUCT
duke@435 178 void dump() const;
duke@435 179 #endif
duke@435 180
duke@435 181 };
duke@435 182
duke@435 183 class ConnectionGraph: public ResourceObj {
duke@435 184 private:
duke@435 185 enum {
duke@435 186 INITIAL_NODE_COUNT = 100 // initial size of _nodes array
duke@435 187 };
duke@435 188
duke@435 189
duke@435 190 GrowableArray<PointsToNode>* _nodes; // connection graph nodes Indexed by ideal
duke@435 191 // node index
duke@435 192 Unique_Node_List _deferred; // Phi's to be processed after parsing
duke@435 193 VectorSet _processed; // records which nodes have been processed
duke@435 194 bool _collecting; // indicates whether escape information is
duke@435 195 // still being collected. If false, no new
duke@435 196 // nodes will be processed
duke@435 197 uint _phantom_object; // index of globally escaping object that
duke@435 198 // pointer values loaded from a field which
duke@435 199 // has not been set are assumed to point to
duke@435 200 Compile * _compile; // Compile object for current compilation
duke@435 201
duke@435 202 // address of an element in _nodes. Used when the element is to be modified
duke@435 203 PointsToNode *ptnode_adr(uint idx) {
duke@435 204 if ((uint)_nodes->length() <= idx) {
duke@435 205 // expand _nodes array
duke@435 206 PointsToNode dummy = _nodes->at_grow(idx);
duke@435 207 }
duke@435 208 return _nodes->adr_at(idx);
duke@435 209 }
duke@435 210
duke@435 211 // offset of a field reference
duke@435 212 int type_to_offset(const Type *t);
duke@435 213
duke@435 214 // compute the escape state for arguments to a call
duke@435 215 void process_call_arguments(CallNode *call, PhaseTransform *phase);
duke@435 216
duke@435 217 // compute the escape state for the return value of a call
duke@435 218 void process_call_result(ProjNode *resproj, PhaseTransform *phase);
duke@435 219
duke@435 220 // compute the escape state of a Phi. This may be called multiple
duke@435 221 // times as new inputs are added to the Phi.
duke@435 222 void process_phi_escape(PhiNode *phi, PhaseTransform *phase);
duke@435 223
duke@435 224 // compute the escape state of an ideal node.
duke@435 225 void record_escape_work(Node *n, PhaseTransform *phase);
duke@435 226
duke@435 227 // walk the connection graph starting at the node corresponding to "n" and
duke@435 228 // add the index of everything it could point to, to "ptset". This may cause
duke@435 229 // Phi's encountered to get (re)processed (which requires "phase".)
duke@435 230 void PointsTo(VectorSet &ptset, Node * n, PhaseTransform *phase);
duke@435 231
duke@435 232 // Edge manipulation. The "from_i" and "to_i" arguments are the
duke@435 233 // node indices of the source and destination of the edge
duke@435 234 void add_pointsto_edge(uint from_i, uint to_i);
duke@435 235 void add_deferred_edge(uint from_i, uint to_i);
duke@435 236 void add_field_edge(uint from_i, uint to_i, int offs);
duke@435 237
duke@435 238
duke@435 239 // Add an edge to node given by "to_i" from any field of adr_i whose offset
duke@435 240 // matches "offset" A deferred edge is added if to_i is a LocalVar, and
duke@435 241 // a pointsto edge is added if it is a JavaObject
duke@435 242 void add_edge_from_fields(uint adr, uint to_i, int offs);
duke@435 243
duke@435 244 // Add a deferred edge from node given by "from_i" to any field of adr_i whose offset
duke@435 245 // matches "offset"
duke@435 246 void add_deferred_edge_to_fields(uint from_i, uint adr, int offs);
duke@435 247
duke@435 248
duke@435 249 // Remove outgoing deferred edges from the node referenced by "ni".
duke@435 250 // Any outgoing edges from the target of the deferred edge are copied
duke@435 251 // to "ni".
duke@435 252 void remove_deferred(uint ni);
duke@435 253
duke@435 254 Node_Array _node_map; // used for bookeeping during type splitting
duke@435 255 // Used for the following purposes:
duke@435 256 // Memory Phi - most recent unique Phi split out
duke@435 257 // from this Phi
duke@435 258 // MemNode - new memory input for this node
duke@435 259 // ChecCastPP - allocation that this is a cast of
duke@435 260 // allocation - CheckCastPP of the allocation
duke@435 261 void split_AddP(Node *addp, Node *base, PhaseGVN *igvn);
duke@435 262 PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created);
duke@435 263 PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn);
duke@435 264 Node *find_mem(Node *mem, int alias_idx, PhaseGVN *igvn);
duke@435 265 // Propagate unique types created for unescaped allocated objects
duke@435 266 // through the graph
duke@435 267 void split_unique_types(GrowableArray<Node *> &alloc_worklist);
duke@435 268
duke@435 269 // manage entries in _node_map
duke@435 270 void set_map(int idx, Node *n) { _node_map.map(idx, n); }
duke@435 271 void set_map_phi(int idx, PhiNode *p) { _node_map.map(idx, (Node *) p); }
duke@435 272 Node *get_map(int idx) { return _node_map[idx]; }
duke@435 273 PhiNode *get_map_phi(int idx) {
duke@435 274 Node *phi = _node_map[idx];
duke@435 275 return (phi == NULL) ? NULL : phi->as_Phi();
duke@435 276 }
duke@435 277
duke@435 278 // Notify optimizer that a node has been modified
duke@435 279 // Node: This assumes that escape analysis is run before
duke@435 280 // PhaseIterGVN creation
duke@435 281 void record_for_optimizer(Node *n) {
duke@435 282 _compile->record_for_igvn(n);
duke@435 283 }
duke@435 284
duke@435 285 // Set the escape state of a node
duke@435 286 void set_escape_state(uint ni, PointsToNode::EscapeState es);
duke@435 287
duke@435 288 // bypass any casts and return the node they refer to
duke@435 289 Node * skip_casts(Node *n);
duke@435 290
duke@435 291 // Get Compile object for current compilation.
duke@435 292 Compile *C() const { return _compile; }
duke@435 293
duke@435 294 public:
duke@435 295 ConnectionGraph(Compile *C);
duke@435 296
duke@435 297 // record a Phi for later processing.
duke@435 298 void record_for_escape_analysis(Node *n);
duke@435 299
duke@435 300 // process a node and fill in its connection graph node
duke@435 301 void record_escape(Node *n, PhaseTransform *phase);
duke@435 302
duke@435 303 // All nodes have been recorded, compute the escape information
duke@435 304 void compute_escape();
duke@435 305
duke@435 306 // escape state of a node
duke@435 307 PointsToNode::EscapeState escape_state(Node *n, PhaseTransform *phase);
duke@435 308
duke@435 309 bool hidden_alias(Node *n) {
duke@435 310 if (_collecting)
duke@435 311 return true;
duke@435 312 PointsToNode ptn = _nodes->at_grow(n->_idx);
duke@435 313 return (ptn.escape_state() != PointsToNode::NoEscape) || ptn._hidden_alias;
duke@435 314 }
duke@435 315
duke@435 316 #ifndef PRODUCT
duke@435 317 void dump();
duke@435 318 #endif
duke@435 319 };

mercurial