Skip to content

Commit 55b4272

Browse files
author
duke
committed
Backport 9b1bed0aa416c615a81d429e2f1f33bc4f679109
1 parent c2087ed commit 55b4272

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, 2024, 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, 2024 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.
@@ -3795,6 +3795,7 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
37953795
MACOS_AARCH64_ONLY(thread->init_wx());
37963796

37973797
if (!os::create_attached_thread(thread)) {
3798+
thread->unregister_thread_stack_with_NMT();
37983799
thread->smr_delete();
37993800
return JNI_ERR;
38003801
}
@@ -3839,6 +3840,8 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae
38393840
if (attach_failed) {
38403841
// Added missing cleanup
38413842
thread->cleanup_failed_attach_current_thread(daemon);
3843+
thread->unregister_thread_stack_with_NMT();
3844+
thread->smr_delete();
38423845
return JNI_ERR;
38433846
}
38443847

@@ -3935,6 +3938,7 @@ jint JNICALL jni_DetachCurrentThread(JavaVM *vm) {
39353938
// (platform-dependent) methods where we do alternate stack
39363939
// maintenance work?)
39373940
thread->exit(false, JavaThread::jni_detach);
3941+
thread->unregister_thread_stack_with_NMT();
39383942
thread->smr_delete();
39393943

39403944
// 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
@@ -1050,7 +1050,6 @@ void JavaThread::cleanup_failed_attach_current_thread(bool is_daemon) {
10501050
}
10511051

10521052
Threads::remove(this, is_daemon);
1053-
this->smr_delete();
10541053
}
10551054

10561055
JavaThread* JavaThread::active() {

src/hotspot/share/runtime/thread.cpp

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

250+
// Logically we should do this->unregister_thread_stack_with_NMT() here, but we
251+
// had to move that into post_run() because of the `this` deletion issue.
252+
250253
assert(Thread::current_or_null() == nullptr, "current thread still present");
251254
}
252255

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, 2024, 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
@@ -150,8 +150,6 @@ serviceability/sa/ClhsdbPstack.java#core 8267433,8318754 macosx-x64,mac
150150
serviceability/sa/TestJmapCore.java 8267433,8318754 macosx-x64,macosx-aarch64
151151
serviceability/sa/TestJmapCoreMetaspace.java 8267433,8318754 macosx-x64,macosx-aarch64
152152

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

157155
#############################################################################

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)