< prev index next >
src/share/vm/jfr/leakprofiler/sampling/objectSampler.cpp
Print this page
rev 9464 : PR for JDK8
@@ -126,43 +126,70 @@
}
}
// We were successful in acquiring the try lock and have been selected for adding a sample.
// Go ahead with installing our previously taken stacktrace into the stacktrace repository.
-//
+
+// TODO: record_for_leak_profiler replaces this function because it's doing
+// the JfrStackTraceRepository::add in leak_profile instance and set_cached_stack_trace_id.
+
traceid ObjectSampler::stacktrace_id(const JfrStackTrace* stacktrace, JavaThread* thread) {
assert(stacktrace != NULL, "invariant");
assert(stacktrace->hash() != 0, "invariant");
- const traceid stacktrace_id = JfrStackTraceRepository::add(stacktrace, thread);
+ const traceid stacktrace_id = JfrStackTraceRepository::add_for_leak_profiler(stacktrace, thread);
thread->jfr_thread_local()->set_cached_stack_trace_id(stacktrace_id, stacktrace->hash());
return stacktrace_id;
}
+class RecordStackTrace {
+ private:
+ JavaThread* _jt;
+ JfrStackTrace* _stacktrace;
+ bool _enabled;
+ public:
+ RecordStackTrace(JavaThread* jt, JfrStackTrace* st) : _jt(jt),
+ _stacktrace(st),
+ _enabled(JfrEventSetting::has_stacktrace(EventOldObjectSample::eventId)) {
+ if (_enabled) {
+ //tty->print_cr("objectSampler.cpp | ", st->)
+ JfrStackTraceRepository::record_for_leak_profiler(jt, st);
+ }
+ }
+ ~RecordStackTrace() {
+ if (_enabled) {
+ _jt->jfr_thread_local()->clear_cached_stack_trace();
+ }
+ }
+};
+
void ObjectSampler::sample(HeapWord* obj, size_t allocated, JavaThread* thread) {
assert(thread != NULL, "invariant");
assert(is_created(), "invariant");
const traceid thread_id = get_thread_id(thread);
if (thread_id == 0) {
return;
}
+
const JfrThreadLocal* const tl = thread->jfr_thread_local();
JfrStackTrace stacktrace(tl->stackframes(), tl->stackdepth());
fill_stacktrace(&stacktrace, thread);
+ RecordStackTrace rst(thread, &stacktrace);
+
// try enter critical section
JfrTryLock tryLock(&_lock);
if (!tryLock.has_lock()) {
if (LogJFR && Verbose) tty->print_cr("Skipping old object sample due to lock contention");
return;
}
- instance().add(obj, allocated, thread_id, &stacktrace, thread);
+ instance().add(obj, allocated, thread_id/*, &stacktrace*/, thread);
}
-void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id, JfrStackTrace* stacktrace, JavaThread* thread) {
- assert(stacktrace != NULL, "invariant");
+void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id/*, JfrStackTrace* stacktrace*/, JavaThread* thread) {
+ //assert(stacktrace != NULL, "invariant");
assert(thread_id != 0, "invariant");
assert(thread != NULL, "invariant");
assert(thread->jfr_thread_local()->has_thread_checkpoint(), "invariant");
if (_dead_samples) {
@@ -187,15 +214,25 @@
assert(sample != NULL, "invariant");
sample->set_thread_id(thread_id);
sample->set_thread_checkpoint(thread->jfr_thread_local()->thread_checkpoint());
+ const JfrThreadLocal* const tl = thread->jfr_thread_local();
+ const unsigned int stacktrace_hash = tl->cached_stack_trace_hash();
+ if (stacktrace_hash != 0) {
+ //tty->print_cr("objectSampler.cpp | Set sample stack trace id(%ld)/hash(%d)", tl->cached_stack_trace_id(), stacktrace_hash);
+ sample->set_stack_trace_id(tl->cached_stack_trace_id());
+ sample->set_stack_trace_hash(stacktrace_hash);
+ }
+ /*
const unsigned int stacktrace_hash = stacktrace->hash();
if (stacktrace_hash != 0) {
+ // Only place where stacktrace_id() is used
+ // stacktrace_id()
sample->set_stack_trace_id(stacktrace_id(stacktrace, thread));
sample->set_stack_trace_hash(stacktrace_hash);
- }
+ }*/
sample->set_span(allocated);
sample->set_object((oop)obj);
sample->set_allocated(allocated);
sample->set_allocation_time(JfrTicks::now());
< prev index next >