On Thu, 28 Apr 2022 09:38:30 GMT, Johannes Bechberger <d...@openjdk.java.net> wrote:
> Calling JavaThread::thread_from_jni_environment for a terminated thread in > AsyncGetCallTrace might cause the acquisition of a lock, making > AsyncGetCallTrace non-signal-safe. > > AsyncGetCallTrace can only be called for the current threads (there are > asserts for that), therefore using JavaThread::current directly and checking > the termination status is semantically equivalent. Changes requested by dholmes (Reviewer). src/hotspot/share/prims/forte.cpp line 566: > 564: void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* > ucontext) { > 565: > 566: JavaThread* thread = JavaThread::current_or_null(); As this can be in a signal handling context it needs to be Thread::current_or_null_safe(). src/hotspot/share/prims/forte.cpp line 568: > 566: JavaThread* thread = JavaThread::current_or_null(); > 567: > 568: if (trace->env_id == NULL || thread == NULL || thread->is_terminated() > || thread->is_exiting()) { `is_exiting()` also covers `is_terminated()`. src/hotspot/share/prims/forte.cpp line 580: > 578: } > 579: > 580: assert(thread == > JavaThread::thread_from_jni_environment(trace->env_id), Please add a comment before the assert: // This is safe now as the thread has not terminated and so no VM exit check occurs. ------------- PR: https://git.openjdk.java.net/jdk/pull/8446