← Back to Pull requests

mn:run: stop adding -Dcom.sun.management.jmxremote to the application's command line #1735

Merged
alvarosanchez merged 6 files (134 lines) on Oct 03, 2026 07:06 UTC
View on GitHub
alvarosanchez alvarosanchez commented on Oct 02, 2026 21:12 UTC
Author

Fixes #1732

What changed

  • RunMojo.buildRunArguments no longer adds -Dcom.sun.management.jmxremote. The first start and every restart both build their command line there, so neither starts the JMX management agent and its local RMI connector before main any more. The rest of the command line is unchanged, -XX:TieredStopAtLevel=1 included.

  • No new parameter, property or type. The opt-in already exists, and run.adoc now documents it in a new "Monitoring with JMX" section next to "Debugging":

  • - mvn mn:run -Dcom.sun.management.jmxremote (mn:run passes Maven user properties on to the application);
    - mvn mn:run -Dmn.jvmArgs=-Dcom.sun.management.jmxremote;
    - <jvmArguments>-Dcom.sun.management.jmxremote</jvmArguments> in the plugin configuration;
    - for remote JMX, com.sun.management.jmxremote.port plus the authentication and SSL properties. The base flag is not needed.

    The section also says that JConsole, VisualVM and JMC start the local agent on demand when they attach, that jcmd does not use the agent, and that a JVM run with -XX:+DisableAttachMechanism needs the opt-in.

    How it was verified

    All local runs used Homebrew OpenJDK 25.0.4.1 on macOS (Apple M4 Pro), with nice -n 19.

  • RunMojoTest, 3 new cases on buildRunArguments. Each one asserts the whole command line after java:

  • - by default, -classpath <reactor outputs>:<dependencies> -XX:TieredStopAtLevel=1 <main class>, with no -Dcom.sun.management.jmxremote;
    - with jvmArguments set to -Dcom.sun.management.jmxremote, the flag appears once, before -classpath;
    - with the user property com.sun.management.jmxremote=true (what Maven gives a -D without a value), -Dcom.sun.management.jmxremote=true appears once.

    With the removed line put back, all 3 fail, because the command line has an extra -Dcom.sun.management.jmxremote before the main class. The existing AOT case still passes.

  • Invoker scenario run, extended as AGENTS.md asks for RunMojo changes. It now runs mn:run three times: by default, with -Dmn.jvmArgs=-Dcom.sun.management.jmxremote, and with -Dcom.sun.management.jmxremote. The app prints whether the property is set and whether the agent started. The agent check looks for the local connector's RMI TCP Accept thread. verify.groovy expects false, true, true for both values.

  • - Without the change, the scenario fails: the default run prints true for both values.
    - jdk.management.agent is not a usable signal for this check. In a full JDK it is in the boot layer with or without the flag, because jdk.jconsole, a default root module, requires it.
  • The other mn:run scenarios also pass: run-aot, run-aot-jvmargs, multi-project, multi-project-multi-runnable, multi-project-multi-runnable-error and test-resources-run. run-native-agent was skipped locally because its selector needs GraalVM; CI runs it.

  • ./mvnw verify -Dinvoker.skip=true passes: all module tests, Checkstyle and Spotless. This repository runs no japicmp.

  • mvn site renders the new run.adoc section.
  • Class loading through mn:run itself (not a timing): I ran mn:run from this branch on the run scenario's app (a picocli command on Micronaut 5.0), with -Xlog:class+load passed through mn.jvmArgs. The counts are deterministic, so one run of each variant:

    | | Default (this PR) | Opt-in (-Dcom.sun.management.jmxremote, today's default) |
    |---|---|---|
    | Classes loaded before main | 404 | 1,919 |
    | Classes loaded by exit | 3,715 | 4,415 |
    | JMX and management classes | 0 | 189 |
    | RMI classes | 0 | 51 |

    Timing: this PR adds no new timing measurement. The figures in #1732 come from the startup study on one Apple M4 Pro (12 CPUs). It ran 3 sessions × 20 interleaved pairs per app and JDK, on the Gradle run task's launch line, which passes the same two JVM flags (-XX:TieredStopAtLevel=1 -Dcom.sun.management.jmxremote, plus Gradle's -Dfile.encoding and -Duser.* properties) and the same class-path shape as mn:run (classes, resources, dependency JARs), without a build tool in the loop. The machine was shared. In each session the bounded wait for load below 3 (12 CPUs / 4) expired after 300 s, and load1 averaged 4.5-5.3 (peak 6.7). The variants ran in a fresh random order in every iteration, so load drift hits both sides of each pair alike, and the paired shares hold: per-session savings ranged from 5.8% to 10.7%, and every session's 95% CI excludes zero. Over the 3 sessions, dropping the flag saved 6.5% to 9.1% of readiness (median of the paired differences, as a share of readiness with the flag). Read them as relative figures for that machine. mn:run itself was not timed.

    SemVer / API

  • This changes a default of mn:run, so it targets 5.1.x (5.1.0) and not a 5.0.x patch.

  • No public or protected member, parameter, user property or type is added, removed or changed. buildRunArguments stays private, and the new test reaches it by reflection, as the existing runAotIfNeeded test does.

  • Labelled type: improvement, like the issue.
  • Release note

    The release notes are the GitHub Releases, generated from PR titles and labels (.github/release.yml; release-history.adoc points there). There is no in-tree changelog, so the note is this PR's title under "Improvements", plus this text for the 5.1.0 notes:

    mn:run no longer adds -Dcom.sun.management.jmxremote to the application's command line, so the JVM no longer starts the JMX agent before main on every start and restart. JConsole, VisualVM, JMC and jcmd still work: they attach on demand. To start the agent with the application anyway (for example with -XX:+DisableAttachMechanism), pass -Dcom.sun.management.jmxremote to mn:run, or set it in mn.jvmArgs / <jvmArguments>. See "Monitoring with JMX" in the mn:run guide.

    Left for follow-ups

  • The Gradle run task: micronaut-projects/micronaut-gradle-plugin#1388, in progress in micronaut-projects/micronaut-gradle-plugin#1391.

  • The parent POM's exec:exec arguments: micronaut-projects/micronaut-platform#2817.

  • The Test Resources server started by ServerUtils in micronaut-test-resources: no issue yet. The gain there is small, because the server is long-lived.

  • The CDS archive for mn:run (#1731) should be re-measured on top of this change. Without the flag, the dump no longer needs --add-modules=jdk.management.agent unless the user opts back in.

  • mn:dev and mn:test (#1725, #1726) do not add the flag and should keep it that way.

  • -XX:TieredStopAtLevel=1 is unchanged. The flag's cost depends on the JIT mode, so re-measure if that line changes.
  • 🤖 Generated with Claude Code

    Diff: 134 lines (+130 / -4) across 6 files Reviewer: graemerocher Review duration: 594m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.40) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 134 lines diff across 6 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.73 · 1 substantive comment(s)
    0.73
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.293
    Reviewers
    Assignees
    alvarosanchez alvarosanchez
    Labels
    risk: low confidence: 81.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.9% · Lower = rushed or shallow review
    81.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.2% · Safe to merge
    7.2%