Skip to content

Commit e0d5b5f

Browse files
committedSep 7, 2020
8252627: Make it safe for JFR thread to read threadObj
Reviewed-by: dholmes, mgronlun
1 parent e29c3f6 commit e0d5b5f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed
 

‎src/hotspot/share/gc/z/zObjectAllocator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ uintptr_t ZObjectAllocator::alloc_medium_object(size_t size, ZAllocationFlags fl
146146
}
147147

148148
uintptr_t ZObjectAllocator::alloc_small_object_from_nonworker(size_t size, ZAllocationFlags flags) {
149-
assert(ZThread::is_java() || ZThread::is_vm() || ZThread::is_runtime_worker(),
150-
"Should be a Java, VM or Runtime worker thread");
149+
assert(!ZThread::is_worker(), "Should not be a worker thread");
151150

152151
// Non-worker small page allocation can never use the reserve
153152
flags.set_no_reserve();
@@ -208,9 +207,6 @@ uintptr_t ZObjectAllocator::alloc_object(size_t size) {
208207
}
209208

210209
uintptr_t ZObjectAllocator::alloc_object_for_relocation(size_t size) {
211-
assert(ZThread::is_java() || ZThread::is_vm() || ZThread::is_worker() || ZThread::is_runtime_worker(),
212-
"Unknown thread");
213-
214210
ZAllocationFlags flags;
215211
flags.set_relocation();
216212
flags.set_non_blocking();

‎src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
202204
class 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

225228
void 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

Comments
 (0)
Please sign in to comment.