src/hotspot/share/opto/buildOopMap.cpp
author never
Wed, 09 Oct 2019 16:35:44 -0700
changeset 58527 f9cc0141574c
parent 49026 844bf1deff1a
permissions -rw-r--r--
8231586: enlarge encoding space for OopMapValue offsets Reviewed-by: dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49026
844bf1deff1a 8196884: VS2017 Multiple Type Cast Conversion Compilation Errors
lfoltan
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22234
diff changeset
    26
#include "code/vmreg.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "compiler/oopMap.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 34174
diff changeset
    28
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/addnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/callnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/compile.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "opto/machnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "opto/phase.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "opto/regalloc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "opto/rootnode.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    37
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// The functions in this file builds OopMaps after all scheduling is done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// OopMaps contain a list of all registers and stack-slots containing oops (so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// they can be updated by GC).  OopMaps also contain a list of derived-pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// base-pointer pairs.  When the base is moved, the derived pointer moves to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// follow it.  Finally, any registers holding callee-save values are also
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// recorded.  These might contain oops, but only the caller knows.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// BuildOopMaps implements a simple forward reaching-defs solution.  At each
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// GC point we'll have the reaching-def Nodes.  If the reaching Nodes are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// typed as pointers (no offset), then they are oops.  Pointers+offsets are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// derived pointers, and bases can be found from them.  Finally, we'll also
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// track reaching callee-save values.  Note that a copy of a callee-save value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// "kills" it's source, so that only 1 copy of a callee-save value is alive at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// a time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// We run a simple bitvector liveness pass to help trim out dead oops.  Due to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// irreducible loops, we can have a reaching def of an oop that only reaches
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// along one path and no way to know if it's valid or not on the other path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// The bitvectors are quite dense and the liveness pass is fast.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// At GC points, we consult this information to build OopMaps.  All reaching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// defs typed as oops are added to the OopMap.  Only 1 instance of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// callee-save register can be recorded.  For derived pointers, we'll have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// find and record the register holding the base.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// The reaching def's is a simple 1-pass worklist approach.  I tried a clever
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// breadth-first approach but it was worse (showed O(n^2) in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// pick-next-block code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 670
diff changeset
    69
