用户 JVM 参数优先于默认参数 (#903)
* close #885: use the GC selected by user by default * fix: default JVM args conflict with user args * Options take precedence over JVM args * compile huge methods by default * update settings.advanced.jvm_args text * Using JVM args suppression options * update settings.advanced.jvm_args text
This commit is contained in:
@@ -52,7 +52,6 @@ import static org.jackhuang.hmcl.util.Lang.mapOf;
|
||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DefaultLauncher extends Launcher {
|
||||
@@ -84,53 +83,63 @@ public class DefaultLauncher extends Launcher {
|
||||
if (!options.isNoGeneratedJVMArgs()) {
|
||||
appendJvmArgs(res);
|
||||
|
||||
res.add("-Dminecraft.client.jar=" + repository.getVersionJar(version));
|
||||
res.addDefault("-Dminecraft.client.jar=", repository.getVersionJar(version).toString());
|
||||
|
||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) {
|
||||
res.add("-Xdock:name=Minecraft " + version.getId());
|
||||
res.add("-Xdock:icon=" + repository.getAssetObject(version.getId(), version.getAssetIndex().getId(), "icons/minecraft.icns").getAbsolutePath());
|
||||
res.addDefault("-Xdock:name=", "Minecraft " + version.getId());
|
||||
res.addDefault("-Xdock:icon=", repository.getAssetObject(version.getId(), version.getAssetIndex().getId(), "icons/minecraft.icns").getAbsolutePath());
|
||||
}
|
||||
|
||||
if (OperatingSystem.CURRENT_OS != OperatingSystem.WINDOWS)
|
||||
res.add("-Duser.home=" + options.getGameDir().getParent());
|
||||
res.addDefault("-Duser.home=", options.getGameDir().getParent());
|
||||
|
||||
// Force using G1GC with its settings
|
||||
// Using G1GC with its settings by default
|
||||
if (options.getJava().getParsedVersion() >= JavaVersion.JAVA_8) {
|
||||
res.add("-XX:+UnlockExperimentalVMOptions");
|
||||
res.add("-XX:+UseG1GC");
|
||||
res.add("-XX:G1NewSizePercent=20");
|
||||
res.add("-XX:G1ReservePercent=20");
|
||||
res.add("-XX:MaxGCPauseMillis=50");
|
||||
res.add("-XX:G1HeapRegionSize=16M");
|
||||
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", "16m");
|
||||
}
|
||||
}
|
||||
|
||||
if (options.getMetaspace() != null && options.getMetaspace() > 0)
|
||||
if (options.getJava().getParsedVersion() < JavaVersion.JAVA_8)
|
||||
res.add("-XX:PermSize= " + options.getMetaspace() + "m");
|
||||
res.addDefault("-XX:PermSize=", options.getMetaspace() + "m");
|
||||
else
|
||||
res.add("-XX:MetaspaceSize=" + options.getMetaspace() + "m");
|
||||
res.addDefault("-XX:MetaspaceSize=", options.getMetaspace() + "m");
|
||||
|
||||
res.add("-XX:-UseAdaptiveSizePolicy");
|
||||
res.add("-XX:-OmitStackTraceInFastThrow");
|
||||
res.add("-Xmn128m");
|
||||
res.addUnstableDefault("UseAdaptiveSizePolicy", false);
|
||||
res.addUnstableDefault("OmitStackTraceInFastThrow", false);
|
||||
res.addUnstableDefault("DontCompileHugeMethods", false);
|
||||
res.addDefault("-Xmn", "128m");
|
||||
|
||||
// As 32-bit JVM allocate 320KB for stack by default rather than 64-bit version allocating 1MB,
|
||||
// causing Minecraft 1.13 crashed accounting for java.lang.StackOverflowError.
|
||||
if (options.getJava().getPlatform() == Platform.BIT_32) {
|
||||
res.add("-Xss1M");
|
||||
res.addDefault("-Xss", "1m");
|
||||
}
|
||||
|
||||
if (options.getMaxMemory() != null && options.getMaxMemory() > 0)
|
||||
res.add("-Xmx" + options.getMaxMemory() + "m");
|
||||
res.addDefault("-Xmx", options.getMaxMemory() + "m");
|
||||
|
||||
if (options.getMinMemory() != null && options.getMinMemory() > 0)
|
||||
res.add("-Xms" + options.getMinMemory() + "m");
|
||||
res.addDefault("-Xms", options.getMinMemory() + "m");
|
||||
|
||||
if (options.getJava().getParsedVersion() == JavaVersion.JAVA_16)
|
||||
res.add("--illegal-access=permit");
|
||||
res.addDefault("--illegal-access=", "permit");
|
||||
|
||||
res.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
|
||||
res.add("-Dfml.ignorePatchDiscrepancies=true");
|
||||
res.addDefault("-Dfml.ignoreInvalidMinecraftCertificates=", "true");
|
||||
res.addDefault("-Dfml.ignorePatchDiscrepancies=", "true");
|
||||
}
|
||||
|
||||
Proxy proxy = options.getProxy();
|
||||
@@ -140,13 +149,13 @@ public class DefaultLauncher extends Launcher {
|
||||
String host = address.getHostString();
|
||||
int port = address.getPort();
|
||||
if (proxy.type() == Proxy.Type.HTTP) {
|
||||
res.add("-Dhttp.proxyHost=" + host);
|
||||
res.add("-Dhttp.proxyPort=" + port);
|
||||
res.add("-Dhttps.proxyHost=" + host);
|
||||
res.add("-Dhttps.proxyPort=" + port);
|
||||
res.addDefault("-Dhttp.proxyHost=", host);
|
||||
res.addDefault("-Dhttp.proxyPort=", String.valueOf(port));
|
||||
res.addDefault("-Dhttps.proxyHost=", host);
|
||||
res.addDefault("-Dhttps.proxyPort=", String.valueOf(port));
|
||||
} else if (proxy.type() == Proxy.Type.SOCKS) {
|
||||
res.add("-DsocksProxyHost=" + host);
|
||||
res.add("-DsocksProxyPort=" + port);
|
||||
res.addDefault("-DsocksProxyHost=", host);
|
||||
res.addDefault("-DsocksProxyPort=", String.valueOf(port));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,20 @@ package org.jackhuang.hmcl.util.platform;
|
||||
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||
|
||||
public final class CommandBuilder {
|
||||
private static final Pattern UNSTABLE_OPTION_PATTERN = Pattern.compile("-XX:(?<key>[a-zA-Z0-9]+)=(?<value>.*)");
|
||||
private static final Pattern UNSTABLE_BOOLEAN_OPTION_PATTERN = Pattern.compile("-XX:(?<value>[+\\-])(?<key>[a-zA-Z0-9]+)");
|
||||
|
||||
private final OperatingSystem os;
|
||||
private List<Item> raw = new LinkedList<>();
|
||||
private final List<Item> raw = new LinkedList<>();
|
||||
|
||||
public CommandBuilder() {
|
||||
this(OperatingSystem.CURRENT_OS);
|
||||
@@ -75,13 +80,66 @@ public final class CommandBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addDefault(String opt) {
|
||||
for (Item item : raw) {
|
||||
if (item.arg.equals(opt)) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
raw.add(new Item(opt, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addDefault(String opt, String value) {
|
||||
for (Item item : raw) {
|
||||
if (item.arg.startsWith(opt)) {
|
||||
LOG.info("Default option '" + opt + value + "' is suppressed by '" + item.arg + "'");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
raw.add(new Item(opt + value, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addUnstableDefault(String opt, boolean value) {
|
||||
for (Item item : raw) {
|
||||
final Matcher matcher = UNSTABLE_BOOLEAN_OPTION_PATTERN.matcher(item.arg);
|
||||
if (matcher.matches()) {
|
||||
if (matcher.group("key").equals(opt)) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (value) {
|
||||
raw.add(new Item("-XX:+" + opt, true));
|
||||
} else {
|
||||
raw.add(new Item("-XX:-" + opt, true));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addUnstableDefault(String opt, String value) {
|
||||
for (Item item : raw) {
|
||||
final Matcher matcher = UNSTABLE_OPTION_PATTERN.matcher(item.arg);
|
||||
if (matcher.matches()) {
|
||||
if (matcher.group("key").equals(opt)) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raw.add(new Item("-XX:" + opt + "=" + value, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean removeIf(Predicate<String> pred) {
|
||||
return raw.removeIf(i -> pred.test(i.arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.join(" ", raw.stream().map(i -> i.parse ? parse(i.arg) : i.arg).collect(Collectors.toList()));
|
||||
return raw.stream().map(i -> i.parse ? parse(i.arg) : i.arg).collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
public List<String> asList() {
|
||||
|
||||
Reference in New Issue
Block a user