From 027eb8b416d2f3238f4c4c65d5d485911ad79ca5 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 29 Jun 2026 10:49:58 +0000 Subject: [PATCH] 8371720: G1: Move concurrent mark initialization to first concurrent start pause Reviewed-by: iwalulya --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 5 +++-- src/hotspot/share/gc/g1/g1ConcurrentMark.hpp | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index b4758897dd6..7396c1ee9ce 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2723,13 +2723,14 @@ void G1CollectedHeap::do_collection_pause_at_safepoint(size_t allocation_word_si _bytes_used_during_gc = 0; - _cm->fully_initialize(); - policy()->decide_on_concurrent_start_pause(); // Record whether this pause may need to trigger a concurrent operation. Later, // when we signal the G1ConcurrentMarkThread, the collector state has already // been reset for the next pause. bool should_start_concurrent_mark_operation = collector_state()->is_in_concurrent_start_gc(); + if (should_start_concurrent_mark_operation) { + _cm->fully_initialize(); + } // Perform the collection. G1YoungCollector collector(gc_cause(), allocation_word_size); diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp index f0071286e04..21518423957 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp @@ -569,6 +569,11 @@ public: uint worker_id_offset() const { return _worker_id_offset; } + // Fully allocates and initializes data structures for the concurrent cycle. + // Methods that use concurrent cycle state such as the concurrent mark threads, + // tasks, marking stack, statistics, TAMS or TARS require this initialization. + // Callers that run before the first concurrent start pause, which calls this, + // should guard calls with is_fully_initialized(). void fully_initialize(); bool is_fully_initialized() const { return _cm_thread != nullptr; }