Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hybrid (G1) GC uses the defeault 200ms MaxGCPauseMillis on JDK-21+ #1706

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.OptionalInt;
import org.gradle.api.JavaVersion;

public interface GcProfile extends Serializable {
Expand Down Expand Up @@ -108,15 +109,30 @@ class Hybrid implements GcProfile {
// in high-garbage or low-gc-thread scenarios. In the happy case, increasing the pause target increases
// both throughput and latency. In degenerate cases, a low target can cause the garbage collector to
// thrash and reduce throughput while increasing latency.
private int maxGCPauseMillis = 500;
private static final int LEGACY_MAX_GC_PAUSE_MILLIS = 500;
private static final int JAVA_21_PLUS_MAX_GC_PAUSE_MILLIS = 200;

private OptionalInt maxGCPauseMillis = OptionalInt.empty();

@Override
public final List<String> gcJvmOpts(JavaVersion _javaVersion) {
return ImmutableList.of("-XX:+UseG1GC", "-XX:+UseNUMA", "-XX:MaxGCPauseMillis=" + maxGCPauseMillis);
public final List<String> gcJvmOpts(JavaVersion javaVersion) {
return ImmutableList.of(
"-XX:+UseG1GC", "-XX:+UseNUMA", "-XX:MaxGCPauseMillis=" + getMaxGCPauseMillis(javaVersion));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be best to exclude this parameter entirely when it's not specified? That way if the default changes in the jdk, we follow it. I don't have a strong preference -- we could update this once we drop support for jdk17 to exclude the value unless specified.

}

private int getMaxGCPauseMillis(JavaVersion javaVersion) {
if (maxGCPauseMillis.isPresent()) {
return maxGCPauseMillis.getAsInt();
}
if (javaVersion.compareTo(JavaVersion.toVersion("21")) >= 0) {
return JAVA_21_PLUS_MAX_GC_PAUSE_MILLIS;
} else {
return LEGACY_MAX_GC_PAUSE_MILLIS;
}
}

public final void maxGCPauseMillis(int value) {
this.maxGCPauseMillis = value;
this.maxGCPauseMillis = OptionalInt.of(value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,75 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
actualStaticConfig.jvmOpts.containsAll(['-XX:+UseG1GC', '-XX:+UseNUMA', "-XX:MaxGCPauseMillis=500"])
carterkozak marked this conversation as resolved.
Show resolved Hide resolved
}

def 'adds maxGCPauseMillis gc profile jvm settings on java 21'() {
given:
buildFile << '''
plugins {
id 'java'
id 'com.palantir.sls-java-service-distribution'
}

repositories {
mavenCentral()
}

version '0.0.1'

distribution {
serviceName 'service-name'
mainClass 'test.Test'
javaVersion 21
gc 'hybrid', {
maxGCPauseMillis 1234
}
}
'''.stripIndent()

createUntarTask(buildFile)

when:
runTasks(':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:+UseG1GC', '-XX:+UseNUMA', '-XX:MaxGCPauseMillis=1234'])
}

def 'gc profile null configuration closure on java 21'() {
// We set a different different default MaxGCPauseMillis in JDK-21 than older JDKs.
mpritham marked this conversation as resolved.
Show resolved Hide resolved
given:
buildFile << '''
plugins {
id 'java'
id 'com.palantir.sls-java-service-distribution'
}

repositories {
mavenCentral()
}

version '0.0.1'

distribution {
serviceName 'service-name'
mainClass 'test.Test'
javaVersion 21
gc 'hybrid'
}
'''.stripIndent()

createUntarTask(buildFile)

when:
runTasks(':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:+UseG1GC', '-XX:+UseNUMA', "-XX:MaxGCPauseMillis=200"])
}

def 'applies java agents'() {
createUntarBuildFile(buildFile)
buildFile << """
Expand Down