Skip to content

Commit

Permalink
[GR-59307] Adapt to the future removal of the ZGenerational flag
Browse files Browse the repository at this point in the history
PullRequest: graal/19103
  • Loading branch information
tkrodriguez committed Oct 26, 2024
2 parents 0afa288 + 775af51 commit 6dab549
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -229,11 +230,20 @@ public enum HotSpotGC {

private static Predicate<GraalHotSpotVMConfig> 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<GraalHotSpotVMConfig> flagIsNotSet(String flag) {
return flagIsSet(flag).negate();
private static Predicate<GraalHotSpotVMConfig> isZGenerational() {
return config -> {
if (JAVA_SPEC == 21) {
return false;
}
if (config.isZGenerationalDefault) {
return true;
} else {
return config.getFlag("ZGenerational", Boolean.class);
}
};
}

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6dab549

Please sign in to comment.