Skip to content

Commit 99cf6a1

Browse files
committed
backport 9b1bed0aa416c615a81d429e2f1f33bc4f679109
1 parent d1aa40f commit 99cf6a1

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

src/hotspot/share/prims/jni.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012 Red Hat, Inc.
44
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -3788,6 +3788,7 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
37883788
MACOS_AARCH64_ONLY(thread->init_wx());
37893789

37903790
if (!os::create_attached_thread(thread)) {
3791+
thread->unregister_thread_stack_with_NMT();
37913792
thread->smr_delete();
37923793
return JNI_ERR;
37933794
}
@@ -3832,6 +3833,8 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
38323833
if (attach_failed) {
38333834
// Added missing cleanup
38343835
thread->cleanup_failed_attach_current_thread(daemon);
3836+
thread->unregister_thread_stack_with_NMT();
3837+
thread->smr_delete();
38353838
return JNI_ERR;
38363839
}
38373840

@@ -3927,6 +3930,7 @@ jint JNICALL jni_DetachCurrentThread(JavaVM *vm) {
39273930
// (platform-dependent) methods where we do alternate stack
39283931
// maintenance work?)
39293932
thread->exit(false, JavaThread::jni_detach);
3933+
thread->unregister_thread_stack_with_NMT();
39303934
thread->smr_delete();
39313935

39323936
// Go to the execute mode, the initial state of the thread on creation.

src/hotspot/share/runtime/javaThread.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,6 @@ void JavaThread::cleanup_failed_attach_current_thread(bool is_daemon) {
978978
}
979979

980980
Threads::remove(this, is_daemon);
981-
this->smr_delete();
982981
}
983982

984983
JavaThread* JavaThread::active() {

src/hotspot/share/runtime/thread.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ void Thread::call_run() {
236236
// asynchronously with respect to its termination - that is what _run_state can
237237
// be used to check.
238238

239+
// Logically we should do this->unregister_thread_stack_with_NMT() here, but we
240+
// had to move that into post_run() because of the `this` deletion issue.
241+
239242
assert(Thread::current_or_null() == nullptr, "current thread still present");
240243
}
241244

test/hotspot/jtreg/ProblemList.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -151,8 +151,6 @@ serviceability/sa/ClhsdbPstack.java#core 8267433 macosx-x64
151151
serviceability/sa/TestJmapCore.java 8267433 macosx-x64
152152
serviceability/sa/TestJmapCoreMetaspace.java 8267433 macosx-x64
153153

154-
serviceability/attach/ConcAttachTest.java 8290043 linux-all
155-
156154
serviceability/jvmti/stress/StackTrace/NotSuspended/GetStackTraceNotSuspendedStressTest.java 8315980 linux-all,windows-x64
157155

158156
#############################################################################

test/hotspot/jtreg/runtime/jni/terminatedThread/TestTerminatedThread.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,8 +32,10 @@
3232
* @library /testlibrary
3333
* @summary Basic test of Thread and ThreadMXBean queries on a natively
3434
* attached thread that has failed to detach before terminating.
35-
* @comment The native code only supports POSIX so no windows testing
36-
* @run main/othervm/native TestTerminatedThread
35+
* @comment The native code only supports POSIX so no windows testing.
36+
* @comment Disable -Xcheck:jni else NMT can report a fatal error because
37+
* we did not detach before exiting.
38+
* @run main/othervm/native -XX:-CheckJNICalls TestTerminatedThread
3739
*/
3840

3941
import jvmti.JVMTIUtils;

0 commit comments

Comments
 (0)