JIT编译性能测试

1、JIT编译器相关VM参数

-server 服务端模式
-Xint 解释器执行
-Xcomp 编译器执行
-Xmixed 混合模式
-XX:+TieredCompilation 打开多级编译策略(JDK1.8是默认开启的,如果关闭则 -XX:-TieredCompilation)
-XX:CompileThreshold 编译阈值 -client模式下为1500,-server模式下为10000
-XX:+PrintCompilation 开启编译日志打印

–XX:ReservedCodeCacheSize 代码缓存大小 (64-bit server with Tiered Compilation, Java 8 ,默认是240mb)

2、性能测试

/**
 * @author: guanjian
 * @date: 2020/11/06 9:52
 * @description: JIT编译测试
 */
public class JITTest {
 
    /**
     * 模拟耗时方法
     */
    public static double cal() {
        double d1 = 0.618d;
        double d2 = 6.18d;
        double d3 = 0d;
 
        for (int i = 0; i < 100000; i++) {
            d3 += (d1 * d2) / (d1 * d2);
        }
        return d3;
    }
 
    public static void main(String[] args) {
 
        long start = System.currentTimeMillis();
        System.out.format("start : %s \n", start);
 
        for (int i = 0; i < 100000; i++) {
            cal();
        }
 
        long end = System.currentTimeMillis();
        System.out.format("end : %s \n", end);
        System.out.format("cost : %s\n", end - start);
    }
}
  • 测试-Xint解释器执行 vs -Xcomp编译器执行性能

50000次,-XX:CompileThreshold为10000触发即时编译,-XX:+TieredCompilation JDK8默认开启分层编译

-server -Xint cost:38077ms
-server -Xcomp cost:4311ms

结论:-Xcomp编译执行更快

50000次,-XX:CompileThreshold为10000触发即时编译,-XX:-TieredCompilation 关闭了分层编译,直接编译

-server -Xint cost:41613ms
-server -Xcomp cost:1587ms

结论:没有了分层编译的加持效果更明显,-Xcomp编译要远远超过-Xint解释器执行

  • 测试-XX:CompileThreshold的影响

100000次,-XX:+TieredCompilation JDK8默认开启分层编译

-server -Xcomp -XX:CompileThreshold=10 cost:7017

-server -Xcomp -XX:CompileThreshold=100000 cost:7686

结论:越早触发优化越能提升性能,由于编译过程也有性能损耗,所以阈值要合理,不然适得其反

  • 测试开启与关闭分层编译性能

50000次,-XX:+TieredCompilation JDK8默认开启分层编译
-server -Xcomp -XX:CompileThreshold=100 -XX:-TieredCompilation cost : 1568ms
-server -Xcomp -XX:CompileThreshold=100 -XX:+TieredCompilation cost : 4281ms

结论:关闭分层编译后,减少了探测优化升级过程,直接编译优化,性能有提升

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大摩羯先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值