Skip to content

Commit 6622b17

Browse files
committed
[GR-64855] Remove JDK 21 code guarded by JavaVersionUtil.JAVA_SPEC from Native Image
PullRequest: graal/20768
2 parents 3afaeb5 + 233930a commit 6622b17

File tree

54 files changed

+156
-1000
lines changed

Some content is hidden

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

54 files changed

+156
-1000
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.oracle.svm.core.config.ConfigurationValues;
3333
import com.oracle.svm.core.util.VMError;
3434

35-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3635
import jdk.internal.foreign.Utils;
3736
import jdk.vm.ci.meta.JavaKind;
3837

@@ -66,9 +65,6 @@ public Object transform(Object receiver, Object originalValue) {
6665
throw VMError.shouldNotReachHere("Unexpected BaseAndScale instance: " + receiver);
6766
}
6867
int offset = ConfigurationValues.getObjectLayout().getArrayBaseOffset(kind);
69-
if (JavaVersionUtil.JAVA_SPEC <= 21) {
70-
return offset;
71-
}
7268
return (long) offset;
7369
}
7470
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.lang.reflect.Constructor;
3131
import java.lang.reflect.Executable;
3232
import java.lang.reflect.Field;
33-
import java.lang.reflect.InvocationTargetException;
3433
import java.lang.reflect.Member;
3534
import java.lang.reflect.Method;
3635
import java.util.List;
@@ -90,26 +89,12 @@ public static String getArchitectureName() {
9089
};
9190
}
9291

93-
/*
94-
* [GR-55515]: Accessing isTerminal() reflectively only for 21 JDK compatibility. After dropping
95-
* JDK 21, use it directly.
96-
*/
97-
private static final Method IS_TERMINAL_METHOD = ReflectionUtil.lookupMethod(true, Console.class, "isTerminal");
98-
9992
private static boolean isTTY() {
10093
Console console = System.console();
10194
if (console == null) {
10295
return false;
10396
}
104-
if (IS_TERMINAL_METHOD != null) {
105-
try {
106-
return (boolean) IS_TERMINAL_METHOD.invoke(console);
107-
} catch (IllegalAccessException | InvocationTargetException e) {
108-
throw new Error(e);
109-
}
110-
} else {
111-
return true;
112-
}
97+
return console.isTerminal();
11398
}
11499

115100
public static boolean isNonInteractiveTerminal() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/bootstrap/BootstrapMethodConfiguration.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@
4040
import java.util.concurrent.ConcurrentMap;
4141

4242
import org.graalvm.nativeimage.ImageSingletons;
43-
import org.graalvm.nativeimage.hosted.RuntimeReflection;
4443

4544
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4645
import com.oracle.svm.core.feature.InternalFeature;
4746
import com.oracle.svm.util.ReflectionUtil;
4847

49-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
5048
import jdk.vm.ci.meta.ResolvedJavaMethod;
5149

5250
/**
@@ -107,37 +105,12 @@ public BootstrapMethodConfiguration() {
107105
Method enumSwitch = ReflectionUtil.lookupMethod(SwitchBootstraps.class, "enumSwitch", MethodHandles.Lookup.class, String.class, MethodType.class, Object[].class);
108106

109107
/* Bootstrap method used for retrieving the value of static final processors. */
110-
if (JavaVersionUtil.JAVA_SPEC < 23) {
111-
Class<?> templateRuntime = ReflectionUtil.lookupClass(false, "java.lang.runtime.TemplateRuntime");
112-
Method processStringTemplate = ReflectionUtil.lookupMethod(templateRuntime, "processStringTemplate", MethodHandles.Lookup.class, String.class, MethodType.class, MethodHandle.class,
113-
String[].class);
114-
indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch, processStringTemplate);
115-
} else {
116-
// JDK-8329948 removed the String Template feature
117-
indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch);
118-
}
108+
indyBuildTimeAllowList = Set.of(metafactory, altMetafactory, makeConcat, makeConcatWithConstants, bootstrap, typeSwitch, enumSwitch);
119109

120110
/* Set of bootstrap methods for constant dynamic allowed at build time is empty for now */
121111
condyBuildTimeAllowList = Set.of();
122112
}
123113

