Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/runtime/advancedThresholdPolicy.cpp
          +++ new/src/share/vm/runtime/advancedThresholdPolicy.cpp
↓ open down ↓ 181 lines elided ↑ open up ↑
 182  182  
 183  183        // Select a method with a higher rate
 184  184        if (compare_methods(method, max_method)) {
 185  185          max_task = task;
 186  186          max_method = method;
 187  187        }
 188  188      }
 189  189      task = next_task;
 190  190    }
 191  191  
 192      -  if (max_task->comp_level() == CompLevel_full_profile && is_method_profiled(max_method)) {
      192 +  if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
      193 +      && is_method_profiled(max_method)) {
 193  194      max_task->set_comp_level(CompLevel_limited_profile);
 194  195      if (PrintTieredEvents) {
 195  196        print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 196  197      }
 197  198    }
 198  199  
 199  200    return max_task;
 200  201  }
 201  202  
 202  203  double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
↓ open down ↓ 111 lines elided ↑ open up ↑
 314  315   *    This can happen if a method fails C1 compilation (it will still be profiled in the interpreter)
 315  316   *    or because of a deopt that didn't require reprofiling (compilation won't happen in this case because
 316  317   *    the compiled version already exists).
 317  318   *
 318  319   * Note that since state 0 can be reached from any other state via deoptimization different loops
 319  320   * are possible.
 320  321   *
 321  322   */
 322  323  
 323  324  // Common transition function. Given a predicate determines if a method should transition to another level.
 324      -CompLevel AdvancedThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
 325      -  if (is_trivial(method)) return CompLevel_simple;
 326      -
      325 +CompLevel AdvancedThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level, bool disable_feedback) {
 327  326    CompLevel next_level = cur_level;
 328  327    int i = method->invocation_count();
 329  328    int b = method->backedge_count();
 330  329  
 331      -  switch(cur_level) {
 332      -  case CompLevel_none:
 333      -    // If we were at full profile level, would we switch to full opt?
 334      -    if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
 335      -      next_level = CompLevel_full_optimization;
 336      -    } else if ((this->*p)(i, b, cur_level)) {
 337      -      // C1-generated fully profiled code is about 30% slower than the limited profile
 338      -      // code that has only invocation and backedge counters. The observation is that
 339      -      // if C2 queue is large enough we can spend too much time in the fully profiled code
 340      -      // while waiting for C2 to pick the method from the queue. To alleviate this problem
 341      -      // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
 342      -      // we choose to compile a limited profiled version and then recompile with full profiling
 343      -      // when the load on C2 goes down.
 344      -      if (CompileBroker::queue_size(CompLevel_full_optimization) >
 345      -          Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
 346      -        next_level = CompLevel_limited_profile;
 347      -      } else {
 348      -        next_level = CompLevel_full_profile;
      330 +  if (is_trivial(method)) {
      331 +    next_level = CompLevel_simple;
      332 +  } else {
      333 +    switch(cur_level) {
      334 +    case CompLevel_none:
      335 +      // If we were at full profile level, would we switch to full opt?
      336 +      if (common(p, method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) {
      337 +        next_level = CompLevel_full_optimization;
      338 +      } else if ((this->*p)(i, b, cur_level)) {
      339 +        // C1-generated fully profiled code is about 30% slower than the limited profile
      340 +        // code that has only invocation and backedge counters. The observation is that
      341 +        // if C2 queue is large enough we can spend too much time in the fully profiled code
      342 +        // while waiting for C2 to pick the method from the queue. To alleviate this problem
      343 +        // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
      344 +        // we choose to compile a limited profiled version and then recompile with full profiling
      345 +        // when the load on C2 goes down.
      346 +        if (!disable_feedback && CompileBroker::queue_size(CompLevel_full_optimization) >
      347 +                                 Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
      348 +          next_level = CompLevel_limited_profile;
      349 +        } else {
      350 +          next_level = CompLevel_full_profile;
      351 +        }
 349  352        }
 350      -    }
 351      -    break;
 352      -  case CompLevel_limited_profile:
 353      -    if (is_method_profiled(method)) {
 354      -      // Special case: we got here because this method was fully profiled in the interpreter.
 355      -      next_level = CompLevel_full_optimization;
 356      -    } else {
 357      -      methodDataOop mdo = method->method_data();
 358      -      if (mdo != NULL) {
 359      -        if (mdo->would_profile()) {
 360      -          if (CompileBroker::queue_size(CompLevel_full_optimization) <=
 361      -              Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
 362      -              (this->*p)(i, b, cur_level)) {
 363      -            next_level = CompLevel_full_profile;
      353 +      break;
      354 +    case CompLevel_limited_profile:
      355 +      if (is_method_profiled(method)) {
      356 +        // Special case: we got here because this method was fully profiled in the interpreter.
      357 +        next_level = CompLevel_full_optimization;
      358 +      } else {
      359 +        methodDataOop mdo = method->method_data();
      360 +        if (mdo != NULL) {
      361 +          if (mdo->would_profile()) {
      362 +            if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
      363 +                                     Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
      364 +                                     (this->*p)(i, b, cur_level))) {
      365 +              next_level = CompLevel_full_profile;
      366 +            }
      367 +          } else {
      368 +            next_level = CompLevel_full_optimization;
 364  369            }
 365      -        } else {
 366      -          next_level = CompLevel_full_optimization;
 367  370          }
 368  371        }
 369      -    }
 370      -    break;
 371      -  case CompLevel_full_profile:
 372      -    {
 373      -      methodDataOop mdo = method->method_data();
 374      -      if (mdo != NULL) {
 375      -        if (mdo->would_profile()) {
 376      -          int mdo_i = mdo->invocation_count_delta();
 377      -          int mdo_b = mdo->backedge_count_delta();
 378      -          if ((this->*p)(mdo_i, mdo_b, cur_level)) {
      372 +      break;
      373 +    case CompLevel_full_profile:
      374 +      {
      375 +        methodDataOop mdo = method->method_data();
      376 +        if (mdo != NULL) {
      377 +          if (mdo->would_profile()) {
      378 +            int mdo_i = mdo->invocation_count_delta();
      379 +            int mdo_b = mdo->backedge_count_delta();
      380 +            if ((this->*p)(mdo_i, mdo_b, cur_level)) {
      381 +              next_level = CompLevel_full_optimization;
      382 +            }
      383 +          } else {
 379  384              next_level = CompLevel_full_optimization;
 380  385            }
 381      -        } else {
 382      -          next_level = CompLevel_full_optimization;
 383  386          }
 384  387        }
      388 +      break;
 385  389      }
 386      -    break;
 387  390    }
 388      -  return next_level;
      391 +  return MIN2(next_level, (CompLevel)TieredStopAtLevel);
 389  392  }
 390  393  
 391  394  // Determine if a method should be compiled with a normal entry point at a different level.
 392  395  CompLevel AdvancedThresholdPolicy::call_event(methodOop method, CompLevel cur_level) {
 393  396    CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
 394      -                             common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level));
      397 +                             common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
 395  398    CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
 396  399  
 397  400    // If OSR method level is greater than the regular method level, the levels should be
 398  401    // equalized by raising the regular method level in order to avoid OSRs during each
 399  402    // invocation of the method.
 400  403    if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
 401  404      methodDataOop mdo = method->method_data();
 402  405      guarantee(mdo != NULL, "MDO should not be NULL");
 403  406      if (mdo->invocation_count() >= 1) {
 404  407        next_level = CompLevel_full_optimization;
 405  408      }
 406  409    } else {
 407  410      next_level = MAX2(osr_level, next_level);
 408  411    }
 409      -
 410  412    return next_level;
 411  413  }
 412  414  
 413  415  // Determine if we should do an OSR compilation of a given method.
 414  416  CompLevel AdvancedThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) {
 415      -  CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level);
      417 +  CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
 416  418    if (cur_level == CompLevel_none) {
 417  419      // If there is a live OSR method that means that we deopted to the interpreter
 418  420      // for the transition.
 419  421      CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
 420  422      if (osr_level > CompLevel_none) {
 421  423        return osr_level;
 422  424      }
 423  425    }
 424  426    return next_level;
 425  427  }
↓ open down ↓ 27 lines elided ↑ open up ↑
 453  455      create_mdo(mh, THREAD);
 454  456    }
 455  457    // Check if MDO should be created for the inlined method
 456  458    if (should_create_mdo(imh(), level)) {
 457  459      create_mdo(imh, THREAD);
 458  460    }
 459  461  
 460  462    if (is_compilation_enabled()) {
 461  463      CompLevel next_osr_level = loop_event(imh(), level);
 462  464      CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
 463      -    if (next_osr_level  == CompLevel_limited_profile) {
 464      -      next_osr_level = CompLevel_full_profile; // OSRs are supposed to be for very hot methods.
 465      -    }
 466      -
 467  465      // At the very least compile the OSR version
 468      -    if (!CompileBroker::compilation_is_in_queue(imh, bci)) {
 469      -      // Check if there's a method like that already
 470      -      nmethod* osr_nm = NULL;
 471      -      if (max_osr_level >= next_osr_level) {
 472      -        // There is an osr method already with the same
 473      -        // or greater level, check if it has the bci we need
 474      -        osr_nm = imh->lookup_osr_nmethod_for(bci, next_osr_level, false);
 475      -      }
 476      -      if (osr_nm == NULL) {
 477      -        compile(imh, bci, next_osr_level, THREAD);
 478      -      }
      466 +    if (!CompileBroker::compilation_is_in_queue(imh, bci) && next_osr_level != level) {
      467 +      compile(imh, bci, next_osr_level, THREAD);
 479  468      }
 480  469  
 481  470      // Use loop event as an opportunity to also check if there's been
 482  471      // enough calls.
 483  472      CompLevel cur_level, next_level;
 484  473      if (mh() != imh()) { // If there is an enclosing method
 485  474        guarantee(nm != NULL, "Should have nmethod here");
 486  475        cur_level = comp_level(mh());
 487  476        next_level = call_event(mh(), cur_level);
 488  477  
↓ open down ↓ 42 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX