# HG changeset patch # User mlarsson # Date 1438332052 -7200 # Fri Jul 31 10:40:52 2015 +0200 # Node ID f438c138d812143ebfaee4db44852c94d2fbbc47 # Parent d9bc27b8ef1ef2625fdbcc63491b4d3ab0e15fad 8065331: Add trace events for failed allocations Reviewed-by: diff --git a/src/share/vm/gc/shared/allocTracer.cpp b/src/share/vm/gc/shared/allocTracer.cpp --- a/src/share/vm/gc/shared/allocTracer.cpp +++ b/src/share/vm/gc/shared/allocTracer.cpp @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "gc/shared/allocTracer.hpp" +#include "gc/shared/gcId.hpp" #include "runtime/handles.hpp" #include "trace/tracing.hpp" #include "utilities/globalDefinitions.hpp" @@ -46,3 +47,12 @@ event.commit(); } } + +void AllocTracer::send_allocation_requiring_gc_event(size_t size, const GCId& gcId) { + EventAllocationRequiringGC event; + if (event.should_commit()) { + event.set_gcId(gcId.id()); + event.set_size(size); + event.commit(); + } +} diff --git a/src/share/vm/gc/shared/allocTracer.hpp b/src/share/vm/gc/shared/allocTracer.hpp --- a/src/share/vm/gc/shared/allocTracer.hpp +++ b/src/share/vm/gc/shared/allocTracer.hpp @@ -32,6 +32,7 @@ public: static void send_allocation_outside_tlab_event(KlassHandle klass, size_t alloc_size); static void send_allocation_in_new_tlab_event(KlassHandle klass, size_t tlab_size, size_t alloc_size); + static void send_allocation_requiring_gc_event(size_t size, const GCId& gcId); }; #endif /* SHARE_VM_GC_SHARED_ALLOCTRACER_HPP */ diff --git a/src/share/vm/gc/shared/vmGCOperations.cpp b/src/share/vm/gc/shared/vmGCOperations.cpp --- a/src/share/vm/gc/shared/vmGCOperations.cpp +++ b/src/share/vm/gc/shared/vmGCOperations.cpp @@ -187,6 +187,18 @@ gch->do_full_collection(gch->must_clear_all_soft_refs(), _max_generation); } +VM_CollectForMetadataAllocation::VM_CollectForMetadataAllocation(ClassLoaderData* loader_data, + 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), + _loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) { + assert(_size != 0, "An allocation should always be requested with this operation."); + AllocTracer::send_allocation_requiring_gc_event(_size * HeapWordSize, GCId::peek()); +} + // Returns true iff concurrent GCs unloads metadata. bool VM_CollectForMetadataAllocation::initiate_concurrent_GC() { #if INCLUDE_ALL_GCS @@ -291,3 +303,11 @@ set_gc_locked(); } } + +VM_CollectForAllocation::VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause) + : VM_GC_Operation(gc_count_before, cause), _result(NULL), _word_size(word_size) { + // Only report if operation was really caused by an allocation. + if (_word_size != 0) { + AllocTracer::send_allocation_requiring_gc_event(_word_size * HeapWordSize, GCId::peek()); + } +} diff --git a/src/share/vm/gc/shared/vmGCOperations.hpp b/src/share/vm/gc/shared/vmGCOperations.hpp --- a/src/share/vm/gc/shared/vmGCOperations.hpp +++ b/src/share/vm/gc/shared/vmGCOperations.hpp @@ -26,6 +26,7 @@ #define SHARE_VM_GC_SHARED_VMGCOPERATIONS_HPP #include "gc/shared/collectedHeap.hpp" +#include "gc/shared/gcId.hpp" #include "gc/shared/genCollectedHeap.hpp" #include "memory/heapInspection.hpp" #include "prims/jvmtiExport.hpp" @@ -166,8 +167,7 @@ HeapWord* _result; // Allocation result (NULL if allocation failed) public: - VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause) - : VM_GC_Operation(gc_count_before, cause), _result(NULL), _word_size(word_size) {} + VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause); HeapWord* result() const { return _result; @@ -218,10 +218,7 @@ 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), - _loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) { - } + GCCause::Cause gc_cause); virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; } virtual void doit(); MetaWord* result() const { return _result; } diff --git a/src/share/vm/trace/trace.xml b/src/share/vm/trace/trace.xml --- a/src/share/vm/trace/trace.xml +++ b/src/share/vm/trace/trace.xml @@ -1,6 +1,6 @@