From 118924282176463c180e2bce8f2e1fd64bc0087b Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Fri, 31 May 2024 13:57:48 +0200 Subject: [PATCH] Do not attempt to read JavaThread state from non-JavaThread threads --- ddprof-lib/src/main/cpp/wallClock.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ddprof-lib/src/main/cpp/wallClock.cpp b/ddprof-lib/src/main/cpp/wallClock.cpp index 5a9e37becd..3440a33842 100644 --- a/ddprof-lib/src/main/cpp/wallClock.cpp +++ b/ddprof-lib/src/main/cpp/wallClock.cpp @@ -73,7 +73,8 @@ void WallClock::signalHandler(int signo, siginfo_t* siginfo, void* ucontext, u64 ExecutionEvent event; VMThread* vm_thread = VMThread::current(); - int raw_thread_state = vm_thread ? vm_thread->state() : 0; + bool is_java_thread = vm_thread && VM::jni(); + int raw_thread_state = vm_thread && is_java_thread ? vm_thread->state() : 0; bool is_initialized = raw_thread_state >= 4 && raw_thread_state < 12; ThreadState state = ThreadState::UNKNOWN; ExecutionMode mode = ExecutionMode::UNKNOWN; @@ -82,7 +83,7 @@ void WallClock::signalHandler(int signo, siginfo_t* siginfo, void* ucontext, u64 if (os_state != ThreadState::UNKNOWN) { state = os_state; } - mode = VM::jni() != NULL ? convertJvmExecutionState(raw_thread_state) : ExecutionMode::JVM; + mode = is_java_thread ? convertJvmExecutionState(raw_thread_state) : ExecutionMode::JVM; } if (state == ThreadState::UNKNOWN) { if (inSyscall(ucontext)) {