diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index ce37e8ab873..f38d167bd5b 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -2308,10 +2308,20 @@ void ShenandoahHeap::flush_liveness_cache(uint worker_id) { } bool ShenandoahHeap::requires_barriers(stackChunkOop obj) const { - ShenandoahHeapRegion* region = heap_region_containing(obj); - bool allocated_after_mark_start = marking_context()->allocated_after_mark_start(obj); - bool requires_concmark_barriers = is_concurrent_mark_in_progress() && !allocated_after_mark_start; - bool requires_loadref_barriers = has_forwarded_objects() && cast_from_oop(obj) < heap_region_containing(obj)->get_update_watermark(); - bool requires_deep_loadref_barriers = allocated_after_mark_start && has_forwarded_objects(); - return requires_concmark_barriers || requires_loadref_barriers || requires_deep_loadref_barriers; + if (is_idle()) return false; + + // Objects allocated after marking start are implicitly alive, don't need any barriers during + // marking phase. + if (is_concurrent_mark_in_progress() && marking_context()->allocated_after_mark_start(obj)) { + return false; + } + + // Objects allocated after evacuation start are guaranteed in to-space, don't need any barriers + // during evacuation/update references phases. + if (has_forwarded_objects() && + cast_from_oop(obj) >= heap_region_containing(obj)->get_update_watermark()) { + return false; + } + + return true; } diff --git a/src/hotspot/share/runtime/continuationFreezeThaw.cpp b/src/hotspot/share/runtime/continuationFreezeThaw.cpp index 993db916336..76fb3cfee0e 100644 --- a/src/hotspot/share/runtime/continuationFreezeThaw.cpp +++ b/src/hotspot/share/runtime/continuationFreezeThaw.cpp @@ -1285,8 +1285,8 @@ stackChunkOop Freeze::allocate_chunk(size_t stack_size) { if (fast_oop != nullptr) { assert(!chunk->requires_barriers(), "Unfamiliar GC requires barriers on TLAB allocation"); } else { - assert(!UseZGC || !chunk->requires_barriers(), "Allocated ZGC object requires barriers"); - _barriers = !UseZGC && chunk->requires_barriers(); + assert(!UseZGC || !UseShenandoahGC || !chunk->requires_barriers(), "Allocated ZGC/ShenandoahGC object requires barriers"); + _barriers = !UseZGC && !UseShenandoahGC && chunk->requires_barriers(); if (_barriers) { log_develop_trace(continuations)("allocation requires barriers");