Skip to content

Commit 175bd05

Browse files
parttimenerdTheRealMDoerr
authored andcommitted
8285794: AsyncGetCallTrace might acquire a lock via JavaThread::thread_from_jni_environment
Reviewed-by: mdoerr Backport-of: d4474b5816c2ec8daaf1c905b77d8ba4e23c9439
1 parent 3486bb2 commit 175bd05

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/hotspot/share/prims/forte.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,14 @@ static void forte_fill_call_trace_given_top(JavaThread* thd,
522522
extern "C" {
523523
JNIEXPORT
524524
void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
525-
JavaThread* thread;
526525

527-
if (trace->env_id == NULL ||
528-
(thread = JavaThread::thread_from_jni_environment(trace->env_id)) == NULL ||
529-
thread->is_exiting()) {
526+
// Can't use thread_from_jni_environment as it may also perform a VM exit check that is unsafe to
527+
// do from this context.
528+
Thread* raw_thread = Thread::current_or_null_safe();
529+
JavaThread* thread;
530530

531+
if (trace->env_id == NULL || raw_thread == NULL || !raw_thread->is_Java_thread() ||
532+
(thread = ((JavaThread*)raw_thread))->is_exiting()) {
531533
// bad env_id, thread has exited or thread is exiting
532534
trace->num_frames = ticks_thread_exit; // -8
533535
return;
@@ -539,7 +541,8 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
539541
return;
540542
}
541543

542-
assert(JavaThread::current() == thread,
544+
// This is safe now as the thread has not terminated and so no VM exit check occurs.
545+
assert(thread == JavaThread::thread_from_jni_environment(trace->env_id),
543546
"AsyncGetCallTrace must be called by the current interrupted thread");
544547

545548
if (!JvmtiExport::should_post_class_load()) {

0 commit comments

Comments
 (0)