Fix the problem of adding redundant G1 parameters (#2092)

This commit is contained in:
Glavo 2023-02-09 22:18:01 +08:00 committed by GitHub
parent a8c1e8d2cb
commit bffbfd7af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 16 deletions

View File

@ -180,22 +180,14 @@ public class DefaultLauncher extends Launcher {
res.addDefault("-Duser.home=", options.getGameDir().getParent());
// Using G1GC with its settings by default
if (options.getJava().getParsedVersion() >= JavaVersion.JAVA_8) {
boolean addG1Args = true;
for (String javaArg : options.getJavaArguments()) {
if ("-XX:-UseG1GC".equals(javaArg) || (javaArg.startsWith("-XX:+Use") && javaArg.endsWith("GC"))) {
addG1Args = false;
break;
}
}
if (addG1Args) {
res.addUnstableDefault("UnlockExperimentalVMOptions", true);
res.addUnstableDefault("UseG1GC", true);
res.addUnstableDefault("G1NewSizePercent", "20");
res.addUnstableDefault("G1ReservePercent", "20");
res.addUnstableDefault("MaxGCPauseMillis", "50");
res.addUnstableDefault("G1HeapRegionSize", "32m");
}
if (options.getJava().getParsedVersion() >= JavaVersion.JAVA_8
&& res.noneMatch(arg -> "-XX:-UseG1GC".equals(arg) || (arg.startsWith("-XX:+Use") && arg.endsWith("GC")))) {
res.addUnstableDefault("UnlockExperimentalVMOptions", true);
res.addUnstableDefault("UseG1GC", true);
res.addUnstableDefault("G1NewSizePercent", "20");
res.addUnstableDefault("G1ReservePercent", "20");
res.addUnstableDefault("MaxGCPauseMillis", "50");
res.addUnstableDefault("G1HeapRegionSize", "32m");
}
res.addUnstableDefault("UseAdaptiveSizePolicy", false);

View File

@ -211,6 +211,10 @@ public final class CommandBuilder {
return raw.removeIf(i -> pred.test(i.arg));
}
public boolean noneMatch(Predicate<String> predicate) {
return raw.stream().noneMatch(it -> predicate.test(it.arg));
}
@Override
public String toString() {
return raw.stream().map(i -> i.parse ? parse(i.arg) : i.arg).collect(Collectors.joining(" "));