Skip to content

Commit 10f822e

Browse files
committed
Merge pull request #50482 from won-seoop
Closes gh-50482 * pr/50482: Polish "Document Java 25 requirement for AOT cache" Document Java 25 requirement for AOT cache
2 parents cfd6164 + b44bb38 commit 10f822e

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/packaging/class-data-sharing.adoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
Class Data Sharing (CDS) is a https://docs.oracle.com/en/java/javase/17/vm/class-data-sharing.html[JVM feature] that can help reduce the startup time and memory footprint of Java applications.
55

6-
In Java 24, CDS is succeeded by the AOT Cache via https://openjdk.org/jeps/483[JEP 483].
7-
Spring Boot supports both CDS and AOT cache, and it is recommended that you use the latter if it is available in the JVM version you are using (Java 24+).
6+
If you are using Java 25 or above, CDS has been succeeded by the AOT Cache via https://openjdk.org/jeps/483[JEP 483].
7+
8+
NOTE: Spring Boot supports both CDS and AOT cache, however, we recommend using the AOT cache whenever possible.
9+
10+
811

912
[[packaging.class-data-sharing.cds]]
1013
== CDS
@@ -29,6 +32,8 @@ $ java -XX:SharedArchiveFile=application.jsa -jar my-app.jar
2932

3033
NOTE: For more details about CDS, refer to the xref:how-to:class-data-sharing.adoc[CDS how-to guide] and the {url-spring-framework-docs}/integration/cds.html[Spring Framework reference documentation].
3134

35+
36+
3237
[[packaging.class-data-sharing.aot-cache]]
3338
== AOT Cache
3439

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/packaging/container-images/dockerfiles.adoc

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,38 @@ Additionally, the layout created by the `jarmode` is CDS and AOT cache friendly
5757

5858

5959

60+
[[packaging.container-images.dockerfiles.aot-cache]]
61+
== AOT cache
62+
63+
If you are using Java 25 or above, and want to additionally enable the xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.aot-cache[AOT cache], you can use this `Dockerfile`:
64+
[source,dockerfile]
65+
----
66+
include::reference:partial$dockerfile[]
67+
68+
# Execute the AOT cache training run
69+
RUN java -XX:AOTCacheOutput=app.aot -Dspring.context.exit=onRefresh -jar application.jar
70+
71+
# Start the application jar with AOT cache enabled - this is not the uber jar used by the builder
72+
# This jar only contains application code and references to the extracted jar files
73+
# This layout is efficient to start up and AOT cache friendly
74+
ENTRYPOINT ["java", "-XX:AOTCache=app.aot", "-jar", "application.jar"]
75+
----
76+
77+
This is mostly the same as the above `Dockerfile`.
78+
As the last steps, it creates the AOT cache file by doing a training run and passes the AOT cache parameter to `java -jar`.
79+
80+
6081
[[packaging.container-images.dockerfiles.cds]]
6182
== CDS
6283

6384
If you want to additionally enable xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.cds[CDS], you can use this `Dockerfile`:
6485
[source,dockerfile]
6586
----
6687
include::reference:partial$dockerfile[]
88+
6789
# Execute the CDS training run
6890
RUN java -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh -jar application.jar
91+
6992
# Start the application jar with CDS enabled - this is not the uber jar used by the builder
7093
# This jar only contains application code and references to the extracted jar files
7194
# This layout is efficient to start up and CDS friendly
@@ -75,21 +98,4 @@ ENTRYPOINT ["java", "-XX:SharedArchiveFile=application.jsa", "-jar", "applicatio
7598
This is mostly the same as the above `Dockerfile`.
7699
As the last steps, it creates the CDS archive by doing a training run and passes the CDS parameter to `java -jar`.
77100

78-
[[packaging.container-images.dockerfiles.aot-cache]]
79-
== AOT cache
80-
81-
If you want to additionally enable the xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.aot-cache[AOT cache], you can use this `Dockerfile`:
82-
[source,dockerfile]
83-
----
84-
include::reference:partial$dockerfile[]
85-
# Execute the AOT cache training run
86-
RUN java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf -Dspring.context.exit=onRefresh -jar application.jar
87-
RUN java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf -XX:AOTCache=app.aot -jar application.jar && rm app.aotconf
88-
# Start the application jar with AOT cache enabled - this is not the uber jar used by the builder
89-
# This jar only contains application code and references to the extracted jar files
90-
# This layout is efficient to start up and AOT cache friendly
91-
ENTRYPOINT ["java", "-XX:AOTCache=app.aot", "-jar", "application.jar"]
92-
----
93-
94-
This is mostly the same as the above `Dockerfile`.
95-
As the last steps, it creates the AOT cache file by doing a training run and passes the AOT cache parameter to `java -jar`.
101+
NOTE: If you are using Java 25 or above, we recommend using an AOT cache instead of CDS.

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/partials/dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Perform the extraction in a separate builder container
22
FROM bellsoft/liberica-openjre-debian:24-cds AS builder
33
WORKDIR /builder
4+
45
# This points to the built jar file in the target folder
56
# Adjust this to 'build/libs/*.jar' if you're using Gradle
67
ARG JAR_FILE=target/*.jar
8+
79
# Copy the jar file to the working directory and rename it to application.jar
810
COPY ${JAR_FILE} application.jar
11+
912
# Extract the jar file using an efficient layout
1013
RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted
1114

1215
# This is the runtime container
1316
FROM bellsoft/liberica-openjre-debian:24-cds
1417
WORKDIR /application
18+
1519
# Copy the extracted jar contents from the builder container into the working directory in the runtime container
1620
# Every copy step creates a new docker layer
1721
# This allows docker to only pull the changes it really needs

0 commit comments

Comments
 (0)