Skip to content

Commit be49dab

Browse files
committed
8321619: Generational ZGC: ZColorStoreGoodOopClosure is only valid for young objects
Reviewed-by: stefank, sjohanss
1 parent ac968c3 commit be49dab

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/hotspot/share/gc/z/zBarrierSet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ void ZBarrierSet::on_slowpath_allocation_exit(JavaThread* thread, oop new_obj) {
152152
deoptimize_allocation(thread);
153153
}
154154

155+
void ZBarrierSet::clone_obj_array(objArrayOop src_obj, objArrayOop dst_obj, size_t size) {
156+
volatile zpointer* src = (volatile zpointer*)src_obj->base();
157+
volatile zpointer* dst = (volatile zpointer*)dst_obj->base();
158+
159+
for (const zpointer* const end = cast_from_oop<const zpointer*>(src_obj) + size; src < end; src++, dst++) {
160+
zaddress elem = ZBarrier::load_barrier_on_oop_field(src);
161+
// We avoid healing here because the store below colors the pointer store good,
162+
// hence avoiding the cost of a CAS.
163+
ZBarrier::store_barrier_on_heap_oop_field(dst, false /* heal */);
164+
Atomic::store(dst, ZAddress::store_good(elem));
165+
}
166+
}
167+
155168
void ZBarrierSet::print_on(outputStream* st) const {
156169
st->print_cr("ZBarrierSet");
157170
}

src/hotspot/share/gc/z/zBarrierSet.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ZBarrierSet : public BarrierSet {
3939
static ZBarrierSetAssembler* assembler();
4040
static bool barrier_needed(DecoratorSet decorators, BasicType type);
4141

42+
static void clone_obj_array(objArrayOop src, objArrayOop dst, size_t size);
43+
4244
virtual void on_thread_create(Thread* thread);
4345
virtual void on_thread_destroy(Thread* thread);
4446
virtual void on_thread_attach(Thread* thread);

src/hotspot/share/gc/z/zBarrierSet.inline.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,13 @@ inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_i
403403
return oop_arraycopy_in_heap_no_check_cast(dst, src, length);
404404
}
405405

406-
class ZStoreBarrierOopClosure : public BasicOopIterateClosure {
406+
class ZColorStoreGoodOopClosure : public BasicOopIterateClosure {
407407
public:
408408
virtual void do_oop(oop* p_) {
409409
volatile zpointer* const p = (volatile zpointer*)p_;
410410
const zpointer ptr = ZBarrier::load_atomic(p);
411411
const zaddress addr = ZPointer::uncolor(ptr);
412-
ZBarrier::store_barrier_on_heap_oop_field(p, false /* heal */);
413-
*p = ZAddress::store_good(addr);
412+
Atomic::store(p, ZAddress::store_good(addr));
414413
}
415414

416415
virtual void do_oop(narrowOop* p) {
@@ -433,17 +432,28 @@ template <DecoratorSet decorators, typename BarrierSetT>
433432
inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
434433
assert_is_valid(to_zaddress(src));
435434

435+
if (dst->is_objArray()) {
436+
// Cloning an object array is similar to performing array copy.
437+
// If an array is large enough to have its allocation segmented,
438+
// this operation might require GC barriers. However, the intrinsics
439+
// for cloning arrays transform the clone to an optimized allocation
440+
// and arraycopy sequence, so the performance of this runtime call
441+
// does not matter for object arrays.
442+
clone_obj_array(objArrayOop(src), objArrayOop(dst), size);
443+
return;
444+
}
445+
436446
// Fix the oops
437447
ZLoadBarrierOopClosure cl;
438448
ZIterator::oop_iterate(src, &cl);
439449

440450
// Clone the object
441451
Raw::clone_in_heap(src, dst, size);
442452

443-
assert(ZHeap::heap()->is_young(to_zaddress(dst)), "ZColorStoreGoodOopClosure is only valid for young objects");
453+
assert(dst->is_typeArray() || ZHeap::heap()->is_young(to_zaddress(dst)), "ZColorStoreGoodOopClosure is only valid for young objects");
444454

445455
// Color store good before handing out
446-
ZStoreBarrierOopClosure cl_sg;
456+
ZColorStoreGoodOopClosure cl_sg;
447457
ZIterator::oop_iterate(dst, &cl_sg);
448458
}
449459

0 commit comments

Comments
 (0)