【问题标题】:Is there a way to trigger JIT manually other than java.lang.Compiler除了 java.lang.Compiler 之外,还有其他方法可以手动触发 JIT
【发布时间】:2015-02-24 15:23:19
【问题描述】:

我正在尝试基于方法结构和分析信息(由 JVM 提供)构建 JIT 策略,但我无法手动触发 JIT。 This documentation 说我可以通过调用 java.lang.Compiler.compileClass() 来运行 JIT,但是每次运行 JVM 时方法都会返回 false 并且 java.lang.Compiler 检查的属性(java.compiler)为空。我在 OpenJDK 和 Oracle JVM 1.7 上试过,结果都一样。

但是,当我用

观察编译统计信息时
$ jstat -printcompilation <PID>

我可以看到 JIT 成功编译了一些符合条件的方法。

如果存在任何方式,我宁愿从 java 代码中触发它。我也尝试在 hotspot VM's code 中进行搜索,但我找不到做出决定和 JIT 开始的类和方法。

编辑:环顾四周后,我发现compilationPolicy.cpp bu 仍然找不到决定所依赖的确切位置。我希望像(简单地思考)

if(hot_count > Threshold){
   compile_method(methodHandle);
}

却发现了这个,

void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) {
const int comp_level = CompLevel_highest_tier;
  const int hot_count = m->invocation_count();
  reset_counter_for_invocation_event(m);
  const char* comment = "count";

  if (is_compilation_enabled() && can_be_compiled(m)) {
    nmethod* nm = m->code();
    if (nm == NULL ) {
    // [MY COMMENT] no check being done on hot_count in here or callee methods
      CompileBroker::compile_method(m, InvocationEntryBci, comp_level, m, hot_count, comment, thread);
    }
  }
}

就跟踪本机 JVM 代码而言,我的主要话题已经结束。 仍在寻找在代码的 java 端使用的简单解决方案

【问题讨论】:

  • 您确定您的机器上启用了java.compiler 属性吗?您引用的文档明确引用了需要设置的内容。您可以通过System.out.println(System.getProperty("java.compiler"));查看。
  • System.out.println(System.getProperty("java.compiler")); 代码打印 null。我不确定我是否应该自己设置一个值,即使我找不到任何文档来设置特定值。

标签: java compiler-optimization jvm-hotspot


【解决方案1】:

听起来您想要类似于编译器控制功能 (http://openjdk.java.net/jeps/165) 的东西。

不幸的是,它还不存在,尽管它目前计划成为 Java 9 的一部分。

【讨论】:

  • 是的,我想要这样的东西,更具体的程序控制。但我不明白当前 JDK 中存在 java.lang.Compiler 类。如果这个类是不同厂商控制JDK的特性,为什么hotspot不提供默认实现来使用'Compiler'。
猜你喜欢
  • 1970-01-01
  • 2018-03-01
  • 1970-01-01
  • 2015-10-27
  • 2019-09-14
  • 2017-07-18
  • 2015-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多