Skip to content

Commit 4b8e3db

Browse files
committed
[GR-64829] Remove JDK21 specific code in compiler.
PullRequest: graal/20750
2 parents 06875ea + 1e3449b commit 4b8e3db

File tree

41 files changed

+306
-1137
lines changed

Some content is hidden

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

41 files changed

+306
-1137
lines changed

compiler/mx.compiler/suite.py

+5-30
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@
269269
"jdk.internal.misc",
270270
"jdk.internal.util",
271271
"jdk.internal.vm.annotation",
272+
"sun.security.util.math",
273+
"sun.security.util.math.intpoly",
272274
],
273275
"java.instrument" : [
274276
"sun.instrument",
@@ -317,7 +319,7 @@
317319
"workingSets" : "Graal,HotSpot",
318320
},
319321

320-
"jdk.graal.compiler.hotspot.jdk21.test" : {
322+
"jdk.graal.compiler.hotspot.preview.test" : {
321323
"testProject" : True,
322324
"subDir" : "src",
323325
"sourceDirs" : ["src"],
@@ -340,32 +342,6 @@
340342
"graalCompilerSourceEdition": "ignore",
341343
},
342344

343-
"jdk.graal.compiler.hotspot.jdk23.test" : {
344-
"testProject" : True,
345-
"subDir" : "src",
346-
"sourceDirs" : ["src"],
347-
"dependencies" : [
348-
"jdk.graal.compiler.test",
349-
],
350-
"requiresConcealed" : {
351-
"java.base" : [
352-
"jdk.internal.util",
353-
"sun.security.util.math",
354-
"sun.security.util.math.intpoly",
355-
],
356-
"jdk.internal.vm.ci" : [
357-
"jdk.vm.ci.code",
358-
"jdk.vm.ci.meta",
359-
],
360-
},
361-
"checkstyle": "jdk.graal.compiler",
362-
"javaCompliance" : "23+",
363-
# GR-51699
364-
"forceJavac": True,
365-
"workingSets" : "Graal,HotSpot,Test",
366-
"graalCompilerSourceEdition": "ignore",
367-
},
368-
369345
"jdk.graal.compiler.virtual.bench" : {
370346
"subDir" : "src",
371347
"sourceDirs" : ["src"],
@@ -555,11 +531,10 @@
555531
"maven": False,
556532
"graalCompilerSourceEdition": "ignore",
557533
},
558-
"GRAAL_TEST_PREVIEW_FEATURE" : {
534+
"GRAAL_TEST_PREVIEW_FEATURES" : {
559535
"subDir" : "src",
560536
"dependencies" : [
561-
"jdk.graal.compiler.hotspot.jdk21.test",
562-
"jdk.graal.compiler.hotspot.jdk23.test",
537+
"jdk.graal.compiler.hotspot.preview.test",
563538
],
564539
"distDependencies" : [
565540
"GRAAL_TEST",
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package jdk.graal.compiler.hotspot.jdk21.test;
25+
package jdk.graal.compiler.hotspot.preview.test;
2626

2727
import java.io.IOException;
2828

Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package jdk.graal.compiler.hotspot.jdk21.test;
25+
package jdk.graal.compiler.hotspot.preview.test;
2626

2727
import java.lang.reflect.Method;
2828

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/BeforeJDK8346781.java

-43
This file was deleted.

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/JDKLatest.java

-40
This file was deleted.

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalFeature.java

+3-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,6 @@
3737
import java.util.IdentityHashMap;
3838
import java.util.List;
3939
import java.util.Map;
40-
import java.util.ServiceLoader;
4140
import java.util.Set;
4241
import java.util.TreeMap;
4342
import java.util.TreeSet;
@@ -46,8 +45,6 @@
4645
import java.util.function.Consumer;
4746
import java.util.stream.Collectors;
4847

49-
import jdk.graal.compiler.core.common.NativeImageSupport;
50-
import jdk.graal.compiler.hotspot.CompilerConfig;
5148
import org.graalvm.collections.EconomicMap;
5249
import org.graalvm.jniutils.NativeBridgeSupport;
5350
import org.graalvm.nativeimage.ImageInfo;
@@ -62,25 +59,23 @@
6259

6360
import jdk.graal.compiler.core.common.Fields;
6461
import jdk.graal.compiler.core.common.LibGraalSupport.HostedOnly;
62+
import jdk.graal.compiler.core.common.NativeImageSupport;
6563
import jdk.graal.compiler.core.common.spi.ForeignCallSignature;
6664
import jdk.graal.compiler.debug.GraalError;
6765
import jdk.graal.compiler.graph.Edges;
6866
import jdk.graal.compiler.graph.NodeClass;
67+
import jdk.graal.compiler.hotspot.CompilerConfig;
6968
import jdk.graal.compiler.hotspot.EncodedSnippets;
7069
import jdk.graal.compiler.hotspot.HotSpotForeignCallLinkage;
7170
import jdk.graal.compiler.hotspot.HotSpotReplacementsImpl;
7271
import jdk.graal.compiler.libgraal.truffle.LibGraalTruffleHostEnvironmentLookup;
7372
import jdk.graal.compiler.options.OptionDescriptor;
7473
import jdk.graal.compiler.options.OptionKey;
7574
import jdk.graal.compiler.options.OptionsParser;
76-
import jdk.graal.compiler.serviceprovider.GraalServices;
7775
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
7876
import jdk.graal.compiler.util.ObjectCopier;
7977
import jdk.internal.module.Modules;
80-
import jdk.vm.ci.hotspot.HotSpotJVMCIBackendFactory;
81-
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
8278
import jdk.vm.ci.hotspot.HotSpotModifiers;
83-
import jdk.vm.ci.services.JVMCIServiceLocator;
8479

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

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

397-
/**
398-
* Initialization of JVMCI code that needs to be done for JDK versions that do not include
399-
* JDK-8346781.
400-
*/
401-
private void doLegacyJVMCIInitialization() {
402-
if (!BeforeJDK8346781.VALUE) {
403-
return;
404-
}
405-
try {
406-
String rawArch = GraalServices.getSavedProperty("os.arch");
407-
String arch = switch (rawArch) {
408-
case "x86_64", "amd64" -> "AMD64";
409-
case "aarch64" -> "aarch64";
410-
case "riscv64" -> "riscv64";
411-
default -> throw new GraalError("Unknown or unsupported arch: %s", rawArch);
412-
};
413-
414-
ClassLoader cl = (ClassLoader) libgraalLoader;
415-
Field cachedHotSpotJVMCIBackendFactoriesField = ObjectCopier.getField(HotSpotJVMCIRuntime.class, "cachedHotSpotJVMCIBackendFactories");
416-
GraalError.guarantee(cachedHotSpotJVMCIBackendFactoriesField.get(null) == null, "Expect cachedHotSpotJVMCIBackendFactories to be null");
417-
ServiceLoader<HotSpotJVMCIBackendFactory> load = ServiceLoader.load(HotSpotJVMCIBackendFactory.class, cl);
418-
List<HotSpotJVMCIBackendFactory> backendFactories = load.stream()//
419-
.map(ServiceLoader.Provider::get)//
420-
.filter(s -> s.getArchitecture().equals(arch))//
421-
.toList();
422-
cachedHotSpotJVMCIBackendFactoriesField.set(null, backendFactories);
423-
GraalError.guarantee(backendFactories.size() == 1, "%s", backendFactories);
424-
425-
var jvmciServiceLocatorCachedLocatorsField = ObjectCopier.getField(JVMCIServiceLocator.class, "cachedLocators");
426-
GraalError.guarantee(jvmciServiceLocatorCachedLocatorsField.get(null) == null, "Expect cachedLocators to be null");
427-
Iterable<JVMCIServiceLocator> serviceLocators = ServiceLoader.load(JVMCIServiceLocator.class, cl);
428-
List<JVMCIServiceLocator> cachedLocators = new ArrayList<>();
429-
serviceLocators.forEach(cachedLocators::add);
430-
jvmciServiceLocatorCachedLocatorsField.set(null, cachedLocators);
431-
} catch (Throwable e) {
432-
throw new GraalError(e);
433-
}
434-
}
435-
436390
@Override
437391
public void afterAnalysis(AfterAnalysisAccess access) {
438392
optionCollector.afterAnalysis(access);

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalSubstitutions.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,22 +27,11 @@
2727
import com.oracle.svm.core.annotate.Alias;
2828
import com.oracle.svm.core.annotate.RecomputeFieldValue;
2929
import com.oracle.svm.core.annotate.TargetClass;
30-
import com.oracle.svm.core.annotate.TargetElement;
3130

3231
class LibGraalSubstitutions {
3332

3433
@TargetClass(className = "jdk.vm.ci.services.Services", onlyWith = LibGraalFeature.IsEnabled.class)
3534
static final class Target_jdk_vm_ci_services_Services {
36-
/**
37-
* Ensures field returns false if seen by the analysis.
38-
*/
39-
// Checkstyle: stop
40-
@Alias //
41-
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true)//
42-
@TargetElement(onlyWith = BeforeJDK8346781.class)//
43-
public static boolean IS_BUILDING_NATIVE_IMAGE = false;
44-
// Checkstyle: resume
45-
4635
/*
4736
* Static final boolean field Services.IS_IN_NATIVE_IMAGE is used in many places in the
4837
* JVMCI codebase to switch between the different implementations needed for regular use (a

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalSupportImpl.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import jdk.graal.compiler.debug.GraalError;
5757
import jdk.graal.compiler.libgraal.truffle.HSTruffleCompilerRuntime;
5858
import jdk.graal.compiler.options.OptionValues;
59-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
6059
import jdk.graal.compiler.word.Word;
6160
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
6261
import jdk.vm.ci.hotspot.HotSpotVMConfigAccess;
@@ -256,11 +255,8 @@ private static MethodHandle findCompilerThreadCanCallJavaScopeConstructor() {
256255
try {
257256
return MethodHandles.lookup().findConstructor(Class.forName("jdk.vm.ci.hotspot.CompilerThreadCanCallJavaScope"), MethodType.methodType(void.class, boolean.class));
258257
} catch (ReflectiveOperationException e) {
259-
if (JavaVersionUtil.JAVA_SPEC != 21) {
260-
throw new InternalError(e);
261-
}
258+
throw new InternalError(e);
262259
}
263-
return null;
264260
}
265261

266262
private final AutoCloseable impl;

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/truffle/LibGraalTruffleHostEnvironment.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424
*/
2525
package jdk.graal.compiler.libgraal.truffle;
2626

27+
import java.lang.invoke.MethodHandle;
28+
import java.lang.invoke.MethodHandles;
29+
import java.lang.invoke.MethodType;
30+
import java.util.List;
31+
2732
import com.oracle.truffle.compiler.HostMethodInfo;
2833
import com.oracle.truffle.compiler.TruffleCompilable;
2934
import com.oracle.truffle.compiler.TruffleCompilerRuntime;
35+
3036
import jdk.graal.compiler.core.common.util.MethodKey;
3137
import jdk.graal.compiler.hotspot.CompilationContext;
3238
import jdk.graal.compiler.hotspot.HotSpotGraalServices;
33-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
3439
import jdk.graal.compiler.truffle.TruffleCompilerImpl;
3540
import jdk.graal.compiler.truffle.TruffleElementCache;
3641
import jdk.graal.compiler.truffle.host.TruffleHostEnvironment;
@@ -40,11 +45,6 @@
4045
import jdk.vm.ci.meta.MetaAccessProvider;
4146
import jdk.vm.ci.meta.ResolvedJavaMethod;
4247

43-
import java.lang.invoke.MethodHandle;
44-
import java.lang.invoke.MethodHandles;
45-
import java.lang.invoke.MethodType;
46-
import java.util.List;
47-
4848
final class LibGraalTruffleHostEnvironment extends TruffleHostEnvironment {
4949

5050
private final HostMethodInfoCache hostCache = new HostMethodInfoCache();
@@ -132,11 +132,8 @@ private static MethodHandle findCompilerThreadCanCallJavaScopeConstructor() {
132132
try {
133133
return MethodHandles.lookup().findConstructor(Class.forName("jdk.vm.ci.hotspot.CompilerThreadCanCallJavaScope"), MethodType.methodType(void.class, boolean.class));
134134
} catch (ReflectiveOperationException e) {
135-
if (JavaVersionUtil.JAVA_SPEC != 21) {
136-
throw new InternalError(e);
137-
}
135+
throw new InternalError(e);
138136
}
139-
return null;
140137
}
141138

142139
private final AutoCloseable impl;

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/jfr/TestGetEventWriter.java

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.lang.reflect.InvocationTargetException;
3030

3131
import org.junit.Assert;
32-
import org.junit.Assume;
3332
import org.junit.Test;
3433
import org.objectweb.asm.AnnotationVisitor;
3534
import org.objectweb.asm.ClassWriter;
@@ -38,7 +37,6 @@
3837

3938
import jdk.graal.compiler.core.common.PermanentBailoutException;
4039
import jdk.graal.compiler.core.test.SubprocessTest;
41-
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
4240
import jdk.graal.compiler.test.AddExports;
4341
import jdk.jfr.Event;
4442
import jdk.jfr.Recording;
@@ -82,7 +80,6 @@ static class InitializationEvent extends Event {
8280

8381
@Test
8482
public void test() throws IOException, InterruptedException {
85-
Assume.assumeTrue(JavaVersionUtil.JAVA_SPEC > 21);
8683
String[] args;
8784
if (isJFRAvailable()) {
8885
args = new String[0];

0 commit comments

Comments
 (0)