Skip to content

Commit f734b47

Browse files
committed
[GR-64843] Remove JDK 21 Substitutions from Native Image
PullRequest: graal/20757
2 parents cd4ccaa + 8d36b5f commit f734b47

File tree

60 files changed

+68
-1827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+68
-1827
lines changed

substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_java_lang_foreign_SymbolLookup.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.oracle.svm.core.jdk.Target_java_lang_Module;
5151
import com.oracle.svm.core.snippets.KnownIntrinsics;
5252

53-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
5453
import jdk.internal.foreign.MemorySessionImpl;
5554
import jdk.internal.foreign.Utils;
5655
import jdk.internal.loader.NativeLibrary;
@@ -139,11 +138,7 @@ static void ensureNativeAccess(Class<?> currentClass, Class<?> owner, String met
139138
*/
140139
Target_java_lang_Module module = SubstrateUtil.cast(currentClass != null ? currentClass.getModule() : ClassLoader.getSystemClassLoader().getUnnamedModule(),
141140
Target_java_lang_Module.class);
142-
if (JavaVersionUtil.JAVA_SPEC <= 21) {
143-
module.ensureNativeAccess(owner, methodName);
144-
} else {
145-
module.ensureNativeAccess(owner, methodName, currentClass, false);
146-
}
141+
module.ensureNativeAccess(owner, methodName, currentClass, false);
147142

148143
}
149144

substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_foreign_Utils_BaseAndScale.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,19 @@
3030
import com.oracle.svm.core.annotate.RecomputeFieldValue;
3131
import com.oracle.svm.core.annotate.TargetClass;
3232
import com.oracle.svm.core.config.ConfigurationValues;
33-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
34-
import com.oracle.svm.core.jdk.JDKLatest;
3533
import com.oracle.svm.core.util.VMError;
3634

3735
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3836
import jdk.internal.foreign.Utils;
3937
import jdk.vm.ci.meta.JavaKind;
4038

41-
@TargetClass(className = "jdk.internal.foreign.Utils", innerClass = "BaseAndScale", onlyWith = {ForeignAPIPredicates.Enabled.class, JDKLatest.class})
39+
@TargetClass(className = "jdk.internal.foreign.Utils", innerClass = "BaseAndScale", onlyWith = ForeignAPIPredicates.Enabled.class)
4240
final class Target_jdk_internal_foreign_Utils_BaseAndScale {
4341
@Alias //
4442
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = BaseFieldRecomputer.class) //
4543
long base;
4644
}
4745

