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