You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/10/14 08:03:47 UTC
(maven) branch maven-4.0.x updated: fix: precompile JvmConfigParser to eliminate per-run source-launch overhead
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new 740ba54e7f fix: precompile JvmConfigParser to eliminate per-run source-launch overhead
740ba54e7f is described below
commit 740ba54e7f47978efe40cd88a90fea47a98beca4
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Oct 14 10:03:39 2026 +0200
fix: precompile JvmConfigParser to eliminate per-run source-launch overhead
Backport of #13431 to `maven-4.0.x`.
Ship `JvmConfigParser` as a precompiled class instead of running it in source-launch mode.
- Add a dedicated `compile-jvm-config-parser` compiler execution in `apache-maven/pom.xml` to compile the parser at build time
- Include `JvmConfigParser.class` in `bin/` via the assembly descriptor; remove `.java` from the `*.cmd` fileset
- Update `bin/mvn` and `bin/mvn.cmd` to invoke the parser with `-cp $MAVEN_HOME/bin JvmConfigParser` instead of source-launch
- Update `test-mvn-path-conversion.sh` stub to match the new invocation style (positional argument shifts)
- Source-launch compilation cost was ~455 ms per invocation with a `.mvn/jvm.config`; precompiled cost is ~30 ms
Fixes #13404
---
apache-maven/pom.xml | 15 +++++++++++++++
apache-maven/src/assembly/component.xml | 8 +++++++-
apache-maven/src/assembly/maven/bin/JvmConfigParser.java | 4 ++--
apache-maven/src/assembly/maven/bin/mvn | 10 +++++-----
apache-maven/src/assembly/maven/bin/mvn.cmd | 6 +++---
apache-maven/src/test/scripts/test-mvn-path-conversion.sh | 8 ++++----
6 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index 5fa9ebc315..21ec647e2c 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -177,6 +177,21 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
+ <execution>
+ <!-- compiled here so that the launchers do not pay for source-launch compilation on every run -->
+ <id>compile-jvm-config-parser</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/assembly/maven/bin</compileSourceRoot>
+ </compileSourceRoots>
+ <includes>
+ <include>JvmConfigParser.java</include>
+ </includes>
+ </configuration>
+ </execution>
<execution>
<id>test-compile</id>
<goals>
diff --git a/apache-maven/src/assembly/component.xml b/apache-maven/src/assembly/component.xml
index 5f55a310c8..ae71cd4e3b 100644
--- a/apache-maven/src/assembly/component.xml
+++ b/apache-maven/src/assembly/component.xml
@@ -68,10 +68,16 @@ under the License.
<includes>
<include>*.cmd</include>
<include>*.conf</include>
- <include>*.java</include>
</includes>
<lineEnding>dos</lineEnding>
</fileSet>
+ <fileSet>
+ <directory>target/classes</directory>
+ <outputDirectory>bin</outputDirectory>
+ <includes>
+ <include>JvmConfigParser.class</include>
+ </includes>
+ </fileSet>
<fileSet>
<directory>target/dependency/org/jline/nativ</directory>
<outputDirectory>lib/jline-native</outputDirectory>
diff --git a/apache-maven/src/assembly/maven/bin/JvmConfigParser.java b/apache-maven/src/assembly/maven/bin/JvmConfigParser.java
index 41b87569dc..21e46b6db1 100644
--- a/apache-maven/src/assembly/maven/bin/JvmConfigParser.java
+++ b/apache-maven/src/assembly/maven/bin/JvmConfigParser.java
@@ -30,7 +30,7 @@
* Parses .mvn/jvm.config file for Windows batch/Unix shell scripts.
* This avoids the complexity of parsing special characters (pipes, quotes, etc.) in scripts.
*
- * Usage: java JvmConfigParser.java <jvm.config-path> <maven-project-basedir> [output-file]
+ * Usage: java -cp <bin-dir> JvmConfigParser <jvm.config-path> <maven-project-basedir> [output-file]
*
* If output-file is provided, writes result to that file (avoids Windows file locking issues).
* Otherwise, outputs to stdout.
@@ -40,7 +40,7 @@
public class JvmConfigParser {
public static void main(String[] args) {
if (args.length < 2 || args.length > 3) {
- System.err.println("Usage: java JvmConfigParser.java <jvm.config-path> <maven-project-basedir> [output-file]");
+ System.err.println("Usage: java -cp <bin-dir> JvmConfigParser <jvm.config-path> <maven-project-basedir> [output-file]");
System.exit(1);
}
diff --git a/apache-maven/src/assembly/maven/bin/mvn b/apache-maven/src/assembly/maven/bin/mvn
index d79763f3a1..da61fa8a59 100755
--- a/apache-maven/src/assembly/maven/bin/mvn
+++ b/apache-maven/src/assembly/maven/bin/mvn
@@ -204,8 +204,8 @@ find_file_argument_basedir() {
# Set MAVEN_DEBUG_SCRIPT=1 to enable debug logging
concat_lines() {
if [ -f "$1" ]; then
- # Use Java source-launch mode (JDK 11+) to run JvmConfigParser directly
- # This avoids the need for compilation and temporary directories
+ # JvmConfigParser is shipped precompiled: source-launch mode would compile it
+ # on every invocation, which costs several times the actual parsing
# $2 is the native (Windows) form of MAVEN_PROJECTBASEDIR for placeholder expansion.
_basedir_native="${2:-$MAVEN_PROJECTBASEDIR}"
@@ -214,7 +214,7 @@ concat_lines() {
printf '[DEBUG] Found jvm.config file at: %s\n' "$1" >&2
printf '[DEBUG] Running JvmConfigParser with Java: %s\n' "$JAVACMD" >&2
printf '[DEBUG] Parser arguments: %s %s %s\n' \
- "$MAVEN_HOME/bin/JvmConfigParser.java" "$1" "$_basedir_native" >&2
+ "-cp $MAVEN_HOME/bin JvmConfigParser" "$1" "$_basedir_native" >&2
fi
# Verify Java is available
@@ -223,9 +223,9 @@ concat_lines() {
return 1
}
- # Run the parser using source-launch mode
+ # Run the parser
# Capture both stdout and stderr for comprehensive error reporting
- parser_output=$("$JAVACMD" "$MAVEN_HOME/bin/JvmConfigParser.java" "$1" "$_basedir_native" 2>&1)
+ parser_output=$("$JAVACMD" -cp "$MAVEN_HOME/bin" JvmConfigParser "$1" "$_basedir_native" 2>&1)
parser_exit=$?
if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
diff --git a/apache-maven/src/assembly/maven/bin/mvn.cmd b/apache-maven/src/assembly/maven/bin/mvn.cmd
index 74d4a5a984..9841a3a9d1 100644
--- a/apache-maven/src/assembly/maven/bin/mvn.cmd
+++ b/apache-maven/src/assembly/maven/bin/mvn.cmd
@@ -182,7 +182,7 @@ set JVM_CONFIG_MAVEN_OPTS=
if not exist "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadJvmConfig
-rem Use Java source-launch mode (JDK 11+) to parse jvm.config
+rem Use the precompiled JvmConfigParser to parse jvm.config
rem This avoids batch script parsing issues with special characters (pipes, quotes, @, etc.)
rem Java writes parsed output to a temp file; we read it with 'set /p' + input redirect.
rem
@@ -206,11 +206,11 @@ if defined MAVEN_DEBUG_SCRIPT (
echo [DEBUG] Found .mvn\jvm.config file at: %MAVEN_PROJECTBASEDIR%\.mvn\jvm.config
echo [DEBUG] Using temp file: %JVM_CONFIG_TEMP%
echo [DEBUG] Running JvmConfigParser with Java: %JAVACMD%
- echo [DEBUG] Parser arguments: "%MAVEN_HOME%\bin\JvmConfigParser.java" "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" "%JVM_CONFIG_TEMP%"
+ echo [DEBUG] Parser arguments: -cp "%MAVEN_HOME%\bin" JvmConfigParser "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" "%JVM_CONFIG_TEMP%"
)
rem Run parser with output file as third argument - Java writes directly to file
-"%JAVACMD%" "%MAVEN_HOME%\bin\JvmConfigParser.java" "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" "%JVM_CONFIG_TEMP%"
+"%JAVACMD%" -cp "%MAVEN_HOME%\bin" JvmConfigParser "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" "%JVM_CONFIG_TEMP%"
set JVM_CONFIG_EXIT=%ERRORLEVEL%
if defined MAVEN_DEBUG_SCRIPT (
diff --git a/apache-maven/src/test/scripts/test-mvn-path-conversion.sh b/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
index 371322af4d..e9ee4255c8 100644
--- a/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
+++ b/apache-maven/src/test/scripts/test-mvn-path-conversion.sh
@@ -131,8 +131,8 @@ case " $* " in
*" -version "*) exit 0 ;;
esac
-case "$1" in
- *JvmConfigParser.java)
+case "$3" in
+ JvmConfigParser)
# Mimics bin/JvmConfigParser: strip comments, expand the base directory
# placeholders and print the arguments quoted.
expand() {
@@ -149,7 +149,7 @@ case "$1" in
printf '%s' "$out$text"
}
- basedir="$3"
+ basedir="$5"
set -f
while IFS= read -r line || [ -n "$line" ]; do
line="${line%%#*}"
@@ -158,7 +158,7 @@ case "$1" in
for token in $line; do
printf '"%s" ' "$token"
done
- done < "$2"
+ done < "$4"
printf '\n'
exit 0 ;;
esac