From 6b7e75c529c52f6b550fe6ef8037a9f15573940f Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Tue, 12 Sep 2023 15:39:06 -0400 Subject: [PATCH 1/2] JDK-21+ response-time gc profile uses generational zgc --- .../gradle/dist/service/gc/GcProfile.java | 10 ++++++++ .../JavaServiceDistributionPluginTests.groovy | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/gc/GcProfile.java b/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/gc/GcProfile.java index ab3778a33..f4dd24f93 100644 --- a/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/gc/GcProfile.java +++ b/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/gc/GcProfile.java @@ -49,6 +49,16 @@ class ResponseTime implements GcProfile { @Override public final List 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"); + } + // 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) { diff --git a/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPluginTests.groovy b/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPluginTests.groovy index 515a734f0..5d6ef20aa 100644 --- a/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPluginTests.groovy +++ b/gradle-sls-packaging/src/test/groovy/com/palantir/gradle/dist/service/JavaServiceDistributionPluginTests.groovy @@ -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: From 8df93aa8d8dcf732520d2fa5ae070ddad1998c78 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Tue, 12 Sep 2023 19:40:16 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-1520.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-1520.v2.yml diff --git a/changelog/@unreleased/pr-1520.v2.yml b/changelog/@unreleased/pr-1520.v2.yml new file mode 100644 index 000000000..a2b3eefad --- /dev/null +++ b/changelog/@unreleased/pr-1520.v2.yml @@ -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