Skip to content
Permalink
Browse files
8285794: AsyncGetCallTrace might acquire a lock via JavaThread::threa…
…d_from_jni_environment

Reviewed-by: dholmes, mdoerr, jbachorik
  • Loading branch information
parttimenerd authored and TheRealMDoerr committed May 9, 2022
1 parent 39f4434 commit d4474b5816c2ec8daaf1c905b77d8ba4e23c9439
Showing 1 changed file with 7 additions and 3 deletions.
@@ -564,10 +564,13 @@ extern "C" {
JNIEXPORT
void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {

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

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

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

if (!JvmtiExport::should_post_class_load()) {

1 comment on commit d4474b5

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on d4474b5 May 9, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.