< prev index next >

src/share/vm/runtime/simpleThresholdPolicy.cpp

Print this page




  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 "compiler/compileBroker.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "runtime/arguments.hpp"
  29 #include "runtime/simpleThresholdPolicy.hpp"
  30 #include "runtime/simpleThresholdPolicy.inline.hpp"
  31 #include "code/scopeDesc.hpp"



  32 
  33 
  34 void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) {
  35   int invocation_count = mh->invocation_count();
  36   int backedge_count = mh->backedge_count();
  37   MethodData* mdh = mh->method_data();
  38   int mdo_invocations = 0, mdo_backedges = 0;
  39   int mdo_invocations_start = 0, mdo_backedges_start = 0;
  40   if (mdh != NULL) {
  41     mdo_invocations = mdh->invocation_count();
  42     mdo_backedges = mdh->backedge_count();
  43     mdo_invocations_start = mdh->invocation_count_start();
  44     mdo_backedges_start = mdh->backedge_count_start();
  45   }
  46   tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
  47       invocation_count, backedge_count, prefix,
  48       mdo_invocations, mdo_invocations_start,
  49       mdo_backedges, mdo_backedges_start);
  50   tty->print(" %smax levels=%d,%d", prefix,
  51       mh->highest_comp_level(), mh->highest_osr_comp_level());


 337         MethodData* mdo = method->method_data();
 338         if (mdo != NULL) {
 339           if (mdo->would_profile()) {
 340             int mdo_i = mdo->invocation_count_delta();
 341             int mdo_b = mdo->backedge_count_delta();
 342             if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
 343               next_level = CompLevel_full_optimization;
 344             }
 345           } else {
 346             next_level = CompLevel_full_optimization;
 347           }
 348         }
 349       }
 350       break;
 351     }
 352   }
 353   return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 354 }
 355 
 356 // Determine if a method should be compiled with a normal entry point at a different level.
 357 CompLevel SimpleThresholdPolicy::call_event(Method* method,  CompLevel cur_level) {
 358   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 359                              common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
 360   CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
 361 
 362   // If OSR method level is greater than the regular method level, the levels should be
 363   // equalized by raising the regular method level in order to avoid OSRs during each
 364   // invocation of the method.
 365   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 366     MethodData* mdo = method->method_data();
 367     guarantee(mdo != NULL, "MDO should not be NULL");
 368     if (mdo->invocation_count() >= 1) {
 369       next_level = CompLevel_full_optimization;
 370     }
 371   } else {
 372     next_level = MAX2(osr_level, next_level);
 373   }
 374 




 375   return next_level;
 376 }
 377 
 378 // Determine if we should do an OSR compilation of a given method.
 379 CompLevel SimpleThresholdPolicy::loop_event(Method* method, CompLevel cur_level) {
 380   CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level);
 381   if (cur_level == CompLevel_none) {
 382     // If there is a live OSR method that means that we deopted to the interpreter
 383     // for the transition.
 384     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 385     if (osr_level > CompLevel_none) {
 386       return osr_level;
 387     }
 388   }





 389   return next_level;
 390 }
 391 
 392 
 393 // Handle the invocation event.
 394 void SimpleThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
 395                                               CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 396   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 397     CompLevel next_level = call_event(mh(), level);
 398     if (next_level != level) {
 399       compile(mh, InvocationEntryBci, next_level, thread);
 400     }
 401   }
 402 }
 403 
 404 // Handle the back branch event. Notice that we can compile the method
 405 // with a regular entry from here.
 406 void SimpleThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
 407                                                      int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 408   // If the method is already compiling, quickly bail out.
 409   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 410     // Use loop event as an opportunity to also check there's been
 411     // enough calls.
 412     CompLevel cur_level = comp_level(mh());
 413     CompLevel next_level = call_event(mh(), cur_level);
 414     CompLevel next_osr_level = loop_event(mh(), level);
 415 
 416     next_level = MAX2(next_level,
 417                       next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
 418     bool is_compiling = false;
 419     if (next_level != cur_level) {
 420       compile(mh, InvocationEntryBci, next_level, thread);
 421       is_compiling = true;
 422     }
 423 
 424     // Do the OSR version
 425     if (!is_compiling && next_osr_level != level) {
 426       compile(mh, bci, next_osr_level, thread);
 427     }
 428   }
 429 }


  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 "compiler/compileBroker.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "runtime/arguments.hpp"
  29 #include "runtime/simpleThresholdPolicy.hpp"
  30 #include "runtime/simpleThresholdPolicy.inline.hpp"
  31 #include "code/scopeDesc.hpp"
  32 #if INCLUDE_JVMCI
  33 #include "jvmci/jvmciRuntime.hpp"
  34 #endif
  35 
  36 
  37 void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) {
  38   int invocation_count = mh->invocation_count();
  39   int backedge_count = mh->backedge_count();
  40   MethodData* mdh = mh->method_data();
  41   int mdo_invocations = 0, mdo_backedges = 0;
  42   int mdo_invocations_start = 0, mdo_backedges_start = 0;
  43   if (mdh != NULL) {
  44     mdo_invocations = mdh->invocation_count();
  45     mdo_backedges = mdh->backedge_count();
  46     mdo_invocations_start = mdh->invocation_count_start();
  47     mdo_backedges_start = mdh->backedge_count_start();
  48   }
  49   tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
  50       invocation_count, backedge_count, prefix,
  51       mdo_invocations, mdo_invocations_start,
  52       mdo_backedges, mdo_backedges_start);
  53   tty->print(" %smax levels=%d,%d", prefix,
  54       mh->highest_comp_level(), mh->highest_osr_comp_level());


 340         MethodData* mdo = method->method_data();
 341         if (mdo != NULL) {
 342           if (mdo->would_profile()) {
 343             int mdo_i = mdo->invocation_count_delta();
 344             int mdo_b = mdo->backedge_count_delta();
 345             if ((this->*p)(mdo_i, mdo_b, cur_level, method)) {
 346               next_level = CompLevel_full_optimization;
 347             }
 348           } else {
 349             next_level = CompLevel_full_optimization;
 350           }
 351         }
 352       }
 353       break;
 354     }
 355   }
 356   return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 357 }
 358 
 359 // Determine if a method should be compiled with a normal entry point at a different level.
 360 CompLevel SimpleThresholdPolicy::call_event(Method* method,  CompLevel cur_level, JavaThread* thread) {
 361   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 362                              common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
 363   CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
 364 
 365   // If OSR method level is greater than the regular method level, the levels should be
 366   // equalized by raising the regular method level in order to avoid OSRs during each
 367   // invocation of the method.
 368   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 369     MethodData* mdo = method->method_data();
 370     guarantee(mdo != NULL, "MDO should not be NULL");
 371     if (mdo->invocation_count() >= 1) {
 372       next_level = CompLevel_full_optimization;
 373     }
 374   } else {
 375     next_level = MAX2(osr_level, next_level);
 376   }
 377 #if INCLUDE_JVMCI
 378   if (UseJVMCICompiler) {
 379     next_level = JVMCIRuntime::adjust_comp_level(method, false, next_level, thread);
 380   }
 381 #endif
 382   return next_level;
 383 }
 384 
 385 // Determine if we should do an OSR compilation of a given method.
 386 CompLevel SimpleThresholdPolicy::loop_event(Method* method, CompLevel cur_level, JavaThread* thread) {
 387   CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level);
 388   if (cur_level == CompLevel_none) {
 389     // If there is a live OSR method that means that we deopted to the interpreter
 390     // for the transition.
 391     CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 392     if (osr_level > CompLevel_none) {
 393       return osr_level;
 394     }
 395   }
 396 #if INCLUDE_JVMCI
 397   if (UseJVMCICompiler) {
 398     next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
 399   }
 400 #endif
 401   return next_level;
 402 }
 403 
 404 
 405 // Handle the invocation event.
 406 void SimpleThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
 407                                               CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 408   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 409     CompLevel next_level = call_event(mh(), level, thread);
 410     if (next_level != level) {
 411       compile(mh, InvocationEntryBci, next_level, thread);
 412     }
 413   }
 414 }
 415 
 416 // Handle the back branch event. Notice that we can compile the method
 417 // with a regular entry from here.
 418 void SimpleThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
 419                                                      int bci, CompLevel level, CompiledMethod* nm, JavaThread* thread) {
 420   // If the method is already compiling, quickly bail out.
 421   if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
 422     // Use loop event as an opportunity to also check there's been
 423     // enough calls.
 424     CompLevel cur_level = comp_level(mh());
 425     CompLevel next_level = call_event(mh(), cur_level, thread);
 426     CompLevel next_osr_level = loop_event(mh(), level, thread);
 427 
 428     next_level = MAX2(next_level,
 429                       next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
 430     bool is_compiling = false;
 431     if (next_level != cur_level) {
 432       compile(mh, InvocationEntryBci, next_level, thread);
 433       is_compiling = true;
 434     }
 435 
 436     // Do the OSR version
 437     if (!is_compiling && next_osr_level != level) {
 438       compile(mh, bci, next_osr_level, thread);
 439     }
 440   }
 441 }
< prev index next >