23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "jfr/jfrEvents.hpp" |
26 #include "jfr/jfrEvents.hpp" |
27 #include "jfr/jni/jfrJavaSupport.hpp" |
27 #include "jfr/jni/jfrJavaSupport.hpp" |
|
28 #include "jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp" |
28 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
29 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
29 #include "jfr/recorder/jfrRecorder.hpp" |
30 #include "jfr/recorder/jfrRecorder.hpp" |
30 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
31 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
31 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
32 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
32 #include "jfr/recorder/service/jfrOptionSet.hpp" |
33 #include "jfr/recorder/service/jfrOptionSet.hpp" |
33 #include "jfr/recorder/storage/jfrStorage.hpp" |
34 #include "jfr/recorder/storage/jfrStorage.hpp" |
34 #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" |
|
35 #include "jfr/support/jfrThreadLocal.hpp" |
35 #include "jfr/support/jfrThreadLocal.hpp" |
36 #include "memory/allocation.inline.hpp" |
36 #include "memory/allocation.inline.hpp" |
37 #include "runtime/os.hpp" |
37 #include "runtime/os.hpp" |
38 #include "runtime/thread.inline.hpp" |
38 #include "runtime/thread.inline.hpp" |
39 #include "utilities/sizes.hpp" |
39 #include "utilities/sizes.hpp" |
44 _java_buffer(NULL), |
44 _java_buffer(NULL), |
45 _native_buffer(NULL), |
45 _native_buffer(NULL), |
46 _shelved_buffer(NULL), |
46 _shelved_buffer(NULL), |
47 _stackframes(NULL), |
47 _stackframes(NULL), |
48 _trace_id(JfrTraceId::assign_thread_id()), |
48 _trace_id(JfrTraceId::assign_thread_id()), |
49 _thread_cp(), |
49 _thread(), |
50 _data_lost(0), |
50 _data_lost(0), |
51 _stack_trace_id(max_julong), |
51 _stack_trace_id(max_julong), |
52 _user_time(0), |
52 _user_time(0), |
53 _cpu_time(0), |
53 _cpu_time(0), |
54 _wallclock_time(os::javaTimeNanos()), |
54 _wallclock_time(os::javaTimeNanos()), |
60 u8 JfrThreadLocal::add_data_lost(u8 value) { |
60 u8 JfrThreadLocal::add_data_lost(u8 value) { |
61 _data_lost += value; |
61 _data_lost += value; |
62 return _data_lost; |
62 return _data_lost; |
63 } |
63 } |
64 |
64 |
65 bool JfrThreadLocal::has_thread_checkpoint() const { |
65 bool JfrThreadLocal::has_thread_blob() const { |
66 return _thread_cp.valid(); |
66 return _thread.valid(); |
67 } |
67 } |
68 |
68 |
69 void JfrThreadLocal::set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) { |
69 void JfrThreadLocal::set_thread_blob(const JfrBlobHandle& ref) { |
70 assert(!_thread_cp.valid(), "invariant"); |
70 assert(!_thread.valid(), "invariant"); |
71 _thread_cp = ref; |
71 _thread = ref; |
72 } |
72 } |
73 |
73 |
74 const JfrCheckpointBlobHandle& JfrThreadLocal::thread_checkpoint() const { |
74 const JfrBlobHandle& JfrThreadLocal::thread_blob() const { |
75 return _thread_cp; |
75 return _thread; |
76 } |
76 } |
77 |
77 |
78 static void send_java_thread_start_event(JavaThread* jt) { |
78 static void send_java_thread_start_event(JavaThread* jt) { |
79 EventThreadStart event; |
79 EventThreadStart event; |
80 event.set_thread(jt->jfr_thread_local()->thread_id()); |
80 event.set_thread(jt->jfr_thread_local()->thread_id()); |
93 |
93 |
94 static void send_java_thread_end_events(traceid id, JavaThread* jt) { |
94 static void send_java_thread_end_events(traceid id, JavaThread* jt) { |
95 assert(jt != NULL, "invariant"); |
95 assert(jt != NULL, "invariant"); |
96 assert(Thread::current() == jt, "invariant"); |
96 assert(Thread::current() == jt, "invariant"); |
97 assert(jt->jfr_thread_local()->trace_id() == id, "invariant"); |
97 assert(jt->jfr_thread_local()->trace_id() == id, "invariant"); |
98 EventThreadEnd event; |
98 if (JfrRecorder::is_recording()) { |
99 event.set_thread(id); |
99 EventThreadEnd event; |
100 event.commit(); |
100 event.set_thread(id); |
101 JfrThreadCPULoadEvent::send_event_for_thread(jt); |
101 event.commit(); |
|
102 JfrThreadCPULoadEvent::send_event_for_thread(jt); |
|
103 } |
102 } |
104 } |
103 |
105 |
104 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) { |
106 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) { |
105 assert(tl != NULL, "invariant"); |
107 assert(tl != NULL, "invariant"); |
106 assert(t != NULL, "invariant"); |
108 assert(t != NULL, "invariant"); |
123 |
125 |
124 void JfrThreadLocal::on_exit(Thread* t) { |
126 void JfrThreadLocal::on_exit(Thread* t) { |
125 assert(t != NULL, "invariant"); |
127 assert(t != NULL, "invariant"); |
126 JfrThreadLocal * const tl = t->jfr_thread_local(); |
128 JfrThreadLocal * const tl = t->jfr_thread_local(); |
127 assert(!tl->is_dead(), "invariant"); |
129 assert(!tl->is_dead(), "invariant"); |
128 if (JfrRecorder::is_recording()) { |
130 if (t->is_Java_thread()) { |
129 if (t->is_Java_thread()) { |
131 JavaThread* const jt = (JavaThread*)t; |
130 send_java_thread_end_events(tl->thread_id(), (JavaThread*)t); |
132 ObjectSampleCheckpoint::on_thread_exit(jt); |
131 } |
133 send_java_thread_end_events(tl->thread_id(), jt); |
132 } |
134 } |
133 release(tl, Thread::current()); // because it could be that Thread::current() != t |
135 release(tl, Thread::current()); // because it could be that Thread::current() != t |
134 } |
136 } |
135 |
137 |
136 JfrBuffer* JfrThreadLocal::install_native_buffer() const { |
138 JfrBuffer* JfrThreadLocal::install_native_buffer() const { |