< prev index next >

src/hotspot/share/opto/arraycopynode.cpp

Print this page
*** 21,16 ***
--- 21,18 ---
   * questions.
   *
   */
  
  #include "precompiled.hpp"
+ #include "ci/ciFlatArrayKlass.hpp"
  #include "gc/shared/barrierSet.hpp"
  #include "gc/shared/c2/barrierSetC2.hpp"
  #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
  #include "gc/shared/gc_globals.hpp"
  #include "opto/arraycopynode.hpp"
  #include "opto/graphKit.hpp"
+ #include "opto/inlinetypenode.hpp"
  #include "runtime/sharedRuntime.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/powerOfTwo.hpp"
  
  ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard)

*** 112,14 ***
  
    return is_clonebasic() ? length->find_intptr_t_con(-1) : length->find_int_con(-1);
  }
  
  int ArrayCopyNode::get_count(PhaseGVN *phase) const {
-   Node* src = in(ArrayCopyNode::Src);
-   const Type* src_type = phase->type(src);
- 
    if (is_clonebasic()) {
      if (src_type->isa_instptr()) {
        const TypeInstPtr* inst_src = src_type->is_instptr();
        ciInstanceKlass* ik = inst_src->instance_klass();
        // ciInstanceKlass::nof_nonstatic_fields() doesn't take injected
        // fields into account. They are rare anyway so easier to simply
--- 114,18 ---
  
    return is_clonebasic() ? length->find_intptr_t_con(-1) : length->find_int_con(-1);
  }
  
  int ArrayCopyNode::get_count(PhaseGVN *phase) const {
    if (is_clonebasic()) {
+     Node* src = in(ArrayCopyNode::Src);
+     const Type* src_type = phase->type(src);
+ 
+     if (src_type == Type::TOP) {
+       return -1;
+     }
+ 
      if (src_type->isa_instptr()) {
        const TypeInstPtr* inst_src = src_type->is_instptr();
        ciInstanceKlass* ik = inst_src->instance_klass();
        // ciInstanceKlass::nof_nonstatic_fields() doesn't take injected
        // fields into account. They are rare anyway so easier to simply

*** 138,10 ***
--- 144,11 ---
        // must be too. Note that the opposite does not need to hold,
        // because different input array lengths (e.g. int arrays with
        // 3 or 4 elements) might lead to the same length input
        // (e.g. 2 double-words).
        assert(!ary_src->size()->is_con() || (get_length_if_constant(phase) >= 0) ||
+              (UseFlatArray && ary_src->elem()->make_oopptr() != nullptr && ary_src->elem()->make_oopptr()->can_be_inline_type()) ||
               phase->is_IterGVN() || phase->C->inlining_incrementally() || StressReflectiveCode, "inconsistent");
        if (ary_src->size()->is_con()) {
          return ary_src->size()->get_con();
        }
        return -1;

*** 191,10 ***
--- 198,11 ---
    if (inst_src == nullptr) {
      return nullptr;
    }
  
    MergeMemNode* mem = phase->transform(MergeMemNode::make(in_mem))->as_MergeMem();
+   phase->record_for_igvn(mem);
    if (can_reshape) {
      phase->is_IterGVN()->_worklist.push(mem);
    }
  
  

*** 277,25 ***
      BasicType src_elem = ary_src->elem()->array_element_basic_type();
      BasicType dest_elem = ary_dest->elem()->array_element_basic_type();
      if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
      if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
  
!     if (src_elem != dest_elem || dest_elem == T_VOID) {
        // We don't know if arguments are arrays of the same type
        return false;
      }
  
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
!     if (bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, false, BarrierSetC2::Optimization)) {
!       // It's an object array copy but we can't emit the card marking
!       // that is needed
        return false;
      }
  
      value_type = ary_src->elem();
  
      uint shift  = exact_log2(type2aelembytes(dest_elem));
      uint header = arrayOopDesc::base_offset_in_bytes(dest_elem);
  
      src_offset = Compile::conv_I2X_index(phase, src_offset, ary_src->size());
      if (src_offset->is_top()) {
        // Offset is out of bounds (the ArrayCopyNode will be removed)
--- 285,29 ---
      BasicType src_elem = ary_src->elem()->array_element_basic_type();
      BasicType dest_elem = ary_dest->elem()->array_element_basic_type();
      if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
      if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
  
!     if (src_elem != dest_elem || ary_src->is_flat() != ary_dest->is_flat() || dest_elem == T_VOID) {
        // We don't know if arguments are arrays of the same type
        return false;
      }
  
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
!     if ((!ary_dest->is_flat() && bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, false, BarrierSetC2::Optimization)) ||
!         (ary_dest->is_flat() && ary_src->elem()->inline_klass()->contains_oops() &&
!          bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), T_OBJECT, false, false, BarrierSetC2::Optimization))) {
+       // It's an object array copy but we can't emit the card marking that is needed
        return false;
      }
  
      value_type = ary_src->elem();
  
      uint shift  = exact_log2(type2aelembytes(dest_elem));
+     if (ary_dest->is_flat()) {
+       shift = ary_src->flat_log_elem_size();
+     }
      uint header = arrayOopDesc::base_offset_in_bytes(dest_elem);
  
      src_offset = Compile::conv_I2X_index(phase, src_offset, ary_src->size());
      if (src_offset->is_top()) {
        // Offset is out of bounds (the ArrayCopyNode will be removed)

*** 331,17 ***
      assert(ary_src != nullptr, "should be a clone");
      assert(is_clonebasic(), "should be");
  
      disjoint_bases = true;
  
      BasicType elem = ary_src->isa_aryptr()->elem()->array_element_basic_type();
      if (is_reference_type(elem, true)) {
        elem = T_OBJECT;
      }
  
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
!     if (bs->array_copy_requires_gc_barriers(true, elem, true, is_clone_inst(), BarrierSetC2::Optimization)) {
        return false;
      }
  
      adr_src  = phase->transform(new AddPNode(base_src, base_src, src_offset));
      adr_dest = phase->transform(new AddPNode(base_dest, base_dest, dest_offset));
--- 343,25 ---
      assert(ary_src != nullptr, "should be a clone");
      assert(is_clonebasic(), "should be");
  
      disjoint_bases = true;
  
+     if (ary_src->elem()->make_oopptr() != nullptr &&
+         ary_src->elem()->make_oopptr()->can_be_inline_type()) {
+       return false;
+     }
+ 
      BasicType elem = ary_src->isa_aryptr()->elem()->array_element_basic_type();
      if (is_reference_type(elem, true)) {
        elem = T_OBJECT;
      }
  
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
!     if ((!ary_src->is_flat() && bs->array_copy_requires_gc_barriers(true, elem, true, is_clone_inst(), BarrierSetC2::Optimization)) ||
+         (ary_src->is_flat() && ary_src->elem()->inline_klass()->contains_oops() &&
+          bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, is_clone_inst(), BarrierSetC2::Optimization))) {
+       // It's an object array copy but we can't emit the card marking that is needed
        return false;
      }
  
      adr_src  = phase->transform(new AddPNode(base_src, base_src, src_offset));
      adr_dest = phase->transform(new AddPNode(base_dest, base_dest, dest_offset));

*** 361,113 ***
      value_type = ary_src->elem();
    }
    return true;
  }
  