124-
@Override
125-
public void beforeAnalysis(BeforeAnalysisAccess a) {
126-
if (JavaVersionUtil.JAVA_SPEC < 23) {
127-
/*
128-
* Those methods are used by ObjectMethods.bootstrap to combine the Strings of the
129-
* records into one String
130-
*/
131-
132-
Class<?> stringConcatHelper = ReflectionUtil.lookupClass(false, "java.lang.StringConcatHelper");
133-
Class<?> formatConcatItem = ReflectionUtil.lookupClass(false, "jdk.internal.util.FormatConcatItem");
134-
RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "prepend", long.class, byte[].class, formatConcatItem, String.class));
135-
RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "mix", long.class, formatConcatItem));
136-
} else {
137-
// JDK-8329948 removed the String Template feature
138-
}
139-
}
140-
141114
/**
142115
* Check if the provided method is allowed to be executed at build time.
143116
*/

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.oracle.svm.core.thread.VMThreads;
4040
import com.oracle.svm.util.ReflectionUtil;
4141

42-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
4342
import jdk.internal.misc.InnocuousThread;
4443

4544
@TargetClass(className = "jdk.internal.ref.Cleaner")
@@ -146,7 +145,7 @@ public Object transform(Object receiver, Object originalValue) {
146145
}
147146

148147
final class Target_jdk_internal_ref_CleanerImpl_CleanableList_Singleton {
149-
static final Object list = JavaVersionUtil.JAVA_SPEC > 21 ? ReflectionUtil.newInstance(ReflectionUtil.lookupClass("jdk.internal.ref.CleanerImpl$CleanableList")) : null;
148+
static final Object list = ReflectionUtil.newInstance(ReflectionUtil.lookupClass("jdk.internal.ref.CleanerImpl$CleanableList"));
150149
}
151150

152151
final class GetCleanableListSingletonTransformer implements FieldValueTransformer {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
import jdk.graal.compiler.core.common.SuppressFBWarnings;
135135
import jdk.graal.compiler.nodes.java.FinalFieldBarrierNode;
136136
import jdk.graal.compiler.replacements.ReplacementsUtil;
137-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
138137
import jdk.internal.access.JavaLangReflectAccess;
139138
import jdk.internal.misc.Unsafe;
140139
import jdk.internal.reflect.CallerSensitive;
@@ -2343,27 +2342,13 @@ private Constructor<?> generateConstructor(Class<?> cl, Constructor<?> construct
23432342
* mutated, as it is not cached. To cache this constructor, setAccessible call must be done
23442343
* on a copy and return that copy instead.
23452344
*/
2346-
Constructor<?> ctor = Helper_jdk_internal_reflect_ReflectionFactory.newConstructorWithAccessor(this, constructorToCall, acc);
2345+
Constructor<?> ctor = langReflectAccess.newConstructorWithAccessor(constructorToCall, acc);
23472346
ctor.setAccessible(true);
23482347
return ctor;
23492348
}
23502349

23512350
}
23522351

2353-
/**
2354-
* Reflectively access {@code JavaLangReflectAccess.newConstructorWithAccessor}. Once we drop JDK
2355-
* 21, this can be replaced by a direct call to the method. (GR-55515)
2356-
*/
2357-
final class Helper_jdk_internal_reflect_ReflectionFactory {
2358-
private static final Method NEW_CONSTRUCTOR_WITH_ACCESSOR = JavaVersionUtil.JAVA_SPEC > 21
2359-
? ReflectionUtil.lookupMethod(JavaLangReflectAccess.class, "newConstructorWithAccessor", Constructor.class, ConstructorAccessor.class)
2360-
: null;
2361-
2362-
static Constructor<?> newConstructorWithAccessor(Target_jdk_internal_reflect_ReflectionFactory reflectionFactory, Constructor<?> constructorToCall, ConstructorAccessor acc) {
2363-
return ReflectionUtil.invokeMethod(NEW_CONSTRUCTOR_WITH_ACCESSOR, reflectionFactory.langReflectAccess, constructorToCall, acc);
2364-
}
2365-
}
2366-
23672352
/**
23682353
* Ensure that we are not accidentally using the method handle based constructor accessor.
23692354
*/

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/AccessControllerUtil.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525
package com.oracle.svm.core.jdk;
2626

