1 /*
   2  * Copyright (c) 1997, 2022, 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 "compiler/compileLog.hpp"
  27 #include "ci/bcEscapeAnalyzer.hpp"
  28 #include "ci/ciNativeEntryPoint.hpp"
  29 #include "compiler/oopMap.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/c2/barrierSetC2.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "opto/callGenerator.hpp"
  34 #include "opto/callnode.hpp"
  35 #include "opto/castnode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/escape.hpp"
  38 #include "opto/locknode.hpp"
  39 #include "opto/machnode.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/parse.hpp"
  42 #include "opto/regalloc.hpp"
  43 #include "opto/regmask.hpp"
  44 #include "opto/rootnode.hpp"
  45 #include "opto/runtime.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "utilities/powerOfTwo.hpp"
  48 #include "code/vmreg.hpp"
  49 
  50 // Portions of code courtesy of Clifford Click
  51 
  52 // Optimization - Graph Style
  53 
  54 //=============================================================================
  55 uint StartNode::size_of() const { return sizeof(*this); }
  56 bool StartNode::cmp( const Node &n ) const
  57 { return _domain == ((StartNode&)n)._domain; }
  58 const Type *StartNode::bottom_type() const { return _domain; }
  59 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
  60 #ifndef PRODUCT
  61 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
  62 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
  63 #endif
  64 
  65 //------------------------------Ideal------------------------------------------
  66 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
  67   return remove_dead_region(phase, can_reshape) ? this : NULL;
  68 }
  69 
  70 //------------------------------calling_convention-----------------------------
  71 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
  72   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
  73 }
  74 
  75 //------------------------------Registers--------------------------------------
  76 const RegMask &StartNode::in_RegMask(uint) const {
  77   return RegMask::Empty;
  78 }
  79 
  80 //------------------------------match------------------------------------------
  81 // Construct projections for incoming parameters, and their RegMask info
  82 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
  83   switch (proj->_con) {
  84   case TypeFunc::Control:
  85   case TypeFunc::I_O:
  86   case TypeFunc::Memory:
  87     return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
  88   case TypeFunc::FramePtr:
  89     return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
  90   case TypeFunc::ReturnAdr:
  91     return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
  92   case TypeFunc::Parms:
  93   default: {
  94       uint parm_num = proj->_con - TypeFunc::Parms;
  95       const Type *t = _domain->field_at(proj->_con);
  96       if (t->base() == Type::Half)  // 2nd half of Longs and Doubles
  97         return new ConNode(Type::TOP);
  98       uint ideal_reg = t->ideal_reg();
  99       RegMask &rm = match->_calling_convention_mask[parm_num];
 100       return new MachProjNode(this,proj->_con,rm,ideal_reg);
 101     }
 102   }
 103   return NULL;
 104 }
 105 
 106 //------------------------------StartOSRNode----------------------------------
 107 // The method start node for an on stack replacement adapter
 108 
 109 //------------------------------osr_domain-----------------------------
 110 const TypeTuple *StartOSRNode::osr_domain() {
 111   const Type **fields = TypeTuple::fields(2);
 112   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
 113 
 114   return TypeTuple::make(TypeFunc::Parms+1, fields);
 115 }
 116 
 117 //=============================================================================
 118 const char * const ParmNode::names[TypeFunc::Parms+1] = {
 119   "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
 120 };
 121 
 122 #ifndef PRODUCT
 123 void ParmNode::dump_spec(outputStream *st) const {
 124   if( _con < TypeFunc::Parms ) {
 125     st->print("%s", names[_con]);
 126   } else {
 127     st->print("Parm%d: ",_con-TypeFunc::Parms);
 128     // Verbose and WizardMode dump bottom_type for all nodes
 129     if( !Verbose && !WizardMode )   bottom_type()->dump_on(st);
 130   }
 131 }
 132 
 133 void ParmNode::dump_compact_spec(outputStream *st) const {
 134   if (_con < TypeFunc::Parms) {
 135     st->print("%s", names[_con]);
 136   } else {
 137     st->print("%d:", _con-TypeFunc::Parms);
 138     // unconditionally dump bottom_type
 139     bottom_type()->dump_on(st);
 140   }
 141 }
 142 
 143 // For a ParmNode, all immediate inputs and outputs are considered relevant
 144 // both in compact and standard representation.
 145 void ParmNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
 146   this->collect_nodes(in_rel, 1, false, false);
 147   this->collect_nodes(out_rel, -1, false, false);
 148 }
 149 #endif
 150 
 151 uint ParmNode::ideal_reg() const {
 152   switch( _con ) {
 153   case TypeFunc::Control  : // fall through
 154   case TypeFunc::I_O      : // fall through
 155   case TypeFunc::Memory   : return 0;
 156   case TypeFunc::FramePtr : // fall through
 157   case TypeFunc::ReturnAdr: return Op_RegP;
 158   default                 : assert( _con > TypeFunc::Parms, "" );
 159     // fall through
 160   case TypeFunc::Parms    : {
 161     // Type of argument being passed
 162     const Type *t = in(0)->as_Start()->_domain->field_at(_con);
 163     return t->ideal_reg();
 164   }
 165   }
 166   ShouldNotReachHere();
 167   return 0;
 168 }
 169 
 170 //=============================================================================
 171 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
 172   init_req(TypeFunc::Control,cntrl);
 173   init_req(TypeFunc::I_O,i_o);
 174   init_req(TypeFunc::Memory,memory);
 175   init_req(TypeFunc::FramePtr,frameptr);
 176   init_req(TypeFunc::ReturnAdr,retadr);
 177 }
 178 
 179 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
 180   return remove_dead_region(phase, can_reshape) ? this : NULL;
 181 }
 182 
 183 const Type* ReturnNode::Value(PhaseGVN* phase) const {
 184   return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
 185     ? Type::TOP
 186     : Type::BOTTOM;
 187 }
 188 
 189 // Do we Match on this edge index or not?  No edges on return nodes
 190 uint ReturnNode::match_edge(uint idx) const {
 191   return 0;
 192 }
 193 
 194 
 195 #ifndef PRODUCT
 196 void ReturnNode::dump_req(outputStream *st) const {
 197   // Dump the required inputs, enclosed in '(' and ')'
 198   uint i;                       // Exit value of loop
 199   for (i = 0; i < req(); i++) {    // For all required inputs
 200     if (i == TypeFunc::Parms) st->print("returns");
 201     if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
 202     else st->print("_ ");
 203   }
 204 }
 205 #endif
 206 
 207 //=============================================================================
 208 RethrowNode::RethrowNode(
 209   Node* cntrl,
 210   Node* i_o,
 211   Node* memory,
 212   Node* frameptr,
 213   Node* ret_adr,
 214   Node* exception
 215 ) : Node(TypeFunc::Parms + 1) {
 216   init_req(TypeFunc::Control  , cntrl    );
 217   init_req(TypeFunc::I_O      , i_o      );
 218   init_req(TypeFunc::Memory   , memory   );
 219   init_req(TypeFunc::FramePtr , frameptr );
 220   init_req(TypeFunc::ReturnAdr, ret_adr);
 221   init_req(TypeFunc::Parms    , exception);
 222 }
 223 
 224 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
 225   return remove_dead_region(phase, can_reshape) ? this : NULL;
 226 }
 227 
 228 const Type* RethrowNode::Value(PhaseGVN* phase) const {
 229   return (phase->type(in(TypeFunc::Control)) == Type::TOP)
 230     ? Type::TOP
 231     : Type::BOTTOM;
 232 }
 233 
 234 uint RethrowNode::match_edge(uint idx) const {
 235   return 0;
 236 }
 237 
 238 #ifndef PRODUCT
 239 void RethrowNode::dump_req(outputStream *st) const {
 240   // Dump the required inputs, enclosed in '(' and ')'
 241   uint i;                       // Exit value of loop
 242   for (i = 0; i < req(); i++) {    // For all required inputs
 243     if (i == TypeFunc::Parms) st->print("exception");
 244     if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
 245     else st->print("_ ");
 246   }
 247 }
 248 #endif
 249 
 250 //=============================================================================
 251 // Do we Match on this edge index or not?  Match only target address & method
 252 uint TailCallNode::match_edge(uint idx) const {
 253   return TypeFunc::Parms <= idx  &&  idx <= TypeFunc::Parms+1;
 254 }
 255 
 256 //=============================================================================
 257 // Do we Match on this edge index or not?  Match only target address & oop
 258 uint TailJumpNode::match_edge(uint idx) const {
 259   return TypeFunc::Parms <= idx  &&  idx <= TypeFunc::Parms+1;
 260 }
 261 
 262 //=============================================================================
 263 JVMState::JVMState(ciMethod* method, JVMState* caller) :
 264   _method(method) {
 265   assert(method != NULL, "must be valid call site");
 266   _bci = InvocationEntryBci;
 267   _reexecute = Reexecute_Undefined;
 268   debug_only(_bci = -99);  // random garbage value
 269   debug_only(_map = (SafePointNode*)-1);
 270   _caller = caller;
 271   _depth  = 1 + (caller == NULL ? 0 : caller->depth());
 272   _locoff = TypeFunc::Parms;
 273   _stkoff = _locoff + _method->max_locals();
 274   _monoff = _stkoff + _method->max_stack();
 275   _scloff = _monoff;
 276   _endoff = _monoff;
 277   _sp = 0;
 278 }
 279 JVMState::JVMState(int stack_size) :
 280   _method(NULL) {
 281   _bci = InvocationEntryBci;
 282   _reexecute = Reexecute_Undefined;
 283   debug_only(_map = (SafePointNode*)-1);
 284   _caller = NULL;
 285   _depth  = 1;
 286   _locoff = TypeFunc::Parms;
 287   _stkoff = _locoff;
 288   _monoff = _stkoff + stack_size;
 289   _scloff = _monoff;
 290   _endoff = _monoff;
 291   _sp = 0;
 292 }
 293 
 294 //--------------------------------of_depth-------------------------------------
 295 JVMState* JVMState::of_depth(int d) const {
 296   const JVMState* jvmp = this;
 297   assert(0 < d && (uint)d <= depth(), "oob");
 298   for (int skip = depth() - d; skip > 0; skip--) {
 299     jvmp = jvmp->caller();
 300   }
 301   assert(jvmp->depth() == (uint)d, "found the right one");
 302   return (JVMState*)jvmp;
 303 }
 304 
 305 //-----------------------------same_calls_as-----------------------------------
 306 bool JVMState::same_calls_as(const JVMState* that) const {
 307   if (this == that)                    return true;
 308   if (this->depth() != that->depth())  return false;
 309   const JVMState* p = this;
 310   const JVMState* q = that;
 311   for (;;) {
 312     if (p->_method != q->_method)    return false;
 313     if (p->_method == NULL)          return true;   // bci is irrelevant
 314     if (p->_bci    != q->_bci)       return false;
 315     if (p->_reexecute != q->_reexecute)  return false;
 316     p = p->caller();
 317     q = q->caller();
 318     if (p == q)                      return true;
 319     assert(p != NULL && q != NULL, "depth check ensures we don't run off end");
 320   }
 321 }
 322 
 323 //------------------------------debug_start------------------------------------
 324 uint JVMState::debug_start()  const {
 325   debug_only(JVMState* jvmroot = of_depth(1));
 326   assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
 327   return of_depth(1)->locoff();
 328 }
 329 
 330 //-------------------------------debug_end-------------------------------------
 331 uint JVMState::debug_end() const {
 332   debug_only(JVMState* jvmroot = of_depth(1));
 333   assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
 334   return endoff();
 335 }
 336 
 337 //------------------------------debug_depth------------------------------------
 338 uint JVMState::debug_depth() const {
 339   uint total = 0;
 340   for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {
 341     total += jvmp->debug_size();
 342   }
 343   return total;
 344 }
 345 
 346 #ifndef PRODUCT
 347 
 348 //------------------------------format_helper----------------------------------
 349 // Given an allocation (a Chaitin object) and a Node decide if the Node carries
 350 // any defined value or not.  If it does, print out the register or constant.
 351 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
 352   if (n == NULL) { st->print(" NULL"); return; }
 353   if (n->is_SafePointScalarObject()) {
 354     // Scalar replacement.
 355     SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
 356     scobjs->append_if_missing(spobj);
 357     int sco_n = scobjs->find(spobj);
 358     assert(sco_n >= 0, "");
 359     st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
 360     return;
 361   }
 362   if (regalloc->node_regs_max_index() > 0 &&
 363       OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined
 364     char buf[50];
 365     regalloc->dump_register(n,buf);
 366     st->print(" %s%d]=%s",msg,i,buf);
 367   } else {                      // No register, but might be constant
 368     const Type *t = n->bottom_type();
 369     switch (t->base()) {
 370     case Type::Int:
 371       st->print(" %s%d]=#" INT32_FORMAT,msg,i,t->is_int()->get_con());
 372       break;
 373     case Type::AnyPtr:
 374       assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
 375       st->print(" %s%d]=#NULL",msg,i);
 376       break;
 377     case Type::AryPtr:
 378     case Type::InstPtr:
 379       st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));
 380       break;
 381     case Type::KlassPtr:
 382     case Type::AryKlassPtr:
 383     case Type::InstKlassPtr:
 384       st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->klass()));
 385       break;
 386     case Type::MetadataPtr:
 387       st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));
 388       break;
 389     case Type::NarrowOop:
 390       st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));
 391       break;
 392     case Type::RawPtr:
 393       st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));
 394       break;
 395     case Type::DoubleCon:
 396       st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
 397       break;
 398     case Type::FloatCon:
 399       st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
 400       break;
 401     case Type::Long:
 402       st->print(" %s%d]=#" INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));
 403       break;
 404     case Type::Half:
 405     case Type::Top:
 406       st->print(" %s%d]=_",msg,i);
 407       break;
 408     default: ShouldNotReachHere();
 409     }
 410   }
 411 }
 412 
 413 //---------------------print_method_with_lineno--------------------------------
 414 void JVMState::print_method_with_lineno(outputStream* st, bool show_name) const {
 415   if (show_name) _method->print_short_name(st);
 416 
 417   int lineno = _method->line_number_from_bci(_bci);
 418   if (lineno != -1) {
 419     st->print(" @ bci:%d (line %d)", _bci, lineno);
 420   } else {
 421     st->print(" @ bci:%d", _bci);
 422   }
 423 }
 424 
 425 //------------------------------format-----------------------------------------
 426 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
 427   st->print("        #");
 428   if (_method) {
 429     print_method_with_lineno(st, true);
 430   } else {
 431     st->print_cr(" runtime stub ");
 432     return;
 433   }
 434   if (n->is_MachSafePoint()) {
 435     GrowableArray<SafePointScalarObjectNode*> scobjs;
 436     MachSafePointNode *mcall = n->as_MachSafePoint();
 437     uint i;
 438     // Print locals
 439     for (i = 0; i < (uint)loc_size(); i++)
 440       format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);
 441     // Print stack
 442     for (i = 0; i < (uint)stk_size(); i++) {
 443       if ((uint)(_stkoff + i) >= mcall->len())
 444         st->print(" oob ");
 445       else
 446        format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);
 447     }
 448     for (i = 0; (int)i < nof_monitors(); i++) {
 449       Node *box = mcall->monitor_box(this, i);
 450       Node *obj = mcall->monitor_obj(this, i);
 451       if (regalloc->node_regs_max_index() > 0 &&
 452           OptoReg::is_valid(regalloc->get_reg_first(box))) {
 453         box = BoxLockNode::box_node(box);
 454         format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);
 455       } else {
 456         OptoReg::Name box_reg = BoxLockNode::reg(box);
 457         st->print(" MON-BOX%d=%s+%d",
 458                    i,
 459                    OptoReg::regname(OptoReg::c_frame_pointer),
 460                    regalloc->reg2offset(box_reg));
 461       }
 462       const char* obj_msg = "MON-OBJ[";
 463       if (EliminateLocks) {
 464         if (BoxLockNode::box_node(box)->is_eliminated())
 465           obj_msg = "MON-OBJ(LOCK ELIMINATED)[";
 466       }
 467       format_helper(regalloc, st, obj, obj_msg, i, &scobjs);
 468     }
 469 
 470     for (i = 0; i < (uint)scobjs.length(); i++) {
 471       // Scalar replaced objects.
 472       st->cr();
 473       st->print("        # ScObj" INT32_FORMAT " ", i);
 474       SafePointScalarObjectNode* spobj = scobjs.at(i);
 475       ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass();
 476       assert(cik->is_instance_klass() ||
 477              cik->is_array_klass(), "Not supported allocation.");
 478       ciInstanceKlass *iklass = NULL;
 479       if (cik->is_instance_klass()) {
 480         cik->print_name_on(st);
 481         iklass = cik->as_instance_klass();
 482       } else if (cik->is_type_array_klass()) {
 483         cik->as_array_klass()->base_element_type()->print_name_on(st);
 484         st->print("[%d]", spobj->n_fields());
 485       } else if (cik->is_obj_array_klass()) {
 486         ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
 487         if (cie->is_instance_klass()) {
 488           cie->print_name_on(st);
 489         } else if (cie->is_type_array_klass()) {
 490           cie->as_array_klass()->base_element_type()->print_name_on(st);
 491         } else {
 492           ShouldNotReachHere();
 493         }
 494         st->print("[%d]", spobj->n_fields());
 495         int ndim = cik->as_array_klass()->dimension() - 1;
 496         while (ndim-- > 0) {
 497           st->print("[]");
 498         }
 499       }
 500       st->print("={");
 501       uint nf = spobj->n_fields();
 502       if (nf > 0) {
 503         uint first_ind = spobj->first_index(mcall->jvms());
 504         Node* fld_node = mcall->in(first_ind);
 505         ciField* cifield;
 506         if (iklass != NULL) {
 507           st->print(" [");
 508           cifield = iklass->nonstatic_field_at(0);
 509           cifield->print_name_on(st);
 510           format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
 511         } else {
 512           format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
 513         }
 514         for (uint j = 1; j < nf; j++) {
 515           fld_node = mcall->in(first_ind+j);
 516           if (iklass != NULL) {
 517             st->print(", [");
 518             cifield = iklass->nonstatic_field_at(j);
 519             cifield->print_name_on(st);
 520             format_helper(regalloc, st, fld_node, ":", j, &scobjs);
 521           } else {
 522             format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
 523           }
 524         }
 525       }
 526       st->print(" }");
 527     }
 528   }
 529   st->cr();
 530   if (caller() != NULL) caller()->format(regalloc, n, st);
 531 }
 532 
 533 
 534 void JVMState::dump_spec(outputStream *st) const {
 535   if (_method != NULL) {
 536     bool printed = false;
 537     if (!Verbose) {
 538       // The JVMS dumps make really, really long lines.
 539       // Take out the most boring parts, which are the package prefixes.
 540       char buf[500];
 541       stringStream namest(buf, sizeof(buf));
 542       _method->print_short_name(&namest);
 543       if (namest.count() < sizeof(buf)) {
 544         const char* name = namest.base();
 545         if (name[0] == ' ')  ++name;
 546         const char* endcn = strchr(name, ':');  // end of class name
 547         if (endcn == NULL)  endcn = strchr(name, '(');
 548         if (endcn == NULL)  endcn = name + strlen(name);
 549         while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
 550           --endcn;
 551         st->print(" %s", endcn);
 552         printed = true;
 553       }
 554     }
 555     print_method_with_lineno(st, !printed);
 556     if(_reexecute == Reexecute_True)
 557       st->print(" reexecute");
 558   } else {
 559     st->print(" runtime stub");
 560   }
 561   if (caller() != NULL)  caller()->dump_spec(st);
 562 }
 563 
 564 
 565 void JVMState::dump_on(outputStream* st) const {
 566   bool print_map = _map && !((uintptr_t)_map & 1) &&
 567                   ((caller() == NULL) || (caller()->map() != _map));
 568   if (print_map) {
 569     if (_map->len() > _map->req()) {  // _map->has_exceptions()
 570       Node* ex = _map->in(_map->req());  // _map->next_exception()
 571       // skip the first one; it's already being printed
 572       while (ex != NULL && ex->len() > ex->req()) {
 573         ex = ex->in(ex->req());  // ex->next_exception()
 574         ex->dump(1);
 575       }
 576     }
 577     _map->dump(Verbose ? 2 : 1);
 578   }
 579   if (caller() != NULL) {
 580     caller()->dump_on(st);
 581   }
 582   st->print("JVMS depth=%d loc=%d stk=%d arg=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d reexecute=%s method=",
 583              depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");
 584   if (_method == NULL) {
 585     st->print_cr("(none)");
 586   } else {
 587     _method->print_name(st);
 588     st->cr();
 589     if (bci() >= 0 && bci() < _method->code_size()) {
 590       st->print("    bc: ");
 591       _method->print_codes_on(bci(), bci()+1, st);
 592     }
 593   }
 594 }
 595 
 596 // Extra way to dump a jvms from the debugger,
 597 // to avoid a bug with C++ member function calls.
 598 void dump_jvms(JVMState* jvms) {
 599   jvms->dump();
 600 }
 601 #endif
 602 
 603 //--------------------------clone_shallow--------------------------------------
 604 JVMState* JVMState::clone_shallow(Compile* C) const {
 605   JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
 606   n->set_bci(_bci);
 607   n->_reexecute = _reexecute;
 608   n->set_locoff(_locoff);
 609   n->set_stkoff(_stkoff);
 610   n->set_monoff(_monoff);
 611   n->set_scloff(_scloff);
 612   n->set_endoff(_endoff);
 613   n->set_sp(_sp);
 614   n->set_map(_map);
 615   return n;
 616 }
 617 
 618 //---------------------------clone_deep----------------------------------------
 619 JVMState* JVMState::clone_deep(Compile* C) const {
 620   JVMState* n = clone_shallow(C);
 621   for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {
 622     p->_caller = p->_caller->clone_shallow(C);
 623   }
 624   assert(n->depth() == depth(), "sanity");
 625   assert(n->debug_depth() == debug_depth(), "sanity");
 626   return n;
 627 }
 628 
 629 /**
 630  * Reset map for all callers
 631  */
 632 void JVMState::set_map_deep(SafePointNode* map) {
 633   for (JVMState* p = this; p != NULL; p = p->_caller) {
 634     p->set_map(map);
 635   }
 636 }
 637 
 638 // unlike set_map(), this is two-way setting.
 639 void JVMState::bind_map(SafePointNode* map) {
 640   set_map(map);
 641   _map->set_jvms(this);
 642 }
 643 
 644 // Adapt offsets in in-array after adding or removing an edge.
 645 // Prerequisite is that the JVMState is used by only one node.
 646 void JVMState::adapt_position(int delta) {
 647   for (JVMState* jvms = this; jvms != NULL; jvms = jvms->caller()) {
 648     jvms->set_locoff(jvms->locoff() + delta);
 649     jvms->set_stkoff(jvms->stkoff() + delta);
 650     jvms->set_monoff(jvms->monoff() + delta);
 651     jvms->set_scloff(jvms->scloff() + delta);
 652     jvms->set_endoff(jvms->endoff() + delta);
 653   }
 654 }
 655 
 656 // Mirror the stack size calculation in the deopt code
 657 // How much stack space would we need at this point in the program in
 658 // case of deoptimization?
 659 int JVMState::interpreter_frame_size() const {
 660   const JVMState* jvms = this;
 661   int size = 0;
 662   int callee_parameters = 0;
 663   int callee_locals = 0;
 664   int extra_args = method()->max_stack() - stk_size();
 665 
 666   while (jvms != NULL) {
 667     int locks = jvms->nof_monitors();
 668     int temps = jvms->stk_size();
 669     bool is_top_frame = (jvms == this);
 670     ciMethod* method = jvms->method();
 671 
 672     int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
 673                                                                  temps + callee_parameters,
 674                                                                  extra_args,
 675                                                                  locks,
 676                                                                  callee_parameters,
 677                                                                  callee_locals,
 678                                                                  is_top_frame);
 679     size += frame_size;
 680 
 681     callee_parameters = method->size_of_parameters();
 682     callee_locals = method->max_locals();
 683     extra_args = 0;
 684     jvms = jvms->caller();
 685   }
 686   return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
 687 }
 688 
 689 //=============================================================================
 690 bool CallNode::cmp( const Node &n ) const
 691 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
 692 #ifndef PRODUCT
 693 void CallNode::dump_req(outputStream *st) const {
 694   // Dump the required inputs, enclosed in '(' and ')'
 695   uint i;                       // Exit value of loop
 696   for (i = 0; i < req(); i++) {    // For all required inputs
 697     if (i == TypeFunc::Parms) st->print("(");
 698     if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
 699     else st->print("_ ");
 700   }
 701   st->print(")");
 702 }
 703 
 704 void CallNode::dump_spec(outputStream *st) const {
 705   st->print(" ");
 706   if (tf() != NULL)  tf()->dump_on(st);
 707   if (_cnt != COUNT_UNKNOWN)  st->print(" C=%f",_cnt);
 708   if (jvms() != NULL)  jvms()->dump_spec(st);
 709 }
 710 #endif
 711 
 712 const Type *CallNode::bottom_type() const { return tf()->range(); }
 713 const Type* CallNode::Value(PhaseGVN* phase) const {
 714   if (phase->type(in(0)) == Type::TOP)  return Type::TOP;
 715   return tf()->range();
 716 }
 717 
 718 //------------------------------calling_convention-----------------------------
 719 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
 720   // Use the standard compiler calling convention
 721   SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
 722 }
 723 
 724 
 725 //------------------------------match------------------------------------------
 726 // Construct projections for control, I/O, memory-fields, ..., and
 727 // return result(s) along with their RegMask info
 728 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
 729   switch (proj->_con) {
 730   case TypeFunc::Control:
 731   case TypeFunc::I_O:
 732   case TypeFunc::Memory:
 733     return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
 734 
 735   case TypeFunc::Parms+1:       // For LONG & DOUBLE returns
 736     assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
 737     // 2nd half of doubles and longs
 738     return new MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
 739 
 740   case TypeFunc::Parms: {       // Normal returns
 741     uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
 742     OptoRegPair regs = Opcode() == Op_CallLeafVector
 743       ? match->vector_return_value(ideal_reg)      // Calls into assembly vector routine
 744       : is_CallRuntime()
 745         ? match->c_return_value(ideal_reg)  // Calls into C runtime
 746         : match->  return_value(ideal_reg); // Calls into compiled Java code
 747     RegMask rm = RegMask(regs.first());
 748 
 749     if (Opcode() == Op_CallLeafVector) {
 750       // If the return is in vector, compute appropriate regmask taking into account the whole range
 751       if(ideal_reg >= Op_VecS && ideal_reg <= Op_VecZ) {
 752         if(OptoReg::is_valid(regs.second())) {
 753           for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
 754             rm.Insert(r);
 755           }
 756         }
 757       }
 758     }
 759 
 760     if( OptoReg::is_valid(regs.second()) )
 761       rm.Insert( regs.second() );
 762     return new MachProjNode(this,proj->_con,rm,ideal_reg);
 763   }
 764 
 765   case TypeFunc::ReturnAdr:
 766   case TypeFunc::FramePtr:
 767   default:
 768     ShouldNotReachHere();
 769   }
 770   return NULL;
 771 }
 772 
 773 // Do we Match on this edge index or not?  Match no edges
 774 uint CallNode::match_edge(uint idx) const {
 775   return 0;
 776 }
 777 
 778 //
 779 // Determine whether the call could modify the field of the specified
 780 // instance at the specified offset.
 781 //
 782 bool CallNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
 783   assert((t_oop != NULL), "sanity");
 784   if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
 785     const TypeTuple* args = _tf->domain();
 786     Node* dest = NULL;
 787     // Stubs that can be called once an ArrayCopyNode is expanded have
 788     // different signatures. Look for the second pointer argument,
 789     // that is the destination of the copy.
 790     for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
 791       if (args->field_at(i)->isa_ptr()) {
 792         j++;
 793         if (j == 2) {
 794           dest = in(i);
 795           break;
 796         }
 797       }
 798     }
 799     guarantee(dest != NULL, "Call had only one ptr in, broken IR!");
 800     if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
 801       return true;
 802     }
 803     return false;
 804   }
 805   if (t_oop->is_known_instance()) {
 806     // The instance_id is set only for scalar-replaceable allocations which
 807     // are not passed as arguments according to Escape Analysis.
 808     return false;
 809   }
 810   if (t_oop->is_ptr_to_boxed_value()) {
 811     ciKlass* boxing_klass = t_oop->klass();
 812     if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {
 813       // Skip unrelated boxing methods.
 814       Node* proj = proj_out_or_null(TypeFunc::Parms);
 815       if ((proj == NULL) || (phase->type(proj)->is_instptr()->klass() != boxing_klass)) {
 816         return false;
 817       }
 818     }
 819     if (is_CallJava() && as_CallJava()->method() != NULL) {
 820       ciMethod* meth = as_CallJava()->method();
 821       if (meth->is_getter()) {
 822         return false;
 823       }
 824       // May modify (by reflection) if an boxing object is passed
 825       // as argument or returned.
 826       Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : NULL;
 827       if (proj != NULL) {
 828         const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
 829         if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
 830                                  (inst_t->klass() == boxing_klass))) {
 831           return true;
 832         }
 833       }
 834       const TypeTuple* d = tf()->domain();
 835       for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 836         const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
 837         if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
 838                                  (inst_t->klass() == boxing_klass))) {
 839           return true;
 840         }
 841       }
 842       return false;
 843     }
 844   }
 845   return true;
 846 }
 847 
 848 // Does this call have a direct reference to n other than debug information?
 849 bool CallNode::has_non_debug_use(Node *n) {
 850   const TypeTuple * d = tf()->domain();
 851   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
 852     Node *arg = in(i);
 853     if (arg == n) {
 854       return true;
 855     }
 856   }
 857   return false;
 858 }
 859 
 860 // Returns the unique CheckCastPP of a call
 861 // or 'this' if there are several CheckCastPP or unexpected uses
 862 // or returns NULL if there is no one.
 863 Node *CallNode::result_cast() {
 864   Node *cast = NULL;
 865 
 866   Node *p = proj_out_or_null(TypeFunc::Parms);
 867   if (p == NULL)
 868     return NULL;
 869 
 870   for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
 871     Node *use = p->fast_out(i);
 872     if (use->is_CheckCastPP()) {
 873       if (cast != NULL) {
 874         return this;  // more than 1 CheckCastPP
 875       }
 876       cast = use;
 877     } else if (!use->is_Initialize() &&
 878                !use->is_AddP() &&
 879                use->Opcode() != Op_MemBarStoreStore) {
 880       // Expected uses are restricted to a CheckCastPP, an Initialize
 881       // node, a MemBarStoreStore (clone) and AddP nodes. If we
 882       // encounter any other use (a Phi node can be seen in rare
 883       // cases) return this to prevent incorrect optimizations.
 884       return this;
 885     }
 886   }
 887   return cast;
 888 }
 889 
 890 
 891 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) {
 892   projs->fallthrough_proj      = NULL;
 893   projs->fallthrough_catchproj = NULL;
 894   projs->fallthrough_ioproj    = NULL;
 895   projs->catchall_ioproj       = NULL;
 896   projs->catchall_catchproj    = NULL;
 897   projs->fallthrough_memproj   = NULL;
 898   projs->catchall_memproj      = NULL;
 899   projs->resproj               = NULL;
 900   projs->exobj                 = NULL;
 901 
 902   for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
 903     ProjNode *pn = fast_out(i)->as_Proj();
 904     if (pn->outcnt() == 0) continue;
 905     switch (pn->_con) {
 906     case TypeFunc::Control:
 907       {
 908         // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
 909         projs->fallthrough_proj = pn;
 910         const Node* cn = pn->unique_ctrl_out_or_null();
 911         if (cn != NULL && cn->is_Catch()) {
 912           ProjNode *cpn = NULL;
 913           for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
 914             cpn = cn->fast_out(k)->as_Proj();
 915             assert(cpn->is_CatchProj(), "must be a CatchProjNode");
 916             if (cpn->_con == CatchProjNode::fall_through_index)
 917               projs->fallthrough_catchproj = cpn;
 918             else {
 919               assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
 920               projs->catchall_catchproj = cpn;
 921             }
 922           }
 923         }
 924         break;
 925       }
 926     case TypeFunc::I_O:
 927       if (pn->_is_io_use)
 928         projs->catchall_ioproj = pn;
 929       else
 930         projs->fallthrough_ioproj = pn;
 931       for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
 932         Node* e = pn->out(j);
 933         if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
 934           assert(projs->exobj == NULL, "only one");
 935           projs->exobj = e;
 936         }
 937       }
 938       break;
 939     case TypeFunc::Memory:
 940       if (pn->_is_io_use)
 941         projs->catchall_memproj = pn;
 942       else
 943         projs->fallthrough_memproj = pn;
 944       break;
 945     case TypeFunc::Parms:
 946       projs->resproj = pn;
 947       break;
 948     default:
 949       assert(false, "unexpected projection from allocation node.");
 950     }
 951   }
 952 
 953   // The resproj may not exist because the result could be ignored
 954   // and the exception object may not exist if an exception handler
 955   // swallows the exception but all the other must exist and be found.
 956   assert(projs->fallthrough_proj      != NULL, "must be found");
 957   do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
 958   assert(!do_asserts || projs->fallthrough_catchproj != NULL, "must be found");
 959   assert(!do_asserts || projs->fallthrough_memproj   != NULL, "must be found");
 960   assert(!do_asserts || projs->fallthrough_ioproj    != NULL, "must be found");
 961   assert(!do_asserts || projs->catchall_catchproj    != NULL, "must be found");
 962   if (separate_io_proj) {
 963     assert(!do_asserts || projs->catchall_memproj    != NULL, "must be found");
 964     assert(!do_asserts || projs->catchall_ioproj     != NULL, "must be found");
 965   }
 966 }
 967 
 968 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 969 #ifdef ASSERT
 970   // Validate attached generator
 971   CallGenerator* cg = generator();
 972   if (cg != NULL) {
 973     assert(is_CallStaticJava()  && cg->is_mh_late_inline() ||
 974            is_CallDynamicJava() && cg->is_virtual_late_inline(), "mismatch");
 975   }
 976 #endif // ASSERT
 977   return SafePointNode::Ideal(phase, can_reshape);
 978 }
 979 
 980 bool CallNode::is_call_to_arraycopystub() const {
 981   if (_name != NULL && strstr(_name, "arraycopy") != 0) {
 982     return true;
 983   }
 984   return false;
 985 }
 986 
 987 //=============================================================================
 988 uint CallJavaNode::size_of() const { return sizeof(*this); }
 989 bool CallJavaNode::cmp( const Node &n ) const {
 990   CallJavaNode &call = (CallJavaNode&)n;
 991   return CallNode::cmp(call) && _method == call._method &&
 992          _override_symbolic_info == call._override_symbolic_info;
 993 }
 994 
 995 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
 996   // Copy debug information and adjust JVMState information
 997   uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
 998   uint new_dbg_start = tf()->domain()->cnt();
 999   int jvms_adj  = new_dbg_start - old_dbg_start;
