Skip to content

Commit

Permalink
fix: Remove Java 8 JVM arguments from settings (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar authored May 2, 2020
1 parent a790227 commit c7fd335
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/terasology/launcher/config/ConfigValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Config validate(final Config config) {
.gameConfig(gameConfig.rebuilder()
.maxMemory(validateMaxMemory(gameConfig))
.initMemory(validateInitMemory(gameConfig))
.javaParam(validateJavaParam(gameConfig))
.build())
.build();
}
Expand Down Expand Up @@ -92,4 +93,16 @@ private JavaHeapSize validateInitMemory(final GameConfig gameConfig) {
}
return valid;
}

private String validateJavaParam(final GameConfig gameConfig) {
String params = gameConfig.getJavaParam();

final String[] deprecatedParams = {"-XX:+UseParNewGC", "-XX:+UseConcMarkSweepGC", "-XX:ParallelGCThreads=10"};

for (String deprecatedParam : deprecatedParams) {
params = params.replaceAll(deprecatedParam, "");
}

return params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,50 @@

package org.terasology.launcher.settings;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.launcher.util.JavaHeapSize;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
* Provides methods to check launcher settings and correct if invalid.
*/
public final class LauncherSettingsValidator {
private static final Logger logger = LoggerFactory.getLogger(LauncherSettingsValidator.class);

private static Set<String> deprecatedParameters =
Sets.newHashSet("-XX:+UseParNewGC", "-XX:+UseConcMarkSweepGC", "-XX:ParallelGCThreads=10");

private static String removeUnsupportedJvmParameters(final List<String> params) {
List<String> correctedParams = Lists.newArrayList(params);
correctedParams.removeAll(deprecatedParameters);
return String.join(" ", correctedParams);
}

private static final List<SettingsValidationRule> RULES = Arrays.asList(
// Rule for max heap size
new SettingsValidationRule(
s -> !(System.getProperty("os.arch").equals("x86") && s.getMaxHeapSize().compareTo(JavaHeapSize.GB_1_5) > 0),
"Max heap size cannot be greater than 1.5 GB for a 32-bit JVM",
s -> s.setMaxHeapSize(JavaHeapSize.GB_1_5)
s -> !(System.getProperty("os.arch").equals("x86") && s.getMaxHeapSize().compareTo(JavaHeapSize.GB_1_5) > 0),
"Max heap size cannot be greater than 1.5 GB for a 32-bit JVM",
s -> s.setMaxHeapSize(JavaHeapSize.GB_1_5)
),

// Rule for initial heap size
new SettingsValidationRule(
s -> s.getInitialHeapSize().compareTo(s.getMaxHeapSize()) < 0,
s -> s.getInitialHeapSize().compareTo(s.getMaxHeapSize()) < 0,
"Initial heap size cannot be greater than max heap size",
s -> s.setInitialHeapSize(s.getMaxHeapSize())
s -> s.setInitialHeapSize(s.getMaxHeapSize())
),

new SettingsValidationRule(
s -> s.getUserGameParameterList().stream().anyMatch(deprecatedParameters::contains),
"Ensure unsupported JVM arguments are removed",
s -> s.setUserJavaParameters(removeUnsupportedJvmParameters(s.getUserJavaParameterList()))
)
);

Expand Down

0 comments on commit c7fd335

Please sign in to comment.