Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/shared/collectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,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);

Expand Down
16 changes: 10 additions & 6 deletions src/hotspot/share/gc/shared/gcVMOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,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_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
uint full_gc_count_before)
: VM_GC_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());
Expand All @@ -215,8 +214,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
Expand All @@ -239,8 +241,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);
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/shared/gcVMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ class VM_CollectForMetadataAllocation: public VM_GC_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();
Expand Down