gpt4 book ai didi

java - 使用 Gradle 运行单元测试时,最大堆大小在哪里设置?

转载 作者:行者123 更新时间:2023-12-05 02:43:58 32 4
gpt4 key购买 nike

我有一个失败的 OOM 单元测试,想知道为什么我需要像这样手动允许更大的 maxHeapSize:

test {
maxHeapSize = '4G'
}

我假设最大堆没有上限,并且在 gradle api 源中找不到任何东西来证明我错了。但是,使用 --info 运行 gradle 会清楚地显示出其他情况:

Starting process 'Gradle Test Executor 427'. Working directory: [project-dir] Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.6.jar_a26f6511a7813217be4cd6439d66563b/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea -cp /Users/[user]/.gradle/caches/6.4/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 427'

我的问题是上面的-Xmx512m是从哪里来的?

除此之外,有没有办法允许无限的最大堆,这会是一件完全不合理的事情吗?

Default maximum heap size for JavaExec Gradle task 可能重复

最佳答案

512m 默认设置在 DefaultWorkerProcessBuilder 中. 512m 是一种权衡,适用于中小型项目,并且可以同时运行多个 worker。根据commit message :

Limit memory for worker processes by default

Our workers for compilation, testing etc. had no defaultmemory settings until now, which mean that we would usethe default given by the JVM, which is 1/4th of system memoryin most cases. This is way too much when running with a highnumber of workers. Limiting this to 256m should be enough forsmall to medium sized projects. Larger projects will have totweak this value.


Next to that, is there a way to allow for unlimited max heap and would that be a totally unreasonable thing to do?

在撰写本文时,我不知道有任何 JVM 实现允许无限内存,老实说,我认为这是不可取的,因为它会大大降低系统速度。

关于java - 使用 Gradle 运行单元测试时,最大堆大小在哪里设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66678712/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com