Skip to content

Commit

Permalink
Backport d29c7e740d51cb50a1aa0a941a5b460782f8da68
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Mar 30, 2022
1 parent bf88ff1 commit d7b2f5f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/hotspot/share/opto/arraycopynode.cpp
Expand Up @@ -189,9 +189,8 @@ Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int c
}

MergeMemNode* mem = phase->transform(MergeMemNode::make(in_mem))->as_MergeMem();
PhaseIterGVN* igvn = phase->is_IterGVN();
if (igvn != NULL) {
igvn->_worklist.push(mem);
if (can_reshape) {
phase->is_IterGVN()->_worklist.push(mem);
}

if (!inst_src->klass_is_exact()) {
Expand Down Expand Up @@ -294,9 +293,17 @@ bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
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)
return false;
}
dest_offset = Compile::conv_I2X_index(phase, dest_offset, ary_dest->size());
if (src_offset->is_top() || dest_offset->is_top()) {
if (dest_offset->is_top()) {
// Offset is out of bounds (the ArrayCopyNode will be removed)
if (can_reshape) {
// record src_offset, so it can be deleted later (if it is dead)
phase->is_IterGVN()->_worklist.push(src_offset);
}
return false;
}

Expand All @@ -316,9 +323,6 @@ bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,

disjoint_bases = true;

adr_src = phase->transform(new AddPNode(base_src, base_src, src_offset));
adr_dest = phase->transform(new AddPNode(base_dest, base_dest, dest_offset));

BasicType elem = ary_src->klass()->as_array_klass()->element_type()->basic_type();
if (is_reference_type(elem)) {
elem = T_OBJECT;
Expand All @@ -329,6 +333,9 @@ bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
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));

// The address is offseted to an aligned address where a raw copy would start.
// If the clone copy is decomposed into load-stores - the address is adjusted to
// point at where the array starts.
Expand Down Expand Up @@ -566,6 +573,8 @@ Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
if (!prepare_array_copy(phase, can_reshape,
adr_src, base_src, adr_dest, base_dest,
copy_type, value_type, disjoint_bases)) {
assert(adr_src == NULL, "no node can be left behind");
assert(adr_dest == NULL, "no node can be left behind");
return NULL;
}

Expand Down Expand Up @@ -629,6 +638,10 @@ Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
}

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 NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/subtypenode.cpp
Expand Up @@ -135,7 +135,7 @@ Node *SubTypeCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* obj = AddPNode::Ideal_base_and_offset(addr, phase, con);
if (con == oopDesc::klass_offset_in_bytes() && obj != NULL) {
assert(is_oop(phase, obj), "only for oop input");
set_req(ObjOrSubKlass, obj);
set_req_X(ObjOrSubKlass, obj, phase);
return this;
}
}
Expand All @@ -144,7 +144,7 @@ Node *SubTypeCheckNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* allocated_klass = AllocateNode::Ideal_klass(obj_or_subklass, phase);
if (allocated_klass != NULL) {
assert(is_oop(phase, obj_or_subklass), "only for oop input");
set_req(ObjOrSubKlass, allocated_klass);
set_req_X(ObjOrSubKlass, allocated_klass, phase);
return this;
}

Expand Down
Expand Up @@ -38,6 +38,19 @@
* compiler.arraycopy.TestArrayCopyAsLoadsStores
*/

/*
* @test
* @bug 8282590
* @library /
*
* @run main/othervm -ea -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestArrayCopyAsLoadsStores::m*
* -XX:TypeProfileLevel=200
* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode
* -XX:-TieredCompilation -XX:+StressReflectiveCode -XX:-ReduceInitialCardMarks
* compiler.arraycopy.TestArrayCopyAsLoadsStores
*/

package compiler.arraycopy;

import java.util.Arrays;
Expand Down

0 comments on commit d7b2f5f

Please sign in to comment.