< prev index next >

src/hotspot/share/opto/arraycopynode.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
  29 #include "opto/arraycopynode.hpp"

  30 #include "opto/graphKit.hpp"
  31 #include "runtime/sharedRuntime.hpp"
  32 #include "utilities/macros.hpp"



  33 
  34 ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard)
  35   : CallNode(arraycopy_type(), NULL, TypeRawPtr::BOTTOM),
  36     _alloc_tightly_coupled(alloc_tightly_coupled),
  37     _has_negative_length_guard(has_negative_length_guard),
  38     _kind(None),
  39     _arguments_validated(false),
  40     _src_type(TypeOopPtr::BOTTOM),
  41     _dest_type(TypeOopPtr::BOTTOM) {
  42   init_class_id(Class_ArrayCopy);
  43   init_flags(Flag_is_macro);
  44   C->add_macro_node(this);
  45 }
  46 
  47 uint ArrayCopyNode::size_of() const { return sizeof(*this); }
  48 
  49 ArrayCopyNode* ArrayCopyNode::make(GraphKit* kit, bool may_throw,
  50                                    Node* src, Node* src_offset,
  51                                    Node* dest, Node* dest_offset,
  52                                    Node* length,


 131       const TypeAryPtr* ary_src = src_type->isa_aryptr();
 132       assert (ary_src != NULL, "not an array or instance?");
 133       // clone passes a length as a rounded number of longs. If we're
 134       // cloning an array we'll do it element by element. If the
 135       // length input to ArrayCopyNode is constant, length of input
 136       // array must be too.
 137 
 138       assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con() ||
 139              phase->is_IterGVN(), "inconsistent");
 140 
 141       if (ary_src->size()->is_con()) {
 142         return ary_src->size()->get_con();
 143       }
 144       return -1;
 145     }
 146   }
 147 
 148   return get_length_if_constant(phase);
 149 }
 150 












 151 Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int count) {
 152   if (!is_clonebasic()) {
 153     return NULL;
 154   }
 155 
 156   Node* src = in(ArrayCopyNode::Src);
 157   Node* dest = in(ArrayCopyNode::Dest);
 158   Node* ctl = in(TypeFunc::Control);
 159   Node* in_mem = in(TypeFunc::Memory);
 160 
 161   const Type* src_type = phase->type(src);
 162 
 163   assert(src->is_AddP(), "should be base + off");
 164   assert(dest->is_AddP(), "should be base + off");
 165   Node* base_src = src->in(AddPNode::Base);
 166   Node* base_dest = dest->in(AddPNode::Base);
 167 
 168   MergeMemNode* mem = MergeMemNode::make(in_mem);
 169 
 170   const TypeInstPtr* inst_src = src_type->isa_instptr();


 188     const TypePtr* adr_type = phase->C->alias_type(field)->adr_type();
 189     Node* off = phase->MakeConX(field->offset());
 190     Node* next_src = phase->transform(new AddPNode(base_src,base_src,off));
 191     Node* next_dest = phase->transform(new AddPNode(base_dest,base_dest,off));
 192     BasicType bt = field->layout_type();
 193 
 194     const Type *type;
 195     if (bt == T_OBJECT) {
 196       if (!field->type()->is_loaded()) {
 197         type = TypeInstPtr::BOTTOM;
 198       } else {
 199         ciType* field_klass = field->type();
 200         type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 201       }
 202     } else {
 203       type = Type::get_const_basic_type(bt);
 204     }
 205 
 206     Node* v = LoadNode::make(*phase, ctl, mem->memory_at(fieldidx), next_src, adr_type, type, bt, MemNode::unordered);
 207     v = phase->transform(v);





 208     Node* s = StoreNode::make(*phase, ctl, mem->memory_at(fieldidx), next_dest, adr_type, v, bt, MemNode::unordered);
 209     s = phase->transform(s);
 210     mem->set_memory_at(fieldidx, s);
 211   }
 212 
 213   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 214     // Return NodeSentinel to indicate that the transform failed
 215     return NodeSentinel;
 216   }
 217 
 218   return mem;
 219 }
 220 
 221 bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
 222                                        Node*& adr_src,
 223                                        Node*& base_src,
 224                                        Node*& adr_dest,
 225                                        Node*& base_dest,
 226                                        BasicType& copy_type,
 227                                        const Type*& value_type,


 333   Node* ctl = in(TypeFunc::Control);
 334   if (!disjoint_bases && count > 1) {
 335     Node* src_offset = in(ArrayCopyNode::SrcPos);
 336     Node* dest_offset = in(ArrayCopyNode::DestPos);
 337     assert(src_offset != NULL && dest_offset != NULL, "should be");
 338     Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
 339     Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
 340     IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
 341 
 342     phase->transform(iff);
 343 
 344     forward_ctl = phase->transform(new IfFalseNode(iff));
 345     backward_ctl = phase->transform(new IfTrueNode(iff));
 346   } else {
 347     forward_ctl = ctl;
 348   }
 349 }
 350 
 351 Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
 352                                         bool can_reshape,
 353                                         Node* forward_ctl,
 354                                         Node* start_mem_src,
 355                                         Node* start_mem_dest,
 356                                         const TypePtr* atp_src,
 357                                         const TypePtr* atp_dest,
 358                                         Node* adr_src,
 359                                         Node* base_src,
 360                                         Node* adr_dest,
 361                                         Node* base_dest,
 362                                         BasicType copy_type,
 363                                         const Type* value_type,
 364                                         int count) {
 365   Node* mem = phase->C->top();
 366   if (!forward_ctl->is_top()) {
 367     // copy forward
 368     mem = start_mem_dest;
 369     uint alias_idx_src = phase->C->get_alias_index(atp_src);
 370     uint alias_idx_dest = phase->C->get_alias_index(atp_dest);



 371     bool same_alias = (alias_idx_src == alias_idx_dest);
 372 
 373     if (count > 0) {
 374       Node* v = LoadNode::make(*phase, forward_ctl, start_mem_src, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 375       v = phase->transform(v);





 376       mem = StoreNode::make(*phase, forward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 377       mem = phase->transform(mem);
 378       for (int i = 1; i < count; i++) {
 379         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 380         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 381         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 382         v = LoadNode::make(*phase, forward_ctl, same_alias ? mem : start_mem_src, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 383         v = phase->transform(v);





 384         mem = StoreNode::make(*phase, forward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 385         mem = phase->transform(mem);
 386       }

 387     } else if(can_reshape) {
 388       PhaseIterGVN* igvn = phase->is_IterGVN();
 389       igvn->_worklist.push(adr_src);
 390       igvn->_worklist.push(adr_dest);
 391     }

 392   }
 393   return mem;
 394 }
 395 
 396 Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
 397                                          bool can_reshape,
 398                                          Node* backward_ctl,
 399                                          Node* start_mem_src,
 400                                          Node* start_mem_dest,
 401                                          const TypePtr* atp_src,
 402                                          const TypePtr* atp_dest,
 403                                          Node* adr_src,
 404                                          Node* base_src,
 405                                          Node* adr_dest,
 406                                          Node* base_dest,
 407                                          BasicType copy_type,
 408                                          const Type* value_type,
 409                                          int count) {
 410   Node* mem = phase->C->top();
 411   if (!backward_ctl->is_top()) {
 412     // copy backward
 413     mem = start_mem_dest;
 414     uint alias_idx_src = phase->C->get_alias_index(atp_src);
 415     uint alias_idx_dest = phase->C->get_alias_index(atp_dest);





 416     bool same_alias = (alias_idx_src == alias_idx_dest);
 417 
 418     if (count > 0) {
 419       for (int i = count-1; i >= 1; i--) {
 420         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 421         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 422         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 423         Node* v = LoadNode::make(*phase, backward_ctl, same_alias ? mem : start_mem_src, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 424         v = phase->transform(v);





 425         mem = StoreNode::make(*phase, backward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 426         mem = phase->transform(mem);
 427       }
 428       Node* v = LoadNode::make(*phase, backward_ctl, same_alias ? mem : start_mem_src, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 429       v = phase->transform(v);





 430       mem = StoreNode::make(*phase, backward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 431       mem = phase->transform(mem);

 432     } else if(can_reshape) {
 433       PhaseIterGVN* igvn = phase->is_IterGVN();
 434       igvn->_worklist.push(adr_src);
 435       igvn->_worklist.push(adr_dest);
 436     }

 437   }
 438   return mem;
 439 }
 440 
 441 bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
 442                                      Node* ctl, Node *mem) {
 443   if (can_reshape) {
 444     PhaseIterGVN* igvn = phase->is_IterGVN();
 445     igvn->set_delay_transform(false);
 446     if (is_clonebasic()) {
 447       Node* out_mem = proj_out(TypeFunc::Memory);
 448 
 449       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 450       if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
 451           out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
 452         assert(bs->array_copy_requires_gc_barriers(T_OBJECT), "can only happen with card marking");
 453         return false;
 454       }
 455 
 456       igvn->replace_node(out_mem->raw_out(0), mem);
 457 
 458       Node* out_ctl = proj_out(TypeFunc::Control);


 468       }
 469       if (callprojs.fallthrough_memproj != NULL) {
 470         igvn->replace_node(callprojs.fallthrough_memproj, mem);
 471       }
 472       if (callprojs.fallthrough_catchproj != NULL) {
 473         igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
 474       }
 475 
 476       // The ArrayCopyNode is not disconnected. It still has the
 477       // projections for the exception case. Replace current
 478       // ArrayCopyNode with a dummy new one with a top() control so
 479       // that this part of the graph stays consistent but is
 480       // eventually removed.
 481 
 482       set_req(0, phase->C->top());
 483       remove_dead_region(phase, can_reshape);
 484     }
 485   } else {
 486     if (in(TypeFunc::Control) != ctl) {
 487       // we can't return new memory and control from Ideal at parse time
 488       assert(!is_clonebasic(), "added control for clone?");

 489       return false;
 490     }
 491   }
 492   return true;
 493 }
 494 
 495 
 496 Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 497   if (remove_dead_region(phase, can_reshape))  return this;
 498 
 499   if (StressArrayCopyMacroNode && !can_reshape) {
 500     phase->record_for_igvn(this);
 501     return NULL;
 502   }
 503 
 504   // See if it's a small array copy and we can inline it as
 505   // loads/stores
 506   // Here we can only do:
 507   // - arraycopy if all arguments were validated before and we don't
 508   // need card marking


 542   }
 543 
 544   Node* adr_src = NULL;
 545   Node* base_src = NULL;
 546   Node* adr_dest = NULL;
 547   Node* base_dest = NULL;
 548   BasicType copy_type = T_ILLEGAL;
 549   const Type* value_type = NULL;
 550   bool disjoint_bases = false;
 551 
 552   if (!prepare_array_copy(phase, can_reshape,
 553                           adr_src, base_src, adr_dest, base_dest,
 554                           copy_type, value_type, disjoint_bases)) {
 555     return NULL;
 556   }
 557 
 558   Node* src = in(ArrayCopyNode::Src);
 559   Node* dest = in(ArrayCopyNode::Dest);
 560   const TypePtr* atp_src = get_address_type(phase, src);
 561   const TypePtr* atp_dest = get_address_type(phase, dest);
 562   uint alias_idx_src = phase->C->get_alias_index(atp_src);
 563   uint alias_idx_dest = phase->C->get_alias_index(atp_dest);
 564 
 565   Node *in_mem = in(TypeFunc::Memory);
 566   Node *start_mem_src = in_mem;
 567   Node *start_mem_dest = in_mem;
 568   if (in_mem->is_MergeMem()) {
 569     start_mem_src = in_mem->as_MergeMem()->memory_at(alias_idx_src);
 570     start_mem_dest = in_mem->as_MergeMem()->memory_at(alias_idx_dest);
 571   }
 572 
 573 
 574   if (can_reshape) {
 575     assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
 576     phase->is_IterGVN()->set_delay_transform(true);
 577   }
 578 
 579   Node* backward_ctl = phase->C->top();
 580   Node* forward_ctl = phase->C->top();
 581   array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
 582 
 583   Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
 584                                          start_mem_src, start_mem_dest,
 585                                          atp_src, atp_dest,
 586                                          adr_src, base_src, adr_dest, base_dest,
 587                                          copy_type, value_type, count);
 588 
 589   Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
 590                                            start_mem_src, start_mem_dest,
 591                                            atp_src, atp_dest,
 592                                            adr_src, base_src, adr_dest, base_dest,
 593                                            copy_type, value_type, count);
 594 
 595   Node* ctl = NULL;
 596   if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
 597     ctl = new RegionNode(3);
 598     mem = new PhiNode(ctl, Type::MEMORY, atp_dest);
 599     ctl->init_req(1, forward_ctl);
 600     mem->init_req(1, forward_mem);
 601     ctl->init_req(2, backward_ctl);
 602     mem->init_req(2, backward_mem);
 603     ctl = phase->transform(ctl);
 604     mem = phase->transform(mem);











 605   } else if (!forward_ctl->is_top()) {
 606     ctl = forward_ctl;
 607     mem = forward_mem;
 608   } else {
 609     assert(!backward_ctl->is_top(), "no copy?");
 610     ctl = backward_ctl;
 611     mem = backward_mem;
 612   }
 613 
 614   if (can_reshape) {
 615     assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
 616     phase->is_IterGVN()->set_delay_transform(false);
 617   }
 618 
 619   MergeMemNode* out_mem = MergeMemNode::make(in_mem);
 620   out_mem->set_memory_at(alias_idx_dest, mem);
 621   mem = out_mem;
 622 
 623   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 624     return NULL;
 625   }
 626 
 627   return mem;
 628 }
 629 
 630 bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
 631   Node* dest = in(ArrayCopyNode::Dest);
 632   if (dest->is_top()) {
 633     return false;
 634   }
 635   const TypeOopPtr* dest_t = phase->type(dest)->is_oopptr();
 636   assert(!dest_t->is_known_instance() || _dest_type->is_known_instance(), "result of EA not recorded");
 637   assert(in(ArrayCopyNode::Src)->is_top() || !phase->type(in(ArrayCopyNode::Src))->is_oopptr()->is_known_instance() ||
 638          _src_type->is_known_instance(), "result of EA not recorded");
 639 
 640   if (_dest_type != TypeOopPtr::BOTTOM || t_oop->is_known_instance()) {
 641     assert(_dest_type == TypeOopPtr::BOTTOM || _dest_type->is_known_instance(), "result of EA is known instance");




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
  29 #include "opto/arraycopynode.hpp"
  30 #include "opto/castnode.hpp"
  31 #include "opto/graphKit.hpp"
  32 #include "runtime/sharedRuntime.hpp"
  33 #include "utilities/macros.hpp"
  34 #if INCLUDE_SHENANDOAHGC
  35 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  36 #endif
  37 
  38 ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard)
  39   : CallNode(arraycopy_type(), NULL, TypeRawPtr::BOTTOM),
  40     _alloc_tightly_coupled(alloc_tightly_coupled),
  41     _has_negative_length_guard(has_negative_length_guard),
  42     _kind(None),
  43     _arguments_validated(false),
  44     _src_type(TypeOopPtr::BOTTOM),
  45     _dest_type(TypeOopPtr::BOTTOM) {
  46   init_class_id(Class_ArrayCopy);
  47   init_flags(Flag_is_macro);
  48   C->add_macro_node(this);
  49 }
  50 
  51 uint ArrayCopyNode::size_of() const { return sizeof(*this); }
  52 
  53 ArrayCopyNode* ArrayCopyNode::make(GraphKit* kit, bool may_throw,
  54                                    Node* src, Node* src_offset,
  55                                    Node* dest, Node* dest_offset,
  56                                    Node* length,


 135       const TypeAryPtr* ary_src = src_type->isa_aryptr();
 136       assert (ary_src != NULL, "not an array or instance?");
 137       // clone passes a length as a rounded number of longs. If we're
 138       // cloning an array we'll do it element by element. If the
 139       // length input to ArrayCopyNode is constant, length of input
 140       // array must be too.
 141 
 142       assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con() ||
 143              phase->is_IterGVN(), "inconsistent");
 144 
 145       if (ary_src->size()->is_con()) {
 146         return ary_src->size()->get_con();
 147       }
 148       return -1;
 149     }
 150   }
 151 
 152   return get_length_if_constant(phase);
 153 }
 154 
 155 #if INCLUDE_SHENANDOAHGC
 156 Node* ArrayCopyNode::shenandoah_add_storeval_barrier(PhaseGVN *phase, bool can_reshape, Node* v, MergeMemNode* mem, Node*& ctl) {
 157   if (ShenandoahLoadRefBarrier) {
 158     return phase->transform(new ShenandoahLoadReferenceBarrierNode(NULL, v));
 159   }
 160   if (ShenandoahStoreValEnqueueBarrier) {
 161     return phase->transform(new ShenandoahEnqueueBarrierNode(v));
 162   }
 163   return v;
 164 }
 165 #endif
 166 
 167 Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int count) {
 168   if (!is_clonebasic()) {
 169     return NULL;
 170   }
 171 
 172   Node* src = in(ArrayCopyNode::Src);
 173   Node* dest = in(ArrayCopyNode::Dest);
 174   Node* ctl = in(TypeFunc::Control);
 175   Node* in_mem = in(TypeFunc::Memory);
 176 
 177   const Type* src_type = phase->type(src);
 178 
 179   assert(src->is_AddP(), "should be base + off");
 180   assert(dest->is_AddP(), "should be base + off");
 181   Node* base_src = src->in(AddPNode::Base);
 182   Node* base_dest = dest->in(AddPNode::Base);
 183 
 184   MergeMemNode* mem = MergeMemNode::make(in_mem);
 185 
 186   const TypeInstPtr* inst_src = src_type->isa_instptr();


 204     const TypePtr* adr_type = phase->C->alias_type(field)->adr_type();
 205     Node* off = phase->MakeConX(field->offset());
 206     Node* next_src = phase->transform(new AddPNode(base_src,base_src,off));
 207     Node* next_dest = phase->transform(new AddPNode(base_dest,base_dest,off));
 208     BasicType bt = field->layout_type();
 209 
 210     const Type *type;
 211     if (bt == T_OBJECT) {
 212       if (!field->type()->is_loaded()) {
 213         type = TypeInstPtr::BOTTOM;
 214       } else {
 215         ciType* field_klass = field->type();
 216         type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 217       }
 218     } else {
 219       type = Type::get_const_basic_type(bt);
 220     }
 221 
 222     Node* v = LoadNode::make(*phase, ctl, mem->memory_at(fieldidx), next_src, adr_type, type, bt, MemNode::unordered);
 223     v = phase->transform(v);
 224 #if INCLUDE_SHENANDOAHGC
 225     if (UseShenandoahGC && bt == T_OBJECT) {
 226       v = shenandoah_add_storeval_barrier(phase, can_reshape, v, mem, ctl);
 227     }
 228 #endif
 229     Node* s = StoreNode::make(*phase, ctl, mem->memory_at(fieldidx), next_dest, adr_type, v, bt, MemNode::unordered);
 230     s = phase->transform(s);
 231     mem->set_memory_at(fieldidx, s);
 232   }
 233 
 234   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 235     // Return NodeSentinel to indicate that the transform failed
 236     return NodeSentinel;
 237   }
 238 
 239   return mem;
 240 }
 241 
 242 bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
 243                                        Node*& adr_src,
 244                                        Node*& base_src,
 245                                        Node*& adr_dest,
 246                                        Node*& base_dest,
 247                                        BasicType& copy_type,
 248                                        const Type*& value_type,


 354   Node* ctl = in(TypeFunc::Control);
 355   if (!disjoint_bases && count > 1) {
 356     Node* src_offset = in(ArrayCopyNode::SrcPos);
 357     Node* dest_offset = in(ArrayCopyNode::DestPos);
 358     assert(src_offset != NULL && dest_offset != NULL, "should be");
 359     Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
 360     Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
 361     IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
 362 
 363     phase->transform(iff);
 364 
 365     forward_ctl = phase->transform(new IfFalseNode(iff));
 366     backward_ctl = phase->transform(new IfTrueNode(iff));
 367   } else {
 368     forward_ctl = ctl;
 369   }
 370 }
 371 
 372 Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
 373                                         bool can_reshape,
 374                                         Node*& forward_ctl,
 375                                         MergeMemNode* mm,

 376                                         const TypePtr* atp_src,
 377                                         const TypePtr* atp_dest,
 378                                         Node* adr_src,
 379                                         Node* base_src,
 380                                         Node* adr_dest,
 381                                         Node* base_dest,
 382                                         BasicType copy_type,
 383                                         const Type* value_type,
 384                                         int count) {

 385   if (!forward_ctl->is_top()) {
 386     // copy forward
 387     mm = mm->clone()->as_MergeMem();
 388     uint alias_idx_src = phase->C->get_alias_index(atp_src);
 389     uint alias_idx_dest = phase->C->get_alias_index(atp_dest);
 390     Node *start_mem_src = mm->memory_at(alias_idx_src);
 391     Node *start_mem_dest = mm->memory_at(alias_idx_dest);
 392     Node* mem = start_mem_dest;
 393     bool same_alias = (alias_idx_src == alias_idx_dest);
 394 
 395     if (count > 0) {
 396       Node* v = LoadNode::make(*phase, forward_ctl, start_mem_src, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 397       v = phase->transform(v);
 398 #if INCLUDE_SHENANDOAHGC
 399       if (UseShenandoahGC && copy_type == T_OBJECT) {
 400         v = shenandoah_add_storeval_barrier(phase, can_reshape, v, mm, forward_ctl);
 401       }
 402 #endif
 403       mem = StoreNode::make(*phase, forward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 404       mem = phase->transform(mem);
 405       for (int i = 1; i < count; i++) {
 406         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 407         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 408         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 409         v = LoadNode::make(*phase, forward_ctl, same_alias ? mem : start_mem_src, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 410         v = phase->transform(v);
 411 #if INCLUDE_SHENANDOAHGC
 412         if (UseShenandoahGC && copy_type == T_OBJECT) {
 413           v = shenandoah_add_storeval_barrier(phase, can_reshape, v, mm, forward_ctl);
 414         }
 415 #endif
 416         mem = StoreNode::make(*phase, forward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 417         mem = phase->transform(mem);
 418       }
 419       mm->set_memory_at(alias_idx_dest, mem);
 420     } else if(can_reshape) {
 421       PhaseIterGVN* igvn = phase->is_IterGVN();
 422       igvn->_worklist.push(adr_src);
 423       igvn->_worklist.push(adr_dest);
 424     }
 425     return mm;
 426   }
 427   return phase->C->top();
 428 }
 429 
 430 Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
 431                                          bool can_reshape,
 432                                          Node*& backward_ctl,
 433                                          MergeMemNode* mm,

 434                                          const TypePtr* atp_src,
 435                                          const TypePtr* atp_dest,
 436                                          Node* adr_src,
 437                                          Node* base_src,
 438                                          Node* adr_dest,
 439                                          Node* base_dest,
 440                                          BasicType copy_type,
 441                                          const Type* value_type,
 442                                          int count) {

 443   if (!backward_ctl->is_top()) {
 444     // copy backward
 445     mm = mm->clone()->as_MergeMem();
 446     uint alias_idx_src = phase->C->get_alias_index(atp_src);
 447     uint alias_idx_dest = phase->C->get_alias_index(atp_dest);
 448     Node *start_mem_src = mm->memory_at(alias_idx_src);
 449     Node *start_mem_dest = mm->memory_at(alias_idx_dest);
 450     Node* mem = start_mem_dest;
 451 
 452     assert(copy_type != T_OBJECT SHENANDOAHGC_ONLY(|| ShenandoahStoreValEnqueueBarrier), "only tightly coupled allocations for object arrays");
 453     bool same_alias = (alias_idx_src == alias_idx_dest);
 454 
 455     if (count > 0) {
 456       for (int i = count-1; i >= 1; i--) {
 457         Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
 458         Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
 459         Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
 460         Node* v = LoadNode::make(*phase, backward_ctl, same_alias ? mem : start_mem_src, next_src, atp_src, value_type, copy_type, MemNode::unordered);
 461         v = phase->transform(v);
 462 #if INCLUDE_SHENANDOAHGC
 463         if (UseShenandoahGC && copy_type == T_OBJECT) {
 464           v = shenandoah_add_storeval_barrier(phase, can_reshape, v, mm, backward_ctl);
 465         }
 466 #endif
 467         mem = StoreNode::make(*phase, backward_ctl,mem,next_dest,atp_dest,v, copy_type, MemNode::unordered);
 468         mem = phase->transform(mem);
 469       }
 470       Node* v = LoadNode::make(*phase, backward_ctl, same_alias ? mem : start_mem_src, adr_src, atp_src, value_type, copy_type, MemNode::unordered);
 471       v = phase->transform(v);
 472 #if INCLUDE_SHENANDOAHGC
 473       if (UseShenandoahGC && copy_type == T_OBJECT) {
 474         v = shenandoah_add_storeval_barrier(phase, can_reshape, v, mm, backward_ctl);
 475       }
 476 #endif
 477       mem = StoreNode::make(*phase, backward_ctl, mem, adr_dest, atp_dest, v, copy_type, MemNode::unordered);
 478       mem = phase->transform(mem);
 479       mm->set_memory_at(alias_idx_dest, mem);
 480     } else if(can_reshape) {
 481       PhaseIterGVN* igvn = phase->is_IterGVN();
 482       igvn->_worklist.push(adr_src);
 483       igvn->_worklist.push(adr_dest);
 484     }
 485     return phase->transform(mm);
 486   }
 487   return phase->C->top();
 488 }
 489 
 490 bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
 491                                      Node* ctl, Node *mem) {
 492   if (can_reshape) {
 493     PhaseIterGVN* igvn = phase->is_IterGVN();
 494     igvn->set_delay_transform(false);
 495     if (is_clonebasic()) {
 496       Node* out_mem = proj_out(TypeFunc::Memory);
 497 
 498       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 499       if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
 500           out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
 501         assert(bs->array_copy_requires_gc_barriers(T_OBJECT), "can only happen with card marking");
 502         return false;
 503       }
 504 
 505       igvn->replace_node(out_mem->raw_out(0), mem);
 506 
 507       Node* out_ctl = proj_out(TypeFunc::Control);


 517       }
 518       if (callprojs.fallthrough_memproj != NULL) {
 519         igvn->replace_node(callprojs.fallthrough_memproj, mem);
 520       }
 521       if (callprojs.fallthrough_catchproj != NULL) {
 522         igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
 523       }
 524 
 525       // The ArrayCopyNode is not disconnected. It still has the
 526       // projections for the exception case. Replace current
 527       // ArrayCopyNode with a dummy new one with a top() control so
 528       // that this part of the graph stays consistent but is
 529       // eventually removed.
 530 
 531       set_req(0, phase->C->top());
 532       remove_dead_region(phase, can_reshape);
 533     }
 534   } else {
 535     if (in(TypeFunc::Control) != ctl) {
 536       // we can't return new memory and control from Ideal at parse time
 537       assert(!is_clonebasic() || UseShenandoahGC, "added control for clone?");
 538       phase->record_for_igvn(this);
 539       return false;
 540     }
 541   }
 542   return true;
 543 }
 544 
 545 
 546 Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 547   if (remove_dead_region(phase, can_reshape))  return this;
 548 
 549   if (StressArrayCopyMacroNode && !can_reshape) {
 550     phase->record_for_igvn(this);
 551     return NULL;
 552   }
 553 
 554   // See if it's a small array copy and we can inline it as
 555   // loads/stores
 556   // Here we can only do:
 557   // - arraycopy if all arguments were validated before and we don't
 558   // need card marking


 592   }
 593 
 594   Node* adr_src = NULL;
 595   Node* base_src = NULL;
 596   Node* adr_dest = NULL;
 597   Node* base_dest = NULL;
 598   BasicType copy_type = T_ILLEGAL;
 599   const Type* value_type = NULL;
 600   bool disjoint_bases = false;
 601 
 602   if (!prepare_array_copy(phase, can_reshape,
 603                           adr_src, base_src, adr_dest, base_dest,
 604                           copy_type, value_type, disjoint_bases)) {
 605     return NULL;
 606   }
 607 
 608   Node* src = in(ArrayCopyNode::Src);
 609   Node* dest = in(ArrayCopyNode::Dest);
 610   const TypePtr* atp_src = get_address_type(phase, src);
 611   const TypePtr* atp_dest = get_address_type(phase, dest);


 612 
 613   Node *in_mem = in(TypeFunc::Memory);
 614   if (!in_mem->is_MergeMem()) {
 615     in_mem = MergeMemNode::make(in_mem);



 616   }
 617 
 618 
 619   if (can_reshape) {
 620     assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
 621     phase->is_IterGVN()->set_delay_transform(true);
 622   }
 623 
 624   Node* backward_ctl = phase->C->top();
 625   Node* forward_ctl = phase->C->top();
 626   array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
 627 
 628   Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
 629                                          in_mem->as_MergeMem(),
 630                                          atp_src, atp_dest,
 631                                          adr_src, base_src, adr_dest, base_dest,
 632                                          copy_type, value_type, count);
 633 
 634   Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
 635                                            in_mem->as_MergeMem(),
 636                                            atp_src, atp_dest,
 637                                            adr_src, base_src, adr_dest, base_dest,
 638                                            copy_type, value_type, count);
 639 
 640   Node* ctl = NULL;
 641   if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
 642     ctl = new RegionNode(3);

 643     ctl->init_req(1, forward_ctl);

 644     ctl->init_req(2, backward_ctl);

 645     ctl = phase->transform(ctl);
 646     MergeMemNode* forward_mm = forward_mem->as_MergeMem();
 647     MergeMemNode* backward_mm = backward_mem->as_MergeMem();
 648     for (MergeMemStream mms(forward_mm, backward_mm); mms.next_non_empty2(); ) {
 649       if (mms.memory() != mms.memory2()) {
 650         Node* phi = new PhiNode(ctl, Type::MEMORY, phase->C->get_adr_type(mms.alias_idx()));
 651         phi->init_req(1, mms.memory());
 652         phi->init_req(2, mms.memory2());
 653         phi = phase->transform(phi);
 654         mms.set_memory(phi);
 655       }
 656     }
 657     mem = forward_mem;
 658   } else if (!forward_ctl->is_top()) {
 659     ctl = forward_ctl;
 660     mem = forward_mem;
 661   } else {
 662     assert(!backward_ctl->is_top(), "no copy?");
 663     ctl = backward_ctl;
 664     mem = backward_mem;
 665   }
 666 
 667   if (can_reshape) {
 668     assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
 669     phase->is_IterGVN()->set_delay_transform(false);
 670   }




 671 
 672   if (!finish_transform(phase, can_reshape, ctl, mem)) {
 673     return NULL;
 674   }
 675 
 676   return mem;
 677 }
 678 
 679 bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
 680   Node* dest = in(ArrayCopyNode::Dest);
 681   if (dest->is_top()) {
 682     return false;
 683   }
 684   const TypeOopPtr* dest_t = phase->type(dest)->is_oopptr();
 685   assert(!dest_t->is_known_instance() || _dest_type->is_known_instance(), "result of EA not recorded");
 686   assert(in(ArrayCopyNode::Src)->is_top() || !phase->type(in(ArrayCopyNode::Src))->is_oopptr()->is_known_instance() ||
 687          _src_type->is_known_instance(), "result of EA not recorded");
 688 
 689   if (_dest_type != TypeOopPtr::BOTTOM || t_oop->is_known_instance()) {
 690     assert(_dest_type == TypeOopPtr::BOTTOM || _dest_type->is_known_instance(), "result of EA is known instance");


< prev index next >