From 569b850fe0cbf930115a9fa32bb9088b8ec7203a Mon Sep 17 00:00:00 2001 From: Dos Debug Date: Wed, 22 May 2019 19:35:29 +0500 Subject: [PATCH 1/2] Default to optimized launch of the JVM when using spring-boot:run See gh-16941 --- .../java/org/springframework/boot/maven/RunMojo.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 3119fbfeb4e..1bddc14f06c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -19,6 +19,7 @@ package org.springframework.boot.maven; import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,6 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.springframework.boot.loader.tools.JavaExecutable; @@ -53,6 +55,9 @@ public class RunMojo extends AbstractRunMojo { */ private Boolean hasDevtools; + @Parameter(property = "optimizedLaunch", defaultValue = "true") + private boolean optimizedLaunch = true; + @Override @Deprecated protected boolean enableForkByDefault() { @@ -70,6 +75,10 @@ public class RunMojo extends AbstractRunMojo { @Override protected void runWithForkedJvm(File workingDirectory, List args, Map environmentVariables) throws MojoExecutionException { + if (this.optimizedLaunch) { + String[] optimizedLaunchArgs = { "-Xverify:none", "-XX:TieredStopAtLevel=1" }; + Collections.addAll(args, optimizedLaunchArgs); + } int exitCode = forkJvm(workingDirectory, args, environmentVariables); if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) { return; From 4cdb5a8ecb31dcdc5a43c0172002dfbc277a2284 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 25 May 2019 12:22:00 +0200 Subject: [PATCH 2/2] Polish "Default to optimized launch of the JVM when using spring-boot:run" Closes gh-16941 --- .../src/it/run-fork/invoker.properties | 1 + .../src/it/run-fork/verify.groovy | 7 +++++-- .../springframework/boot/maven/RunMojo.java | 21 +++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/invoker.properties diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/invoker.properties b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/invoker.properties new file mode 100644 index 00000000000..8056f772dae --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/invoker.properties @@ -0,0 +1 @@ +invoker.goals=clean verify -X \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/verify.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/verify.groovy index 323ffc863b2..54e7b17fa2a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/verify.groovy +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-fork/verify.groovy @@ -1,3 +1,6 @@ -def file = new File(basedir, "build.log") -return file.text.contains("I haz been run from '$basedir'") +import static org.junit.Assert.assertTrue + +def file = new File(basedir, "build.log") +assertTrue file.text.contains("I haz been run from '$basedir'") +assertTrue file.text.contains("JVM argument(s): -Xverify:none -XX:TieredStopAtLevel=1") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 1bddc14f06c..29420c733ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -19,7 +19,6 @@ package org.springframework.boot.maven; import java.io.File; import java.net.URL; import java.net.URLClassLoader; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -55,8 +54,12 @@ public class RunMojo extends AbstractRunMojo { */ private Boolean hasDevtools; + /** + * Whether the JVM's launch should be optimized. + * @since 2.2.0 + */ @Parameter(property = "optimizedLaunch", defaultValue = "true") - private boolean optimizedLaunch = true; + private boolean optimizedLaunch; @Override @Deprecated @@ -72,13 +75,19 @@ public class RunMojo extends AbstractRunMojo { } } + @Override + protected RunArguments resolveJvmArguments() { + RunArguments jvmArguments = super.resolveJvmArguments(); + if (isFork() && this.optimizedLaunch) { + jvmArguments.getArgs().addFirst("-XX:TieredStopAtLevel=1"); + jvmArguments.getArgs().addFirst("-Xverify:none"); + } + return jvmArguments; + } + @Override protected void runWithForkedJvm(File workingDirectory, List args, Map environmentVariables) throws MojoExecutionException { - if (this.optimizedLaunch) { - String[] optimizedLaunchArgs = { "-Xverify:none", "-XX:TieredStopAtLevel=1" }; - Collections.addAll(args, optimizedLaunchArgs); - } int exitCode = forkJvm(workingDirectory, args, environmentVariables); if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) { return;