annotate src/hotspot/share/opto/arraycopynode.cpp @ 54048:744dc9c33676

8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC Summary: Fixed typo in decorator name, variables, and comments. Reviewed-by: tschatzl
author kbarrett
date Mon, 11 Mar 2019 02:05:07 -0400
parents 9c18c9d839d3
children bec1bb783c7e
rev   line source
roland@29337 1 /*
kbarrett@54048 2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
roland@29337 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
roland@29337 4 *
roland@29337 5 * This code is free software; you can redistribute it and/or modify it
roland@29337 6 * under the terms of the GNU General Public License version 2 only, as
roland@29337 7 * published by the Free Software Foundation.
roland@29337 8 *
roland@29337 9 * This code is distributed in the hope that it will be useful, but WITHOUT
roland@29337 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
roland@29337 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
roland@29337 12 * version 2 for more details (a copy is included in the LICENSE file that
roland@29337 13 * accompanied this code).
roland@29337 14 *
roland@29337 15 * You should have received a copy of the GNU General Public License version
roland@29337 16 * 2 along with this work; if not, write to the Free Software Foundation,
roland@29337 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
roland@29337 18 *
roland@29337 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
roland@29337 20 * or visit www.oracle.com if you need additional information or have any
roland@29337 21 * questions.
roland@29337 22 *
roland@29337 23 */
roland@29337 24
roland@29337 25 #include "precompiled.hpp"
eosterlund@50180 26 #include "gc/shared/barrierSet.hpp"
eosterlund@50180 27 #include "gc/shared/c2/barrierSetC2.hpp"
eosterlund@50180 28 #include "gc/shared/c2/cardTableBarrierSetC2.hpp"
roland@29337 29 #include "opto/arraycopynode.hpp"
roland@29337 30 #include "opto/graphKit.hpp"
roland@45427 31 #include "runtime/sharedRuntime.hpp"
eosterlund@50180 32 #include "utilities/macros.hpp"
roland@29337 33
simonis@42086 34 ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard)
roland@51984 35 : CallNode(arraycopy_type(), NULL, TypePtr::BOTTOM),
tschatzl@51333 36 _kind(None),
roland@29337 37 _alloc_tightly_coupled(alloc_tightly_coupled),
simonis@42086 38 _has_negative_length_guard(has_negative_length_guard),
roland@30629 39 _arguments_validated(false),
roland@30629 40 _src_type(TypeOopPtr::BOTTOM),
roland@30629 41 _dest_type(TypeOopPtr::BOTTOM) {
roland@29337 42 init_class_id(Class_ArrayCopy);
roland@29337 43 init_flags(Flag_is_macro);
roland@29337 44 C->add_macro_node(this);
roland@29337 45 }
roland@29337 46
roland@29337 47 uint ArrayCopyNode::size_of() const { return sizeof(*this); }
roland@29337 48
roland@29337 49 ArrayCopyNode* ArrayCopyNode::make(GraphKit* kit, bool may_throw,
roland@29337 50 Node* src, Node* src_offset,
roland@29337 51 Node* dest, Node* dest_offset,
roland@29337 52 Node* length,
roland@29337 53 bool alloc_tightly_coupled,
simonis@42086 54 bool has_negative_length_guard,
roland@29337 55 Node* src_klass, Node* dest_klass,
roland@29337 56 Node* src_length, Node* dest_length) {
roland@29337 57
simonis@42086 58 ArrayCopyNode* ac = new ArrayCopyNode(kit->C, alloc_tightly_coupled, has_negative_length_guard);
roland@29337 59 Node* prev_mem = kit->set_predefined_input_for_runtime_call(ac);
roland@29337 60
roland@29337 61 ac->init_req(ArrayCopyNode::Src, src);
roland@29337 62 ac->init_req(ArrayCopyNode::SrcPos, src_offset);
roland@29337 63 ac->init_req(ArrayCopyNode::Dest, dest);
roland@29337 64 ac->init_req(ArrayCopyNode::DestPos, dest_offset);
roland@29337 65 ac->init_req(ArrayCopyNode::Length, length);
roland@29337 66 ac->init_req(ArrayCopyNode::SrcLen, src_length);
roland@29337 67 ac->init_req(ArrayCopyNode::DestLen, dest_length);
roland@29337 68 ac->init_req(ArrayCopyNode::SrcKlass, src_klass);
roland@29337 69 ac->init_req(ArrayCopyNode::DestKlass, dest_klass);
roland@29337 70
roland@29337 71 if (may_throw) {
roland@29337 72 ac->set_req(TypeFunc::I_O , kit->i_o());
roland@29337 73 kit->add_safepoint_edges(ac, false);
roland@29337 74 }
roland@29337 75
roland@29337 76 return ac;
roland@29337 77 }
roland@29337 78
roland@29337 79 void ArrayCopyNode::connect_outputs(GraphKit* kit) {
roland@29337 80 kit->set_all_memory_call(this, true);
roland@29337 81 kit->set_control(kit->gvn().transform(new ProjNode(this,TypeFunc::Control)));
roland@29337 82 kit->set_i_o(kit->gvn().transform(new ProjNode(this, TypeFunc::I_O)));
roland@29337 83 kit->make_slow_call_ex(this, kit->env()->Throwable_klass(), true);
roland@29337 84 kit->set_all_memory_call(this);
roland@29337 85 }
roland@29337 86
roland@29337 87 #ifndef PRODUCT
roland@29337 88 const char* ArrayCopyNode::_kind_names[] = {"arraycopy", "arraycopy, validated arguments", "clone", "oop array clone", "CopyOf", "CopyOfRange"};
mhaupt@32084 89
roland@29337 90 void ArrayCopyNode::dump_spec(outputStream *st) const {
roland@29337 91 CallNode::dump_spec(st);
roland@29337 92 st->print(" (%s%s)", _kind_names[_kind], _alloc_tightly_coupled ? ", tightly coupled allocation" : "");
roland@29337 93 }
mhaupt@32084 94
mhaupt@32084 95 void ArrayCopyNode::dump_compact_spec(outputStream* st) const {
mhaupt@32084 96 st->print("%s%s", _kind_names[_kind], _alloc_tightly_coupled ? ",tight" : "");
mhaupt@32084 97 }
roland@29337 98 #endif
roland@29337 99
roland@29337 100 intptr_t ArrayCopyNode::get_length_if_constant(PhaseGVN *phase) const {
roland@29337 101 // check that length is constant
roland@29337 102 Node* length = in(ArrayCopyNode::Length);
roland@29337 103 const Type* length_type = phase->type(length);
roland@29337 104
roland@29337 105 if (length_type == Type::TOP) {
roland@29337 106 return -1;
roland@29337 107 }
roland@29337 108
roland@29337 109 assert(is_clonebasic() || is_arraycopy() || is_copyof() || is_copyofrange(), "unexpected array copy type");
roland@29337 110
roland@29337 111 return is_clonebasic() ? length->find_intptr_t_con(-1) : length->find_int_con(-1);
roland@29337 112 }
roland@29337 113
roland@29337 114 int ArrayCopyNode::get_count(PhaseGVN *phase) const {
roland@29337 115 Node* src = in(ArrayCopyNode::Src);
roland@29337 116 const Type* src_type = phase->type(src);
roland@29337 117
roland@29337 118 if (is_clonebasic()) {
roland@29337 119 if (src_type->isa_instptr()) {
roland@29337 120 const TypeInstPtr* inst_src = src_type->is_instptr();
roland@29337 121 ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
roland@29337 122 // ciInstanceKlass::nof_nonstatic_fields() doesn't take injected
roland@29337 123 // fields into account. They are rare anyway so easier to simply
roland@29337 124 // skip instances with injected fields.
roland@29337 125 if ((!inst_src->klass_is_exact() && (ik->is_interface() || ik->has_subklass())) || ik->has_injected_fields()) {
roland@29337 126 return -1;
roland@29337 127 }
roland@29337 128 int nb_fields = ik->nof_nonstatic_fields();
roland@29337 129 return nb_fields;
roland@29337 130 } else {
roland@29337 131 const TypeAryPtr* ary_src = src_type->isa_aryptr();
roland@29337 132 assert (ary_src != NULL, "not an array or instance?");
roland@29337 133 // clone passes a length as a rounded number of longs. If we're
roland@29337 134 // cloning an array we'll do it element by element. If the
roland@29337 135 // length input to ArrayCopyNode is constant, length of input
roland@29337 136 // array must be too.
roland@29337 137
roland@29345 138 assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con() ||
roland@29345 139 phase->is_IterGVN(), "inconsistent");
roland@29337 140
roland@29337 141 if (ary_src->size()->is_con()) {
roland@29337 142 return ary_src->size()->get_con();
roland@29337 143 }
roland@29337 144 return -1;
roland@29337 145 }
roland@29337 146 }
roland@29337 147
roland@29337 148 return get_length_if_constant(phase);
roland@29337 149 }
roland@29337 150
roland@52424 151 Node* ArrayCopyNode::load(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* adr, const TypePtr* adr_type, const Type *type, BasicType bt) {
roland@52424 152 DecoratorSet decorators = C2_READ_ACCESS | C2_CONTROL_DEPENDENT_LOAD | IN_HEAP | C2_ARRAY_COPY;
roland@52424 153 C2AccessValuePtr addr(adr, adr_type);
roland@52424 154 C2OptAccess access(*phase, ctl, mem, decorators, bt, adr->in(AddPNode::Base), addr);
roland@52424 155 Node* res = bs->load_at(access, type);
roland@52424 156 ctl = access.ctl();
roland@52424 157 return res;
roland@52424 158 }
roland@52424 159
roland@52424 160 void ArrayCopyNode::store(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* adr, const TypePtr* adr_type, Node* val, const Type *type, BasicType bt) {
roland@52424 161 DecoratorSet decorators = C2_WRITE_ACCESS | IN_HEAP | C2_ARRAY_COPY;
roland@52424 162 if (is_alloc_tightly_coupled()) {
kbarrett@54048 163 decorators |= C2_TIGHTLY_COUPLED_ALLOC;
roland@52424 164 }
roland@52424 165 C2AccessValuePtr addr(adr, adr_type);
roland@52424 166 C2AccessValue value(val, type);
roland@52424 167 C2OptAccess access(*phase, ctl, mem, decorators, bt, adr->in(AddPNode::Base), addr);
roland@52424 168 bs->store_at(access, value);
roland@52424 169 ctl = access.ctl();
roland@52424 170 }
roland@52424 171
roland@52424 172
roland@29337 173 Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int count) {
roland@29337 174 if (!is_clonebasic()) {
roland@29337 175 return NULL;
roland@29337 176 }
roland@29337 177
roland@29337 178 Node* src = in(ArrayCopyNode::Src);
roland@29337 179 Node* dest = in(ArrayCopyNode::Dest);
roland@29337 180 Node* ctl = in(TypeFunc::Control);
roland@29337 181 Node* in_mem = in(TypeFunc::Memory);
roland@29337 182
roland@29337 183 const Type* src_type = phase->type(src);
roland@29337 184
roland@29337 185 assert(src->is_AddP(), "should be base + off");
roland@29337 186 assert(dest->is_AddP(), "should be base + off");
roland@29337 187 Node* base_src = src->in(AddPNode::Base);
roland@29337 188 Node* base_dest = dest->in(AddPNode::Base);
roland@29337 189
roland@29337 190 MergeMemNode* mem = MergeMemNode::make(in_mem);
roland@29337 191
roland@29337 192 const TypeInstPtr* inst_src = src_type->isa_instptr();
roland@29337 193
roland@29337 194 if (inst_src == NULL) {
roland@29337 195 return NULL;
roland@29337 196 }
roland@29337 197
roland@29337 198 if (!inst_src->klass_is_exact()) {
roland@29337 199 ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
roland@29337 200 assert(!ik->is_interface() && !ik->has_subklass(), "inconsistent klass hierarchy");
roland@29337 201 phase->C->dependencies()->assert_leaf_type(ik);
roland@29337 202 }
roland@29337 203
roland@29337 204 ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
roland@29337 205 assert(ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem, "too many fields");
roland@29337 206
roland@52424 207 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@29337 208 for (int i = 0; i < count; i++) {
roland@29337 209 ciField* field = ik->nonstatic_field_at(i);
roland@29337 210 int fieldidx = phase->C->alias_type(field)->index();
roland@29337 211 const TypePtr* adr_type = phase->C->alias_type(field)->adr_type();
roland@29337 212 Node* off = phase->MakeConX(field->offset());
roland@29337 213 Node* next_src = phase->transform(new AddPNode(base_src,base_src,off));
roland@29337 214 Node* next_dest = phase->transform(new AddPNode(base_dest,base_dest,off));
roland@29337 215 BasicType bt = field->layout_type();
roland@29337 216
roland@29337 217 const Type *type;
roland@29337 218 if (bt == T_OBJECT) {
roland@29337 219 if (!field->type()->is_loaded()) {
roland@29337 220 type = TypeInstPtr::BOTTOM;
roland@29337 221 } else {
roland@29337 222 ciType* field_klass = field->type();
roland@29337 223 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
roland@29337 224 }
roland@29337 225 } else {
roland@29337 226 type = Type::get_const_basic_type(bt);
roland@29337 227 }
roland@29337 228
roland@52424 229 Node* v = load(bs, phase, ctl, mem, next_src, adr_type, type, bt);
roland@52424 230 store(bs, phase, ctl, mem, next_dest, adr_type, v, type, bt);
roland@29337 231 }
roland@29337 232
roland@29337 233 if (!finish_transform(phase, can_reshape, ctl, mem)) {
thartmann@39254 234 // Return NodeSentinel to indicate that the transform failed
thartmann@39254 235 return NodeSentinel;
roland@29337 236 }
roland@29337 237
roland@29337 238 return mem;
roland@29337 239 }
roland@29337 240
roland@29337 241 bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
roland@29337 242 Node*& adr_src,
roland@29337 243 Node*& base_src,
roland@29337 244 Node*& adr_dest,
roland@29337 245 Node*& base_dest,
roland@29337 246 BasicType& copy_type,
roland@29337 247 const Type*& value_type,
roland@29337 248 bool& disjoint_bases) {
roland@29337 249 Node* src = in(ArrayCopyNode::Src);
roland@29337 250 Node* dest = in(ArrayCopyNode::Dest);
roland@29337 251 const Type* src_type = phase->type(src);
roland@29337 252 const TypeAryPtr* ary_src = src_type->isa_aryptr();
roland@29337 253
roland@29337 254 if (is_arraycopy() || is_copyofrange() || is_copyof()) {
roland@29337 255 const Type* dest_type = phase->type(dest);
roland@29337 256 const TypeAryPtr* ary_dest = dest_type->isa_aryptr();
roland@29337 257 Node* src_offset = in(ArrayCopyNode::SrcPos);
roland@29337 258 Node* dest_offset = in(ArrayCopyNode::DestPos);
roland@29337 259
roland@29337 260 // newly allocated object is guaranteed to not overlap with source object
roland@29337 261 disjoint_bases = is_alloc_tightly_coupled();
roland@29337 262
roland@29337 263 if (ary_src == NULL || ary_src->klass() == NULL ||
roland@29337 264 ary_dest == NULL || ary_dest->klass() == NULL) {
roland@29337 265 // We don't know if arguments are arrays
roland@29337 266 return false;
roland@29337 267 }
roland@29337 268
roland@29337 269 BasicType src_elem = ary_src->klass()->as_array_klass()->element_type()->basic_type();
roland@29337 270 BasicType dest_elem = ary_dest->klass()->as_array_klass()->element_type()->basic_type();
roland@29337 271 if (src_elem == T_ARRAY) src_elem = T_OBJECT;
roland@29337 272 if (dest_elem == T_ARRAY) dest_elem = T_OBJECT;
roland@29337 273
roland@29337 274 if (src_elem != dest_elem || dest_elem == T_VOID) {
roland@29337 275 // We don't know if arguments are arrays of the same type
roland@29337 276 return false;
roland@29337 277 }
roland@29337 278
eosterlund@50180 279 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@51984 280 if (bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, BarrierSetC2::Optimization)) {
roland@29337 281 // It's an object array copy but we can't emit the card marking
roland@29337 282 // that is needed
roland@29337 283 return false;
roland@29337 284 }
roland@29337 285
roland@29337 286 value_type = ary_src->elem();
roland@29337 287
roland@29337 288 base_src = src;
roland@29337 289 base_dest = dest;
roland@29337 290
roland@29337 291 uint shift = exact_log2(type2aelembytes(dest_elem));
roland@29337 292 uint header = arrayOopDesc::base_offset_in_bytes(dest_elem);
roland@29337 293
roland@29337 294 adr_src = src;
roland@29337 295 adr_dest = dest;
roland@29337 296
roland@29337 297 src_offset = Compile::conv_I2X_index(phase, src_offset, ary_src->size());
roland@29337 298 dest_offset = Compile::conv_I2X_index(phase, dest_offset, ary_dest->size());
roland@29337 299
roland@29337 300 Node* src_scale = phase->transform(new LShiftXNode(src_offset, phase->intcon(shift)));
roland@29337 301 Node* dest_scale = phase->transform(new LShiftXNode(dest_offset, phase->intcon(shift)));
roland@29337 302
roland@29337 303 adr_src = phase->transform(new AddPNode(base_src, adr_src, src_scale));
roland@29337 304 adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, dest_scale));
roland@29337 305
roland@29337 306 adr_src = new AddPNode(base_src, adr_src, phase->MakeConX(header));
roland@29337 307 adr_dest = new AddPNode(base_dest, adr_dest, phase->MakeConX(header));
roland@29337 308
roland@29337 309 adr_src = phase->transform(adr_src);
roland@29337 310 adr_dest = phase->transform(adr_dest);
roland@29337 311
roland@29337 312 copy_type = dest_elem;
roland@29337 313 } else {
simonis@44322 314 assert(ary_src != NULL, "should be a clone");
simonis@44322 315 assert(is_clonebasic(), "should be");
roland@29337 316
roland@29337 317 disjoint_bases = true;
roland@29337 318 assert(src->is_AddP(), "should be base + off");
roland@29337 319 assert(dest->is_AddP(), "should be base + off");
roland@29337 320 adr_src = src;
roland@29337 321 base_src = src->in(AddPNode::Base);
roland@29337 322 adr_dest = dest;
roland@29337 323 base_dest = dest->in(AddPNode::Base);
roland@29337 324
roland@29337 325 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?");
roland@29337 326 BasicType elem = ary_src->klass()->as_array_klass()->element_type()->basic_type();
roland@29337 327 if (elem == T_ARRAY) elem = T_OBJECT;
roland@29337 328
roland@51984 329 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@51984 330 if (bs->array_copy_requires_gc_barriers(true, elem, true, BarrierSetC2::Optimization)) {
roland@51984 331 return false;
roland@51984 332 }
roland@51984 333
roland@29337 334 int diff = arrayOopDesc::base_offset_in_bytes(elem) - phase->type(src->in(AddPNode::Offset))->is_intptr_t()->get_con();
roland@29337 335 assert(diff >= 0, "clone should not start after 1st array element");
roland@29337 336 if (diff > 0) {
roland@29337 337 adr_src = phase->transform(new AddPNode(base_src, adr_src, phase->MakeConX(diff)));
roland@29337 338 adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, phase->MakeConX(diff)));
roland@29337 339 }
roland@29337 340
roland@29337 341 copy_type = elem;
roland@29337 342 value_type = ary_src->elem();
roland@29337 343 }
roland@29337 344 return true;
roland@29337 345 }
roland@29337 346
roland@29337 347 const TypePtr* ArrayCopyNode::get_address_type(PhaseGVN *phase, Node* n) {
roland@29337 348 const Type* at = phase->type(n);
roland@29337 349 assert(at != Type::TOP, "unexpected type");
roland@29337 350 const TypePtr* atp = at->isa_ptr();
roland@29337 351 // adjust atp to be the correct array element address type
roland@29337 352 atp = atp->add_offset(Type::OffsetBot);
roland@29337 353 return atp;
roland@29337 354 }
roland@29337 355
roland@29337 356 void ArrayCopyNode::array_copy_test_overlap(PhaseGVN *phase, bool can_reshape, bool disjoint_bases, int count, Node*& forward_ctl, Node*& backward_ctl) {
roland@29337 357 Node* ctl = in(TypeFunc::Control);
roland@29337 358 if (!disjoint_bases && count > 1) {
roland@29337 359 Node* src_offset = in(ArrayCopyNode::SrcPos);
roland@29337 360 Node* dest_offset = in(ArrayCopyNode::DestPos);
roland@29337 361 assert(src_offset != NULL && dest_offset != NULL, "should be");
roland@29337 362 Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
roland@29337 363 Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
roland@29337 364 IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
roland@29337 365
roland@29337 366 phase->transform(iff);
roland@29337 367
roland@29337 368 forward_ctl = phase->transform(new IfFalseNode(iff));
roland@29337 369 backward_ctl = phase->transform(new IfTrueNode(iff));
roland@29337 370 } else {
roland@29337 371 forward_ctl = ctl;
roland@29337 372 }
roland@29337 373 }
roland@29337 374
roland@29337 375 Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
roland@29337 376 bool can_reshape,
roland@51984 377 Node*& forward_ctl,
roland@51984 378 MergeMemNode* mm,
roland@29337 379 const TypePtr* atp_src,
roland@29337 380 const TypePtr* atp_dest,
roland@29337 381 Node* adr_src,
roland@29337 382 Node* base_src,
roland@29337 383 Node* adr_dest,
roland@29337 384 Node* base_dest,
roland@29337 385 BasicType copy_type,
roland@29337 386 const Type* value_type,
roland@29337 387 int count) {
roland@29337 388 if (!forward_ctl->is_top()) {
roland@29337 389 // copy forward
roland@51984 390 mm = mm->clone()->as_MergeMem();
roland@29337 391
roland@29337 392 if (count > 0) {
roland@52424 393 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@52424 394 Node* v = load(bs, phase, forward_ctl, mm, adr_src, atp_src, value_type, copy_type);
roland@52424 395 store(bs, phase, forward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
roland@29337 396 for (int i = 1; i < count; i++) {
roland@29337 397 Node* off = phase->MakeConX(type2aelembytes(copy_type) * i);
roland@29337 398 Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
roland@29337 399 Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
roland@52424 400 v = load(bs, phase, forward_ctl, mm, next_src, atp_src, value_type, copy_type);
roland@52424 401 store(bs, phase, forward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
roland@29337 402 }
roland@29337 403 } else if(can_reshape) {
roland@29337 404 PhaseIterGVN* igvn = phase->is_IterGVN();
roland@29337 405 igvn->_worklist.push(adr_src);
roland@29337 406 igvn->_worklist.push(adr_dest);
roland@29337 407 }
roland@51984 408 return mm;
roland@29337 409 }
roland@51984 410 return phase->C->top();
roland@29337 411 }
roland@29337 412
roland@29337 413 Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
roland@29337 414 bool can_reshape,
roland@51984 415 Node*& backward_ctl,
roland@51984 416 MergeMemNode* mm,
roland@29337 417 const TypePtr* atp_src,
roland@29337 418 const TypePtr* atp_dest,
roland@29337 419 Node* adr_src,
roland@29337 420 Node* base_src,
roland@29337 421 Node* adr_dest,
roland@29337 422 Node* base_dest,
roland@29337 423 BasicType copy_type,
roland@29337 424 const Type* value_type,
roland@29337 425 int count) {
roland@29337 426 if (!backward_ctl->is_top()) {
roland@29337 427 // copy backward
roland@51984 428 mm = mm->clone()->as_MergeMem();
roland@51984 429
roland@51984 430 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@51984 431 assert(copy_type != T_OBJECT || !bs->array_copy_requires_gc_barriers(false, T_OBJECT, false, BarrierSetC2::Optimization), "only tightly coupled allocations for object arrays");
roland@29337 432
roland@29337 433 if (count > 0) {
roland@29337 434 for (int i = count-1; i >= 1; i--) {
roland@29337 435 Node* off = phase->MakeConX(type2aelembytes(copy_type) * i);
roland@29337 436 Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
roland@29337 437 Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
roland@52424 438 Node* v = load(bs, phase, backward_ctl, mm, next_src, atp_src, value_type, copy_type);
roland@52424 439 store(bs, phase, backward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
roland@29337 440 }
roland@52424 441 Node* v = load(bs, phase, backward_ctl, mm, adr_src, atp_src, value_type, copy_type);
roland@52424 442 store(bs, phase, backward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
roland@29337 443 } else if(can_reshape) {
roland@29337 444 PhaseIterGVN* igvn = phase->is_IterGVN();
roland@29337 445 igvn->_worklist.push(adr_src);
roland@29337 446 igvn->_worklist.push(adr_dest);
roland@29337 447 }
roland@51984 448 return phase->transform(mm);
roland@29337 449 }
roland@51984 450 return phase->C->top();
roland@29337 451 }
roland@29337 452
roland@29337 453 bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
roland@29337 454 Node* ctl, Node *mem) {
roland@29337 455 if (can_reshape) {
roland@29337 456 PhaseIterGVN* igvn = phase->is_IterGVN();
roland@29337 457 igvn->set_delay_transform(false);
roland@29337 458 if (is_clonebasic()) {
roland@29337 459 Node* out_mem = proj_out(TypeFunc::Memory);
roland@29337 460
eosterlund@50180 461 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
roland@29337 462 if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
roland@29337 463 out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
roland@51984 464 assert(bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Optimization), "can only happen with card marking");
roland@29337 465 return false;
roland@29337 466 }
roland@29337 467
roland@29337 468 igvn->replace_node(out_mem->raw_out(0), mem);
roland@29337 469
roland@29337 470 Node* out_ctl = proj_out(TypeFunc::Control);
roland@29337 471 igvn->replace_node(out_ctl, ctl);
roland@29337 472 } else {
roland@29337 473 // replace fallthrough projections of the ArrayCopyNode by the
roland@29337 474 // new memory, control and the input IO.
roland@29337 475 CallProjections callprojs;
roland@31233 476 extract_projections(&callprojs, true, false);
roland@29337 477
roland@31233 478 if (callprojs.fallthrough_ioproj != NULL) {
roland@31233 479 igvn->replace_node(callprojs.fallthrough_ioproj, in(TypeFunc::I_O));
roland@31233 480 }
roland@31233 481 if (callprojs.fallthrough_memproj != NULL) {
roland@31233 482 igvn->replace_node(callprojs.fallthrough_memproj, mem);
roland@31233 483 }
roland@31233 484 if (callprojs.fallthrough_catchproj != NULL) {
roland@31233 485 igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
roland@31233 486 }
roland@29337 487
roland@29337 488 // The ArrayCopyNode is not disconnected. It still has the
roland@29337 489 // projections for the exception case. Replace current
roland@29337 490 // ArrayCopyNode with a dummy new one with a top() control so
roland@29337 491 // that this part of the graph stays consistent but is
roland@29337 492 // eventually removed.
roland@29337 493
roland@29337 494 set_req(0, phase->C->top());
roland@29337 495 remove_dead_region(phase, can_reshape);
roland@29337 496 }
roland@29337 497 } else {
roland@29337 498 if (in(TypeFunc::Control) != ctl) {
roland@29337 499 // we can't return new memory and control from Ideal at parse time
rkennke@52925 500 assert(!is_clonebasic() || UseShenandoahGC, "added control for clone?");
roland@51984 501 phase->record_for_igvn(this);
simonis@29340 502 return false;
roland@29337 503 }
roland@29337 504 }
roland@29337 505 return true;
roland@29337 506 }
roland@29337 507
roland@29337 508
roland@29337 509 Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
roland@29337 510 if (remove_dead_region(phase, can_reshape)) return this;
roland@29337 511
roland@29337 512 if (StressArrayCopyMacroNode && !can_reshape) {
roland@29337 513 phase->record_for_igvn(this);
roland@29337 514 return NULL;
roland@29337 515 }
roland@29337 516
roland@29337 517 // See if it's a small array copy and we can inline it as
roland@29337 518 // loads/stores
roland@29337 519 // Here we can only do:
roland@29337 520 // - arraycopy if all arguments were validated before and we don't
roland@29337 521 // need card marking
roland@29337 522 // - clone for which we don't need to do card marking
roland@29337 523
roland@29337 524 if (!is_clonebasic() && !is_arraycopy_validated() &&
roland@29337 525 !is_copyofrange_validated() && !is_copyof_validated()) {
roland@29337 526 return NULL;
roland@29337 527 }
roland@29337 528
roland@29360 529 assert(in(TypeFunc::Control) != NULL &&
roland@29360 530 in(TypeFunc::Memory) != NULL &&
roland@29360 531 in(ArrayCopyNode::Src) != NULL &&
roland@29360 532 in(ArrayCopyNode::Dest) != NULL &&
roland@29360 533 in(ArrayCopyNode::Length) != NULL &&
roland@29360 534 ((in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::DestPos) != NULL) ||
roland@29360 535 is_clonebasic()), "broken inputs");
roland@29360 536
roland@29360 537 if (in(TypeFunc::Control)->is_top() ||
roland@29360 538 in(TypeFunc::Memory)->is_top() ||
roland@29360 539 phase->type(in(ArrayCopyNode::Src)) == Type::TOP ||
roland@29360 540 phase->type(in(ArrayCopyNode::Dest)) == Type::TOP ||
roland@29360 541 (in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::SrcPos)->is_top()) ||
roland@29360 542 (in(ArrayCopyNode::DestPos) != NULL && in(ArrayCopyNode::DestPos)->is_top())) {
roland@29337 543 return NULL;
roland@29337 544 }
roland@29337 545
roland@29337 546 int count = get_count(phase);
roland@29337 547
roland@29337 548 if (count < 0 || count > ArrayCopyLoadStoreMaxElem) {
roland@29337 549 return NULL;
roland@29337 550 }
roland@29337 551
roland@29337 552 Node* mem = try_clone_instance(phase, can_reshape, count);
roland@29337 553 if (mem != NULL) {
thartmann@39254 554 return (mem == NodeSentinel) ? NULL : mem;
roland@29337 555 }
roland@29337 556
roland@29337 557 Node* adr_src = NULL;
roland@29337 558 Node* base_src = NULL;
roland@29337 559 Node* adr_dest = NULL;
roland@29337 560 Node* base_dest = NULL;
roland@29337 561 BasicType copy_type = T_ILLEGAL;
roland@29337 562 const Type* value_type = NULL;
roland@29337 563 bool disjoint_bases = false;
roland@29337 564
roland@29337 565 if (!prepare_array_copy(phase, can_reshape,
roland@29337 566 adr_src, base_src, adr_dest, base_dest,
roland@29337 567 copy_type, value_type, disjoint_bases)) {
roland@29337 568 return NULL;
roland@29337 569 }
roland@29337 570
roland@29337 571 Node* src = in(ArrayCopyNode::Src);
roland@29337 572 Node* dest = in(ArrayCopyNode::Dest);
roland@29337 573 const TypePtr* atp_src = get_address_type(phase, src);
roland@29337 574 const TypePtr* atp_dest = get_address_type(phase, dest);
roland@29337 575
roland@29337 576 Node *in_mem = in(TypeFunc::Memory);
roland@51984 577 if (!in_mem->is_MergeMem()) {
roland@51984 578 in_mem = MergeMemNode::make(in_mem);
roland@29337 579 }
roland@29337 580
roland@29337 581
roland@29337 582 if (can_reshape) {
roland@29337 583 assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
roland@29337 584 phase->is_IterGVN()->set_delay_transform(true);
roland@29337 585 }
roland@29337 586
roland@29337 587 Node* backward_ctl = phase->C->top();
roland@29337 588 Node* forward_ctl = phase->C->top();
roland@29337 589 array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
roland@29337 590
roland@29337 591 Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
roland@51984 592 in_mem->as_MergeMem(),
roland@29337 593 atp_src, atp_dest,
roland@29337 594 adr_src, base_src, adr_dest, base_dest,
roland@29337 595 copy_type, value_type, count);
roland@29337 596
roland@29337 597 Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
roland@51984 598 in_mem->as_MergeMem(),
roland@29337 599 atp_src, atp_dest,
roland@29337 600 adr_src, base_src, adr_dest, base_dest,
roland@29337 601 copy_type, value_type, count);
roland@29337 602
roland@29337 603 Node* ctl = NULL;
roland@29337 604 if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
roland@29337 605 ctl = new RegionNode(3);
roland@29337 606 ctl->init_req(1, forward_ctl);
roland@29337 607 ctl->init_req(2, backward_ctl);
roland@29337 608 ctl = phase->transform(ctl);
roland@51984 609 MergeMemNode* forward_mm = forward_mem->as_MergeMem();
roland@51984 610 MergeMemNode* backward_mm = backward_mem->as_MergeMem();
roland@51984 611 for (MergeMemStream mms(forward_mm, backward_mm); mms.next_non_empty2(); ) {
roland@51984 612 if (mms.memory() != mms.memory2()) {
roland@51984 613 Node* phi = new PhiNode(ctl, Type::MEMORY, phase->C->get_adr_type(mms.alias_idx()));
roland@51984 614 phi->init_req(1, mms.memory());
roland@51984 615 phi->init_req(2, mms.memory2());
roland@51984 616 phi = phase->transform(phi);
roland@51984 617 mms.set_memory(phi);
roland@51984 618 }
roland@51984 619 }
roland@51984 620 mem = forward_mem;
roland@29337 621 } else if (!forward_ctl->is_top()) {
roland@29337 622 ctl = forward_ctl;
roland@29337 623 mem = forward_mem;
roland@29337 624 } else {
roland@29337 625 assert(!backward_ctl->is_top(), "no copy?");
roland@29337 626 ctl = backward_ctl;
roland@29337 627 mem = backward_mem;
roland@29337 628 }
roland@29337 629
roland@29337 630 if (can_reshape) {
roland@29337 631 assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
roland@29337 632 phase->is_IterGVN()->set_delay_transform(false);
roland@29337 633 }
roland@29337 634
roland@29337 635 if (!finish_transform(phase, can_reshape, ctl, mem)) {
roland@29337 636 return NULL;
roland@29337 637 }
roland@29337 638
roland@29337 639 return mem;
roland@29337 640 }
roland@30629 641
roland@30629 642 bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
roland@31044 643 Node* dest = in(ArrayCopyNode::Dest);
roland@31044 644 if (dest->is_top()) {
roland@31044 645 return false;
roland@31044 646 }
roland@31044 647 const TypeOopPtr* dest_t = phase->type(dest)->is_oopptr();
roland@30629 648 assert(!dest_t->is_known_instance() || _dest_type->is_known_instance(), "result of EA not recorded");
roland@31044 649 assert(in(ArrayCopyNode::Src)->is_top() || !phase->type(in(ArrayCopyNode::Src))->is_oopptr()->is_known_instance() ||
roland@31044 650 _src_type->is_known_instance(), "result of EA not recorded");
roland@30629 651
roland@30629 652 if (_dest_type != TypeOopPtr::BOTTOM || t_oop->is_known_instance()) {
roland@30629 653 assert(_dest_type == TypeOopPtr::BOTTOM || _dest_type->is_known_instance(), "result of EA is known instance");
roland@30629 654 return t_oop->instance_id() == _dest_type->instance_id();
roland@30629 655 }
roland@30629 656
roland@30629 657 return CallNode::may_modify_arraycopy_helper(dest_t, t_oop, phase);
roland@30629 658 }
roland@32370 659
roland@45427 660 bool ArrayCopyNode::may_modify_helper(const TypeOopPtr *t_oop, Node* n, PhaseTransform *phase, CallNode*& call) {
roland@45427 661 if (n != NULL &&
roland@45427 662 n->is_Call() &&
roland@45427 663 n->as_Call()->may_modify(t_oop, phase) &&
roland@45427 664 (n->as_Call()->is_ArrayCopy() || n->as_Call()->is_call_to_arraycopystub())) {
roland@45427 665 call = n->as_Call();
roland@45427 666 return true;
roland@32370 667 }
roland@32370 668 return false;
roland@32370 669 }
roland@32370 670
roland@45427 671 bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, MemBarNode* mb, PhaseTransform *phase, ArrayCopyNode*& ac) {
roland@45427 672
roland@45427 673 Node* c = mb->in(0);
roland@45427 674
eosterlund@50180 675 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
eosterlund@50180 676 // step over g1 gc barrier if we're at e.g. a clone with ReduceInitialCardMarks off
eosterlund@50180 677 c = bs->step_over_gc_barrier(c);
roland@45427 678
roland@45427 679 CallNode* call = NULL;
goetz@51078 680 guarantee(c != NULL, "step_over_gc_barrier failed, there must be something to step to.");
goetz@51078 681 if (c->is_Region()) {
roland@45427 682 for (uint i = 1; i < c->req(); i++) {
roland@45427 683 if (c->in(i) != NULL) {
roland@45427 684 Node* n = c->in(i)->in(0);
roland@45427 685 if (may_modify_helper(t_oop, n, phase, call)) {
roland@45427 686 ac = call->isa_ArrayCopy();
roland@45427 687 assert(c == mb->in(0), "only for clone");
roland@45427 688 return true;
roland@45427 689 }
roland@45427 690 }
roland@45427 691 }
roland@45427 692 } else if (may_modify_helper(t_oop, c->in(0), phase, call)) {
roland@45427 693 ac = call->isa_ArrayCopy();
eosterlund@50180 694 #ifdef ASSERT
eosterlund@50180 695 bool use_ReduceInitialCardMarks = BarrierSet::barrier_set()->is_a(BarrierSet::CardTableBarrierSet) &&
eosterlund@50180 696 static_cast<CardTableBarrierSetC2*>(bs)->use_ReduceInitialCardMarks();
eosterlund@50180 697 assert(c == mb->in(0) || (ac != NULL && ac->is_clonebasic() && !use_ReduceInitialCardMarks), "only for clone");
eosterlund@50180 698 #endif
roland@45427 699 return true;
roland@45427 700 }
roland@32370 701
roland@32370 702 return false;
roland@32370 703 }
roland@32370 704
roland@32370 705 // Does this array copy modify offsets between offset_lo and offset_hi
roland@32370 706 // in the destination array
roland@32370 707 // if must_modify is false, return true if the copy could write
roland@32370 708 // between offset_lo and offset_hi
roland@32370 709 // if must_modify is true, return true if the copy is guaranteed to
roland@32370 710 // write between offset_lo and offset_hi
roland@45427 711 bool ArrayCopyNode::modifies(intptr_t offset_lo, intptr_t offset_hi, PhaseTransform* phase, bool must_modify) const {
roland@32370 712 assert(_kind == ArrayCopy || _kind == CopyOf || _kind == CopyOfRange, "only for real array copies");
roland@32370 713
roland@45427 714 Node* dest = in(Dest);
roland@45427 715 Node* dest_pos = in(DestPos);
roland@45427 716 Node* len = in(Length);
roland@32370 717
roland@32370 718 const TypeInt *dest_pos_t = phase->type(dest_pos)->isa_int();
roland@32370 719 const TypeInt *len_t = phase->type(len)->isa_int();
roland@32370 720 const TypeAryPtr* ary_t = phase->type(dest)->isa_aryptr();
roland@32370 721
roland@45427 722 if (dest_pos_t == NULL || len_t == NULL || ary_t == NULL) {
roland@45427 723 return !must_modify;
roland@45427 724 }
roland@32370 725
roland@45427 726 BasicType ary_elem = ary_t->klass()->as_array_klass()->element_type()->basic_type();
roland@45427 727 uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
roland@45427 728 uint elemsize = type2aelembytes(ary_elem);
roland@32370 729
roland@45427 730 jlong dest_pos_plus_len_lo = (((jlong)dest_pos_t->_lo) + len_t->_lo) * elemsize + header;
roland@45427 731 jlong dest_pos_plus_len_hi = (((jlong)dest_pos_t->_hi) + len_t->_hi) * elemsize + header;
roland@45427 732 jlong dest_pos_lo = ((jlong)dest_pos_t->_lo) * elemsize + header;
roland@45427 733 jlong dest_pos_hi = ((jlong)dest_pos_t->_hi) * elemsize + header;
roland@45427 734
roland@45427 735 if (must_modify) {
roland@45427 736 if (offset_lo >= dest_pos_hi && offset_hi < dest_pos_plus_len_lo) {
roland@45427 737 return true;
roland@45427 738 }
roland@45427 739 } else {
roland@45427 740 if (offset_hi >= dest_pos_lo && offset_lo < dest_pos_plus_len_hi) {
roland@45427 741 return true;
roland@32370 742 }
roland@32370 743 }
roland@32370 744 return false;
roland@32370 745 }