Skip to content

[GR-64829] Remove JDK21 specific code in compiler. #11167

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

Closed
wants to merge 1 commit into from
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
35 changes: 5 additions & 30 deletions compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@
"jdk.internal.misc",
"jdk.internal.util",
"jdk.internal.vm.annotation",
"sun.security.util.math",
"sun.security.util.math.intpoly",
],
"java.instrument" : [
"sun.instrument",
Expand Down Expand Up @@ -317,7 +319,7 @@
"workingSets" : "Graal,HotSpot",
},

"jdk.graal.compiler.hotspot.jdk21.test" : {
"jdk.graal.compiler.hotspot.preview.test" : {
"testProject" : True,
"subDir" : "src",
"sourceDirs" : ["src"],
Expand All @@ -340,32 +342,6 @@
"graalCompilerSourceEdition": "ignore",
},

"jdk.graal.compiler.hotspot.jdk23.test" : {
"testProject" : True,
"subDir" : "src",
"sourceDirs" : ["src"],
"dependencies" : [
"jdk.graal.compiler.test",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.util",
"sun.security.util.math",
"sun.security.util.math.intpoly",
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.code",
"jdk.vm.ci.meta",
],
},
"checkstyle": "jdk.graal.compiler",
"javaCompliance" : "23+",
# GR-51699
"forceJavac": True,
"workingSets" : "Graal,HotSpot,Test",
"graalCompilerSourceEdition": "ignore",
},