48-
@TargetClass(className = "jdk.internal.foreign.Utils", innerClass = "BaseAndScale", onlyWith = {ForeignAPIPredicates.Enabled.class, JDK21OrEarlier.class})
49-
final class Target_jdk_internal_foreign_Utils_BaseAndScale_JDK21 {
50-
@Alias //
51-
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = BaseFieldRecomputer.class) //
52-
int base;
53-
}
54-
5546
final class BaseFieldRecomputer implements FieldValueTransformer {
5647

5748
@Override

substratevm/src/com.oracle.svm.core.foreign/src/com/oracle/svm/core/foreign/Target_jdk_internal_misc_ScopedMemoryAccess.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
import com.oracle.svm.core.ArenaIntrinsics;
3434
import com.oracle.svm.core.annotate.Substitute;
3535
import com.oracle.svm.core.annotate.TargetClass;
36-
import com.oracle.svm.core.annotate.TargetElement;
37-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
38-
import com.oracle.svm.core.jdk.JDKLatest;
3936
import com.oracle.svm.core.nodes.foreign.MemoryArenaValidInScopeNode;
4037
import com.oracle.svm.core.util.BasedOnJDKFile;
4138

@@ -99,7 +96,6 @@ static void registerNatives() {
9996
@SuppressWarnings("static-method")
10097
@Substitute
10198
@Target_jdk_internal_misc_ScopedMemoryAccess_Scoped
102-
@TargetElement(onlyWith = JDKLatest.class)
10399
@AlwaysInline("Safepoints must be visible in caller")
104100
public void loadInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mappedUtils, long address, boolean isSync, long size) {
105101
SubstrateForeignUtil.checkIdentity(mappedUtils, Target_java_nio_MappedMemoryUtils.PROXY);
@@ -120,7 +116,6 @@ public void loadInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mappe
120116
@SuppressWarnings("static-method")
121117
@Substitute
122118
@Target_jdk_internal_misc_ScopedMemoryAccess_Scoped
123-
@TargetElement(onlyWith = JDKLatest.class)
124119
@AlwaysInline("Safepoints must be visible in caller")
125120
public boolean isLoadedInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mappedUtils, long address, boolean isSync, long size) {
126121
SubstrateForeignUtil.checkIdentity(mappedUtils, Target_java_nio_MappedMemoryUtils.PROXY);
@@ -142,7 +137,6 @@ public boolean isLoadedInternal(MemorySessionImpl session, MappedMemoryUtilsProx
142137
@SuppressWarnings("static-method")
143138
@Substitute
144139
@Target_jdk_internal_misc_ScopedMemoryAccess_Scoped
145-
@TargetElement(onlyWith = JDKLatest.class)
146140
@AlwaysInline("Safepoints must be visible in caller")
147141
public void unloadInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mappedUtils, long address, boolean isSync, long size) {
148142
SubstrateForeignUtil.checkIdentity(mappedUtils, Target_java_nio_MappedMemoryUtils.PROXY);
@@ -165,7 +159,6 @@ public void unloadInternal(MemorySessionImpl session, MappedMemoryUtilsProxy map
165159
@SuppressWarnings("static-method")
166160
@Substitute
167161
@Target_jdk_internal_misc_ScopedMemoryAccess_Scoped
168-
@TargetElement(onlyWith = JDKLatest.class)
169162
@AlwaysInline("Safepoints must be visible in caller")
170163
public void forceInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mappedUtils, FileDescriptor fd, long address, boolean isSync, long index, long length) {
171164
SubstrateForeignUtil.checkIdentity(mappedUtils, Target_java_nio_MappedMemoryUtils.PROXY);
@@ -202,22 +195,13 @@ public void forceInternal(MemorySessionImpl session, MappedMemoryUtilsProxy mapp
202195
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-25+20/src/hotspot/share/prims/scopedMemoryAccess.cpp#L215-L218")
203196
@SuppressWarnings("static-method")
204197
@Substitute
205-
@TargetElement(onlyWith = JDKLatest.class)
206198
void closeScope0(Target_jdk_internal_foreign_MemorySessionImpl session, @SuppressWarnings("unused") Target_jdk_internal_misc_ScopedMemoryAccess_ScopedAccessError error) {
207199
new SyncCloseScopeOperation(session).enqueue();
208200
}
209-
210-
@SuppressWarnings("static-method")
211-
@Substitute
212-
@TargetElement(onlyWith = JDK21OrEarlier.class)
213-
boolean closeScope0(Target_jdk_internal_foreign_MemorySessionImpl session) {
214-
new SyncCloseScopeOperation(session).enqueue();
215-
return true;
216-
}
217201
}
218202

219203
@Retention(RetentionPolicy.RUNTIME)
220-
@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess$Scoped", onlyWith = {JDKLatest.class, ForeignAPIPredicates.Enabled.class})
204+
@TargetClass(className = "jdk.internal.misc.ScopedMemoryAccess$Scoped", onlyWith = ForeignAPIPredicates.Enabled.class)
221205
@interface Target_jdk_internal_misc_ScopedMemoryAccess_Scoped {
222206

223207
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/dcmd/AbstractJfrDCmd.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_dcmd_AbstractDCmd;
2929
import com.oracle.svm.core.util.VMError;
3030

31-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
32-
3331
/**
3432
* Base class for JFR-related diagnostic commands. Note that the JDK already implements those
3533
* diagnostic commands, so we wrap and reuse the JDK implementations.
@@ -57,16 +55,9 @@ protected String execute(DCmdArguments args) throws Throwable {
5755
@Override
5856
protected String getSyntaxAndExamples() {
5957
Target_jdk_jfr_internal_dcmd_AbstractDCmd cmd = createDCmd();
60-
String[] lines = getHelp(cmd);
58+
String[] lines = cmd.getHelp();
6159
return String.join(System.lineSeparator(), lines);
6260
}
6361

64-
private static String[] getHelp(Target_jdk_jfr_internal_dcmd_AbstractDCmd cmd) {
65-
if (JavaVersionUtil.JAVA_SPEC <= 21) {
66-
return cmd.printHelp();
67-
}
68-
return cmd.getHelp();
69-
}
70-
7162
protected abstract Target_jdk_jfr_internal_dcmd_AbstractDCmd createDCmd();
7263
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/ReferenceInternals.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.lang.ref.Reference;
3131
import java.lang.ref.SoftReference;
3232

33-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3433
import org.graalvm.word.Pointer;
3534

3635
import com.oracle.svm.core.NeverInline;
@@ -162,8 +161,7 @@ public static <T> void setNextDiscovered(Reference<T> instance, Reference<?> new
162161
}
163162

164163
public static boolean hasQueue(Reference<?> instance) {
165-
return cast(instance).queue != (JavaVersionUtil.JAVA_SPEC > 21 ? Target_java_lang_ref_ReferenceQueue.NULL_QUEUE
166-
: Target_java_lang_ref_ReferenceQueue.NULL);
164+
return cast(instance).queue != Target_java_lang_ref_ReferenceQueue.NULL_QUEUE;
167165
}
168166

169167
/*
@@ -231,8 +229,7 @@ public static void processPendingReferences() {
231229
} else {
232230
@SuppressWarnings("unchecked")
233231
Target_java_lang_ref_ReferenceQueue<? super Object> queue = SubstrateUtil.cast(ref.queue, Target_java_lang_ref_ReferenceQueue.class);
234-
if (queue != (JavaVersionUtil.JAVA_SPEC > 21 ? Target_java_lang_ref_ReferenceQueue.NULL_QUEUE
235-
: Target_java_lang_ref_ReferenceQueue.NULL)) {
232+
if (queue != Target_java_lang_ref_ReferenceQueue.NULL_QUEUE) {
236233
// Enqueues, avoiding the potentially overridden Reference.enqueue().
237234
queue.enqueue(ref);
238235
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_java_lang_ref_PhantomReference.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import com.oracle.svm.core.SubstrateUtil;
3030
import com.oracle.svm.core.annotate.Substitute;
3131
import com.oracle.svm.core.annotate.TargetClass;
32-
import com.oracle.svm.core.annotate.TargetElement;
33-
import com.oracle.svm.core.jdk.JDKLatest;
3432

3533
@TargetClass(PhantomReference.class)
3634
public final class Target_java_lang_ref_PhantomReference<T> {
@@ -40,7 +38,6 @@ boolean refersTo0(Object obj) {
4038
}
4139

4240
@Substitute
43-
@TargetElement(onlyWith = JDKLatest.class)
4441
private void clear0() {
4542
ReferenceInternals.clear(SubstrateUtil.cast(this, PhantomReference.class));
4643
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_java_lang_ref_Reference.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.lang.reflect.Field;
3030
import java.util.function.BooleanSupplier;
3131

32-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3332
import org.graalvm.nativeimage.Platform;
3433
import org.graalvm.nativeimage.Platforms;
3534
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
@@ -44,8 +43,6 @@
4443
import com.oracle.svm.core.annotate.RecomputeFieldValue;
4544
import com.oracle.svm.core.annotate.Substitute;
4645
import com.oracle.svm.core.annotate.TargetClass;
47-
import com.oracle.svm.core.annotate.TargetElement;
48-
import com.oracle.svm.core.jdk.JDKLatest;
4946
import com.oracle.svm.core.util.VMError;
5047
import com.oracle.svm.util.ReflectionUtil;
5148

@@ -120,8 +117,7 @@ public final class Target_java_lang_ref_Reference<T> {
120117
@Uninterruptible(reason = "The initialization of the fields must be atomic with respect to collection.")
121118
Target_java_lang_ref_Reference(T referent, Target_java_lang_ref_ReferenceQueue<? super T> queue) {
122119
this.referent = referent;
123-
this.queue = (queue == null) ? (JavaVersionUtil.JAVA_SPEC > 21 ? Target_java_lang_ref_ReferenceQueue.NULL_QUEUE
124-
: Target_java_lang_ref_ReferenceQueue.NULL) : queue;
120+
this.queue = (queue == null) ? Target_java_lang_ref_ReferenceQueue.NULL_QUEUE : queue;
125121
}
126122

127123
@KeepOriginal
@@ -135,7 +131,6 @@ private void clear0() {
135131
ReferenceInternals.clear(SubstrateUtil.cast(this, Reference.class));
136132
}
137133

138-
@TargetElement(onlyWith = JDKLatest.class)
139134
@KeepOriginal
140135
native void clearImpl();
141136

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_java_lang_ref_ReferenceQueue.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,14 @@
3030
import com.oracle.svm.core.annotate.Alias;
3131
import com.oracle.svm.core.annotate.RecomputeFieldValue;
3232
import com.oracle.svm.core.annotate.TargetClass;
33-
import com.oracle.svm.core.annotate.TargetElement;
34-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
35-
import com.oracle.svm.core.jdk.JDKLatest;
3633

3734
@TargetClass(ReferenceQueue.class)
3835
final class Target_java_lang_ref_ReferenceQueue<T> {
3936
// Checkstyle: stop
4037
@Alias //
41-
@TargetElement(onlyWith = JDKLatest.class) //
4238
static Target_java_lang_ref_ReferenceQueue<Object> NULL_QUEUE;
4339
// CheckStyle: resume
4440

45-
@Alias //
46-
@TargetElement(onlyWith = JDK21OrEarlier.class) //
47-
static Target_java_lang_ref_ReferenceQueue<Object> NULL;
48-
4941
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) //
5042
volatile Reference<? extends T> head;
5143

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Target_jdk_internal_ref_Cleaner.java

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.lang.ref.Cleaner;
2828
import java.lang.ref.ReferenceQueue;
2929

30-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3130
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
3231

3332
import com.oracle.svm.core.NeverInline;
@@ -37,11 +36,10 @@
3736
import com.oracle.svm.core.annotate.Substitute;
3837
import com.oracle.svm.core.annotate.TargetClass;
3938
import com.oracle.svm.core.annotate.TargetElement;
40-
import com.oracle.svm.core.jdk.JDK21OrEarlier;
41-
import com.oracle.svm.core.jdk.JDKLatest;
4239
import com.oracle.svm.core.thread.VMThreads;
4340
import com.oracle.svm.util.ReflectionUtil;
4441

42+
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
4543
import jdk.internal.misc.InnocuousThread;
4644

4745
@TargetClass(className = "jdk.internal.ref.Cleaner")
@@ -79,45 +77,13 @@ final class Target_java_lang_ref_Cleaner_Cleanable {
7977
@TargetClass(className = "jdk.internal.ref.CleanerImpl")
8078
final class Target_jdk_internal_ref_CleanerImpl {
8179

82-
@TargetElement(onlyWith = JDK21OrEarlier.class)//
83-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$PhantomCleanableRef")//
84-
Target_jdk_internal_ref_PhantomCleanable_JDK21 phantomCleanableList;
85-
86-
@TargetElement(onlyWith = JDKLatest.class)//
8780
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$CleanableList")//
8881
Target_jdk_internal_ref_CleanerImpl_CleanableList activeList;
8982

9083
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "java.lang.ref.ReferenceQueue")//
9184
public ReferenceQueue<Object> queue;
9285

93-
/**
94-
* This loop executes in a daemon thread and waits until there are no more cleanables (including
95-
* the {@code Cleaner} itself), ignoring {@link InterruptedException}. This blocks VM tear-down,
96-
* so we add a check if the VM is tearing down here.
97-
*/
98-
@TargetElement(name = "run", onlyWith = JDK21OrEarlier.class)
99-
@Substitute
100-
public void runJDK21() {
101-
Thread t = Thread.currentThread();
102-
InnocuousThread mlThread = (t instanceof InnocuousThread) ? (InnocuousThread) t : null;
103-
while (!phantomCleanableList.isListEmpty()) {
104-
if (mlThread != null) {
105-
mlThread.eraseThreadLocals();
106-
}
107-
try {
108-
Cleaner.Cleanable ref = (Cleaner.Cleanable) queue.remove(60 * 1000L);
109-
if (ref != null) {
110-
ref.clean();
111-
}
112-
} catch (Throwable e) {
113-
if (VMThreads.isTearingDown()) {
114-
return;
115-
}
116-
}
117-
}
118-
}
119-
120-
@TargetElement(name = "run", onlyWith = JDKLatest.class)
86+
@TargetElement(name = "run")
12187
@Substitute
12288
public void run() {
12389
Thread t = Thread.currentThread();
@@ -140,28 +106,7 @@ public void run() {
140106
}
141107
}
142108

143-
@TargetClass(className = "jdk.internal.ref.PhantomCleanable", onlyWith = JDK21OrEarlier.class)
144-
final class Target_jdk_internal_ref_PhantomCleanable_JDK21 {
145-
/*
146-
* Unlink from the list for the image heap so that we cannot reach Cleanables irrelevant for the
147-
* image heap which could fail the image build; we reset the list head anyway.
148-
*/
149-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = HolderObjectFieldTransformer.class) //
150-
Target_jdk_internal_ref_PhantomCleanable_JDK21 prev;
151-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = HolderObjectFieldTransformer.class) //
152-
Target_jdk_internal_ref_PhantomCleanable_JDK21 next;
153-
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = HolderObjectFieldTransformer.class) //
154-
Target_jdk_internal_ref_PhantomCleanable_JDK21 list;
155-
156-
@Alias
157-
native boolean isListEmpty();
158-
159-
@AnnotateOriginal
160-
@NeverInline("Ensure that every exception can be caught, including implicit exceptions.")
161-
/* final */ native void clean();
162-
}
163-
164-
@TargetClass(className = "jdk.internal.ref.PhantomCleanable", onlyWith = JDKLatest.class)
109+
@TargetClass(className = "jdk.internal.ref.PhantomCleanable")
165110
final class Target_jdk_internal_ref_PhantomCleanable {
166111
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = GetCleanableListSingletonTransformer.class) //
167112
Target_jdk_internal_ref_CleanerImpl_CleanableList list;
@@ -175,7 +120,7 @@ final class Target_jdk_internal_ref_PhantomCleanable {
175120
/* final */ native void clean();
176121
}
177122

178-
@TargetClass(className = "jdk.internal.ref.CleanerImpl$CleanableList", onlyWith = JDKLatest.class)
123+
@TargetClass(className = "jdk.internal.ref.CleanerImpl$CleanableList")
179124
final class Target_jdk_internal_ref_CleanerImpl_CleanableList {
180125

181126
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClassName = "jdk.internal.ref.CleanerImpl$CleanableList$Node") //
@@ -189,7 +134,7 @@ final class Target_jdk_internal_ref_CleanerImpl_CleanableList {
189134

190135
}
191136

192-
@TargetClass(className = "jdk.internal.ref.CleanerImpl$CleanableList$Node", onlyWith = JDKLatest.class)
137+
@TargetClass(className = "jdk.internal.ref.CleanerImpl$CleanableList$Node")
193138
final class Target_jdk_internal_ref_CleanerImpl_CleanableList_Node {
194139
}
195140

0 commit comments

Comments
 (0)