! const TypePtr* ArrayCopyNode::get_address_type(PhaseGVN* phase, const TypePtr* atp, Node* n) {
    if (atp == TypeOopPtr::BOTTOM) {
      atp = phase->type(n)->isa_ptr();
    }
    // adjust atp to be the correct array element address type
!   return atp->add_offset(Type::OffsetBot);
  }
  
! void ArrayCopyNode::array_copy_test_overlap(PhaseGVN *phase, bool can_reshape, bool disjoint_bases, int count, Node*& forward_ctl, Node*& backward_ctl) {
!   Node* ctl = in(TypeFunc::Control);
    if (!disjoint_bases && count > 1) {
      Node* src_offset = in(ArrayCopyNode::SrcPos);
      Node* dest_offset = in(ArrayCopyNode::DestPos);
      assert(src_offset != nullptr && dest_offset != nullptr, "should be");
!     Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
!     Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
      IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
  
!     phase->transform(iff);
  
!     forward_ctl = phase->transform(new IfFalseNode(iff));
!     backward_ctl = phase->transform(new IfTrueNode(iff));
    } else {
!     forward_ctl = ctl;
    }
  }
  
- Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
-                                         bool can_reshape,
-                                         Node*& forward_ctl,
-                                         Node* mem,
-                                         const TypePtr* atp_src,
-                                         const TypePtr* atp_dest,
-                                         Node* adr_src,
-                                         Node* base_src,
-                                         Node* adr_dest,
-                                         Node* base_dest,
-                                         BasicType copy_type,
-                                         const Type* value_type,
-                                         int count) {
-   if (!forward_ctl->is_top()) {
-     // copy forward
-     MergeMemNode* mm = MergeMemNode::make(mem);
  
      if (count > 0) {
!       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
!       Node* v = load(bs, phase, forward_ctl, mm, adr_src, atp_src, value_type, copy_type);
-       store(bs, phase, forward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
-       for (int i = 1; i < count; i++) {
-         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
-         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
-         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
-         v = load(bs, phase, forward_ctl, mm, next_src, atp_src, value_type, copy_type);
-         store(bs, phase, forward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
        }
      } else if (can_reshape) {
!       PhaseIterGVN* igvn = phase->is_IterGVN();
!       igvn->_worklist.push(adr_src);
!       igvn->_worklist.push(adr_dest);
      }
-     return mm;
    }
-   return phase->C->top();
  }
  
! Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
!                                          bool can_reshape,
!                                          Node*& backward_ctl,
!                                          Node* mem,
!                                          const TypePtr* atp_src,
!                                          const TypePtr* atp_dest,
!                                          Node* adr_src,
!                                          Node* base_src,
!                                          Node* adr_dest,
!                                          Node* base_dest,
!                                          BasicType copy_type,
!                                          const Type* value_type,
-                                          int count) {
-   if (!backward_ctl->is_top()) {
      // copy backward
!     MergeMemNode* mm = MergeMemNode::make(mem);
- 
-     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-     assert(copy_type != T_OBJECT || !bs->array_copy_requires_gc_barriers(false, T_OBJECT, false, false, BarrierSetC2::Optimization), "only tightly coupled allocations for object arrays");
  
      if (count > 0) {
!       for (int i = count-1; i >= 1; i--) {
!         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
-         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
-         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
-         Node* v = load(bs, phase, backward_ctl, mm, next_src, atp_src, value_type, copy_type);
-         store(bs, phase, backward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
        }
!       Node* v = load(bs, phase, backward_ctl, mm, adr_src, atp_src, value_type, copy_type);
!       store(bs, phase, backward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
!     } else if (can_reshape) {
!       PhaseIterGVN* igvn = phase->is_IterGVN();
!       igvn->_worklist.push(adr_src);
-       igvn->_worklist.push(adr_dest);
      }
-     return phase->transform(mm);
    }
-   return phase->C->top();
  }
  
  bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
                                       Node* ctl, Node *mem) {
    if (can_reshape) {
--- 381,128 ---
      value_type = ary_src->elem();
    }
    return true;
  }
  
! const TypeAryPtr* ArrayCopyNode::get_address_type(PhaseGVN* phase, const TypePtr* atp, Node* n) {
    if (atp == TypeOopPtr::BOTTOM) {
      atp = phase->type(n)->isa_ptr();
    }
    // adjust atp to be the correct array element address type
!   return atp->add_offset(Type::OffsetBot)->is_aryptr();
  }
  
! void ArrayCopyNode::array_copy_test_overlap(GraphKit& kit, bool disjoint_bases, int count, Node*& backward_ctl) {
!   Node* ctl = kit.control();
    if (!disjoint_bases && count > 1) {
+     PhaseGVN& gvn = kit.gvn();
      Node* src_offset = in(ArrayCopyNode::SrcPos);
      Node* dest_offset = in(ArrayCopyNode::DestPos);
      assert(src_offset != nullptr && dest_offset != nullptr, "should be");
!     Node* cmp = gvn.transform(new CmpINode(src_offset, dest_offset));
!     Node *bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
      IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
  
!     gvn.transform(iff);
+ 
+     kit.set_control(gvn.transform(new IfFalseNode(iff)));
+     backward_ctl = gvn.transform(new IfTrueNode(iff));
+   }
+ }
  
! void ArrayCopyNode::copy(GraphKit& kit,
!                          const TypeAryPtr* atp_src,
+                          const TypeAryPtr* atp_dest,
+                          int i,
+                          Node* base_src,
+                          Node* base_dest,
+                          Node* adr_src,
+                          Node* adr_dest,
+                          BasicType copy_type,
+                          const Type* value_type) {
+   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
+   Node* ctl = kit.control();
+   if (atp_dest->is_flat()) {
+     ciInlineKlass* vk = atp_src->elem()->inline_klass();
+     for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
+       ciField* field = vk->nonstatic_field_at(j);
+       int off_in_vt = field->offset_in_bytes() - vk->first_field_offset();
+       Node* off  = kit.MakeConX(off_in_vt + i * atp_src->flat_elem_size());
+       ciType* ft = field->type();
+       BasicType bt = type2field[ft->basic_type()];
+       assert(!field->is_flat(), "flat field encountered");
+       const Type* rt = Type::get_const_type(ft);
+       const TypePtr* adr_type = atp_src->with_field_offset(off_in_vt)->add_offset(Type::OffsetBot);
+       assert(!bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), bt, false, false, BarrierSetC2::Optimization), "GC barriers required");
+       Node* next_src = kit.gvn().transform(new AddPNode(base_src, adr_src, off));
+       Node* next_dest = kit.gvn().transform(new AddPNode(base_dest, adr_dest, off));
+       Node* v = load(bs, &kit.gvn(), ctl, kit.merged_memory(), next_src, adr_type, rt, bt);
+       store(bs, &kit.gvn(), ctl, kit.merged_memory(), next_dest, adr_type, v, rt, bt);
+     }
    } else {
!     Node* off = kit.MakeConX(type2aelembytes(copy_type) * i);
+     Node* next_src = kit.gvn().transform(new AddPNode(base_src, adr_src, off));
+     Node* next_dest = kit.gvn().transform(new AddPNode(base_dest, adr_dest, off));
+     Node* v = load(bs, &kit.gvn(), ctl, kit.merged_memory(), next_src, atp_src, value_type, copy_type);
+     store(bs, &kit.gvn(), ctl, kit.merged_memory(), next_dest, atp_dest, v, value_type, copy_type);
    }