2727
import java.security.AccessControlContext;
28-
import java.security.ProtectionDomain;
2928
import java.util.ArrayDeque;
3029
import java.util.Objects;
3130

32-
import com.oracle.svm.util.ReflectionUtil;
33-
34-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
35-
3631
/**
3732
* Stack for storing AccessControlContexts. Used in conjunction with
3833
* {@code StackAccessControlContextVisitor}.
@@ -93,19 +88,3 @@ public static int length() {
9388
return getStack().size();
9489
}
9590
}
96-
97-
@SuppressWarnings({"unused"})
98-
public class AccessControllerUtil {
99-
100-
/**
101-
* Instance that is used to mark contexts that were disallowed in
102-
* {@code AccessControlContextReplacerFeature.replaceAccessControlContext()} If this marker is
103-
* passed to {@code AccessController.doPrivileged()} a runtime error will be thrown.
104-
*/
105-
public static final AccessControlContext DISALLOWED_CONTEXT_MARKER;
106-
107-
static {
108-
DISALLOWED_CONTEXT_MARKER = JavaVersionUtil.JAVA_SPEC > 21 ? null
109-
: ReflectionUtil.newInstance(ReflectionUtil.lookupConstructor(AccessControlContext.class, ProtectionDomain[].class, boolean.class), new ProtectionDomain[0], true);
110-
}
111-
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/DeferredCommonPool.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package com.oracle.svm.core.jdk;
2626

27-
import java.lang.reflect.Method;
2827
import java.util.Collection;
2928
import java.util.List;
3029
import java.util.concurrent.Callable;
@@ -36,18 +35,11 @@
3635
import java.util.concurrent.TimeUnit;
3736
import java.util.concurrent.TimeoutException;
3837

