src/share/vm/runtime/compilationPolicy.cpp

Print this page
rev 2893 : 7121756: Improve C1 inlining policy by using profiling at call sites
Summary: profile based recompilation of methods with C1 with more inlining.
Reviewed-by:


  39 #include "runtime/rframe.hpp"
  40 #include "runtime/simpleThresholdPolicy.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "runtime/thread.hpp"
  43 #include "runtime/timer.hpp"
  44 #include "runtime/vframe.hpp"
  45 #include "runtime/vm_operations.hpp"
  46 #include "utilities/events.hpp"
  47 #include "utilities/globalDefinitions.hpp"
  48 
  49 CompilationPolicy* CompilationPolicy::_policy;
  50 elapsedTimer       CompilationPolicy::_accumulated_time;
  51 bool               CompilationPolicy::_in_vm_startup;
  52 
  53 // Determine compilation policy based on command line argument
  54 void compilationPolicy_init() {
  55   CompilationPolicy::set_in_vm_startup(DelayCompilationDuringStartup);
  56 
  57   switch(CompilationPolicyChoice) {
  58   case 0:





  59     CompilationPolicy::set_policy(new SimpleCompPolicy());



  60     break;
  61 
  62   case 1:
  63 #ifdef COMPILER2
  64     CompilationPolicy::set_policy(new StackWalkCompPolicy());
  65 #else
  66     Unimplemented();
  67 #endif
  68     break;
  69   case 2:
  70 #ifdef TIERED
  71     CompilationPolicy::set_policy(new SimpleThresholdPolicy());
  72 #else
  73     Unimplemented();
  74 #endif
  75     break;
  76   case 3:
  77 #ifdef TIERED
  78     CompilationPolicy::set_policy(new AdvancedThresholdPolicy());
  79 #else


 403   if (is_compilation_enabled() && can_be_compiled(m)) {
 404     nmethod* nm = m->code();
 405     if (nm == NULL ) {
 406       const char* comment = "count";
 407       CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier,
 408                                     m, hot_count, comment, CHECK);
 409     }
 410   }
 411 }
 412 
 413 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) {
 414   int hot_count = m->backedge_count();
 415   const char* comment = "backedge_count";
 416 
 417   if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) {
 418     CompileBroker::compile_method(m, bci, CompLevel_highest_tier,
 419                                   m, hot_count, comment, CHECK);
 420     NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));)
 421   }
 422 }



























































 423 // StackWalkCompPolicy - walk up stack to find a suitable method to compile
 424 
 425 #ifdef COMPILER2
 426 const char* StackWalkCompPolicy::_msg = NULL;
 427 
 428 
 429 // Consider m for compilation
 430 void StackWalkCompPolicy::method_invocation_event(methodHandle m, TRAPS) {
 431   int hot_count = m->invocation_count();
 432   reset_counter_for_invocation_event(m);
 433   const char* comment = "count";
 434 
 435   if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) {
 436     ResourceMark rm(THREAD);
 437     JavaThread *thread = (JavaThread*)THREAD;
 438     frame       fr     = thread->last_frame();
 439     assert(fr.is_interpreted_frame(), "must be interpreted");
 440     assert(fr.interpreter_frame_method() == m(), "bad method");
 441 
 442     if (TraceCompilationPolicy) {




  39 #include "runtime/rframe.hpp"
  40 #include "runtime/simpleThresholdPolicy.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "runtime/thread.hpp"
  43 #include "runtime/timer.hpp"
  44 #include "runtime/vframe.hpp"
  45 #include "runtime/vm_operations.hpp"
  46 #include "utilities/events.hpp"
  47 #include "utilities/globalDefinitions.hpp"
  48 
  49 CompilationPolicy* CompilationPolicy::_policy;
  50 elapsedTimer       CompilationPolicy::_accumulated_time;
  51 bool               CompilationPolicy::_in_vm_startup;
  52 
  53 // Determine compilation policy based on command line argument
  54 void compilationPolicy_init() {
  55   CompilationPolicy::set_in_vm_startup(DelayCompilationDuringStartup);
  56 
  57   switch(CompilationPolicyChoice) {
  58   case 0:
  59 #ifdef COMPILER1
  60     if (C1ProfileInlining) {
  61       CompilationPolicy::set_policy(new SimpleProfiledCompPolicy());
  62     } else {
  63 #endif
  64     CompilationPolicy::set_policy(new SimpleCompPolicy());
  65 #ifdef COMPILER1
  66     }
  67 #endif
  68     break;
  69 
  70   case 1:
  71 #ifdef COMPILER2
  72     CompilationPolicy::set_policy(new StackWalkCompPolicy());
  73 #else
  74     Unimplemented();
  75 #endif
  76     break;
  77   case 2:
  78 #ifdef TIERED
  79     CompilationPolicy::set_policy(new SimpleThresholdPolicy());
  80 #else
  81     Unimplemented();
  82 #endif
  83     break;
  84   case 3:
  85 #ifdef TIERED
  86     CompilationPolicy::set_policy(new AdvancedThresholdPolicy());
  87 #else


 411   if (is_compilation_enabled() && can_be_compiled(m)) {
 412     nmethod* nm = m->code();
 413     if (nm == NULL ) {
 414       const char* comment = "count";
 415       CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier,
 416                                     m, hot_count, comment, CHECK);
 417     }
 418   }
 419 }
 420 
 421 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) {
 422   int hot_count = m->backedge_count();
 423   const char* comment = "backedge_count";
 424 
 425   if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) {
 426     CompileBroker::compile_method(m, bci, CompLevel_highest_tier,
 427                                   m, hot_count, comment, CHECK);
 428     NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));)
 429   }
 430 }
 431 
 432 #ifdef COMPILER1
 433 bool SimpleProfiledCompPolicy::profile_overflow_event(JavaThread *thread, TRAPS) {
 434   RegisterMap map(thread, false);
 435   frame fr =  thread->last_frame().sender(&map);
 436   nmethod* nm = (nmethod*) fr.cb();
 437   assert(nm!= NULL && nm->is_nmethod(), "what?");
 438   ResourceMark rm;
 439   
 440   vframeStream vfst(thread);
 441   methodHandle mh = methodHandle(vfst.method());
 442   int bci = vfst.bci();
 443   
 444   bool fix_call = false;
 445   {
 446     nmethodLocker nml(nm);
 447     if (!nm->needs_recomp()) {
 448       CounterData* profile = mh->method_data()->bci_to_data(bci)->as_CounterData();
 449       bool warm;
 450       
 451       if (is_hot(C1ProfileCompileThreshold, profile->timestamp(), &warm)) {
 452         
 453         assert(mh->method_data() != NULL, "should have a mdo if we get here");
 454         nm->set_needs_recomp(true);
 455         methodHandle mh_recomp(nm->method());
 456         
 457         if (TraceC1ProfileInlining) {
 458           ttyLocker ttyl;
 459           tty->print("C1ProfileInlining: recompiling: ");
 460           mh_recomp->print_short_name(tty);
 461           tty->print(" because of ");
 462           mh->print_short_name(tty);
 463           tty->print_cr(" at bci = %d", bci);
 464         }
 465 
 466         const char* comment = "tier1 overflow";
 467         profile->set_hot();
 468         CompileBroker::compile_method(mh_recomp, InvocationEntryBci, CompLevel_highest_tier,
 469                                       mh_recomp, C1ProfileCompileThreshold, comment, CHECK_(true));
 470         fix_call = true;
 471       } else if (warm) {
 472         fix_call = true;
 473         profile->set_warm();
 474       } else {
 475         profile->set_cold();
 476       }
 477       if (!fix_call) {
 478         profile->set_count(0);
 479         profile->set_timestamp(os::javaTimeNanos());
 480       }
 481     } else {
 482       fix_call = true;
 483     }
 484   }
 485   return fix_call;
 486 }
 487 #endif
 488 
 489 
 490 // StackWalkCompPolicy - walk up stack to find a suitable method to compile
 491 
 492 #ifdef COMPILER2
 493 const char* StackWalkCompPolicy::_msg = NULL;
 494 
 495 
 496 // Consider m for compilation
 497 void StackWalkCompPolicy::method_invocation_event(methodHandle m, TRAPS) {
 498   int hot_count = m->invocation_count();
 499   reset_counter_for_invocation_event(m);
 500   const char* comment = "count";
 501 
 502   if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) {
 503     ResourceMark rm(THREAD);
 504     JavaThread *thread = (JavaThread*)THREAD;
 505     frame       fr     = thread->last_frame();
 506     assert(fr.is_interpreted_frame(), "must be interpreted");
 507     assert(fr.interpreter_frame_method() == m(), "bad method");
 508 
 509     if (TraceCompilationPolicy) {