From d01e7d9850a57dd8e4849e2b7db6eacb37605647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Sikstr=C3=B6m?= Date: Fri, 21 Nov 2025 13:44:09 +0000 Subject: [PATCH] 8371783: Refactor GCCause in VM_CollectForMetadataAllocation Reviewed-by: kbarrett, ayang --- src/hotspot/share/gc/shared/collectedHeap.cpp | 3 +-- src/hotspot/share/gc/shared/gcVMOperations.cpp | 16 ++++++++++------ src/hotspot/share/gc/shared/gcVMOperations.hpp | 3 +-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/shared/collectedHeap.cpp b/src/hotspot/share/gc/shared/collectedHeap.cpp index 4207f83e0a4..8576781f7c8 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.cpp +++ b/src/hotspot/share/gc/shared/collectedHeap.cpp @@ -379,8 +379,7 @@ MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loa word_size, mdtype, gc_count, - full_gc_count, - GCCause::_metadata_GC_threshold); + full_gc_count); VMThread::execute(&op); diff --git a/src/hotspot/share/gc/shared/gcVMOperations.cpp b/src/hotspot/share/gc/shared/gcVMOperations.cpp index 3f5e9bd4f6b..6dbfd56b4e9 100644 --- a/src/hotspot/share/gc/shared/gcVMOperations.cpp +++ b/src/hotspot/share/gc/shared/gcVMOperations.cpp @@ -220,9 +220,8 @@ VM_CollectForMetadataAllocation::VM_CollectForMetadataAllocation(ClassLoaderData size_t size, Metaspace::MetadataType mdtype, uint gc_count_before, - uint full_gc_count_before, - GCCause::Cause gc_cause) - : VM_GC_Collect_Operation(gc_count_before, gc_cause, full_gc_count_before, true), + uint full_gc_count_before) + : VM_GC_Collect_Operation(gc_count_before, GCCause::_metadata_GC_threshold, full_gc_count_before, true), _result(nullptr), _size(size), _mdtype(mdtype), _loader_data(loader_data) { assert(_size != 0, "An allocation should always be requested with this operation."); AllocTracer::send_allocation_requiring_gc_event(_size * HeapWordSize, GCId::peek()); @@ -231,8 +230,11 @@ VM_CollectForMetadataAllocation::VM_CollectForMetadataAllocation(ClassLoaderData void VM_CollectForMetadataAllocation::doit() { SvcGCMarker sgcm(SvcGCMarker::FULL); - CollectedHeap* heap = Universe::heap(); - GCCauseSetter gccs(heap, _gc_cause); + // Note: GCCauseSetter is intentionally not used here. + // The specific GC cause is set directly in downstream calls that initiate + // collections, allowing us to accurately reflect different situations: + // - A typical metadata allocation failure triggers a collection. + // - As a last resort, a collection clears soft references if prior attempts fail. // Check again if the space is available. Another thread // may have similarly failed a metadata allocation and induced @@ -255,8 +257,10 @@ void VM_CollectForMetadataAllocation::doit() { } #endif + CollectedHeap* heap = Universe::heap(); + // Don't clear the soft refs yet. - heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold); + heap->collect_as_vm_thread(_gc_cause); // After a GC try to allocate without expanding. Could fail // and expansion will be tried below. _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype); diff --git a/src/hotspot/share/gc/shared/gcVMOperations.hpp b/src/hotspot/share/gc/shared/gcVMOperations.hpp index 321ad8e435f..a9aee2faf5d 100644 --- a/src/hotspot/share/gc/shared/gcVMOperations.hpp +++ b/src/hotspot/share/gc/shared/gcVMOperations.hpp @@ -222,8 +222,7 @@ class VM_CollectForMetadataAllocation: public VM_GC_Collect_Operation { size_t size, Metaspace::MetadataType mdtype, uint gc_count_before, - uint full_gc_count_before, - GCCause::Cause gc_cause); + uint full_gc_count_before); virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; } virtual void doit();