+   kit.set_control(ctl);
  }
  
  
+ void ArrayCopyNode::array_copy_forward(GraphKit& kit,
+                                        bool can_reshape,
+                                        const TypeAryPtr* atp_src,
+                                        const TypeAryPtr* atp_dest,
+                                        Node* adr_src,
+                                        Node* base_src,
+                                        Node* adr_dest,
+                                        Node* base_dest,
+                                        BasicType copy_type,
+                                        const Type* value_type,
+                                        int count) {
+   if (!kit.stopped()) {
+     // copy forward
      if (count > 0) {
!       for (int i = 0; i < count; i++) {
!         copy(kit, atp_src, atp_dest, i, base_src, base_dest, adr_src, adr_dest, copy_type, value_type);
        }
      } else if (can_reshape) {
!       PhaseGVN& gvn = kit.gvn();
!       assert(gvn.is_IterGVN(), "");
!       gvn.record_for_igvn(adr_src);
+       gvn.record_for_igvn(adr_dest);
      }
    }
  }
  
! void ArrayCopyNode::array_copy_backward(GraphKit& kit,
!                                         bool can_reshape,
!                                         const TypeAryPtr* atp_src,
!                                         const TypeAryPtr* atp_dest,
!                                         Node* adr_src,
!                                         Node* base_src,
!                                         Node* adr_dest,
!                                         Node* base_dest,
!                                         BasicType copy_type,
!                                         const Type* value_type,
!                                         int count) {
!   if (!kit.stopped()) {
      // copy backward
!     PhaseGVN& gvn = kit.gvn();
  
      if (count > 0) {
!       for (int i = count-1; i >= 0; i--) {
!         copy(kit, atp_src, atp_dest, i, base_src, base_dest, adr_src, adr_dest, copy_type, value_type);
        }
!     } else if(can_reshape) {
!       PhaseGVN& gvn = kit.gvn();
!       assert(gvn.is_IterGVN(), "");
!       gvn.record_for_igvn(adr_src);
!       gvn.record_for_igvn(adr_dest);
      }
    }
  }
  
  bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
                                       Node* ctl, Node *mem) {
    if (can_reshape) {

*** 488,21 ***
        Node* out_ctl = proj_out(TypeFunc::Control);
        igvn->replace_node(out_ctl, ctl);
      } else {
        // replace fallthrough projections of the ArrayCopyNode by the
        // new memory, control and the input IO.
!       CallProjections callprojs;
-       extract_projections(&callprojs, true, false);
  
!       if (callprojs.fallthrough_ioproj != nullptr) {
!         igvn->replace_node(callprojs.fallthrough_ioproj, in(TypeFunc::I_O));
        }
!       if (callprojs.fallthrough_memproj != nullptr) {
!         igvn->replace_node(callprojs.fallthrough_memproj, mem);
        }
!       if (callprojs.fallthrough_catchproj != nullptr) {
!         igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
        }
  
        // The ArrayCopyNode is not disconnected. It still has the
        // projections for the exception case. Replace current
        // ArrayCopyNode with a dummy new one with a top() control so
--- 523,20 ---
        Node* out_ctl = proj_out(TypeFunc::Control);
        igvn->replace_node(out_ctl, ctl);
      } else {
        // replace fallthrough projections of the ArrayCopyNode by the
        // new memory, control and the input IO.
!       CallProjections* callprojs = extract_projections(true, false);
  
!       if (callprojs->fallthrough_ioproj != nullptr) {
!         igvn->replace_node(callprojs->fallthrough_ioproj, in(TypeFunc::I_O));
        }
!       if (callprojs->fallthrough_memproj != nullptr) {
!         igvn->replace_node(callprojs->fallthrough_memproj, mem);
        }
!       if (callprojs->fallthrough_catchproj != nullptr) {
!         igvn->replace_node(callprojs->fallthrough_catchproj, ctl);
        }
  
        // The ArrayCopyNode is not disconnected. It still has the
        // projections for the exception case. Replace current
        // ArrayCopyNode with a dummy new one with a top() control so

*** 523,11 ***
    return true;
  }
  
  
  Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
!   if (remove_dead_region(phase, can_reshape))  return this;
  
    if (StressArrayCopyMacroNode && !can_reshape) {
      phase->record_for_igvn(this);
      return nullptr;
    }
--- 557,15 ---
    return true;
  }
  
  
  Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
