Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.internal.foreign.Utils;
import jdk.vm.ci.meta.JavaKind;

Expand Down Expand Up @@ -66,9 +65,6 @@ public Object transform(Object receiver, Object originalValue) {
throw VMError.shouldNotReachHere("Unexpected BaseAndScale instance: " + receiver);
}
int offset = ConfigurationValues.getObjectLayout().getArrayBaseOffset(kind);
if (JavaVersionUtil.JAVA_SPEC <= 21) {
return offset;
}
return (long) offset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.List;
Expand Down Expand Up @@ -90,26 +89,12 @@ public static String getArchitectureName() {
};
}

/*
* [GR-55515]: Accessing isTerminal() reflectively only for 21 JDK compatibility. After dropping
* JDK 21, use it directly.
*/
private static final Method IS_TERMINAL_METHOD = ReflectionUtil.lookupMethod(true, Console.class, "isTerminal");

private static boolean isTTY() {
Console console = System.console();
if (console == null) {
return false;
}
if (IS_TERMINAL_METHOD != null) {
try {
return (boolean) IS_TERMINAL_METHOD.invoke(console);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new Error(e);
}
} else {
return true;
}
return console.isTerminal();
}

public static boolean isNonInteractiveTerminal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
import java.util.concurrent.ConcurrentMap;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.vm.ci.meta.ResolvedJavaMethod;

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

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

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

@Override
public void beforeAnalysis(BeforeAnalysisAccess a) {
if (JavaVersionUtil.JAVA_SPEC < 23) {
/*
* Those methods are used by ObjectMethods.bootstrap to combine the Strings of the
* records into one String
*/

Class<?> stringConcatHelper = ReflectionUtil.lookupClass(false, "java.lang.StringConcatHelper");
Class<?> formatConcatItem = ReflectionUtil.lookupClass(false, "jdk.internal.util.FormatConcatItem");
RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "prepend", long.class, byte[].class, formatConcatItem, String.class));
RuntimeReflection.register(ReflectionUtil.lookupMethod(stringConcatHelper, "mix", long.class, formatConcatItem));
} else {
// JDK-8329948 removed the String Template feature
}
}

/**
* Check if the provided method is allowed to be executed at build time.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.internal.misc.InnocuousThread;

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

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

final class GetCleanableListSingletonTransformer implements FieldValueTransformer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
import jdk.graal.compiler.core.common.SuppressFBWarnings;
import jdk.graal.compiler.nodes.java.FinalFieldBarrierNode;
import jdk.graal.compiler.replacements.ReplacementsUtil;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.internal.access.JavaLangReflectAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.reflect.CallerSensitive;
Expand Down Expand Up @@ -2343,27 +2342,13 @@ private Constructor<?> generateConstructor(Class<?> cl, Constructor<?> construct
* mutated, as it is not cached. To cache this constructor, setAccessible call must be done
* on a copy and return that copy instead.
*/
Constructor<?> ctor = Helper_jdk_internal_reflect_ReflectionFactory.newConstructorWithAccessor(this, constructorToCall, acc);
Constructor<?> ctor = langReflectAccess.newConstructorWithAccessor(constructorToCall, acc);
ctor.setAccessible(true);
return ctor;
}

}

/**
* Reflectively access {@code JavaLangReflectAccess.newConstructorWithAccessor}. Once we drop JDK
* 21, this can be replaced by a direct call to the method. (GR-55515)
*/
final class Helper_jdk_internal_reflect_ReflectionFactory {
private static final Method NEW_CONSTRUCTOR_WITH_ACCESSOR = JavaVersionUtil.JAVA_SPEC > 21
? ReflectionUtil.lookupMethod(JavaLangReflectAccess.class, "newConstructorWithAccessor", Constructor.class, ConstructorAccessor.class)
: null;

static Constructor<?> newConstructorWithAccessor(Target_jdk_internal_reflect_ReflectionFactory reflectionFactory, Constructor<?> constructorToCall, ConstructorAccessor acc) {
return ReflectionUtil.invokeMethod(NEW_CONSTRUCTOR_WITH_ACCESSOR, reflectionFactory.langReflectAccess, constructorToCall, acc);
}
}

/**
* Ensure that we are not accidentally using the method handle based constructor accessor.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@
package com.oracle.svm.core.jdk;

import java.security.AccessControlContext;
import java.security.ProtectionDomain;
import java.util.ArrayDeque;
import java.util.Objects;

import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;

/**
* Stack for storing AccessControlContexts. Used in conjunction with
* {@code StackAccessControlContextVisitor}.
Expand Down Expand Up @@ -93,19 +88,3 @@ public static int length() {
return getStack().size();
}
}

@SuppressWarnings({"unused"})
public class AccessControllerUtil {

/**
* Instance that is used to mark contexts that were disallowed in
* {@code AccessControlContextReplacerFeature.replaceAccessControlContext()} If this marker is
* passed to {@code AccessController.doPrivileged()} a runtime error will be thrown.
*/
public static final AccessControlContext DISALLOWED_CONTEXT_MARKER;

