[英]Getting started with JMH: java.lang.OutOfMemoryError: Java heap space
My first JMH benchmark code: 我的第一个JMH基准代码:
package org.sample;
import org.openjdk.jmh.annotations.Benchmark;
public class MyBenchmark {
@Benchmark
public void testMethod() {
// This is a demo/sample template for building your JMH benchmarks. Edit as needed.
// Put your benchmark code here.
int i = 100;
while (i > 0) {
i--;
}
}
}
Running it with any of the following commands results in 使用以下任何命令运行它会导致
java.lang.OutOfMemoryError: Java heap space
on the very first warmup iteration. 在第一次热身迭代中。
java -jar target/benchmarks.jar
java -Xmx256m -jar target/benchmarks.jar
java -Xmx500m -jar target/benchmarks.jar
java -Xmx700m -jar target/benchmarks.jar
java -Xms512m -Xmx1152m -XX:MaxNewSize=256m -jar target/benchmarks.jar
What am I missing? 我想念什么?
Because the code I did have was memory intensive (adding a string to itself a hundred times), and I did not rebuild the project before running it again. 因为我确实有代码为内存密集型(添加一个字符串本身百倍),我重新运行前未重建项目。
Once rebuilt with 一旦重建
mvn clean install
it works fine with the default command/heap size: 它可以与默认命令/堆大小一起正常工作:
java -jar target/benchmarks.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.