diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java index ea338c321011..7beb49240367 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java @@ -35,6 +35,7 @@ import jdk.graal.compiler.debug.Assertions; import jdk.graal.compiler.debug.GraalError; import jdk.graal.compiler.options.OptionValues; +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; import jdk.vm.ci.hotspot.HotSpotVMConfigStore; import jdk.vm.ci.meta.MetaAccessProvider; @@ -87,6 +88,14 @@ public boolean useG1GC() { return gc == HotSpotGraalRuntime.HotSpotGC.G1; } + /* + * There's no direct way to test for the presence of the boolean flag ZGenerational since there + * aren't any notPresent values which are distinct from the possible values. Instead use true + * and false as the notPresent value and check if it returns different answers. + */ + public final boolean isZGenerationalDefault = JavaVersionUtil.JAVA_SPEC > 21 && + (!access.getFlag("ZGenerational", Boolean.class, false).equals(access.getFlag("ZGenerational", Boolean.class, true))); + public boolean useXGC() { return gc == HotSpotGraalRuntime.HotSpotGC.X; } @@ -602,6 +611,13 @@ private long getZGCAddressField(String name) { public final int zPointerLoadShift = getConstant("ZPointerLoadShift", Integer.class, -1, osArch.equals("aarch64") && zgcSupport); private long getXGCAddressField(String name) { + if (JavaVersionUtil.JAVA_SPEC == 21 || isZGenerationalDefault) { + /* + * Graal does not support single gen ZGC in JDK 21 and it's no longer supported in 24 + * once the ZGenerational global flag has been removed. + */ + return 0; + } String realName = name; long address = 0; if (zgcSupport) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotGraalRuntime.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotGraalRuntime.java index 1c16b4c2a6dd..8319b8838d23 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotGraalRuntime.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotGraalRuntime.java @@ -25,6 +25,7 @@ package jdk.graal.compiler.hotspot; import static jdk.graal.compiler.core.common.GraalOptions.HotSpotPrintInlining; +import static jdk.graal.compiler.serviceprovider.JavaVersionUtil.JAVA_SPEC; import static jdk.vm.ci.common.InitTimer.timer; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; @@ -35,7 +36,6 @@ import java.util.Map; import java.util.function.Predicate; -import jdk.vm.ci.services.Services; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; @@ -75,6 +75,7 @@ import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.runtime.JVMCIBackend; +import jdk.vm.ci.services.Services; //JaCoCo Exclude @@ -206,8 +207,8 @@ public enum HotSpotGC { Parallel("UseParallelGC"), G1("UseG1GC"), // non-generational ZGC - X(flagIsSet("UseZGC").and(flagIsNotSet("ZGenerational"))), - Z(flagIsSet("UseZGC").and(flagIsSet("ZGenerational"))), + X(JAVA_SPEC >= 24, true, flagIsSet("UseZGC").and(isZGenerational().negate())), + Z(JAVA_SPEC >= 24, true, flagIsSet("UseZGC").and(isZGenerational())), Epsilon(true, true, flagIsSet("UseEpsilonGC")), // Unsupported GCs @@ -229,11 +230,20 @@ public enum HotSpotGC { private static Predicate flagIsSet(String flag) { final boolean notPresent = false; - return config1 -> config1.getFlag(flag, Boolean.class, notPresent, true); + return config -> config.getFlag(flag, Boolean.class, notPresent, true); } - private static Predicate flagIsNotSet(String flag) { - return flagIsSet(flag).negate(); + private static Predicate isZGenerational() { + return config -> { + if (JAVA_SPEC == 21) { + return false; + } + if (config.isZGenerationalDefault) { + return true; + } else { + return config.getFlag("ZGenerational", Boolean.class); + } + }; } /** @@ -267,7 +277,7 @@ static HotSpotGC forName(int name, GraalHotSpotVMConfig config) { // CollectedHeap::X is not defined in HotSpot. Query CollectedHeap::Z instead // and the ZGenerational flag. if (config.getConstant("CollectedHeap::Z", Integer.class, -1, gc.expectNamePresent) == name) { - if (config.getFlag("ZGenerational", Boolean.class, false, true)) { + if (isZGenerational().test(config)) { return Z; } else { return X;