Skip to content

Commit e36136f

Browse files
author
Nils Eliasson
committed
8268125: ZGC: Clone oop array gets wrong acopy stub
Reviewed-by: vlivanov
1 parent 35d867d commit e36136f

5 files changed

Lines changed: 339 additions & 7 deletions

File tree

src/hotspot/share/gc/shared/c2/barrierSetC2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,5 @@ void BarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac
852852

853853
phase->igvn().replace_node(ac, call);
854854
}
855+
856+
#undef XTOP

src/hotspot/share/gc/z/c2/zBarrierSetC2.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "opto/output.hpp"
4040
#include "opto/regalloc.hpp"
4141
#include "opto/rootnode.hpp"
42+
#include "opto/runtime.hpp"
4243
#include "opto/type.hpp"
4344
#include "utilities/growableArray.hpp"
4445
#include "utilities/macros.hpp"
@@ -253,11 +254,51 @@ static const TypeFunc* clone_type() {
253254
return TypeFunc::make(domain, range);
254255
}
255256

257+
#define XTOP LP64_ONLY(COMMA phase->top())
258+
256259
void ZBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
257260
Node* const src = ac->in(ArrayCopyNode::Src);
261+
258262
if (ac->is_clone_array()) {
259-
// Clone primitive array
260-
BarrierSetC2::clone_at_expansion(phase, ac);
263+
const TypeAryPtr* ary_ptr = src->get_ptr_type()->isa_aryptr();
264+
BasicType bt;
265+
if (ary_ptr == NULL) {
266+
// ary_ptr can be null iff we are running with StressReflectiveCode
267+
// This code will be unreachable
268+
assert(StressReflectiveCode, "Guard against surprises");
269+
bt = T_LONG;
270+
} else {
271+
bt = ary_ptr->elem()->array_element_basic_type();
272+
if (is_reference_type(bt)) {
273+
// Clone object array
274+
bt = T_OBJECT;
275+
} else {
276+
// Clone primitive array
277+
bt = T_LONG;
278+
}
279+
}
280+
281+
Node* ctrl = ac->in(TypeFunc::Control);
282+
Node* mem = ac->in(TypeFunc::Memory);
283+
Node* src = ac->in(ArrayCopyNode::Src);
284+
Node* src_offset = ac->in(ArrayCopyNode::SrcPos);
285+
Node* dest = ac->in(ArrayCopyNode::Dest);
286+
Node* dest_offset = ac->in(ArrayCopyNode::DestPos);
287+
Node* length = ac->in(ArrayCopyNode::Length);
288+
289+
Node* payload_src = phase->basic_plus_adr(src, src_offset);
290+
Node* payload_dst = phase->basic_plus_adr(dest, dest_offset);
291+
292+
const char* copyfunc_name = "arraycopy";
293+
address copyfunc_addr = phase->basictype2arraycopy(bt, NULL, NULL, true, copyfunc_name, true);
294+
295+
const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
296+
const TypeFunc* call_type = OptoRuntime::fast_arraycopy_Type();
297+
298+
Node* call = phase->make_leaf_call(ctrl, mem, call_type, copyfunc_addr, copyfunc_name, raw_adr_type, payload_src, payload_dst, length XTOP);
299+
phase->transform_later(call);
300+
301+
phase->igvn().replace_node(ac, call);
261302
return;
262303
}
263304

@@ -289,6 +330,8 @@ void ZBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* a
289330
phase->igvn().replace_node(ac, call);
290331
}
291332

333+
#undef XTOP
334+
292335
// == Dominating barrier elision ==
293336

294337
static bool block_has_safepoint(const Block* block, uint from, uint to) {

src/hotspot/share/opto/library_call.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,8 @@ bool LibraryCallKit::inline_unsafe_copyMemory() {
41174117
return true;
41184118
}
41194119

4120+
#undef XTOP
4121+
41204122
//------------------------clone_coping-----------------------------------
41214123
// Helper function for inline_native_clone.
41224124
void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) {

src/hotspot/share/opto/macroArrayCopy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,8 @@ bool PhaseMacroExpand::generate_unchecked_arraycopy(Node** ctrl, MergeMemNode**
12241224
return false;
12251225
}
12261226

1227+
#undef XTOP
1228+
12271229
void PhaseMacroExpand::expand_arraycopy_node(ArrayCopyNode *ac) {
12281230
Node* ctrl = ac->in(TypeFunc::Control);
12291231
Node* io = ac->in(TypeFunc::I_O);

0 commit comments

Comments
 (0)