!   // Perform any generic optimizations first
+   Node* result = SafePointNode::Ideal(phase, can_reshape);
+   if (result != nullptr) {
+     return result;
+   }
  
    if (StressArrayCopyMacroNode && !can_reshape) {
      phase->record_for_igvn(this);
      return nullptr;
    }

*** 565,10 ***
--- 603,21 ---
  
    if (count < 0 || count > ArrayCopyLoadStoreMaxElem) {
      return nullptr;
    }
  
+   Node* src = in(ArrayCopyNode::Src);
+   Node* dest = in(ArrayCopyNode::Dest);
+   const Type* src_type = phase->type(src);
+   const Type* dest_type = phase->type(dest);
+ 
+   if (src_type->isa_aryptr() && dest_type->isa_instptr()) {
+     // clone used for load of unknown inline type can't be optimized at
+     // this point
+     return nullptr;
+   }
+ 
    Node* mem = try_clone_instance(phase, can_reshape, count);
    if (mem != nullptr) {
      return (mem == NodeSentinel) ? nullptr : mem;
    }
  

*** 586,71 ***
      assert(adr_src == nullptr, "no node can be left behind");
      assert(adr_dest == nullptr, "no node can be left behind");
      return nullptr;
    }
  
!   Node* src = in(ArrayCopyNode::Src);
!   Node* dest = in(ArrayCopyNode::Dest);
!   const TypePtr* atp_src = get_address_type(phase, _src_type, src);
!   const TypePtr* atp_dest = get_address_type(phase, _dest_type, dest);
!   Node* in_mem = in(TypeFunc::Memory);
  
    if (can_reshape) {
      assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
      phase->is_IterGVN()->set_delay_transform(true);
    }
  
    Node* backward_ctl = phase->C->top();
