38 #include "runtime/thread.inline.hpp"
39 #include "utilities/sizes.hpp"
40
41 /* This data structure is per thread and only accessed by the thread itself, no locking required */
42 JfrThreadLocal::JfrThreadLocal() :
43 _java_event_writer(NULL),
44 _java_buffer(NULL),
45 _native_buffer(NULL),
46 _shelved_buffer(NULL),
47 _stackframes(NULL),
48 _trace_id(JfrTraceId::assign_thread_id()),
49 _thread_cp(),
50 _data_lost(0),
51 _stack_trace_id(max_julong),
52 _user_time(0),
53 _cpu_time(0),
54 _wallclock_time(os::javaTimeNanos()),
55 _stack_trace_hash(0),
56 _stackdepth(0),
57 _entering_suspend_flag(0),
58 _dead(false) {}
59
60 u8 JfrThreadLocal::add_data_lost(u8 value) {
61 _data_lost += value;
62 return _data_lost;
63 }
64
65 bool JfrThreadLocal::has_thread_checkpoint() const {
66 return _thread_cp.valid();
67 }
68
69 void JfrThreadLocal::set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) {
70 assert(!_thread_cp.valid(), "invariant");
71 _thread_cp = ref;
72 }
73
74 const JfrCheckpointBlobHandle& JfrThreadLocal::thread_checkpoint() const {
75 return _thread_cp;
76 }
77
78 static void send_java_thread_start_event(JavaThread* jt) {
79 EventThreadStart event;
80 event.set_thread(jt->jfr_thread_local()->thread_id());
81 event.commit();
82 }
83
84 void JfrThreadLocal::on_start(Thread* t) {
85 assert(t != NULL, "invariant");
86 assert(Thread::current() == t, "invariant");
87 if (JfrRecorder::is_recording()) {
88 if (t->is_Java_thread()) {
89 send_java_thread_start_event((JavaThread*)t);
90 }
91 }
92 }
93
94 static void send_java_thread_end_events(traceid id, JavaThread* jt) {
95 assert(jt != NULL, "invariant");
96 assert(Thread::current() == jt, "invariant");
97 assert(jt->jfr_thread_local()->trace_id() == id, "invariant");
98 EventThreadEnd event;
99 event.set_thread(id);
100 event.commit();
101 JfrThreadCPULoadEvent::send_event_for_thread(jt);
102 }
103
104 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) {
105 assert(tl != NULL, "invariant");
106 assert(t != NULL, "invariant");
107 assert(Thread::current() == t, "invariant");
108 assert(!tl->is_dead(), "invariant");
109 assert(tl->shelved_buffer() == NULL, "invariant");
110 if (tl->has_native_buffer()) {
|
38 #include "runtime/thread.inline.hpp"
39 #include "utilities/sizes.hpp"
40
41 /* This data structure is per thread and only accessed by the thread itself, no locking required */
42 JfrThreadLocal::JfrThreadLocal() :
43 _java_event_writer(NULL),
44 _java_buffer(NULL),
45 _native_buffer(NULL),
46 _shelved_buffer(NULL),
47 _stackframes(NULL),
48 _trace_id(JfrTraceId::assign_thread_id()),
49 _thread_cp(),
50 _data_lost(0),
51 _stack_trace_id(max_julong),
52 _user_time(0),
53 _cpu_time(0),
54 _wallclock_time(os::javaTimeNanos()),
55 _stack_trace_hash(0),
56 _stackdepth(0),
57 _entering_suspend_flag(0),
58 _dead(false) {
59
60 Thread* thread = Thread::current_or_null();
61 _parent_trace_id = thread != NULL ? thread->jfr_thread_local()->trace_id() : (traceid)0;
62 }
63
64 u8 JfrThreadLocal::add_data_lost(u8 value) {
65 _data_lost += value;
66 return _data_lost;
67 }
68
69 bool JfrThreadLocal::has_thread_checkpoint() const {
70 return _thread_cp.valid();
71 }
72
73 void JfrThreadLocal::set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) {
74 assert(!_thread_cp.valid(), "invariant");
75 _thread_cp = ref;
76 }
77
78 const JfrCheckpointBlobHandle& JfrThreadLocal::thread_checkpoint() const {
79 return _thread_cp;
80 }
81
82 static void send_java_thread_start_event(JavaThread* jt) {
83 EventThreadStart event;
84 event.set_thread(jt->jfr_thread_local()->thread_id());
85 event.set_parentThread(jt->jfr_thread_local()->parent_thread_id());
86 event.commit();
87 }
88
89 void JfrThreadLocal::on_start(Thread* t) {
90 assert(t != NULL, "invariant");
91 assert(Thread::current() == t, "invariant");
92 if (JfrRecorder::is_recording()) {
93 if (t->is_Java_thread()) {
94 send_java_thread_start_event((JavaThread*)t);
95 }
96 }
97 if (t->jfr_thread_local()->has_cached_stack_trace()) {
98 t->jfr_thread_local()->clear_cached_stack_trace();
99 }
100 }
101
102 static void send_java_thread_end_events(traceid id, JavaThread* jt) {
103 assert(jt != NULL, "invariant");
104 assert(Thread::current() == jt, "invariant");
105 assert(jt->jfr_thread_local()->trace_id() == id, "invariant");
106 EventThreadEnd event;
107 event.set_thread(id);
108 event.commit();
109 JfrThreadCPULoadEvent::send_event_for_thread(jt);
110 }
111
112 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) {
113 assert(tl != NULL, "invariant");
114 assert(t != NULL, "invariant");
115 assert(Thread::current() == t, "invariant");
116 assert(!tl->is_dead(), "invariant");
117 assert(tl->shelved_buffer() == NULL, "invariant");
118 if (tl->has_native_buffer()) {
|