From 47612c06cf705f3b34d95a64e43d647a04cbda9c Mon Sep 17 00:00:00 2001 From: Nityanand Rai Date: Fri, 7 Nov 2025 12:36:32 -0800 Subject: [PATCH 1/5] exclude young-yong, old-old and honor UseCondCardMark in dirty card marking --- .../shenandoahBarrierSet.inline.hpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp index b176446452a19..1749744add9d9 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp @@ -191,8 +191,32 @@ inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oo template inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { assert(ShenandoahCardBarrier, "Should have been checked by caller"); + volatile CardTable::CardValue* byte = card_table()->byte_for(field); - *byte = CardTable::dirty_card_val(); + + // Exclude if young field + if (_heap->is_in_young(field)) { + return; + } + + // Exclude old-old + T heap_oop = RawAccess<>::oop_load(field); + if (!CompressedOops::is_null(heap_oop)) { + oop obj = CompressedOops::decode_not_null(heap_oop); + // Field is in old generation, If referenced object is also in old gen, skip card marking + if (!_heap->is_in_young(obj)) { + return; + } + } + + // Honor UseCondCardMark: check if card is already dirty before writing + if (UseCondCardMark) { + if (*byte != CardTable::dirty_card_val()) { + *byte = CardTable::dirty_card_val(); + } + } else { + *byte = CardTable::dirty_card_val(); + } } template From 154a5092098e052e10abd27da8097e25eca60d84 Mon Sep 17 00:00:00 2001 From: Nityanand Rai Date: Fri, 7 Nov 2025 12:47:00 -0800 Subject: [PATCH 2/5] minor cleanup --- .../share/gc/shenandoah/shenandoahBarrierSet.inline.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp index 1749744add9d9..f57fabd2442ef 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp @@ -191,14 +191,10 @@ inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oo template inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { assert(ShenandoahCardBarrier, "Should have been checked by caller"); - - volatile CardTable::CardValue* byte = card_table()->byte_for(field); - // Exclude if young field if (_heap->is_in_young(field)) { return; } - // Exclude old-old T heap_oop = RawAccess<>::oop_load(field); if (!CompressedOops::is_null(heap_oop)) { @@ -208,8 +204,8 @@ inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { return; } } - // Honor UseCondCardMark: check if card is already dirty before writing + volatile CardTable::CardValue* byte = card_table()->byte_for(field); if (UseCondCardMark) { if (*byte != CardTable::dirty_card_val()) { *byte = CardTable::dirty_card_val(); From 09ad25aba8a3f14a3b5bf0d967506c03a346cd13 Mon Sep 17 00:00:00 2001 From: Nityanand Rai Date: Fri, 7 Nov 2025 12:58:25 -0800 Subject: [PATCH 3/5] clean whitespace --- src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp index f57fabd2442ef..fa2930f5a419f 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp @@ -191,7 +191,7 @@ inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oo template inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { assert(ShenandoahCardBarrier, "Should have been checked by caller"); - // Exclude if young field + //Exclude if young field if (_heap->is_in_young(field)) { return; } From 59f7a0d0b03f8394298f4c5bbc49a20a2acf5a92 Mon Sep 17 00:00:00 2001 From: Nityanand Rai Date: Fri, 7 Nov 2025 15:04:23 -0800 Subject: [PATCH 4/5] early return of oop is null --- .../gc/shenandoah/shenandoahBarrierSet.inline.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp index fa2930f5a419f..09f57f4670192 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp @@ -195,14 +195,14 @@ inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { if (_heap->is_in_young(field)) { return; } - // Exclude old-old T heap_oop = RawAccess<>::oop_load(field); - if (!CompressedOops::is_null(heap_oop)) { - oop obj = CompressedOops::decode_not_null(heap_oop); - // Field is in old generation, If referenced object is also in old gen, skip card marking - if (!_heap->is_in_young(obj)) { - return; - } + if (CompressedOops::is_null(heap_oop)) { + return; + } + oop obj = CompressedOops::decode_not_null(heap_oop); + // Field is in old generation, If referenced object is also in old gen, skip card marking + if (!_heap->is_in_young(obj)) { + return; } // Honor UseCondCardMark: check if card is already dirty before writing volatile CardTable::CardValue* byte = card_table()->byte_for(field); From 1c85da721ba59ab84aefabf65aa7dec01197d829 Mon Sep 17 00:00:00 2001 From: Nityanand Rai <163765635+nityarai08@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:27:00 -0800 Subject: [PATCH 5/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aleksey Shipilëv --- .../share/gc/shenandoah/shenandoahBarrierSet.inline.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp index 09f57f4670192..951b08007ac60 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp @@ -191,8 +191,8 @@ inline void ShenandoahBarrierSet::keep_alive_if_weak(DecoratorSet decorators, oo template inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { assert(ShenandoahCardBarrier, "Should have been checked by caller"); - //Exclude if young field if (_heap->is_in_young(field)) { + // Young field stores do not require card mark. return; } T heap_oop = RawAccess<>::oop_load(field); @@ -200,11 +200,10 @@ inline void ShenandoahBarrierSet::write_ref_field_post(T* field) { return; } oop obj = CompressedOops::decode_not_null(heap_oop); - // Field is in old generation, If referenced object is also in old gen, skip card marking if (!_heap->is_in_young(obj)) { + // Young object -> old field stores do not require card mark. return; } - // Honor UseCondCardMark: check if card is already dirty before writing volatile CardTable::CardValue* byte = card_table()->byte_for(field); if (UseCondCardMark) { if (*byte != CardTable::dirty_card_val()) {