< prev index next >

src/share/vm/runtime/advancedThresholdPolicy.cpp

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "runtime/advancedThresholdPolicy.hpp"
  28 #include "runtime/simpleThresholdPolicy.inline.hpp"
  29 #if INCLUDE_JVMCI
  30 #include "jvmci/jvmciRuntime.hpp"
  31 #endif
  32 
  33 #ifdef TIERED
  34 // Print an event.
  35 void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh,
  36                                              int bci, CompLevel level) {
  37   tty->print(" rate=");
  38   if (mh->prev_time() == 0) tty->print("n/a");
  39   else tty->print("%f", mh->rate());
  40 
  41   tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
  42                                threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
  43 
  44 }
  45 
  46 void AdvancedThresholdPolicy::initialize() {
  47   int count = CICompilerCount;
  48 #ifdef _LP64
  49   // Turn on ergonomic compiler count selection
  50   if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
  51     FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);
  52   }
  53   if (CICompilerCountPerCPU) {
  54     // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n
  55     int log_cpu = log2_intptr(os::active_processor_count());


 322     int i = method->invocation_count();
 323     int b = method->backedge_count();
 324     double k = Tier0ProfilingStartPercentage / 100.0;
 325     return call_predicate_helper<CompLevel_none>(i, b, k, method) || loop_predicate_helper<CompLevel_none>(i, b, k, method);
 326   }
 327   return false;
 328 }
 329 
 330 // Inlining control: if we're compiling a profiled method with C1 and the callee
 331 // is known to have OSRed in a C2 version, don't inline it.
 332 bool AdvancedThresholdPolicy::should_not_inline(ciEnv* env, ciMethod* callee) {
 333   CompLevel comp_level = (CompLevel)env->comp_level();
 334   if (comp_level == CompLevel_full_profile ||
 335       comp_level == CompLevel_limited_profile) {
 336     return callee->highest_osr_comp_level() == CompLevel_full_optimization;
 337   }
 338   return false;
 339 }
 340 
 341 // Create MDO if necessary.
 342 void AdvancedThresholdPolicy::create_mdo(methodHandle mh, JavaThread* THREAD) {
 343   if (mh->is_native() ||
 344       mh->is_abstract() ||
 345       mh->is_accessor() ||
 346       mh->is_constant_getter()) {
 347     return;
 348   }
 349   if (mh->method_data() == NULL) {
 350     Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR);
 351   }
 352 }
 353 
 354 
 355 /*
 356  * Method states:
 357  *   0 - interpreter (CompLevel_none)
 358  *   1 - pure C1 (CompLevel_simple)
 359  *   2 - C1 with invocation and backedge counting (CompLevel_limited_profile)
 360  *   3 - C1 with full profiling (CompLevel_full_profile)
 361  *   4 - C2 (CompLevel_full_optimization)
 362  *


 529     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 530     if (osr_level > CompLevel_none) {
 531       return osr_level;
 532     }
 533   }
 534 #if INCLUDE_JVMCI
 535   if (UseJVMCICompiler) {
 536     next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
 537   }
 538 #endif
 539   return next_level;
 540 }
 541 
 542 // Update the rate and submit compile
 543 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
 544   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 545   update_rate(os::javaTimeMillis(), mh());
 546   CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
 547 }
 548 
 549 bool AdvancedThresholdPolicy::maybe_switch_to_aot(methodHandle mh, CompLevel cur_level, CompLevel next_level, JavaThread* thread) {
 550   if (UseAOT && !delay_compilation_during_startup()) {
 551     if (cur_level == CompLevel_full_profile || cur_level == CompLevel_none) {
 552       // If the current level is full profile or interpreter and we're switching to any other level,
 553       // activate the AOT code back first so that we won't waste time overprofiling.
 554       compile(mh, InvocationEntryBci, CompLevel_aot, thread);
 555       // Fall through for JIT compilation.
 556     }
 557     if (next_level == CompLevel_limited_profile && cur_level != CompLevel_aot && mh->has_aot_code()) {
 558       // If the next level is limited profile, use the aot code (if there is any),
 559       // since it's essentially the same thing.
 560       compile(mh, InvocationEntryBci, CompLevel_aot, thread);
 561       // Not need to JIT, we're done.
 562       return true;
 563     }
 564   }
 565   return false;
 566 }
 567 
 568 
 569 // Handle the invocation event.




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeCache.hpp"
  27 #include "runtime/advancedThresholdPolicy.hpp"
  28 #include "runtime/simpleThresholdPolicy.inline.hpp"
  29 #if INCLUDE_JVMCI
  30 #include "jvmci/jvmciRuntime.hpp"
  31 #endif
  32 
  33 #ifdef TIERED
  34 // Print an event.
  35 void AdvancedThresholdPolicy::print_specific(EventType type, const methodHandle& mh, const methodHandle& imh,
  36                                              int bci, CompLevel level) {
  37   tty->print(" rate=");
  38   if (mh->prev_time() == 0) tty->print("n/a");
  39   else tty->print("%f", mh->rate());
  40 
  41   tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
  42                                threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
  43 
  44 }
  45 
  46 void AdvancedThresholdPolicy::initialize() {
  47   int count = CICompilerCount;
  48 #ifdef _LP64
  49   // Turn on ergonomic compiler count selection
  50   if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
  51     FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);
  52   }
  53   if (CICompilerCountPerCPU) {
  54     // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n
  55     int log_cpu = log2_intptr(os::active_processor_count());


 322     int i = method->invocation_count();
 323     int b = method->backedge_count();
 324     double k = Tier0ProfilingStartPercentage / 100.0;
 325     return call_predicate_helper<CompLevel_none>(i, b, k, method) || loop_predicate_helper<CompLevel_none>(i, b, k, method);
 326   }
 327   return false;
 328 }
 329 
 330 // Inlining control: if we're compiling a profiled method with C1 and the callee
 331 // is known to have OSRed in a C2 version, don't inline it.
 332 bool AdvancedThresholdPolicy::should_not_inline(ciEnv* env, ciMethod* callee) {
 333   CompLevel comp_level = (CompLevel)env->comp_level();
 334   if (comp_level == CompLevel_full_profile ||
 335       comp_level == CompLevel_limited_profile) {
 336     return callee->highest_osr_comp_level() == CompLevel_full_optimization;
 337   }
 338   return false;
 339 }
 340 
 341 // Create MDO if necessary.
 342 void AdvancedThresholdPolicy::create_mdo(const methodHandle& mh, JavaThread* THREAD) {
 343   if (mh->is_native() ||
 344       mh->is_abstract() ||
 345       mh->is_accessor() ||
 346       mh->is_constant_getter()) {
 347     return;
 348   }
 349   if (mh->method_data() == NULL) {
 350     Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR);
 351   }
 352 }
 353 
 354 
 355 /*
 356  * Method states:
 357  *   0 - interpreter (CompLevel_none)
 358  *   1 - pure C1 (CompLevel_simple)
 359  *   2 - C1 with invocation and backedge counting (CompLevel_limited_profile)
 360  *   3 - C1 with full profiling (CompLevel_full_profile)
 361  *   4 - C2 (CompLevel_full_optimization)
 362  *


 529     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 530     if (osr_level > CompLevel_none) {
 531       return osr_level;
 532     }
 533   }
 534 #if INCLUDE_JVMCI
 535   if (UseJVMCICompiler) {
 536     next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
 537   }
 538 #endif
 539   return next_level;
 540 }
 541 
 542 // Update the rate and submit compile
 543 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
 544   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 545   update_rate(os::javaTimeMillis(), mh());
 546   CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
 547 }
 548 
 549 bool AdvancedThresholdPolicy::maybe_switch_to_aot(const methodHandle& mh, CompLevel cur_level, CompLevel next_level, JavaThread* thread) {
 550   if (UseAOT && !delay_compilation_during_startup()) {
 551     if (cur_level == CompLevel_full_profile || cur_level == CompLevel_none) {
 552       // If the current level is full profile or interpreter and we're switching to any other level,
 553       // activate the AOT code back first so that we won't waste time overprofiling.
 554       compile(mh, InvocationEntryBci, CompLevel_aot, thread);
 555       // Fall through for JIT compilation.
 556     }
 557     if (next_level == CompLevel_limited_profile && cur_level != CompLevel_aot && mh->has_aot_code()) {
 558       // If the next level is limited profile, use the aot code (if there is any),
 559       // since it's essentially the same thing.
 560       compile(mh, InvocationEntryBci, CompLevel_aot, thread);
 561       // Not need to JIT, we're done.
 562       return true;
 563     }
 564   }
 565   return false;
 566 }
 567 
 568 
 569 // Handle the invocation event.


< prev index next >