Skip to content

Commit

Permalink
General ObjectAllocationSample event definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mgronlun committed Dec 6, 2020
1 parent dba878a commit 196d254
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
24 changes: 4 additions & 20 deletions src/hotspot/share/gc/shared/allocTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,12 @@
#include "jfr/support/jfrAllocationTracer.hpp"
#endif

/*
* Allocation events are throttled so not each event will get written to JFR.
* _skipped_allocations and _skipped_events are maintained for tracking
* information about discarded allocation events, and are included in an event
* that is accepted.
*/
static THREAD_LOCAL size_t _skipped_allocations = 0;
static THREAD_LOCAL size_t _skipped_events = 0;

static void send_allocation_sample(Klass* klass, HeapWord* obj, size_t obj_alloc_size, size_t memory_alloc_size, Thread* thread) {
static void send_allocation_sample(Klass* klass, HeapWord* obj, size_t alloc_size, Thread* thread) {
EventObjectAllocationSample event;
if (event.should_commit()) {
event.set_objectClass(klass);
event.set_allocationSize(obj_alloc_size);
event.set_allocatedSinceLast(_skipped_allocations + memory_alloc_size);
event.set_skippedEvents(_skipped_events);
event.set_allocatedBytes(thread->allocated_bytes() + alloc_size);
event.commit();
_skipped_allocations = 0;
_skipped_events = 0;
} else {
_skipped_events++;
_skipped_allocations += memory_alloc_size;
}
}

Expand All @@ -65,7 +49,7 @@ void AllocTracer::send_allocation_outside_tlab(Klass* klass, HeapWord* obj, size
event.set_allocationSize(alloc_size);
event.commit();
}
send_allocation_sample(klass, obj, alloc_size, alloc_size, thread);
send_allocation_sample(klass, obj, 0, thread); // 0 as alloc_size, because it is already attributed to thread->allocated_bytes()
}

void AllocTracer::send_allocation_in_new_tlab(Klass* klass, HeapWord* obj, size_t tlab_size, size_t alloc_size, Thread* thread) {
Expand All @@ -77,7 +61,7 @@ void AllocTracer::send_allocation_in_new_tlab(Klass* klass, HeapWord* obj, size_
event.set_tlabSize(tlab_size);
event.commit();
}
send_allocation_sample(klass, obj, alloc_size, tlab_size, thread);
send_allocation_sample(klass, obj, alloc_size, thread);
}

void AllocTracer::send_allocation_requiring_gc_event(size_t size, uint gcId) {
Expand Down
4 changes: 1 addition & 3 deletions src/hotspot/share/jfr/metadata/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,7 @@
<Event name="ObjectAllocationSample" category="Java Application" label="Allocation sample" description="Allocation sample"
thread="true" stackTrace="true" startTime="false" throttle="true">
<Field type="Class" name="objectClass" label="Object Class" description="Class of allocated object" />
<Field type="ulong" contentType="bytes" name="allocationSize" label="Allocation Size" />
<Field type="ulong" contentType="bytes" name="allocatedSinceLast" label="Allocated since last sample"/>
<Field type="ulong" name="skippedEvents" label="Number of events skipped since last sample"/>
<Field type="long" contentType="bytes" name="allocatedBytes" label="Allocated Bytes" description="Cumulative number of bytes allocated on the Java heap by this thread"/>
</Event>

<Event name="OldObjectSample" category="Java Virtual Machine, Profiling" label="Old Object Sample" description="A potential memory leak" stackTrace="true" thread="true"
Expand Down

0 comments on commit 196d254

Please sign in to comment.