"jdk.graal.compiler.virtual.bench" : {
"subDir" : "src",
"sourceDirs" : ["src"],
Expand Down Expand Up @@ -555,11 +531,10 @@
"maven": False,
"graalCompilerSourceEdition": "ignore",
},
"GRAAL_TEST_PREVIEW_FEATURE" : {
"GRAAL_TEST_PREVIEW_FEATURES" : {
"subDir" : "src",
"dependencies" : [
"jdk.graal.compiler.hotspot.jdk21.test",
"jdk.graal.compiler.hotspot.jdk23.test",
"jdk.graal.compiler.hotspot.preview.test",
],
"distDependencies" : [
"GRAAL_TEST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.graal.compiler.hotspot.jdk21.test;
package jdk.graal.compiler.hotspot.preview.test;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.graal.compiler.hotspot.jdk21.test;
package jdk.graal.compiler.hotspot.preview.test;

import java.lang.reflect.Method;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,7 +37,6 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
Expand All @@ -46,8 +45,6 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import jdk.graal.compiler.core.common.NativeImageSupport;
import jdk.graal.compiler.hotspot.CompilerConfig;
import org.graalvm.collections.EconomicMap;
import org.graalvm.jniutils.NativeBridgeSupport;
import org.graalvm.nativeimage.ImageInfo;
Expand All @@ -62,25 +59,23 @@

import jdk.graal.compiler.core.common.Fields;
import jdk.graal.compiler.core.common.LibGraalSupport.HostedOnly;
import jdk.graal.compiler.core.common.NativeImageSupport;
import jdk.graal.compiler.core.common.spi.ForeignCallSignature;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.graph.Edges;
import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.hotspot.CompilerConfig;
import jdk.graal.compiler.hotspot.EncodedSnippets;
import jdk.graal.compiler.hotspot.HotSpotForeignCallLinkage;
import jdk.graal.compiler.hotspot.HotSpotReplacementsImpl;
import jdk.graal.compiler.libgraal.truffle.LibGraalTruffleHostEnvironmentLookup;
import jdk.graal.compiler.options.OptionDescriptor;
import jdk.graal.compiler.options.OptionKey;
import jdk.graal.compiler.options.OptionsParser;
import jdk.graal.compiler.serviceprovider.GraalServices;
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
import jdk.graal.compiler.util.ObjectCopier;
import jdk.internal.module.Modules;
import jdk.vm.ci.hotspot.HotSpotJVMCIBackendFactory;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
import jdk.vm.ci.hotspot.HotSpotModifiers;
import jdk.vm.ci.services.JVMCIServiceLocator;

/**
* This feature builds the libgraal shared library (e.g., libjvmcicompiler.so on linux).
Expand Down Expand Up @@ -360,8 +355,6 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
RuntimeReflection.registerAllDeclaredClasses(Long.class);
RuntimeReflection.register(lookupField(lookupClass("java.lang.Long$LongCache"), "cache"));

doLegacyJVMCIInitialization();

GetCompilerConfig.Result configResult = GetCompilerConfig.from(libgraalJavaHome);
for (var e : configResult.opens().entrySet()) {
Module module = ModuleLayer.boot().findModule(e.getKey()).orElseThrow();
Expand Down Expand Up @@ -394,45 +387,6 @@ private static void checkNodeClasses(EncodedSnippets encodedSnippets, String act
GraalError.guarantee(actual.equals(expect), "%n%s%n !=%n%s", actual, expect);
}

/**
* Initialization of JVMCI code that needs to be done for JDK versions that do not include
* JDK-8346781.
*/
private void doLegacyJVMCIInitialization() {
if (!BeforeJDK8346781.VALUE) {
return;
}
try {
String rawArch = GraalServices.getSavedProperty("os.arch");
String arch = switch (rawArch) {
case "x86_64", "amd64" -> "AMD64";
case "aarch64" -> "aarch64";
case "riscv64" -> "riscv64";
default -> throw new GraalError("Unknown or unsupported arch: %s", rawArch);
};

ClassLoader cl = (ClassLoader) libgraalLoader;
Field cachedHotSpotJVMCIBackendFactoriesField = ObjectCopier.getField(HotSpotJVMCIRuntime.class, "cachedHotSpotJVMCIBackendFactories");
GraalError.guarantee(cachedHotSpotJVMCIBackendFactoriesField.get(null) == null, "Expect cachedHotSpotJVMCIBackendFactories to be null");
ServiceLoader<HotSpotJVMCIBackendFactory> load = ServiceLoader.load(HotSpotJVMCIBackendFactory.class, cl);
List<HotSpotJVMCIBackendFactory> backendFactories = load.stream()//
.map(ServiceLoader.Provider::get)//
.filter(s -> s.getArchitecture().equals(arch))//
.toList();
cachedHotSpotJVMCIBackendFactoriesField.set(null, backendFactories);
GraalError.guarantee(backendFactories.size() == 1, "%s", backendFactories);

var jvmciServiceLocatorCachedLocatorsField = ObjectCopier.getField(JVMCIServiceLocator.class, "cachedLocators");
GraalError.guarantee(jvmciServiceLocatorCachedLocatorsField.get(null) == null, "Expect cachedLocators to be null");
Iterable<JVMCIServiceLocator> serviceLocators = ServiceLoader.load(JVMCIServiceLocator.class, cl);
List<JVMCIServiceLocator> cachedLocators = new ArrayList<>();
serviceLocators.forEach(cachedLocators::add);
jvmciServiceLocatorCachedLocatorsField.set(null, cachedLocators);
} catch (Throwable e) {
throw new GraalError(e);
}
}

@Override
public void afterAnalysis(AfterAnalysisAccess access) {
optionCollector.afterAnalysis(access);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,22 +27,11 @@
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;

class LibGraalSubstitutions {

@TargetClass(className = "jdk.vm.ci.services.Services", onlyWith = LibGraalFeature.IsEnabled.class)
static final class Target_jdk_vm_ci_services_Services {
/**
* Ensures field returns false if seen by the analysis.
*/
// Checkstyle: stop
@Alias //
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true)//
@TargetElement(onlyWith = BeforeJDK8346781.class)//
public static boolean IS_BUILDING_NATIVE_IMAGE = false;
// Checkstyle: resume

/*
* Static final boolean field Services.IS_IN_NATIVE_IMAGE is used in many places in the
* JVMCI codebase to switch between the different implementations needed for regular use (a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.libgraal.truffle.HSTruffleCompilerRuntime;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.graal.compiler.word.Word;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
import jdk.vm.ci.hotspot.HotSpotVMConfigAccess;
Expand Down Expand Up @@ -256,11 +255,8 @@ private static MethodHandle findCompilerThreadCanCallJavaScopeConstructor() {
try {
return MethodHandles.lookup().findConstructor(Class.forName("jdk.vm.ci.hotspot.CompilerThreadCanCallJavaScope"), MethodType.methodType(void.class, boolean.class));
} catch (ReflectiveOperationException e) {
if (JavaVersionUtil.JAVA_SPEC != 21) {
throw new InternalError(e);
}
throw new InternalError(e);
}
return null;
}

private final AutoCloseable impl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
*/
package jdk.graal.compiler.libgraal.truffle;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.List;

import com.oracle.truffle.compiler.HostMethodInfo;
import com.oracle.truffle.compiler.TruffleCompilable;
import com.oracle.truffle.compiler.TruffleCompilerRuntime;

import jdk.graal.compiler.core.common.util.MethodKey;
import jdk.graal.compiler.hotspot.CompilationContext;
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.graal.compiler.truffle.TruffleCompilerImpl;
import jdk.graal.compiler.truffle.TruffleElementCache;
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
Expand All @@ -40,11 +45,6 @@
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaMethod;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.List;

final class LibGraalTruffleHostEnvironment extends TruffleHostEnvironment {

private final HostMethodInfoCache hostCache = new HostMethodInfoCache();
Expand Down Expand Up @@ -132,11 +132,8 @@ private static MethodHandle findCompilerThreadCanCallJavaScopeConstructor() {
try {
return MethodHandles.lookup().findConstructor(Class.forName("jdk.vm.ci.hotspot.CompilerThreadCanCallJavaScope"), MethodType.methodType(void.class, boolean.class));
} catch (ReflectiveOperationException e) {
if (JavaVersionUtil.JAVA_SPEC != 21) {
throw new InternalError(e);
}
throw new InternalError(e);
}
return null;
}

private final AutoCloseable impl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.lang.reflect.InvocationTargetException;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
Expand All @@ -38,7 +37,6 @@

import jdk.graal.compiler.core.common.PermanentBailoutException;
import jdk.graal.compiler.core.test.SubprocessTest;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.graal.compiler.test.AddExports;
import jdk.jfr.Event;
import jdk.jfr.Recording;
Expand Down Expand Up @@ -82,7 +80,6 @@ static class InitializationEvent extends Event {

@Test
public void test() throws IOException, InterruptedException {
Assume.assumeTrue(JavaVersionUtil.JAVA_SPEC > 21);
String[] args;
if (isJFRAvailable()) {
args = new String[0];
Expand Down
Loading