Skip to content

Commit bb3b0e6

Browse files
authored
Update linker plugin aot option (#1157)
* Update aotCache option and behavior when addClassDataSharingArchive=false
1 parent 22a5ae0 commit bb3b0e6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ node_modules/
2424
node/
2525
*.swp
2626
.factorypath
27+
.oca/

maven-plugins/helidon-maven-plugin/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ This goal binds to the `package` phase by default.
139139
| defaultDebugOptions | List | [] | JVM debug options to use if the `--debug` flag is passed to the `start` script |
140140
| additionalModules | Set | [] | Add any modules that may not be found automatically |
141141
| addClassDataSharingArchive | boolean | `true` | Add a Class Data Sharing archive to reduce startup time |
142-
| addAotCache | boolean | `true` | Add an Aot Cache to reduce startup/warmup time. Ignored if Java 24 or earlier |
142+
| aotCache | String | `true` | Add an Aot Cache to reduce startup/warmup time. Ignored if Java 24 or earlier |
143143
| testImage | boolean | `true` | Start the application after the image is built |
144144
| stripDebug | boolean | `false` | Remove all debug support from the image, including within `.class` files |
145145
| skipJavaImage | boolean | `false` | Skip this goal execution |
@@ -150,7 +150,8 @@ Notes:
150150
* The above parameters are mapped to user properties of the form `jlink.image.PROPERTY`, e.g.
151151
`-Djlink.image.addClassDataSharingArchive=false`
152152
* Multiple arguments for the `jlink.image.additionalJlinkArgs` property must be comma separated.
153-
* If both `addClassDataSharingArchive` and `addAotCache` are true then an Aot Cache will be created if Java 25 or newer.
153+
* If `addClassDataSharingArchive` is `false` then `aotCache` is ignored.
154+
* Values for `aotCache`: `true`, `false`, `cds` (to force use of CDS archive instead of AOT Cache).
154155

155156
### General usage
156157

maven-plugins/helidon-maven-plugin/src/main/java/io/helidon/build/maven/JLinkImageMojo.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public class JLinkImageMojo extends AbstractMojo {
6868
private boolean addClassDataSharingArchive;
6969

7070
/**
71-
* Add an AOT cache to reduce startup time.
71+
* Add an AOT cache to reduce startup time if Java 25 or newer: true, false, cds.
7272
*/
73-
@Parameter(defaultValue = "true", property = "jlink.image.addAotCache")
74-
private boolean addAotCache;
73+
@Parameter(defaultValue = "true", property = "jlink.image.aotCache")
74+
private String aotCache;
7575

7676
/**
7777
* Test the image after creation.
@@ -178,22 +178,28 @@ private Path mainJar(Path buildDir) throws MojoFailureException {
178178
*
179179
* @return Startup cache type to use
180180
*/
181-
private Configuration.CacheType determinCacheType() {
181+
private Configuration.CacheType determinCacheType() throws MojoFailureException {
182+
183+
if (!addClassDataSharingArchive) {
184+
// For backwards compatibility we don't generate any cache if old CDS flag is false
185+
// No matter what JDK we are running on.
186+
return Configuration.CacheType.NONE;
187+
}
188+
182189
if (JavaRuntime.CURRENT_JDK.version().feature() <= 24) {
183-
if (addClassDataSharingArchive) {
184-
return Configuration.CacheType.CDS;
185-
} else {
186-
return Configuration.CacheType.NONE;
187-
}
190+
return Configuration.CacheType.CDS;
188191
}
189192

190193
// Java 25 or newer
191-
if (addAotCache) {
194+
if (aotCache.equalsIgnoreCase("true")) {
195+
// Default case under Java 25
192196
return Configuration.CacheType.AOT;
193-
} else if (addClassDataSharingArchive) {
197+
} else if (aotCache.equalsIgnoreCase("false")) {
198+
return Configuration.CacheType.NONE;
199+
} else if (aotCache.equalsIgnoreCase("cds")) {
194200
return Configuration.CacheType.CDS;
195201
} else {
196-
return Configuration.CacheType.NONE;
202+
throw new MojoFailureException("Invalid aotCache value " + aotCache + ": must be one of: true, false, cds");
197203
}
198204
}
199205
}

0 commit comments

Comments
 (0)