@@ -119,6 +119,7 @@ class OSThreadSampler : public os::SuspendedThreadTask {
119119 JfrStackFrame *frames,
120120 u4 max_frames) : os::SuspendedThreadTask((Thread*)thread),
121121 _success (false ),
122+ _thread_oop(thread->threadObj ()),
122123 _stacktrace(frames, max_frames),
123124 _closure(closure),
124125 _suspend_time() {}
@@ -131,6 +132,7 @@ class OSThreadSampler : public os::SuspendedThreadTask {
131132
132133 private:
133134 bool _success;
135+ oop _thread_oop;
134136 JfrStackTrace _stacktrace;
135137 JfrThreadSampleClosure& _closure;
136138 JfrTicks _suspend_time;
@@ -190,7 +192,7 @@ void OSThreadSampler::protected_task(const os::SuspendedThreadTaskContext& conte
190192 ev->set_starttime (_suspend_time);
191193 ev->set_endtime (_suspend_time); // fake to not take an end time
192194 ev->set_sampledThread (JFR_THREAD_ID (jth));
193- ev->set_state (java_lang_Thread::get_thread_status (jth-> threadObj () ));
195+ ev->set_state (java_lang_Thread::get_thread_status (_thread_oop ));
194196 }
195197 }
196198}
@@ -202,7 +204,7 @@ void OSThreadSampler::take_sample() {
202204class JfrNativeSamplerCallback : public os ::CrashProtectionCallback {
203205 public:
204206 JfrNativeSamplerCallback (JfrThreadSampleClosure& closure, JavaThread* jt, JfrStackFrame* frames, u4 max_frames) :
205- _closure (closure), _jt(jt), _stacktrace(frames, max_frames), _success(false ) {
207+ _closure (closure), _jt(jt), _thread_oop(jt-> threadObj ()), _stacktrace(frames, max_frames), _success(false ) {
206208 }
207209 virtual void call ();
208210 bool success () { return _success; }
@@ -211,15 +213,16 @@ class JfrNativeSamplerCallback : public os::CrashProtectionCallback {
211213 private:
212214 JfrThreadSampleClosure& _closure;
213215 JavaThread* _jt;
216+ oop _thread_oop;
214217 JfrStackTrace _stacktrace;
215218 bool _success;
216219};
217220
218- static void write_native_event (JfrThreadSampleClosure& closure, JavaThread* jt) {
221+ static void write_native_event (JfrThreadSampleClosure& closure, JavaThread* jt, oop thread_oop ) {
219222 EventNativeMethodSample *ev = closure.next_event_native ();
220223 ev->set_starttime (JfrTicks::now ());
221224 ev->set_sampledThread (JFR_THREAD_ID (jt));
222- ev->set_state (java_lang_Thread::get_thread_status (jt-> threadObj () ));
225+ ev->set_state (java_lang_Thread::get_thread_status (thread_oop ));
223226}
224227
225228void JfrNativeSamplerCallback::call () {
@@ -241,7 +244,7 @@ void JfrNativeSamplerCallback::call() {
241244 topframe = first_java_frame;
242245 _success = _stacktrace.record_thread (*_jt, topframe);
243246 if (_success) {
244- write_native_event (_closure, _jt);
247+ write_native_event (_closure, _jt, _thread_oop );
245248 }
246249}
247250
0 commit comments