From 0ad81fbd161edbc8479e5af5c0f8d6098f6c72d1 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Thu, 22 Jan 2026 11:04:09 +0000 Subject: [PATCH] 8375541: G1: Race in G1BarrierSet::write_ref_field_post() Reviewed-by: iwalulya, sjohanss, shade --- src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp b/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp index ee2c1450d9b..794e5db0634 100644 --- a/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp +++ b/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp @@ -70,7 +70,11 @@ inline void G1BarrierSet::write_ref_field_pre(T* field) { template inline void G1BarrierSet::write_ref_field_post(T* field) { - volatile CardValue* byte = _card_table->byte_for(field); + // Make sure that the card table reference is read only once. Otherwise the compiler + // might reload that value in the two accesses below, that could cause writes to + // the wrong card table. + CardTable* card_table = AtomicAccess::load(&_card_table); + CardValue* byte = card_table->byte_for(field); if (*byte == G1CardTable::clean_card_val()) { *byte = G1CardTable::dirty_card_val(); }