Add an opt-in CDS archive of the dependency JARs to mn:run #1736
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.72) × (1 − Review Confidence (0.65)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 2894 lines diff across 39 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.32 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.400
Shallow Review Depth
shallow_review_depth
0.239
Mass File Touch
mass_file_touch
0.080
Real PR Conversation Timeline
4 items
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Approved
Approved these changes.
 Quality Gate passed
Issues
 0 New issues
 0 Accepted issues
Measures
 0 Security Hotspots
 85.1% Coverage on New Code
 0.0% Duplication on New Code
<!-- sqra-placement-anchor -->
See analysis details on SonarQube Cloud
graemerocher
alvarosanchez
Motivation
Every launch and restart of
mn:runparses, verifies and links all the classes of the dependency JARs again. A static CDS archive of those JARs removes that work, but the JDK refuses an archive whose class path holds a non-empty directory, and an archive of the JARs alone is only used when the runtime class path starts with exactly those JARs. Todaymn:runputs the reactor'starget/classesdirectories first, so no application archive can work. #1731 has the details and the study's measurements.Fixes #1731
What changed
Everything is behind a new
mn:runparameter,mn.classDataSharing(@Experimental,@since 5.1.0, defaultfalse). With it off,buildRunArgumentsreturns the same list as before (pinned by a newRunMojoTest). All the logic is in the package-privateClassDataSharingSupport, next toNativeImageAgentSupport;RunMojoonly calls it.With the option on (JDK 25 or later):
.jarfiles of the resolved class path, in today's order, then the reactor outputs (target/classesof the runnable project and of the reactor modules it depends on), then any other dependency entry. Only the JARs go into the archive, so editing the project never invalidates it. Every launch uses this order, with or without an archive.<key>.entries). On a match (a class,logback.xml,application.yml, ...), one warning names the path and the JAR, and the launch keeps today's order and gets no CDS flag. Exempt:META-INF/services/,META-INF/micronaut/,META-INF/MANIFEST.MF,module-info.class,META-INF/versions/, and, as in micronaut-projects/micronaut-gradle-plugin#1387,META-INF/maven/, signature files and licence/notice files.-XX:DumpLoadedClassList=<key>.recording. The list is kept (trimmed to its last complete line, sincedestroy()is forcible on Windows) when the plugin stopped the application (restart or end of the goal), or when it exited with 0 or 130 (Ctrl+C). Any other exit status discards it.java -Xshare:dump -XX:SharedClassListFile=… -XX:SharedArchiveFile=<tmp> --add-modules=<root modules> <-XX: and heap options of the launch> -cp <JARs>, withJAVA_TOOL_OPTIONS,JDK_JAVA_OPTIONSand_JAVA_OPTIONSremoved from its environment and its output in<key>.log. Then one probe,java -Xshare:on -XX:SharedArchiveFile=<tmp> --add-modules=… <module, -XX: and heap options> -cp <launch class path> -version, and an atomic move to<key>.jsa. A failed dump or probe deletes the file, writes<key>.failedand logs one line that names the log; that key then launches without an archive. Launches during the dump run without the archive and record nothing. A successful dump deletes the files of other keys.jdk.management.agentfor any-Dcom.sun.management…property (today's-Dcom.sun.management.jmxremote, a forwarded user property ormn.jvmArgs),java.instrumentfor-javaagent:,jdk.jfrfor-XX:StartFlightRecordingor-XX:FlightRecorderOptions(also in their-XX:Option:valueform; the dump still gets neither option, so it starts no recording), every--add-modules, andjdk.internal.vm.ciwhen the launch JVM enables JVMCI (GraalVM does by default; read before the dump withjava <the launch's -XX: options> -XX:+PrintFlagsFinal -version). So the archive stays right before and after #1732.-XX:SharedArchiveFile=<key>.jsa -Xlog:cds=off,aot=offright afterjava, beforemn.jvmArgs, so a user's own-Xlogwins. Default-Xshare:auto, no probe on this path (the debug log says so).-Dmn.watch=false. The shutdown hook now marks Maven as shutting down before it stops the application: a recording launch keeps its trimmed list, no dump starts and a running dump is killed and its temporary file deleted, so the exit is not delayed. The next goal dumps that list in the background, and its first launch runs without the archive. When the goal ends on its own (-Dmn.watch=false), it waits for the dump, so the goal leaves<key>.jsabehind.statper JAR):java.homeandjava.vm.versionof the launchjava(the toolchain's when one is configured; read once per goal with-XshowSettings:properties -version), the root modules, the plain mode, the module options, the-XX:,-Xmx/-Xmsand--enable-previewoptions, and the path, size and mtime of every JAR in order.-Xshare:,-XX:SharedArchiveFile,-XX:SharedClassListFile,-XX:ArchiveClassesAtExit,-XX:+AutoCreateSharedArchive,-XX:DumpLoadedClassList,-XX:AOTCache,-XX:AOTCacheOutput,-XX:AOTMode,-XX:AOTConfiguration,-XX:+AOTClassLinking,--limit-modules,--upgrade-module-path,--patch-module,--module-path/-p, an@argfile,-XX:VMOptionsFileor-XX:Flags, inmn.jvmArgsor the environment.target/mn-cds/, which the watches already exclude, never attached or declared as an output.mvn cleanresets it.run.adoc, after "Debugging": what it does and costs, the class path order and the duplicate check, the bean and service-provider order caveat, how to check that the archive is used, when it has no effect.Choices where I filled in the issue
1. The dump also gets the launch's
-XX:and heap options, not only--add-modules. Checked on JDK 25.0.4.1 with hello-netty's JARs: an archive dumped with the default heap is refused with-Xmx64g("Unable to map shared spaces", no class from any archive, the probe exits 1), and one dumped with-XX:+UseZGCis refused with G1. Dumped with the launch's options, both pass the probe, and the-Xmx64glaunch loads 1,868 classes from the archive. The functional test runs once with-XX:-UseCompressedOopsto pin this.2. The dump and probe failure line is at info level, once per key, naming the log file (the issue said debug for the probe). A user who turned the option on otherwise has no way to see why it never helps.
3. Option files hand off too (
@argfile,-XX:VMOptionsFile,-XX:Flags): the plugin cannot see the options inside them.4. The exempt list is the union of both issues (Maven's plus Gradle's
META-INF/maven/, signatures and licence files).5. JVMCI's module. GraalVM enables JVMCI by default, and HotSpot then adds
jdk.internal.vm.cito the root modules, but a dump always runs without JVMCI (-Xint). Without the module in the dump, every launch on GraalVM loggedMismatched values for property jdk.module.addmods: runtime jdk.internal.vm.ci,jdk.management.agent dump time jdk.management.agentand disabled optimized module handling (silenced, but a loss). The functional test caught it on the CI's GraalVM CE 25; fixed in c9990f9f.6. Parameter name
mn.classDataSharing, the word of micronaut-projects/micronaut-gradle-plugin#1387'srunClassDataSharing.7. JFR's module.
-XX:StartFlightRecordingand-XX:FlightRecorderOptionsaddjdk.jfrto the root modules. Before 24179c71 the dump got neither the options nor the module, and a launch with an archive and either option loggedMismatched values for property jdk.module.addmods: runtime jdk.jfr,jdk.management.agent dump time jdk.management.agentand disabled optimized module handling (checked on JDK 25.0.4.1; the classes still came from the archive). The dump now adds the module but still not the options.-agentlib:jdwpadds no module.8.
-XX:+AOTClassLinkinghands off instead of going to the dump (24179c71). Forwarded, it made the plain key's archive AOT-linked: the dump and the-Xshare:onprobe pass, but a later-Dmn.debuglaunch, whose JDWP agent is not part of the key, logsshared archive file has aot-linked classes. It cannot be used with JDWP agentand loads no class from any archive, not even the JDK's default one (checked on JDK 25.0.4.1). AOT linking stays the separate opt-in of the follow-up below.Verification
Unit tests (
with the option off,
order: JARs, reactor outputs, other entries;
a duplicate class, a duplicate
the key changes with a JAR's size, its mtime alone, the JDK's home and build, the root modules,
status 0, 130 and a stop by the plugin keep the (trimmed) class list, 1 and 143 on its own discard it, and so does a list without a complete line; a list kept on shutdown starts no dump and the next goal dumps it; a restart through
a launch prepared while the recording one still runs, or during a dump, records nothing; a recording launch that failed on its own is recorded again; a failed key launches without an archive; an unreadable
below JDK 25: no flag, no
every CDS, AOT-cache (
a functional test with the test JDK: real recording launch, background dump and probe, a launch during the dump with no flag, then a launch with the archive and no probe, where
ClassDataSharingSupportTest, 51 tests, andRunMojoTest, 5):buildRunArgumentsis today's list; with it on, the JARs come first and the flag comes right afterjava;logback.xmland a duplicate in a non-JAR entry fall back to today's list with a warning; a sharedMETA-INF/micronaut/<type>/directory and the other exempt files do not; a damaged entry index is rebuilt;-Xmxand a module option;jdk.management.agentfrom any-Dcom.sun.management…,java.instrumentfrom-javaagent:,jdk.jfrfrom-XX:StartFlightRecordingand-XX:FlightRecorderOptions(also with:), also fromJAVA_TOOL_OPTIONSandJDK_JAVA_OPTIONS; the JFR options stay out of the dump's options;RunMojo.killProcesskeeps the list and starts the dump, and the shutdown hook keeps it without starting one; a running dump is stopped on shutdown without a failure marker or temporary file;javaor a class path without JARs keeps today's list;aottag, today's order, one info line;-XX:+AOTClassLinkingincluded), module-graph and option-file option (inmn.jvmArgsor the environment) keeps today's list;-Xlog:class+loadshows the dependency class fromshared objects fileand the application class from its directory, and a user-Xlog:cds=warningshows no module mismatch; the archive of an older key is deleted. It runs three times: with-XX:TieredStopAtLevel=1, with-XX:-UseCompressedOops, and with-XX:FlightRecorderOptions=stackdepth=128(no recording; its-Xlog:cds=warningcheck fails withoutjdk.jfrin the dump).Mutation check (each change made alone, then reverted): dropping the
jdk.management.agentderivation, the Ctrl+C status, the duplicate check, the exemptions, the dump's-XX:options, the JDK gate, the hands-off check or the mtime in the key, or moving the flags aftermn.jvmArgs, each fails at least one test; so does dropping JVMCI's module, on GraalVM. The cases added in 24179c71 (jdk.jfrfrom both JFR options and their:form, the JFR functional run,-XX:+AOTClassLinkinghanding off) fail against f7b4f099. A dump started during shutdown is caught once the test waits for background work (fixed in the test).Invoker ITs (pass locally on Homebrew OpenJDK 25.0.4.1, the base and native-agent ones also on Oracle GraalVM 25.0.3, and all of them in this PR's CI on GraalVM CE 25, Linux and Windows, where the watch IT is skipped; against
Unchanged and passing:
5.1.xwithout this change,run-class-data-sharing,run-class-data-sharing-duplicateand the extendedmulti-project-multi-runnablefail):run-class-data-sharing: invocation 1 records and leaves<key>.jsa(the goal waits for the dump); invocation 2 loadsio.micronaut.context.DefaultBeanContextfromshared objects fileand the application class fromtarget/classes; invocation 3 with-Dmn.debug -Dmn.debug.port=0opens the debugger port and still loads from the archive; no[cds]/[aot]line in any invocation.run-class-data-sharing-native-agent(GraalVM 25+): with-Dagent=true, the agent writesreachability-metadata.jsonand the dependency classes still come from the archive.run-class-data-sharing-watch(not on Windows): watch mode; the application restarts itself by changing a resource, waits for the archive, restarts again, then sends SIGTERM to Maven. The-Xlog shows the recording launch, a launch without flags during the dump, and a third launch with-XX:SharedArchiveFileand "without a probe"; the dump log has exactly one-versionoutput; the third launch's class-load log shows the archive.run-class-data-sharing-duplicate: a library JAR with its ownlogback.xml; the warning nameslogback.xmland the JAR, the project'slogback.xmlwins, the class path keepstarget/classesfirst and nothing is recorded.multi-project-multi-runnable: a second invocation with the option;lib/target/classesandapp1/target/classescome right after the last JAR, the archive is left behind, and the existing assertions hold for both invocations.run,run-aot,run-aot-jvmargs,run-native-agent,multi-project,multi-project-multi-runnable-error,issue465.End to end by hand on a Maven port of benchmark-large (Micronaut platform 5.1.5, 49 JARs, 105 project classes), in its own process group like a terminal:
watch mode: recording launch, restart (the list of 10,476 lines is kept and dumped in the background: 53.6 MB), restart with the archive, Ctrl+C (Maven exits 130);
Ctrl+C on the recording launch:
<key>.classlistkept, no archive and no.failed; the next goal logs "creating the CDS archive" for its first launch, creates the archive in the background (4.4 s while the application ran, undernice), and its restart uses it../mvnw install -Dinvoker.skip=true(all unit tests, Checkstyle, Spotless) passes on OpenJDK 25.0.4.1 and GraalVM 25.0.3. SonarCloud's findings on the first push (constants named like fields, anullOptional, a temporary file in the shared temporary directory, 78% coverage on new code) are fixed in f7b4f099; its quality gate passes.Measurements
Readiness of a restart with the option on against one with it off, on one sample application, with the method of the study behind #1731 and micronaut-projects/micronaut-gradle-plugin#1387.
micronaut-parent5.1.5, 49 dependency JARs, 105 project classes, 48 beans), run with this branch.mn:run -Xlogged (Running …): today's (option off) and, with the option on, a restart with the archive, the recording launch, and a launch without an archive (as during a dump). The archive came from a watch-mode session whose class list was recorded until the restart (10,476 lines, 53.6 MB archive). The harness started the commands directly, intarget, so Maven's own time (compilation, configuration validation) is not in the figures./hello; 3 sessions, each with 3 warm-ups and 15 iterations, the variants interleaved in random order (n = 45 pairs per variant); the median of the paired differences as a share of today's launch, with a bootstrap 95% CI. "3/3" means that each session's own CI excludes zero.| Launch with the option on | Readiness against today's launch | Sessions |
|---|---|---|
| Restart with the archive | −42.5% [−43.1, −41.9] | 3/3 (session medians −41.8%, −42.0%, −43.1%) |
| Recording launch (the first one per key) | +2.1% [+1.5, +3.8] | 3/3 |
| Launch without an archive (during a dump, or for a failed key) | −1.1% [−2.4, +0.3] | no effect |
nice; not timed under the lock).SemVer and API
New, opt-in behaviour, so it targets
5.1.x(the next minor,5.1.0-SNAPSHOT). The only new user-facing surface is themn.classDataSharingparameter ofmn:run(private field,@Experimental,@since 5.1.0, defaultfalse). No new public type or method;ClassDataSharingSupportis package-private. With the option off, the command line is unchanged;killProcessand the shutdown hook only gained calls that are no-ops when the option is off.Follow-ups
mn.classDataSharing.aotClassLinkingto matchaotClassLinkingof micronaut-projects/micronaut-gradle-plugin#1387, on JDK 25 and 26 only, with a plain archive for JDWP, agents,--add-opens/--add-exports, a plain fallback when the AOT-linked dump fails, and a measurement with a session-length class list.-Dcom.sun.management.jmxremoteonce both exist (the archive also holds the JMX agent's classes; the root modules follow the launch, so the archive stays correct either way).mn:dev** (#1725) could reuse the helper for its JAR-only class path.mn:runitself (with Maven's compilation), and the cost of the duplicate check per launch.🤖 Generated with Claude Code