提交 d504f843 编写于 作者: D Denghui Dong 提交者: D-D-H

[Backport] 8237499: JFR: Include stack trace in the ThreadStart event

Summary:

Test Plan: jdk/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java

Reviewed-by: zhengxiaolinX, yuleil

Issue: https://github.com/alibaba/dragonwell8/issues/127
上级 0192ed8b
......@@ -26,8 +26,9 @@
<Metadata>
<Event name="ThreadStart" category="Java Application" label="Java Thread Start" thread="true" startTime="false">
<Field type="Thread" name="thread" label="Java Thread" />
<Event name="ThreadStart" category="Java Application" label="Java Thread Start" thread="true" startTime="false" stackTrace="true">
<Field type="Thread" name="thread" label="New Java Thread" />
<Field type="Thread" name="parentThread" label="Parent Java Thread" />
</Event>
<Event name="ThreadEnd" category="Java Application" label="Java Thread End" thread="true" startTime="false">
......
......@@ -60,7 +60,11 @@ JfrThreadLocal::JfrThreadLocal() :
_cached_top_frame_bci(max_jint),
_alloc_count(0),
_alloc_count_until_sample(1),
_cached_event_id(MaxJfrEventId) {}
_cached_event_id(MaxJfrEventId) {
Thread* thread = ThreadLocalStorage::thread();
_parent_trace_id = thread != NULL ? thread->jfr_thread_local()->trace_id() : (traceid)0;
}
u8 JfrThreadLocal::add_data_lost(u8 value) {
_data_lost += value;
......@@ -83,6 +87,7 @@ const JfrBlobHandle& JfrThreadLocal::thread_blob() const {
static void send_java_thread_start_event(JavaThread* jt) {
EventThreadStart event;
event.set_thread(jt->jfr_thread_local()->thread_id());
event.set_parentThread(jt->jfr_thread_local()->parent_thread_id());
event.commit();
}
......@@ -98,6 +103,9 @@ void JfrThreadLocal::on_start(Thread* t) {
}
}
}
if (t->jfr_thread_local()->has_cached_stack_trace()) {
t->jfr_thread_local()->clear_cached_stack_trace();
}
}
static void send_java_thread_end_events(traceid id, JavaThread* jt) {
......
......@@ -52,6 +52,7 @@ class JfrThreadLocal {
volatile jint _entering_suspend_flag;
bool _excluded;
bool _dead;
traceid _parent_trace_id;
// Jfr callstack collection relies on vframeStream.
// But the bci of top frame can not be determined by vframeStream in some scenarios.
// For example, in the opto CallLeafNode runtime call of
......@@ -149,6 +150,10 @@ class JfrThreadLocal {
_trace_id = thread_id;
}
traceid parent_thread_id() const {
return _parent_trace_id;
}
void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) {
_stack_trace_id = id;
_stack_trace_hash = hash;
......
......@@ -5025,7 +5025,14 @@ static void post_thread_start_event(const JavaThread* jt) {
EventThreadStart event;
if (event.should_commit()) {
event.set_thread(JFR_THREAD_ID(jt));
event.set_parentThread((traceid)0);
if (EventThreadStart::is_stacktrace_enabled()) {
jt->jfr_thread_local()->set_cached_stack_trace_id((traceid)0);
event.commit();
jt->jfr_thread_local()->clear_cached_stack_trace();
} else {
event.commit();
}
}
}
......
......@@ -101,6 +101,7 @@
#endif // INCLUDE_ALL_GCS
#include <errno.h>
#include <jfr/recorder/jfrRecorder.hpp>
#ifndef USDT2
HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
......@@ -3230,6 +3231,15 @@ JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
"unable to create new native thread");
}
#if INCLUDE_JFR
if (JfrRecorder::is_recording() && EventThreadStart::is_enabled() &&
EventThreadStart::is_stacktrace_enabled()) {
JfrThreadLocal* tl = native_thread->jfr_thread_local();
// skip Thread.start() and Thread.start0()
tl->set_cached_stack_trace_id(JfrStackTraceRepository::record(thread, 2, WALK_BY_DEFAULT));
}
#endif
Thread::start(native_thread);
JVM_END
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册