Remove default values for heap options (#610)

* Set default max heap size to null

Let the JVM decide the max heap size instead of using hardcoded defaults
to match the behaviour of vanilla Maven.

* Add ITs for verifying max heap behaviour

- By default no max heap should be set
- If configured via jvm.config then max heap should be set but not mvnd.maxHeapSize
- If configured via mvnd.maxHeapSize then max heap should be set

* Remove defaults memory options

* Add missing test project

* Fix too small heap size

* Fix tests

Co-authored-by: Ashhar Hasan <hashhar_dev@outlook.com>
This commit is contained in:
Guillaume Nodet
2022-04-26 13:22:37 +02:00
committed by GitHub
parent 8b2d8dc1f2
commit 73f4d50bcb
14 changed files with 237 additions and 85 deletions

View File

@@ -204,17 +204,17 @@ public enum Environment {
* The <code>-Xms</code> value to pass to the daemon. * The <code>-Xms</code> value to pass to the daemon.
* This option takes precedence over options specified in {@link #MVND_JVM_ARGS}. * This option takes precedence over options specified in {@link #MVND_JVM_ARGS}.
*/ */
MVND_MIN_HEAP_SIZE("mvnd.minHeapSize", null, "128M", OptionType.MEMORY_SIZE, Flags.DISCRIMINATING), MVND_MIN_HEAP_SIZE("mvnd.minHeapSize", null, null, OptionType.MEMORY_SIZE, Flags.DISCRIMINATING | Flags.OPTIONAL),
/** /**
* The <code>-Xmx</code> value to pass to the daemon. * The <code>-Xmx</code> value to pass to the daemon.
* This option takes precedence over options specified in {@link #MVND_JVM_ARGS}. * This option takes precedence over options specified in {@link #MVND_JVM_ARGS}.
*/ */
MVND_MAX_HEAP_SIZE("mvnd.maxHeapSize", null, "2G", OptionType.MEMORY_SIZE, Flags.DISCRIMINATING), MVND_MAX_HEAP_SIZE("mvnd.maxHeapSize", null, null, OptionType.MEMORY_SIZE, Flags.DISCRIMINATING | Flags.OPTIONAL),
/** /**
* The <code>-Xss</code> value to pass to the daemon. * The <code>-Xss</code> value to pass to the daemon.
* This option takes precedence over options specified in {@link #MVND_JVM_ARGS}. * This option takes precedence over options specified in {@link #MVND_JVM_ARGS}.
*/ */
MVND_THREAD_STACK_SIZE("mvnd.threadStackSize", null, "1M", OptionType.MEMORY_SIZE, Flags.DISCRIMINATING), MVND_THREAD_STACK_SIZE("mvnd.threadStackSize", null, null, OptionType.MEMORY_SIZE, Flags.DISCRIMINATING | Flags.OPTIONAL),
/** /**
* Additional JVM args to pass to the daemon. * Additional JVM args to pass to the daemon.
* The content of the <code>.mvn/jvm.config</code> file will prepended (and thus with * The content of the <code>.mvn/jvm.config</code> file will prepended (and thus with

View File

@@ -1,51 +0,0 @@
/*
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mvndaemon.mvnd.it;
import java.io.IOException;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.client.DaemonParameters;
import org.mvndaemon.mvnd.junit.MvndNativeTest;
import static org.junit.jupiter.api.Assertions.assertTrue;
@MvndNativeTest(projectDir = "src/test/projects/jvm-config")
public class JvmConfigNativeIT {
@Inject
Client client;
@Inject
DaemonParameters parameters;
@Test
void version() throws IOException, InterruptedException {
final TestClientOutput o = new TestClientOutput();
client.execute(o, "org.codehaus.gmaven:groovy-maven-plugin:2.1.1:execute",
"-Dsource=System.out.println(java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments())")
.assertSuccess();
String xmx = "-Xmx512k";
assertTrue(o.getMessages().stream()
.anyMatch(m -> m.toString().contains(xmx)),
"Output should contain " + xmx + " but is:\n"
+ o.getMessages().stream().map(Object::toString).collect(Collectors.joining("\n")));
}
}

View File

@@ -15,37 +15,9 @@
*/ */
package org.mvndaemon.mvnd.it; package org.mvndaemon.mvnd.it;
import java.io.IOException;
import javax.inject.Inject;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.client.DaemonParameters;
import org.mvndaemon.mvnd.junit.MvndTest; import org.mvndaemon.mvnd.junit.MvndTest;
import org.mvndaemon.mvnd.junit.TestRegistry;
import static org.junit.jupiter.api.Assertions.assertTrue;
@MvndTest(projectDir = "src/test/projects/maven-conf") @MvndTest(projectDir = "src/test/projects/maven-conf")
public class MavenConfTest extends MavenConfNativeIT { public class MavenConfTest extends MavenConfNativeIT {
@Inject
Client client;
@Inject
DaemonParameters parameters;
@Inject
TestRegistry registry;
@Test
void version() throws IOException, InterruptedException {
final TestClientOutput o = new TestClientOutput();
client.execute(o, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
"-Dexpression=maven.conf", "-q", "-DforceStdout", "--raw-streams").assertSuccess();
String conf = parameters.mvndHome().resolve("mvn/conf").toString();
assertTrue(o.getMessages().stream()
.anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
}
} }

View File

@@ -0,0 +1,117 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mvndaemon.mvnd.it;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import javax.inject.Inject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.junit.MvndNativeTest;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MaxHeapNativeIT {
static class BaseTest {
@Inject
Client client;
static ListAppender<ILoggingEvent> appender = new ListAppender<>();
@BeforeAll
static void setup() {
Logger logger = (Logger) LoggerFactory.getLogger("org.mvndaemon.mvnd.client.DaemonConnector");
logger.setLevel(Level.DEBUG);
logger.addAppender(appender);
appender.start();
}
@AfterAll
static void tearDown() {
Logger logger = (Logger) LoggerFactory.getLogger("org.mvndaemon.mvnd.client.DaemonConnector");
logger.detachAppender(appender);
}
static String getDaemonArgs() {
return appender.list.stream()
.filter(e -> e.getMessage().contains("Starting daemon process"))
.map(e -> e.getArgumentArray()[2].toString())
.findAny().orElseThrow();
}
@BeforeEach
void unitSetup() {
appender.list.clear();
}
}
@MvndNativeTest(projectDir = "src/test/projects/max-heap/default-heap")
static class DefaultConfig extends BaseTest {
@Test
void noXmxPassedByDefault() throws InterruptedException {
final TestClientOutput output = new TestClientOutput();
client.execute(output, "-Dmvnd.log.level=DEBUG", "org.codehaus.gmaven:groovy-maven-plugin:2.1.1:execute",
"-Dsource=System.out.println(java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments())")
.assertSuccess();
String daemonArgs = getDaemonArgs();
assertTrue(!daemonArgs.contains("-Xmx") && !daemonArgs.contains("mvnd.maxHeapSize"),
"Args must not contain -Xmx or mvnd.maxHeapSize but is:\n" + daemonArgs);
}
}
@MvndNativeTest(projectDir = "src/test/projects/max-heap/jvm-heap")
static class JvmConfig extends BaseTest {
@Test
void xmxFromJvmConfig() throws InterruptedException {
final TestClientOutput output = new TestClientOutput();
client.execute(output, "-Dmvnd.log.level=DEBUG", "org.codehaus.gmaven:groovy-maven-plugin:2.1.1:execute",
"-Dsource=System.out.println(java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments())")
.assertSuccess();
String daemonArgs = getDaemonArgs();
assertTrue(!daemonArgs.contains("-Xmx") && !daemonArgs.contains("mvnd.maxHeapSize"),
"Args must not contain -Xmx or mvnd.maxHeapSize but is:\n" + daemonArgs);
}
}
@MvndNativeTest(projectDir = "src/test/projects/max-heap/mvnd-props")
static class MvndProps extends BaseTest {
@Test
void xmxFromMvndProperties() throws InterruptedException {
final TestClientOutput output = new TestClientOutput();
client.execute(output, "-Dmvnd.log.level=DEBUG", "org.codehaus.gmaven:groovy-maven-plugin:2.1.1:execute",
"-Dsource=System.out.println(java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments())")
.assertSuccess();
String daemonArgs = getDaemonArgs();
assertTrue(daemonArgs.contains("-Xmx130M") && daemonArgs.contains("mvnd.maxHeapSize=130M"),
"Args must contain -Xmx130M or mvnd.maxHeapSize=130M but is:\n" + daemonArgs);
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mvndaemon.mvnd.it;
import org.mvndaemon.mvnd.junit.MvndTest;
public class MaxHeapTest extends MaxHeapNativeIT {
@MvndTest(projectDir = "src/test/projects/max-heap/default-heap")
static class DefaultConfig extends MaxHeapNativeIT.DefaultConfig {
}
@MvndTest(projectDir = "src/test/projects/max-heap/jvm-config")
static class JvmConfig extends MaxHeapNativeIT.JvmConfig {
}
@MvndTest(projectDir = "src/test/projects/max-heap/mvnd-props")
static class MvndProps extends MaxHeapNativeIT.MvndProps {
}
}

View File

@@ -0,0 +1,27 @@
<!--
Copyright 2021 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mvndaemon.mvnd.test.max-heap</groupId>
<artifactId>max-heap-default-heap</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>

View File

@@ -0,0 +1 @@
-Xmx140M

View File

@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10

View File

@@ -19,8 +19,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.mvndaemon.mvnd.test.jvm-config</groupId> <groupId>org.mvndaemon.mvnd.test.max-heap</groupId>
<artifactId>jvm-config</artifactId> <artifactId>max-heap-jvm-config</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10

View File

@@ -0,0 +1,17 @@
#
# Copyright 2019 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
mvnd.maxHeapSize=130M

View File

@@ -0,0 +1,27 @@
<!--
Copyright 2021 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mvndaemon.mvnd.test.max-heap</groupId>
<artifactId>max-heap-jvm-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>