8387387: Parallel: Clean up startup allocation locking

Co-authored-by: Axel Boldt-Christmas <aboldtch@openjdk.org>
Reviewed-by: tschatzl, aboldtch
This commit is contained in:
Albert Mingkun Yang 2026-07-01 06:02:23 +00:00
parent 64ae319b5c
commit b186074751

View File

@ -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;
}
}
}