!   Node* forward_ctl = phase->C->top();
!   array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
! 
!   Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
!                                          in_mem,
!                                          atp_src, atp_dest,
!                                          adr_src, base_src, adr_dest, base_dest,
!                                          copy_type, value_type, count);
! 
!   Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
!                                            in_mem,
!                                            atp_src, atp_dest,
!                                            adr_src, base_src, adr_dest, base_dest,
!                                            copy_type, value_type, count);
! 
!   Node* ctl = nullptr;
!   if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
!     ctl = new RegionNode(3);
!     ctl->init_req(1, forward_ctl);
!     ctl->init_req(2, backward_ctl);
!     ctl = phase->transform(ctl);
!     MergeMemNode* forward_mm = forward_mem->as_MergeMem();
!     MergeMemNode* backward_mm = backward_mem->as_MergeMem();
!     for (MergeMemStream mms(forward_mm, backward_mm); mms.next_non_empty2(); ) {
!       if (mms.memory() != mms.memory2()) {
!         Node* phi = new PhiNode(ctl, Type::MEMORY, phase->C->get_adr_type(mms.alias_idx()));
!         phi->init_req(1, mms.memory());
!         phi->init_req(2, mms.memory2());
!         phi = phase->transform(phi);
!         mms.set_memory(phi);
!       }
!     }
!     mem = forward_mem;
!   } else if (!forward_ctl->is_top()) {
!     ctl = forward_ctl;
!     mem = forward_mem;
    } else {
!     assert(!backward_ctl->is_top(), "no copy?");
!     ctl = backward_ctl;
-     mem = backward_mem;
    }
  
    if (can_reshape) {
      assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
      phase->is_IterGVN()->set_delay_transform(false);
    }
  
