我正在尝试基于具有分析信息的方法结构(由JVM提供)构建JIT策略,但我无法手动触发JIT.这个文档说我可以通过调用运行JIT java.lang.Compiler.compileClass()但是每次方法都返回false,并且java.lang.Compiler每次运行JVM时检查的属性(java.compiler)都为null.我试过OpenJDK和Oracle JVM 1.7的结果都是一样的.
但是当我观察编译统计时
$ jstat -printcompilation <PID>
Run Code Online (Sandbox Code Playgroud)
我可以看到JIT成功编译了一些符合条件的方法.
如果存在任何方式,我宁愿从java代码触发它.我也尝试在热点VM的代码中搜索,但是找不到决策和JIT开始的类和方法.
编辑:在查看更多后,我发现compilationPolicy.cpp bu仍无法找到决定所依赖的确切位置.我会期待像(简单地思考)
if(hot_count > Threshold){
compile_method(methodHandle);
}
Run Code Online (Sandbox Code Playgroud)
但相反发现了这个,
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, …Run Code Online (Sandbox Code Playgroud)