39-
import com.oracle.svm.core.util.VMError;
40-
import com.oracle.svm.util.ReflectionUtil;
41-
42-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
43-
4438
/**
4539
* Pure delegate implementation to ForkJoinPool.commonPool().
4640
*/
4741
public final class DeferredCommonPool extends ForkJoinPool {
4842

49-
private static final Method methodInvokeAllUninterruptibly = JavaVersionUtil.JAVA_SPEC >= 22 ? ReflectionUtil.lookupMethod(ForkJoinPool.class, "invokeAllUninterruptibly", Collection.class) : null;
50-
5143
public DeferredCommonPool() {
5244
super(1, new DisallowingForkJoinWorkerThreadFactory(), null, false);
5345
}
@@ -89,12 +81,7 @@ public ForkJoinTask<?> submit(Runnable task) {
8981

9082
@SuppressWarnings({"unchecked", "static-method", "all"})
9183
public <T> List<Future<T>> invokeAllUninterruptibly(Collection<? extends Callable<T>> tasks) {
92-
VMError.guarantee(JavaVersionUtil.JAVA_SPEC >= 22, "invokeAllUninterruptibly only exists in JDK 22+");
93-
try {
94-
return (List<Future<T>>) methodInvokeAllUninterruptibly.invoke(ForkJoinPool.commonPool(), tasks);
95-
} catch (ReflectiveOperationException e) {
96-
throw VMError.shouldNotReachHere(e);
97-
}
84+
return ForkJoinPool.commonPool().invokeAllUninterruptibly(tasks);
9885
}
9986

10087
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535
import com.oracle.svm.core.annotate.RecomputeFieldValue;
3636
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
3737
import com.oracle.svm.core.annotate.TargetClass;
38-
import com.oracle.svm.core.jfr.Name_jdk_jfr_internal_JDKEvents_helper;
3938

40-
@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class)
39+
@TargetClass(jdk.jfr.internal.JDKEvents.class)
4140
@Platforms(LINUX.class)
4241
final class Target_jdk_jfr_internal_JDKEvents {
4342
@Alias //

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/PlatformNativeLibrarySupport.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import com.oracle.svm.core.feature.InternalFeature;
4040
import com.oracle.svm.core.util.VMError;
4141

42-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
43-
4442
public abstract class PlatformNativeLibrarySupport {
4543

4644
public static final String[] defaultBuiltInLibraries = {
@@ -128,14 +126,11 @@ public abstract class PlatformNativeLibrarySupport {
128126
"java_lang_invoke_VarHandle_set",
129127
"java_lang_invoke_VarHandle_compareAndExchange",
130128
"java_lang_invoke_VarHandle_getAcquire",
131-
"java_lang_invoke_VarHandle_getAndSetAcquire");
132-
if (JavaVersionUtil.JAVA_SPEC > 21) {
133-
Collections.addAll(blocklist,
134-
"java_nio_MappedMemoryUtils_load0",
135-
"java_nio_MappedMemoryUtils_unload0",
136-
"java_nio_MappedMemoryUtils_isLoaded0",
137-
"java_nio_MappedMemoryUtils_force0");
138-
}
129+
"java_lang_invoke_VarHandle_getAndSetAcquire",
130+
"java_nio_MappedMemoryUtils_load0",
131+
"java_nio_MappedMemoryUtils_unload0",
132+
"java_nio_MappedMemoryUtils_isLoaded0",
133+
"java_nio_MappedMemoryUtils_force0");
139134
defaultBuiltInPkgNativesBlocklist = blocklist.toArray(new String[0]);
140135
}
141136

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_internal_util_StaticProperty.java

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import com.oracle.svm.core.annotate.Substitute;
3434
import com.oracle.svm.core.annotate.TargetClass;
3535

36-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
37-
3836
/**
3937
* This class provides JDK-internal access to values that are also available via system properties.
4038
* However, it must not return values changed by the user. We do not want to query the values during
@@ -198,40 +196,38 @@ final class Target_jdk_internal_util_StaticProperty {
198196
SUN_JNU_ENCODING = p.getInitialProperty("sun.jnu.encoding");
199197
JAVA_LOCALE_USE_OLD_ISO_CODES = p.getInitialProperty("java.locale.useOldISOCodes", "");
200198

201-
if (JavaVersionUtil.JAVA_SPEC > 21) {
202-
OS_ARCH = p.getInitialProperty("os.arch");
203-
204-
USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en");
205-
USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE);
206-
USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE);
207-
// for compatibility, check for old user.region property
208-
USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, "");
209-
if (!USER_REGION.isEmpty()) {
210-
// region can be of form country, country_variant, or _variant
211-
int i = USER_REGION.indexOf('_');
212-
if (i >= 0) {
213-
USER_COUNTRY = USER_REGION.substring(0, i);
214-
USER_VARIANT = USER_REGION.substring(i + 1);
215-
} else {
216-
USER_COUNTRY = USER_REGION;
217-
USER_VARIANT = "";
218-
}
219-
USER_SCRIPT = "";
199+
OS_ARCH = p.getInitialProperty("os.arch");
200+
201+
USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en");
202+
USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE);
203+
USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE);
204+
// for compatibility, check for old user.region property
205+
USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, "");
206+
if (!USER_REGION.isEmpty()) {
207+
// region can be of form country, country_variant, or _variant
208+
int i = USER_REGION.indexOf('_');
209+
if (i >= 0) {
210+
USER_COUNTRY = USER_REGION.substring(0, i);
211+
USER_VARIANT = USER_REGION.substring(i + 1);
220212
} else {
221-
USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, "");
222-
USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, "");
223-
USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, "");
213+
USER_COUNTRY = USER_REGION;
214+
USER_VARIANT = "";
224215
}
225-
USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT);
226-
USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT);
227-
USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY);
228-
USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY);
229-
USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT);
230-
USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT);
231-
USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, "");
232-
USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS);
233-
USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS);
216+
USER_SCRIPT = "";
217+
} else {
218+
USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, "");
219+
USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, "");
220+
USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, "");
234221
}
222+
USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT);
223+
USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT);
224+
USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY);
225+
USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY);
226+
USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT);
227+
USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT);
228+
USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, "");
229+
USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS);
230+
USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS);
235231
}
236232
}
237233

0 commit comments

Comments
 (0)