Skip to content

Commit 752842a

Browse files
committed
Merge branch '3.4.x'
Closes gh-45200
2 parents c1bcd6f + f20e796 commit 752842a

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
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-
To use it, you should first perform a training run on your application in extracted form:
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+).
8+
9+
[[packaging.class-data-sharing.cds]]
10+
== CDS
11+
12+
To use CDS, you should first perform a training run on your application in extracted form:
713

814
[source,shell]
915
----
@@ -12,13 +18,36 @@ $ cd application
1218
$ java -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh -jar my-app.jar
1319
----
1420

15-
This creates an `application.jsa` file that can be reused as long as the application is not updated.
21+
This creates an `application.jsa` archive file that can be reused as long as the application is not updated.
1622

17-
To use the cache, you need to add an extra parameter when starting the application:
23+
To use the archive file, you need to add an extra parameter when starting the application:
1824

1925
[source,shell]
2026
----
2127
$ java -XX:SharedArchiveFile=application.jsa -jar my-app.jar
2228
----
2329

2430
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].
31+
32+
[[packaging.class-data-sharing.aot-cache]]
33+
== AOT Cache
34+
35+
To use the AOT cache, you should first perform a training run on your application in extracted form:
36+
37+
[source,shell]
38+
----
39+
$ java -Djarmode=tools -jar my-app.jar extract --destination application
40+
$ cd application
41+
$ java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf -Dspring.context.exit=onRefresh -jar my-app.jar
42+
$ java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf -XX:AOTCache=app.aot -jar my-app.jar
43+
----
44+
45+
This creates an `app.aot` cache file that can be reused as long as the application is not updated.
46+
The intermediate `app.aotconf` file is no longer needed and can be safely deleted.
47+
48+
To use the cache file, you need to add an extra parameter when starting the application:
49+
50+
[source,shell]
51+
----
52+
$ java -XX:AOTCache=app.aot -jar my-app.jar
53+
----

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

+21-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Here is an example of a `Dockerfile` using `jarmode`.
3636
include::reference:partial$dockerfile[]
3737
# Start the application jar - this is not the uber jar used by the builder
3838
# This jar only contains application code and references to the extracted jar files
39-
# This layout is efficient to start up and CDS friendly
39+
# This layout is efficient to start up and CDS/AOT cache friendly
4040
ENTRYPOINT ["java", "-jar", "application.jar"]
4141
----
4242

@@ -53,14 +53,14 @@ Each of the `COPY` commands relates to the layers extracted by the jarmode.
5353

5454
Of course, a `Dockerfile` can be written without using the `jarmode`.
5555
You can use some combination of `unzip` and `mv` to move things to the right layer but `jarmode` simplifies that.
56-
Additionally, the layout created by the `jarmode` is CDS friendly out of the box.
56+
Additionally, the layout created by the `jarmode` is CDS and AOT cache friendly out of the box.
5757

5858

5959

6060
[[packaging.container-images.dockerfiles.cds]]
6161
== CDS
6262

63-
If you want to additionally enable xref:reference:packaging/class-data-sharing.adoc[CDS], you can use this `Dockerfile`:
63+
If you want to additionally enable xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.cds[CDS], you can use this `Dockerfile`:
6464
[source,dockerfile]
6565
----
6666
include::reference:partial$dockerfile[]
@@ -75,3 +75,21 @@ ENTRYPOINT ["java", "-XX:SharedArchiveFile=application.jsa", "-jar", "applicatio
7575
This is mostly the same as the above `Dockerfile`.
7676
As the last steps, it creates the CDS archive by doing a training run and passes the CDS parameter to `java -jar`.
7777

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`.

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/packaging/efficient.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Certain PaaS implementations may also choose to extract archives before they run
1212
For example, Cloud Foundry operates this way.
1313

1414
Spring Boot supports extracting your application to a directory using different layouts.
15-
The default layout is the most efficient, and is xref:reference:packaging/class-data-sharing.adoc[CDS friendly].
15+
The default layout is the most efficient, and it is xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.cds[CDS] and xref:reference:packaging/class-data-sharing.adoc#packaging.class-data-sharing.aot-cache[AOT cache] friendly.
1616

1717
In this layout, the libraries are extracted to a `lib/` folder, and the application jar
1818
contains the application classes and a manifest which references the libraries in the `lib/` folder.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Perform the extraction in a separate builder container
2-
FROM bellsoft/liberica-openjre-debian:17-cds AS builder
2+
FROM bellsoft/liberica-openjre-debian:24-cds AS builder
33
WORKDIR /builder
44
# This points to the built jar file in the target folder
55
# Adjust this to 'build/libs/*.jar' if you're using Gradle
@@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar
1010
RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted
1111

1212
# This is the runtime container
13-
FROM bellsoft/liberica-openjre-debian:17-cds
13+
FROM bellsoft/liberica-openjre-debian:24-cds
1414
WORKDIR /application
1515
# Copy the extracted jar contents from the builder container into the working directory in the runtime container
1616
# Every copy step creates a new docker layer

0 commit comments

Comments
 (0)