为了账号安全,请及时绑定邮箱和手机立即绑定

标准 JIT 编译而不是 HotSpot 中的 On Stack Replacement

标准 JIT 编译而不是 HotSpot 中的 On Stack Replacement

RISEBY 2022-11-30 11:23:55
我试图在 Java HotSpot VM 中使用 C1 查看标准 JIT 编译而不是 OSR 的结果。我已经关闭了 OSR using-XX:-UseOnStackReplacement并使用-XX:TieredStopAtLevel=1. 但是现在我的方法根本没有被编译。我打开了 Print Compilation,如果我让它使用 OSR,它会很好地记录编译。此外,在没有 OSR 的情况下,我的所有断点都不会在 C1 文件中命中。我正在使用一个非常简单的代码片段来测试这个class Demo {  public static void main(String[] args) {      int a = workload();    System.out.println("Calculated answer is: " + a);  }  private static int workload() {    int a = 14;    for (int i = 0; i<100000; i++) {      a = a + i;    }    return a;  }}
查看完整描述

1 回答

?
慕神8447489

TA贡献1780条经验 获得超1个赞

问题是您workload只调用一次并多次执行该循环;你没有执行workload很多次;这是你在这里遇到的主要问题。JIT可以优化方法,但这里只有一个循环 - 因此除非OSR处于活动状态,否则没有太多需要优化的地方。


这很容易证明,您可以使用以下方法运行您的方法:


-XX:+UnlockDiagnosticVMOptions  

-XX:TieredStopAtLevel=1 

-XX:+TraceNMethodInstalls // this is to track the compiled methods

-XX:-UseOnStackReplacement  

   com.so.jit.OSRCompilation // this is the classname I've used

在您将获得的输出中,您会看到很多Installing method.


但是,如果您启用OSR:


-XX:+UnlockDiagnosticVMOptions  

-XX:TieredStopAtLevel=1 

-XX:+TraceNMethodInstalls // this is to track the compiled methods

-XX:+UseOnStackReplacement  

   com.so.jit.OSRCompilation // this is the classname I've used

你会得到很多Installing method,而且还有一行:


 Installing osr method (1) com.so.jit.OSRCompilation.workload()I @ 5


查看完整回答
反对 回复 2022-11-30
  • 1 回答
  • 0 关注
  • 62 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信