Skip to content

Commit

Permalink
JDK-21+ response-time gc profile uses generational zgc (#1520)
Browse files Browse the repository at this point in the history
JDK-21+ response-time gc profile uses generational zgc
  • Loading branch information
carterkozak authored Sep 12, 2023
1 parent 04ad187 commit 317e097
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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");
}

// 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 @@ -609,6 +609,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

0 comments on commit 317e097

Please sign in to comment.