8290043: serviceability/attach/ConcAttachTest.java failed "guarantee(!CheckJNICalls) failed: Attached JNI thread exited without being detached"

Reviewed-by: jsjolen, coleenp
This commit is contained in:
David Holmes 2025-01-14 19:49:55 +00:00
parent 2de71d0445
commit 9b1bed0aa4
5 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024 Red Hat, Inc.
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@ -3795,6 +3795,7 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
MACOS_AARCH64_ONLY(thread->init_wx());
if (!os::create_attached_thread(thread)) {
thread->unregister_thread_stack_with_NMT();
thread->smr_delete();
return JNI_ERR;
}
@ -3839,6 +3840,8 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
if (attach_failed) {
// Added missing cleanup
thread->cleanup_failed_attach_current_thread(daemon);
thread->unregister_thread_stack_with_NMT();
thread->smr_delete();
return JNI_ERR;
}
@ -3935,6 +3938,7 @@ jint JNICALL jni_DetachCurrentThread(JavaVM *vm) {
// (platform-dependent) methods where we do alternate stack
// maintenance work?)
thread->exit(false, JavaThread::jni_detach);
thread->unregister_thread_stack_with_NMT();
thread->smr_delete();
// Go to the execute mode, the initial state of the thread on creation.

View File

@ -1051,7 +1051,6 @@ void JavaThread::cleanup_failed_attach_current_thread(bool is_daemon) {
}
Threads::remove(this, is_daemon);
this->smr_delete();
}
JavaThread* JavaThread::active() {

View File

@ -247,6 +247,9 @@ void Thread::call_run() {
// asynchronously with respect to its termination - that is what _run_state can
// be used to check.
// Logically we should do this->unregister_thread_stack_with_NMT() here, but we
// had to move that into post_run() because of the `this` deletion issue.
assert(Thread::current_or_null() == nullptr, "current thread still present");
}

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -147,8 +147,6 @@ serviceability/sa/ClhsdbPstack.java#core 8267433,8318754 macosx-x64,mac
serviceability/sa/TestJmapCore.java 8267433,8318754 macosx-x64,macosx-aarch64
serviceability/sa/TestJmapCoreMetaspace.java 8267433,8318754 macosx-x64,macosx-aarch64
serviceability/attach/ConcAttachTest.java 8290043 linux-all
serviceability/jvmti/stress/StackTrace/NotSuspended/GetStackTraceNotSuspendedStressTest.java 8315980 linux-all,windows-x64
#############################################################################

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -32,8 +32,10 @@ import java.lang.management.*;
* @library /testlibrary
* @summary Basic test of Thread and ThreadMXBean queries on a natively
* attached thread that has failed to detach before terminating.
* @comment The native code only supports POSIX so no windows testing
* @run main/othervm/native TestTerminatedThread
* @comment The native code only supports POSIX so no windows testing.
* @comment Disable -Xcheck:jni else NMT can report a fatal error because
* we did not detach before exiting.
* @run main/othervm/native -XX:-CheckJNICalls TestTerminatedThread
*/
import jvmti.JVMTIUtils;