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