!   if (!finish_transform(phase, can_reshape, ctl, mem)) {
!     if (can_reshape) {
        // put in worklist, so that if it happens to be dead it is removed
        phase->is_IterGVN()->_worklist.push(mem);
      }
      return nullptr;
    }
--- 635,93 ---
      assert(adr_src == nullptr, "no node can be left behind");
      assert(adr_dest == nullptr, "no node can be left behind");
      return nullptr;
    }
  
!   JVMState* new_jvms = nullptr;
!   SafePointNode* new_map = nullptr;
!   if (!is_clonebasic()) {
!     new_jvms = jvms()->clone_shallow(phase->C);
!     new_map = new SafePointNode(req(), new_jvms);
+     for (uint i = TypeFunc::FramePtr; i < req(); i++) {
+       new_map->init_req(i, in(i));
+     }
+     new_jvms->set_map(new_map);
+   } else {
+     new_jvms = new (phase->C) JVMState(0);
+     new_map = new SafePointNode(TypeFunc::Parms, new_jvms);
+     new_jvms->set_map(new_map);
+   }
+   new_map->set_control(in(TypeFunc::Control));
+   new_map->set_memory(MergeMemNode::make(in(TypeFunc::Memory)));
+   new_map->set_i_o(in(TypeFunc::I_O));
+   phase->record_for_igvn(new_map);
+ 
+   const TypeAryPtr* atp_src = get_address_type(phase, _src_type, src);
+   const TypeAryPtr* atp_dest = get_address_type(phase, _dest_type, dest);
  
    if (can_reshape) {
      assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
      phase->is_IterGVN()->set_delay_transform(true);
    }
  