// The relevant data is kept in a struct of arrays (it could just as well be
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// an array of structs, but the struct-of-arrays is generally a little more
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// efficient).  The arrays are indexed by register number (including
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// stack-slots as registers) and so is bounded by 200 to 300 elements in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// practice.  One array will map to a reaching def Node (or NULL for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// conflict/dead).  The other array will map to a callee-saved register or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// OptoReg::Bad for not-callee-saved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// Structure to pass around
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
struct OopFlow : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  short *_callees;              // Array mapping register to callee-saved
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  Node **_defs;                 // array mapping register to reaching def
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                                // or NULL if dead/conflict
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // OopFlow structs, when not being actively modified, describe the _end_ of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // this block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  Block *_b;                    // Block for this struct
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  OopFlow *_next;               // Next free OopFlow
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
    87
                                // or NULL if dead/conflict
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
    88
  Compile* C;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
    90
  OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs),
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
    91
    _b(NULL), _next(NULL), C(c) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Given reaching-defs for this block start, compute it for this block end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Merge these two OopFlows into the 'this' pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void merge( OopFlow *flow, int max_reg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Copy a 'flow' over an existing flow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void clone( OopFlow *flow, int max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Make a new OopFlow from scratch
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   103
  static OopFlow *make( Arena *A, int max_size, Compile* C );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // Build an oopmap from the current flow info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// Given reaching-defs for this block start, compute it for this block end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   112
  for( uint i=0; i<_b->number_of_nodes(); i++ ) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   113
    Node *n = _b->get_node(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if( n->jvms() ) {           // Build an OopMap here?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      JVMState *jvms = n->jvms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      // no map needed for leaf calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        int *live = (int*) (*safehash)[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        assert( live, "must find live" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // Assign new reaching def's.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    // Note that I padded the _defs and _callees arrays so it's legal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // to index at _defs[OptoReg::Bad].
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    OptoReg::Name first = regalloc->get_reg_first(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    OptoReg::Name second = regalloc->get_reg_second(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    _defs[first] = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _defs[second] = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // Pass callee-save info around copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    int idx = n->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    if( idx ) {                 // Copies move callee-save info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      int tmp_first = _callees[old_first];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      int tmp_second = _callees[old_second];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      _callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      _callees[old_second] = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      _callees[first] = tmp_first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      _callees[second] = tmp_second;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    } else if( n->is_Phi() ) {  // Phis do not mod callee-saves
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      _callees[first] = OptoReg::Bad; // No longer holding a callee-save value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      _callees[second] = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      // Find base case for callee saves
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      if( n->is_Proj() && n->in(0)->is_Start() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        if( OptoReg::is_reg(first) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
            regalloc->_matcher.is_save_on_entry(first) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
          _callees[first] = first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        if( OptoReg::is_reg(second) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
            regalloc->_matcher.is_save_on_entry(second) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          _callees[second] = second;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// Merge the given flow into the 'this' flow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
void OopFlow::merge( OopFlow *flow, int max_reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  assert( _b == NULL, "merging into a happy flow" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  assert( flow->_b, "this flow is still alive" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  assert( flow != this, "no self flow" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // Do the merge.  If there are any differences, drop to 'bottom' which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // is OptoReg::Bad or NULL depending.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  for( int i=0; i<max_reg; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    // Merge the callee-save's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if( _callees[i] != flow->_callees[i] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      _callees[i] = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // Merge the reaching defs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if( _defs[i] != flow->_defs[i] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      _defs[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
void OopFlow::clone( OopFlow *flow, int max_size ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  _b = flow->_b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  memcpy( _callees, flow->_callees, sizeof(short)*max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  memcpy( _defs   , flow->_defs   , sizeof(Node*)*max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   191
OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  short *callees = NEW_ARENA_ARRAY(A,short,max_size+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  Node **defs    = NEW_ARENA_ARRAY(A,Node*,max_size+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) );
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   195
  OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert( &flow->_defs   [OptoReg::Bad] == defs   , "Ok to index at OptoReg::Bad" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  return flow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
static int get_live_bit( int *live, int reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  return live[reg>>LogBitsPerInt] &   (1<<(reg&(BitsPerInt-1))); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
static void set_live_bit( int *live, int reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
         live[reg>>LogBitsPerInt] |=  (1<<(reg&(BitsPerInt-1))); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
static void clr_live_bit( int *live, int reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
         live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// Build an oopmap from the current flow info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  int framesize = regalloc->_framesize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
              memset(dup_check,0,OptoReg::stack0()) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  OopMap *omap = new OopMap( framesize,  max_inarg_slot );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  JVMState* jvms = n->jvms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // For all registers do...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  for( int reg=0; reg<max_reg; reg++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if( get_live_bit(live,reg) == 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      continue;                 // Ignore if not live
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    // %%% C2 can use 2 OptoRegs when the physical register is only one 64bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    // register in that case we'll get an non-concrete register for the second
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    // half. We only need to tell the map the register once!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    // However for the moment we disable this change and leave things as they
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // were.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    if (false && r->is_reg() && !r->is_concrete()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    // See if dead (no reaching def).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    Node *def = _defs[reg];     // Get reaching def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    assert( def, "since live better have reaching def" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    // Classify the reaching def as oop, derived, callee-save, dead, or other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    const Type *t = def->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    if( t->isa_oop_ptr() ) {    // Oop or derived?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      // 64-bit pointers record oop-ishness on 2 aligned adjacent registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      // Make sure both are record from the same reaching def, but do not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      // put both into the oopmap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      if( (reg&1) == 1 ) {      // High half of oop-pair?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        continue;               // Do not record high parts in oopmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      // Check for a legal reg name in the oopMap and bailout if it is not.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      if (!omap->legal_vm_reg_name(r)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        regalloc->C->record_method_not_compilable("illegal oopMap register name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      if( t->is_ptr()->_offset == 0 ) { // Not derived?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        if( mcall ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
          // Outgoing argument GC mask responsibility belongs to the callee,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
          // not the caller.  Inspect the inputs to the call, to see if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
          // this live-range is one of them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          uint cnt = mcall->tf()->domain()->cnt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          uint j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
          for( j = TypeFunc::Parms; j < cnt; j++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
            if( mcall->in(j) == def )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
              break;            // reaching def is an argument oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
          if( j < cnt )         // arg oops dont go in GC map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
            continue;           // Continue on to the next register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        omap->set_oop(r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      } else {                  // Else it's derived.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        // Find the base of the derived value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        // Fast, common case, scan
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        for( i = jvms->oopoff(); i < n->req(); i+=2 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          if( n->in(i) == def ) break; // Common case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        if( i == n->req() ) {   // Missed, try a more generous scan
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
          // Scan again, but this time peek through copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
          for( i = jvms->oopoff(); i < n->req(); i+=2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
            Node *m = n->in(i); // Get initial derived value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
            while( 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
              Node *d = def;    // Get initial reaching def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
              while( 1 ) {      // Follow copies of reaching def to end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
                if( m == d ) goto found; // breaks 3 loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
                int idx = d->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
                if( !idx ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
                d = d->in(idx);     // Link through copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
              int idx = m->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
              if( !idx ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
              m = m->in(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
          }
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   297
          guarantee( 0, "must find derived/base pair" );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      found: ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
        Node *base = n->in(i+1); // Base is other half of pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
        int breg = regalloc->get_reg_first(base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
        VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
        // I record liveness at safepoints BEFORE I make the inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
        // live.  This is because argument oops are NOT live at a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
        // safepoint (or at least they cannot appear in the oopmap).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        // Thus bases of base/derived pairs might not be in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
        // liveness data but they need to appear in the oopmap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        if( get_live_bit(live,breg) == 0 ) {// Not live?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
          // Flag it, so next derived pointer won't re-insert into oopmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
          set_live_bit(live,breg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
          // Already missed our turn?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
          if( breg < reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
            if (b->is_stack() || b->is_concrete() || true ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
              omap->set_oop( b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        if (b->is_stack() || b->is_concrete() || true ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
          omap->set_derived_oop( r, b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   324
    } else if( t->isa_narrowoop() ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   325
      assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   326
      // Check for a legal reg name in the oopMap and bailout if it is not.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   327
      if (!omap->legal_vm_reg_name(r)) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   328
        regalloc->C->record_method_not_compilable("illegal oopMap register name");
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   329
        continue;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   330
      }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   331
      if( mcall ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   332
          // Outgoing argument GC mask responsibility belongs to the callee,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   333
          // not the caller.  Inspect the inputs to the call, to see if
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   334
          // this live-range is one of them.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   335
        uint cnt = mcall->tf()->domain()->cnt();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   336
        uint j;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   337
        for( j = TypeFunc::Parms; j < cnt; j++)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   338
          if( mcall->in(j) == def )
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   339
            break;            // reaching def is an argument oop
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   340
        if( j < cnt )         // arg oops dont go in GC map
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   341
          continue;           // Continue on to the next register
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   342
      }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   343
      omap->set_narrowoop(r);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    } else if( OptoReg::is_valid(_callees[reg])) { // callee-save?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      // It's a callee-save value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      debug_only( dup_check[_callees[reg]]=1; )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      if ( callee->is_concrete() || true ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
        omap->set_callee_saved( r, callee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      // Other - some reaching non-oop value
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   355
#ifdef ASSERT
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   356
      if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) {
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   357
        def->dump();
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   358
        n->dump();
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   359
        assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint");
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   360
      }
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   361
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  /* Nice, Intel-only assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  int cnt_callee_saves=0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  int reg2 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  while (OptoReg::is_reg(reg2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    if( dup_check[reg2] != 0) cnt_callee_saves++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    reg2++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
2573
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   378
#ifdef ASSERT
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   379
  for( OopMapStream oms1(omap); !oms1.is_done(); oms1.next()) {
2573
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   380
    OopMapValue omv1 = oms1.current();
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   381
    if (omv1.type() != OopMapValue::derived_oop_value) {
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   382
      continue;
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   383
    }
2573
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   384
    bool found = false;
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   385
    for( OopMapStream oms2(omap); !oms2.is_done(); oms2.next()) {
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   386
      OopMapValue omv2 = oms2.current();
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   387
      if (omv2.type() != OopMapValue::oop_value) {
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   388
        continue;
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   389
      }
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 49026
diff changeset
   390
      if( omv1.content_reg() == omv2.reg() ) {
2573
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   391
        found = true;
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   392
        break;
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   393
      }
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   394
    }
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   395
    assert( found, "derived with no base in oopmap" );
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   396
  }
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   397
#endif
b5002ef26155 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 2131
diff changeset
   398
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  return omap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
// Compute backwards liveness on registers
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   403
static void do_liveness(PhaseRegAlloc* regalloc, PhaseCFG* cfg, Block_List* worklist, int max_reg_ints, Arena* A, Dict* safehash) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   404
  int* live = NEW_ARENA_ARRAY(A, int, (cfg->number_of_blocks() + 1) * max_reg_ints);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   405
  int* tmp_live = &live[cfg->number_of_blocks() * max_reg_ints];
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   406
  Node* root = cfg->get_root_node();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // On CISC platforms, get the node representing the stack pointer  that regalloc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // used for spills
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  Node *fp = NodeSentinel;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  if (UseCISCSpill && root->req() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    fp = root->in(1)->in(TypeFunc::FramePtr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   413
  memset(live, 0, cfg->number_of_blocks() * (max_reg_ints << LogBytesPerInt));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  // Push preds onto worklist
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   415
  for (uint i = 1; i < root->req(); i++) {
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   416
    Block* block = cfg->get_block_for_node(root->in(i));
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   417
    worklist->push(block);
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   418
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // ZKM.jar includes tiny infinite loops which are unreached from below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // If we missed any blocks, we'll retry here after pushing all missed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // blocks on the worklist.  Normally this outer loop never trips more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  // than once.
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   424
  while (1) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    while( worklist->size() ) { // Standard worklist algorithm
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      Block *b = worklist->rpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      // Copy first successor into my tmp_live space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      int s0num = b->_succs[0]->_pre_order;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      int *t = &live[s0num*max_reg_ints];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
      for( int i=0; i<max_reg_ints; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
        tmp_live[i] = t[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      // OR in the remaining live registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      for( uint j=1; j<b->_num_succs; j++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
        uint sjnum = b->_succs[j]->_pre_order;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        int *t = &live[sjnum*max_reg_ints];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
        for( int i=0; i<max_reg_ints; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
          tmp_live[i] |= t[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      // Now walk tmp_live up the block backwards, computing live
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   444
      for( int k=b->number_of_nodes()-1; k>=0; k-- ) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   445
        Node *n = b->get_node(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        // KILL def'd bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        int first = regalloc->get_reg_first(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        int second = regalloc->get_reg_second(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
        MachNode *m = n->is_Mach() ? n->as_Mach() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
        // Check if m is potentially a CISC alternate instruction (i.e, possibly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        // synthesized by RegAlloc from a conventional instruction and a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
        // spilled input)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
        bool is_cisc_alternate = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
        if (UseCISCSpill && m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
          is_cisc_alternate = m->is_cisc_alternate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        // GEN use'd bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
        for( uint l=1; l<n->req(); l++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
          Node *def = n->in(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
          assert(def != 0, "input edge required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
          int first = regalloc->get_reg_first(def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
          int second = regalloc->get_reg_second(def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
          if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
          if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
          // If we use the stack pointer in a cisc-alternative instruction,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
          // check for use as a memory operand.  Then reconstruct the RegName
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
          // for this stack location, and set the appropriate bit in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
          // live vector 4987749.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
          if (is_cisc_alternate && def == fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
            const TypePtr *adr_type = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
            intptr_t offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
            const Node* base = m->get_base_and_disp(offset, adr_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
            if (base == NodeSentinel) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
              // Machnode has multiple memory inputs. We are unable to reason
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
              // with these, but are presuming (with trepidation) that not any of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
              // them are oops. This can be fixed by making get_base_and_disp()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
              // look at a specific input instead of all inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
              assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
            } else if (base != fp || offset == Type::OffsetBot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
              // Do nothing: the fp operand is either not from a memory use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
              // (base == NULL) OR the fp is used in a non-memory context
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
              // (base is some other register) OR the offset is not constant,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
              // so it is not a stack slot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
              assert(offset >= 0, "unexpected negative offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
              offset -= (offset % jintSize);  // count the whole word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
              int stack_reg = regalloc->offset2reg(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
              if (OptoReg::is_stack(stack_reg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
                set_live_bit(tmp_live, stack_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
                assert(false, "stack_reg not on stack?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
        if( n->jvms() ) {       // Record liveness at safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
          // This placement of this stanza means inputs to calls are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          // considered live at the callsite's OopMap.  Argument oops are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
          // hence live, but NOT included in the oopmap.  See cutout in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
          // build_oop_map.  Debug oops are live (and in OopMap).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
          int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
          for( int l=0; l<max_reg_ints; l++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
            n_live[l] = tmp_live[l];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
          safehash->Insert(n,n_live);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
      // Now at block top, see if we have any changes.  If so, propagate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      // to prior blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      int *old_live = &live[b->_pre_order*max_reg_ints];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      int l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      for( l=0; l<max_reg_ints; l++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
        if( tmp_live[l] != old_live[l] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      if( l<max_reg_ints ) {     // Change!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
        // Copy in new value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        for( l=0; l<max_reg_ints; l++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
          old_live[l] = tmp_live[l];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
        // Push preds onto worklist
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   528
        for (l = 1; l < (int)b->num_preds(); l++) {
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   529
          Block* block = cfg->get_block_for_node(b->pred(l));
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   530
          worklist->push(block);
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   531
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    // Scan for any missing safepoints.  Happens to infinite loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    // ala ZKM.jar
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    uint i;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   538
    for (i = 1; i < cfg->number_of_blocks(); i++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   539
      Block* block = cfg->get_block(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      uint j;
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   541
      for (j = 1; j < block->number_of_nodes(); j++) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   542
        if (block->get_node(j)->jvms() && (*safehash)[block->get_node(j)] == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
           break;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   544
        }
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   545
      }
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   546
      if (j < block->number_of_nodes()) {
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   547
        break;
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   548
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   550
    if (i == cfg->number_of_blocks()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
      break;                    // Got 'em all
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   552
    }
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 26913
diff changeset
   553
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 26913
diff changeset
   554
    if (PrintOpto && Verbose) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      tty->print_cr("retripping live calc");
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 26913
diff changeset
   556
    }
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 26913
diff changeset
   557
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    // Force the issue (expensively): recheck everybody
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   559
    for (i = 1; i < cfg->number_of_blocks(); i++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   560
      worklist->push(cfg->get_block(i));
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   561
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
// Collect GC mask info - where are all the OOPs?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
void Compile::BuildOopMaps() {
26913
9ad70cd32368 8058968: Compiler time traces should be improved
shade
parents: 25715
diff changeset
   567
  TracePhase tp("bldOopMaps", &timers[_t_buildOopMaps]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // Can't resource-mark because I need to leave all those OopMaps around,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // or else I need to resource-mark some arena other than the default.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // ResourceMark rm;              // Reclaim all OopFlows when done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  int max_reg = _regalloc->_max_reg; // Current array extent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  Arena *A = Thread::current()->resource_area();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  Block_List worklist;          // Worklist of pending blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 37248
diff changeset
   576
  int max_reg_ints = align_up(max_reg, BitsPerInt)>>LogBitsPerInt;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  Dict *safehash = NULL;        // Used for assert only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  // Compute a backwards liveness per register.  Needs a bitarray of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  // #blocks x (#registers, rounded up to ints)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  safehash = new Dict(cmpkey,hashkey,A);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  OopFlow *free_list = NULL;    // Free, unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // Array mapping blocks to completed oopflows
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   585
  OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->number_of_blocks());
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   586
  memset( flows, 0, _cfg->number_of_blocks() * sizeof(OopFlow*) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // Do the first block 'by hand' to prime the worklist
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   590
  Block *entry = _cfg->get_block(1);
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   591
  OopFlow *rootflow = OopFlow::make(A,max_reg,this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  // Initialize to 'bottom' (not 'top')
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  memset( rootflow->_defs   ,            0, max_reg*sizeof(Node*) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  flows[entry->_pre_order] = rootflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  // Do the first block 'by hand' to prime the worklist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  rootflow->_b = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  rootflow->compute_reach( _regalloc, max_reg, safehash );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  for( uint i=0; i<entry->_num_succs; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    worklist.push(entry->_succs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  // Now worklist contains blocks which have some, but perhaps not all,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  // predecessors visited.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  while( worklist.size() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    // Scan for a block with all predecessors visited, or any randoms slob
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    // otherwise.  All-preds-visited order allows me to recycle OopFlow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    // structures rapidly and cut down on the memory footprint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    // Note: not all predecessors might be visited yet (must happen for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    // irreducible loops).  This is OK, since every live value must have the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    // SAME reaching def for the block, so any reaching def is OK.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    uint i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    Block *b = worklist.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    // Ignore root block
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   616
    if (b == _cfg->get_root_block()) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   617
      continue;
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   618
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    // Block is already done?  Happens if block has several predecessors,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    // he can get on the worklist more than once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    if( flows[b->_pre_order] ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    // If this block has a visited predecessor AND that predecessor has this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    // last block as his only undone child, we can move the OopFlow from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    // pred to this block.  Otherwise we have to grab a new OopFlow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    OopFlow *flow = NULL;       // Flag for finding optimized flow
49026
844bf1deff1a 8196884: VS2017 Multiple Type Cast Conversion Compilation Errors
lfoltan
parents: 47216
diff changeset
   627
    Block *pred = (Block*)((intptr_t)0xdeadbeef);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    // Scan this block's preds to find a done predecessor
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   629
    for (uint j = 1; j < b->num_preds(); j++) {
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8921
diff changeset
   630
      Block* p = _cfg->get_block_for_node(b->pred(j));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
      OopFlow *p_flow = flows[p->_pre_order];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      if( p_flow ) {            // Predecessor is done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
        assert( p_flow->_b == p, "cross check" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
        pred = p;               // Record some predecessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
        // If all successors of p are done except for 'b', then we can carry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
        // p_flow forward to 'b' without copying, otherwise we have to draw
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
        // from the free_list and clone data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
        uint k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
        for( k=0; k<p->_num_succs; k++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
          if( !flows[p->_succs[k]->_pre_order] &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
              p->_succs[k] != b )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
        // Either carry-forward the now-unused OopFlow for b's use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
        // or draw a new one from the free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
        if( k==p->_num_succs ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
          flow = p_flow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
          break;                // Found an ideal pred, use him
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    if( flow ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      // We have an OopFlow that's the last-use of a predecessor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      // Carry it forward.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    } else {                    // Draw a new OopFlow from the freelist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      if( !free_list )
3186
11ba3d09bd0e 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 2573
diff changeset
   658
        free_list = OopFlow::make(A,max_reg,C);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      flow = free_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      assert( flow->_b == NULL, "oopFlow is not free" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      free_list = flow->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
      flow->_next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
      // Copy/clone over the data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      flow->clone(flows[pred->_pre_order], max_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    // Mark flow for block.  Blocks can only be flowed over once,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    // because after the first time they are guarded from entering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    // this code again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    assert( flow->_b == pred, "have some prior flow" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    flow->_b = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    // Now push flow forward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    flows[b->_pre_order] = flow;// Mark flow for this block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    flow->_b = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    flow->compute_reach( _regalloc, max_reg, safehash );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    // Now push children onto worklist
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    for( i=0; i<b->_num_succs; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
      worklist.push(b->_succs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
}