src/share/vm/opto/bytecodeInfo.cpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 7854
e8260b6328fb
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

     1 /*
     2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    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  */
    25 #include "precompiled.hpp"
    26 #include "ci/ciReplay.hpp"
    27 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/vmSymbols.hpp"
    29 #include "compiler/compileBroker.hpp"
    30 #include "compiler/compileLog.hpp"
    31 #include "interpreter/linkResolver.hpp"
    32 #include "jfr/jfrEvents.hpp"
    33 #include "oops/objArrayKlass.hpp"
    34 #include "opto/callGenerator.hpp"
    35 #include "opto/parse.hpp"
    36 #include "runtime/handles.inline.hpp"
    38 //=============================================================================
    39 //------------------------------InlineTree-------------------------------------
    40 InlineTree::InlineTree(Compile* c,
    41                        const InlineTree *caller_tree, ciMethod* callee,
    42                        JVMState* caller_jvms, int caller_bci,
    43                        float site_invoke_ratio, int max_inline_level) :
    44   C(c),
    45   _caller_jvms(caller_jvms),
    46   _caller_tree((InlineTree*) caller_tree),
    47   _method(callee),
    48   _site_invoke_ratio(site_invoke_ratio),
    49   _max_inline_level(max_inline_level),
    50   _count_inline_bcs(method()->code_size_for_inlining()),
    51   _subtrees(c->comp_arena(), 2, 0, NULL),
    52   _msg(NULL)
    53 {
    54 #ifndef PRODUCT
    55   _count_inlines = 0;
    56   _forced_inline = false;
    57 #endif
    58   if (_caller_jvms != NULL) {
    59     // Keep a private copy of the caller_jvms:
    60     _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms());
    61     _caller_jvms->set_bci(caller_jvms->bci());
    62     assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining");
    63   }
    64   assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS");
    65   assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter");
    66   assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter");
    67   // Update hierarchical counts, count_inline_bcs() and count_inlines()
    68   InlineTree *caller = (InlineTree *)caller_tree;
    69   for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) {
    70     caller->_count_inline_bcs += count_inline_bcs();
    71     NOT_PRODUCT(caller->_count_inlines++;)
    72   }
    73 }
    75 /**
    76  *  Return true when EA is ON and a java constructor is called or
    77  *  a super constructor is called from an inlined java constructor.
    78  *  Also return true for boxing methods.
    79  */
    80 static bool is_init_with_ea(ciMethod* callee_method,
    81                             ciMethod* caller_method, Compile* C) {
    82   if (!C->do_escape_analysis() || !EliminateAllocations) {
    83     return false; // EA is off
    84   }
    85   if (callee_method->is_initializer()) {
    86     return true; // constuctor
    87   }
    88   if (caller_method->is_initializer() &&
    89       caller_method != C->method() &&
    90       caller_method->holder()->is_subclass_of(callee_method->holder())) {
    91     return true; // super constructor is called from inlined constructor
    92   }
    93   if (C->eliminate_boxing() && callee_method->is_boxing_method()) {
    94     return true;
    95   }
    96   return false;
    97 }
    99 /**
   100  *  Force inlining unboxing accessor.
   101  */
   102 static bool is_unboxing_method(ciMethod* callee_method, Compile* C) {
   103   return C->eliminate_boxing() && callee_method->is_unboxing_method();
   104 }
   106 // positive filter: should callee be inlined?
   107 bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
   108                                int caller_bci, ciCallProfile& profile,
   109                                WarmCallInfo* wci_result) {
   110   // Allows targeted inlining
   111   if (callee_method->should_inline()) {
   112     *wci_result = *(WarmCallInfo::always_hot());
   113     if (C->print_inlining() && Verbose) {
   114       CompileTask::print_inline_indent(inline_level());
   115       tty->print_cr("Inlined method is hot: ");
   116     }
   117     set_msg("force inline by CompilerOracle");
   118     _forced_inline = true;
   119     return true;
   120   }
   122   if (callee_method->force_inline()) {
   123       set_msg("force inline by annotation");
   124       _forced_inline = true;
   125       return true;
   126   }
   128 #ifndef PRODUCT
   129   int inline_depth = inline_level()+1;
   130   if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
   131     set_msg("force inline by ciReplay");
   132     _forced_inline = true;
   133     return true;
   134   }
   135 #endif
   137   int size = callee_method->code_size_for_inlining();
   139   // Check for too many throws (and not too huge)
   140   if(callee_method->interpreter_throwout_count() > InlineThrowCount &&
   141      size < InlineThrowMaxSize ) {
   142     wci_result->set_profit(wci_result->profit() * 100);
   143     if (C->print_inlining() && Verbose) {
   144       CompileTask::print_inline_indent(inline_level());
   145       tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
   146     }
   147     set_msg("many throws");
   148     return true;
   149   }
   151   int default_max_inline_size = C->max_inline_size();
   152   int inline_small_code_size  = InlineSmallCode / 4;
   153   int max_inline_size         = default_max_inline_size;
   155   int call_site_count  = method()->scale_count(profile.count());
   156   int invoke_count     = method()->interpreter_invocation_count();
   158   assert(invoke_count != 0, "require invocation count greater than zero");
   159   int freq = call_site_count / invoke_count;
   161   // bump the max size if the call is frequent
   162   if ((freq >= InlineFrequencyRatio) ||
   163       (call_site_count >= InlineFrequencyCount) ||
   164       is_unboxing_method(callee_method, C) ||
   165       is_init_with_ea(callee_method, caller_method, C)) {
   167     max_inline_size = C->freq_inline_size();
   168     if (size <= max_inline_size && TraceFrequencyInlining) {
   169       CompileTask::print_inline_indent(inline_level());
   170       tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count);
   171       CompileTask::print_inline_indent(inline_level());
   172       callee_method->print();
   173       tty->cr();
   174     }
   175   } else {
   176     // Not hot.  Check for medium-sized pre-existing nmethod at cold sites.
   177     if (callee_method->has_compiled_code() &&
   178         callee_method->instructions_size() > inline_small_code_size) {
   179       set_msg("already compiled into a medium method");
   180       return false;
   181     }
   182   }
   183   if (size > max_inline_size) {
   184     if (max_inline_size > default_max_inline_size) {
   185       set_msg("hot method too big");
   186     } else {
   187       set_msg("too big");
   188     }
   189     return false;
   190   }
   191   return true;
   192 }
   195 // negative filter: should callee NOT be inlined?
   196 bool InlineTree::should_not_inline(ciMethod *callee_method,
   197                                    ciMethod* caller_method,
   198                                    JVMState* jvms,
   199                                    WarmCallInfo* wci_result) {
   201   const char* fail_msg = NULL;
   203   // First check all inlining restrictions which are required for correctness
   204   if ( callee_method->is_abstract()) {
   205     fail_msg = "abstract method"; // // note: we allow ik->is_abstract()
   206   } else if (!callee_method->holder()->is_initialized()) {
   207     fail_msg = "method holder not initialized";
   208   } else if ( callee_method->is_native()) {
   209     fail_msg = "native method";
   210   } else if ( callee_method->dont_inline()) {
   211     fail_msg = "don't inline by annotation";
   212   }
   214   // one more inlining restriction
   215   if (fail_msg == NULL && callee_method->has_unloaded_classes_in_signature()) {
   216     fail_msg = "unloaded signature classes";
   217   }
   219   if (fail_msg != NULL) {
   220     set_msg(fail_msg);
   221     return true;
   222   }
   224   // ignore heuristic controls on inlining
   225   if (callee_method->should_inline()) {
   226     set_msg("force inline by CompilerOracle");
   227     return false;
   228   }
   230   if (callee_method->should_not_inline()) {
   231     set_msg("disallowed by CompilerOracle");
   232     return true;
   233   }
   235 #ifndef PRODUCT
   236   int caller_bci = jvms->bci();
   237   int inline_depth = inline_level()+1;
   238   if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
   239     set_msg("force inline by ciReplay");
   240     return false;
   241   }
   243   if (ciReplay::should_not_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
   244     set_msg("disallowed by ciReplay");
   245     return true;
   246   }
   248   if (ciReplay::should_not_inline(callee_method)) {
   249     set_msg("disallowed by ciReplay");
   250     return true;
   251   }
   252 #endif
   254   if (callee_method->force_inline()) {
   255     set_msg("force inline by annotation");
   256     return false;
   257   }
   259   // Now perform checks which are heuristic
   261   if (is_unboxing_method(callee_method, C)) {
   262     // Inline unboxing methods.
   263     return false;
   264   }
   266   if (callee_method->has_compiled_code() &&
   267       callee_method->instructions_size() > InlineSmallCode) {
   268     set_msg("already compiled into a big method");
   269     return true;
   270   }
   272   // don't inline exception code unless the top method belongs to an
   273   // exception class
   274   if (caller_tree() != NULL &&
   275       callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
   276     const InlineTree *top = this;
   277     while (top->caller_tree() != NULL) top = top->caller_tree();
   278     ciInstanceKlass* k = top->method()->holder();
   279     if (!k->is_subclass_of(C->env()->Throwable_klass())) {
   280       set_msg("exception method");
   281       return true;
   282     }
   283   }
   285   // use frequency-based objections only for non-trivial methods
   286   if (callee_method->code_size() <= MaxTrivialSize) {
   287     return false;
   288   }
   290   // don't use counts with -Xcomp or CTW
   291   if (UseInterpreter && !CompileTheWorld) {
   293     if (!callee_method->has_compiled_code() &&
   294         !callee_method->was_executed_more_than(0)) {
   295       set_msg("never executed");
   296       return true;
   297     }
   299     if (is_init_with_ea(callee_method, caller_method, C)) {
   300       // Escape Analysis: inline all executed constructors
   301       return false;
   302     } else if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold,
   303                                                            CompileThreshold >> 1))) {
   304       set_msg("executed < MinInliningThreshold times");
   305       return true;
   306     }
   307   }
   309   return false;
   310 }
   312 //-----------------------------try_to_inline-----------------------------------
   313 // return true if ok
   314 // Relocated from "InliningClosure::try_to_inline"
   315 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
   316                                int caller_bci, JVMState* jvms, ciCallProfile& profile,
   317                                WarmCallInfo* wci_result, bool& should_delay) {
   319   if (ClipInlining && (int)count_inline_bcs() >= DesiredMethodLimit) {
   320     if (!callee_method->force_inline() || !IncrementalInline) {
   321       set_msg("size > DesiredMethodLimit");
   322       return false;
   323     } else if (!C->inlining_incrementally()) {
   324       should_delay = true;
   325     }
   326   }
   328   _forced_inline = false; // Reset
   329   if (!should_inline(callee_method, caller_method, caller_bci, profile,
   330                      wci_result)) {
   331     return false;
   332   }
   333   if (should_not_inline(callee_method, caller_method, jvms, wci_result)) {
   334     return false;
   335   }
   337   if (InlineAccessors && callee_method->is_accessor()) {
   338     // accessor methods are not subject to any of the following limits.
   339     set_msg("accessor");
   340     return true;
   341   }
   343   // suppress a few checks for accessors and trivial methods
   344   if (callee_method->code_size() > MaxTrivialSize) {
   346     // don't inline into giant methods
   347     if (C->over_inlining_cutoff()) {
   348       if ((!callee_method->force_inline() && !caller_method->is_compiled_lambda_form())
   349           || !IncrementalInline) {
   350         set_msg("NodeCountInliningCutoff");
   351         return false;
   352       } else {
   353         should_delay = true;
   354       }
   355     }
   357     if ((!UseInterpreter || CompileTheWorld) &&
   358         is_init_with_ea(callee_method, caller_method, C)) {
   359       // Escape Analysis stress testing when running Xcomp or CTW:
   360       // inline constructors even if they are not reached.
   361     } else if (forced_inline()) {
   362       // Inlining was forced by CompilerOracle, ciReplay or annotation
   363     } else if (profile.count() == 0) {
   364       // don't inline unreached call sites
   365        set_msg("call site not reached");
   366        return false;
   367     }
   368   }
   370   if (!C->do_inlining() && InlineAccessors) {
   371     set_msg("not an accessor");
   372     return false;
   373   }
   375   // Limit inlining depth in case inlining is forced or
   376   // _max_inline_level was increased to compensate for lambda forms.
   377   if (inline_level() > MaxForceInlineLevel) {
   378     set_msg("MaxForceInlineLevel");
   379     return false;
   380   }
   381   if (inline_level() > _max_inline_level) {
   382     if (!callee_method->force_inline() || !IncrementalInline) {
   383       set_msg("inlining too deep");
   384       return false;
   385     } else if (!C->inlining_incrementally()) {
   386       should_delay = true;
   387     }
   388   }
   390   // detect direct and indirect recursive inlining
   391   {
   392     // count the current method and the callee
   393     const bool is_compiled_lambda_form = callee_method->is_compiled_lambda_form();
   394     int inline_level = 0;
   395     if (!is_compiled_lambda_form) {
   396       if (method() == callee_method) {
   397         inline_level++;
   398       }
   399     }
   400     // count callers of current method and callee
   401     Node* callee_argument0 = is_compiled_lambda_form ? jvms->map()->argument(jvms, 0)->uncast() : NULL;
   402     for (JVMState* j = jvms->caller(); j != NULL && j->has_method(); j = j->caller()) {
   403       if (j->method() == callee_method) {
   404         if (is_compiled_lambda_form) {
   405           // Since compiled lambda forms are heavily reused we allow recursive inlining.  If it is truly
   406           // a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the
   407           // compiler stack.
   408           Node* caller_argument0 = j->map()->argument(j, 0)->uncast();
   409           if (caller_argument0 == callee_argument0) {
   410             inline_level++;
   411           }
   412         } else {
   413           inline_level++;
   414         }
   415       }
   416     }
   417     if (inline_level > MaxRecursiveInlineLevel) {
   418       set_msg("recursive inlining is too deep");
   419       return false;
   420     }
   421   }
   423   int size = callee_method->code_size_for_inlining();
   425   if (ClipInlining && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
   426     if (!callee_method->force_inline() || !IncrementalInline) {
   427       set_msg("size > DesiredMethodLimit");
   428       return false;
   429     } else if (!C->inlining_incrementally()) {
   430       should_delay = true;
   431     }
   432   }
   434   // ok, inline this method
   435   return true;
   436 }
   438 //------------------------------pass_initial_checks----------------------------
   439 bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) {
   440   ciInstanceKlass *callee_holder = callee_method ? callee_method->holder() : NULL;
   441   // Check if a callee_method was suggested
   442   if( callee_method == NULL )            return false;
   443   // Check if klass of callee_method is loaded
   444   if( !callee_holder->is_loaded() )      return false;
   445   if( !callee_holder->is_initialized() ) return false;
   446   if( !UseInterpreter || CompileTheWorld /* running Xcomp or CTW */ ) {
   447     // Checks that constant pool's call site has been visited
   448     // stricter than callee_holder->is_initialized()
   449     ciBytecodeStream iter(caller_method);
   450     iter.force_bci(caller_bci);
   451     Bytecodes::Code call_bc = iter.cur_bc();
   452     // An invokedynamic instruction does not have a klass.
   453     if (call_bc != Bytecodes::_invokedynamic) {
   454       int index = iter.get_index_u2_cpcache();
   455       if (!caller_method->is_klass_loaded(index, true)) {
   456         return false;
   457       }
   458       // Try to do constant pool resolution if running Xcomp
   459       if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) {
   460         return false;
   461       }
   462     }
   463   }
   464   // We will attempt to see if a class/field/etc got properly loaded.  If it
   465   // did not, it may attempt to throw an exception during our probing.  Catch
   466   // and ignore such exceptions and do not attempt to compile the method.
   467   if( callee_method->should_exclude() )  return false;
   469   return true;
   470 }
   472 //------------------------------check_can_parse--------------------------------
   473 const char* InlineTree::check_can_parse(ciMethod* callee) {
   474   // Certain methods cannot be parsed at all:
   475   if ( callee->is_native())                     return "native method";
   476   if ( callee->is_abstract())                   return "abstract method";
   477   if (!callee->can_be_compiled())               return "not compilable (disabled)";
   478   if (!callee->has_balanced_monitors())         return "not compilable (unbalanced monitors)";
   479   if ( callee->get_flow_analysis()->failing())  return "not compilable (flow analysis failed)";
   480   return NULL;
   481 }
   483 static void post_inlining_event(int compile_id,const char* msg, bool success, int bci, ciMethod* caller, ciMethod* callee) {
   484   assert(caller != NULL, "invariant");
   485   assert(callee != NULL, "invariant");
   486   EventCompilerInlining event;
   487   if (event.should_commit()) {
   488     JfrStructCalleeMethod callee_struct;
   489     callee_struct.set_type(callee->holder()->name()->as_utf8());
   490     callee_struct.set_name(callee->name()->as_utf8());
   491     callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8());
   492     event.set_compileId(compile_id);
   493     event.set_message(msg);
   494     event.set_succeeded(success);
   495     event.set_bci(bci);
   496     event.set_caller(caller->get_Method());
   497     event.set_callee(callee_struct);
   498     event.commit();
   499   }
   500 }
   502 //------------------------------print_inlining---------------------------------
   503 void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci,
   504                                 ciMethod* caller_method, bool success) const {
   505   const char* inline_msg = msg();
   506   assert(inline_msg != NULL, "just checking");
   507   if (C->log() != NULL) {
   508     if (success) {
   509       C->log()->inline_success(inline_msg);
   510     } else {
   511       C->log()->inline_fail(inline_msg);
   512     }
   513   }
   514   if (C->print_inlining()) {
   515     C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
   516     if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
   517     if (Verbose && callee_method) {
   518       const InlineTree *top = this;
   519       while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
   520       //tty->print("  bcs: %d+%d  invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
   521     }
   522   }
   523   post_inlining_event(C->compile_id(), inline_msg, success, caller_bci, caller_method, callee_method);
   524 }
   526 //------------------------------ok_to_inline-----------------------------------
   527 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci, bool& should_delay) {
   528   assert(callee_method != NULL, "caller checks for optimized virtual!");
   529   assert(!should_delay, "should be initialized to false");
   530 #ifdef ASSERT
   531   // Make sure the incoming jvms has the same information content as me.
   532   // This means that we can eventually make this whole class AllStatic.
   533   if (jvms->caller() == NULL) {
   534     assert(_caller_jvms == NULL, "redundant instance state");
   535   } else {
   536     assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
   537   }
   538   assert(_method == jvms->method(), "redundant instance state");
   539 #endif
   540   int         caller_bci    = jvms->bci();
   541   ciMethod*   caller_method = jvms->method();
   543   // Do some initial checks.
   544   if (!pass_initial_checks(caller_method, caller_bci, callee_method)) {
   545     set_msg("failed initial checks");
   546     print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
   547     return NULL;
   548   }
   550   // Do some parse checks.
   551   set_msg(check_can_parse(callee_method));
   552   if (msg() != NULL) {
   553     print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
   554     return NULL;
   555   }
   557   // Check if inlining policy says no.
   558   WarmCallInfo wci = *(initial_wci);
   559   bool success = try_to_inline(callee_method, caller_method, caller_bci,
   560                                jvms, profile, &wci, should_delay);
   562 #ifndef PRODUCT
   563   if (InlineWarmCalls && (PrintOpto || C->print_inlining())) {
   564     bool cold = wci.is_cold();
   565     bool hot  = !cold && wci.is_hot();
   566     bool old_cold = !success;
   567     if (old_cold != cold || (Verbose || WizardMode)) {
   568       if (msg() == NULL) {
   569         set_msg("OK");
   570       }
   571       tty->print("   OldInlining= %4s : %s\n           WCI=",
   572                  old_cold ? "cold" : "hot", msg());
   573       wci.print();
   574     }
   575   }
   576 #endif
   577   if (success) {
   578     wci = *(WarmCallInfo::always_hot());
   579   } else {
   580     wci = *(WarmCallInfo::always_cold());
   581   }
   583   if (!InlineWarmCalls) {
   584     if (!wci.is_cold() && !wci.is_hot()) {
   585       // Do not inline the warm calls.
   586       wci = *(WarmCallInfo::always_cold());
   587     }
   588   }
   590   if (!wci.is_cold()) {
   591     // Inline!
   592     if (msg() == NULL) {
   593       set_msg("inline (hot)");
   594     }
   595     print_inlining(callee_method, caller_bci, caller_method, true /* success */);
   596     build_inline_tree_for_callee(callee_method, jvms, caller_bci);
   597     if (InlineWarmCalls && !wci.is_hot())
   598       return new (C) WarmCallInfo(wci);  // copy to heap
   599     return WarmCallInfo::always_hot();
   600   }
   602   // Do not inline
   603   if (msg() == NULL) {
   604     set_msg("too cold to inline");
   605   }
   606   print_inlining(callee_method, caller_bci, caller_method, false /* !success */ );
   607   return NULL;
   608 }
   610 //------------------------------compute_callee_frequency-----------------------
   611 float InlineTree::compute_callee_frequency( int caller_bci ) const {
   612   int count  = method()->interpreter_call_site_count(caller_bci);
   613   int invcnt = method()->interpreter_invocation_count();
   614   float freq = (float)count/(float)invcnt;
   615   // Call-site count / interpreter invocation count, scaled recursively.
   616   // Always between 0.0 and 1.0.  Represents the percentage of the method's
   617   // total execution time used at this call site.
   619   return freq;
   620 }
   622 //------------------------------build_inline_tree_for_callee-------------------
   623 InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) {
   624   float recur_frequency = _site_invoke_ratio * compute_callee_frequency(caller_bci);
   625   // Attempt inlining.
   626   InlineTree* old_ilt = callee_at(caller_bci, callee_method);
   627   if (old_ilt != NULL) {
   628     return old_ilt;
   629   }
   630   int max_inline_level_adjust = 0;
   631   if (caller_jvms->method() != NULL) {
   632     if (caller_jvms->method()->is_compiled_lambda_form()) {
   633       max_inline_level_adjust += 1;  // don't count actions in MH or indy adapter frames
   634     } else if (callee_method->is_method_handle_intrinsic() ||
   635                callee_method->is_compiled_lambda_form()) {
   636       max_inline_level_adjust += 1;  // don't count method handle calls from java.lang.invoke implementation
   637     }
   638     if (max_inline_level_adjust != 0 && C->print_inlining() && (Verbose || WizardMode)) {
   639       CompileTask::print_inline_indent(inline_level());
   640       tty->print_cr(" \\-> discounting inline depth");
   641     }
   642     if (max_inline_level_adjust != 0 && C->log()) {
   643       int id1 = C->log()->identify(caller_jvms->method());
   644       int id2 = C->log()->identify(callee_method);
   645       C->log()->elem("inline_level_discount caller='%d' callee='%d'", id1, id2);
   646     }
   647   }
   648   InlineTree* ilt = new InlineTree(C, this, callee_method, caller_jvms, caller_bci, recur_frequency, _max_inline_level + max_inline_level_adjust);
   649   _subtrees.append(ilt);
   651   NOT_PRODUCT( _count_inlines += 1; )
   653   return ilt;
   654 }
   657 //---------------------------------------callee_at-----------------------------
   658 InlineTree *InlineTree::callee_at(int bci, ciMethod* callee) const {
   659   for (int i = 0; i < _subtrees.length(); i++) {
   660     InlineTree* sub = _subtrees.at(i);
   661     if (sub->caller_bci() == bci && callee == sub->method()) {
   662       return sub;
   663     }
   664   }
   665   return NULL;
   666 }
   669 //------------------------------build_inline_tree_root-------------------------
   670 InlineTree *InlineTree::build_inline_tree_root() {
   671   Compile* C = Compile::current();
   673   // Root of inline tree
   674   InlineTree* ilt = new InlineTree(C, NULL, C->method(), NULL, -1, 1.0F, MaxInlineLevel);
   676   return ilt;
   677 }
   680 //-------------------------find_subtree_from_root-----------------------------
   681 // Given a jvms, which determines a call chain from the root method,
   682 // find the corresponding inline tree.
   683 // Note: This method will be removed or replaced as InlineTree goes away.
   684 InlineTree* InlineTree::find_subtree_from_root(InlineTree* root, JVMState* jvms, ciMethod* callee) {
   685   InlineTree* iltp = root;
   686   uint depth = jvms && jvms->has_method() ? jvms->depth() : 0;
   687   for (uint d = 1; d <= depth; d++) {
   688     JVMState* jvmsp  = jvms->of_depth(d);
   689     // Select the corresponding subtree for this bci.
   690     assert(jvmsp->method() == iltp->method(), "tree still in sync");
   691     ciMethod* d_callee = (d == depth) ? callee : jvms->of_depth(d+1)->method();
   692     InlineTree* sub = iltp->callee_at(jvmsp->bci(), d_callee);
   693     if (sub == NULL) {
   694       if (d == depth) {
   695         sub = iltp->build_inline_tree_for_callee(d_callee, jvmsp, jvmsp->bci());
   696       }
   697       guarantee(sub != NULL, "should be a sub-ilt here");
   698       return sub;
   699     }
   700     iltp = sub;
   701   }
   702   return iltp;
   703 }
   705 // Count number of nodes in this subtree
   706 int InlineTree::count() const {
   707   int result = 1;
   708   for (int i = 0 ; i < _subtrees.length(); i++) {
   709     result += _subtrees.at(i)->count();
   710   }
   711   return result;
   712 }
   714 void InlineTree::dump_replay_data(outputStream* out) {
   715   out->print(" %d %d ", inline_level(), caller_bci());
   716   method()->dump_name_as_ascii(out);
   717   for (int i = 0 ; i < _subtrees.length(); i++) {
   718     _subtrees.at(i)->dump_replay_data(out);
   719   }
   720 }
   723 #ifndef PRODUCT
   724 void InlineTree::print_impl(outputStream* st, int indent) const {
   725   for (int i = 0; i < indent; i++) st->print(" ");
   726   st->print(" @ %d", caller_bci());
   727   method()->print_short_name(st);
   728   st->cr();
   730   for (int i = 0 ; i < _subtrees.length(); i++) {
   731     _subtrees.at(i)->print_impl(st, indent + 2);
   732   }
   733 }
   735 void InlineTree::print_value_on(outputStream* st) const {
   736   print_impl(st, 2);
   737 }
   738 #endif

mercurial