卡尺错误:CICompilerCount为1无效;必须至少为2。

14

我有一个卡尺基准(1.0-beta-2):

import com.google.caliper.Benchmark;
import com.google.caliper.runner.CaliperMain;

public class MyBenchmark {

    @Benchmark public int a(int rep) {
        return 0;
    }

    public static void main(String[] args) {
        CaliperMain.main(MyBenchmark.class, args);
    }   
}

我可以从Eclipse或命令行运行它:

mvn exec:java -Dexec.mainClass="com.google.caliper.runner.CaliperMain" -Dexec.args="MyBenchmark" 

在这两种情况下,我都收到了一个错误:

ERROR: Trial failed to complete (its results will not be included in the run):
  The worker exited without producing data. It has likely crashed. Inspect /tmp/1427055470061-0/trial-1.log to see any worker output.

在这个文件中我看到:

Trial Number: 1
Trial Id: d663a0b5-55b4-43c3-97d8-93f14f436342
Experiment: {instrument=allocation, benchmarkMethod=a, vm=default, parameters={}}

[stderr] CICompilerCount of 1 is invalid; must be at least 2
[stderr] Error: Could not create the Java Virtual Machine.
[stderr] Error: A fatal exception has occurred. Program will exit.

Ubuntu 14.04,Java:

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

有什么想法可以修复它吗?

2个回答

15
我找到了一个解决方案。标志-XX:-TieredCompilation可以帮助解决问题。它可以直接在微基准测试的Java类中使用,如下所示:
import com.google.caliper.api.VmOptions;

@VmOptions("-XX:-TieredCompilation")
public class MyMicrobenchmark {
...

1
这不好,因为它显著改变了JVM的默认行为,并破坏了基准测试的主要思想:如果您在生产中运行不同的东西,则测量一件事情是没有意义的。 - apangin
2
我个人建议使用JMH而不是Caliper。这个工具是由JVM工程师开发和使用的。 - apangin
非常感谢。在添加了VmOption之后,我忘记重新构建类,因此花了一个小时才意识到你的帖子有多么有用。 - Mehmet

4

这是Caliper中的一个bug。它默认使用-XX:CICompilerCount=1作为JVM参数。然而,当启用分层编译时,必须至少有2个编译器线程(一个用于C1和一个用于C2)。

尝试手动覆盖-XX:CICompilerCount并使用更大的值。


卡钳似乎覆盖了这个设置。 - piotrek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接