Skip to content

Commit

Permalink
JDK24 removes CleanerImpl.phantomCleanableList
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Feng <[email protected]>
  • Loading branch information
JasonFengJ9 committed Dec 5, 2024
1 parent c963d9e commit 108d958
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/
package jdk.internal.ref;

import jdk.internal.ref.CleanerFactory;

import java.lang.ref.Cleaner;
import java.lang.ref.Cleaner.Cleanable;
/*[IF JAVA_SPEC_VERSION < 24]*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
/*[ENDIF] JAVA_SPEC_VERSION < 24 */

@SuppressWarnings("javadoc")
public class CleanerShutdown {
Expand All @@ -47,14 +47,15 @@ public static void shutdownCleaner() {
}
}

/*[IF JAVA_SPEC_VERSION < 24]*/
try {
Method phantomRemove = PhantomCleanable.class.getDeclaredMethod("remove", (Class<?>[]) null); //$NON-NLS-1$
Method phantomRemove = PhantomCleanable.class.getDeclaredMethod("remove"); //$NON-NLS-1$
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
phantomRemove.setAccessible(true);
return null;
});
while(!commonCleanerImpl.phantomCleanableList.isListEmpty()) {
phantomRemove.invoke(commonCleanerImpl.phantomCleanableList, (Object[]) null);
while (!commonCleanerImpl.phantomCleanableList.isListEmpty()) {
phantomRemove.invoke(commonCleanerImpl.phantomCleanableList);
}
} catch (NoSuchMethodException
| SecurityException
Expand All @@ -65,5 +66,6 @@ public static void shutdownCleaner() {
/* should not fail */
e.printStackTrace();
}
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
}
}

0 comments on commit 108d958

Please sign in to comment.