1 /*
   2  * Copyright (c) 2015, 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 "opto/arraycopynode.hpp"
  27 #include "opto/graphKit.hpp"
  28 
  29 ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled)
  30   : CallNode(arraycopy_type(), NULL, TypeRawPtr::BOTTOM),
  31     _alloc_tightly_coupled(alloc_tightly_coupled),
  32     _kind(None),
  33     _arguments_validated(false),
  34     _src_type(TypeOopPtr::BOTTOM),
  35     _dest_type(TypeOopPtr::BOTTOM) {
  36   init_class_id(Class_ArrayCopy);
  37   init_flags(Flag_is_macro);
  38   C->add_macro_node(this);
  39 }
  40 
  41 uint ArrayCopyNode::size_of() const { return sizeof(*this); }
  42 
  43 ArrayCopyNode* ArrayCopyNode::make(GraphKit* kit, bool may_throw,
  44                                    Node* src, Node* src_offset,
  45                                    Node* dest, Node* dest_offset,
  46                                    Node* length,
  47                                    bool alloc_tightly_coupled,
  48                                    Node* src_klass, Node* dest_klass,
  49                                    Node* src_length, Node* dest_length) {
  50 
  51   ArrayCopyNode* ac = new ArrayCopyNode(kit->C, alloc_tightly_coupled);
  52   Node* prev_mem = kit->set_predefined_input_for_runtime_call(ac);
  53 
  54   ac->init_req(ArrayCopyNode::Src, src);
  55   ac->init_req(ArrayCopyNode::SrcPos, src_offset);
  56   ac->init_req(ArrayCopyNode::Dest, dest);
  57   ac->init_req(ArrayCopyNode::DestPos, dest_offset);
  58   ac->init_req(ArrayCopyNode::Length, length);
  59   ac->init_req(ArrayCopyNode::SrcLen, src_length);
  60   ac->init_req(ArrayCopyNode::DestLen, dest_length);
  61   ac->init_req(ArrayCopyNode::SrcKlass, src_klass);
  62   ac->init_req(ArrayCopyNode::DestKlass, dest_klass);
  63 
  64   if (may_throw) {
  65     ac->set_req(TypeFunc::I_O , kit->i_o());
  66     kit->add_safepoint_edges(ac, false);
  67   }
  68 
  69   return ac;
  70 }
  71 
  72 void ArrayCopyNode::connect_outputs(GraphKit* kit) {
  73   kit->set_all_memory_call(this, true);
  74   kit->set_control(kit->gvn().transform(new ProjNode(this,TypeFunc::Control)));
  75   kit->set_i_o(kit->gvn().transform(new ProjNode(this, TypeFunc::I_O)));
  76   kit->make_slow_call_ex(this, kit->env()->Throwable_klass(), true);
  77   kit->set_all_memory_call(this);
  78 }
  79 
  80 #ifndef PRODUCT
  81 const char* ArrayCopyNode::_kind_names[] = {"arraycopy", "arraycopy, validated arguments", "clone", "oop array clone", "CopyOf", "CopyOfRange"};
  82 void ArrayCopyNode::dump_spec(outputStream *st) const {
  83   CallNode::dump_spec(st);
  84   st->print(" (%s%s)", _kind_names[_kind], _alloc_tightly_coupled ? ", tightly coupled allocation" : "");
  85 }
  86 #endif
  87 
  88 intptr_t ArrayCopyNode::get_length_if_constant(PhaseGVN *phase) const {
  89   // check that length is constant
  90   Node* length = in(ArrayCopyNode::Length);
  91   const Type* length_type = phase->type(length);
  92 
  93   if (length_type == Type::TOP) {
  94     return -1;
  95   }
  96 
  97   assert(is_clonebasic() || is_arraycopy() || is_copyof() || is_copyofrange(), "unexpected array copy type");
  98 
  99   return is_clonebasic() ? length->find_intptr_t_con(-1) : length->find_int_con(-1);
 100 }
 101 
 102 int ArrayCopyNode::get_count(PhaseGVN *phase) const {
 103   Node* src = in(ArrayCopyNode::Src);
 104   const Type* src_type = phase->type(src);
 105 
 106   if (is_clonebasic()) {
 107     if (src_type->isa_instptr()) {
 108       const TypeInstPtr* inst_src = src_type->is_instptr();
 109       ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
 110       // ciInstanceKlass::nof_nonstatic_fields() doesn't take injected
 111       // fields into account. They are rare anyway so easier to simply
 112       // skip instances with injected fields.
 113       if ((!inst_src->klass_is_exact() && (ik->is_interface() || ik->has_subklass())) || ik->has_injected_fields()) {
 114         return -1;
 115       }
 116       int nb_fields = ik->nof_nonstatic_fields();
 117       return nb_fields;
 118     } else {
 119       const TypeAryPtr* ary_src = src_type->isa_aryptr();
 120       assert (ary_src != NULL, "not an array or instance?");
 121       // clone passes a length as a rounded number of longs. If we're
 122       // cloning an array we'll do it element by element. If the
 123       // length input to ArrayCopyNode is constant, length of input
 124       // array must be too.
 125 
 126       assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con() ||
 127              phase->is_IterGVN(), "inconsistent");
 128 
 129       if (ary_src->size()->is_con()) {
 130         return ary_src->size()->get_con();
 131       }
 132       return -1;
 133     }
 134   }
 135 
 136   return get_length_if_constant(phase);
 137 }
 138 
 139 Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int count) {
 140   if (!is_clonebasic()) {
 141     return NULL;
 142   }
 143 
 144   Node* src = in(ArrayCopyNode::Src);
 145   Node* dest = in(ArrayCopyNode::Dest);
 146   Node* ctl = in(TypeFunc::Control);
 147   Node* in_mem = in(TypeFunc::Memory);
 148 
 149   const Type* src_type = phase->type(src);
 150 
 151   assert(src->is_AddP(), "should be base + off");
 152   assert(dest->is_AddP(), "should be base + off");
 153   Node* base_src = src->in(AddPNode::Base);
 154   Node* base_dest = dest->in(AddPNode::Base);
 155 
 156   MergeMemNode* mem = MergeMemNode::make(in_mem);
 157 
 158   const TypeInstPtr* inst_src = src_type->isa_instptr();
 159 
 160   if (inst_src == NULL) {
 161     return NULL;
 162   }
 163 
 164   if (!inst_src->klass_is_exact()) {
 165     ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
 166     assert(!ik->is_interface() && !ik->has_subklass(), "inconsistent klass hierarchy");
 167     phase->C->dependencies()->assert_leaf_type(ik);
 168   }
 169 
 170   ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
 171   assert(ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem, "too many fields");
 172 
 173   for (int i = 0; i < count; i++) {
 174     ciField* field = ik->nonstatic_field_at(i);
 175     int fieldidx = phase->C->alias_type(field)->index();
 176     const TypePtr* adr_type = phase->C->alias_type(field)->adr_type();
 177     Node* off = phase->MakeConX(field->offset());
 178     Node* next_src = phase->transform(new AddPNode(base_src,base_src,off));
 179     Node* next_dest = phase->transform(new AddPNode(base_dest,base_dest,off));
 180     BasicType bt = field->layout_type();
 181 
 182     const Type *type;
 183     if (bt == T_OBJECT) {
 184       if (!field->type()->is_loaded()) {
 185         type = TypeInstPtr::BOTTOM;
 186       } else {
 187         ciType* field_klass = field->type();
 188         type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 189       }
 190     } else {
 191       type = Type::get_const_basic_type(bt);
 192     }
 193 
 194     Node* v = LoadNode::make(*phase, ctl, mem->memory_at(fieldidx), next_src, adr_type, type, bt, MemNode::unordered);
 195     v = phase->transform(v);
 196     Node* s = StoreNode::make(*phase, ctl, mem->memory_at(fieldidx), next_dest, adr_type, v, bt, MemNode::unordered);
 197     s = phase->transform(s);
 198     mem->set_memory_at(fieldidx, s);
 199   }
 200 
 201   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 202     return NULL;
 203   }
 204 
 205   return mem;
 206 }
 207 
 208 bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
 209                                        Node*& adr_src,
 210                                        Node*& base_src,
 211                                        Node*& adr_dest,
 212                                        Node*& base_dest,
 213                                        BasicType& copy_type,
 214                                        const Type*& value_type,
 215                                        bool& disjoint_bases) {
 216   Node* src = in(ArrayCopyNode::Src);
 217   Node* dest = in(ArrayCopyNode::Dest);
 218   const Type* src_type = phase->type(src);
 219   const TypeAryPtr* ary_src = src_type->isa_aryptr();
 220 
 221   if (is_arraycopy() || is_copyofrange() || is_copyof()) {
 222     const Type* dest_type = phase->type(dest);
 223     const TypeAryPtr* ary_dest = dest_type->isa_aryptr();
 224     Node* src_offset = in(ArrayCopyNode::SrcPos);
 225     Node* dest_offset = in(ArrayCopyNode::DestPos);
 226 
 227     // newly allocated object is guaranteed to not overlap with source object
 228     disjoint_bases = is_alloc_tightly_coupled();
 229 
 230     if (ary_src  == NULL || ary_src->klass()  == NULL ||
 231         ary_dest == NULL || ary_dest->klass() == NULL) {
 232       // We don't know if arguments are arrays
 233       return false;
 234     }
 235 
 236     BasicType src_elem  = ary_src->klass()->as_array_klass()->element_type()->basic_type();
 237     BasicType dest_elem = ary_dest->klass()->as_array_klass()->element_type()->basic_type();
 238     if (src_elem  == T_ARRAY)  src_elem  = T_OBJECT;
 239     if (dest_elem == T_ARRAY)  dest_elem = T_OBJECT;
 240 
 241     if (src_elem != dest_elem || dest_elem == T_VOID) {
 242       // We don't know if arguments are arrays of the same type
 243       return false;
 244     }
 245 
 246     if (dest_elem == T_OBJECT && (!is_alloc_tightly_coupled() || !GraphKit::use_ReduceInitialCardMarks())) {
 247       // It's an object array copy but we can't emit the card marking
 248       // that is needed
 249       return false;
 250     }
 251 
 252     value_type = ary_src->elem();
 253 
 254     base_src = src;
 255     base_dest = dest;
 256 
 257     uint shift  = exact_log2(type2aelembytes(dest_elem));
 258     uint header = arrayOopDesc::base_offset_in_bytes(dest_elem);
 259 
 260     adr_src = src;
 261     adr_dest = dest;
 262 
 263     src_offset = Compile::conv_I2X_index(phase, src_offset, ary_src->size());
 264     dest_offset = Compile::conv_I2X_index(phase, dest_offset, ary_dest->size());
 265 
 266     Node* src_scale = phase->transform(new LShiftXNode(src_offset, phase->intcon(shift)));
 267     Node* dest_scale = phase->transform(new LShiftXNode(dest_offset, phase->intcon(shift)));
 268 
 269     adr_src = phase->transform(new AddPNode(base_src, adr_src, src_scale));
 270     adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, dest_scale));
 271 
 272     adr_src = new AddPNode(base_src, adr_src, phase->MakeConX(header));
 273     adr_dest = new AddPNode(base_dest, adr_dest, phase->MakeConX(header));
 274 
 275     adr_src = phase->transform(adr_src);
 276     adr_dest = phase->transform(adr_dest);
 277 
 278     copy_type = dest_elem;
 279   } else {
 280     assert (is_clonebasic(), "should be");
 281 
 282     disjoint_bases = true;
 283     assert(src->is_AddP(), "should be base + off");
 284     assert(dest->is_AddP(), "should be base + off");
 285     adr_src = src;
 286     base_src = src->in(AddPNode::Base);
 287     adr_dest = dest;
 288     base_dest = dest->in(AddPNode::Base);
 289 
 290     assert(phase->type(src->in(AddPNode::Offset))->is_intptr_t()->get_con() == phase->type(dest->in(AddPNode::Offset))->is_intptr_t()->get_con(), "same start offset?");
 291     BasicType elem = ary_src->klass()->as_array_klass()->element_type()->basic_type();
 292     if (elem == T_ARRAY)  elem = T_OBJECT;
 293 
 294     int diff = arrayOopDesc::base_offset_in_bytes(elem) - phase->type(src->in(AddPNode::Offset))->is_intptr_t()->get_con();
 295     assert(diff >= 0, "clone should not start after 1st array element");
 296     if (diff > 0) {
 297       adr_src = phase->transform(new AddPNode(base_src, adr_src, phase->MakeConX(diff)));
 298       adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, phase->MakeConX(diff)));
 299     }
 300 
 301     copy_type = elem;
 302     value_type = ary_src->elem();
 303   }
 304   return true;
 305 }
 306 
 307 const TypePtr* ArrayCopyNode::get_address_type(PhaseGVN *phase, Node* n) {
 308   const Type* at = phase->type(n);
 309   assert(at != Type::TOP, "unexpected type");
 310   const TypePtr* atp = at->isa_ptr();
 311   // adjust atp to be the correct array element address type
 312   atp = atp->add_offset(Type::OffsetBot);
 313   return atp;
 314 }
 315 
 316 void ArrayCopyNode::array_copy_test_overlap(PhaseGVN *phase, bool can_reshape, bool disjoint_bases, int count, Node*& forward_ctl, Node*& backward_ctl) {
 317   Node* ctl = in(TypeFunc::Control);
 318   if (!disjoint_bases && count > 1) {
 319     Node* src_offset = in(ArrayCopyNode::SrcPos);
 320     Node* dest_offset = in(ArrayCopyNode::DestPos);
 321     assert(src_offset != NULL && dest_offset != NULL, "should be");
 322     Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
 323     Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
 324     IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
 325 
 326     phase->transform(iff);
 327 
 328     forward_ctl = phase->transform(new IfFalseNode(iff));
 329     backward_ctl = phase->transform(new IfTrueNode(iff));
 330   } else {
 331     forward_ctl = ctl;
 332   }
 333 }
 334 
 335 Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
 336                                         bool can_reshape,
 337                                         Node* forward_ctl,
 338                                         Node* start_mem_src,
 339                                         Node* start_mem_dest,
 340                                         const TypePtr* atp_src,
 341                                         const TypePtr* atp_dest,
 342                                         Node* adr_src,
 343                                         Node* base_src,
 344                                         Node* adr_dest,
 345                                         Node* base_dest,
 346                                         BasicType copy_type,
 347                                         const Type* value_type,
 348                                         int count) {
 349   Node* mem = phase->C->top();
 350   if (!forward_ctl->is_top()) {
 351     // copy forward
 352     mem = start_mem_dest;
 353 
 354     if (count > 0) {
 355       Node* v = LoadNode::make(*phase, forward_ctl, start_mem_src, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 356       v = phase->transform(v);
 357       mem = StoreNode::make(*phase, forward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 358       mem = phase->transform(mem);
 359       for (int i = 1; i < count; i++) {
 360         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 361         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 362         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 363         v = LoadNode::make(*phase, forward_ctl, mem, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 364         v = phase->transform(v);
 365         mem = StoreNode::make(*phase, forward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 366         mem = phase->transform(mem);
 367       }
 368     } else if(can_reshape) {
 369       PhaseIterGVN* igvn = phase->is_IterGVN();
 370       igvn->_worklist.push(adr_src);
 371       igvn->_worklist.push(adr_dest);
 372     }
 373   }
 374   return mem;
 375 }
 376 
 377 Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
 378                                          bool can_reshape,
 379                                          Node* backward_ctl,
 380                                          Node* start_mem_src,
 381                                          Node* start_mem_dest,
 382                                          const TypePtr* atp_src,
 383                                          const TypePtr* atp_dest,
 384                                          Node* adr_src,
 385                                          Node* base_src,
 386                                          Node* adr_dest,
 387                                          Node* base_dest,
 388                                          BasicType copy_type,
 389                                          const Type* value_type,
 390                                          int count) {
 391   Node* mem = phase->C->top();
 392   if (!backward_ctl->is_top()) {
 393     // copy backward
 394     mem = start_mem_dest;
 395 
 396     if (count > 0) {
 397       for (int i = count-1; i >= 1; i--) {
 398         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 399         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 400         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 401         Node* v = LoadNode::make(*phase, backward_ctl, mem, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 402         v = phase->transform(v);
 403         mem = StoreNode::make(*phase, backward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 404         mem = phase->transform(mem);
 405       }
 406       Node* v = LoadNode::make(*phase, backward_ctl, mem, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 407       v = phase->transform(v);
 408       mem = StoreNode::make(*phase, backward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 409       mem = phase->transform(mem);
 410     } else if(can_reshape) {
 411       PhaseIterGVN* igvn = phase->is_IterGVN();
 412       igvn->_worklist.push(adr_src);
 413       igvn->_worklist.push(adr_dest);
 414     }
 415   }
 416   return mem;
 417 }
 418 
 419 bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
 420                                      Node* ctl, Node *mem) {
 421   if (can_reshape) {
 422     PhaseIterGVN* igvn = phase->is_IterGVN();
 423     igvn->set_delay_transform(false);
 424     if (is_clonebasic()) {
 425       Node* out_mem = proj_out(TypeFunc::Memory);
 426 
 427       if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
 428           out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
 429         assert(!GraphKit::use_ReduceInitialCardMarks(), "can only happen with card marking");
 430         return false;
 431       }
 432 
 433       igvn->replace_node(out_mem->raw_out(0), mem);
 434 
 435       Node* out_ctl = proj_out(TypeFunc::Control);
 436       igvn->replace_node(out_ctl, ctl);
 437     } else {
 438       // replace fallthrough projections of the ArrayCopyNode by the
 439       // new memory, control and the input IO.
 440       CallProjections callprojs;
 441       extract_projections(&callprojs, true, false);
 442 
 443       if (callprojs.fallthrough_ioproj != NULL) {
 444         igvn->replace_node(callprojs.fallthrough_ioproj, in(TypeFunc::I_O));
 445       }
 446       if (callprojs.fallthrough_memproj != NULL) {
 447         igvn->replace_node(callprojs.fallthrough_memproj, mem);
 448       }
 449       if (callprojs.fallthrough_catchproj != NULL) {
 450         igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
 451       }
 452 
 453       // The ArrayCopyNode is not disconnected. It still has the
 454       // projections for the exception case. Replace current
 455       // ArrayCopyNode with a dummy new one with a top() control so
 456       // that this part of the graph stays consistent but is
 457       // eventually removed.
 458 
 459       set_req(0, phase->C->top());
 460       remove_dead_region(phase, can_reshape);
 461     }
 462   } else {
 463     if (in(TypeFunc::Control) != ctl) {
 464       // we can't return new memory and control from Ideal at parse time
 465       assert(!is_clonebasic(), "added control for clone?");
 466       return false;
 467     }
 468   }
 469   return true;
 470 }
 471 
 472 
 473 Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 474   if (remove_dead_region(phase, can_reshape))  return this;
 475 
 476   if (StressArrayCopyMacroNode && !can_reshape) {
 477     phase->record_for_igvn(this);
 478     return NULL;
 479   }
 480 
 481   // See if it's a small array copy and we can inline it as
 482   // loads/stores
 483   // Here we can only do:
 484   // - arraycopy if all arguments were validated before and we don't
 485   // need card marking
 486   // - clone for which we don't need to do card marking
 487 
 488   if (!is_clonebasic() && !is_arraycopy_validated() &&
 489       !is_copyofrange_validated() && !is_copyof_validated()) {
 490     return NULL;
 491   }
 492 
 493   assert(in(TypeFunc::Control) != NULL &&
 494          in(TypeFunc::Memory) != NULL &&
 495          in(ArrayCopyNode::Src) != NULL &&
 496          in(ArrayCopyNode::Dest) != NULL &&
 497          in(ArrayCopyNode::Length) != NULL &&
 498          ((in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::DestPos) != NULL) ||
 499           is_clonebasic()), "broken inputs");
 500 
 501   if (in(TypeFunc::Control)->is_top() ||
 502       in(TypeFunc::Memory)->is_top() ||
 503       phase->type(in(ArrayCopyNode::Src)) == Type::TOP ||
 504       phase->type(in(ArrayCopyNode::Dest)) == Type::TOP ||
 505       (in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::SrcPos)->is_top()) ||
 506       (in(ArrayCopyNode::DestPos) != NULL && in(ArrayCopyNode::DestPos)->is_top())) {
 507     return NULL;
 508   }
 509 
 510   int count = get_count(phase);
 511 
 512   if (count < 0 || count > ArrayCopyLoadStoreMaxElem) {
 513     return NULL;
 514   }
 515 
 516   Node* mem = try_clone_instance(phase, can_reshape, count);
 517   if (mem != NULL) {
 518     return mem;
 519   }
 520 
 521   Node* adr_src = NULL;
 522   Node* base_src = NULL;
 523   Node* adr_dest = NULL;
 524   Node* base_dest = NULL;
 525   BasicType copy_type = T_ILLEGAL;
 526   const Type* value_type = NULL;
 527   bool disjoint_bases = false;
 528 
 529   if (!prepare_array_copy(phase, can_reshape,
 530                           adr_src, base_src, adr_dest, base_dest,
 531                           copy_type, value_type, disjoint_bases)) {
 532     return NULL;
 533   }
 534 
 535   Node* src = in(ArrayCopyNode::Src);
 536   Node* dest = in(ArrayCopyNode::Dest);
 537   const TypePtr* atp_src = get_address_type(phase, src);
 538   const TypePtr* atp_dest = get_address_type(phase, dest);
 539   uint alias_idx_src = phase->C->get_alias_index(atp_src);
 540   uint alias_idx_dest = phase->C->get_alias_index(atp_dest);
 541 
 542   Node *in_mem = in(TypeFunc::Memory);
 543   Node *start_mem_src = in_mem;
 544   Node *start_mem_dest = in_mem;
 545   if (in_mem->is_MergeMem()) {
 546     start_mem_src = in_mem->as_MergeMem()->memory_at(alias_idx_src);
 547     start_mem_dest = in_mem->as_MergeMem()->memory_at(alias_idx_dest);
 548   }
 549 
 550 
 551   if (can_reshape) {
 552     assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
 553     phase->is_IterGVN()->set_delay_transform(true);
 554   }
 555 
 556   Node* backward_ctl = phase->C->top();
 557   Node* forward_ctl = phase->C->top();
 558   array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
 559 
 560   Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
 561                                          start_mem_src, start_mem_dest,
 562                                          atp_src, atp_dest,
 563                                          adr_src, base_src, adr_dest, base_dest,
 564                                          copy_type, value_type, count);
 565 
 566   Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
 567                                            start_mem_src, start_mem_dest,
 568                                            atp_src, atp_dest,
 569                                            adr_src, base_src, adr_dest, base_dest,
 570                                            copy_type, value_type, count);
 571 
 572   Node* ctl = NULL;
 573   if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
 574     ctl = new RegionNode(3);
 575     mem = new PhiNode(ctl, Type::MEMORY, atp_dest);
 576     ctl->init_req(1, forward_ctl);
 577     mem->init_req(1, forward_mem);
 578     ctl->init_req(2, backward_ctl);
 579     mem->init_req(2, backward_mem);
 580     ctl = phase->transform(ctl);
 581     mem = phase->transform(mem);
 582   } else if (!forward_ctl->is_top()) {
 583     ctl = forward_ctl;
 584     mem = forward_mem;
 585   } else {
 586     assert(!backward_ctl->is_top(), "no copy?");
 587     ctl = backward_ctl;
 588     mem = backward_mem;
 589   }
 590 
 591   if (can_reshape) {
 592     assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
 593     phase->is_IterGVN()->set_delay_transform(false);
 594   }
 595 
 596   MergeMemNode* out_mem = MergeMemNode::make(in_mem);
 597   out_mem->set_memory_at(alias_idx_dest, mem);
 598   mem = out_mem;
 599 
 600   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 601     return NULL;
 602   }
 603 
 604   return mem;
 605 }
 606 
 607 bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
 608   Node* dest = in(ArrayCopyNode::Dest);
 609   if (dest->is_top()) {
 610     return false;
 611   }
 612   const TypeOopPtr* dest_t = phase->type(dest)->is_oopptr();
 613   assert(!dest_t->is_known_instance() || _dest_type->is_known_instance(), "result of EA not recorded");
 614   assert(in(ArrayCopyNode::Src)->is_top() || !phase->type(in(ArrayCopyNode::Src))->is_oopptr()->is_known_instance() ||
 615          _src_type->is_known_instance(), "result of EA not recorded");
 616 
 617   if (_dest_type != TypeOopPtr::BOTTOM || t_oop->is_known_instance()) {
 618     assert(_dest_type == TypeOopPtr::BOTTOM || _dest_type->is_known_instance(), "result of EA is known instance");
 619     return t_oop->instance_id() == _dest_type->instance_id();
 620   }
 621 
 622   return CallNode::may_modify_arraycopy_helper(dest_t, t_oop, phase);
 623 }