Skip to content

Commit

Permalink
8341427: JFR: Adjust object sampler span handling
Browse files Browse the repository at this point in the history
Reviewed-by: egahlin
  • Loading branch information
srdo authored and egahlin committed Nov 23, 2024
1 parent d00f311 commit 822a155
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,25 @@ void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id, bool
// quick reject, will not fit
return;
}
sample = _list->reuse(_priority_queue->pop());
ObjectSample* popped = _priority_queue->pop();
size_t popped_span = popped->span();
ObjectSample* previous = popped->prev();
sample = _list->reuse(popped);
assert(sample != nullptr, "invariant");
if (previous != nullptr) {
push_span(previous, popped_span);
sample->set_span(span);
} else {
// The removed sample was the youngest sample in the list, which means the new sample is now the youngest
// sample. It should cover the spans of both.
sample->set_span(span + popped_span);
}
} else {
sample = _list->get();
assert(sample != nullptr, "invariant");
sample->set_span(span);
}

assert(sample != nullptr, "invariant");
signal_unresolved_entry();
sample->set_thread_id(thread_id);
if (virtual_thread) {
Expand All @@ -278,7 +291,6 @@ void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id, bool
sample->set_stack_trace_hash(stacktrace_hash);
}

sample->set_span(allocated);
sample->set_object(cast_to_oop(obj));
sample->set_allocated(allocated);
sample->set_allocation_time(JfrTicks::now());
Expand All @@ -305,14 +317,18 @@ void ObjectSampler::remove_dead(ObjectSample* sample) {
ObjectSample* const previous = sample->prev();
// push span onto previous
if (previous != nullptr) {
_priority_queue->remove(previous);
previous->add_span(sample->span());
_priority_queue->push(previous);
push_span(previous, sample->span());
}
_priority_queue->remove(sample);
_list->release(sample);
}

void ObjectSampler::push_span(ObjectSample* sample, size_t span) {
_priority_queue->remove(sample);
sample->add_span(span);
_priority_queue->push(sample);
}

ObjectSample* ObjectSampler::last() const {
return _list->last();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ObjectSampler : public CHeapObj<mtTracing> {
void add(HeapWord* object, size_t size, traceid thread_id, bool virtual_thread, const JfrBlobHandle& bh, JavaThread* thread);
void scavenge();
void remove_dead(ObjectSample* sample);
void push_span(ObjectSample* sample, size_t span);

const ObjectSample* item_at(int index) const;
ObjectSample* item_at(int index);
Expand Down

1 comment on commit 822a155

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.