src/share/vm/opto/bytecodeInfo.cpp

changeset 4660
133bf557ef77
parent 4532
60bba1398c51
child 4772
80208f353616
     1.1 --- a/src/share/vm/opto/bytecodeInfo.cpp	Mon Feb 18 16:47:15 2013 -0800
     1.2 +++ b/src/share/vm/opto/bytecodeInfo.cpp	Wed Feb 27 05:58:48 2013 -0800
     1.3 @@ -47,7 +47,8 @@
     1.4    _site_invoke_ratio(site_invoke_ratio),
     1.5    _max_inline_level(max_inline_level),
     1.6    _count_inline_bcs(method()->code_size_for_inlining()),
     1.7 -  _subtrees(c->comp_arena(), 2, 0, NULL)
     1.8 +  _subtrees(c->comp_arena(), 2, 0, NULL),
     1.9 +  _msg(NULL)
    1.10  {
    1.11    NOT_PRODUCT(_count_inlines = 0;)
    1.12    if (_caller_jvms != NULL) {
    1.13 @@ -77,7 +78,8 @@
    1.14    _method(callee_method),
    1.15    _site_invoke_ratio(site_invoke_ratio),
    1.16    _max_inline_level(max_inline_level),
    1.17 -  _count_inline_bcs(method()->code_size())
    1.18 +  _count_inline_bcs(method()->code_size()),
    1.19 +  _msg(NULL)
    1.20  {
    1.21    NOT_PRODUCT(_count_inlines = 0;)
    1.22    assert(!UseOldInlining, "do not use for old stuff");
    1.23 @@ -95,8 +97,10 @@
    1.24           );
    1.25  }
    1.26  
    1.27 -// positive filter: should callee be inlined?  returns NULL, if yes, or rejection msg
    1.28 -const char* InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result) const {
    1.29 +// positive filter: should callee be inlined?
    1.30 +bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
    1.31 +                               int caller_bci, ciCallProfile& profile,
    1.32 +                               WarmCallInfo* wci_result) {
    1.33    // Allows targeted inlining
    1.34    if(callee_method->should_inline()) {
    1.35      *wci_result = *(WarmCallInfo::always_hot());
    1.36 @@ -104,11 +108,10 @@
    1.37        CompileTask::print_inline_indent(inline_level());
    1.38        tty->print_cr("Inlined method is hot: ");
    1.39      }
    1.40 -    return NULL;
    1.41 +    set_msg("force inline by CompilerOracle");
    1.42 +    return true;
    1.43    }
    1.44  
    1.45 -  // positive filter: should send be inlined?  returns NULL (--> yes)
    1.46 -  // or rejection msg
    1.47    int size = callee_method->code_size_for_inlining();
    1.48  
    1.49    // Check for too many throws (and not too huge)
    1.50 @@ -119,11 +122,13 @@
    1.51        CompileTask::print_inline_indent(inline_level());
    1.52        tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
    1.53      }
    1.54 -    return NULL;
    1.55 +    set_msg("many throws");
    1.56 +    return true;
    1.57    }
    1.58  
    1.59    if (!UseOldInlining) {
    1.60 -    return NULL;  // size and frequency are represented in a new way
    1.61 +    set_msg("!UseOldInlining");
    1.62 +    return true;  // size and frequency are represented in a new way
    1.63    }
    1.64  
    1.65    int default_max_inline_size = C->max_inline_size();
    1.66 @@ -153,31 +158,44 @@
    1.67      // Not hot.  Check for medium-sized pre-existing nmethod at cold sites.
    1.68      if (callee_method->has_compiled_code() &&
    1.69          callee_method->instructions_size() > inline_small_code_size)
    1.70 -      return "already compiled into a medium method";
    1.71 +      set_msg("already compiled into a medium method");
    1.72 +      return false;
    1.73    }
    1.74    if (size > max_inline_size) {
    1.75 -    if (max_inline_size > default_max_inline_size)
    1.76 -      return "hot method too big";
    1.77 -    return "too big";
    1.78 +    if (max_inline_size > default_max_inline_size) {
    1.79 +      set_msg("hot method too big");
    1.80 +    } else {
    1.81 +      set_msg("too big");
    1.82 +    }
    1.83 +    return false;
    1.84    }
    1.85 -  return NULL;
    1.86 +  return true;
    1.87  }
    1.88  
    1.89  
    1.90 -// negative filter: should callee NOT be inlined?  returns NULL, ok to inline, or rejection msg
    1.91 -const char* InlineTree::should_not_inline(ciMethod *callee_method, ciMethod* caller_method, WarmCallInfo* wci_result) const {
    1.92 -  // negative filter: should send NOT be inlined?  returns NULL (--> inline) or rejection msg
    1.93 +// negative filter: should callee NOT be inlined?
    1.94 +bool InlineTree::should_not_inline(ciMethod *callee_method,
    1.95 +                                   ciMethod* caller_method,
    1.96 +                                   WarmCallInfo* wci_result) {
    1.97 +
    1.98 +  const char* fail_msg = NULL;
    1.99 +
   1.100 +  // First check all inlining restrictions which are required for correctness
   1.101 +  if ( callee_method->is_abstract()) {
   1.102 +    fail_msg = "abstract method"; // // note: we allow ik->is_abstract()
   1.103 +  } else if (!callee_method->holder()->is_initialized()) {
   1.104 +    fail_msg = "method holder not initialized";
   1.105 +  } else if ( callee_method->is_native()) {
   1.106 +    fail_msg = "native method";
   1.107 +  } else if ( callee_method->dont_inline()) {
   1.108 +    fail_msg = "don't inline by annotation";
   1.109 +  }
   1.110 +
   1.111    if (!UseOldInlining) {
   1.112 -    const char* fail = NULL;
   1.113 -    if ( callee_method->is_abstract())               fail = "abstract method";
   1.114 -    // note: we allow ik->is_abstract()
   1.115 -    if (!callee_method->holder()->is_initialized())  fail = "method holder not initialized";
   1.116 -    if ( callee_method->is_native())                 fail = "native method";
   1.117 -    if ( callee_method->dont_inline())               fail = "don't inline by annotation";
   1.118 -
   1.119 -    if (fail) {
   1.120 +    if (fail_msg != NULL) {
   1.121        *wci_result = *(WarmCallInfo::always_cold());
   1.122 -      return fail;
   1.123 +      set_msg(fail_msg);
   1.124 +      return true;
   1.125      }
   1.126  
   1.127      if (callee_method->has_unloaded_classes_in_signature()) {
   1.128 @@ -199,20 +217,23 @@
   1.129        // %%% adjust wci_result->size()?
   1.130      }
   1.131  
   1.132 -    return NULL;
   1.133 +    return false;
   1.134    }
   1.135  
   1.136 -  // First check all inlining restrictions which are required for correctness
   1.137 -  if ( callee_method->is_abstract())                        return "abstract method";
   1.138 -  // note: we allow ik->is_abstract()
   1.139 -  if (!callee_method->holder()->is_initialized())           return "method holder not initialized";
   1.140 -  if ( callee_method->is_native())                          return "native method";
   1.141 -  if ( callee_method->dont_inline())                        return "don't inline by annotation";
   1.142 -  if ( callee_method->has_unloaded_classes_in_signature())  return "unloaded signature classes";
   1.143 +  // one more inlining restriction
   1.144 +  if (fail_msg == NULL && callee_method->has_unloaded_classes_in_signature()) {
   1.145 +    fail_msg = "unloaded signature classes";
   1.146 +  }
   1.147  
   1.148 +  if (fail_msg != NULL) {
   1.149 +    set_msg(fail_msg);
   1.150 +    return true;
   1.151 +  }
   1.152 +
   1.153 +  // ignore heuristic controls on inlining
   1.154    if (callee_method->should_inline()) {
   1.155 -    // ignore heuristic controls on inlining
   1.156 -    return NULL;
   1.157 +    set_msg("force inline by CompilerOracle");
   1.158 +    return false;
   1.159    }
   1.160  
   1.161    // Now perform checks which are heuristic
   1.162 @@ -220,7 +241,8 @@
   1.163    if (!callee_method->force_inline()) {
   1.164      if (callee_method->has_compiled_code() &&
   1.165          callee_method->instructions_size() > InlineSmallCode) {
   1.166 -    return "already compiled into a big method";
   1.167 +      set_msg("already compiled into a big method");
   1.168 +      return true;
   1.169      }
   1.170    }
   1.171  
   1.172 @@ -231,17 +253,21 @@
   1.173      const InlineTree *top = this;
   1.174      while (top->caller_tree() != NULL) top = top->caller_tree();
   1.175      ciInstanceKlass* k = top->method()->holder();
   1.176 -    if (!k->is_subclass_of(C->env()->Throwable_klass()))
   1.177 -      return "exception method";
   1.178 +    if (!k->is_subclass_of(C->env()->Throwable_klass())) {
   1.179 +      set_msg("exception method");
   1.180 +      return true;
   1.181 +    }
   1.182    }
   1.183  
   1.184    if (callee_method->should_not_inline()) {
   1.185 -    return "disallowed by CompilerOracle";
   1.186 +    set_msg("disallowed by CompilerOracle");
   1.187 +    return true;
   1.188    }
   1.189  
   1.190  #ifndef PRODUCT
   1.191    if (ciReplay::should_not_inline(callee_method)) {
   1.192 -    return "disallowed by ciReplay";
   1.193 +    set_msg("disallowed by ciReplay");
   1.194 +    return true;
   1.195    }
   1.196  #endif
   1.197  
   1.198 @@ -249,19 +275,23 @@
   1.199      // Do not inline StringCache::profile() method used only at the beginning.
   1.200      if (callee_method->name() == ciSymbol::profile_name() &&
   1.201          callee_method->holder()->name() == ciSymbol::java_lang_StringCache()) {
   1.202 -      return "profiling method";
   1.203 +      set_msg("profiling method");
   1.204 +      return true;
   1.205      }
   1.206    }
   1.207  
   1.208    // use frequency-based objections only for non-trivial methods
   1.209 -  if (callee_method->code_size() <= MaxTrivialSize) return NULL;
   1.210 +  if (callee_method->code_size() <= MaxTrivialSize) {
   1.211 +    return false;
   1.212 +  }
   1.213  
   1.214    // don't use counts with -Xcomp or CTW
   1.215    if (UseInterpreter && !CompileTheWorld) {
   1.216  
   1.217      if (!callee_method->has_compiled_code() &&
   1.218          !callee_method->was_executed_more_than(0)) {
   1.219 -      return "never executed";
   1.220 +      set_msg("never executed");
   1.221 +      return true;
   1.222      }
   1.223  
   1.224      if (is_init_with_ea(callee_method, caller_method, C)) {
   1.225 @@ -270,39 +300,44 @@
   1.226  
   1.227      } else if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold,
   1.228                                                             CompileThreshold >> 1))) {
   1.229 -      return "executed < MinInliningThreshold times";
   1.230 +      set_msg("executed < MinInliningThreshold times");
   1.231 +      return true;
   1.232      }
   1.233    }
   1.234  
   1.235 -  return NULL;
   1.236 +  return false;
   1.237  }
   1.238  
   1.239  //-----------------------------try_to_inline-----------------------------------
   1.240 -// return NULL if ok, reason for not inlining otherwise
   1.241 +// return true if ok
   1.242  // Relocated from "InliningClosure::try_to_inline"
   1.243 -const char* InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result, bool& should_delay) {
   1.244 -  // Old algorithm had funny accumulating BC-size counters
   1.245 +bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
   1.246 +                               int caller_bci, ciCallProfile& profile,
   1.247 +                               WarmCallInfo* wci_result, bool& should_delay) {
   1.248 +
   1.249 +   // Old algorithm had funny accumulating BC-size counters
   1.250    if (UseOldInlining && ClipInlining
   1.251        && (int)count_inline_bcs() >= DesiredMethodLimit) {
   1.252      if (!callee_method->force_inline() || !IncrementalInline) {
   1.253 -      return "size > DesiredMethodLimit";
   1.254 +      set_msg("size > DesiredMethodLimit");
   1.255 +      return false;
   1.256      } else if (!C->inlining_incrementally()) {
   1.257        should_delay = true;
   1.258      }
   1.259    }
   1.260  
   1.261 -  const char *msg = NULL;
   1.262 -  msg = should_inline(callee_method, caller_method, caller_bci, profile, wci_result);
   1.263 -  if (msg != NULL)
   1.264 -    return msg;
   1.265 -
   1.266 -  msg = should_not_inline(callee_method, caller_method, wci_result);
   1.267 -  if (msg != NULL)
   1.268 -    return msg;
   1.269 +  if (!should_inline(callee_method, caller_method, caller_bci, profile,
   1.270 +                     wci_result)) {
   1.271 +    return false;
   1.272 +  }
   1.273 +  if (should_not_inline(callee_method, caller_method, wci_result)) {
   1.274 +    return false;
   1.275 +  }
   1.276  
   1.277    if (InlineAccessors && callee_method->is_accessor()) {
   1.278      // accessor methods are not subject to any of the following limits.
   1.279 -    return NULL;
   1.280 +    set_msg("accessor");
   1.281 +    return true;
   1.282    }
   1.283  
   1.284    // suppress a few checks for accessors and trivial methods
   1.285 @@ -312,7 +347,8 @@
   1.286      if (C->over_inlining_cutoff()) {
   1.287        if ((!callee_method->force_inline() && !caller_method->is_compiled_lambda_form())
   1.288            || !IncrementalInline) {
   1.289 -        return "NodeCountInliningCutoff";
   1.290 +        set_msg("NodeCountInliningCutoff");
   1.291 +        return false;
   1.292        } else {
   1.293          should_delay = true;
   1.294        }
   1.295 @@ -326,16 +362,19 @@
   1.296  
   1.297      } else if (profile.count() == 0) {
   1.298        // don't inline unreached call sites
   1.299 -      return "call site not reached";
   1.300 +       set_msg("call site not reached");
   1.301 +       return false;
   1.302      }
   1.303    }
   1.304  
   1.305    if (!C->do_inlining() && InlineAccessors) {
   1.306 -    return "not an accessor";
   1.307 +    set_msg("not an accessor");
   1.308 +    return false;
   1.309    }
   1.310    if (inline_level() > _max_inline_level) {
   1.311      if (!callee_method->force_inline() || !IncrementalInline) {
   1.312 -      return "inlining too deep";
   1.313 +      set_msg("inlining too deep");
   1.314 +      return false;
   1.315      } else if (!C->inlining_incrementally()) {
   1.316        should_delay = true;
   1.317      }
   1.318 @@ -345,15 +384,19 @@
   1.319    if (!callee_method->is_compiled_lambda_form()) {
   1.320      // count the current method and the callee
   1.321      int inline_level = (method() == callee_method) ? 1 : 0;
   1.322 -    if (inline_level > MaxRecursiveInlineLevel)
   1.323 -      return "recursively inlining too deep";
   1.324 +    if (inline_level > MaxRecursiveInlineLevel) {
   1.325 +      set_msg("recursively inlining too deep");
   1.326 +      return false;
   1.327 +    }
   1.328      // count callers of current method and callee
   1.329      JVMState* jvms = caller_jvms();
   1.330      while (jvms != NULL && jvms->has_method()) {
   1.331        if (jvms->method() == callee_method) {
   1.332          inline_level++;
   1.333 -        if (inline_level > MaxRecursiveInlineLevel)
   1.334 -          return "recursively inlining too deep";
   1.335 +        if (inline_level > MaxRecursiveInlineLevel) {
   1.336 +          set_msg("recursively inlining too deep");
   1.337 +          return false;
   1.338 +        }
   1.339        }
   1.340        jvms = jvms->caller();
   1.341      }
   1.342 @@ -364,14 +407,15 @@
   1.343    if (UseOldInlining && ClipInlining
   1.344        && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
   1.345      if (!callee_method->force_inline() || !IncrementalInline) {
   1.346 -      return "size > DesiredMethodLimit";
   1.347 +      set_msg("size > DesiredMethodLimit");
   1.348 +      return false;
   1.349      } else if (!C->inlining_incrementally()) {
   1.350        should_delay = true;
   1.351      }
   1.352    }
   1.353  
   1.354    // ok, inline this method
   1.355 -  return NULL;
   1.356 +  return true;
   1.357  }
   1.358  
   1.359  //------------------------------pass_initial_checks----------------------------
   1.360 @@ -421,17 +465,18 @@
   1.361  
   1.362  //------------------------------print_inlining---------------------------------
   1.363  void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci,
   1.364 -                                const char* msg, bool success) const {
   1.365 -  assert(msg != NULL, "just checking");
   1.366 +                                bool success) const {
   1.367 +  const char* inline_msg = msg();
   1.368 +  assert(inline_msg != NULL, "just checking");
   1.369    if (C->log() != NULL) {
   1.370      if (success) {
   1.371 -      C->log()->inline_success(msg);
   1.372 +      C->log()->inline_success(inline_msg);
   1.373      } else {
   1.374 -      C->log()->inline_fail(msg);
   1.375 +      C->log()->inline_fail(inline_msg);
   1.376      }
   1.377    }
   1.378    if (PrintInlining) {
   1.379 -    C->print_inlining(callee_method, inline_level(), caller_bci, msg);
   1.380 +    C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
   1.381      if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
   1.382      if (Verbose && callee_method) {
   1.383        const InlineTree *top = this;
   1.384 @@ -455,49 +500,51 @@
   1.385    }
   1.386    assert(_method == jvms->method(), "redundant instance state");
   1.387  #endif
   1.388 -  const char *failure_msg   = NULL;
   1.389    int         caller_bci    = jvms->bci();
   1.390 -  ciMethod   *caller_method = jvms->method();
   1.391 +  ciMethod*   caller_method = jvms->method();
   1.392  
   1.393    // Do some initial checks.
   1.394    if (!pass_initial_checks(caller_method, caller_bci, callee_method)) {
   1.395 -    print_inlining(callee_method, caller_bci, "failed initial checks",
   1.396 -                   false /* !success */);
   1.397 +    set_msg("failed initial checks");
   1.398 +    print_inlining(callee_method, caller_bci, false /* !success */);
   1.399      return NULL;
   1.400    }
   1.401  
   1.402    // Do some parse checks.
   1.403 -  failure_msg = check_can_parse(callee_method);
   1.404 -  if (failure_msg != NULL) {
   1.405 -    print_inlining(callee_method, caller_bci, failure_msg,
   1.406 -                   false /* !success */);
   1.407 +  set_msg(check_can_parse(callee_method));
   1.408 +  if (msg() != NULL) {
   1.409 +    print_inlining(callee_method, caller_bci, false /* !success */);
   1.410      return NULL;
   1.411    }
   1.412  
   1.413    // Check if inlining policy says no.
   1.414    WarmCallInfo wci = *(initial_wci);
   1.415 -  failure_msg = try_to_inline(callee_method, caller_method, caller_bci, profile,
   1.416 -                              &wci, should_delay);
   1.417 +  bool success = try_to_inline(callee_method, caller_method, caller_bci,
   1.418 +                               profile, &wci, should_delay);
   1.419  
   1.420  #ifndef PRODUCT
   1.421    if (UseOldInlining && InlineWarmCalls
   1.422        && (PrintOpto || PrintOptoInlining || PrintInlining)) {
   1.423      bool cold = wci.is_cold();
   1.424      bool hot  = !cold && wci.is_hot();
   1.425 -    bool old_cold = (failure_msg != NULL);
   1.426 +    bool old_cold = !success;
   1.427      if (old_cold != cold || (Verbose || WizardMode)) {
   1.428 +      if (msg() == NULL) {
   1.429 +        set_msg("OK");
   1.430 +      }
   1.431        tty->print("   OldInlining= %4s : %s\n           WCI=",
   1.432 -                 old_cold ? "cold" : "hot", failure_msg ? failure_msg : "OK");
   1.433 +                 old_cold ? "cold" : "hot", msg());
   1.434        wci.print();
   1.435      }
   1.436    }
   1.437  #endif
   1.438    if (UseOldInlining) {
   1.439 -    if (failure_msg == NULL)
   1.440 +    if (success) {
   1.441        wci = *(WarmCallInfo::always_hot());
   1.442 -    else
   1.443 +    } else {
   1.444        wci = *(WarmCallInfo::always_cold());
   1.445      }
   1.446 +  }
   1.447    if (!InlineWarmCalls) {
   1.448      if (!wci.is_cold() && !wci.is_hot()) {
   1.449        // Do not inline the warm calls.
   1.450 @@ -507,9 +554,10 @@
   1.451  
   1.452    if (!wci.is_cold()) {
   1.453      // Inline!
   1.454 -    print_inlining(callee_method, caller_bci,
   1.455 -                   failure_msg ? failure_msg : "inline (hot)",
   1.456 -                   true /* success */);
   1.457 +    if (msg() == NULL) {
   1.458 +      set_msg("inline (hot)");
   1.459 +    }
   1.460 +    print_inlining(callee_method, caller_bci, true /* success */);
   1.461      if (UseOldInlining)
   1.462        build_inline_tree_for_callee(callee_method, jvms, caller_bci);
   1.463      if (InlineWarmCalls && !wci.is_hot())
   1.464 @@ -518,9 +566,10 @@
   1.465    }
   1.466  
   1.467    // Do not inline
   1.468 -  print_inlining(callee_method, caller_bci,
   1.469 -                 failure_msg ? failure_msg : "too cold to inline",
   1.470 -                 false /* !success */ );
   1.471 +  if (msg() == NULL) {
   1.472 +    set_msg("too cold to inline");
   1.473 +  }
   1.474 +  print_inlining(callee_method, caller_bci, false /* !success */ );
   1.475    return NULL;
   1.476  }
   1.477  

mercurial