1 /*
   2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "libadt/vectset.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "opto/ad.hpp"
  32 #include "opto/callGenerator.hpp"
  33 #include "opto/castnode.hpp"
  34 #include "opto/cfgnode.hpp"
  35 #include "opto/connode.hpp"
  36 #include "opto/loopnode.hpp"
  37 #include "opto/machnode.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/node.hpp"
  40 #include "opto/opcodes.hpp"
  41 #include "opto/regmask.hpp"
  42 #include "opto/rootnode.hpp"
  43 #include "opto/type.hpp"
  44 #include "utilities/copy.hpp"
  45 #include "utilities/macros.hpp"
  46 #include "utilities/powerOfTwo.hpp"
  47 
  48 class RegMask;
  49 // #include "phase.hpp"
  50 class PhaseTransform;
  51 class PhaseGVN;
  52 
  53 // Arena we are currently building Nodes in
  54 const uint Node::NotAMachineReg = 0xffff0000;
  55 
  56 #ifndef PRODUCT
  57 extern int nodes_created;
  58 #endif
  59 #ifdef __clang__
  60 #pragma clang diagnostic push
  61 #pragma GCC diagnostic ignored "-Wuninitialized"
  62 #endif
  63 
  64 #ifdef ASSERT
  65 
  66 //-------------------------- construct_node------------------------------------
  67 // Set a breakpoint here to identify where a particular node index is built.
  68 void Node::verify_construction() {
  69   _debug_orig = NULL;
  70   int old_debug_idx = Compile::debug_idx();
  71   int new_debug_idx = old_debug_idx + 1;
  72   if (new_debug_idx > 0) {
  73     // Arrange that the lowest five decimal digits of _debug_idx
  74     // will repeat those of _idx. In case this is somehow pathological,
  75     // we continue to assign negative numbers (!) consecutively.
  76     const int mod = 100000;
  77     int bump = (int)(_idx - new_debug_idx) % mod;
  78     if (bump < 0) {
  79       bump += mod;
  80     }
  81     assert(bump >= 0 && bump < mod, "");
  82     new_debug_idx += bump;
  83   }
  84   Compile::set_debug_idx(new_debug_idx);
  85   set_debug_idx(new_debug_idx);
  86   Compile* C = Compile::current();
  87   assert(C->unique() < (INT_MAX - 1), "Node limit exceeded INT_MAX");
  88   if (!C->phase_optimize_finished()) {
  89     // Only check assert during parsing and optimization phase. Skip it while generating code.
  90     assert(C->live_nodes() <= C->max_node_limit(), "Live Node limit exceeded limit");
  91   }
  92   if (BreakAtNode != 0 && (_debug_idx == BreakAtNode || (int)_idx == BreakAtNode)) {
  93     tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d", _idx, _debug_idx);
  94     BREAKPOINT;
  95   }
  96 #if OPTO_DU_ITERATOR_ASSERT
  97   _last_del = NULL;
  98   _del_tick = 0;
  99 #endif
 100   _hash_lock = 0;
 101 }
 102 
 103 
 104 // #ifdef ASSERT ...
 105 
 106 #if OPTO_DU_ITERATOR_ASSERT
 107 void DUIterator_Common::sample(const Node* node) {
 108   _vdui     = VerifyDUIterators;
 109   _node     = node;
 110   _outcnt   = node->_outcnt;
 111   _del_tick = node->_del_tick;
 112   _last     = NULL;
 113 }
 114 
 115 void DUIterator_Common::verify(const Node* node, bool at_end_ok) {
 116   assert(_node     == node, "consistent iterator source");
 117   assert(_del_tick == node->_del_tick, "no unexpected deletions allowed");
 118 }
 119 
 120 void DUIterator_Common::verify_resync() {
 121   // Ensure that the loop body has just deleted the last guy produced.
 122   const Node* node = _node;
 123   // Ensure that at least one copy of the last-seen edge was deleted.
 124   // Note:  It is OK to delete multiple copies of the last-seen edge.
 125   // Unfortunately, we have no way to verify that all the deletions delete
 126   // that same edge.  On this point we must use the Honor System.
 127   assert(node->_del_tick >= _del_tick+1, "must have deleted an edge");
 128   assert(node->_last_del == _last, "must have deleted the edge just produced");
 129   // We liked this deletion, so accept the resulting outcnt and tick.
 130   _outcnt   = node->_outcnt;
 131   _del_tick = node->_del_tick;
 132 }
 133 
 134 void DUIterator_Common::reset(const DUIterator_Common& that) {
 135   if (this == &that)  return;  // ignore assignment to self
 136   if (!_vdui) {
 137     // We need to initialize everything, overwriting garbage values.
 138     _last = that._last;
 139     _vdui = that._vdui;
 140   }
 141   // Note:  It is legal (though odd) for an iterator over some node x
 142   // to be reassigned to iterate over another node y.  Some doubly-nested
 143   // progress loops depend on being able to do this.
 144   const Node* node = that._node;
 145   // Re-initialize everything, except _last.
 146   _node     = node;
 147   _outcnt   = node->_outcnt;
 148   _del_tick = node->_del_tick;
 149 }
 150 
 151 void DUIterator::sample(const Node* node) {
 152   DUIterator_Common::sample(node);      // Initialize the assertion data.
 153   _refresh_tick = 0;                    // No refreshes have happened, as yet.
 154 }
 155 
 156 void DUIterator::verify(const Node* node, bool at_end_ok) {
 157   DUIterator_Common::verify(node, at_end_ok);
 158   assert(_idx      <  node->_outcnt + (uint)at_end_ok, "idx in range");
 159 }
 160 
 161 void DUIterator::verify_increment() {
 162   if (_refresh_tick & 1) {
 163     // We have refreshed the index during this loop.
 164     // Fix up _idx to meet asserts.
 165     if (_idx > _outcnt)  _idx = _outcnt;
 166   }
 167   verify(_node, true);
 168 }
 169 
 170 void DUIterator::verify_resync() {
 171   // Note:  We do not assert on _outcnt, because insertions are OK here.
 172   DUIterator_Common::verify_resync();
 173   // Make sure we are still in sync, possibly with no more out-edges:
 174   verify(_node, true);
 175 }
 176 
 177 void DUIterator::reset(const DUIterator& that) {
 178   if (this == &that)  return;  // self assignment is always a no-op
 179   assert(that._refresh_tick == 0, "assign only the result of Node::outs()");
 180   assert(that._idx          == 0, "assign only the result of Node::outs()");
 181   assert(_idx               == that._idx, "already assigned _idx");
 182   if (!_vdui) {
 183     // We need to initialize everything, overwriting garbage values.
 184     sample(that._node);
 185   } else {
 186     DUIterator_Common::reset(that);
 187     if (_refresh_tick & 1) {
 188       _refresh_tick++;                  // Clear the "was refreshed" flag.
 189     }
 190     assert(_refresh_tick < 2*100000, "DU iteration must converge quickly");
 191   }
 192 }
 193 
 194 void DUIterator::refresh() {
 195   DUIterator_Common::sample(_node);     // Re-fetch assertion data.
 196   _refresh_tick |= 1;                   // Set the "was refreshed" flag.
 197 }
 198 
 199 void DUIterator::verify_finish() {
 200   // If the loop has killed the node, do not require it to re-run.
 201   if (_node->_outcnt == 0)  _refresh_tick &= ~1;
 202   // If this assert triggers, it means that a loop used refresh_out_pos
 203   // to re-synch an iteration index, but the loop did not correctly
 204   // re-run itself, using a "while (progress)" construct.
 205   // This iterator enforces the rule that you must keep trying the loop
 206   // until it "runs clean" without any need for refreshing.
 207   assert(!(_refresh_tick & 1), "the loop must run once with no refreshing");
 208 }
 209 
 210 
 211 void DUIterator_Fast::verify(const Node* node, bool at_end_ok) {
 212   DUIterator_Common::verify(node, at_end_ok);
 213   Node** out    = node->_out;
 214   uint   cnt    = node->_outcnt;
 215   assert(cnt == _outcnt, "no insertions allowed");
 216   assert(_outp >= out && _outp <= out + cnt - !at_end_ok, "outp in range");
 217   // This last check is carefully designed to work for NO_OUT_ARRAY.
 218 }
 219 
 220 void DUIterator_Fast::verify_limit() {
 221   const Node* node = _node;
 222   verify(node, true);
 223   assert(_outp == node->_out + node->_outcnt, "limit still correct");
 224 }
 225 
 226 void DUIterator_Fast::verify_resync() {
 227   const Node* node = _node;
 228   if (_outp == node->_out + _outcnt) {
 229     // Note that the limit imax, not the pointer i, gets updated with the
 230     // exact count of deletions.  (For the pointer it's always "--i".)
 231     assert(node->_outcnt+node->_del_tick == _outcnt+_del_tick, "no insertions allowed with deletion(s)");
 232     // This is a limit pointer, with a name like "imax".
 233     // Fudge the _last field so that the common assert will be happy.
 234     _last = (Node*) node->_last_del;
 235     DUIterator_Common::verify_resync();
 236   } else {
 237     assert(node->_outcnt < _outcnt, "no insertions allowed with deletion(s)");
 238     // A normal internal pointer.
 239     DUIterator_Common::verify_resync();
 240     // Make sure we are still in sync, possibly with no more out-edges:
 241     verify(node, true);
 242   }
 243 }
 244 
 245 void DUIterator_Fast::verify_relimit(uint n) {
 246   const Node* node = _node;
 247   assert((int)n > 0, "use imax -= n only with a positive count");
 248   // This must be a limit pointer, with a name like "imax".
 249   assert(_outp == node->_out + node->_outcnt, "apply -= only to a limit (imax)");
 250   // The reported number of deletions must match what the node saw.
 251   assert(node->_del_tick == _del_tick + n, "must have deleted n edges");
 252   // Fudge the _last field so that the common assert will be happy.
 253   _last = (Node*) node->_last_del;
 254   DUIterator_Common::verify_resync();
 255 }
 256 
 257 void DUIterator_Fast::reset(const DUIterator_Fast& that) {
 258   assert(_outp              == that._outp, "already assigned _outp");
 259   DUIterator_Common::reset(that);
 260 }
 261 
 262 void DUIterator_Last::verify(const Node* node, bool at_end_ok) {
 263   // at_end_ok means the _outp is allowed to underflow by 1
 264   _outp += at_end_ok;
 265   DUIterator_Fast::verify(node, at_end_ok);  // check _del_tick, etc.
 266   _outp -= at_end_ok;
 267   assert(_outp == (node->_out + node->_outcnt) - 1, "pointer must point to end of nodes");
 268 }
 269 
 270 void DUIterator_Last::verify_limit() {
 271   // Do not require the limit address to be resynched.
 272   //verify(node, true);
 273   assert(_outp == _node->_out, "limit still correct");
 274 }
 275 
 276 void DUIterator_Last::verify_step(uint num_edges) {
 277   assert((int)num_edges > 0, "need non-zero edge count for loop progress");
 278   _outcnt   -= num_edges;
 279   _del_tick += num_edges;
 280   // Make sure we are still in sync, possibly with no more out-edges:
 281   const Node* node = _node;
 282   verify(node, true);
 283   assert(node->_last_del == _last, "must have deleted the edge just produced");
 284 }
 285 
 286 #endif //OPTO_DU_ITERATOR_ASSERT
 287 
 288 
 289 #endif //ASSERT
 290 
 291 
 292 // This constant used to initialize _out may be any non-null value.
 293 // The value NULL is reserved for the top node only.
 294 #define NO_OUT_ARRAY ((Node**)-1)
 295 
 296 // Out-of-line code from node constructors.
 297 // Executed only when extra debug info. is being passed around.
 298 static void init_node_notes(Compile* C, int idx, Node_Notes* nn) {
 299   C->set_node_notes_at(idx, nn);
 300 }
 301 
 302 // Shared initialization code.
 303 inline int Node::Init(int req) {
 304   Compile* C = Compile::current();
 305   int idx = C->next_unique();
 306   NOT_PRODUCT(_igv_idx = C->next_igv_idx());
 307 
 308   // Allocate memory for the necessary number of edges.
 309   if (req > 0) {
 310     // Allocate space for _in array to have double alignment.
 311     _in = (Node **) ((char *) (C->node_arena()->AmallocWords(req * sizeof(void*))));
 312   }
 313   // If there are default notes floating around, capture them:
 314   Node_Notes* nn = C->default_node_notes();
 315   if (nn != NULL)  init_node_notes(C, idx, nn);
 316 
 317   // Note:  At this point, C is dead,
 318   // and we begin to initialize the new Node.
 319 
 320   _cnt = _max = req;
 321   _outcnt = _outmax = 0;
 322   _class_id = Class_Node;
 323   _flags = 0;
 324   _out = NO_OUT_ARRAY;
 325   return idx;
 326 }
 327 
 328 //------------------------------Node-------------------------------------------
 329 // Create a Node, with a given number of required edges.
 330 Node::Node(uint req)
 331   : _idx(Init(req))
 332 #ifdef ASSERT
 333   , _parse_idx(_idx)
 334   , _indent(0)
 335 #endif
 336 {
 337   assert( req < Compile::current()->max_node_limit() - NodeLimitFudgeFactor, "Input limit exceeded" );
 338   debug_only( verify_construction() );
 339   NOT_PRODUCT(nodes_created++);
 340   if (req == 0) {
 341     _in = NULL;
 342   } else {
 343     Node** to = _in;
 344     for(uint i = 0; i < req; i++) {
 345       to[i] = NULL;
 346     }
 347   }
 348 }
 349 
 350 //------------------------------Node-------------------------------------------
 351 Node::Node(Node *n0)
 352   : _idx(Init(1))
 353 #ifdef ASSERT
 354   , _parse_idx(_idx)
 355   , _indent(0)
 356 #endif
 357 {
 358   debug_only( verify_construction() );
 359   NOT_PRODUCT(nodes_created++);
 360   assert( is_not_dead(n0), "can not use dead node");
 361   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 362 }
 363 
 364 //------------------------------Node-------------------------------------------
 365 Node::Node(Node *n0, Node *n1)
 366   : _idx(Init(2))
 367 #ifdef ASSERT
 368   , _parse_idx(_idx)
 369   , _indent(0)
 370 #endif
 371 {
 372   debug_only( verify_construction() );
 373   NOT_PRODUCT(nodes_created++);
 374   assert( is_not_dead(n0), "can not use dead node");
 375   assert( is_not_dead(n1), "can not use dead node");
 376   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 377   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 378 }
 379 
 380 //------------------------------Node-------------------------------------------
 381 Node::Node(Node *n0, Node *n1, Node *n2)
 382   : _idx(Init(3))
 383 #ifdef ASSERT
 384   , _parse_idx(_idx)
 385   , _indent(0)
 386 #endif
 387 {
 388   debug_only( verify_construction() );
 389   NOT_PRODUCT(nodes_created++);
 390   assert( is_not_dead(n0), "can not use dead node");
 391   assert( is_not_dead(n1), "can not use dead node");
 392   assert( is_not_dead(n2), "can not use dead node");
 393   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 394   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 395   _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this);
 396 }
 397 
 398 //------------------------------Node-------------------------------------------
 399 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3)
 400   : _idx(Init(4))
 401 #ifdef ASSERT
 402   , _parse_idx(_idx)
 403   , _indent(0)
 404 #endif
 405 {
 406   debug_only( verify_construction() );
 407   NOT_PRODUCT(nodes_created++);
 408   assert( is_not_dead(n0), "can not use dead node");
 409   assert( is_not_dead(n1), "can not use dead node");
 410   assert( is_not_dead(n2), "can not use dead node");
 411   assert( is_not_dead(n3), "can not use dead node");
 412   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 413   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 414   _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this);
 415   _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this);
 416 }
 417 
 418 //------------------------------Node-------------------------------------------
 419 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4)
 420   : _idx(Init(5))
 421 #ifdef ASSERT
 422   , _parse_idx(_idx)
 423   , _indent(0)
 424 #endif
 425 {
 426   debug_only( verify_construction() );
 427   NOT_PRODUCT(nodes_created++);
 428   assert( is_not_dead(n0), "can not use dead node");
 429   assert( is_not_dead(n1), "can not use dead node");
 430   assert( is_not_dead(n2), "can not use dead node");
 431   assert( is_not_dead(n3), "can not use dead node");
 432   assert( is_not_dead(n4), "can not use dead node");
 433   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 434   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 435   _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this);
 436   _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this);
 437   _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this);
 438 }
 439 
 440 //------------------------------Node-------------------------------------------
 441 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
 442                      Node *n4, Node *n5)
 443   : _idx(Init(6))
 444 #ifdef ASSERT
 445   , _parse_idx(_idx)
 446   , _indent(0)
 447 #endif
 448 {
 449   debug_only( verify_construction() );
 450   NOT_PRODUCT(nodes_created++);
 451   assert( is_not_dead(n0), "can not use dead node");
 452   assert( is_not_dead(n1), "can not use dead node");
 453   assert( is_not_dead(n2), "can not use dead node");
 454   assert( is_not_dead(n3), "can not use dead node");
 455   assert( is_not_dead(n4), "can not use dead node");
 456   assert( is_not_dead(n5), "can not use dead node");
 457   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 458   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 459   _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this);
 460   _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this);
 461   _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this);
 462   _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this);
 463 }
 464 
 465 //------------------------------Node-------------------------------------------
 466 Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
 467                      Node *n4, Node *n5, Node *n6)
 468   : _idx(Init(7))
 469 #ifdef ASSERT
 470   , _parse_idx(_idx)
 471   , _indent(0)
 472 #endif
 473 {
 474   debug_only( verify_construction() );
 475   NOT_PRODUCT(nodes_created++);
 476   assert( is_not_dead(n0), "can not use dead node");
 477   assert( is_not_dead(n1), "can not use dead node");
 478   assert( is_not_dead(n2), "can not use dead node");
 479   assert( is_not_dead(n3), "can not use dead node");
 480   assert( is_not_dead(n4), "can not use dead node");
 481   assert( is_not_dead(n5), "can not use dead node");
 482   assert( is_not_dead(n6), "can not use dead node");
 483   _in[0] = n0; if (n0 != NULL) n0->add_out((Node *)this);
 484   _in[1] = n1; if (n1 != NULL) n1->add_out((Node *)this);
 485   _in[2] = n2; if (n2 != NULL) n2->add_out((Node *)this);
 486   _in[3] = n3; if (n3 != NULL) n3->add_out((Node *)this);
 487   _in[4] = n4; if (n4 != NULL) n4->add_out((Node *)this);
 488   _in[5] = n5; if (n5 != NULL) n5->add_out((Node *)this);
 489   _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this);
 490 }
 491 
 492 #ifdef __clang__
 493 #pragma clang diagnostic pop
 494 #endif
 495 
 496 
 497 //------------------------------clone------------------------------------------
 498 // Clone a Node.
 499 Node *Node::clone() const {
 500   Compile* C = Compile::current();
 501   uint s = size_of();           // Size of inherited Node
 502   Node *n = (Node*)C->node_arena()->AmallocWords(size_of() + _max*sizeof(Node*));
 503   Copy::conjoint_words_to_lower((HeapWord*)this, (HeapWord*)n, s);
 504   // Set the new input pointer array
 505   n->_in = (Node**)(((char*)n)+s);
 506   // Cannot share the old output pointer array, so kill it
 507   n->_out = NO_OUT_ARRAY;
 508   // And reset the counters to 0
 509   n->_outcnt = 0;
 510   n->_outmax = 0;
 511   // Unlock this guy, since he is not in any hash table.
 512   debug_only(n->_hash_lock = 0);
 513   // Walk the old node's input list to duplicate its edges
 514   uint i;
 515   for( i = 0; i < len(); i++ ) {
 516     Node *x = in(i);
 517     n->_in[i] = x;
 518     if (x != NULL) x->add_out(n);
 519   }
 520   if (is_macro()) {
 521     C->add_macro_node(n);
 522   }
 523   if (is_expensive()) {
 524     C->add_expensive_node(n);
 525   }
 526   if (for_post_loop_opts_igvn()) {
 527     // Don't add cloned node to Compile::_for_post_loop_opts_igvn list automatically.
 528     // If it is applicable, it will happen anyway when the cloned node is registered with IGVN.
 529     n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
 530   }
 531   if (n->is_reduction()) {
 532     // Do not copy reduction information. This must be explicitly set by the calling code.
 533     n->remove_flag(Node::Flag_is_reduction);
 534   }
 535   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 536   bs->register_potential_barrier_node(n);
 537 
 538   n->set_idx(C->next_unique()); // Get new unique index as well
 539   NOT_PRODUCT(n->_igv_idx = C->next_igv_idx());
 540   debug_only( n->verify_construction() );
 541   NOT_PRODUCT(nodes_created++);
 542   // Do not patch over the debug_idx of a clone, because it makes it
 543   // impossible to break on the clone's moment of creation.
 544   //debug_only( n->set_debug_idx( debug_idx() ) );
 545 
 546   C->copy_node_notes_to(n, (Node*) this);
 547 
 548   // MachNode clone
 549   uint nopnds;
 550   if (this->is_Mach() && (nopnds = this->as_Mach()->num_opnds()) > 0) {
 551     MachNode *mach  = n->as_Mach();
 552     MachNode *mthis = this->as_Mach();
 553     // Get address of _opnd_array.
 554     // It should be the same offset since it is the clone of this node.
 555     MachOper **from = mthis->_opnds;
 556     MachOper **to = (MachOper **)((size_t)(&mach->_opnds) +
 557                     pointer_delta((const void*)from,
 558                                   (const void*)(&mthis->_opnds), 1));
 559     mach->_opnds = to;
 560     for ( uint i = 0; i < nopnds; ++i ) {
 561       to[i] = from[i]->clone();
 562     }
 563   }
 564   if (n->is_Call()) {
 565     // CallGenerator is linked to the original node.
 566     CallGenerator* cg = n->as_Call()->generator();
 567     if (cg != NULL) {
 568       CallGenerator* cloned_cg = cg->with_call_node(n->as_Call());
 569       n->as_Call()->set_generator(cloned_cg);
 570 
 571       C->print_inlining_assert_ready();
 572       C->print_inlining_move_to(cg);
 573       C->print_inlining_update(cloned_cg);
 574     }
 575   }
 576   if (n->is_SafePoint()) {
 577     // Scalar replacement and macro expansion might modify the JVMState.
 578     // Clone it to make sure it's not shared between SafePointNodes.
 579     n->as_SafePoint()->clone_jvms(C);
 580     n->as_SafePoint()->clone_replaced_nodes();
 581   }
 582   if (n->is_InlineTypeBase()) {
 583     C->add_inline_type(n);
 584   }
 585   return n;                     // Return the clone
 586 }
 587 
 588 //---------------------------setup_is_top--------------------------------------
 589 // Call this when changing the top node, to reassert the invariants
 590 // required by Node::is_top.  See Compile::set_cached_top_node.
 591 void Node::setup_is_top() {
 592   if (this == (Node*)Compile::current()->top()) {
 593     // This node has just become top.  Kill its out array.
 594     _outcnt = _outmax = 0;
 595     _out = NULL;                           // marker value for top
 596     assert(is_top(), "must be top");
 597   } else {
 598     if (_out == NULL)  _out = NO_OUT_ARRAY;
 599     assert(!is_top(), "must not be top");
 600   }
 601 }
 602 
 603 //------------------------------~Node------------------------------------------
 604 // Fancy destructor; eagerly attempt to reclaim Node numberings and storage
 605 void Node::destruct(PhaseValues* phase) {
 606   Compile* compile = (phase != NULL) ? phase->C : Compile::current();
 607   if (phase != NULL && phase->is_IterGVN()) {
 608     phase->is_IterGVN()->_worklist.remove(this);
 609   }
 610   // If this is the most recently created node, reclaim its index. Otherwise,
 611   // record the node as dead to keep liveness information accurate.
 612   if ((uint)_idx+1 == compile->unique()) {
 613     compile->set_unique(compile->unique()-1);
 614   } else {
 615     compile->record_dead_node(_idx);
 616   }
 617   // Clear debug info:
 618   Node_Notes* nn = compile->node_notes_at(_idx);
 619   if (nn != NULL)  nn->clear();
 620   // Walk the input array, freeing the corresponding output edges
 621   _cnt = _max;  // forget req/prec distinction
 622   uint i;
 623   for( i = 0; i < _max; i++ ) {
 624     set_req(i, NULL);
 625     //assert(def->out(def->outcnt()-1) == (Node *)this,"bad def-use hacking in reclaim");
 626   }
 627   assert(outcnt() == 0, "deleting a node must not leave a dangling use");
 628   // See if the input array was allocated just prior to the object
 629   int edge_size = _max*sizeof(void*);
 630   int out_edge_size = _outmax*sizeof(void*);
 631   char *edge_end = ((char*)_in) + edge_size;
 632   char *out_array = (char*)(_out == NO_OUT_ARRAY? NULL: _out);
 633   int node_size = size_of();
 634 
 635   // Free the output edge array
 636   if (out_edge_size > 0) {
 637     compile->node_arena()->Afree(out_array, out_edge_size);
 638   }
 639 
 640   // Free the input edge array and the node itself
 641   if( edge_end == (char*)this ) {
 642     // It was; free the input array and object all in one hit
 643 #ifndef ASSERT
 644     compile->node_arena()->Afree(_in,edge_size+node_size);
 645 #endif
 646   } else {
 647     // Free just the input array
 648     compile->node_arena()->Afree(_in,edge_size);
 649 
 650     // Free just the object
 651 #ifndef ASSERT
 652     compile->node_arena()->Afree(this,node_size);
 653 #endif
 654   }
 655   if (is_macro()) {
 656     compile->remove_macro_node(this);
 657   }
 658   if (is_expensive()) {
 659     compile->remove_expensive_node(this);
 660   }
 661   if (Opcode() == Op_Opaque4) {
 662     compile->remove_skeleton_predicate_opaq(this);
 663   }
 664   if (for_post_loop_opts_igvn()) {
 665     compile->remove_from_post_loop_opts_igvn(this);
 666   }
 667   if (is_InlineTypeBase()) {
 668     compile->remove_inline_type(this);
 669   }
 670 
 671   if (is_SafePoint()) {
 672     as_SafePoint()->delete_replaced_nodes();
 673   }
 674   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 675   bs->unregister_potential_barrier_node(this);
 676 #ifdef ASSERT
 677   // We will not actually delete the storage, but we'll make the node unusable.
 678   *(address*)this = badAddress;  // smash the C++ vtbl, probably
 679   _in = _out = (Node**) badAddress;
 680   _max = _cnt = _outmax = _outcnt = 0;
 681   compile->remove_modified_node(this);
 682 #endif
 683 }
 684 
 685 //------------------------------grow-------------------------------------------
 686 // Grow the input array, making space for more edges
 687 void Node::grow(uint len) {
 688   Arena* arena = Compile::current()->node_arena();
 689   uint new_max = _max;
 690   if( new_max == 0 ) {
 691     _max = 4;
 692     _in = (Node**)arena->Amalloc(4*sizeof(Node*));
 693     Node** to = _in;
 694     to[0] = NULL;
 695     to[1] = NULL;
 696     to[2] = NULL;
 697     to[3] = NULL;
 698     return;
 699   }
 700   new_max = next_power_of_2(len);
 701   // Trimming to limit allows a uint8 to handle up to 255 edges.
 702   // Previously I was using only powers-of-2 which peaked at 128 edges.
 703   //if( new_max >= limit ) new_max = limit-1;
 704   _in = (Node**)arena->Arealloc(_in, _max*sizeof(Node*), new_max*sizeof(Node*));
 705   Copy::zero_to_bytes(&_in[_max], (new_max-_max)*sizeof(Node*)); // NULL all new space
 706   _max = new_max;               // Record new max length
 707   // This assertion makes sure that Node::_max is wide enough to
 708   // represent the numerical value of new_max.
 709   assert(_max == new_max && _max > len, "int width of _max is too small");
 710 }
 711 
 712 //-----------------------------out_grow----------------------------------------
 713 // Grow the input array, making space for more edges
 714 void Node::out_grow( uint len ) {
 715   assert(!is_top(), "cannot grow a top node's out array");
 716   Arena* arena = Compile::current()->node_arena();
 717   uint new_max = _outmax;
 718   if( new_max == 0 ) {
 719     _outmax = 4;
 720     _out = (Node **)arena->Amalloc(4*sizeof(Node*));
 721     return;
 722   }
 723   new_max = next_power_of_2(len);
 724   // Trimming to limit allows a uint8 to handle up to 255 edges.
 725   // Previously I was using only powers-of-2 which peaked at 128 edges.
 726   //if( new_max >= limit ) new_max = limit-1;
 727   assert(_out != NULL && _out != NO_OUT_ARRAY, "out must have sensible value");
 728   _out = (Node**)arena->Arealloc(_out,_outmax*sizeof(Node*),new_max*sizeof(Node*));
 729   //Copy::zero_to_bytes(&_out[_outmax], (new_max-_outmax)*sizeof(Node*)); // NULL all new space
 730   _outmax = new_max;               // Record new max length
 731   // This assertion makes sure that Node::_max is wide enough to
 732   // represent the numerical value of new_max.
 733   assert(_outmax == new_max && _outmax > len, "int width of _outmax is too small");
 734 }
 735 
 736 #ifdef ASSERT
 737 //------------------------------is_dead----------------------------------------
 738 bool Node::is_dead() const {
 739   // Mach and pinch point nodes may look like dead.
 740   if( is_top() || is_Mach() || (Opcode() == Op_Node && _outcnt > 0) )
 741     return false;
 742   for( uint i = 0; i < _max; i++ )
 743     if( _in[i] != NULL )
 744       return false;
 745   dump();
 746   return true;
 747 }
 748 
 749 bool Node::is_reachable_from_root() const {
 750   ResourceMark rm;
 751   Unique_Node_List wq;
 752   wq.push((Node*)this);
 753   RootNode* root = Compile::current()->root();
 754   for (uint i = 0; i < wq.size(); i++) {
 755     Node* m = wq.at(i);
 756     if (m == root) {
 757       return true;
 758     }
 759     for (DUIterator_Fast jmax, j = m->fast_outs(jmax); j < jmax; j++) {
 760       Node* u = m->fast_out(j);
 761       wq.push(u);
 762     }
 763   }
 764   return false;
 765 }
 766 #endif
 767 
 768 //------------------------------is_unreachable---------------------------------
 769 bool Node::is_unreachable(PhaseIterGVN &igvn) const {
 770   assert(!is_Mach(), "doesn't work with MachNodes");
 771   return outcnt() == 0 || igvn.type(this) == Type::TOP || (in(0) != NULL && in(0)->is_top());
 772 }
 773 
 774 //------------------------------add_req----------------------------------------
 775 // Add a new required input at the end
 776 void Node::add_req( Node *n ) {
 777   assert( is_not_dead(n), "can not use dead node");
 778 
 779   // Look to see if I can move precedence down one without reallocating
 780   if( (_cnt >= _max) || (in(_max-1) != NULL) )
 781     grow( _max+1 );
 782 
 783   // Find a precedence edge to move
 784   if( in(_cnt) != NULL ) {       // Next precedence edge is busy?
 785     uint i;
 786     for( i=_cnt; i<_max; i++ )
 787       if( in(i) == NULL )       // Find the NULL at end of prec edge list
 788         break;                  // There must be one, since we grew the array
 789     _in[i] = in(_cnt);          // Move prec over, making space for req edge
 790   }
 791   _in[_cnt++] = n;            // Stuff over old prec edge
 792   if (n != NULL) n->add_out((Node *)this);
 793 }
 794 
 795 //---------------------------add_req_batch-------------------------------------
 796 // Add a new required input at the end
 797 void Node::add_req_batch( Node *n, uint m ) {
 798   assert( is_not_dead(n), "can not use dead node");
 799   // check various edge cases
 800   if ((int)m <= 1) {
 801     assert((int)m >= 0, "oob");
 802     if (m != 0)  add_req(n);
 803     return;
 804   }
 805 
 806   // Look to see if I can move precedence down one without reallocating
 807   if( (_cnt+m) > _max || _in[_max-m] )
 808     grow( _max+m );
 809 
 810   // Find a precedence edge to move
 811   if( _in[_cnt] != NULL ) {     // Next precedence edge is busy?
 812     uint i;
 813     for( i=_cnt; i<_max; i++ )
 814       if( _in[i] == NULL )      // Find the NULL at end of prec edge list
 815         break;                  // There must be one, since we grew the array
 816     // Slide all the precs over by m positions (assume #prec << m).
 817     Copy::conjoint_words_to_higher((HeapWord*)&_in[_cnt], (HeapWord*)&_in[_cnt+m], ((i-_cnt)*sizeof(Node*)));
 818   }
 819 
 820   // Stuff over the old prec edges
 821   for(uint i=0; i<m; i++ ) {
 822     _in[_cnt++] = n;
 823   }
 824 
 825   // Insert multiple out edges on the node.
 826   if (n != NULL && !n->is_top()) {
 827     for(uint i=0; i<m; i++ ) {
 828       n->add_out((Node *)this);
 829     }
 830   }
 831 }
 832 
 833 //------------------------------del_req----------------------------------------
 834 // Delete the required edge and compact the edge array
 835 void Node::del_req( uint idx ) {
 836   assert( idx < _cnt, "oob");
 837   assert( !VerifyHashTableKeys || _hash_lock == 0,
 838           "remove node from hash table before modifying it");
 839   // First remove corresponding def-use edge
 840   Node *n = in(idx);
 841   if (n != NULL) n->del_out((Node *)this);
 842   _in[idx] = in(--_cnt); // Compact the array
 843   // Avoid spec violation: Gap in prec edges.
 844   close_prec_gap_at(_cnt);
 845   Compile::current()->record_modified_node(this);
 846 }
 847 
 848 //------------------------------del_req_ordered--------------------------------
 849 // Delete the required edge and compact the edge array with preserved order
 850 void Node::del_req_ordered( uint idx ) {
 851   assert( idx < _cnt, "oob");
 852   assert( !VerifyHashTableKeys || _hash_lock == 0,
 853           "remove node from hash table before modifying it");
 854   // First remove corresponding def-use edge
 855   Node *n = in(idx);
 856   if (n != NULL) n->del_out((Node *)this);
 857   if (idx < --_cnt) {    // Not last edge ?
 858     Copy::conjoint_words_to_lower((HeapWord*)&_in[idx+1], (HeapWord*)&_in[idx], ((_cnt-idx)*sizeof(Node*)));
 859   }
 860   // Avoid spec violation: Gap in prec edges.
 861   close_prec_gap_at(_cnt);
 862   Compile::current()->record_modified_node(this);
 863 }
 864 
 865 //------------------------------ins_req----------------------------------------
 866 // Insert a new required input at the end
 867 void Node::ins_req( uint idx, Node *n ) {
 868   assert( is_not_dead(n), "can not use dead node");
 869   add_req(NULL);                // Make space
 870   assert( idx < _max, "Must have allocated enough space");
 871   // Slide over
 872   if(_cnt-idx-1 > 0) {
 873     Copy::conjoint_words_to_higher((HeapWord*)&_in[idx], (HeapWord*)&_in[idx+1], ((_cnt-idx-1)*sizeof(Node*)));
 874   }
 875   _in[idx] = n;                            // Stuff over old required edge
 876   if (n != NULL) n->add_out((Node *)this); // Add reciprocal def-use edge
 877 }
 878 
 879 //-----------------------------find_edge---------------------------------------
 880 int Node::find_edge(Node* n) {
 881   for (uint i = 0; i < len(); i++) {
 882     if (_in[i] == n)  return i;
 883   }
 884   return -1;
 885 }
 886 
 887 //----------------------------replace_edge-------------------------------------
 888 int Node::replace_edge(Node* old, Node* neww, PhaseGVN* gvn) {
 889   if (old == neww)  return 0;  // nothing to do
 890   uint nrep = 0;
 891   for (uint i = 0; i < len(); i++) {
 892     if (in(i) == old) {
 893       if (i < req()) {
 894         if (gvn != NULL) {
 895           set_req_X(i, neww, gvn);
 896         } else {
 897           set_req(i, neww);
 898         }
 899       } else {
 900         assert(gvn == NULL || gvn->is_IterGVN() == NULL, "no support for igvn here");
 901         assert(find_prec_edge(neww) == -1, "spec violation: duplicated prec edge (node %d -> %d)", _idx, neww->_idx);
 902         set_prec(i, neww);
 903       }
 904       nrep++;
 905     }
 906   }
 907   return nrep;
 908 }
 909 
 910 /**
 911  * Replace input edges in the range pointing to 'old' node.
 912  */
 913 int Node::replace_edges_in_range(Node* old, Node* neww, int start, int end, PhaseGVN* gvn) {
 914   if (old == neww)  return 0;  // nothing to do
 915   uint nrep = 0;
 916   for (int i = start; i < end; i++) {
 917     if (in(i) == old) {
 918       set_req_X(i, neww, gvn);
 919       nrep++;
 920     }
 921   }
 922   return nrep;
 923 }
 924 
 925 //-------------------------disconnect_inputs-----------------------------------
 926 // NULL out all inputs to eliminate incoming Def-Use edges.
 927 void Node::disconnect_inputs(Compile* C) {
 928   // the layout of Node::_in
 929   // r: a required input, null is allowed
 930   // p: a precedence, null values are all at the end
 931   // -----------------------------------
 932   // |r|...|r|p|...|p|null|...|null|
 933   //         |                     |
 934   //         req()                 len()
 935   // -----------------------------------
 936   for (uint i = 0; i < req(); ++i) {
 937     if (in(i) != nullptr) {
 938       set_req(i, nullptr);
 939     }
 940   }
 941 
 942   // Remove precedence edges if any exist
 943   // Note: Safepoints may have precedence edges, even during parsing
 944   for (uint i = len(); i > req(); ) {
 945     rm_prec(--i);  // no-op if _in[i] is nullptr
 946   }
 947 
 948 #ifdef ASSERT
 949   // sanity check
 950   for (uint i = 0; i < len(); ++i) {
 951     assert(_in[i] == nullptr, "disconnect_inputs() failed!");
 952   }
 953 #endif
 954 
 955   // Node::destruct requires all out edges be deleted first
 956   // debug_only(destruct();)   // no reuse benefit expected
 957   C->record_dead_node(_idx);
 958 }
 959 
 960 //-----------------------------uncast---------------------------------------
 961 // %%% Temporary, until we sort out CheckCastPP vs. CastPP.
 962 // Strip away casting.  (It is depth-limited.)
 963 // Optionally, keep casts with dependencies.
 964 Node* Node::uncast(bool keep_deps) const {
 965   // Should be inline:
 966   //return is_ConstraintCast() ? uncast_helper(this) : (Node*) this;
 967   if (is_ConstraintCast()) {
 968     return uncast_helper(this, keep_deps);
 969   } else {
 970     return (Node*) this;
 971   }
 972 }
 973 
 974 // Find out of current node that matches opcode.
 975 Node* Node::find_out_with(int opcode) {
 976   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 977     Node* use = fast_out(i);
 978     if (use->Opcode() == opcode) {
 979       return use;
 980     }
 981   }
 982   return NULL;
 983 }
 984 
 985 // Return true if the current node has an out that matches opcode.
 986 bool Node::has_out_with(int opcode) {
 987   return (find_out_with(opcode) != NULL);
 988 }
 989 
 990 // Return true if the current node has an out that matches any of the opcodes.
 991 bool Node::has_out_with(int opcode1, int opcode2, int opcode3, int opcode4) {
 992   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 993       int opcode = fast_out(i)->Opcode();
 994       if (opcode == opcode1 || opcode == opcode2 || opcode == opcode3 || opcode == opcode4) {
 995         return true;
 996       }
 997   }
 998   return false;
 999 }
