From b186074751bbd5b34dc92a1119e7b93e91cd8c7c Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Wed, 1 Jul 2026 06:02:23 +0000 Subject: [PATCH] 8387387: Parallel: Clean up startup allocation locking Co-authored-by: Axel Boldt-Christmas Reviewed-by: tschatzl, aboldtch --- .../gc/parallel/parallelScavengeHeap.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp index 7aa88110fc8..ea3a85861b8 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp @@ -315,17 +315,16 @@ HeapWord* ParallelScavengeHeap::mem_allocate_work(size_t size, bool is_tlab) { return result; } + // Ensure that is_init_completed() does not transition while expanding the heap. + ConditionalMutexLocker ml_init(InitCompleted_lock, !is_init_completed(), Mutex::_no_safepoint_check_flag); if (!is_init_completed()) { - // Double checked locking, this ensure that is_init_completed() does not - // transition while expanding the heap. - MonitorLocker ml(InitCompleted_lock, Monitor::_no_safepoint_check_flag); - if (!is_init_completed()) { - result = expand_heap_and_allocate(size, is_tlab); - // Return the result if it's tlab-allocation. If the result is null, callers will retry - // non-tlab allocation. - if (result != nullptr || is_tlab) { - return result; - } + // Rechecked !is_init_completed() implies we have mutual exclusion via + // `Heap_lock` and `InitCompleted_lock` + result = expand_heap_and_allocate(size, is_tlab); + // Return the result if it's tlab-allocation. If the result is null, + // callers will retry non-tlab allocation. + if (result != nullptr || is_tlab) { + return result; } } }