src/share/vm/runtime/simpleThresholdPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File tiered-osr-logic-fix Sdiff src/share/vm/runtime

src/share/vm/runtime/simpleThresholdPolicy.cpp

Print this page




 189 
 190   if (PrintTieredEvents) {
 191     print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
 192   }
 193 
 194   if (bci == InvocationEntryBci) {
 195     method_invocation_event(method, inlinee, comp_level, nm, THREAD);
 196   } else {
 197     method_back_branch_event(method, inlinee, bci, comp_level, nm, THREAD);
 198     // method == inlinee if the event originated in the main method
 199     int highest_level = inlinee->highest_osr_comp_level();
 200     if (highest_level > comp_level) {
 201       osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
 202     }
 203   }
 204   return osr_nm;
 205 }
 206 
 207 // Check if the method can be compiled, change level if necessary
 208 void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
 209   // Take the given ceiling into the account.
 210   // NOTE: You can set it to 1 to get a pure C1 version.
 211   if ((CompLevel)TieredStopAtLevel < level) {
 212     level = (CompLevel)TieredStopAtLevel;
 213   }
 214   if (level == CompLevel_none) {
 215     return;
 216   }
 217   // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
 218   // in the interpreter and then compile with C2 (the transition function will request that,
 219   // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
 220   // pure C1.
 221   if (!can_be_compiled(mh, level)) {
 222     if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
 223         compile(mh, bci, CompLevel_simple, THREAD);
 224     }
 225     return;
 226   }
 227   if (bci != InvocationEntryBci && mh->is_not_osr_compilable()) {
 228     return;
 229   }

 230   if (PrintTieredEvents) {
 231     print_event(COMPILE, mh, mh, bci, level);
 232   }
 233   if (!CompileBroker::compilation_is_in_queue(mh, bci)) {
 234     submit_compile(mh, bci, level, THREAD);
 235   }
 236 }
 237 
 238 // Tell the broker to compile the method
 239 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
 240   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 241   CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", THREAD);
 242 }
 243 
 244 // Call and loop predicates determine whether a transition to a higher
 245 // compilation level should be performed (pointers to predicate functions
 246 // are passed to common() transition function).
 247 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
 248   switch(cur_level) {
 249   case CompLevel_none:
 250   case CompLevel_limited_profile: {
 251     return loop_predicate_helper<CompLevel_none>(i, b, 1.0);
 252   }
 253   case CompLevel_full_profile: {


 271     return true;
 272   }
 273 }
 274 
 275 // Determine is a method is mature.
 276 bool SimpleThresholdPolicy::is_mature(methodOop method) {
 277   if (is_trivial(method)) return true;
 278   methodDataOop mdo = method->method_data();
 279   if (mdo != NULL) {
 280     int i = mdo->invocation_count();
 281     int b = mdo->backedge_count();
 282     double k = ProfileMaturityPercentage / 100.0;
 283     return call_predicate_helper<CompLevel_full_profile>(i, b, k) ||
 284            loop_predicate_helper<CompLevel_full_profile>(i, b, k);
 285   }
 286   return false;
 287 }
 288 
 289 // Common transition function. Given a predicate determines if a method should transition to another level.
 290 CompLevel SimpleThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
 291   if (is_trivial(method)) return CompLevel_simple;
 292 
 293   CompLevel next_level = cur_level;
 294   int i = method->invocation_count();
 295   int b = method->backedge_count();
 296 



 297   switch(cur_level) {
 298   case CompLevel_none:
 299     // If we were at full profile level, would we switch to full opt?
 300     if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
 301       next_level = CompLevel_full_optimization;
 302     } else if ((this->*p)(i, b, cur_level)) {
 303       next_level = CompLevel_full_profile;
 304     }
 305     break;
 306   case CompLevel_limited_profile:
 307   case CompLevel_full_profile:
 308     {
 309       methodDataOop mdo = method->method_data();
 310       if (mdo != NULL) {
 311         if (mdo->would_profile()) {
 312           int mdo_i = mdo->invocation_count_delta();
 313           int mdo_b = mdo->backedge_count_delta();
 314           if ((this->*p)(mdo_i, mdo_b, cur_level)) {
 315             next_level = CompLevel_full_optimization;
 316           }
 317         } else {
 318           next_level = CompLevel_full_optimization;
 319         }
 320       }
 321     }
 322     break;
 323   }
 324   return next_level;

 325 }
 326 
 327 // Determine if a method should be compiled with a normal entry point at a different level.
 328 CompLevel SimpleThresholdPolicy::call_event(methodOop method,  CompLevel cur_level) {
 329   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 330                              common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
 331   CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
 332 
 333   // If OSR method level is greater than the regular method level, the levels should be
 334   // equalized by raising the regular method level in order to avoid OSRs during each
 335   // invocation of the method.
 336   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 337     methodDataOop mdo = method->method_data();
 338     guarantee(mdo != NULL, "MDO should not be NULL");
 339     if (mdo->invocation_count() >= 1) {
 340       next_level = CompLevel_full_optimization;
 341     }
 342   } else {
 343     next_level = MAX2(osr_level, next_level);
 344   }




 189 
 190   if (PrintTieredEvents) {
 191     print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
 192   }
 193 
 194   if (bci == InvocationEntryBci) {
 195     method_invocation_event(method, inlinee, comp_level, nm, THREAD);
 196   } else {
 197     method_back_branch_event(method, inlinee, bci, comp_level, nm, THREAD);
 198     // method == inlinee if the event originated in the main method
 199     int highest_level = inlinee->highest_osr_comp_level();
 200     if (highest_level > comp_level) {
 201       osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
 202     }
 203   }
 204   return osr_nm;
 205 }
 206 
 207 // Check if the method can be compiled, change level if necessary
 208 void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
 209   assert(level <= TieredStopAtLevel, "Invalid compilation level");




 210   if (level == CompLevel_none) {
 211     return;
 212   }
 213   // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
 214   // in the interpreter and then compile with C2 (the transition function will request that,
 215   // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
 216   // pure C1.
 217   if (!can_be_compiled(mh, level)) {
 218     if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
 219         compile(mh, bci, CompLevel_simple, THREAD);
 220     }
 221     return;
 222   }
 223   if (bci != InvocationEntryBci && mh->is_not_osr_compilable()) {
 224     return;
 225   }
 226   if (!CompileBroker::compilation_is_in_queue(mh, bci)) {
 227     if (PrintTieredEvents) {
 228       print_event(COMPILE, mh, mh, bci, level);
 229     }

 230     submit_compile(mh, bci, level, THREAD);
 231   }
 232 }
 233 
 234 // Tell the broker to compile the method
 235 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
 236   int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
 237   CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", THREAD);
 238 }
 239 
 240 // Call and loop predicates determine whether a transition to a higher
 241 // compilation level should be performed (pointers to predicate functions
 242 // are passed to common() transition function).
 243 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
 244   switch(cur_level) {
 245   case CompLevel_none:
 246   case CompLevel_limited_profile: {
 247     return loop_predicate_helper<CompLevel_none>(i, b, 1.0);
 248   }
 249   case CompLevel_full_profile: {


 267     return true;
 268   }
 269 }
 270 
 271 // Determine is a method is mature.
 272 bool SimpleThresholdPolicy::is_mature(methodOop method) {
 273   if (is_trivial(method)) return true;
 274   methodDataOop mdo = method->method_data();
 275   if (mdo != NULL) {
 276     int i = mdo->invocation_count();
 277     int b = mdo->backedge_count();
 278     double k = ProfileMaturityPercentage / 100.0;
 279     return call_predicate_helper<CompLevel_full_profile>(i, b, k) ||
 280            loop_predicate_helper<CompLevel_full_profile>(i, b, k);
 281   }
 282   return false;
 283 }
 284 
 285 // Common transition function. Given a predicate determines if a method should transition to another level.
 286 CompLevel SimpleThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {


 287   CompLevel next_level = cur_level;
 288   int i = method->invocation_count();
 289   int b = method->backedge_count();
 290 
 291   if (is_trivial(method)) {
 292     next_level = CompLevel_simple;
 293   } else {
 294     switch(cur_level) {
 295     case CompLevel_none:
 296       // If we were at full profile level, would we switch to full opt?
 297       if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
 298         next_level = CompLevel_full_optimization;
 299       } else if ((this->*p)(i, b, cur_level)) {
 300         next_level = CompLevel_full_profile;
 301       }
 302       break;
 303     case CompLevel_limited_profile:
 304     case CompLevel_full_profile:
 305       {
 306         methodDataOop mdo = method->method_data();
 307         if (mdo != NULL) {
 308           if (mdo->would_profile()) {
 309             int mdo_i = mdo->invocation_count_delta();
 310             int mdo_b = mdo->backedge_count_delta();
 311             if ((this->*p)(mdo_i, mdo_b, cur_level)) {
 312               next_level = CompLevel_full_optimization;
 313             }
 314           } else {
 315             next_level = CompLevel_full_optimization;
 316           }
 317         }
 318       }
 319       break;
 320     }
 321   }
 322   return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 323 }
 324 
 325 // Determine if a method should be compiled with a normal entry point at a different level.
 326 CompLevel SimpleThresholdPolicy::call_event(methodOop method,  CompLevel cur_level) {
 327   CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 328                              common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
 329   CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
 330 
 331   // If OSR method level is greater than the regular method level, the levels should be
 332   // equalized by raising the regular method level in order to avoid OSRs during each
 333   // invocation of the method.
 334   if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 335     methodDataOop mdo = method->method_data();
 336     guarantee(mdo != NULL, "MDO should not be NULL");
 337     if (mdo->invocation_count() >= 1) {
 338       next_level = CompLevel_full_optimization;
 339     }
 340   } else {
 341     next_level = MAX2(osr_level, next_level);
 342   }


src/share/vm/runtime/simpleThresholdPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File