Skip to content

Commit

Permalink
8252627: Make it safe for JFR thread to read threadObj
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, mgronlun
  • Loading branch information
fisk committed Sep 7, 2020
1 parent e29c3f6 commit e0d5b5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/hotspot/share/gc/z/zObjectAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ uintptr_t ZObjectAllocator::alloc_medium_object(size_t size, ZAllocationFlags fl
}

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

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

uintptr_t ZObjectAllocator::alloc_object_for_relocation(size_t size) {
assert(ZThread::is_java() || ZThread::is_vm() || ZThread::is_worker() || ZThread::is_runtime_worker(),
"Unknown thread");

ZAllocationFlags flags;
flags.set_relocation();
flags.set_non_blocking();
Expand Down
13 changes: 8 additions & 5 deletions src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class OSThreadSampler : public os::SuspendedThreadTask {
JfrStackFrame *frames,
u4 max_frames) : os::SuspendedThreadTask((Thread*)thread),
_success(false),
_thread_oop(thread->threadObj()),
_stacktrace(frames, max_frames),
_closure(closure),
_suspend_time() {}
Expand All @@ -131,6 +132,7 @@ class OSThreadSampler : public os::SuspendedThreadTask {

private:
bool _success;
oop _thread_oop;
JfrStackTrace _stacktrace;
JfrThreadSampleClosure& _closure;
JfrTicks _suspend_time;
Expand Down Expand Up @@ -190,7 +192,7 @@ void OSThreadSampler::protected_task(const os::SuspendedThreadTaskContext& conte
ev->set_starttime(_suspend_time);
ev->set_endtime(_suspend_time); // fake to not take an end time
ev->set_sampledThread(JFR_THREAD_ID(jth));
ev->set_state(java_lang_Thread::get_thread_status(jth->threadObj()));
ev->set_state(java_lang_Thread::get_thread_status(_thread_oop));
}
}
}
Expand All @@ -202,7 +204,7 @@ void OSThreadSampler::take_sample() {
class JfrNativeSamplerCallback : public os::CrashProtectionCallback {
public:
JfrNativeSamplerCallback(JfrThreadSampleClosure& closure, JavaThread* jt, JfrStackFrame* frames, u4 max_frames) :
_closure(closure), _jt(jt), _stacktrace(frames, max_frames), _success(false) {
_closure(closure), _jt(jt), _thread_oop(jt->threadObj()), _stacktrace(frames, max_frames), _success(false) {
}
virtual void call();
bool success() { return _success; }
Expand All @@ -211,15 +213,16 @@ class JfrNativeSamplerCallback : public os::CrashProtectionCallback {
private:
JfrThreadSampleClosure& _closure;
JavaThread* _jt;
oop _thread_oop;
JfrStackTrace _stacktrace;
bool _success;
};

static void write_native_event(JfrThreadSampleClosure& closure, JavaThread* jt) {
static void write_native_event(JfrThreadSampleClosure& closure, JavaThread* jt, oop thread_oop) {
EventNativeMethodSample *ev = closure.next_event_native();
ev->set_starttime(JfrTicks::now());
ev->set_sampledThread(JFR_THREAD_ID(jt));
ev->set_state(java_lang_Thread::get_thread_status(jt->threadObj()));
ev->set_state(java_lang_Thread::get_thread_status(thread_oop));
}

void JfrNativeSamplerCallback::call() {
Expand All @@ -241,7 +244,7 @@ void JfrNativeSamplerCallback::call() {
topframe = first_java_frame;
_success = _stacktrace.record_thread(*_jt, topframe);
if (_success) {
write_native_event(_closure, _jt);
write_native_event(_closure, _jt, _thread_oop);
}
}

Expand Down

1 comment on commit e0d5b5f

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on e0d5b5f Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Issues

Please sign in to comment.