Skip to content

Commit d4474b5

Browse files
parttimenerdTheRealMDoerr
authored andcommitted
8285794: AsyncGetCallTrace might acquire a lock via JavaThread::thread_from_jni_environment
Reviewed-by: dholmes, mdoerr, jbachorik
1 parent 39f4434 commit d4474b5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/hotspot/share/prims/forte.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,13 @@ extern "C" {
564564
JNIEXPORT
565565
void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
566566

567+
// Can't use thread_from_jni_environment as it may also perform a VM exit check that is unsafe to
568+
// do from this context.
569+
Thread* raw_thread = Thread::current_or_null_safe();
567570
JavaThread* thread;
568571

569-
if (trace->env_id == NULL ||
570-
(thread = JavaThread::thread_from_jni_environment(trace->env_id))->is_exiting()) {
572+
if (trace->env_id == NULL || raw_thread == NULL || !raw_thread->is_Java_thread() ||
573+
(thread = JavaThread::cast(raw_thread))->is_exiting()) {
571574
// bad env_id, thread has exited or thread is exiting
572575
trace->num_frames = ticks_thread_exit; // -8
573576
return;
@@ -579,7 +582,8 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
579582
return;
580583
}
581584

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

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

0 commit comments

Comments
 (0)