static {
DISALLOWED_CONTEXT_MARKER = JavaVersionUtil.JAVA_SPEC > 21 ? null
: ReflectionUtil.newInstance(ReflectionUtil.lookupConstructor(AccessControlContext.class, ProtectionDomain[].class, boolean.class), new ProtectionDomain[0], true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.svm.core.jdk;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
Expand All @@ -36,18 +35,11 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;

/**
* Pure delegate implementation to ForkJoinPool.commonPool().
*/
public final class DeferredCommonPool extends ForkJoinPool {

private static final Method methodInvokeAllUninterruptibly = JavaVersionUtil.JAVA_SPEC >= 22 ? ReflectionUtil.lookupMethod(ForkJoinPool.class, "invokeAllUninterruptibly", Collection.class) : null;

public DeferredCommonPool() {
super(1, new DisallowingForkJoinWorkerThreadFactory(), null, false);
}
Expand Down Expand Up @@ -89,12 +81,7 @@ public ForkJoinTask<?> submit(Runnable task) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jfr.Name_jdk_jfr_internal_JDKEvents_helper;

@TargetClass(classNameProvider = Name_jdk_jfr_internal_JDKEvents_helper.class)
@TargetClass(jdk.jfr.internal.JDKEvents.class)
@Platforms(LINUX.class)
final class Target_jdk_jfr_internal_JDKEvents {
@Alias //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;

public abstract class PlatformNativeLibrarySupport {

public static final String[] defaultBuiltInLibraries = {
Expand Down Expand Up @@ -128,14 +126,11 @@ public abstract class PlatformNativeLibrarySupport {
"java_lang_invoke_VarHandle_set",
"java_lang_invoke_VarHandle_compareAndExchange",
"java_lang_invoke_VarHandle_getAcquire",
"java_lang_invoke_VarHandle_getAndSetAcquire");
if (JavaVersionUtil.JAVA_SPEC > 21) {
Collections.addAll(blocklist,
"java_nio_MappedMemoryUtils_load0",
"java_nio_MappedMemoryUtils_unload0",
"java_nio_MappedMemoryUtils_isLoaded0",
"java_nio_MappedMemoryUtils_force0");
}
"java_lang_invoke_VarHandle_getAndSetAcquire",
"java_nio_MappedMemoryUtils_load0",
"java_nio_MappedMemoryUtils_unload0",
"java_nio_MappedMemoryUtils_isLoaded0",
"java_nio_MappedMemoryUtils_force0");
defaultBuiltInPkgNativesBlocklist = blocklist.toArray(new String[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;

/**
* This class provides JDK-internal access to values that are also available via system properties.
* However, it must not return values changed by the user. We do not want to query the values during
Expand Down Expand Up @@ -198,40 +196,38 @@ final class Target_jdk_internal_util_StaticProperty {
SUN_JNU_ENCODING = p.getInitialProperty("sun.jnu.encoding");
JAVA_LOCALE_USE_OLD_ISO_CODES = p.getInitialProperty("java.locale.useOldISOCodes", "");

if (JavaVersionUtil.JAVA_SPEC > 21) {
OS_ARCH = p.getInitialProperty("os.arch");

USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en");
USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE);
USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE);
// for compatibility, check for old user.region property
USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, "");
if (!USER_REGION.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = USER_REGION.indexOf('_');
if (i >= 0) {
USER_COUNTRY = USER_REGION.substring(0, i);
USER_VARIANT = USER_REGION.substring(i + 1);
} else {
USER_COUNTRY = USER_REGION;
USER_VARIANT = "";
}
USER_SCRIPT = "";
OS_ARCH = p.getInitialProperty("os.arch");

USER_LANGUAGE = p.getInitialProperty(UserSystemProperty.LANGUAGE, "en");
USER_LANGUAGE_DISPLAY = p.getInitialProperty(UserSystemProperty.LANGUAGE_DISPLAY, USER_LANGUAGE);
USER_LANGUAGE_FORMAT = p.getInitialProperty(UserSystemProperty.LANGUAGE_FORMAT, USER_LANGUAGE);
// for compatibility, check for old user.region property
USER_REGION = p.getInitialProperty(UserSystemProperty.REGION, "");
if (!USER_REGION.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = USER_REGION.indexOf('_');
if (i >= 0) {
USER_COUNTRY = USER_REGION.substring(0, i);
USER_VARIANT = USER_REGION.substring(i + 1);
} else {
USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, "");
USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, "");
USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, "");
USER_COUNTRY = USER_REGION;
USER_VARIANT = "";
}
USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT);
USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT);
USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY);
USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY);
USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT);
USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT);
USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, "");
USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS);
USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS);
USER_SCRIPT = "";
} else {
USER_SCRIPT = p.getInitialProperty(UserSystemProperty.SCRIPT, "");
USER_COUNTRY = p.getInitialProperty(UserSystemProperty.COUNTRY, "");
USER_VARIANT = p.getInitialProperty(UserSystemProperty.VARIANT, "");
}
USER_SCRIPT_DISPLAY = p.getInitialProperty(UserSystemProperty.SCRIPT_DISPLAY, USER_SCRIPT);
USER_SCRIPT_FORMAT = p.getInitialProperty(UserSystemProperty.SCRIPT_FORMAT, USER_SCRIPT);
USER_COUNTRY_DISPLAY = p.getInitialProperty(UserSystemProperty.COUNTRY_DISPLAY, USER_COUNTRY);
USER_COUNTRY_FORMAT = p.getInitialProperty(UserSystemProperty.COUNTRY_FORMAT, USER_COUNTRY);
USER_VARIANT_DISPLAY = p.getInitialProperty(UserSystemProperty.VARIANT_DISPLAY, USER_VARIANT);
USER_VARIANT_FORMAT = p.getInitialProperty(UserSystemProperty.VARIANT_FORMAT, USER_VARIANT);
USER_EXTENSIONS = p.getInitialProperty(UserSystemProperty.EXTENSIONS, "");
USER_EXTENSIONS_DISPLAY = p.getInitialProperty(UserSystemProperty.EXTENSIONS_DISPLAY, USER_EXTENSIONS);
USER_EXTENSIONS_FORMAT = p.getInitialProperty(UserSystemProperty.EXTENSIONS_FORMAT, USER_EXTENSIONS);
}
}

Expand Down
Loading