1000   assert (new_dbg_start == req(), "argument count mismatch");
1001   Compile* C = phase->C;
1002 
1003   // SafePointScalarObject node could be referenced several times in debug info.
1004   // Use Dict to record cloned nodes.
1005   Dict* sosn_map = new Dict(cmpkey,hashkey);
1006   for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1007     Node* old_in = sfpt->in(i);
1008     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1009     if (old_in != NULL && old_in->is_SafePointScalarObject()) {
1010       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1011       bool new_node;
1012       Node* new_in = old_sosn->clone(sosn_map, new_node);
1013       if (new_node) { // New node?
1014         new_in->set_req(0, C->root()); // reset control edge
1015         new_in = phase->transform(new_in); // Register new node.
1016       }
1017       old_in = new_in;
1018     }
1019     add_req(old_in);
1020   }
1021 
1022   // JVMS may be shared so clone it before we modify it
1023   set_jvms(sfpt->jvms() != NULL ? sfpt->jvms()->clone_deep(C) : NULL);
1024   for (JVMState *jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
1025     jvms->set_map(this);
1026     jvms->set_locoff(jvms->locoff()+jvms_adj);
1027     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1028     jvms->set_monoff(jvms->monoff()+jvms_adj);
1029     jvms->set_scloff(jvms->scloff()+jvms_adj);
1030     jvms->set_endoff(jvms->endoff()+jvms_adj);
1031   }
1032 }
1033 
1034 #ifdef ASSERT
1035 bool CallJavaNode::validate_symbolic_info() const {
1036   if (method() == NULL) {
1037     return true; // call into runtime or uncommon trap
1038   }
1039   ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1040   ciMethod* callee = method();
1041   if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1042     assert(override_symbolic_info(), "should be set");
1043   }
1044   assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1045   return true;
1046 }
1047 #endif
1048 
1049 #ifndef PRODUCT
1050 void CallJavaNode::dump_spec(outputStream* st) const {
1051   if( _method ) _method->print_short_name(st);
1052   CallNode::dump_spec(st);
1053 }
1054 
1055 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1056   if (_method) {
1057     _method->print_short_name(st);
1058   } else {
1059     st->print("<?>");
1060   }
1061 }
1062 #endif
1063 
1064 //=============================================================================
1065 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1066 bool CallStaticJavaNode::cmp( const Node &n ) const {
1067   CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1068   return CallJavaNode::cmp(call);
1069 }
1070 
1071 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1072   CallGenerator* cg = generator();
1073   if (can_reshape && cg != NULL) {
1074     assert(IncrementalInlineMH, "required");
1075     assert(cg->call_node() == this, "mismatch");
1076     assert(cg->is_mh_late_inline(), "not virtual");
1077 
1078     // Check whether this MH handle call becomes a candidate for inlining.
1079     ciMethod* callee = cg->method();
1080     vmIntrinsics::ID iid = callee->intrinsic_id();
1081     if (iid == vmIntrinsics::_invokeBasic) {
1082       if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1083         phase->C->prepend_late_inline(cg);
1084         set_generator(NULL);
1085       }
1086     } else if (iid == vmIntrinsics::_linkToNative) {
1087       Node* nep_node = in(TypeFunc::Parms + callee->arg_size() - 1);
1088       if (nep_node->Opcode() == Op_ConP /* NEP */
1089           && in(TypeFunc::Parms + 0)->Opcode() == Op_ConL /* address */
1090           && !nep_node->bottom_type()->is_oopptr()->const_oop()->as_native_entry_point()->need_transition()) {
1091         phase->C->prepend_late_inline(cg);
1092         set_generator(NULL);
1093       }
1094     } else {
1095       assert(callee->has_member_arg(), "wrong type of call?");
1096       if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1097         phase->C->prepend_late_inline(cg);
1098         set_generator(NULL);
1099       }
1100     }
1101   }
1102   return CallNode::Ideal(phase, can_reshape);
1103 }
1104 
1105 //----------------------------uncommon_trap_request----------------------------
1106 // If this is an uncommon trap, return the request code, else zero.
1107 int CallStaticJavaNode::uncommon_trap_request() const {
1108   if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
1109     return extract_uncommon_trap_request(this);
1110   }
1111   return 0;
1112 }
1113 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1114 #ifndef PRODUCT
1115   if (!(call->req() > TypeFunc::Parms &&
1116         call->in(TypeFunc::Parms) != NULL &&
1117         call->in(TypeFunc::Parms)->is_Con() &&
1118         call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1119     assert(in_dump() != 0, "OK if dumping");
1120     tty->print("[bad uncommon trap]");
1121     return 0;
1122   }
1123 #endif
1124   return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1125 }
1126 
1127 #ifndef PRODUCT
1128 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1129   st->print("# Static ");
1130   if (_name != NULL) {
1131     st->print("%s", _name);
1132     int trap_req = uncommon_trap_request();
1133     if (trap_req != 0) {
1134       char buf[100];
1135       st->print("(%s)",
1136                  Deoptimization::format_trap_request(buf, sizeof(buf),
1137                                                      trap_req));
1138     }
1139     st->print(" ");
1140   }
1141   CallJavaNode::dump_spec(st);
1142 }
1143 
1144 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1145   if (_method) {
1146     _method->print_short_name(st);
1147   } else if (_name) {
1148     st->print("%s", _name);
1149   } else {
1150     st->print("<?>");
1151   }
1152 }
1153 #endif
1154 
1155 //=============================================================================
1156 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
1157 bool CallDynamicJavaNode::cmp( const Node &n ) const {
1158   CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
1159   return CallJavaNode::cmp(call);
1160 }
1161 
1162 Node* CallDynamicJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1163   CallGenerator* cg = generator();
1164   if (can_reshape && cg != NULL) {
1165     assert(IncrementalInlineVirtual, "required");
1166     assert(cg->call_node() == this, "mismatch");
1167     assert(cg->is_virtual_late_inline(), "not virtual");
1168 
1169     // Recover symbolic info for method resolution.
1170     ciMethod* caller = jvms()->method();
1171     ciBytecodeStream iter(caller);
1172     iter.force_bci(jvms()->bci());
1173 
1174     bool             not_used1;
1175     ciSignature*     not_used2;
1176     ciMethod*        orig_callee  = iter.get_method(not_used1, &not_used2);  // callee in the bytecode
1177     ciKlass*         holder       = iter.get_declared_method_holder();
1178     if (orig_callee->is_method_handle_intrinsic()) {
1179       assert(_override_symbolic_info, "required");
1180       orig_callee = method();
1181       holder = method()->holder();
1182     }
1183 
1184     ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1185 
1186     Node* receiver_node = in(TypeFunc::Parms);
1187     const TypeOopPtr* receiver_type = phase->type(receiver_node)->isa_oopptr();
1188 
1189     int  not_used3;
1190     bool call_does_dispatch;
1191     ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true /*is_virtual*/,
1192                                                        call_does_dispatch, not_used3);  // out-parameters
1193     if (!call_does_dispatch) {
1194       // Register for late inlining.
1195       cg->set_callee_method(callee);
1196       phase->C->prepend_late_inline(cg); // MH late inlining prepends to the list, so do the same
1197       set_generator(NULL);
1198     }
1199   }
1200   return CallNode::Ideal(phase, can_reshape);
1201 }
1202 
1203 #ifndef PRODUCT
1204 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
1205   st->print("# Dynamic ");
1206   CallJavaNode::dump_spec(st);
1207 }
1208 #endif
1209 
1210 //=============================================================================
1211 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1212 bool CallRuntimeNode::cmp( const Node &n ) const {
1213   CallRuntimeNode &call = (CallRuntimeNode&)n;
1214   return CallNode::cmp(call) && !strcmp(_name,call._name);
1215 }
1216 #ifndef PRODUCT
1217 void CallRuntimeNode::dump_spec(outputStream *st) const {
1218   st->print("# ");
1219   st->print("%s", _name);
1220   CallNode::dump_spec(st);
1221 }
1222 #endif
1223 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1224 bool CallLeafVectorNode::cmp( const Node &n ) const {
1225   CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1226   return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1227 }
1228 
1229 //=============================================================================
1230 uint CallNativeNode::size_of() const { return sizeof(*this); }
1231 bool CallNativeNode::cmp( const Node &n ) const {
1232   CallNativeNode &call = (CallNativeNode&)n;
1233   return CallNode::cmp(call) && !strcmp(_name,call._name)
1234     && _arg_regs == call._arg_regs && _ret_regs == call._ret_regs;
1235 }
1236 Node* CallNativeNode::match(const ProjNode *proj, const Matcher *matcher) {
1237   switch (proj->_con) {
1238     case TypeFunc::Control:
1239     case TypeFunc::I_O:
1240     case TypeFunc::Memory:
1241       return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
1242     case TypeFunc::ReturnAdr:
1243     case TypeFunc::FramePtr:
1244       ShouldNotReachHere();
1245     case TypeFunc::Parms: {
1246       const Type* field_at_con = tf()->range()->field_at(proj->_con);
1247       const BasicType bt = field_at_con->basic_type();
1248       OptoReg::Name optoreg = OptoReg::as_OptoReg(_ret_regs.at(proj->_con - TypeFunc::Parms));
1249       OptoRegPair regs;
1250       if (bt == T_DOUBLE || bt == T_LONG) {
1251         regs.set2(optoreg);
1252       } else {
1253         regs.set1(optoreg);
1254       }
1255       RegMask rm = RegMask(regs.first());
1256       if(OptoReg::is_valid(regs.second()))
1257         rm.Insert(regs.second());
1258       return new MachProjNode(this, proj->_con, rm, field_at_con->ideal_reg());
1259     }
1260     case TypeFunc::Parms + 1: {
1261       assert(tf()->range()->field_at(proj->_con) == Type::HALF, "Expected HALF");
1262       assert(_ret_regs.at(proj->_con - TypeFunc::Parms) == VMRegImpl::Bad(), "Unexpected register for Type::HALF");
1263       // 2nd half of doubles and longs
1264       return new MachProjNode(this, proj->_con, RegMask::Empty, (uint) OptoReg::Bad);
1265     }
1266     default:
1267       ShouldNotReachHere();
1268   }
1269   return NULL;
1270 }
1271 #ifndef PRODUCT
1272 void CallNativeNode::print_regs(const GrowableArray<VMReg>& regs, outputStream* st) {
1273   st->print("{ ");
1274   for (int i = 0; i < regs.length(); i++) {
1275     regs.at(i)->print_on(st);
1276     if (i < regs.length() - 1) {
1277       st->print(", ");
1278     }
1279   }
1280   st->print(" } ");
1281 }
1282 
1283 void CallNativeNode::dump_spec(outputStream *st) const {
1284   st->print("# ");
1285   st->print("%s ", _name);
1286   st->print("_arg_regs: ");
1287   print_regs(_arg_regs, st);
1288   st->print("_ret_regs: ");
1289   print_regs(_ret_regs, st);
1290   CallNode::dump_spec(st);
1291 }
1292 #endif
1293 
1294 //------------------------------calling_convention-----------------------------
1295 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1296   SharedRuntime::c_calling_convention(sig_bt, parm_regs, /*regs2=*/nullptr, argcnt);
1297 }
1298 
1299 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1300 #ifdef ASSERT
1301   assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1302          "return vector size must match");
1303   const TypeTuple* d = tf()->domain();
1304   for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1305     Node* arg = in(i);
1306     assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1307            "vector argument size must match");
1308   }
1309 #endif
1310 
1311   SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1312 }
1313 
1314 void CallNativeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1315   assert((tf()->domain()->cnt() - TypeFunc::Parms) == argcnt, "arg counts must match!");
1316 #ifdef ASSERT
1317   for (uint i = 0; i < argcnt; i++) {
1318     assert(tf()->domain()->field_at(TypeFunc::Parms + i)->basic_type() == sig_bt[i], "types must match!");
1319   }
1320 #endif
1321   for (uint i = 0; i < argcnt; i++) {
1322     switch (sig_bt[i]) {
1323       case T_BOOLEAN:
1324       case T_CHAR:
1325       case T_BYTE:
1326       case T_SHORT:
1327       case T_INT:
1328       case T_FLOAT:
1329         parm_regs[i].set1(_arg_regs.at(i));
1330         break;
1331       case T_LONG:
1332       case T_DOUBLE:
1333         assert((i + 1) < argcnt && sig_bt[i + 1] == T_VOID, "expecting half");
1334         parm_regs[i].set2(_arg_regs.at(i));
1335         break;
1336       case T_VOID: // Halves of longs and doubles
1337         assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
1338         assert(_arg_regs.at(i) == VMRegImpl::Bad(), "expecting bad reg");
1339         parm_regs[i].set_bad();
1340         break;
1341       default:
1342         ShouldNotReachHere();
1343         break;
1344     }
1345   }
1346 }
1347 
1348 //=============================================================================
1349 //------------------------------calling_convention-----------------------------
1350 
1351 
1352 //=============================================================================
1353 #ifndef PRODUCT
1354 void CallLeafNode::dump_spec(outputStream *st) const {
1355   st->print("# ");
1356   st->print("%s", _name);
1357   CallNode::dump_spec(st);
1358 }
1359 #endif
1360 
1361 //=============================================================================
1362 
1363 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1364   assert(verify_jvms(jvms), "jvms must match");
1365   int loc = jvms->locoff() + idx;
1366   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1367     // If current local idx is top then local idx - 1 could
1368     // be a long/double that needs to be killed since top could
1369     // represent the 2nd half of the long/double.
1370     uint ideal = in(loc -1)->ideal_reg();
1371     if (ideal == Op_RegD || ideal == Op_RegL) {
1372       // set other (low index) half to top
1373       set_req(loc - 1, in(loc));
1374     }
1375   }
1376   set_req(loc, c);
1377 }
1378 
1379 uint SafePointNode::size_of() const { return sizeof(*this); }
1380 bool SafePointNode::cmp( const Node &n ) const {
1381   return (&n == this);          // Always fail except on self
1382 }
1383 
1384 //-------------------------set_next_exception----------------------------------
1385 void SafePointNode::set_next_exception(SafePointNode* n) {
1386   assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");
1387   if (len() == req()) {
1388     if (n != NULL)  add_prec(n);
1389   } else {
1390     set_prec(req(), n);
1391   }
1392 }
1393 
1394 
1395 //----------------------------next_exception-----------------------------------
1396 SafePointNode* SafePointNode::next_exception() const {
1397   if (len() == req()) {
1398     return NULL;
1399   } else {
1400     Node* n = in(req());
1401     assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1402     return (SafePointNode*) n;
1403   }
1404 }
1405 
1406 
1407 //------------------------------Ideal------------------------------------------
1408 // Skip over any collapsed Regions
1409 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1410   assert(_jvms == NULL || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1411   return remove_dead_region(phase, can_reshape) ? this : NULL;
1412 }
1413 
1414 //------------------------------Identity---------------------------------------
1415 // Remove obviously duplicate safepoints
1416 Node* SafePointNode::Identity(PhaseGVN* phase) {
1417 
1418   // If you have back to back safepoints, remove one
1419   if (in(TypeFunc::Control)->is_SafePoint()) {
1420     Node* out_c = unique_ctrl_out_or_null();
1421     // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1422     // outer loop's safepoint could confuse removal of the outer loop.
1423     if (out_c != NULL && !out_c->is_OuterStripMinedLoopEnd()) {
1424       return in(TypeFunc::Control);
1425     }
1426   }
1427 
1428   // Transforming long counted loops requires a safepoint node. Do not
1429   // eliminate a safepoint until loop opts are over.
1430   if (in(0)->is_Proj() && !phase->C->major_progress()) {
1431     Node *n0 = in(0)->in(0);
1432     // Check if he is a call projection (except Leaf Call)
1433     if( n0->is_Catch() ) {
1434       n0 = n0->in(0)->in(0);
1435       assert( n0->is_Call(), "expect a call here" );
1436     }
1437     if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
1438       // Don't remove a safepoint belonging to an OuterStripMinedLoopEndNode.
1439       // If the loop dies, they will be removed together.
1440       if (has_out_with(Op_OuterStripMinedLoopEnd)) {
1441         return this;
1442       }
1443       // Useless Safepoint, so remove it
1444       return in(TypeFunc::Control);
1445     }
1446   }
1447 
1448   return this;
1449 }
1450 
1451 //------------------------------Value------------------------------------------
1452 const Type* SafePointNode::Value(PhaseGVN* phase) const {
1453   if (phase->type(in(0)) == Type::TOP) {
1454     return Type::TOP;
1455   }
1456   if (in(0) == this) {
1457     return Type::TOP; // Dead infinite loop
1458   }
1459   return Type::CONTROL;
1460 }
1461 
1462 #ifndef PRODUCT
1463 void SafePointNode::dump_spec(outputStream *st) const {
1464   st->print(" SafePoint ");
1465   _replaced_nodes.dump(st);
1466 }
1467 
1468 // The related nodes of a SafepointNode are all data inputs, excluding the
1469 // control boundary, as well as all outputs till level 2 (to include projection
1470 // nodes and targets). In compact mode, just include inputs till level 1 and
1471 // outputs as before.
1472 void SafePointNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
1473   if (compact) {
1474     this->collect_nodes(in_rel, 1, false, false);
1475   } else {
1476     this->collect_nodes_in_all_data(in_rel, false);
1477   }
1478   this->collect_nodes(out_rel, -2, false, false);
1479 }
1480 #endif
1481 
1482 const RegMask &SafePointNode::in_RegMask(uint idx) const {
1483   if( idx < TypeFunc::Parms ) return RegMask::Empty;
1484   // Values outside the domain represent debug info
1485   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1486 }
1487 const RegMask &SafePointNode::out_RegMask() const {
1488   return RegMask::Empty;
1489 }
1490 
1491 
1492 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
1493   assert((int)grow_by > 0, "sanity");
1494   int monoff = jvms->monoff();
1495   int scloff = jvms->scloff();
1496   int endoff = jvms->endoff();
1497   assert(endoff == (int)req(), "no other states or debug info after me");
1498   Node* top = Compile::current()->top();
1499   for (uint i = 0; i < grow_by; i++) {
1500     ins_req(monoff, top);
1501   }
1502   jvms->set_monoff(monoff + grow_by);
1503   jvms->set_scloff(scloff + grow_by);
1504   jvms->set_endoff(endoff + grow_by);
1505 }
1506 
1507 void SafePointNode::push_monitor(const FastLockNode *lock) {
1508   // Add a LockNode, which points to both the original BoxLockNode (the
1509   // stack space for the monitor) and the Object being locked.
1510   const int MonitorEdges = 2;
1511   assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1512   assert(req() == jvms()->endoff(), "correct sizing");
1513   int nextmon = jvms()->scloff();
1514   if (GenerateSynchronizationCode) {
1515     ins_req(nextmon,   lock->box_node());
1516     ins_req(nextmon+1, lock->obj_node());
1517   } else {
1518     Node* top = Compile::current()->top();
1519     ins_req(nextmon, top);
1520     ins_req(nextmon, top);
1521   }
1522   jvms()->set_scloff(nextmon + MonitorEdges);
1523   jvms()->set_endoff(req());
1524 }
1525 
1526 void SafePointNode::pop_monitor() {
1527   // Delete last monitor from debug info
1528   debug_only(int num_before_pop = jvms()->nof_monitors());
1529   const int MonitorEdges = 2;
1530   assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1531   int scloff = jvms()->scloff();
1532   int endoff = jvms()->endoff();
1533   int new_scloff = scloff - MonitorEdges;
1534   int new_endoff = endoff - MonitorEdges;
1535   jvms()->set_scloff(new_scloff);
1536   jvms()->set_endoff(new_endoff);
1537   while (scloff > new_scloff)  del_req_ordered(--scloff);
1538   assert(jvms()->nof_monitors() == num_before_pop-1, "");
1539 }
1540 
1541 Node *SafePointNode::peek_monitor_box() const {
1542   int mon = jvms()->nof_monitors() - 1;
1543   assert(mon >= 0, "must have a monitor");
1544   return monitor_box(jvms(), mon);
1545 }
1546 
1547 Node *SafePointNode::peek_monitor_obj() const {
1548   int mon = jvms()->nof_monitors() - 1;
1549   assert(mon >= 0, "must have a monitor");
1550   return monitor_obj(jvms(), mon);
1551 }
1552 
1553 // Do we Match on this edge index or not?  Match no edges
1554 uint SafePointNode::match_edge(uint idx) const {
1555   return (TypeFunc::Parms == idx);
1556 }
1557 
1558 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1559   assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1560   int nb = igvn->C->root()->find_prec_edge(this);
1561   if (nb != -1) {
1562     igvn->C->root()->rm_prec(nb);
1563   }
1564 }
1565 
1566 //==============  SafePointScalarObjectNode  ==============
1567 
1568 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,
1569 #ifdef ASSERT
1570                                                      Node* alloc,
1571 #endif
1572                                                      uint first_index,
1573                                                      uint n_fields) :
1574   TypeNode(tp, 1), // 1 control input -- seems required.  Get from root.
1575   _first_index(first_index),
1576   _n_fields(n_fields)
1577 #ifdef ASSERT
1578   , _alloc(alloc)
1579 #endif
1580 {
1581 #ifdef ASSERT
1582   if (!alloc->is_Allocate()
1583       && !(alloc->Opcode() == Op_VectorBox)) {
1584     alloc->dump();
1585     assert(false, "unexpected call node");
1586   }
1587 #endif
1588   init_class_id(Class_SafePointScalarObject);
1589 }
1590 
1591 // Do not allow value-numbering for SafePointScalarObject node.
1592 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1593 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1594   return (&n == this); // Always fail except on self
1595 }
1596 
1597 uint SafePointScalarObjectNode::ideal_reg() const {
1598   return 0; // No matching to machine instruction
1599 }
1600 
1601 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1602   return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1603 }
1604 
1605 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
1606   return RegMask::Empty;
1607 }
1608 
1609 uint SafePointScalarObjectNode::match_edge(uint idx) const {
1610   return 0;
1611 }
1612 
1613 SafePointScalarObjectNode*
1614 SafePointScalarObjectNode::clone(Dict* sosn_map, bool& new_node) const {
1615   void* cached = (*sosn_map)[(void*)this];
1616   if (cached != NULL) {
1617     new_node = false;
1618     return (SafePointScalarObjectNode*)cached;
1619   }
1620   new_node = true;
1621   SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
1622   sosn_map->Insert((void*)this, (void*)res);
1623   return res;
1624 }
1625 
1626 
1627 #ifndef PRODUCT
1628 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
1629   st->print(" # fields@[%d..%d]", first_index(),
1630              first_index() + n_fields() - 1);
1631 }
1632 
1633 #endif
1634 
1635 //=============================================================================
1636 uint AllocateNode::size_of() const { return sizeof(*this); }
1637 
1638 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1639                            Node *ctrl, Node *mem, Node *abio,
1640                            Node *size, Node *klass_node, Node *initial_test)
1641   : CallNode(atype, NULL, TypeRawPtr::BOTTOM)
1642 {
1643   init_class_id(Class_Allocate);
1644   init_flags(Flag_is_macro);
1645   _is_scalar_replaceable = false;
1646   _is_non_escaping = false;
1647   _is_allocation_MemBar_redundant = false;
1648   Node *topnode = C->top();
1649 
1650   init_req( TypeFunc::Control  , ctrl );
1651   init_req( TypeFunc::I_O      , abio );
1652   init_req( TypeFunc::Memory   , mem );
1653   init_req( TypeFunc::ReturnAdr, topnode );
1654   init_req( TypeFunc::FramePtr , topnode );
1655   init_req( AllocSize          , size);
1656   init_req( KlassNode          , klass_node);
1657   init_req( InitialTest        , initial_test);
1658   init_req( ALength            , topnode);
1659   init_req( ValidLengthTest    , topnode);
1660   C->add_macro_node(this);
1661 }
1662 
1663 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1664 {
1665   assert(initializer != NULL &&
1666          initializer->is_initializer() &&
1667          !initializer->is_static(),
1668              "unexpected initializer method");
1669   BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1670   if (analyzer == NULL) {
1671     return;
1672   }
1673 
1674   // Allocation node is first parameter in its initializer
1675   if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1676     _is_allocation_MemBar_redundant = true;
1677   }
1678 }
1679 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1680   Node* mark_node = NULL;
1681   // For now only enable fast locking for non-array types
1682   mark_node = phase->MakeConX(markWord::prototype().value());
1683   return mark_node;
1684 }
1685 
1686 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1687 // CastII, if appropriate.  If we are not allowed to create new nodes, and
1688 // a CastII is appropriate, return NULL.
1689 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {
1690   Node *length = in(AllocateNode::ALength);
1691   assert(length != NULL, "length is not null");
1692 
1693   const TypeInt* length_type = phase->find_int_type(length);
1694   const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1695 
1696   if (ary_type != NULL && length_type != NULL) {
1697     const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1698     if (narrow_length_type != length_type) {
1699       // Assert one of:
1700       //   - the narrow_length is 0
1701       //   - the narrow_length is not wider than length
1702       assert(narrow_length_type == TypeInt::ZERO ||
1703              length_type->is_con() && narrow_length_type->is_con() &&
1704                 (narrow_length_type->_hi <= length_type->_lo) ||
1705              (narrow_length_type->_hi <= length_type->_hi &&
1706               narrow_length_type->_lo >= length_type->_lo),
1707              "narrow type must be narrower than length type");
1708 
1709       // Return NULL if new nodes are not allowed
1710       if (!allow_new_nodes) return NULL;
1711       // Create a cast which is control dependent on the initialization to
1712       // propagate the fact that the array length must be positive.
1713       InitializeNode* init = initialization();
1714       assert(init != NULL, "initialization not found");
1715       length = new CastIINode(length, narrow_length_type);
1716       length->set_req(TypeFunc::Control, init->proj_out_or_null(TypeFunc::Control));
1717     }
1718   }
1719 
1720   return length;
1721 }
1722 
1723 //=============================================================================
1724 uint LockNode::size_of() const { return sizeof(*this); }
1725 
1726 // Redundant lock elimination
1727 //
1728 // There are various patterns of locking where we release and
1729 // immediately reacquire a lock in a piece of code where no operations
1730 // occur in between that would be observable.  In those cases we can
1731 // skip releasing and reacquiring the lock without violating any
1732 // fairness requirements.  Doing this around a loop could cause a lock
1733 // to be held for a very long time so we concentrate on non-looping
1734 // control flow.  We also require that the operations are fully
1735 // redundant meaning that we don't introduce new lock operations on
1736 // some paths so to be able to eliminate it on others ala PRE.  This
1737 // would probably require some more extensive graph manipulation to
1738 // guarantee that the memory edges were all handled correctly.
1739 //
1740 // Assuming p is a simple predicate which can't trap in any way and s
1741 // is a synchronized method consider this code:
1742 //
1743 //   s();
1744 //   if (p)
1745 //     s();
1746 //   else
1747 //     s();
1748 //   s();
1749 //
1750 // 1. The unlocks of the first call to s can be eliminated if the
1751 // locks inside the then and else branches are eliminated.
1752 //
1753 // 2. The unlocks of the then and else branches can be eliminated if
1754 // the lock of the final call to s is eliminated.
1755 //
1756 // Either of these cases subsumes the simple case of sequential control flow
1757 //
1758 // Additionally we can eliminate versions without the else case:
1759 //
1760 //   s();
1761 //   if (p)
1762 //     s();
1763 //   s();
1764 //
1765 // 3. In this case we eliminate the unlock of the first s, the lock
1766 // and unlock in the then case and the lock in the final s.
1767 //
1768 // Note also that in all these cases the then/else pieces don't have
1769 // to be trivial as long as they begin and end with synchronization
1770 // operations.
1771 //
1772 //   s();
1773 //   if (p)
1774 //     s();
1775 //     f();
1776 //     s();
1777 //   s();
1778 //
1779 // The code will work properly for this case, leaving in the unlock
1780 // before the call to f and the relock after it.
1781 //
1782 // A potentially interesting case which isn't handled here is when the
1783 // locking is partially redundant.
1784 //
1785 //   s();
1786 //   if (p)
1787 //     s();
1788 //
1789 // This could be eliminated putting unlocking on the else case and
1790 // eliminating the first unlock and the lock in the then side.
1791 // Alternatively the unlock could be moved out of the then side so it
1792 // was after the merge and the first unlock and second lock
1793 // eliminated.  This might require less manipulation of the memory
1794 // state to get correct.
1795 //
1796 // Additionally we might allow work between a unlock and lock before
1797 // giving up eliminating the locks.  The current code disallows any
1798 // conditional control flow between these operations.  A formulation
1799 // similar to partial redundancy elimination computing the
1800 // availability of unlocking and the anticipatability of locking at a
1801 // program point would allow detection of fully redundant locking with
1802 // some amount of work in between.  I'm not sure how often I really
1803 // think that would occur though.  Most of the cases I've seen
1804 // indicate it's likely non-trivial work would occur in between.
1805 // There may be other more complicated constructs where we could
1806 // eliminate locking but I haven't seen any others appear as hot or
1807 // interesting.
1808 //
1809 // Locking and unlocking have a canonical form in ideal that looks
1810 // roughly like this:
1811 //
1812 //              <obj>
1813 //                | \\------+
1814 //                |  \       \
1815 //                | BoxLock   \
1816 //                |  |   |     \
1817 //                |  |    \     \
1818 //                |  |   FastLock
1819 //                |  |   /
1820 //                |  |  /
1821 //                |  |  |
1822 //
1823 //               Lock
1824 //                |
1825 //            Proj #0
1826 //                |
1827 //            MembarAcquire
1828 //                |
1829 //            Proj #0
1830 //
1831 //            MembarRelease
1832 //                |
1833 //            Proj #0
1834 //                |
1835 //              Unlock
1836 //                |
1837 //            Proj #0
1838 //
1839 //
1840 // This code proceeds by processing Lock nodes during PhaseIterGVN
1841 // and searching back through its control for the proper code
1842 // patterns.  Once it finds a set of lock and unlock operations to
1843 // eliminate they are marked as eliminatable which causes the
1844 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
1845 //
1846 //=============================================================================
1847 
1848 //
1849 // Utility function to skip over uninteresting control nodes.  Nodes skipped are:
1850 //   - copy regions.  (These may not have been optimized away yet.)
1851 //   - eliminated locking nodes
1852 //
1853 static Node *next_control(Node *ctrl) {
1854   if (ctrl == NULL)
1855     return NULL;
1856   while (1) {
1857     if (ctrl->is_Region()) {
1858       RegionNode *r = ctrl->as_Region();
1859       Node *n = r->is_copy();
1860       if (n == NULL)
1861         break;  // hit a region, return it
1862       else
1863         ctrl = n;
1864     } else if (ctrl->is_Proj()) {
1865       Node *in0 = ctrl->in(0);
1866       if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
1867         ctrl = in0->in(0);
1868       } else {
1869         break;
1870       }
1871     } else {
1872       break; // found an interesting control
1873     }
1874   }
1875   return ctrl;
1876 }
1877 //
1878 // Given a control, see if it's the control projection of an Unlock which
1879 // operating on the same object as lock.
1880 //
1881 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1882                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1883   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
1884   if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
1885     Node *n = ctrl_proj->in(0);
1886     if (n != NULL && n->is_Unlock()) {
1887       UnlockNode *unlock = n->as_Unlock();
1888       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1889       Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1890       Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1891       if (lock_obj->eqv_uncast(unlock_obj) &&
1892           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1893           !unlock->is_eliminated()) {
1894         lock_ops.append(unlock);
1895         return true;
1896       }
1897     }
1898   }
1899   return false;
1900 }
1901 
1902 //
1903 // Find the lock matching an unlock.  Returns null if a safepoint
1904 // or complicated control is encountered first.
1905 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1906   LockNode *lock_result = NULL;
1907   // find the matching lock, or an intervening safepoint
1908   Node *ctrl = next_control(unlock->in(0));
1909   while (1) {
1910     assert(ctrl != NULL, "invalid control graph");
1911     assert(!ctrl->is_Start(), "missing lock for unlock");
1912     if (ctrl->is_top()) break;  // dead control path
1913     if (ctrl->is_Proj()) ctrl = ctrl->in(0);
1914     if (ctrl->is_SafePoint()) {
1915         break;  // found a safepoint (may be the lock we are searching for)
1916     } else if (ctrl->is_Region()) {
1917       // Check for a simple diamond pattern.  Punt on anything more complicated
1918       if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
1919         Node *in1 = next_control(ctrl->in(1));
1920         Node *in2 = next_control(ctrl->in(2));
1921         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1922              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1923           ctrl = next_control(in1->in(0)->in(0));
1924         } else {
1925           break;
1926         }
1927       } else {
1928         break;
1929       }
1930     } else {
1931       ctrl = next_control(ctrl->in(0));  // keep searching
1932     }
1933   }
1934   if (ctrl->is_Lock()) {
1935     LockNode *lock = ctrl->as_Lock();
1936     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1937     Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1938     Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1939     if (lock_obj->eqv_uncast(unlock_obj) &&
1940         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1941       lock_result = lock;
1942     }
1943   }
1944   return lock_result;
1945 }
1946 
1947 // This code corresponds to case 3 above.
1948 
1949 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1950                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
1951   Node* if_node = node->in(0);
1952   bool  if_true = node->is_IfTrue();
1953 
1954   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1955     Node *lock_ctrl = next_control(if_node->in(0));
1956     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1957       Node* lock1_node = NULL;
1958       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1959       if (if_true) {
1960         if (proj->is_IfFalse() && proj->outcnt() == 1) {
1961           lock1_node = proj->unique_out();
1962         }
1963       } else {
1964         if (proj->is_IfTrue() && proj->outcnt() == 1) {
1965           lock1_node = proj->unique_out();
1966         }
1967       }
1968       if (lock1_node != NULL && lock1_node->is_Lock()) {
1969         LockNode *lock1 = lock1_node->as_Lock();
1970         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1971         Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1972         Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
1973         if (lock_obj->eqv_uncast(lock1_obj) &&
1974             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1975             !lock1->is_eliminated()) {
1976           lock_ops.append(lock1);
1977           return true;
1978         }
1979       }
1980     }
1981   }
1982 
1983   lock_ops.trunc_to(0);
1984   return false;
1985 }
1986 
1987 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1988                                GrowableArray<AbstractLockNode*> &lock_ops) {
1989   // check each control merging at this point for a matching unlock.
1990   // in(0) should be self edge so skip it.
1991   for (int i = 1; i < (int)region->req(); i++) {
1992     Node *in_node = next_control(region->in(i));
1993     if (in_node != NULL) {
1994       if (find_matching_unlock(in_node, lock, lock_ops)) {
1995         // found a match so keep on checking.
1996         continue;
1997       } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
1998         continue;
1999       }
2000 
2001       // If we fall through to here then it was some kind of node we
2002       // don't understand or there wasn't a matching unlock, so give
2003       // up trying to merge locks.
2004       lock_ops.trunc_to(0);
2005       return false;
2006     }
2007   }
2008   return true;
2009 
2010 }
2011 
2012 const char* AbstractLockNode::_kind_names[] = {"Regular", "NonEscObj", "Coarsened", "Nested"};
2013 
2014 const char * AbstractLockNode::kind_as_string() const {
2015   return _kind_names[_kind];
2016 }
2017 
2018 #ifndef PRODUCT
2019 //
2020 // Create a counter which counts the number of times this lock is acquired
2021 //
2022 void AbstractLockNode::create_lock_counter(JVMState* state) {
2023   _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
2024 }
2025 
2026 void AbstractLockNode::set_eliminated_lock_counter() {
2027   if (_counter) {
2028     // Update the counter to indicate that this lock was eliminated.
2029     // The counter update code will stay around even though the
2030     // optimizer will eliminate the lock operation itself.
2031     _counter->set_tag(NamedCounter::EliminatedLockCounter);
2032   }
2033 }
2034 
2035 void AbstractLockNode::dump_spec(outputStream* st) const {
2036   st->print("%s ", _kind_names[_kind]);
2037   CallNode::dump_spec(st);
2038 }
2039 
2040 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2041   st->print("%s", _kind_names[_kind]);
2042 }
2043 
2044 // The related set of lock nodes includes the control boundary.
2045 void AbstractLockNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
2046   if (compact) {
2047       this->collect_nodes(in_rel, 1, false, false);
2048     } else {
2049       this->collect_nodes_in_all_data(in_rel, true);
2050     }
2051     this->collect_nodes(out_rel, -2, false, false);
2052 }
2053 #endif
2054 
2055 //=============================================================================
2056 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2057 
2058   // perform any generic optimizations first (returns 'this' or NULL)
2059   Node *result = SafePointNode::Ideal(phase, can_reshape);
2060   if (result != NULL)  return result;
2061   // Don't bother trying to transform a dead node
2062   if (in(0) && in(0)->is_top())  return NULL;
2063 
2064   // Now see if we can optimize away this lock.  We don't actually
2065   // remove the locking here, we simply set the _eliminate flag which
2066   // prevents macro expansion from expanding the lock.  Since we don't
2067   // modify the graph, the value returned from this function is the
2068   // one computed above.
2069   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2070     //
2071     // If we are locking an non-escaped object, the lock/unlock is unnecessary
2072     //
2073     ConnectionGraph *cgr = phase->C->congraph();
2074     if (cgr != NULL && cgr->not_global_escape(obj_node())) {
2075       assert(!is_eliminated() || is_coarsened(), "sanity");
2076       // The lock could be marked eliminated by lock coarsening
2077       // code during first IGVN before EA. Replace coarsened flag
2078       // to eliminate all associated locks/unlocks.
2079 #ifdef ASSERT
2080       this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2081 #endif
2082       this->set_non_esc_obj();
2083       return result;
2084     }
2085 
2086     if (!phase->C->do_locks_coarsening()) {
2087       return result; // Compiling without locks coarsening
2088     }
2089     //
2090     // Try lock coarsening
2091     //
2092     PhaseIterGVN* iter = phase->is_IterGVN();
2093     if (iter != NULL && !is_eliminated()) {
2094 
2095       GrowableArray<AbstractLockNode*>   lock_ops;
2096 
2097       Node *ctrl = next_control(in(0));
2098 
2099       // now search back for a matching Unlock
2100       if (find_matching_unlock(ctrl, this, lock_ops)) {
2101         // found an unlock directly preceding this lock.  This is the
2102         // case of single unlock directly control dependent on a
2103         // single lock which is the trivial version of case 1 or 2.
2104       } else if (ctrl->is_Region() ) {
2105         if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
2106         // found lock preceded by multiple unlocks along all paths
2107         // joining at this point which is case 3 in description above.
2108         }
2109       } else {
2110         // see if this lock comes from either half of an if and the
2111         // predecessors merges unlocks and the other half of the if
2112         // performs a lock.
2113         if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
2114           // found unlock splitting to an if with locks on both branches.
2115         }
2116       }
2117 
2118       if (lock_ops.length() > 0) {
2119         // add ourselves to the list of locks to be eliminated.
2120         lock_ops.append(this);
2121 
2122   #ifndef PRODUCT
2123         if (PrintEliminateLocks) {
2124           int locks = 0;
2125           int unlocks = 0;
2126           if (Verbose) {
2127             tty->print_cr("=== Locks coarsening ===");
2128           }
2129           for (int i = 0; i < lock_ops.length(); i++) {
2130             AbstractLockNode* lock = lock_ops.at(i);
2131             if (lock->Opcode() == Op_Lock)
2132               locks++;
2133             else
2134               unlocks++;
2135             if (Verbose) {
2136               tty->print(" %d: ", i);
2137               lock->dump();
2138             }
2139           }
2140           tty->print_cr("=== Coarsened %d unlocks and %d locks", unlocks, locks);
2141         }
2142   #endif
2143 
2144         // for each of the identified locks, mark them
2145         // as eliminatable
2146         for (int i = 0; i < lock_ops.length(); i++) {
2147           AbstractLockNode* lock = lock_ops.at(i);
2148 
2149           // Mark it eliminated by coarsening and update any counters
2150 #ifdef ASSERT
2151           lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");
2152 #endif
2153           lock->set_coarsened();
2154         }
2155         // Record this coarsened group.
2156         phase->C->add_coarsened_locks(lock_ops);
2157       } else if (ctrl->is_Region() &&
2158                  iter->_worklist.member(ctrl)) {
2159         // We weren't able to find any opportunities but the region this
2160         // lock is control dependent on hasn't been processed yet so put
2161         // this lock back on the worklist so we can check again once any
2162         // region simplification has occurred.
2163         iter->_worklist.push(this);
2164       }
2165     }
2166   }
2167 
2168   return result;
2169 }
2170 
2171 //=============================================================================
2172 bool LockNode::is_nested_lock_region() {
2173   return is_nested_lock_region(NULL);
2174 }
2175 
2176 // p is used for access to compilation log; no logging if NULL
2177 bool LockNode::is_nested_lock_region(Compile * c) {
2178   BoxLockNode* box = box_node()->as_BoxLock();
2179   int stk_slot = box->stack_slot();
2180   if (stk_slot <= 0) {
2181 #ifdef ASSERT
2182     this->log_lock_optimization(c, "eliminate_lock_INLR_1");
2183 #endif
2184     return false; // External lock or it is not Box (Phi node).
2185   }
2186 
2187   // Ignore complex cases: merged locks or multiple locks.
2188   Node* obj = obj_node();
2189   LockNode* unique_lock = NULL;
2190   Node* bad_lock = NULL;
2191   if (!box->is_simple_lock_region(&unique_lock, obj, &bad_lock)) {
2192 #ifdef ASSERT
2193     this->log_lock_optimization(c, "eliminate_lock_INLR_2a", bad_lock);
2194 #endif
2195     return false;
2196   }
2197   if (unique_lock != this) {
2198 #ifdef ASSERT
2199     this->log_lock_optimization(c, "eliminate_lock_INLR_2b", (unique_lock != NULL ? unique_lock : bad_lock));
2200     if (PrintEliminateLocks && Verbose) {
2201       tty->print_cr("=============== unique_lock != this ============");
2202       tty->print(" this: ");
2203       this->dump();
2204       tty->print(" box: ");
2205       box->dump();
2206       tty->print(" obj: ");
2207       obj->dump();
2208       if (unique_lock != NULL) {
2209         tty->print(" unique_lock: ");
2210         unique_lock->dump();
2211       }
2212       if (bad_lock != NULL) {
2213         tty->print(" bad_lock: ");
2214         bad_lock->dump();
2215       }
2216       tty->print_cr("===============");
2217     }
2218 #endif
2219     return false;
2220   }
2221 
2222   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2223   obj = bs->step_over_gc_barrier(obj);
2224   // Look for external lock for the same object.
2225   SafePointNode* sfn = this->as_SafePoint();
2226   JVMState* youngest_jvms = sfn->jvms();
2227   int max_depth = youngest_jvms->depth();
2228   for (int depth = 1; depth <= max_depth; depth++) {
2229     JVMState* jvms = youngest_jvms->of_depth(depth);
2230     int num_mon  = jvms->nof_monitors();
2231     // Loop over monitors
2232     for (int idx = 0; idx < num_mon; idx++) {
2233       Node* obj_node = sfn->monitor_obj(jvms, idx);
2234       obj_node = bs->step_over_gc_barrier(obj_node);
2235       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2236       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2237         return true;
2238       }
2239     }
2240   }
2241 #ifdef ASSERT
2242   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2243 #endif
2244   return false;
2245 }
2246 
2247 //=============================================================================
2248 uint UnlockNode::size_of() const { return sizeof(*this); }
2249 
2250 //=============================================================================
2251 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2252 
2253   // perform any generic optimizations first (returns 'this' or NULL)
2254   Node *result = SafePointNode::Ideal(phase, can_reshape);
2255   if (result != NULL)  return result;
2256   // Don't bother trying to transform a dead node
2257   if (in(0) && in(0)->is_top())  return NULL;
2258 
2259   // Now see if we can optimize away this unlock.  We don't actually
2260   // remove the unlocking here, we simply set the _eliminate flag which
2261   // prevents macro expansion from expanding the unlock.  Since we don't
2262   // modify the graph, the value returned from this function is the
2263   // one computed above.
2264   // Escape state is defined after Parse phase.
2265   if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2266     //
2267     // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2268     //
2269     ConnectionGraph *cgr = phase->C->congraph();
2270     if (cgr != NULL && cgr->not_global_escape(obj_node())) {
2271       assert(!is_eliminated() || is_coarsened(), "sanity");
2272       // The lock could be marked eliminated by lock coarsening
2273       // code during first IGVN before EA. Replace coarsened flag
2274       // to eliminate all associated locks/unlocks.
2275 #ifdef ASSERT
2276       this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2277 #endif
2278       this->set_non_esc_obj();
2279     }
2280   }
2281   return result;
2282 }
2283 
2284 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock)  const {
2285   if (C == NULL) {
2286     return;
2287   }
2288   CompileLog* log = C->log();
2289   if (log != NULL) {
2290     Node* box = box_node();
2291     Node* obj = obj_node();
2292     int box_id = box != NULL ? box->_idx : -1;
2293     int obj_id = obj != NULL ? obj->_idx : -1;
2294 
2295     log->begin_head("%s compile_id='%d' lock_id='%d' class='%s' kind='%s' box_id='%d' obj_id='%d' bad_id='%d'",
2296           tag, C->compile_id(), this->_idx,
2297           is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",
2298           kind_as_string(), box_id, obj_id, (bad_lock != NULL ? bad_lock->_idx : -1));
2299     log->stamp();
2300     log->end_head();
2301     JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();
2302     while (p != NULL) {
2303       log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
2304       p = p->caller();
2305     }
2306     log->tail(tag);
2307   }
2308 }
2309 
2310 bool CallNode::may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr *t_oop, PhaseTransform *phase) {
2311   if (dest_t->is_known_instance() && t_oop->is_known_instance()) {
2312     return dest_t->instance_id() == t_oop->instance_id();
2313   }
2314 
2315   if (dest_t->isa_instptr() && !dest_t->klass()->equals(phase->C->env()->Object_klass())) {
2316     // clone
2317     if (t_oop->isa_aryptr()) {
2318       return false;
2319     }
2320     if (!t_oop->isa_instptr()) {
2321       return true;
2322     }
2323     if (dest_t->klass()->is_subtype_of(t_oop->klass()) || t_oop->klass()->is_subtype_of(dest_t->klass())) {
2324       return true;
2325     }
2326     // unrelated
2327     return false;
2328   }
2329 
2330   if (dest_t->isa_aryptr()) {
2331     // arraycopy or array clone
2332     if (t_oop->isa_instptr()) {
2333       return false;
2334     }
2335     if (!t_oop->isa_aryptr()) {
2336       return true;
2337     }
2338 
2339     const Type* elem = dest_t->is_aryptr()->elem();
2340     if (elem == Type::BOTTOM) {
2341       // An array but we don't know what elements are
2342       return true;
2343     }
2344 
2345     dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2346     uint dest_alias = phase->C->get_alias_index(dest_t);
2347     uint t_oop_alias = phase->C->get_alias_index(t_oop);
2348 
2349     return dest_alias == t_oop_alias;
2350   }
2351 
2352   return true;
2353 }