Skip to content

[JDK-8361636] Adapt JDK-8361426: (ref) Remove jdk.internal.ref.Cleaner #11588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
"galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-26+6-469", "platformspecific": true, "extrabundles": ["static-libs"]},
"galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-26+6-542", "platformspecific": true, "extrabundles": ["static-libs"]},

"oraclejdk17": {"name": "jpg-jdk", "version": "17.0.7", "build_id": "jdk-17.0.7+8", "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+4-jvmci-23.1-b02", "platformspecific": true },
Expand Down
7 changes: 7 additions & 0 deletions sdk/mx.sdk/mx_sdk_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,13 @@ def renaissanceIterations(self):
del benchmarks["gauss-mix"]
del benchmarks["page-rank"]
del benchmarks["movie-lens"]
if mx.get_jdk().javaCompliance >= '26':
# JDK-8361426 removes jdk.internal.ref.Cleaner and causes the following to fail
del benchmarks["als"]
del benchmarks["db-shootout"]
del benchmarks["dec-tree"]
del benchmarks["log-regression"]
del benchmarks["naive-bayes"]

return benchmarks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,11 @@ public static void processPendingReferences() {
pendingList = ref.discovered;
ref.discovered = null;

if (Target_jdk_internal_ref_Cleaner.class.isInstance(ref)) {
Target_jdk_internal_ref_Cleaner cleaner = Target_jdk_internal_ref_Cleaner.class.cast(ref);
// Cleaner catches all exceptions, cannot be overridden due to private c'tor
cleaner.clean();
synchronized (processPendingLock) {
// Notify any waiters that progress has been made. This improves latency
// for nio.Bits waiters, which are the only important ones.
processPendingLock.notifyAll();
}
} else {
@SuppressWarnings("unchecked")
Target_java_lang_ref_ReferenceQueue<? super Object> queue = SubstrateUtil.cast(ref.queue, Target_java_lang_ref_ReferenceQueue.class);
if (queue != Target_java_lang_ref_ReferenceQueue.NULL_QUEUE) {
// Enqueues, avoiding the potentially overridden Reference.enqueue().
queue.enqueue(ref);
}
@SuppressWarnings("unchecked")
Target_java_lang_ref_ReferenceQueue<? super Object> queue = SubstrateUtil.cast(ref.queue, Target_java_lang_ref_ReferenceQueue.class);
if (queue != Target_java_lang_ref_ReferenceQueue.NULL_QUEUE) {
// Enqueues, avoiding the potentially overridden Reference.enqueue().
queue.enqueue(ref);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,10 @@

import jdk.internal.misc.InnocuousThread;

@TargetClass(className = "jdk.internal.ref.Cleaner")
public final class Target_jdk_internal_ref_Cleaner {

@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)//
static Target_jdk_internal_ref_Cleaner first;

@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)//
static ReferenceQueue<Object> dummyQueue = new ReferenceQueue<>();

@Alias
native void clean();
@TargetClass(className = "java.lang.ref.Cleaner")
public final class Target_java_lang_ref_Cleaner {
@Alias//
public Target_jdk_internal_ref_CleanerImpl impl;
}

@TargetClass(className = "jdk.internal.ref.CleanerFactory")
Expand All @@ -60,12 +53,6 @@ final class Target_jdk_internal_ref_CleanerFactory {
public static native Target_java_lang_ref_Cleaner cleaner();
}

@TargetClass(className = "java.lang.ref.Cleaner")
final class Target_java_lang_ref_Cleaner {
@Alias//
public Target_jdk_internal_ref_CleanerImpl impl;
}

@TargetClass(className = "java.lang.ref.Cleaner$Cleanable")
final class Target_java_lang_ref_Cleaner_Cleanable {
@AnnotateOriginal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public interface DisallowedObjectReporter {
public static final Class<?> CONTINUATION_CLASS = ReflectionUtil.lookupClass("jdk.internal.vm.Continuation");
private static final Method CONTINUATION_IS_STARTED_METHOD = ReflectionUtil.lookupMethod(CONTINUATION_CLASS, "isStarted");
private static final Class<?> CLEANER_CLEANABLE_CLASS = ReflectionUtil.lookupClass("jdk.internal.ref.CleanerImpl$CleanerCleanable");
public static final Class<?> LEGACY_CLEANER_CLASS = ReflectionUtil.lookupClass("jdk.internal.ref.Cleaner");
public static final Class<?> MEMORY_SEGMENT_CLASS = ReflectionUtil.lookupClass("java.lang.foreign.MemorySegment");
public static final Class<?> SCOPE_CLASS = ReflectionUtil.lookupClass("java.lang.foreign.MemorySegment$Scope");

Expand All @@ -86,7 +85,7 @@ public static void check(Object obj, DisallowedObjectReporter reporter) {
onBufferReachable(buffer, reporter);
}

if (obj instanceof Cleaner.Cleanable || LEGACY_CLEANER_CLASS.isInstance(obj)) {
if (obj instanceof Cleaner.Cleanable) {
onCleanableReachable(obj, reporter);
}

Expand Down Expand Up @@ -182,22 +181,18 @@ public static void onBufferReachable(Buffer buffer, DisallowedObjectReporter rep
}

public static void onCleanableReachable(Object cleanable, DisallowedObjectReporter reporter) {
VMError.guarantee(cleanable instanceof Cleaner.Cleanable || LEGACY_CLEANER_CLASS.isInstance(cleanable));
VMError.guarantee(cleanable instanceof Cleaner.Cleanable);
/*
* Cleanable and jdk.internal.ref.Cleaner are used to release various resources such as
* native memory, file descriptors, or timers, which are not available at image runtime. By
* disallowing these objects, we detect when such resources are reachable.
* Cleanable is used to release various resources such as native memory, file descriptors,
* or timers, which are not available at image runtime. By disallowing these objects, we
* detect when such resources are reachable.
*
* If a Cleanable is a nulled (Phantom)Reference, its problematic resource is already
* unreachable, so we tolerate it.
*
* A CleanerCleanable serves only to keep a cleaner thread alive (without referencing the
* Thread) and does nothing, so we also tolerate it. We should encounter at least one such
* object for jdk.internal.ref.CleanerFactory.commonCleaner.
*
* Legacy jdk.internal.ref.Cleaner objects (formerly in sun.misc) should be used only by
* DirectByteBuffer, which we already cover above, but other code could also use them. If
* they have been nulled, we tolerate them, too.
*/
if (!(cleanable instanceof Reference<?> && ((Reference<?>) cleanable).refersTo(null)) && !CLEANER_CLEANABLE_CLASS.isInstance(cleanable)) {
throw reporter.raise("Detected an active instance of Cleanable or jdk.internal.ref.Cleaner in the image heap. This usually means that a resource " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.oracle.svm.hosted.image;

import static com.oracle.svm.core.image.DisallowedImageHeapObjects.CANCELLABLE_CLASS;
import static com.oracle.svm.core.image.DisallowedImageHeapObjects.LEGACY_CLEANER_CLASS;
import static com.oracle.svm.core.image.DisallowedImageHeapObjects.MEMORY_SEGMENT_CLASS;
import static com.oracle.svm.core.image.DisallowedImageHeapObjects.SCOPE_CLASS;

Expand Down Expand Up @@ -85,7 +84,6 @@ public void duringSetup(DuringSetupAccess a) {
access.registerObjectReachableCallback(FileDescriptor.class, (a1, obj, reason) -> DisallowedImageHeapObjects.onFileDescriptorReachable(obj, this::error));
access.registerObjectReachableCallback(Buffer.class, (a1, obj, reason) -> DisallowedImageHeapObjects.onBufferReachable(obj, this::error));
access.registerObjectReachableCallback(Cleaner.Cleanable.class, (a1, obj, reason) -> DisallowedImageHeapObjects.onCleanableReachable(obj, this::error));
access.registerObjectReachableCallback(LEGACY_CLEANER_CLASS, (a1, obj, reason) -> DisallowedImageHeapObjects.onCleanableReachable(obj, this::error));
access.registerObjectReachableCallback(Cleaner.class, (a1, obj, reason) -> DisallowedImageHeapObjects.onCleanerReachable(obj, this::error));
access.registerObjectReachableCallback(ZipFile.class, (a1, obj, reason) -> DisallowedImageHeapObjects.onZipFileReachable(obj, this::error));
access.registerObjectReachableCallback(CANCELLABLE_CLASS, (a1, obj, reason) -> DisallowedImageHeapObjects.onCancellableReachable(obj, this::error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,5 @@
"justification": "In native-image resource bundles are statically configured."
}
]
},
{
"name": "jdk.internal.ref.Cleaner",
"methods": [
{
"name": "clean",
"parameterTypes" : [
],
"justification": "Internal JDK Cleaner which does System.exit if it fails during JVM boot."
}
]
}
]
Loading