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

JDK-21+ response-time gc profile uses generational zgc #1520

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1520.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: JDK-21+ response-time gc profile uses generational zgc
links:
- https://github.com/palantir/sls-packaging/pull/1520
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class ResponseTime implements GcProfile {

@Override
public final List<String> gcJvmOpts(JavaVersion javaVersion) {
// JDK-21+ uses generational ZGC as the response-time optimized garbage collector.
if (javaVersion.compareTo(JavaVersion.toVersion("21")) >= 0) {
return ImmutableList.of(
"-XX:+UseZGC",
// https://openjdk.org/jeps/439
"-XX:+ZGenerational",
// "forces concurrent cycle instead of Full GC on System.gc()"
"-XX:+ExplicitGCInvokesConcurrent");
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on https://www.chriswhocodes.com/corretto_jdk11_options.html -XX:+ClassUnloadingWithConcurrentMark defaults to true (and has since jdk-11, I haven't verified earlier releases).

The zgc documentation suggested that numa support is enabled by default, but turned off if the jvm detects it's not needed, but that UseNUMA flag overrides this behavior: https://wiki.openjdk.org/display/zgc/Main#Main-EnablingNUMASupport

}

// The CMS garbage collector was removed in Java 14: https://openjdk.java.net/jeps/363. Users are free to
// use it up until this release.
if (javaVersion.compareTo(JavaVersion.toVersion("14")) >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,29 @@ class JavaServiceDistributionPluginTests extends GradleIntegrationSpec {
])
}

def 'Uses generational zgc for jdk-21'() {
createUntarBuildFile(buildFile)
buildFile << """
dependencies { implementation files("${EXTERNAL_JAR}") }
tasks.jar.archiveBaseName = "internal"
distribution {
javaVersion 21
gc 'response-time'
}""".stripIndent()
file('src/main/java/test/Test.java') << "package test;\npublic class Test {}"

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

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

def 'produce distribution bundle that populates check.sh'() {
given:
Expand Down