From bffbfd7af95b7707adcfe359262f066f83dcd360 Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 9 Feb 2023 22:18:01 +0800 Subject: [PATCH] Fix the problem of adding redundant G1 parameters (#2092) --- .../hmcl/launch/DefaultLauncher.java | 24 +++++++------------ .../hmcl/util/platform/CommandBuilder.java | 4 ++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java index 8291c9cc8..028125f79 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java @@ -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); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java index eb61ba746..c06117f4b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java @@ -211,6 +211,10 @@ public final class CommandBuilder { return raw.removeIf(i -> pred.test(i.arg)); } + public boolean noneMatch(Predicate 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(" "));