< prev index next >

src/share/vm/runtime/advancedThresholdPolicy.cpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 "compiler/compileTask.hpp"
  28 #include "runtime/advancedThresholdPolicy.hpp"
  29 #include "runtime/simpleThresholdPolicy.inline.hpp"



  30 
  31 #ifdef TIERED
  32 // Print an event.
  33 void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh,
  34                                              int bci, CompLevel level) {
  35   tty->print(" rate=");
  36   if (mh->prev_time() == 0) tty->print("n/a");
  37   else tty->print("%f", mh->rate());
  38 
  39   tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
  40                                threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
  41 
  42 }
  43 
  44 void AdvancedThresholdPolicy::initialize() {
  45   int count = CICompilerCount;
  46 #ifdef _LP64
  47   // Turn on ergonomic compiler count selection
  48   if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
  49     FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);


 436         MethodData* mdo = method->method_data();
 437         if (mdo != NULL) {
 438           if (mdo->would_profile()) {
 439             int mdo_i = mdo->invocation_count_delta();
 440             int mdo_b = mdo->backedge_count_delta();
 441             if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
 442               next_level = CompLevel_full_optimization;
 443             }
 444           } else {
 445             next_level = CompLevel_full_optimization;
 446           }
 447         }
 448       }
 449       break;
 450     }
 451   }
 452   return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 453 }
 454 
 455 // Determine if a method should be compiled with a normal entry point at a different level.
 456 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level) {
 457   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 458                              common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
 459   CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
 460 
 461   // If OSR method level is greater than the regular method level, the levels should be
 462   // equalized by raising the regular method level in order to avoid OSRs during each
 463   // invocation of the method.
 464   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 465     MethodData* mdo = method->method_data();
 466     guarantee(mdo != NULL, "MDO should not be NULL");
 467     if (mdo->invocation_count() >= 1) {
 468       next_level = CompLevel_full_optimization;
 469     }
 470   } else {
 471     next_level = MAX2(osr_level, next_level);
 472   }





 473   return next_level;
 474 }
 475 
 476 // Determine if we should do an OSR compilation of a given method.
 477 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level) {
 478   CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
 479   if (cur_level == CompLevel_none) {
 480     // If there is a live OSR method that means that we deopted to the interpreter
 481     // for the transition.
 482     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 483     if (osr_level > CompLevel_none) {
 484       return osr_level;
 485     }
 486   }





 487   return next_level;
 488 }
 489 
 490 // Update the rate and submit compile
 491 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
 492   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 493   update_rate(os::javaTimeMillis(), mh());
 494   CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
 495 }
 496 
 497 // Handle the invocation event.
 498 void AdvancedThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
 499                                                       CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 500   if (should_create_mdo(mh(), level)) {
 501     create_mdo(mh, thread);
 502   }
 503   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 504     CompLevel next_level = call_event(mh(), level);
 505     if (next_level != level) {
 506       compile(mh, InvocationEntryBci, next_level, thread);
 507     }
 508   }
 509 }
 510 
 511 // Handle the back branch event. Notice that we can compile the method
 512 // with a regular entry from here.
 513 void AdvancedThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
 514                                                        int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 515   if (should_create_mdo(mh(), level)) {
 516     create_mdo(mh, thread);
 517   }
 518   // Check if MDO should be created for the inlined method
 519   if (should_create_mdo(imh(), level)) {
 520     create_mdo(imh, thread);
 521   }
 522 
 523   if (is_compilation_enabled()) {
 524     CompLevel next_osr_level = loop_event(imh(), level);
 525     CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
 526     // At the very least compile the OSR version
 527     if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) {
 528       compile(imh, bci, next_osr_level, thread);
 529     }
 530 
 531     // Use loop event as an opportunity to also check if there's been
 532     // enough calls.
 533     CompLevel cur_level, next_level;
 534     if (mh() != imh()) { // If there is an enclosing method
 535       guarantee(nm != NULL, "Should have nmethod here");
 536       cur_level = comp_level(mh());
 537       next_level = call_event(mh(), cur_level);
 538 
 539       if (max_osr_level == CompLevel_full_optimization) {
 540         // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts
 541         bool make_not_entrant = false;
 542         if (nm->is_osr_method()) {
 543           // This is an osr method, just make it not entrant and recompile later if needed
 544           make_not_entrant = true;
 545         } else {
 546           if (next_level != CompLevel_full_optimization) {
 547             // next_level is not full opt, so we need to recompile the
 548             // enclosing method without the inlinee
 549             cur_level = CompLevel_none;
 550             make_not_entrant = true;
 551           }
 552         }
 553         if (make_not_entrant) {
 554           if (PrintTieredEvents) {
 555             int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
 556             print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
 557           }
 558           nm->make_not_entrant();
 559         }
 560       }
 561       if (!CompileBroker::compilation_is_in_queue(mh)) {
 562         // Fix up next_level if necessary to avoid deopts
 563         if (next_level == CompLevel_limited_profile && max_osr_level == CompLevel_full_profile) {
 564           next_level = CompLevel_full_profile;
 565         }
 566         if (cur_level != next_level) {
 567           compile(mh, InvocationEntryBci, next_level, thread);
 568         }
 569       }
 570     } else {
 571       cur_level = comp_level(imh());
 572       next_level = call_event(imh(), cur_level);
 573       if (!CompileBroker::compilation_is_in_queue(imh) && (next_level != cur_level)) {
 574         compile(imh, InvocationEntryBci, next_level, thread);
 575       }
 576     }
 577   }
 578 }
 579 
 580 #endif // TIERED


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 "compiler/compileTask.hpp"
  28 #include "runtime/advancedThresholdPolicy.hpp"
  29 #include "runtime/simpleThresholdPolicy.inline.hpp"
  30 #if INCLUDE_JVMCI
  31 #include "jvmci/jvmciRuntime.hpp"
  32 #endif
  33 
  34 #ifdef TIERED
  35 // Print an event.
  36 void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh,
  37                                              int bci, CompLevel level) {
  38   tty->print(" rate=");
  39   if (mh->prev_time() == 0) tty->print("n/a");
  40   else tty->print("%f", mh->rate());
  41 
  42   tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
  43                                threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
  44 
  45 }
  46 
  47 void AdvancedThresholdPolicy::initialize() {
  48   int count = CICompilerCount;
  49 #ifdef _LP64
  50   // Turn on ergonomic compiler count selection
  51   if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
  52     FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);


 439         MethodData* mdo = method->method_data();
 440         if (mdo != NULL) {
 441           if (mdo->would_profile()) {
 442             int mdo_i = mdo->invocation_count_delta();
 443             int mdo_b = mdo->backedge_count_delta();
 444             if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
 445               next_level = CompLevel_full_optimization;
 446             }
 447           } else {
 448             next_level = CompLevel_full_optimization;
 449           }
 450         }
 451       }
 452       break;
 453     }
 454   }
 455   return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 456 }
 457 
 458 // Determine if a method should be compiled with a normal entry point at a different level.
 459 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level, JavaThread * thread) {
 460   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 461                              common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
 462   CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
 463 
 464   // If OSR method level is greater than the regular method level, the levels should be
 465   // equalized by raising the regular method level in order to avoid OSRs during each
 466   // invocation of the method.
 467   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 468     MethodData* mdo = method->method_data();
 469     guarantee(mdo != NULL, "MDO should not be NULL");
 470     if (mdo->invocation_count() >= 1) {
 471       next_level = CompLevel_full_optimization;
 472     }
 473   } else {
 474     next_level = MAX2(osr_level, next_level);
 475   }
 476 #if INCLUDE_JVMCI
 477   if (UseJVMCICompiler) {
 478     next_level = JVMCIRuntime::adjust_comp_level(method, false, next_level, thread);
 479   }
 480 #endif
 481   return next_level;
 482 }
 483 
 484 // Determine if we should do an OSR compilation of a given method.
 485 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level, JavaThread * thread) {
 486   CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
 487   if (cur_level == CompLevel_none) {
 488     // If there is a live OSR method that means that we deopted to the interpreter
 489     // for the transition.
 490     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 491     if (osr_level > CompLevel_none) {
 492       return osr_level;
 493     }
 494   }
 495 #if INCLUDE_JVMCI
 496   if (UseJVMCICompiler) {
 497     next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
 498   }
 499 #endif
 500   return next_level;
 501 }
 502 
 503 // Update the rate and submit compile
 504 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
 505   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 506   update_rate(os::javaTimeMillis(), mh());
 507   CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
 508 }
 509 
 510 // Handle the invocation event.
 511 void AdvancedThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
 512                                                       CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 513   if (should_create_mdo(mh(), level)) {
 514     create_mdo(mh, thread);
 515   }
 516   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 517     CompLevel next_level = call_event(mh(), level, thread);
 518     if (next_level != level) {
 519       compile(mh, InvocationEntryBci, next_level, thread);
 520     }
 521   }
 522 }
 523 
 524 // Handle the back branch event. Notice that we can compile the method
 525 // with a regular entry from here.
 526 void AdvancedThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
 527                                                        int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 528   if (should_create_mdo(mh(), level)) {
 529     create_mdo(mh, thread);
 530   }
 531   // Check if MDO should be created for the inlined method
 532   if (should_create_mdo(imh(), level)) {
 533     create_mdo(imh, thread);
 534   }
 535 
 536   if (is_compilation_enabled()) {
 537     CompLevel next_osr_level = loop_event(imh(), level, thread);
 538     CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
 539     // At the very least compile the OSR version
 540     if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) {
 541       compile(imh, bci, next_osr_level, thread);
 542     }
 543 
 544     // Use loop event as an opportunity to also check if there's been
 545     // enough calls.
 546     CompLevel cur_level, next_level;
 547     if (mh() != imh()) { // If there is an enclosing method
 548       guarantee(nm != NULL, "Should have nmethod here");
 549       cur_level = comp_level(mh());
 550       next_level = call_event(mh(), cur_level, thread);
 551 
 552       if (max_osr_level == CompLevel_full_optimization) {
 553         // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts
 554         bool make_not_entrant = false;
 555         if (nm->is_osr_method()) {
 556           // This is an osr method, just make it not entrant and recompile later if needed
 557           make_not_entrant = true;
 558         } else {
 559           if (next_level != CompLevel_full_optimization) {
 560             // next_level is not full opt, so we need to recompile the
 561             // enclosing method without the inlinee
 562             cur_level = CompLevel_none;
 563             make_not_entrant = true;
 564           }
 565         }
 566         if (make_not_entrant) {
 567           if (PrintTieredEvents) {
 568             int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
 569             print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
 570           }
 571           nm->make_not_entrant();
 572         }
 573       }
 574       if (!CompileBroker::compilation_is_in_queue(mh)) {
 575         // Fix up next_level if necessary to avoid deopts
 576         if (next_level == CompLevel_limited_profile && max_osr_level == CompLevel_full_profile) {
 577           next_level = CompLevel_full_profile;
 578         }
 579         if (cur_level != next_level) {
 580           compile(mh, InvocationEntryBci, next_level, thread);
 581         }
 582       }
 583     } else {
 584       cur_level = comp_level(imh());
 585       next_level = call_event(imh(), cur_level, thread);
 586       if (!CompileBroker::compilation_is_in_queue(imh) && (next_level != cur_level)) {
 587         compile(imh, InvocationEntryBci, next_level, thread);
 588       }
 589     }
 590   }
 591 }
 592 
 593 #endif // TIERED
< prev index next >