Skip to content

Commit

Permalink
8290043: serviceability/attach/ConcAttachTest.java failed "guarantee(…
Browse files Browse the repository at this point in the history
…!CheckJNICalls) failed: Attached JNI thread exited without being detached"

Backport-of: 9b1bed0
  • Loading branch information
David Holmes committed Jan 24, 2025
1 parent 268ba3c commit 96bd21d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/hotspot/share/prims/jni.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@ void JavaThread::cleanup_failed_attach_current_thread(bool is_daemon) {
}

Threads::remove(this, is_daemon);
this->smr_delete();
}

JavaThread* JavaThread::active() {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
4 changes: 1 addition & 3 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -148,8 +148,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

#############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,8 +32,10 @@
* @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;
Expand Down

0 comments on commit 96bd21d

Please sign in to comment.