+   GraphKit kit(new_jvms, phase);
+ 
+   SafePointNode* backward_map = nullptr;
+   SafePointNode* forward_map = nullptr;
    Node* backward_ctl = phase->C->top();
! 
!   array_copy_test_overlap(kit, disjoint_bases, count, backward_ctl);
! 
!   {
!     PreserveJVMState pjvms(&kit);
! 
!     array_copy_forward(kit, can_reshape,
!                        atp_src, atp_dest,
!                        adr_src, base_src, adr_dest, base_dest,
!                        copy_type, value_type, count);
! 
!     forward_map = kit.stop();
!   }
! 
!   kit.set_control(backward_ctl);
!   array_copy_backward(kit, can_reshape,
!                       atp_src, atp_dest,
!                       adr_src, base_src, adr_dest, base_dest,
!                       copy_type, value_type, count);
! 
!   backward_map = kit.stop();
! 
!   if (!forward_map->control()->is_top() && !backward_map->control()->is_top()) {
!     assert(forward_map->i_o() == backward_map->i_o(), "need a phi on IO?");
!     Node* ctl = new RegionNode(3);
!     Node* mem = new PhiNode(ctl, Type::MEMORY, TypePtr::BOTTOM);
!     kit.set_map(forward_map);
!     ctl->init_req(1, kit.control());
!     mem->init_req(1, kit.reset_memory());
!     kit.set_map(backward_map);
!     ctl->init_req(2, kit.control());
!     mem->init_req(2, kit.reset_memory());
!     kit.set_control(phase->transform(ctl));
!     kit.set_all_memory(phase->transform(mem));
!   } else if (!forward_map->control()->is_top()) {
!     kit.set_map(forward_map);
    } else {
!     assert(!backward_map->control()->is_top(), "no copy?");
!     kit.set_map(backward_map);
    }
  
    if (can_reshape) {
      assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
      phase->is_IterGVN()->set_delay_transform(false);
    }
  
!   mem = kit.map()->memory();
!   if (!finish_transform(phase, can_reshape, kit.control(), mem)) {
+     if (!can_reshape) {
+       phase->record_for_igvn(this);
+     } else {
        // put in worklist, so that if it happens to be dead it is removed
        phase->is_IterGVN()->_worklist.push(mem);
      }
      return nullptr;
    }

*** 745,11 ***
  
    BasicType ary_elem = ary_t->isa_aryptr()->elem()->array_element_basic_type();
    if (is_reference_type(ary_elem, true)) ary_elem = T_OBJECT;
  
    uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
!   uint elemsize = type2aelembytes(ary_elem);
  
    jlong dest_pos_plus_len_lo = (((jlong)dest_pos_t->_lo) + len_t->_lo) * elemsize + header;
    jlong dest_pos_plus_len_hi = (((jlong)dest_pos_t->_hi) + len_t->_hi) * elemsize + header;
    jlong dest_pos_lo = ((jlong)dest_pos_t->_lo) * elemsize + header;
    jlong dest_pos_hi = ((jlong)dest_pos_t->_hi) * elemsize + header;
--- 816,11 ---
  
    BasicType ary_elem = ary_t->isa_aryptr()->elem()->array_element_basic_type();
    if (is_reference_type(ary_elem, true)) ary_elem = T_OBJECT;
  
    uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
!   uint elemsize = ary_t->is_flat() ? ary_t->flat_elem_size() : type2aelembytes(ary_elem);
  
    jlong dest_pos_plus_len_lo = (((jlong)dest_pos_t->_lo) + len_t->_lo) * elemsize + header;
    jlong dest_pos_plus_len_hi = (((jlong)dest_pos_t->_hi) + len_t->_hi) * elemsize + header;
    jlong dest_pos_lo = ((jlong)dest_pos_t->_lo) * elemsize + header;
    jlong dest_pos_hi = ((jlong)dest_pos_t->_hi) * elemsize + header;
< prev index next >