1000 
1001 
1002 //---------------------------uncast_helper-------------------------------------
1003 Node* Node::uncast_helper(const Node* p, bool keep_deps) {
1004 #ifdef ASSERT
1005   uint depth_count = 0;
1006   const Node* orig_p = p;
1007 #endif
1008 
1009   while (true) {
1010 #ifdef ASSERT
1011     if (depth_count >= K) {
1012       orig_p->dump(4);
1013       if (p != orig_p)
1014         p->dump(1);
1015     }
1016     assert(depth_count++ < K, "infinite loop in Node::uncast_helper");
1017 #endif
1018     if (p == NULL || p->req() != 2) {
1019       break;
1020     } else if (p->is_ConstraintCast()) {
1021       if (keep_deps && p->as_ConstraintCast()->carry_dependency()) {
1022         break; // stop at casts with dependencies
1023       }
1024       p = p->in(1);
1025     } else {
1026       break;
1027     }
1028   }
1029   return (Node*) p;
1030 }
1031 
1032 //------------------------------add_prec---------------------------------------
1033 // Add a new precedence input.  Precedence inputs are unordered, with
1034 // duplicates removed and NULLs packed down at the end.
1035 void Node::add_prec( Node *n ) {
1036   assert( is_not_dead(n), "can not use dead node");
1037 
1038   // Check for NULL at end
1039   if( _cnt >= _max || in(_max-1) )
1040     grow( _max+1 );
1041 
1042   // Find a precedence edge to move
1043   uint i = _cnt;
1044   while( in(i) != NULL ) {
1045     if (in(i) == n) return; // Avoid spec violation: duplicated prec edge.
1046     i++;
1047   }
1048   _in[i] = n;                                // Stuff prec edge over NULL
1049   if ( n != NULL) n->add_out((Node *)this);  // Add mirror edge
1050 
1051 #ifdef ASSERT
1052   while ((++i)<_max) { assert(_in[i] == NULL, "spec violation: Gap in prec edges (node %d)", _idx); }
1053 #endif
1054 }
1055 
1056 //------------------------------rm_prec----------------------------------------
1057 // Remove a precedence input.  Precedence inputs are unordered, with
1058 // duplicates removed and NULLs packed down at the end.
1059 void Node::rm_prec( uint j ) {
1060   assert(j < _max, "oob: i=%d, _max=%d", j, _max);
1061   assert(j >= _cnt, "not a precedence edge");
1062   if (_in[j] == NULL) return;   // Avoid spec violation: Gap in prec edges.
1063   _in[j]->del_out((Node *)this);
1064   close_prec_gap_at(j);
1065 }
1066 
1067 //------------------------------size_of----------------------------------------
1068 uint Node::size_of() const { return sizeof(*this); }
1069 
1070 //------------------------------ideal_reg--------------------------------------
1071 uint Node::ideal_reg() const { return 0; }
1072 
1073 //------------------------------jvms-------------------------------------------
1074 JVMState* Node::jvms() const { return NULL; }
1075 
1076 #ifdef ASSERT
1077 //------------------------------jvms-------------------------------------------
1078 bool Node::verify_jvms(const JVMState* using_jvms) const {
1079   for (JVMState* jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1080     if (jvms == using_jvms)  return true;
1081   }
1082   return false;
1083 }
1084 
1085 //------------------------------init_NodeProperty------------------------------
1086 void Node::init_NodeProperty() {
1087   assert(_max_classes <= max_juint, "too many NodeProperty classes");
1088   assert(max_flags() <= max_juint, "too many NodeProperty flags");
1089 }
1090 
1091 //-----------------------------max_flags---------------------------------------
1092 juint Node::max_flags() {
1093   return (PD::_last_flag << 1) - 1; // allow flags combination
1094 }
1095 #endif
1096 
1097 //------------------------------format-----------------------------------------
1098 // Print as assembly
1099 void Node::format( PhaseRegAlloc *, outputStream *st ) const {}
1100 //------------------------------emit-------------------------------------------
1101 // Emit bytes starting at parameter 'ptr'.
1102 void Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {}
1103 //------------------------------size-------------------------------------------
1104 // Size of instruction in bytes
1105 uint Node::size(PhaseRegAlloc *ra_) const { return 0; }
1106 
1107 //------------------------------CFG Construction-------------------------------
1108 // Nodes that end basic blocks, e.g. IfTrue/IfFalse, JumpProjNode, Root,
1109 // Goto and Return.
1110 const Node *Node::is_block_proj() const { return 0; }
1111 
1112 // Minimum guaranteed type
1113 const Type *Node::bottom_type() const { return Type::BOTTOM; }
1114 
1115 
1116 //------------------------------raise_bottom_type------------------------------
1117 // Get the worst-case Type output for this Node.
1118 void Node::raise_bottom_type(const Type* new_type) {
1119   if (is_Type()) {
1120     TypeNode *n = this->as_Type();
1121     if (VerifyAliases) {
1122       assert(new_type->higher_equal_speculative(n->type()), "new type must refine old type");
1123     }
1124     n->set_type(new_type);
1125   } else if (is_Load()) {
1126     LoadNode *n = this->as_Load();
1127     if (VerifyAliases) {
1128       assert(new_type->higher_equal_speculative(n->type()), "new type must refine old type");
1129     }
1130     n->set_type(new_type);
1131   }
1132 }
1133 
1134 //------------------------------Identity---------------------------------------
1135 // Return a node that the given node is equivalent to.
1136 Node* Node::Identity(PhaseGVN* phase) {
1137   return this;                  // Default to no identities
1138 }
1139 
1140 //------------------------------Value------------------------------------------
1141 // Compute a new Type for a node using the Type of the inputs.
1142 const Type* Node::Value(PhaseGVN* phase) const {
1143   return bottom_type();         // Default to worst-case Type
1144 }
1145 
1146 //------------------------------Ideal------------------------------------------
1147 //
1148 // 'Idealize' the graph rooted at this Node.
1149 //
1150 // In order to be efficient and flexible there are some subtle invariants
1151 // these Ideal calls need to hold.  Running with '+VerifyIterativeGVN' checks
1152 // these invariants, although its too slow to have on by default.  If you are
1153 // hacking an Ideal call, be sure to test with +VerifyIterativeGVN!
1154 //
1155 // The Ideal call almost arbitrarily reshape the graph rooted at the 'this'
1156 // pointer.  If ANY change is made, it must return the root of the reshaped
1157 // graph - even if the root is the same Node.  Example: swapping the inputs
1158 // to an AddINode gives the same answer and same root, but you still have to
1159 // return the 'this' pointer instead of NULL.
1160 //
1161 // You cannot return an OLD Node, except for the 'this' pointer.  Use the
1162 // Identity call to return an old Node; basically if Identity can find
1163 // another Node have the Ideal call make no change and return NULL.
1164 // Example: AddINode::Ideal must check for add of zero; in this case it
1165 // returns NULL instead of doing any graph reshaping.
1166 //
1167 // You cannot modify any old Nodes except for the 'this' pointer.  Due to
1168 // sharing there may be other users of the old Nodes relying on their current
1169 // semantics.  Modifying them will break the other users.
1170 // Example: when reshape "(X+3)+4" into "X+7" you must leave the Node for
1171 // "X+3" unchanged in case it is shared.
1172 //
1173 // If you modify the 'this' pointer's inputs, you should use
1174 // 'set_req'.  If you are making a new Node (either as the new root or
1175 // some new internal piece) you may use 'init_req' to set the initial
1176 // value.  You can make a new Node with either 'new' or 'clone'.  In
1177 // either case, def-use info is correctly maintained.
1178 //
1179 // Example: reshape "(X+3)+4" into "X+7":
1180 //    set_req(1, in(1)->in(1));
1181 //    set_req(2, phase->intcon(7));
1182 //    return this;
1183 // Example: reshape "X*4" into "X<<2"
1184 //    return new LShiftINode(in(1), phase->intcon(2));
1185 //
1186 // You must call 'phase->transform(X)' on any new Nodes X you make, except
1187 // for the returned root node.  Example: reshape "X*31" with "(X<<5)-X".
1188 //    Node *shift=phase->transform(new LShiftINode(in(1),phase->intcon(5)));
1189 //    return new AddINode(shift, in(1));
1190 //
1191 // When making a Node for a constant use 'phase->makecon' or 'phase->intcon'.
1192 // These forms are faster than 'phase->transform(new ConNode())' and Do
1193 // The Right Thing with def-use info.
1194 //
1195 // You cannot bury the 'this' Node inside of a graph reshape.  If the reshaped
1196 // graph uses the 'this' Node it must be the root.  If you want a Node with
1197 // the same Opcode as the 'this' pointer use 'clone'.
1198 //
1199 Node *Node::Ideal(PhaseGVN *phase, bool can_reshape) {
1200   return NULL;                  // Default to being Ideal already
1201 }
1202 
1203 // Some nodes have specific Ideal subgraph transformations only if they are
1204 // unique users of specific nodes. Such nodes should be put on IGVN worklist
1205 // for the transformations to happen.
1206 bool Node::has_special_unique_user() const {
1207   assert(outcnt() == 1, "match only for unique out");
1208   Node* n = unique_out();
1209   int op  = Opcode();
1210   if (this->is_Store()) {
1211     // Condition for back-to-back stores folding.
1212     return n->Opcode() == op && n->in(MemNode::Memory) == this;
1213   } else if (this->is_Load() || this->is_DecodeN() || this->is_Phi()) {
1214     // Condition for removing an unused LoadNode or DecodeNNode from the MemBarAcquire precedence input
1215     return n->Opcode() == Op_MemBarAcquire;
1216   } else if (op == Op_AddL) {
1217     // Condition for convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
1218     return n->Opcode() == Op_ConvL2I && n->in(1) == this;
1219   } else if (op == Op_SubI || op == Op_SubL) {
1220     // Condition for subI(x,subI(y,z)) ==> subI(addI(x,z),y)
1221     return n->Opcode() == op && n->in(2) == this;
1222   } else if (is_If() && (n->is_IfFalse() || n->is_IfTrue())) {
1223     // See IfProjNode::Identity()
1224     return true;
1225   } else {
1226     return false;
1227   }
1228 };
1229 
1230 //--------------------------find_exact_control---------------------------------
1231 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1232 Node* Node::find_exact_control(Node* ctrl) {
1233   if (ctrl == NULL && this->is_Region())
1234     ctrl = this->as_Region()->is_copy();
1235 
1236   if (ctrl != NULL && ctrl->is_CatchProj()) {
1237     if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1238       ctrl = ctrl->in(0);
1239     if (ctrl != NULL && !ctrl->is_top())
1240       ctrl = ctrl->in(0);
1241   }
1242 
1243   if (ctrl != NULL && ctrl->is_Proj())
1244     ctrl = ctrl->in(0);
1245 
1246   return ctrl;
1247 }
1248 
1249 //--------------------------dominates------------------------------------------
1250 // Helper function for MemNode::all_controls_dominate().
1251 // Check if 'this' control node dominates or equal to 'sub' control node.
1252 // We already know that if any path back to Root or Start reaches 'this',
1253 // then all paths so, so this is a simple search for one example,
1254 // not an exhaustive search for a counterexample.
1255 bool Node::dominates(Node* sub, Node_List &nlist) {
1256   assert(this->is_CFG(), "expecting control");
1257   assert(sub != NULL && sub->is_CFG(), "expecting control");
1258 
1259   // detect dead cycle without regions
1260   int iterations_without_region_limit = DominatorSearchLimit;
1261 
1262   Node* orig_sub = sub;
1263   Node* dom      = this;
1264   bool  met_dom  = false;
1265   nlist.clear();
1266 
1267   // Walk 'sub' backward up the chain to 'dom', watching for regions.
1268   // After seeing 'dom', continue up to Root or Start.
1269   // If we hit a region (backward split point), it may be a loop head.
1270   // Keep going through one of the region's inputs.  If we reach the
1271   // same region again, go through a different input.  Eventually we
1272   // will either exit through the loop head, or give up.
1273   // (If we get confused, break out and return a conservative 'false'.)
1274   while (sub != NULL) {
1275     if (sub->is_top())  break; // Conservative answer for dead code.
1276     if (sub == dom) {
1277       if (nlist.size() == 0) {
1278         // No Region nodes except loops were visited before and the EntryControl
1279         // path was taken for loops: it did not walk in a cycle.
1280         return true;
1281       } else if (met_dom) {
1282         break;          // already met before: walk in a cycle
1283       } else {
1284         // Region nodes were visited. Continue walk up to Start or Root
1285         // to make sure that it did not walk in a cycle.
1286         met_dom = true; // first time meet
1287         iterations_without_region_limit = DominatorSearchLimit; // Reset
1288      }
1289     }
1290     if (sub->is_Start() || sub->is_Root()) {
1291       // Success if we met 'dom' along a path to Start or Root.
1292       // We assume there are no alternative paths that avoid 'dom'.
1293       // (This assumption is up to the caller to ensure!)
1294       return met_dom;
1295     }
1296     Node* up = sub->in(0);
1297     // Normalize simple pass-through regions and projections:
1298     up = sub->find_exact_control(up);
1299     // If sub == up, we found a self-loop.  Try to push past it.
1300     if (sub == up && sub->is_Loop()) {
1301       // Take loop entry path on the way up to 'dom'.
1302       up = sub->in(1); // in(LoopNode::EntryControl);
1303     } else if (sub == up && sub->is_Region() && sub->req() == 2) {
1304       // Take in(1) path on the way up to 'dom' for regions with only one input
1305       up = sub->in(1);
1306     } else if (sub == up && sub->is_Region() && sub->req() == 3) {
1307       // Try both paths for Regions with 2 input paths (it may be a loop head).
1308       // It could give conservative 'false' answer without information
1309       // which region's input is the entry path.
1310       iterations_without_region_limit = DominatorSearchLimit; // Reset
1311 
1312       bool region_was_visited_before = false;
1313       // Was this Region node visited before?
1314       // If so, we have reached it because we accidentally took a
1315       // loop-back edge from 'sub' back into the body of the loop,
1316       // and worked our way up again to the loop header 'sub'.
1317       // So, take the first unexplored path on the way up to 'dom'.
1318       for (int j = nlist.size() - 1; j >= 0; j--) {
1319         intptr_t ni = (intptr_t)nlist.at(j);
1320         Node* visited = (Node*)(ni & ~1);
1321         bool  visited_twice_already = ((ni & 1) != 0);
1322         if (visited == sub) {
1323           if (visited_twice_already) {
1324             // Visited 2 paths, but still stuck in loop body.  Give up.
1325             return false;
1326           }
1327           // The Region node was visited before only once.
1328           // (We will repush with the low bit set, below.)
1329           nlist.remove(j);
1330           // We will find a new edge and re-insert.
1331           region_was_visited_before = true;
1332           break;
1333         }
1334       }
1335 
1336       // Find an incoming edge which has not been seen yet; walk through it.
1337       assert(up == sub, "");
1338       uint skip = region_was_visited_before ? 1 : 0;
1339       for (uint i = 1; i < sub->req(); i++) {
1340         Node* in = sub->in(i);
1341         if (in != NULL && !in->is_top() && in != sub) {
1342           if (skip == 0) {
1343             up = in;
1344             break;
1345           }
1346           --skip;               // skip this nontrivial input
1347         }
1348       }
1349 
1350       // Set 0 bit to indicate that both paths were taken.
1351       nlist.push((Node*)((intptr_t)sub + (region_was_visited_before ? 1 : 0)));
1352     }
1353 
1354     if (up == sub) {
1355       break;    // some kind of tight cycle
1356     }
1357     if (up == orig_sub && met_dom) {
1358       // returned back after visiting 'dom'
1359       break;    // some kind of cycle
1360     }
1361     if (--iterations_without_region_limit < 0) {
1362       break;    // dead cycle
1363     }
1364     sub = up;
1365   }
1366 
1367   // Did not meet Root or Start node in pred. chain.
1368   // Conservative answer for dead code.
1369   return false;
1370 }
1371 
1372 //------------------------------remove_dead_region-----------------------------
1373 // This control node is dead.  Follow the subgraph below it making everything
1374 // using it dead as well.  This will happen normally via the usual IterGVN
1375 // worklist but this call is more efficient.  Do not update use-def info
1376 // inside the dead region, just at the borders.
1377 static void kill_dead_code( Node *dead, PhaseIterGVN *igvn ) {
1378   // Con's are a popular node to re-hit in the hash table again.
1379   if( dead->is_Con() ) return;
1380 
1381   ResourceMark rm;
1382   Node_List nstack;
1383 
1384   Node *top = igvn->C->top();
1385   nstack.push(dead);
1386   bool has_irreducible_loop = igvn->C->has_irreducible_loop();
1387 
1388   while (nstack.size() > 0) {
1389     dead = nstack.pop();
1390     if (dead->Opcode() == Op_SafePoint) {
1391       dead->as_SafePoint()->disconnect_from_root(igvn);
1392     }
1393     if (dead->outcnt() > 0) {
1394       // Keep dead node on stack until all uses are processed.
1395       nstack.push(dead);
1396       // For all Users of the Dead...    ;-)
1397       for (DUIterator_Last kmin, k = dead->last_outs(kmin); k >= kmin; ) {
1398         Node* use = dead->last_out(k);
1399         igvn->hash_delete(use);       // Yank from hash table prior to mod
1400         if (use->in(0) == dead) {     // Found another dead node
1401           assert (!use->is_Con(), "Control for Con node should be Root node.");
1402           use->set_req(0, top);       // Cut dead edge to prevent processing
1403           nstack.push(use);           // the dead node again.
1404         } else if (!has_irreducible_loop && // Backedge could be alive in irreducible loop
1405                    use->is_Loop() && !use->is_Root() &&       // Don't kill Root (RootNode extends LoopNode)
1406                    use->in(LoopNode::EntryControl) == dead) { // Dead loop if its entry is dead
1407           use->set_req(LoopNode::EntryControl, top);          // Cut dead edge to prevent processing
1408           use->set_req(0, top);       // Cut self edge
1409           nstack.push(use);
1410         } else {                      // Else found a not-dead user
1411           // Dead if all inputs are top or null
1412           bool dead_use = !use->is_Root(); // Keep empty graph alive
1413           for (uint j = 1; j < use->req(); j++) {
1414             Node* in = use->in(j);
1415             if (in == dead) {         // Turn all dead inputs into TOP
1416               use->set_req(j, top);
1417             } else if (in != NULL && !in->is_top()) {
1418               dead_use = false;
1419             }
1420           }
1421           if (dead_use) {
1422             if (use->is_Region()) {
1423               use->set_req(0, top);   // Cut self edge
1424             }
1425             nstack.push(use);
1426           } else {
1427             igvn->_worklist.push(use);
1428           }
1429         }
1430         // Refresh the iterator, since any number of kills might have happened.
1431         k = dead->last_outs(kmin);
1432       }
1433     } else { // (dead->outcnt() == 0)
1434       // Done with outputs.
1435       igvn->hash_delete(dead);
1436       igvn->_worklist.remove(dead);
1437       igvn->set_type(dead, Type::TOP);
1438       // Kill all inputs to the dead guy
1439       for (uint i=0; i < dead->req(); i++) {
1440         Node *n = dead->in(i);      // Get input to dead guy
1441         if (n != NULL && !n->is_top()) { // Input is valid?
1442           dead->set_req(i, top);    // Smash input away
1443           if (n->outcnt() == 0) {   // Input also goes dead?
1444             if (!n->is_Con())
1445               nstack.push(n);       // Clear it out as well
1446           } else if (n->outcnt() == 1 &&
1447                      n->has_special_unique_user()) {
1448             igvn->add_users_to_worklist( n );
1449           } else if (n->outcnt() <= 2 && n->is_Store()) {
1450             // Push store's uses on worklist to enable folding optimization for
1451             // store/store and store/load to the same address.
1452             // The restriction (outcnt() <= 2) is the same as in set_req_X()
1453             // and remove_globally_dead_node().
1454             igvn->add_users_to_worklist( n );
1455           } else {
1456             BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(igvn, n);
1457           }
1458         }
1459       }
1460       igvn->C->remove_useless_node(dead);
1461     } // (dead->outcnt() == 0)
1462   }   // while (nstack.size() > 0) for outputs
1463   return;
1464 }
1465 
1466 //------------------------------remove_dead_region-----------------------------
1467 bool Node::remove_dead_region(PhaseGVN *phase, bool can_reshape) {
1468   Node *n = in(0);
1469   if( !n ) return false;
1470   // Lost control into this guy?  I.e., it became unreachable?
1471   // Aggressively kill all unreachable code.
1472   if (can_reshape && n->is_top()) {
1473     kill_dead_code(this, phase->is_IterGVN());
1474     return false; // Node is dead.
1475   }
1476 
1477   if( n->is_Region() && n->as_Region()->is_copy() ) {
1478     Node *m = n->nonnull_req();
1479     set_req(0, m);
1480     return true;
1481   }
1482   return false;
1483 }
1484 
1485 //------------------------------hash-------------------------------------------
1486 // Hash function over Nodes.
1487 uint Node::hash() const {
1488   uint sum = 0;
1489   for( uint i=0; i<_cnt; i++ )  // Add in all inputs
1490     sum = (sum<<1)-(uintptr_t)in(i);        // Ignore embedded NULLs
1491   return (sum>>2) + _cnt + Opcode();
1492 }
1493 
1494 //------------------------------cmp--------------------------------------------
1495 // Compare special parts of simple Nodes
1496 bool Node::cmp( const Node &n ) const {
1497   return true;                  // Must be same
1498 }
1499 
1500 //------------------------------rematerialize-----------------------------------
1501 // Should we clone rather than spill this instruction?
1502 bool Node::rematerialize() const {
1503   if ( is_Mach() )
1504     return this->as_Mach()->rematerialize();
1505   else
1506     return (_flags & Flag_rematerialize) != 0;
1507 }
1508 
1509 //------------------------------needs_anti_dependence_check---------------------
1510 // Nodes which use memory without consuming it, hence need antidependences.
1511 bool Node::needs_anti_dependence_check() const {
1512   if (req() < 2 || (_flags & Flag_needs_anti_dependence_check) == 0) {
1513     return false;
1514   }
1515   return in(1)->bottom_type()->has_memory();
1516 }
1517 
1518 // Get an integer constant from a ConNode (or CastIINode).
1519 // Return a default value if there is no apparent constant here.
1520 const TypeInt* Node::find_int_type() const {
1521   if (this->is_Type()) {
1522     return this->as_Type()->type()->isa_int();
1523   } else if (this->is_Con()) {
1524     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1525     return this->bottom_type()->isa_int();
1526   }
1527   return NULL;
1528 }
1529 
1530 const TypeInteger* Node::find_integer_type(BasicType bt) const {
1531   if (this->is_Type()) {
1532     return this->as_Type()->type()->isa_integer(bt);
1533   } else if (this->is_Con()) {
1534     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1535     return this->bottom_type()->isa_integer(bt);
1536   }
1537   return NULL;
1538 }
1539 
1540 // Get a pointer constant from a ConstNode.
1541 // Returns the constant if it is a pointer ConstNode
1542 intptr_t Node::get_ptr() const {
1543   assert( Opcode() == Op_ConP, "" );
1544   return ((ConPNode*)this)->type()->is_ptr()->get_con();
1545 }
1546 
1547 // Get a narrow oop constant from a ConNNode.
1548 intptr_t Node::get_narrowcon() const {
1549   assert( Opcode() == Op_ConN, "" );
1550   return ((ConNNode*)this)->type()->is_narrowoop()->get_con();
1551 }
1552 
1553 // Get a long constant from a ConNode.
1554 // Return a default value if there is no apparent constant here.
1555 const TypeLong* Node::find_long_type() const {
1556   if (this->is_Type()) {
1557     return this->as_Type()->type()->isa_long();
1558   } else if (this->is_Con()) {
1559     assert(is_Mach(), "should be ConNode(TypeNode) or else a MachNode");
1560     return this->bottom_type()->isa_long();
1561   }
1562   return NULL;
1563 }
1564 
1565 
1566 /**
1567  * Return a ptr type for nodes which should have it.
1568  */
1569 const TypePtr* Node::get_ptr_type() const {
1570   const TypePtr* tp = this->bottom_type()->make_ptr();
1571 #ifdef ASSERT
1572   if (tp == NULL) {
1573     this->dump(1);
1574     assert((tp != NULL), "unexpected node type");
1575   }
1576 #endif
1577   return tp;
1578 }
1579 
1580 // Get a double constant from a ConstNode.
1581 // Returns the constant if it is a double ConstNode
1582 jdouble Node::getd() const {
1583   assert( Opcode() == Op_ConD, "" );
1584   return ((ConDNode*)this)->type()->is_double_constant()->getd();
1585 }
1586 
1587 // Get a float constant from a ConstNode.
1588 // Returns the constant if it is a float ConstNode
1589 jfloat Node::getf() const {
1590   assert( Opcode() == Op_ConF, "" );
1591   return ((ConFNode*)this)->type()->is_float_constant()->getf();
1592 }
1593 
1594 #ifndef PRODUCT
1595 
1596 // Call this from debugger:
1597 Node* find_node(Node* n, const int idx) {
1598   return n->find(idx);
1599 }
1600 
1601 // Call this from debugger with root node as default:
1602 Node* find_node(const int idx) {
1603   return Compile::current()->root()->find(idx);
1604 }
1605 
1606 // Call this from debugger:
1607 Node* find_ctrl(Node* n, const int idx) {
1608   return n->find_ctrl(idx);
1609 }
1610 
1611 // Call this from debugger with root node as default:
1612 Node* find_ctrl(const int idx) {
1613   return Compile::current()->root()->find_ctrl(idx);
1614 }
1615 
1616 //------------------------------find_ctrl--------------------------------------
1617 // Find an ancestor to this node in the control history with given _idx
1618 Node* Node::find_ctrl(int idx) {
1619   return find(idx, true);
1620 }
1621 
1622 //------------------------------find-------------------------------------------
1623 // Tries to find the node with the index |idx| starting from this node. If idx is negative,
1624 // the search also includes forward (out) edges. Returns NULL if not found.
1625 // If only_ctrl is set, the search will only be done on control nodes. Returns NULL if
1626 // not found or if the node to be found is not a control node (search will not find it).
1627 Node* Node::find(const int idx, bool only_ctrl) {
1628   ResourceMark rm;
1629   VectorSet old_space;
1630   VectorSet new_space;
1631   Node_List worklist;
1632   Arena* old_arena = Compile::current()->old_arena();
1633   add_to_worklist(this, &worklist, old_arena, &old_space, &new_space);
1634   Node* result = NULL;
1635   int node_idx = (idx >= 0) ? idx : -idx;
1636 
1637   for (uint list_index = 0; list_index < worklist.size(); list_index++) {
1638     Node* n = worklist[list_index];
1639 
1640     if ((int)n->_idx == node_idx debug_only(|| n->debug_idx() == node_idx)) {
1641       if (result != NULL) {
1642         tty->print("find: " INTPTR_FORMAT " and " INTPTR_FORMAT " both have idx==%d\n",
1643                   (uintptr_t)result, (uintptr_t)n, node_idx);
1644       }
1645       result = n;
1646     }
1647 
1648     for (uint i = 0; i < n->len(); i++) {
1649       if (!only_ctrl || n->is_Region() || (n->Opcode() == Op_Root) || (i == TypeFunc::Control)) {
1650         // If only_ctrl is set: Add regions, the root node, or control inputs only
1651         add_to_worklist(n->in(i), &worklist, old_arena, &old_space, &new_space);
1652       }
1653     }
1654 
1655     // Also search along forward edges if idx is negative and the search is not done on control nodes only
1656     if (idx < 0 && !only_ctrl) {
1657       for (uint i = 0; i < n->outcnt(); i++) {
1658         add_to_worklist(n->raw_out(i), &worklist, old_arena, &old_space, &new_space);
1659       }
1660     }
1661 #ifdef ASSERT
1662     // Search along debug_orig edges last
1663     Node* orig = n->debug_orig();
1664     while (orig != NULL && add_to_worklist(orig, &worklist, old_arena, &old_space, &new_space)) {
1665       orig = orig->debug_orig();
1666     }
1667 #endif // ASSERT
1668   }
1669   return result;
1670 }
1671 
1672 bool Node::add_to_worklist(Node* n, Node_List* worklist, Arena* old_arena, VectorSet* old_space, VectorSet* new_space) {
1673   if (not_a_node(n)) {
1674     return false; // Gracefully handle NULL, -1, 0xabababab, etc.
1675   }
1676 
1677   // Contained in new_space or old_space? Check old_arena first since it's mostly empty.
1678   VectorSet* v = old_arena->contains(n) ? old_space : new_space;
1679   if (!v->test_set(n->_idx)) {
1680     worklist->push(n);
1681     return true;
1682   }
1683   return false;
1684 }
1685 
1686 // -----------------------------Name-------------------------------------------
1687 extern const char *NodeClassNames[];
1688 const char *Node::Name() const { return NodeClassNames[Opcode()]; }
1689 
1690 static bool is_disconnected(const Node* n) {
1691   for (uint i = 0; i < n->req(); i++) {
1692     if (n->in(i) != NULL)  return false;
1693   }
1694   return true;
1695 }
1696 
1697 #ifdef ASSERT
1698 void Node::dump_orig(outputStream *st, bool print_key) const {
1699   Compile* C = Compile::current();
1700   Node* orig = _debug_orig;
1701   if (not_a_node(orig)) orig = NULL;
1702   if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL;
1703   if (orig == NULL) return;
1704   if (print_key) {
1705     st->print(" !orig=");
1706   }
1707   Node* fast = orig->debug_orig(); // tortoise & hare algorithm to detect loops
1708   if (not_a_node(fast)) fast = NULL;
1709   while (orig != NULL) {
1710     bool discon = is_disconnected(orig);  // if discon, print [123] else 123
1711     if (discon) st->print("[");
1712     if (!Compile::current()->node_arena()->contains(orig))
1713       st->print("o");
1714     st->print("%d", orig->_idx);
1715     if (discon) st->print("]");
1716     orig = orig->debug_orig();
1717     if (not_a_node(orig)) orig = NULL;
1718     if (orig != NULL && !C->node_arena()->contains(orig)) orig = NULL;
1719     if (orig != NULL) st->print(",");
1720     if (fast != NULL) {
1721       // Step fast twice for each single step of orig:
1722       fast = fast->debug_orig();
1723       if (not_a_node(fast)) fast = NULL;
1724       if (fast != NULL && fast != orig) {
1725         fast = fast->debug_orig();
1726         if (not_a_node(fast)) fast = NULL;
1727       }
1728       if (fast == orig) {
1729         st->print("...");
1730         break;
1731       }
1732     }
1733   }
1734 }
1735 
1736 void Node::set_debug_orig(Node* orig) {
1737   _debug_orig = orig;
1738   if (BreakAtNode == 0)  return;
1739   if (not_a_node(orig))  orig = NULL;
1740   int trip = 10;
1741   while (orig != NULL) {
1742     if (orig->debug_idx() == BreakAtNode || (int)orig->_idx == BreakAtNode) {
1743       tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d orig._idx=%d orig._debug_idx=%d",
1744                     this->_idx, this->debug_idx(), orig->_idx, orig->debug_idx());
1745       BREAKPOINT;
1746     }
1747     orig = orig->debug_orig();
1748     if (not_a_node(orig))  orig = NULL;
1749     if (trip-- <= 0)  break;
1750   }
1751 }
1752 #endif //ASSERT
1753 
1754 //------------------------------dump------------------------------------------
1755 // Dump a Node
1756 void Node::dump(const char* suffix, bool mark, outputStream *st) const {
1757   Compile* C = Compile::current();
1758   bool is_new = C->node_arena()->contains(this);
1759   C->_in_dump_cnt++;
1760 
1761   if (_indent > 0) {
1762     st->print("%*s", (_indent << 1), "  ");
1763   }
1764 
1765   st->print("%c%d%s%s  === ", is_new ? ' ' : 'o', _idx, mark ? " >" : "  ", Name());
1766 
1767   // Dump the required and precedence inputs
1768   dump_req(st);
1769   dump_prec(st);
1770   // Dump the outputs
1771   dump_out(st);
1772 
1773   if (is_disconnected(this)) {
1774 #ifdef ASSERT
1775     st->print("  [%d]",debug_idx());
1776     dump_orig(st);
1777 #endif
1778     st->cr();
1779     C->_in_dump_cnt--;
1780     return;                     // don't process dead nodes
1781   }
1782 
1783   if (C->clone_map().value(_idx) != 0) {
1784     C->clone_map().dump(_idx);
1785   }
1786   // Dump node-specific info
1787   dump_spec(st);
1788 #ifdef ASSERT
1789   // Dump the non-reset _debug_idx
1790   if (Verbose && WizardMode) {
1791     st->print("  [%d]",debug_idx());
1792   }
1793 #endif
1794 
1795   const Type *t = bottom_type();
1796 
1797   if (t != NULL && (t->isa_instptr() || t->isa_klassptr())) {
1798     const TypeInstPtr  *toop = t->isa_instptr();
1799     const TypeKlassPtr *tkls = t->isa_klassptr();
1800     ciKlass*           klass = toop ? toop->klass() : (tkls ? tkls->klass() : NULL );
1801     if (klass && klass->is_loaded() && klass->is_interface()) {
1802       st->print("  Interface:");
1803     } else if (toop) {
1804       st->print("  Oop:");
1805     } else if (tkls) {
1806       st->print("  Klass:");
1807     }
1808     t->dump_on(st);
1809   } else if (t == Type::MEMORY) {
1810     st->print("  Memory:");
1811     MemNode::dump_adr_type(this, adr_type(), st);
1812   } else if (Verbose || WizardMode) {
1813     st->print("  Type:");
1814     if (t) {
1815       t->dump_on(st);
1816     } else {
1817       st->print("no type");
1818     }
1819   } else if (t->isa_vect() && this->is_MachSpillCopy()) {
1820     // Dump MachSpillcopy vector type.
1821     t->dump_on(st);
1822   }
1823   if (is_new) {
1824     DEBUG_ONLY(dump_orig(st));
1825     Node_Notes* nn = C->node_notes_at(_idx);
1826     if (nn != NULL && !nn->is_clear()) {
1827       if (nn->jvms() != NULL) {
1828         st->print(" !jvms:");
1829         nn->jvms()->dump_spec(st);
1830       }
1831     }
1832   }
1833   if (suffix) st->print("%s", suffix);
1834   C->_in_dump_cnt--;
1835 }
1836 
1837 //------------------------------dump_req--------------------------------------
1838 void Node::dump_req(outputStream *st) const {
1839   // Dump the required input edges
1840   for (uint i = 0; i < req(); i++) {    // For all required inputs
1841     Node* d = in(i);
1842     if (d == NULL) {
1843       st->print("_ ");
1844     } else if (not_a_node(d)) {
1845       st->print("not_a_node ");  // uninitialized, sentinel, garbage, etc.
1846     } else {
1847       st->print("%c%d ", Compile::current()->node_arena()->contains(d) ? ' ' : 'o', d->_idx);
1848     }
1849   }
1850 }
1851 
1852 
1853 //------------------------------dump_prec-------------------------------------
1854 void Node::dump_prec(outputStream *st) const {
1855   // Dump the precedence edges
1856   int any_prec = 0;
1857   for (uint i = req(); i < len(); i++) {       // For all precedence inputs
1858     Node* p = in(i);
1859     if (p != NULL) {
1860       if (!any_prec++) st->print(" |");
1861       if (not_a_node(p)) { st->print("not_a_node "); continue; }
1862       st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
1863     }
1864   }
1865 }
1866 
1867 //------------------------------dump_out--------------------------------------
1868 void Node::dump_out(outputStream *st) const {
1869   // Delimit the output edges
1870   st->print(" [[");
1871   // Dump the output edges
1872   for (uint i = 0; i < _outcnt; i++) {    // For all outputs
1873     Node* u = _out[i];
1874     if (u == NULL) {
1875       st->print("_ ");
1876     } else if (not_a_node(u)) {
1877       st->print("not_a_node ");
1878     } else {
1879       st->print("%c%d ", Compile::current()->node_arena()->contains(u) ? ' ' : 'o', u->_idx);
1880     }
1881   }
1882   st->print("]] ");
1883 }
1884 
1885 //----------------------------collect_nodes_i----------------------------------
1886 // Collects nodes from an Ideal graph, starting from a given start node and
1887 // moving in a given direction until a certain depth (distance from the start
1888 // node) is reached. Duplicates are ignored.
1889 // Arguments:
1890 //   queue:         the nodes are collected into this array.
1891 //   start:         the node at which to start collecting.
1892 //   direction:     if this is a positive number, collect input nodes; if it is
1893 //                  a negative number, collect output nodes.
1894 //   depth:         collect nodes up to this distance from the start node.
1895 //   include_start: whether to include the start node in the result collection.
1896 //   only_ctrl:     whether to regard control edges only during traversal.
1897 //   only_data:     whether to regard data edges only during traversal.
1898 static void collect_nodes_i(GrowableArray<Node*>* queue, const Node* start, int direction, uint depth, bool include_start, bool only_ctrl, bool only_data) {
1899   bool indent = depth <= PrintIdealIndentThreshold;
1900   Node* s = (Node*) start; // remove const
1901   queue->append(s);
1902   int begin = 0;
1903   int end = 0;
1904 
1905   s->set_indent(0);
1906   for(uint i = 0; i < depth; i++) {
1907     end = queue->length();
1908     for(int j = begin; j < end; j++) {
1909       Node* tp  = queue->at(j);
1910       uint limit = direction > 0 ? tp->len() : tp->outcnt();
1911       for(uint k = 0; k < limit; k++) {
1912         Node* n = direction > 0 ? tp->in(k) : tp->raw_out(k);
1913 
1914         if (not_a_node(n))  continue;
1915         // do not recurse through top or the root (would reach unrelated stuff)
1916         if (n->is_Root() || n->is_top()) continue;
1917         if (only_ctrl && !n->is_CFG()) continue;
1918         if (only_data && n->is_CFG()) continue;
1919         bool in_queue = queue->contains(n);
1920         if (!in_queue) {
1921           queue->append(n);
1922           n->set_indent(indent ? (i + 1) : 0);
1923         }
1924       }
1925     }
1926     begin = end;
1927   }
1928   if (!include_start) {
1929     queue->remove(s);
1930   }
1931 }
1932 
1933 //------------------------------dump_nodes-------------------------------------
1934 static void dump_nodes(const Node* start, int d, bool only_ctrl) {
1935   if (not_a_node(start)) return;
1936 
1937   GrowableArray <Node *> queue(Compile::current()->live_nodes());
1938   collect_nodes_i(&queue, start, d, (uint) ABS(d), true, only_ctrl, false);
1939 
1940   int end = queue.length();
1941   if (d > 0) {
1942     for(int j = end-1; j >= 0; j--) {
1943       queue.at(j)->dump();
1944     }
1945   } else {
1946     for(int j = 0; j < end; j++) {
1947       queue.at(j)->dump();
1948     }
1949   }
1950 }
1951 
1952 //------------------------------dump-------------------------------------------
1953 void Node::dump(int d) const {
1954   dump_nodes(this, d, false);
1955 }
1956 
1957 //------------------------------dump_ctrl--------------------------------------
1958 // Dump a Node's control history to depth
1959 void Node::dump_ctrl(int d) const {
1960   dump_nodes(this, d, true);
1961 }
1962 
1963 //-----------------------------dump_compact------------------------------------
1964 void Node::dump_comp() const {
1965   this->dump_comp("\n");
1966 }
1967 
1968 //-----------------------------dump_compact------------------------------------
1969 // Dump a Node in compact representation, i.e., just print its name and index.
1970 // Nodes can specify additional specifics to print in compact representation by
1971 // implementing dump_compact_spec.
1972 void Node::dump_comp(const char* suffix, outputStream *st) const {
1973   Compile* C = Compile::current();
1974   C->_in_dump_cnt++;
1975   st->print("%s(%d)", Name(), _idx);
1976   this->dump_compact_spec(st);
1977   if (suffix) {
1978     st->print("%s", suffix);
1979   }
1980   C->_in_dump_cnt--;
1981 }
1982 
1983 //----------------------------dump_related-------------------------------------
1984 // Dump a Node's related nodes - the notion of "related" depends on the Node at
1985 // hand and is determined by the implementation of the virtual method rel.
1986 void Node::dump_related() const {
1987   Compile* C = Compile::current();
1988   GrowableArray <Node *> in_rel(C->unique());
1989   GrowableArray <Node *> out_rel(C->unique());
1990   this->related(&in_rel, &out_rel, false);
1991   for (int i = in_rel.length() - 1; i >= 0; i--) {
1992     in_rel.at(i)->dump();
1993   }
1994   this->dump("\n", true);
1995   for (int i = 0; i < out_rel.length(); i++) {
1996     out_rel.at(i)->dump();
1997   }
1998 }
1999 
2000 //----------------------------dump_related-------------------------------------
2001 // Dump a Node's related nodes up to a given depth (distance from the start
2002 // node).
2003 // Arguments:
2004 //   d_in:  depth for input nodes.
2005 //   d_out: depth for output nodes (note: this also is a positive number).
2006 void Node::dump_related(uint d_in, uint d_out) const {
2007   Compile* C = Compile::current();
2008   GrowableArray <Node *> in_rel(C->unique());
2009   GrowableArray <Node *> out_rel(C->unique());
2010 
2011   // call collect_nodes_i directly
2012   collect_nodes_i(&in_rel, this, 1, d_in, false, false, false);
2013   collect_nodes_i(&out_rel, this, -1, d_out, false, false, false);
2014 
2015   for (int i = in_rel.length() - 1; i >= 0; i--) {
2016     in_rel.at(i)->dump();
2017   }
2018   this->dump("\n", true);
2019   for (int i = 0; i < out_rel.length(); i++) {
2020     out_rel.at(i)->dump();
2021   }
2022 }
2023 
2024 //------------------------dump_related_compact---------------------------------
2025 // Dump a Node's related nodes in compact representation. The notion of
2026 // "related" depends on the Node at hand and is determined by the implementation
2027 // of the virtual method rel.
2028 void Node::dump_related_compact() const {
2029   Compile* C = Compile::current();
2030   GrowableArray <Node *> in_rel(C->unique());
2031   GrowableArray <Node *> out_rel(C->unique());
2032   this->related(&in_rel, &out_rel, true);
2033   int n_in = in_rel.length();
2034   int n_out = out_rel.length();
2035 
2036   this->dump_comp(n_in == 0 ? "\n" : "  ");
2037   for (int i = 0; i < n_in; i++) {
2038     in_rel.at(i)->dump_comp(i == n_in - 1 ? "\n" : "  ");
2039   }
2040   for (int i = 0; i < n_out; i++) {
2041     out_rel.at(i)->dump_comp(i == n_out - 1 ? "\n" : "  ");
2042   }
2043 }
2044 
2045 //------------------------------related----------------------------------------
2046 // Collect a Node's related nodes. The default behaviour just collects the
2047 // inputs and outputs at depth 1, including both control and data flow edges,
2048 // regardless of whether the presentation is compact or not. For data nodes,
2049 // the default is to collect all data inputs (till level 1 if compact), and
2050 // outputs till level 1.
2051 void Node::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2052   if (this->is_CFG()) {
2053     collect_nodes_i(in_rel, this, 1, 1, false, false, false);
2054     collect_nodes_i(out_rel, this, -1, 1, false, false, false);
2055   } else {
2056     if (compact) {
2057       this->collect_nodes(in_rel, 1, false, true);
2058     } else {
2059       this->collect_nodes_in_all_data(in_rel, false);
2060     }
2061     this->collect_nodes(out_rel, -1, false, false);
2062   }
2063 }
2064 
2065 //---------------------------collect_nodes-------------------------------------
2066 // An entry point to the low-level node collection facility, to start from a
2067 // given node in the graph. The start node is by default not included in the
2068 // result.
2069 // Arguments:
2070 //   ns:   collect the nodes into this data structure.
2071 //   d:    the depth (distance from start node) to which nodes should be
2072 //         collected. A value >0 indicates input nodes, a value <0, output
2073 //         nodes.
2074 //   ctrl: include only control nodes.
2075 //   data: include only data nodes.
2076 void Node::collect_nodes(GrowableArray<Node*> *ns, int d, bool ctrl, bool data) const {
2077   if (ctrl && data) {
2078     // ignore nonsensical combination
2079     return;
2080   }
2081   collect_nodes_i(ns, this, d, (uint) ABS(d), false, ctrl, data);
2082 }
2083 
2084 //--------------------------collect_nodes_in-----------------------------------
2085 static void collect_nodes_in(Node* start, GrowableArray<Node*> *ns, bool primary_is_data, bool collect_secondary) {
2086   // The maximum depth is determined using a BFS that visits all primary (data
2087   // or control) inputs and increments the depth at each level.
2088   uint d_in = 0;
2089   GrowableArray<Node*> nodes(Compile::current()->unique());
2090   nodes.push(start);
2091   int nodes_at_current_level = 1;
2092   int n_idx = 0;
2093   while (nodes_at_current_level > 0) {
2094     // Add all primary inputs reachable from the current level to the list, and
2095     // increase the depth if there were any.
2096     int nodes_at_next_level = 0;
2097     bool nodes_added = false;
2098     while (nodes_at_current_level > 0) {
2099       nodes_at_current_level--;
2100       Node* current = nodes.at(n_idx++);
2101       for (uint i = 0; i < current->len(); i++) {
2102         Node* n = current->in(i);
2103         if (not_a_node(n)) {
2104           continue;
2105         }
2106         if ((primary_is_data && n->is_CFG()) || (!primary_is_data && !n->is_CFG())) {
2107           continue;
2108         }
2109         if (!nodes.contains(n)) {
2110           nodes.push(n);
2111           nodes_added = true;
2112           nodes_at_next_level++;
2113         }
2114       }
2115     }
2116     if (nodes_added) {
2117       d_in++;
2118     }
2119     nodes_at_current_level = nodes_at_next_level;
2120   }
2121   start->collect_nodes(ns, d_in, !primary_is_data, primary_is_data);
2122   if (collect_secondary) {
2123     // Now, iterate over the secondary nodes in ns and add the respective
2124     // boundary reachable from them.
2125     GrowableArray<Node*> sns(Compile::current()->unique());
2126     for (GrowableArrayIterator<Node*> it = ns->begin(); it != ns->end(); ++it) {
2127       Node* n = *it;
2128       n->collect_nodes(&sns, 1, primary_is_data, !primary_is_data);
2129       for (GrowableArrayIterator<Node*> d = sns.begin(); d != sns.end(); ++d) {
2130         ns->append_if_missing(*d);
2131       }
2132       sns.clear();
2133     }
2134   }
2135 }
2136 
2137 //---------------------collect_nodes_in_all_data-------------------------------
2138 // Collect the entire data input graph. Include the control boundary if
2139 // requested.
2140 // Arguments:
2141 //   ns:   collect the nodes into this data structure.
2142 //   ctrl: if true, include the control boundary.
2143 void Node::collect_nodes_in_all_data(GrowableArray<Node*> *ns, bool ctrl) const {
2144   collect_nodes_in((Node*) this, ns, true, ctrl);
2145 }
2146 
2147 //--------------------------collect_nodes_in_all_ctrl--------------------------
2148 // Collect the entire control input graph. Include the data boundary if
2149 // requested.
2150 //   ns:   collect the nodes into this data structure.
2151 //   data: if true, include the control boundary.
2152 void Node::collect_nodes_in_all_ctrl(GrowableArray<Node*> *ns, bool data) const {
2153   collect_nodes_in((Node*) this, ns, false, data);
2154 }
2155 
2156 //------------------collect_nodes_out_all_ctrl_boundary------------------------
2157 // Collect the entire output graph until hitting control node boundaries, and
2158 // include those.
2159 void Node::collect_nodes_out_all_ctrl_boundary(GrowableArray<Node*> *ns) const {
2160   // Perform a BFS and stop at control nodes.
2161   GrowableArray<Node*> nodes(Compile::current()->unique());
2162   nodes.push((Node*) this);
2163   while (nodes.length() > 0) {
2164     Node* current = nodes.pop();
2165     if (not_a_node(current)) {
2166       continue;
2167     }
2168     ns->append_if_missing(current);
2169     if (!current->is_CFG()) {
2170       for (DUIterator i = current->outs(); current->has_out(i); i++) {
2171         nodes.push(current->out(i));
2172       }
2173     }
2174   }
2175   ns->remove((Node*) this);
2176 }
2177 
2178 // VERIFICATION CODE
2179 // For each input edge to a node (ie - for each Use-Def edge), verify that
2180 // there is a corresponding Def-Use edge.
2181 //------------------------------verify_edges-----------------------------------
2182 void Node::verify_edges(Unique_Node_List &visited) {
2183   uint i, j, idx;
2184   int  cnt;
2185   Node *n;
2186 
2187   // Recursive termination test
2188   if (visited.member(this))  return;
2189   visited.push(this);
2190 
2191   // Walk over all input edges, checking for correspondence
2192   for( i = 0; i < len(); i++ ) {
2193     n = in(i);
2194     if (n != NULL && !n->is_top()) {
2195       // Count instances of (Node *)this
2196       cnt = 0;
2197       for (idx = 0; idx < n->_outcnt; idx++ ) {
2198         if (n->_out[idx] == (Node *)this)  cnt++;
2199       }
2200       assert( cnt > 0,"Failed to find Def-Use edge." );
2201       // Check for duplicate edges
2202       // walk the input array downcounting the input edges to n
2203       for( j = 0; j < len(); j++ ) {
2204         if( in(j) == n ) cnt--;
2205       }
2206       assert( cnt == 0,"Mismatched edge count.");
2207     } else if (n == NULL) {
2208       assert(i >= req() || i == 0 || is_Region() || is_Phi() || is_ArrayCopy() ||
2209              (is_Allocate() && i >= AllocateNode::InlineTypeNode) ||
2210              (is_Unlock() && i == req()-1)
2211               || (is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
2212              "only region, phi, arraycopy, allocate or unlock nodes have null data edges");
2213     } else {
2214       assert(n->is_top(), "sanity");
2215       // Nothing to check.
2216     }
2217   }
2218   // Recursive walk over all input edges
2219   for( i = 0; i < len(); i++ ) {
2220     n = in(i);
2221     if( n != NULL )
2222       in(i)->verify_edges(visited);
2223   }
2224 }
2225 
2226 // Verify all nodes if verify_depth is negative
2227 void Node::verify(int verify_depth, VectorSet& visited, Node_List& worklist) {
2228   assert(verify_depth != 0, "depth should not be 0");
2229   Compile* C = Compile::current();
2230   uint last_index_on_current_depth = worklist.size() - 1;
2231   verify_depth--; // Visiting the first node on depth 1
2232   // Only add nodes to worklist if verify_depth is negative (visit all nodes) or greater than 0
2233   bool add_to_worklist = verify_depth != 0;
2234 
2235   for (uint list_index = 0; list_index < worklist.size(); list_index++) {
2236     Node* n = worklist[list_index];
2237 
2238     if (n->is_Con() && n->bottom_type() == Type::TOP) {
2239       if (C->cached_top_node() == NULL) {
2240         C->set_cached_top_node((Node*)n);
2241       }
2242       assert(C->cached_top_node() == n, "TOP node must be unique");
2243     }
2244 
2245     uint in_len = n->len();
2246     for (uint i = 0; i < in_len; i++) {
2247       Node* x = n->_in[i];
2248       if (!x || x->is_top()) {
2249         continue;
2250       }
2251 
2252       // Verify my input has a def-use edge to me
2253       // Count use-def edges from n to x
2254       int cnt = 1;
2255       for (uint j = 0; j < i; j++) {
2256         if (n->_in[j] == x) {
2257           cnt++;
2258           break;
2259         }
2260       }
2261       if (cnt == 2) {
2262         // x is already checked as n's previous input, skip its duplicated def-use count checking
2263         continue;
2264       }
2265       for (uint j = i + 1; j < in_len; j++) {
2266         if (n->_in[j] == x) {
2267           cnt++;
2268         }
2269       }
2270 
2271       // Count def-use edges from x to n
2272       uint max = x->_outcnt;
2273       for (uint k = 0; k < max; k++) {
2274         if (x->_out[k] == n) {
2275           cnt--;
2276         }
2277       }
2278       assert(cnt == 0, "mismatched def-use edge counts");
2279 
2280       if (add_to_worklist && !visited.test_set(x->_idx)) {
2281         worklist.push(x);
2282       }
2283     }
2284 
2285     if (verify_depth > 0 && list_index == last_index_on_current_depth) {
2286       // All nodes on this depth were processed and its inputs are on the worklist. Decrement verify_depth and
2287       // store the current last list index which is the last node in the list with the new depth. All nodes
2288       // added afterwards will have a new depth again. Stop adding new nodes if depth limit is reached (=0).
2289       verify_depth--;
2290       if (verify_depth == 0) {
2291         add_to_worklist = false;
2292       }
2293       last_index_on_current_depth = worklist.size() - 1;
2294     }
2295   }
2296 }
2297 #endif // not PRODUCT
2298 
2299 //------------------------------Registers--------------------------------------
2300 // Do we Match on this edge index or not?  Generally false for Control
2301 // and true for everything else.  Weird for calls & returns.
2302 uint Node::match_edge(uint idx) const {
2303   return idx;                   // True for other than index 0 (control)
2304 }
2305 
2306 // Register classes are defined for specific machines
2307 const RegMask &Node::out_RegMask() const {
2308   ShouldNotCallThis();
2309   return RegMask::Empty;
2310 }
2311 
2312 const RegMask &Node::in_RegMask(uint) const {
2313   ShouldNotCallThis();
2314   return RegMask::Empty;
2315 }
2316 
2317 void Node_Array::grow(uint i) {
2318   assert(_max > 0, "invariant");
2319   uint old = _max;
2320   _max = next_power_of_2(i);
2321   _nodes = (Node**)_a->Arealloc( _nodes, old*sizeof(Node*),_max*sizeof(Node*));
2322   Copy::zero_to_bytes( &_nodes[old], (_max-old)*sizeof(Node*) );
2323 }
2324 
2325 void Node_Array::insert(uint i, Node* n) {
2326   if (_nodes[_max - 1]) {
2327     grow(_max);
2328   }
2329   Copy::conjoint_words_to_higher((HeapWord*)&_nodes[i], (HeapWord*)&_nodes[i + 1], ((_max - i - 1) * sizeof(Node*)));
2330   _nodes[i] = n;
2331 }
2332 
2333 void Node_Array::remove(uint i) {
2334   Copy::conjoint_words_to_lower((HeapWord*)&_nodes[i + 1], (HeapWord*)&_nodes[i], ((_max - i - 1) * sizeof(Node*)));
2335   _nodes[_max - 1] = NULL;
2336 }
2337 
2338 void Node_Array::dump() const {
2339 #ifndef PRODUCT
2340   for (uint i = 0; i < _max; i++) {
2341     Node* nn = _nodes[i];
2342     if (nn != NULL) {
2343       tty->print("%5d--> ",i); nn->dump();
2344     }
2345   }
2346 #endif
2347 }
2348 
2349 //--------------------------is_iteratively_computed------------------------------
2350 // Operation appears to be iteratively computed (such as an induction variable)
2351 // It is possible for this operation to return false for a loop-varying
2352 // value, if it appears (by local graph inspection) to be computed by a simple conditional.
2353 bool Node::is_iteratively_computed() {
2354   if (ideal_reg()) { // does operation have a result register?
2355     for (uint i = 1; i < req(); i++) {
2356       Node* n = in(i);
2357       if (n != NULL && n->is_Phi()) {
2358         for (uint j = 1; j < n->req(); j++) {
2359           if (n->in(j) == this) {
2360             return true;
2361           }
2362         }
2363       }
2364     }
2365   }
2366   return false;
2367 }
2368 
2369 //--------------------------find_similar------------------------------
2370 // Return a node with opcode "opc" and same inputs as "this" if one can
2371 // be found; Otherwise return NULL;
2372 Node* Node::find_similar(int opc) {
2373   if (req() >= 2) {
2374     Node* def = in(1);
2375     if (def && def->outcnt() >= 2) {
2376       for (DUIterator_Fast dmax, i = def->fast_outs(dmax); i < dmax; i++) {
2377         Node* use = def->fast_out(i);
2378         if (use != this &&
2379             use->Opcode() == opc &&
2380             use->req() == req()) {
2381           uint j;
2382           for (j = 0; j < use->req(); j++) {
2383             if (use->in(j) != in(j)) {
2384               break;
2385             }
2386           }
2387           if (j == use->req()) {
2388             return use;
2389           }
2390         }
2391       }
2392     }
2393   }
2394   return NULL;
2395 }
2396 
2397 
2398 //--------------------------unique_ctrl_out------------------------------
2399 // Return the unique control out if only one. Null if none or more than one.
2400 Node* Node::unique_ctrl_out() const {
2401   Node* found = NULL;
2402   for (uint i = 0; i < outcnt(); i++) {
2403     Node* use = raw_out(i);
2404     if (use->is_CFG() && use != this) {
2405       if (found != NULL) {
2406         return NULL;
2407       }
2408       found = use;
2409     }
2410   }
2411   return found;
2412 }
2413 
2414 void Node::ensure_control_or_add_prec(Node* c) {
2415   if (in(0) == NULL) {
2416     set_req(0, c);
2417   } else if (in(0) != c) {
2418     add_prec(c);
2419   }
2420 }
2421 
2422 bool Node::is_dead_loop_safe() const {
2423   if (is_Phi()) {
2424     return true;
2425   }
2426   if (is_Proj() && in(0) == NULL)  {
2427     return true;
2428   }
2429   if ((_flags & (Flag_is_dead_loop_safe | Flag_is_Con)) != 0) {
2430     if (!is_Proj()) {
2431       return true;
2432     }
2433     if (in(0)->is_Allocate()) {
2434       return false;
2435     }
2436     // MemNode::can_see_stored_value() peeks through the boxing call
2437     if (in(0)->is_CallStaticJava() && in(0)->as_CallStaticJava()->is_boxing_method()) {
2438       return false;
2439     }
2440     return true;
2441   }
2442   return false;
2443 }
2444 
2445 //=============================================================================
2446 //------------------------------yank-------------------------------------------
2447 // Find and remove
2448 void Node_List::yank( Node *n ) {
2449   uint i;
2450   for (i = 0; i < _cnt; i++) {
2451     if (_nodes[i] == n) {
2452       break;
2453     }
2454   }
2455 
2456   if (i < _cnt) {
2457     _nodes[i] = _nodes[--_cnt];
2458   }
2459 }
2460 
2461 //------------------------------dump-------------------------------------------
2462 void Node_List::dump() const {
2463 #ifndef PRODUCT
2464   for (uint i = 0; i < _cnt; i++) {
2465     if (_nodes[i]) {
2466       tty->print("%5d--> ", i);
2467       _nodes[i]->dump();
2468     }
2469   }
2470 #endif
2471 }
2472 
2473 void Node_List::dump_simple() const {
2474 #ifndef PRODUCT
2475   for (uint i = 0; i < _cnt; i++) {
2476     if( _nodes[i] ) {
2477       tty->print(" %d", _nodes[i]->_idx);
2478     } else {
2479       tty->print(" NULL");
2480     }
2481   }
2482 #endif
2483 }
2484 
2485 //=============================================================================
2486 //------------------------------remove-----------------------------------------
2487 void Unique_Node_List::remove(Node* n) {
2488   if (_in_worklist.test(n->_idx)) {
2489     for (uint i = 0; i < size(); i++) {
2490       if (_nodes[i] == n) {
2491         map(i, Node_List::pop());
2492         _in_worklist.remove(n->_idx);
2493         return;
2494       }
2495     }
2496     ShouldNotReachHere();
2497   }
2498 }
2499 
2500 //-----------------------remove_useless_nodes----------------------------------
2501 // Remove useless nodes from worklist
2502 void Unique_Node_List::remove_useless_nodes(VectorSet &useful) {
2503   for (uint i = 0; i < size(); ++i) {
2504     Node *n = at(i);
2505     assert( n != NULL, "Did not expect null entries in worklist");
2506     if (!useful.test(n->_idx)) {
2507       _in_worklist.remove(n->_idx);
2508       map(i, Node_List::pop());
2509       --i;  // Visit popped node
2510       // If it was last entry, loop terminates since size() was also reduced
2511     }
2512   }
2513 }
2514 
2515 //=============================================================================
2516 void Node_Stack::grow() {
2517   size_t old_top = pointer_delta(_inode_top,_inodes,sizeof(INode)); // save _top
2518   size_t old_max = pointer_delta(_inode_max,_inodes,sizeof(INode));
2519   size_t max = old_max << 1;             // max * 2
2520   _inodes = REALLOC_ARENA_ARRAY(_a, INode, _inodes, old_max, max);
2521   _inode_max = _inodes + max;
2522   _inode_top = _inodes + old_top;        // restore _top
2523 }
2524 
2525 // Node_Stack is used to map nodes.
2526 Node* Node_Stack::find(uint idx) const {
2527   uint sz = size();
2528   for (uint i = 0; i < sz; i++) {
2529     if (idx == index_at(i)) {
2530       return node_at(i);
2531     }
2532   }
2533   return NULL;
2534 }
2535 
2536 //=============================================================================
2537 uint TypeNode::size_of() const { return sizeof(*this); }
2538 #ifndef PRODUCT
2539 void TypeNode::dump_spec(outputStream *st) const {
2540   if (!Verbose && !WizardMode) {
2541     // standard dump does this in Verbose and WizardMode
2542     st->print(" #"); _type->dump_on(st);
2543   }
2544 }
2545 
2546 void TypeNode::dump_compact_spec(outputStream *st) const {
2547   st->print("#");
2548   _type->dump_on(st);
2549 }
2550 #endif
2551 uint TypeNode::hash() const {
2552   return Node::hash() + _type->hash();
2553 }
2554 bool TypeNode::cmp(const Node& n) const {
2555   return !Type::cmp(_type, ((TypeNode&)n)._type);
2556 }
2557 const Type* TypeNode::bottom_type() const { return _type; }
2558 const Type* TypeNode::Value(PhaseGVN* phase) const { return _type; }
2559 
2560 //------------------------------ideal_reg--------------------------------------
2561 uint TypeNode::ideal_reg() const {
2562   return _type->ideal_reg();
2563 }