From 36d63910f4818f8d91871be152a57b4313bb8600 Mon Sep 17 00:00:00 2001 From: tajila Date: Wed, 25 Oct 2023 09:11:28 -0400 Subject: [PATCH] Clear vmthread from thread object at shutdown Related to: eclipse-openj9/openj9#16659 Signed-off-by: tajila --- .../share/classes/java/lang/Thread.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/jcl/src/java.base/share/classes/java/lang/Thread.java b/jcl/src/java.base/share/classes/java/lang/Thread.java index 54a1f5f461a..28e6d94bb6c 100644 --- a/jcl/src/java.base/share/classes/java/lang/Thread.java +++ b/jcl/src/java.base/share/classes/java/lang/Thread.java @@ -1550,29 +1550,32 @@ void uncaughtException(Throwable e) { * @see J9VMInternals#threadCleanup() */ void exit() { + try { /*[IF JAVA_SPEC_VERSION >= 14]*/ - /* Refresh deadInterrupt value so it is accurate when thread reference is removed. */ - deadInterrupt = interrupted(); + /* Refresh deadInterrupt value so it is accurate when thread reference is removed. */ + deadInterrupt = interrupted(); /*[ENDIF] JAVA_SPEC_VERSION >= 14 */ /*[IF Sidecar18-SE-OpenJ9]*/ - if ((threadLocals != null) && TerminatingThreadLocal.REGISTRY.isPresent()) { - TerminatingThreadLocal.threadTerminated(); - } + if ((threadLocals != null) && TerminatingThreadLocal.REGISTRY.isPresent()) { + TerminatingThreadLocal.threadTerminated(); + } /*[ENDIF] Sidecar18-SE-OpenJ9 */ - /*[PR 97317]*/ - group = null; - - /*[PR CVMC 118827] references are not removed in dead threads */ - runnable = null; - inheritedAccessControlContext = null; + /*[PR 97317]*/ + group = null; - threadLocals = null; - inheritableThreadLocals = null; + /*[PR CVMC 118827] references are not removed in dead threads. */ + runnable = null; + inheritedAccessControlContext = null; - synchronized(lock) { - threadRef = Thread.NO_REF; // So that isAlive() can work + threadLocals = null; + inheritableThreadLocals = null; + } finally { + synchronized(lock) { + // So that isAlive() can work. + threadRef = Thread.NO_REF; + } } }