Skip to content

Commit bba3728

Browse files
author
Nils Eliasson
committed
8267726: ZGC: array_copy_requires_gc_barriers too strict
Reviewed-by: thartmann, vlivanov
1 parent d47a77d commit bba3728

10 files changed

+21
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class BarrierSetC2: public CHeapObj<mtGC> {
254254
Expansion
255255
};
256256

257-
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const { return false; }
257+
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const { return false; }
258258
virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
259259

260260
// Support for GC barriers emitted during parsing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void CardTableBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node*
176176
}
177177
}
178178

179-
bool CardTableBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const {
179+
bool CardTableBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {
180180
bool is_oop = is_reference_type(type);
181181
return is_oop && (!tightly_coupled_alloc || !use_ReduceInitialCardMarks());
182182
}

src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CardTableBarrierSetC2: public ModRefBarrierSetC2 {
4545
virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const;
4646
virtual bool is_gc_barrier_node(Node* node) const;
4747
virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
48-
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const;
48+
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const;
4949

5050
bool use_ReduceInitialCardMarks() const;
5151
};

src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ bool ShenandoahBarrierSetC2::optimize_loops(PhaseIdealLoop* phase, LoopOptsMode
763763
return false;
764764
}
765765

766-
bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const {
766+
bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {
767767
bool is_oop = is_reference_type(type);
768768
if (!is_oop) {
769769
return false;

src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ShenandoahBarrierSetC2 : public BarrierSetC2 {
109109
virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
110110

111111
// These are general helper methods used by C2
112-
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const;
112+
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const;
113113

114114
// Support for GC barriers emitted during parsing
115115
virtual bool is_gc_barrier_node(Node* node) const;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ Node* ZBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node*
224224
}
225225

226226
bool ZBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type,
227-
bool is_clone, ArrayCopyPhase phase) const {
227+
bool is_clone, bool is_clone_instance,
228+
ArrayCopyPhase phase) const {
229+
if (phase == ArrayCopyPhase::Parsing) {
230+
return false;
231+
}
232+
if (phase == ArrayCopyPhase::Optimization) {
233+
return is_clone_instance;
234+
}
235+
// else ArrayCopyPhase::Expansion
228236
return type == T_OBJECT || type == T_ARRAY;
229237
}
230238

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ZBarrierSetC2 : public BarrierSetC2 {
8383
virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc,
8484
BasicType type,
8585
bool is_clone,
86+
bool is_clone_instance,
8687
ArrayCopyPhase phase) const;
8788
virtual void clone_at_expansion(PhaseMacroExpand* phase,
8889
ArrayCopyNode* ac) const;

src/hotspot/share/opto/arraycopynode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
276276
}
277277

278278
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
279-
if (bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, BarrierSetC2::Optimization)) {
279+
if (bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, false, BarrierSetC2::Optimization)) {
280280
// It's an object array copy but we can't emit the card marking
281281
// that is needed
282282
return false;
@@ -319,7 +319,7 @@ bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
319319
}
320320

321321
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
322-
if (bs->array_copy_requires_gc_barriers(true, elem, true, BarrierSetC2::Optimization)) {
322+
if (bs->array_copy_requires_gc_barriers(true, elem, true, is_clone_inst(), BarrierSetC2::Optimization)) {
323323
return false;
324324
}
325325

@@ -423,7 +423,7 @@ Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
423423
MergeMemNode* mm = MergeMemNode::make(mem);
424424

425425
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
426-
assert(copy_type != T_OBJECT || !bs->array_copy_requires_gc_barriers(false, T_OBJECT, false, BarrierSetC2::Optimization), "only tightly coupled allocations for object arrays");
426+
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");
427427

428428
if (count > 0) {
429429
for (int i = count-1; i >= 1; i--) {
@@ -456,7 +456,7 @@ bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
456456
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
457457
if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
458458
out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
459-
assert(bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Optimization), "can only happen with card marking");
459+
assert(bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, is_clone_inst(), BarrierSetC2::Optimization), "can only happen with card marking");
460460
return false;
461461
}
462462

src/hotspot/share/opto/library_call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4233,7 +4233,7 @@ bool LibraryCallKit::inline_native_clone(bool is_virtual) {
42334233
Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size, /*deoptimize_on_exception=*/true);
42344234

42354235
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
4236-
if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Parsing)) {
4236+
if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) {
42374237
// If it is an oop array, it requires very special treatment,
42384238
// because gc barriers are required when accessing the array.
42394239
Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);

src/hotspot/share/opto/macroArrayCopy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ Node* PhaseMacroExpand::generate_arraycopy(ArrayCopyNode *ac, AllocateArrayNode*
656656
// At this point we know we do not need type checks on oop stores.
657657

658658
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
659-
if (!bs->array_copy_requires_gc_barriers(alloc != NULL, copy_type, false, BarrierSetC2::Expansion)) {
659+
if (!bs->array_copy_requires_gc_barriers(alloc != NULL, copy_type, false, false, BarrierSetC2::Expansion)) {
660660
// If we do not need gc barriers, copy using the jint or jlong stub.
661661
copy_type = LP64_ONLY(UseCompressedOops ? T_INT : T_LONG) NOT_LP64(T_INT);
662662
assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type),

0 commit comments

Comments
 (0)