Skip to content

Commit

Permalink
Add enableAlwaysPreTouch option (#1772)
Browse files Browse the repository at this point in the history
Add enableAlwaysPreTouch option
  • Loading branch information
parker89 authored Feb 14, 2025
1 parent 4a66e60 commit e2a797d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1772.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: Add enableAlwaysPreTouch option
links:
- https://github.com/palantir/sls-packaging/pull/1772
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class JavaServiceDistributionExtension extends BaseDistributionExtension
private final Property<Boolean> addJava8GcLogging;
private final Property<Boolean> enableManifestClasspath;
private final Property<GcProfile> gc;
private final Property<Boolean> alwaysPreTouch;
private final ListProperty<String> args;
private final ListProperty<String> checkArgs;
private final ListProperty<String> defaultJvmOpts;
Expand Down Expand Up @@ -90,6 +91,8 @@ public JavaServiceDistributionExtension(Project project) {
.property(GcProfile.class)
.value(javaVersion.map(JavaServiceDistributionExtension::getDefaultGcProfile));

alwaysPreTouch = objectFactory.property(Boolean.class).value(false);

args = objectFactory.listProperty(String.class).empty();
checkArgs = objectFactory.listProperty(String.class).empty();
defaultJvmOpts = objectFactory.listProperty(String.class).empty();
Expand Down Expand Up @@ -148,6 +151,14 @@ public final void enableManifestClasspath(boolean newEnableManifestClasspath) {
this.enableManifestClasspath.set(newEnableManifestClasspath);
}

public final Provider<Boolean> getAlwaysPreTouch() {
return alwaysPreTouch;
}

public final void enableAlwaysPreTouch() {
this.alwaysPreTouch.set(true);
}

public final Provider<List<String>> getArgs() {
return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void execute(Task _task) {
task.getAddJava8GcLogging().set(distributionExtension.getAddJava8GcLogging());
task.getJavaHome().set(distributionExtension.getJavaHome());
task.getJavaVersion().set(distributionExtension.getJavaVersion());
task.getAlwaysPreTouch().set(distributionExtension.getAlwaysPreTouch());
task.getBundledJdks()
.set(distributionExtension
.getJdks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public final class LaunchConfig {
// When a system supports UseAVX=N, setting UseAVX=N+1 will set the flag to the highest supported value.
private static final ImmutableList<String> disableAvx512 = ImmutableList.of("-XX:UseAVX=2");

private static final ImmutableList<String> alwaysPreTouchOptions = ImmutableList.of("-XX:+AlwaysPreTouch");

// Reduce memory usage for some versions of glibc.
// Default value is 8 * CORES.
// See https://issues.apache.org/jira/browse/HADOOP-7154
Expand Down Expand Up @@ -117,6 +119,9 @@ interface Params {
@Input
Property<Boolean> getBundledJdks();

@Input
Property<Boolean> getAlwaysPreTouch();

@Input
ListProperty<String> getArgs();

Expand Down Expand Up @@ -191,6 +196,7 @@ static void action(Params params) {
: ImmutableList.of())
.addAllJvmOpts(ModuleArgs.collectClasspathArgs(javaVersion, params.getFullClasspath()))
.addAllJvmOpts(params.getGcJvmOptions().get())
.addAllJvmOpts(params.getAlwaysPreTouch().get() ? alwaysPreTouchOptions : ImmutableList.of())
.addAllJvmOpts(params.getDefaultJvmOpts().get())
.putAllEnv(defaultEnvironment)
.putAllEnv(params.getEnv().get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class JavaServiceDistributionExtensionTest extends Specification {
ext.getCheckArgs().get() == []
ext.getDefaultJvmOpts().get() == []
ext.getExcludeFromVar().get() == ['log', 'run']
ext.getAlwaysPreTouch().get() == false
}

def 'correct java homes depending on java version' () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,27 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
fileExists("dist/service-name-0.0.1/service/bin/go-init-${goJavaLauncherVersion}/service/bin")
}

def 'enableAlwaysPreTouch'() {
createUntarBuildFile(buildFile)
buildFile << """
dependencies { implementation files("${EXTERNAL_JAR}") }
tasks.jar.archiveBaseName = "internal"
distribution {
enableAlwaysPreTouch()
}""".stripIndent()
file('src/main/java/test/Test.java') << "package test;\npublic class Test {}"

when:
runTasks(':build', ':distTar', ':untar')

then:
def actualStaticConfig = OBJECT_MAPPER.readValue(
new File(projectDir, 'dist/service-name-0.0.1/service/bin/launcher-static.yml'), LaunchConfig.LaunchConfigInfo)
actualStaticConfig.jvmOpts().containsAll([
"-XX:+AlwaysPreTouch",
])
}

private static createUntarBuildFile(File buildFile) {
buildFile << '''
plugins {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ And the complete list of configurable properties:
Java 9 or higher will default to `$JAVA_<majorversion>_HOME` ie for Java 11 this would be `$JAVA_11_HOME`.
* (optional) `gc` override the default GC settings. Available GC settings: `throughput` (default for Java 14 and lower), `hybrid` (default for Java 15 and higher) and `response-time`. Additionally, there is also `dangerous-no-profile` which does not apply any additional JVM flags and allows you to fully configure any GC settings through JVM options (not recommended for normal usage!).
* (optional) `addJava8GcLogging` add java 8 specific gc logging options.
* (optional) `enableAlwaysPreTouch()` adds the `-XX:+AlwaysPreTouch` JVM option.

#### JVM Options

Expand Down

0 comments on commit e2a797d

Please sign in to comment.