Skip to content

Commit eb02540

Browse files
authored
Merge pull request #22939 from pshipton/bufcleanershut
Support jdk26 shutdown of the BufferCleaner thread
2 parents 983fdc8 + 372294f commit eb02540

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

jcl/src/java.base/share/classes/java/lang/J9VMInternals.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ private static void completeInitialization() {
113113
if (Boolean.getBoolean("ibm.java9.forceCommonCleanerShutdown")) { //$NON-NLS-1$
114114
Runnable runnable = () -> {
115115
Thread[] threads;
116-
/*[IF JAVA_SPEC_VERSION < 19]*/
117116
ThreadGroup threadGroup;
118117
try {
119118
Field innocuousThreadGroupField = InnocuousThread.class.getDeclaredField("INNOCUOUSTHREADGROUP"); //$NON-NLS-1$
@@ -123,16 +122,18 @@ private static void completeInitialization() {
123122
throw new InternalError(e);
124123
}
125124

126-
threads = new Thread[threadGroup.numThreads];
125+
threads = new Thread[threadGroup.activeCount()];
127126
threadGroup.enumerate(threads, false);
128-
/*[ELSE] JAVA_SPEC_VERSION < 19 */
129-
threads = Thread.getAllThreads();
130-
/*[ENDIF] JAVA_SPEC_VERSION < 19 */
131127

132128
CleanerShutdown.shutdownCleaner();
133129

134130
for (Thread t : threads) {
135-
if (t.getName().equals("Common-Cleaner")) { //$NON-NLS-1$
131+
String threadName = t.getName();
132+
if (threadName.equals("Common-Cleaner") //$NON-NLS-1$
133+
/*[IF JAVA_SPEC_VERSION >= 26]*/
134+
|| threadName.equals("BufferCleaner") //$NON-NLS-1$
135+
/*[ENDIF] JAVA_SPEC_VERSION >= 26 */
136+
) {
136137
t.interrupt();
137138
try {
138139
/* Need to wait for the Common-Cleaner thread to die before
@@ -150,7 +151,6 @@ private static void completeInitialization() {
150151
} catch (Throwable e) {
151152
/* empty block */
152153
}
153-
break;
154154
}
155155
}
156156
};

jcl/src/java.base/share/classes/jdk/internal/ref/CleanerShutdown.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434
@SuppressWarnings("javadoc")
3535
public class CleanerShutdown {
3636

37+
private static volatile boolean shuttingDown;
38+
39+
public static boolean shuttingDown() {
40+
return shuttingDown;
41+
}
42+
3743
public static void shutdownCleaner() {
44+
shuttingDown = true;
3845
Cleaner commonCleaner = CleanerFactory.cleaner();
3946
CleanerImpl commonCleanerImpl = CleanerImpl.getCleanerImpl(commonCleaner);
4047
Cleanable ref = null;

0 commit comments

Comments
 (0)