1 /*
   2  * Copyright (c) 2000, 2021, 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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/bcEscapeAnalyzer.hpp"
  27 #include "ci/ciCallSite.hpp"
  28 #include "ci/ciObjArray.hpp"
  29 #include "ci/ciMemberName.hpp"
  30 #include "ci/ciMethodHandle.hpp"
  31 #include "classfile/javaClasses.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "opto/addnode.hpp"
  34 #include "opto/callGenerator.hpp"
  35 #include "opto/callnode.hpp"
  36 #include "opto/castnode.hpp"
  37 #include "opto/cfgnode.hpp"
  38 #include "opto/inlinetypenode.hpp"
  39 #include "opto/parse.hpp"
  40 #include "opto/rootnode.hpp"
  41 #include "opto/runtime.hpp"
  42 #include "opto/subnode.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "ci/ciNativeEntryPoint.hpp"
  45 #include "utilities/debug.hpp"
  46 
  47 // Utility function.
  48 const TypeFunc* CallGenerator::tf() const {
  49   return TypeFunc::make(method());
  50 }
  51 
  52 bool CallGenerator::is_inlined_method_handle_intrinsic(JVMState* jvms, ciMethod* m) {
  53   return is_inlined_method_handle_intrinsic(jvms->method(), jvms->bci(), m);
  54 }
  55 
  56 bool CallGenerator::is_inlined_method_handle_intrinsic(ciMethod* caller, int bci, ciMethod* m) {
  57   ciMethod* symbolic_info = caller->get_method_at_bci(bci);
  58   return is_inlined_method_handle_intrinsic(symbolic_info, m);
  59 }
  60 
  61 bool CallGenerator::is_inlined_method_handle_intrinsic(ciMethod* symbolic_info, ciMethod* m) {
  62   return symbolic_info->is_method_handle_intrinsic() && !m->is_method_handle_intrinsic();
  63 }
  64 
  65 //-----------------------------ParseGenerator---------------------------------
  66 // Internal class which handles all direct bytecode traversal.
  67 class ParseGenerator : public InlineCallGenerator {
  68 private:
  69   bool  _is_osr;
  70   float _expected_uses;
  71 
  72 public:
  73   ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false)
  74     : InlineCallGenerator(method)
  75   {
  76     _is_osr        = is_osr;
  77     _expected_uses = expected_uses;
  78     assert(InlineTree::check_can_parse(method) == NULL, "parse must be possible");
  79   }
  80 
  81   virtual bool      is_parse() const           { return true; }
  82   virtual JVMState* generate(JVMState* jvms);
  83   int is_osr() { return _is_osr; }
  84 
  85 };
  86 
  87 JVMState* ParseGenerator::generate(JVMState* jvms) {
  88   Compile* C = Compile::current();
  89   C->print_inlining_update(this);
  90 
  91   if (is_osr()) {
  92     // The JVMS for a OSR has a single argument (see its TypeFunc).
  93     assert(jvms->depth() == 1, "no inline OSR");
  94   }
  95 
  96   if (C->failing()) {
  97     return NULL;  // bailing out of the compile; do not try to parse
  98   }
  99 
 100   Parse parser(jvms, method(), _expected_uses);
 101   // Grab signature for matching/allocation
 102   GraphKit& exits = parser.exits();
 103 
 104   if (C->failing()) {
 105     while (exits.pop_exception_state() != NULL) ;
 106     return NULL;
 107   }
 108 
 109   assert(exits.jvms()->same_calls_as(jvms), "sanity");
 110 
 111   // Simply return the exit state of the parser,
 112   // augmented by any exceptional states.
 113   return exits.transfer_exceptions_into_jvms();
 114 }
 115 
 116 //---------------------------DirectCallGenerator------------------------------
 117 // Internal class which handles all out-of-line calls w/o receiver type checks.
 118 class DirectCallGenerator : public CallGenerator {
 119  private:
 120   CallStaticJavaNode* _call_node;
 121   // Force separate memory and I/O projections for the exceptional
 122   // paths to facilitate late inlining.
 123   bool                _separate_io_proj;
 124 
 125 protected:
 126   void set_call_node(CallStaticJavaNode* call) { _call_node = call; }
 127 
 128  public:
 129   DirectCallGenerator(ciMethod* method, bool separate_io_proj)
 130     : CallGenerator(method),
 131       _call_node(NULL),
 132       _separate_io_proj(separate_io_proj)
 133   {
 134     if (InlineTypeReturnedAsFields && method->is_method_handle_intrinsic()) {
 135       // If that call has not been optimized by the time optimizations are over,
 136       // we'll need to add a call to create an inline type instance from the klass
 137       // returned by the call (see PhaseMacroExpand::expand_mh_intrinsic_return).
 138       // Separating memory and I/O projections for exceptions is required to
 139       // perform that graph transformation.
 140       _separate_io_proj = true;
 141     }
 142   }
 143   virtual JVMState* generate(JVMState* jvms);
 144 
 145   virtual CallNode* call_node() const { return _call_node; }
 146   virtual CallGenerator* with_call_node(CallNode* call) {
 147     DirectCallGenerator* dcg = new DirectCallGenerator(method(), _separate_io_proj);
 148     dcg->set_call_node(call->as_CallStaticJava());
 149     return dcg;
 150   }
 151 };
 152 
 153 JVMState* DirectCallGenerator::generate(JVMState* jvms) {
 154   GraphKit kit(jvms);
 155   kit.C->print_inlining_update(this);
 156   PhaseGVN& gvn = kit.gvn();
 157   bool is_static = method()->is_static();
 158   address target = is_static ? SharedRuntime::get_resolve_static_call_stub()
 159                              : SharedRuntime::get_resolve_opt_virtual_call_stub();
 160 
 161   if (kit.C->log() != NULL) {
 162     kit.C->log()->elem("direct_call bci='%d'", jvms->bci());
 163   }
 164 
 165   CallStaticJavaNode* call = new CallStaticJavaNode(kit.C, tf(), target, method());
 166   if (is_inlined_method_handle_intrinsic(jvms, method())) {
 167     // To be able to issue a direct call and skip a call to MH.linkTo*/invokeBasic adapter,
 168     // additional information about the method being invoked should be attached
 169     // to the call site to make resolution logic work
 170     // (see SharedRuntime::resolve_static_call_C).
 171     call->set_override_symbolic_info(true);
 172   }
 173   _call_node = call;  // Save the call node in case we need it later
 174   if (!is_static) {
 175     // Make an explicit receiver null_check as part of this call.
 176     // Since we share a map with the caller, his JVMS gets adjusted.
 177     kit.null_check_receiver_before_call(method());
 178     if (kit.stopped()) {
 179       // And dump it back to the caller, decorated with any exceptions:
 180       return kit.transfer_exceptions_into_jvms();
 181     }
 182     // Mark the call node as virtual, sort of:
 183     call->set_optimized_virtual(true);
 184     if (method()->is_method_handle_intrinsic() ||
 185         method()->is_compiled_lambda_form()) {
 186       call->set_method_handle_invoke(true);
 187     }
 188   }
 189   kit.set_arguments_for_java_call(call, is_late_inline());
 190   if (kit.stopped()) {
 191     return kit.transfer_exceptions_into_jvms();
 192   }
 193   kit.set_edges_for_java_call(call, false, _separate_io_proj);
 194   Node* ret = kit.set_results_for_java_call(call, _separate_io_proj);
 195   kit.push_node(method()->return_type()->basic_type(), ret);
 196   return kit.transfer_exceptions_into_jvms();
 197 }
 198 
 199 //--------------------------VirtualCallGenerator------------------------------
 200 // Internal class which handles all out-of-line calls checking receiver type.
 201 class VirtualCallGenerator : public CallGenerator {
 202 private:
 203   int _vtable_index;
 204   bool _separate_io_proj;
 205   CallDynamicJavaNode* _call_node;
 206 
 207 protected:
 208   void set_call_node(CallDynamicJavaNode* call) { _call_node = call; }
 209 
 210 public:
 211   VirtualCallGenerator(ciMethod* method, int vtable_index, bool separate_io_proj)
 212     : CallGenerator(method), _vtable_index(vtable_index), _separate_io_proj(separate_io_proj), _call_node(NULL)
 213   {
 214     assert(vtable_index == Method::invalid_vtable_index ||
 215            vtable_index >= 0, "either invalid or usable");
 216   }
 217   virtual bool      is_virtual() const          { return true; }
 218   virtual JVMState* generate(JVMState* jvms);
 219 
 220   virtual CallNode* call_node() const { return _call_node; }
 221   int vtable_index() const { return _vtable_index; }
 222 
 223   virtual CallGenerator* with_call_node(CallNode* call) {
 224     VirtualCallGenerator* cg = new VirtualCallGenerator(method(), _vtable_index, _separate_io_proj);
 225     cg->set_call_node(call->as_CallDynamicJava());
 226     return cg;
 227   }
 228 };
 229 
 230 JVMState* VirtualCallGenerator::generate(JVMState* jvms) {
 231   GraphKit kit(jvms);
 232   Node* receiver = kit.argument(0);
 233   kit.C->print_inlining_update(this);
 234 
 235   if (kit.C->log() != NULL) {
 236     kit.C->log()->elem("virtual_call bci='%d'", jvms->bci());
 237   }
 238 
 239   // If the receiver is a constant null, do not torture the system
 240   // by attempting to call through it.  The compile will proceed
 241   // correctly, but may bail out in final_graph_reshaping, because
 242   // the call instruction will have a seemingly deficient out-count.
 243   // (The bailout says something misleading about an "infinite loop".)
 244   if (!receiver->is_InlineType() && kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) {
 245     assert(Bytecodes::is_invoke(kit.java_bc()), "%d: %s", kit.java_bc(), Bytecodes::name(kit.java_bc()));
 246     ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
 247     int arg_size = declared_method->signature()->arg_size_for_bc(kit.java_bc());
 248     kit.inc_sp(arg_size);  // restore arguments
 249     kit.uncommon_trap(Deoptimization::Reason_null_check,
 250                       Deoptimization::Action_none,
 251                       NULL, "null receiver");
 252     return kit.transfer_exceptions_into_jvms();
 253   }
 254 
 255   // Ideally we would unconditionally do a null check here and let it
 256   // be converted to an implicit check based on profile information.
 257   // However currently the conversion to implicit null checks in
 258   // Block::implicit_null_check() only looks for loads and stores, not calls.
 259   ciMethod *caller = kit.method();
 260   ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data();
 261   if (!UseInlineCaches || !ImplicitNullChecks || !os::zero_page_read_protected() ||
 262        ((ImplicitNullCheckThreshold > 0) && caller_md &&
 263        (caller_md->trap_count(Deoptimization::Reason_null_check)
 264        >= (uint)ImplicitNullCheckThreshold))) {
 265     // Make an explicit receiver null_check as part of this call.
 266     // Since we share a map with the caller, his JVMS gets adjusted.
 267     receiver = kit.null_check_receiver_before_call(method());
 268     if (kit.stopped()) {
 269       // And dump it back to the caller, decorated with any exceptions:
 270       return kit.transfer_exceptions_into_jvms();
 271     }
 272   }
 273 
 274   assert(!method()->is_static(), "virtual call must not be to static");
 275   assert(!method()->is_final(), "virtual call should not be to final");
 276   assert(!method()->is_private(), "virtual call should not be to private");
 277   assert(_vtable_index == Method::invalid_vtable_index || !UseInlineCaches,
 278          "no vtable calls if +UseInlineCaches ");
 279   address target = SharedRuntime::get_resolve_virtual_call_stub();
 280   // Normal inline cache used for call
 281   CallDynamicJavaNode* call = new CallDynamicJavaNode(tf(), target, method(), _vtable_index);
 282   if (is_inlined_method_handle_intrinsic(jvms, method())) {
 283     // To be able to issue a direct call (optimized virtual or virtual)
 284     // and skip a call to MH.linkTo*/invokeBasic adapter, additional information
 285     // about the method being invoked should be attached to the call site to
 286     // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C).
 287     call->set_override_symbolic_info(true);
 288   }
 289   _call_node = call;  // Save the call node in case we need it later
 290 
 291   kit.set_arguments_for_java_call(call);
 292   if (kit.stopped()) {
 293     return kit.transfer_exceptions_into_jvms();
 294   }
 295   kit.set_edges_for_java_call(call, false /*must_throw*/, _separate_io_proj);
 296   Node* ret = kit.set_results_for_java_call(call, _separate_io_proj);
 297   kit.push_node(method()->return_type()->basic_type(), ret);
 298 
 299   // Represent the effect of an implicit receiver null_check
 300   // as part of this call.  Since we share a map with the caller,
 301   // his JVMS gets adjusted.
 302   kit.cast_not_null(receiver);
 303   return kit.transfer_exceptions_into_jvms();
 304 }
 305 
 306 CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) {
 307   if (InlineTree::check_can_parse(m) != NULL)  return NULL;
 308   return new ParseGenerator(m, expected_uses);
 309 }
 310 
 311 // As a special case, the JVMS passed to this CallGenerator is
 312 // for the method execution already in progress, not just the JVMS
 313 // of the caller.  Thus, this CallGenerator cannot be mixed with others!
 314 CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) {
 315   if (InlineTree::check_can_parse(m) != NULL)  return NULL;
 316   float past_uses = m->interpreter_invocation_count();
 317   float expected_uses = past_uses;
 318   return new ParseGenerator(m, expected_uses, true);
 319 }
 320 
 321 CallGenerator* CallGenerator::for_direct_call(ciMethod* m, bool separate_io_proj) {
 322   assert(!m->is_abstract(), "for_direct_call mismatch");
 323   return new DirectCallGenerator(m, separate_io_proj);
 324 }
 325 
 326 CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) {
 327   assert(!m->is_static(), "for_virtual_call mismatch");
 328   assert(!m->is_method_handle_intrinsic(), "should be a direct call");
 329   return new VirtualCallGenerator(m, vtable_index, false /*separate_io_projs*/);
 330 }
 331 
 332 // Allow inlining decisions to be delayed
 333 class LateInlineCallGenerator : public DirectCallGenerator {
 334  private:
 335   jlong _unique_id;   // unique id for log compilation
 336   bool _is_pure_call; // a hint that the call doesn't have important side effects to care about
 337 
 338  protected:
 339   CallGenerator* _inline_cg;
 340   virtual bool do_late_inline_check(Compile* C, JVMState* jvms) { return true; }
 341   virtual CallGenerator* inline_cg() const { return _inline_cg; }
 342   virtual bool is_pure_call() const { return _is_pure_call; }
 343 
 344  public:
 345   LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg, bool is_pure_call = false) :
 346     DirectCallGenerator(method, true), _unique_id(0), _is_pure_call(is_pure_call), _inline_cg(inline_cg) {}
 347 
 348   virtual bool is_late_inline() const { return true; }
 349 
 350   // Convert the CallStaticJava into an inline
 351   virtual void do_late_inline();
 352 
 353   virtual JVMState* generate(JVMState* jvms) {
 354     Compile *C = Compile::current();
 355 
 356     C->log_inline_id(this);
 357 
 358     // Record that this call site should be revisited once the main
 359     // parse is finished.
 360     if (!is_mh_late_inline()) {
 361       C->add_late_inline(this);
 362     }
 363 
 364     // Emit the CallStaticJava and request separate projections so
 365     // that the late inlining logic can distinguish between fall
 366     // through and exceptional uses of the memory and io projections
 367     // as is done for allocations and macro expansion.
 368     return DirectCallGenerator::generate(jvms);
 369   }
 370 
 371   virtual void print_inlining_late(const char* msg) {
 372     CallNode* call = call_node();
 373     Compile* C = Compile::current();
 374     C->print_inlining_assert_ready();
 375     C->print_inlining(method(), call->jvms()->depth()-1, call->jvms()->bci(), msg);
 376     C->print_inlining_move_to(this);
 377     C->print_inlining_update_delayed(this);
 378   }
 379 
 380   virtual void set_unique_id(jlong id) {
 381     _unique_id = id;
 382   }
 383 
 384   virtual jlong unique_id() const {
 385     return _unique_id;
 386   }
 387 
 388   virtual CallGenerator* inline_cg() {
 389     return _inline_cg;
 390   }
 391 
 392   virtual CallGenerator* with_call_node(CallNode* call) {
 393     LateInlineCallGenerator* cg = new LateInlineCallGenerator(method(), _inline_cg, _is_pure_call);
 394     cg->set_call_node(call->as_CallStaticJava());
 395     return cg;
 396   }
 397 };
 398 
 399 CallGenerator* CallGenerator::for_late_inline(ciMethod* method, CallGenerator* inline_cg) {
 400   return new LateInlineCallGenerator(method, inline_cg);
 401 }
 402 
 403 class LateInlineMHCallGenerator : public LateInlineCallGenerator {
 404   ciMethod* _caller;
 405   bool _input_not_const;
 406 
 407   virtual bool do_late_inline_check(Compile* C, JVMState* jvms);
 408 
 409  public:
 410   LateInlineMHCallGenerator(ciMethod* caller, ciMethod* callee, bool input_not_const) :
 411     LateInlineCallGenerator(callee, NULL), _caller(caller), _input_not_const(input_not_const) {}
 412 
 413   virtual bool is_mh_late_inline() const { return true; }
 414 
 415   // Convert the CallStaticJava into an inline
 416   virtual void do_late_inline();
 417 
 418   virtual JVMState* generate(JVMState* jvms) {
 419     JVMState* new_jvms = LateInlineCallGenerator::generate(jvms);
 420 
 421     Compile* C = Compile::current();
 422     if (_input_not_const) {
 423       // inlining won't be possible so no need to enqueue right now.
 424       call_node()->set_generator(this);
 425     } else {
 426       C->add_late_inline(this);
 427     }
 428     return new_jvms;
 429   }
 430 
 431   virtual CallGenerator* with_call_node(CallNode* call) {
 432     LateInlineMHCallGenerator* cg = new LateInlineMHCallGenerator(_caller, method(), _input_not_const);
 433     cg->set_call_node(call->as_CallStaticJava());
 434     return cg;
 435   }
 436 };
 437 
 438 bool LateInlineMHCallGenerator::do_late_inline_check(Compile* C, JVMState* jvms) {
 439   // When inlining a virtual call, the null check at the call and the call itself can throw. These 2 paths have different
 440   // expression stacks which causes late inlining to break. The MH invoker is not expected to be called from a method wih
 441   // exception handlers. When there is no exception handler, GraphKit::builtin_throw() pops the stack which solves the issue
 442   // of late inlining with exceptions.
 443   assert(!jvms->method()->has_exception_handlers() ||
 444          (method()->intrinsic_id() != vmIntrinsics::_linkToVirtual &&
 445           method()->intrinsic_id() != vmIntrinsics::_linkToInterface), "no exception handler expected");
 446   // Even if inlining is not allowed, a virtual call can be strength-reduced to a direct call.
 447   bool allow_inline = C->inlining_incrementally();
 448   bool input_not_const = true;
 449   CallGenerator* cg = for_method_handle_inline(jvms, _caller, method(), allow_inline, input_not_const);
 450   assert(!input_not_const, "sanity"); // shouldn't have been scheduled for inlining in the first place
 451 
 452   if (cg != NULL) {
 453     // AlwaysIncrementalInline causes for_method_handle_inline() to
 454     // return a LateInlineCallGenerator. Extract the
 455     // InlineCallGenerator from it.
 456     if (AlwaysIncrementalInline && cg->is_late_inline() && !cg->is_virtual_late_inline()) {
 457       cg = cg->inline_cg();
 458       assert(cg != NULL, "inline call generator expected");
 459     }
 460 
 461     assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline, "we're doing late inlining");
 462     _inline_cg = cg;
 463     C->dec_number_of_mh_late_inlines();
 464     return true;
 465   } else {
 466     // Method handle call which has a constant appendix argument should be either inlined or replaced with a direct call
 467     // unless there's a signature mismatch between caller and callee. If the failure occurs, there's not much to be improved later,
 468     // so don't reinstall the generator to avoid pushing the generator between IGVN and incremental inlining indefinitely.
 469     return false;
 470   }
 471 }
 472 
 473 CallGenerator* CallGenerator::for_mh_late_inline(ciMethod* caller, ciMethod* callee, bool input_not_const) {
 474   assert(IncrementalInlineMH, "required");
 475   Compile::current()->inc_number_of_mh_late_inlines();
 476   CallGenerator* cg = new LateInlineMHCallGenerator(caller, callee, input_not_const);
 477   return cg;
 478 }
 479 
 480 // Allow inlining decisions to be delayed
 481 class LateInlineVirtualCallGenerator : public VirtualCallGenerator {
 482  private:
 483   jlong          _unique_id;   // unique id for log compilation
 484   CallGenerator* _inline_cg;
 485   ciMethod*      _callee;
 486   bool           _is_pure_call;
 487   float          _prof_factor;
 488 
 489  protected:
 490   virtual bool do_late_inline_check(Compile* C, JVMState* jvms);
 491   virtual CallGenerator* inline_cg() const { return _inline_cg; }
 492   virtual bool is_pure_call() const { return _is_pure_call; }
 493 
 494  public:
 495   LateInlineVirtualCallGenerator(ciMethod* method, int vtable_index, float prof_factor)
 496   : VirtualCallGenerator(method, vtable_index, true /*separate_io_projs*/),
 497     _unique_id(0), _inline_cg(NULL), _callee(NULL), _is_pure_call(false), _prof_factor(prof_factor) {
 498     assert(IncrementalInlineVirtual, "required");
 499   }
 500 
 501   virtual bool is_late_inline() const { return true; }
 502 
 503   virtual bool is_virtual_late_inline() const { return true; }
 504 
 505   // Convert the CallDynamicJava into an inline
 506   virtual void do_late_inline();
 507 
 508   virtual void set_callee_method(ciMethod* m) {
 509     assert(_callee == NULL, "repeated inlining attempt");
 510     _callee = m;
 511   }
 512 
 513   virtual JVMState* generate(JVMState* jvms) {
 514     // Emit the CallDynamicJava and request separate projections so
 515     // that the late inlining logic can distinguish between fall
 516     // through and exceptional uses of the memory and io projections
 517     // as is done for allocations and macro expansion.
 518     JVMState* new_jvms = VirtualCallGenerator::generate(jvms);
 519     if (call_node() != NULL) {
 520       call_node()->set_generator(this);
 521     }
 522     return new_jvms;
 523   }
 524 
 525   virtual void print_inlining_late(const char* msg) {
 526     CallNode* call = call_node();
 527     Compile* C = Compile::current();
 528     C->print_inlining_assert_ready();
 529     C->print_inlining(method(), call->jvms()->depth()-1, call->jvms()->bci(), msg);
 530     C->print_inlining_move_to(this);
 531     C->print_inlining_update_delayed(this);
 532   }
 533 
 534   virtual void set_unique_id(jlong id) {
 535     _unique_id = id;
 536   }
 537 
 538   virtual jlong unique_id() const {
 539     return _unique_id;
 540   }
 541 
 542   virtual CallGenerator* with_call_node(CallNode* call) {
 543     LateInlineVirtualCallGenerator* cg = new LateInlineVirtualCallGenerator(method(), vtable_index(), _prof_factor);
 544     cg->set_call_node(call->as_CallDynamicJava());
 545     return cg;
 546   }
 547 };
 548 
 549 bool LateInlineVirtualCallGenerator::do_late_inline_check(Compile* C, JVMState* jvms) {
 550   // Method handle linker case is handled in CallDynamicJavaNode::Ideal().
 551   // Unless inlining is performed, _override_symbolic_info bit will be set in DirectCallGenerator::generate().
 552 
 553   // Implicit receiver null checks introduce problems when exception states are combined.
 554   Node* receiver = jvms->map()->argument(jvms, 0);
 555   const Type* recv_type = C->initial_gvn()->type(receiver);
 556   if (recv_type->maybe_null()) {
 557     if (C->print_inlining() || C->print_intrinsics()) {
 558       C->print_inlining(method(), jvms->depth()-1, call_node()->jvms()->bci(),
 559                         "late call devirtualization failed (receiver may be null)");
 560     }
 561     return false;
 562   }
 563   // Even if inlining is not allowed, a virtual call can be strength-reduced to a direct call.
 564   bool allow_inline = C->inlining_incrementally();
 565   if (!allow_inline && _callee->holder()->is_interface()) {
 566     // Don't convert the interface call to a direct call guarded by an interface subtype check.
 567     if (C->print_inlining() || C->print_intrinsics()) {
 568       C->print_inlining(method(), jvms->depth()-1, call_node()->jvms()->bci(),
 569                         "late call devirtualization failed (interface call)");
 570     }
 571     return false;
 572   }
 573   CallGenerator* cg = C->call_generator(_callee,
 574                                         vtable_index(),
 575                                         false /*call_does_dispatch*/,
 576                                         jvms,
 577                                         allow_inline,
 578                                         _prof_factor,
 579                                         NULL /*speculative_receiver_type*/,
 580                                         true /*allow_intrinsics*/);
 581 
 582   if (cg != NULL) {
 583     assert(!cg->is_late_inline() || cg->is_mh_late_inline() || AlwaysIncrementalInline, "we're doing late inlining");
 584     _inline_cg = cg;
 585     return true;
 586   } else {
 587     // Virtual call which provably doesn't dispatch should be either inlined or replaced with a direct call.
 588     assert(false, "no progress");
 589     return false;
 590   }
 591 }
 592 
 593 CallGenerator* CallGenerator::for_late_inline_virtual(ciMethod* m, int vtable_index, float prof_factor) {
 594   assert(IncrementalInlineVirtual, "required");
 595   assert(!m->is_static(), "for_virtual_call mismatch");
 596   assert(!m->is_method_handle_intrinsic(), "should be a direct call");
 597   return new LateInlineVirtualCallGenerator(m, vtable_index, prof_factor);
 598 }
 599 
 600 void LateInlineCallGenerator::do_late_inline() {
 601   CallGenerator::do_late_inline_helper();
 602 }
 603 
 604 void LateInlineMHCallGenerator::do_late_inline() {
 605   CallGenerator::do_late_inline_helper();
 606 }
 607 
 608 void LateInlineVirtualCallGenerator::do_late_inline() {
 609   assert(_callee != NULL, "required"); // set up in CallDynamicJavaNode::Ideal
 610   CallGenerator::do_late_inline_helper();
 611 }
 612 
 613 static bool has_non_debug_usages(Node* n) {
 614   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
 615     Node* m = n->fast_out(i);
 616     if (!m->is_SafePoint()
 617         || (m->is_Call() && m->as_Call()->has_non_debug_use(n))) {
 618       return true;
 619     }
 620   }
 621   return false;
 622 }
 623 
 624 static bool is_box_cache_valid(CallNode* call) {
 625   ciInstanceKlass* klass = call->as_CallStaticJava()->method()->holder();
 626   return klass->is_box_cache_valid();
 627 }
 628 
 629 // delay box in runtime, treat box as a scalarized object
 630 static void scalarize_debug_usages(CallNode* call, Node* resproj) {
 631   GraphKit kit(call->jvms());
 632   PhaseGVN& gvn = kit.gvn();
 633 
 634   ProjNode* res = resproj->as_Proj();
 635   ciInstanceKlass* klass = call->as_CallStaticJava()->method()->holder();
 636   int n_fields = klass->nof_nonstatic_fields();
 637   assert(n_fields == 1, "the klass must be an auto-boxing klass");
 638 
 639   for (DUIterator_Last imin, i = res->last_outs(imin); i >= imin;) {
 640     SafePointNode* sfpt = res->last_out(i)->as_SafePoint();
 641     uint first_ind = sfpt->req() - sfpt->jvms()->scloff();
 642     Node* sobj = new SafePointScalarObjectNode(gvn.type(res)->isa_oopptr(),
 643 #ifdef ASSERT
 644                                                 call,
 645 #endif // ASSERT
 646                                                 first_ind, n_fields, true);
 647     sobj->init_req(0, kit.root());
 648     sfpt->add_req(call->in(TypeFunc::Parms));
 649     sobj = gvn.transform(sobj);
 650     JVMState* jvms = sfpt->jvms();
 651     jvms->set_endoff(sfpt->req());
 652     int start = jvms->debug_start();
 653     int end   = jvms->debug_end();
 654     int num_edges = sfpt->replace_edges_in_range(res, sobj, start, end, &gvn);
 655     i -= num_edges;
 656   }
 657 
 658   assert(res->outcnt() == 0, "the box must have no use after replace");
 659 
 660 #ifndef PRODUCT
 661   if (PrintEliminateAllocations) {
 662     tty->print("++++ Eliminated: %d ", call->_idx);
 663     call->as_CallStaticJava()->method()->print_short_name(tty);
 664     tty->cr();
 665   }
 666 #endif
 667 }
 668 
 669 void CallGenerator::do_late_inline_helper() {
 670   assert(is_late_inline(), "only late inline allowed");
 671 
 672   // Can't inline it
 673   CallNode* call = call_node();
 674   if (call == NULL || call->outcnt() == 0 ||
 675       call->in(0) == NULL || call->in(0)->is_top()) {
 676     return;
 677   }
 678 
 679   const TypeTuple* r = call->tf()->domain_cc();
 680   for (uint i1 = TypeFunc::Parms; i1 < r->cnt(); i1++) {
 681     if (call->in(i1)->is_top() && r->field_at(i1) != Type::HALF) {
 682       assert(Compile::current()->inlining_incrementally(), "shouldn't happen during parsing");
 683       return;
 684     }
 685   }
 686 
 687   if (call->in(TypeFunc::Memory)->is_top()) {
 688     assert(Compile::current()->inlining_incrementally(), "shouldn't happen during parsing");
 689     return;
 690   }
 691   if (call->in(TypeFunc::Memory)->is_MergeMem()) {
 692     MergeMemNode* merge_mem = call->in(TypeFunc::Memory)->as_MergeMem();
 693     if (merge_mem->base_memory() == merge_mem->empty_memory()) {
 694       return; // dead path
 695     }
 696   }
 697 
 698   // check for unreachable loop
 699   CallProjections* callprojs = call->extract_projections(true);
 700   if ((callprojs->fallthrough_catchproj == call->in(0)) ||
 701       (callprojs->catchall_catchproj    == call->in(0)) ||
 702       (callprojs->fallthrough_memproj   == call->in(TypeFunc::Memory)) ||
 703       (callprojs->catchall_memproj      == call->in(TypeFunc::Memory)) ||
 704       (callprojs->fallthrough_ioproj    == call->in(TypeFunc::I_O)) ||
 705       (callprojs->catchall_ioproj       == call->in(TypeFunc::I_O)) ||
 706       (callprojs->exobj != NULL && call->find_edge(callprojs->exobj) != -1)) {
 707     return;
 708   }
 709 
 710   Compile* C = Compile::current();
 711   // Remove inlined methods from Compiler's lists.
 712   if (call->is_macro()) {
 713     C->remove_macro_node(call);
 714   }
 715 
 716   bool result_not_used = false;
 717 
 718   if (is_pure_call()) {
 719     // Disabled due to JDK-8276112
 720     if (false && is_boxing_late_inline() && callprojs->resproj[0] != nullptr) {
 721         // replace box node to scalar node only in case it is directly referenced by debug info
 722         assert(call->as_CallStaticJava()->is_boxing_method(), "sanity");
 723         if (!has_non_debug_usages(callprojs->resproj[0]) && is_box_cache_valid(call)) {
 724           scalarize_debug_usages(call, callprojs->resproj[0]);
 725         }
 726     }
 727 
 728     // The call is marked as pure (no important side effects), but result isn't used.
 729     // It's safe to remove the call.
 730     result_not_used = true;
 731     for (uint i = 0; i < callprojs->nb_resproj; i++) {
 732       if (callprojs->resproj[i] != NULL) {
 733         if (callprojs->resproj[i]->outcnt() != 0) {
 734           result_not_used = false;
 735         }
 736         if (call->find_edge(callprojs->resproj[i]) != -1) {
 737           return;
 738         }
 739       }
 740     }
 741   }
 742 
 743   if (result_not_used) {
 744     GraphKit kit(call->jvms());
 745     kit.replace_call(call, C->top(), true);
 746   } else {
 747     // Make a clone of the JVMState that appropriate to use for driving a parse
 748     JVMState* old_jvms = call->jvms();
 749     JVMState* jvms = old_jvms->clone_shallow(C);
 750     uint size = call->req();
 751     SafePointNode* map = new SafePointNode(size, jvms);
 752     for (uint i1 = 0; i1 < size; i1++) {
 753       map->init_req(i1, call->in(i1));
 754     }
 755 
 756     PhaseGVN& gvn = *C->initial_gvn();
 757     // Make sure the state is a MergeMem for parsing.
 758     if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
 759       Node* mem = MergeMemNode::make(map->in(TypeFunc::Memory));
 760       gvn.set_type_bottom(mem);
 761       map->set_req(TypeFunc::Memory, mem);
 762     }
 763 
 764     // blow away old call arguments
 765     for (uint i1 = TypeFunc::Parms; i1 < r->cnt(); i1++) {
 766       map->set_req(i1, C->top());
 767     }
 768     jvms->set_map(map);
 769 
 770     // Make enough space in the expression stack to transfer
 771     // the incoming arguments and return value.
 772     map->ensure_stack(jvms, jvms->method()->max_stack());
 773     const TypeTuple* domain_sig = call->_tf->domain_sig();
 774     uint nargs = method()->arg_size();
 775     assert(domain_sig->cnt() - TypeFunc::Parms == nargs, "inconsistent signature");
 776 
 777     uint j = TypeFunc::Parms;
 778     int arg_num = 0;
 779     for (uint i1 = 0; i1 < nargs; i1++) {
 780       const Type* t = domain_sig->field_at(TypeFunc::Parms + i1);
 781       if (t->is_inlinetypeptr() && method()->is_scalarized_arg(arg_num)) {
 782         // Inline type arguments are not passed by reference: we get an argument per
 783         // field of the inline type. Build InlineTypeNodes from the inline type arguments.
 784         GraphKit arg_kit(jvms, &gvn);
 785         Node* vt = InlineTypeNode::make_from_multi(&arg_kit, call, t->inline_klass(), j, /* in= */ true, /* null_free= */ !t->maybe_null());
 786         map->set_control(arg_kit.control());
 787         map->set_argument(jvms, i1, vt);
 788       } else {
 789         map->set_argument(jvms, i1, call->in(j++));
 790       }
 791       if (t != Type::HALF) {
 792         arg_num++;
 793       }
 794     }
 795 
 796     C->print_inlining_assert_ready();
 797 
 798     C->print_inlining_move_to(this);
 799 
 800     C->log_late_inline(this);
 801 
 802     // JVMState is ready, so time to perform some checks and prepare for inlining attempt.
 803     if (!do_late_inline_check(C, jvms)) {
 804       map->disconnect_inputs(C);
 805       C->print_inlining_update_delayed(this);
 806       return;
 807     }
 808 
 809     // Check if we are late inlining a method handle call that returns an inline type as fields.
 810     Node* buffer_oop = NULL;
 811     ciMethod* inline_method = inline_cg()->method();
 812     ciType* return_type = inline_method->return_type();
 813     if (!call->tf()->returns_inline_type_as_fields() && is_mh_late_inline() &&
 814         return_type->is_inlinetype() && return_type->as_inline_klass()->can_be_returned_as_fields()) {
 815       // Allocate a buffer for the inline type returned as fields because the caller expects an oop return.
 816       // Do this before the method handle call in case the buffer allocation triggers deoptimization and
 817       // we need to "re-execute" the call in the interpreter (to make sure the call is only executed once).
 818       GraphKit arg_kit(jvms, &gvn);
 819       {
 820         PreserveReexecuteState preexecs(&arg_kit);
 821         arg_kit.jvms()->set_should_reexecute(true);
 822         arg_kit.inc_sp(nargs);
 823         Node* klass_node = arg_kit.makecon(TypeKlassPtr::make(return_type->as_inline_klass()));
 824         buffer_oop = arg_kit.new_instance(klass_node, NULL, NULL, /* deoptimize_on_exception */ true);
 825       }
 826       jvms = arg_kit.transfer_exceptions_into_jvms();
 827     }
 828 
 829     // Setup default node notes to be picked up by the inlining
 830     Node_Notes* old_nn = C->node_notes_at(call->_idx);
 831     if (old_nn != NULL) {
 832       Node_Notes* entry_nn = old_nn->clone(C);
 833       entry_nn->set_jvms(jvms);
 834       C->set_default_node_notes(entry_nn);
 835     }
 836 
 837     // Now perform the inlining using the synthesized JVMState
 838     JVMState* new_jvms = inline_cg()->generate(jvms);
 839     if (new_jvms == NULL)  return;  // no change
 840     if (C->failing())      return;
 841 
 842     // Capture any exceptional control flow
 843     GraphKit kit(new_jvms);
 844 
 845     // Find the result object
 846     Node* result = C->top();
 847     int   result_size = method()->return_type()->size();
 848     if (result_size != 0 && !kit.stopped()) {
 849       result = (result_size == 1) ? kit.pop() : kit.pop_pair();
 850     }
 851 
 852     if (inline_cg()->is_inline()) {
 853       C->set_has_loops(C->has_loops() || inline_method->has_loops());
 854       C->env()->notice_inlined_method(inline_method);
 855     }
 856     C->set_inlining_progress(true);
 857     C->set_do_cleanup(kit.stopped()); // path is dead; needs cleanup
 858 
 859     // Handle inline type returns
 860     InlineTypeBaseNode* vt = result->isa_InlineTypeBase();
 861     if (vt != NULL) {
 862       if (call->tf()->returns_inline_type_as_fields()) {
 863         vt->replace_call_results(&kit, call, C, inline_method->signature()->returns_null_free_inline_type());
 864       } else if (vt->is_InlineType()) {
 865         // Result might still be allocated (for example, if it has been stored to a non-flattened field)
 866         if (!vt->is_allocated(&kit.gvn())) {
 867           assert(buffer_oop != NULL, "should have allocated a buffer");
 868           RegionNode* region = new RegionNode(3);
 869 
 870           // Check if result is null
 871           Node* null_ctl = kit.top();
 872           if (!inline_method->signature()->returns_null_free_inline_type()) {
 873             kit.null_check_common(vt->get_is_init(), T_INT, false, &null_ctl);
 874           }
 875           region->init_req(1, null_ctl);
 876           PhiNode* oop = PhiNode::make(region, kit.gvn().zerocon(T_OBJECT), TypeInstPtr::make(TypePtr::BotPTR, vt->type()->inline_klass()));
 877           Node* init_mem = kit.reset_memory();
 878           PhiNode* mem = PhiNode::make(region, init_mem, Type::MEMORY, TypePtr::BOTTOM);
 879 
 880           // Not null, initialize the buffer
 881           kit.set_all_memory(init_mem);
 882           vt->store(&kit, buffer_oop, buffer_oop, vt->type()->inline_klass());
 883           // Do not let stores that initialize this buffer be reordered with a subsequent
 884           // store that would make this buffer accessible by other threads.
 885           AllocateNode* alloc = AllocateNode::Ideal_allocation(buffer_oop, &kit.gvn());
 886           assert(alloc != NULL, "must have an allocation node");
 887           kit.insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 888           region->init_req(2, kit.control());
 889           oop->init_req(2, buffer_oop);
 890           mem->init_req(2, kit.merged_memory());
 891 
 892           // Update oop input to buffer
 893           kit.gvn().hash_delete(vt);
 894           vt->set_oop(kit.gvn().transform(oop));
 895           vt = kit.gvn().transform(vt)->as_InlineTypeBase();
 896 
 897           kit.set_control(kit.gvn().transform(region));
 898           kit.set_all_memory(kit.gvn().transform(mem));
 899           kit.record_for_igvn(region);
 900           kit.record_for_igvn(oop);
 901           kit.record_for_igvn(mem);
 902         }
 903         result = vt->as_ptr(&kit.gvn(), inline_method->signature()->returns_null_free_inline_type());
 904       }
 905       DEBUG_ONLY(buffer_oop = NULL);
 906     } else {
 907       assert(result->is_top() || !call->tf()->returns_inline_type_as_fields(), "Unexpected return value");
 908     }
 909     assert(buffer_oop == NULL, "unused buffer allocation");
 910 
 911     kit.replace_call(call, result, true);
 912   }
 913 }
 914 
 915 class LateInlineStringCallGenerator : public LateInlineCallGenerator {
 916 
 917  public:
 918   LateInlineStringCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
 919     LateInlineCallGenerator(method, inline_cg) {}
 920 
 921   virtual JVMState* generate(JVMState* jvms) {
 922     Compile *C = Compile::current();
 923 
 924     C->log_inline_id(this);
 925 
 926     C->add_string_late_inline(this);
 927 
 928     JVMState* new_jvms = DirectCallGenerator::generate(jvms);
 929     return new_jvms;
 930   }
 931 
 932   virtual bool is_string_late_inline() const { return true; }
 933 
 934   virtual CallGenerator* with_call_node(CallNode* call) {
 935     LateInlineStringCallGenerator* cg = new LateInlineStringCallGenerator(method(), _inline_cg);
 936     cg->set_call_node(call->as_CallStaticJava());
 937     return cg;
 938   }
 939 };
 940 
 941 CallGenerator* CallGenerator::for_string_late_inline(ciMethod* method, CallGenerator* inline_cg) {
 942   return new LateInlineStringCallGenerator(method, inline_cg);
 943 }
 944 
 945 class LateInlineBoxingCallGenerator : public LateInlineCallGenerator {
 946 
 947  public:
 948   LateInlineBoxingCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
 949     LateInlineCallGenerator(method, inline_cg, /*is_pure=*/true) {}
 950 
 951   virtual JVMState* generate(JVMState* jvms) {
 952     Compile *C = Compile::current();
 953 
 954     C->log_inline_id(this);
 955 
 956     C->add_boxing_late_inline(this);
 957 
 958     JVMState* new_jvms = DirectCallGenerator::generate(jvms);
 959     return new_jvms;
 960   }
 961 
 962   virtual bool is_boxing_late_inline() const { return true; }
 963 
 964   virtual CallGenerator* with_call_node(CallNode* call) {
 965     LateInlineBoxingCallGenerator* cg = new LateInlineBoxingCallGenerator(method(), _inline_cg);
 966     cg->set_call_node(call->as_CallStaticJava());
 967     return cg;
 968   }
 969 };
 970 
 971 CallGenerator* CallGenerator::for_boxing_late_inline(ciMethod* method, CallGenerator* inline_cg) {
 972   return new LateInlineBoxingCallGenerator(method, inline_cg);
 973 }
 974 
 975 class LateInlineVectorReboxingCallGenerator : public LateInlineCallGenerator {
 976 
 977  public:
 978   LateInlineVectorReboxingCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
 979     LateInlineCallGenerator(method, inline_cg, /*is_pure=*/true) {}
 980 
 981   virtual JVMState* generate(JVMState* jvms) {
 982     Compile *C = Compile::current();
 983 
 984     C->log_inline_id(this);
 985 
 986     C->add_vector_reboxing_late_inline(this);
 987 
 988     JVMState* new_jvms = DirectCallGenerator::generate(jvms);
 989     return new_jvms;
 990   }
 991 
 992   virtual CallGenerator* with_call_node(CallNode* call) {
 993     LateInlineVectorReboxingCallGenerator* cg = new LateInlineVectorReboxingCallGenerator(method(), _inline_cg);
 994     cg->set_call_node(call->as_CallStaticJava());
 995     return cg;
 996   }
 997 };
 998 
 999 //   static CallGenerator* for_vector_reboxing_late_inline(ciMethod* m, CallGenerator* inline_cg);
1000 CallGenerator* CallGenerator::for_vector_reboxing_late_inline(ciMethod* method, CallGenerator* inline_cg) {
1001   return new LateInlineVectorReboxingCallGenerator(method, inline_cg);
1002 }
1003 
1004 //------------------------PredictedCallGenerator------------------------------
1005 // Internal class which handles all out-of-line calls checking receiver type.
1006 class PredictedCallGenerator : public CallGenerator {
1007   ciKlass*       _predicted_receiver;
1008   CallGenerator* _if_missed;
1009   CallGenerator* _if_hit;
1010   float          _hit_prob;
1011   bool           _exact_check;
1012 
1013 public:
1014   PredictedCallGenerator(ciKlass* predicted_receiver,
1015                          CallGenerator* if_missed,
1016                          CallGenerator* if_hit, bool exact_check,
1017                          float hit_prob)
1018     : CallGenerator(if_missed->method())
1019   {
1020     // The call profile data may predict the hit_prob as extreme as 0 or 1.
1021     // Remove the extremes values from the range.
1022     if (hit_prob > PROB_MAX)   hit_prob = PROB_MAX;
1023     if (hit_prob < PROB_MIN)   hit_prob = PROB_MIN;
1024 
1025     _predicted_receiver = predicted_receiver;
1026     _if_missed          = if_missed;
1027     _if_hit             = if_hit;
1028     _hit_prob           = hit_prob;
1029     _exact_check        = exact_check;
1030   }
1031 
1032   virtual bool      is_virtual()   const    { return true; }
1033   virtual bool      is_inline()    const    { return _if_hit->is_inline(); }
1034   virtual bool      is_deferred()  const    { return _if_hit->is_deferred(); }
1035 
1036   virtual JVMState* generate(JVMState* jvms);
1037 };
1038 
1039 
1040 CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver,
1041                                                  CallGenerator* if_missed,
1042                                                  CallGenerator* if_hit,
1043                                                  float hit_prob) {
1044   return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit,
1045                                     /*exact_check=*/true, hit_prob);
1046 }
1047 
1048 CallGenerator* CallGenerator::for_guarded_call(ciKlass* guarded_receiver,
1049                                                CallGenerator* if_missed,
1050                                                CallGenerator* if_hit) {
1051   return new PredictedCallGenerator(guarded_receiver, if_missed, if_hit,
1052                                     /*exact_check=*/false, PROB_ALWAYS);
1053 }
1054 
1055 JVMState* PredictedCallGenerator::generate(JVMState* jvms) {
1056   GraphKit kit(jvms);
1057   kit.C->print_inlining_update(this);
1058   PhaseGVN& gvn = kit.gvn();
1059   // We need an explicit receiver null_check before checking its type.
1060   // We share a map with the caller, so his JVMS gets adjusted.
1061   Node* receiver = kit.argument(0);
1062   CompileLog* log = kit.C->log();
1063   if (log != NULL) {
1064     log->elem("predicted_call bci='%d' exact='%d' klass='%d'",
1065               jvms->bci(), (_exact_check ? 1 : 0), log->identify(_predicted_receiver));
1066   }
1067 
1068   receiver = kit.null_check_receiver_before_call(method());
1069   if (kit.stopped()) {
1070     return kit.transfer_exceptions_into_jvms();
1071   }
1072 
1073   // Make a copy of the replaced nodes in case we need to restore them
1074   ReplacedNodes replaced_nodes = kit.map()->replaced_nodes();
1075   replaced_nodes.clone();
1076 
1077   Node* casted_receiver = receiver;  // will get updated in place...
1078   Node* slow_ctl = NULL;
1079   if (_exact_check) {
1080     slow_ctl = kit.type_check_receiver(receiver, _predicted_receiver, _hit_prob,
1081                                        &casted_receiver);
1082   } else {
1083     slow_ctl = kit.subtype_check_receiver(receiver, _predicted_receiver,
1084                                           &casted_receiver);
1085   }
1086 
1087   SafePointNode* slow_map = NULL;
1088   JVMState* slow_jvms = NULL;
1089   { PreserveJVMState pjvms(&kit);
1090     kit.set_control(slow_ctl);
1091     if (!kit.stopped()) {
1092       slow_jvms = _if_missed->generate(kit.sync_jvms());
1093       if (kit.failing())
1094         return NULL;  // might happen because of NodeCountInliningCutoff
1095       assert(slow_jvms != NULL, "must be");
1096       kit.add_exception_states_from(slow_jvms);
1097       kit.set_map(slow_jvms->map());
1098       if (!kit.stopped())
1099         slow_map = kit.stop();
1100     }
1101   }
1102 
1103   if (kit.stopped()) {
1104     // Instance does not match the predicted type.
1105     kit.set_jvms(slow_jvms);
1106     return kit.transfer_exceptions_into_jvms();
1107   }
1108 
1109   // Fall through if the instance matches the desired type.
1110   kit.replace_in_map(receiver, casted_receiver);
1111 
1112   // Make the hot call:
1113   JVMState* new_jvms = _if_hit->generate(kit.sync_jvms());
1114   if (new_jvms == NULL) {
1115     // Inline failed, so make a direct call.
1116     assert(_if_hit->is_inline(), "must have been a failed inline");
1117     CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method());
1118     new_jvms = cg->generate(kit.sync_jvms());
1119   }
1120   kit.add_exception_states_from(new_jvms);
1121   kit.set_jvms(new_jvms);
1122 
1123   // Need to merge slow and fast?
1124   if (slow_map == NULL) {
1125     // The fast path is the only path remaining.
1126     return kit.transfer_exceptions_into_jvms();
1127   }
1128 
1129   if (kit.stopped()) {
1130     // Inlined method threw an exception, so it's just the slow path after all.
1131     kit.set_jvms(slow_jvms);
1132     return kit.transfer_exceptions_into_jvms();
1133   }
1134 
1135   // Allocate inline types if they are merged with objects (similar to Parse::merge_common())
1136   uint tos = kit.jvms()->stkoff() + kit.sp();
1137   uint limit = slow_map->req();
1138   for (uint i = TypeFunc::Parms; i < limit; i++) {
1139     Node* m = kit.map()->in(i);
1140     Node* n = slow_map->in(i);
1141     const Type* t = gvn.type(m)->meet_speculative(gvn.type(n));
1142     if (m->is_InlineType() && !t->isa_inlinetype()) {
1143       // Allocate inline type in fast path
1144       m = m->as_InlineType()->buffer(&kit);
1145       kit.map()->set_req(i, m);
1146     }
1147     if (n->is_InlineType() && !t->isa_inlinetype()) {
1148       // Allocate inline type in slow path
1149       PreserveJVMState pjvms(&kit);
1150       kit.set_map(slow_map);
1151       n = n->as_InlineType()->buffer(&kit);
1152       kit.map()->set_req(i, n);
1153       slow_map = kit.stop();
1154     }
1155   }
1156 
1157   // There are 2 branches and the replaced nodes are only valid on
1158   // one: restore the replaced nodes to what they were before the
1159   // branch.
1160   kit.map()->set_replaced_nodes(replaced_nodes);
1161 
1162   // Finish the diamond.
1163   kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
1164   RegionNode* region = new RegionNode(3);
1165   region->init_req(1, kit.control());
1166   region->init_req(2, slow_map->control());
1167   kit.set_control(gvn.transform(region));
1168   Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
1169   iophi->set_req(2, slow_map->i_o());
1170   kit.set_i_o(gvn.transform(iophi));
1171   // Merge memory
1172   kit.merge_memory(slow_map->merged_memory(), region, 2);
1173   // Transform new memory Phis.
1174   for (MergeMemStream mms(kit.merged_memory()); mms.next_non_empty();) {
1175     Node* phi = mms.memory();
1176     if (phi->is_Phi() && phi->in(0) == region) {
1177       mms.set_memory(gvn.transform(phi));
1178     }
1179   }
1180   for (uint i = TypeFunc::Parms; i < limit; i++) {
1181     // Skip unused stack slots; fast forward to monoff();
1182     if (i == tos) {
1183       i = kit.jvms()->monoff();
1184       if( i >= limit ) break;
1185     }
1186     Node* m = kit.map()->in(i);
1187     Node* n = slow_map->in(i);
1188     if (m != n) {
1189       const Type* t = gvn.type(m)->meet_speculative(gvn.type(n));
1190       Node* phi = PhiNode::make(region, m, t);
1191       phi->set_req(2, n);
1192       kit.map()->set_req(i, gvn.transform(phi));
1193     }
1194   }
1195   return kit.transfer_exceptions_into_jvms();
1196 }
1197 
1198 
1199 CallGenerator* CallGenerator::for_method_handle_call(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool allow_inline) {
1200   assert(callee->is_method_handle_intrinsic(), "for_method_handle_call mismatch");
1201   bool input_not_const;
1202   CallGenerator* cg = CallGenerator::for_method_handle_inline(jvms, caller, callee, allow_inline, input_not_const);
1203   Compile* C = Compile::current();
1204   if (cg != NULL) {
1205     if (AlwaysIncrementalInline) {
1206       return CallGenerator::for_late_inline(callee, cg);
1207     } else {
1208       return cg;
1209     }
1210   }
1211   int bci = jvms->bci();
1212   ciCallProfile profile = caller->call_profile_at_bci(bci);
1213   int call_site_count = caller->scale_count(profile.count());
1214 
1215   if (IncrementalInlineMH && (AlwaysIncrementalInline ||
1216                             (call_site_count > 0 && (input_not_const || !C->inlining_incrementally() || C->over_inlining_cutoff())))) {
1217     return CallGenerator::for_mh_late_inline(caller, callee, input_not_const);
1218   } else {
1219     // Out-of-line call.
1220     return CallGenerator::for_direct_call(callee);
1221   }
1222 }
1223 
1224 static void cast_argument(int nargs, int arg_nb, ciType* t, GraphKit& kit, bool null_free) {
1225   PhaseGVN& gvn = kit.gvn();
1226   Node* arg = kit.argument(arg_nb);
1227   const Type* arg_type = arg->bottom_type();
1228   const Type* sig_type = TypeOopPtr::make_from_klass(t->as_klass());
1229   if (t->as_klass()->is_inlinetype() && null_free) {
1230     sig_type = sig_type->filter_speculative(TypePtr::NOTNULL);
1231   }
1232   if (arg_type->isa_oopptr() && !arg_type->higher_equal(sig_type)) {
1233     const Type* narrowed_arg_type = arg_type->filter_speculative(sig_type); // keep speculative part
1234     arg = gvn.transform(new CheckCastPPNode(kit.control(), arg, narrowed_arg_type));
1235     kit.set_argument(arg_nb, arg);
1236   }
1237   if (sig_type->is_inlinetypeptr() && !arg->is_InlineType()) {
1238     arg = InlineTypeNode::make_from_oop(&kit, arg, t->as_inline_klass(), !kit.gvn().type(arg)->maybe_null());
1239     kit.set_argument(arg_nb, arg);
1240   }
1241 }
1242 
1243 class NativeCallGenerator : public CallGenerator {
1244 private:
1245   address _call_addr;
1246   ciNativeEntryPoint* _nep;
1247 public:
1248   NativeCallGenerator(ciMethod* m, address call_addr, ciNativeEntryPoint* nep)
1249    : CallGenerator(m), _call_addr(call_addr), _nep(nep) {}
1250 
1251   virtual JVMState* generate(JVMState* jvms);
1252 };
1253 
1254 JVMState* NativeCallGenerator::generate(JVMState* jvms) {
1255   GraphKit kit(jvms);
1256 
1257   Node* call = kit.make_native_call(_call_addr, tf(), method()->arg_size(), _nep); // -fallback, - nep
1258   if (call == NULL) return NULL;
1259 
1260   kit.C->print_inlining_update(this);
1261   if (kit.C->log() != NULL) {
1262     kit.C->log()->elem("l2n_intrinsification_success bci='%d' entry_point='" INTPTR_FORMAT "'", jvms->bci(), p2i(_call_addr));
1263   }
1264 
1265   return kit.transfer_exceptions_into_jvms();
1266 }
1267 
1268 CallGenerator* CallGenerator::for_method_handle_inline(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool allow_inline, bool& input_not_const) {
1269   GraphKit kit(jvms);
1270   PhaseGVN& gvn = kit.gvn();
1271   Compile* C = kit.C;
1272   vmIntrinsics::ID iid = callee->intrinsic_id();
1273   input_not_const = true;
1274   if (StressMethodHandleLinkerInlining) {
1275     allow_inline = false;
1276   }
1277   switch (iid) {
1278   case vmIntrinsics::_invokeBasic:
1279     {
1280       // Get MethodHandle receiver:
1281       Node* receiver = kit.argument(0);
1282       if (receiver->Opcode() == Op_ConP) {
1283         input_not_const = false;
1284         const TypeOopPtr* oop_ptr = receiver->bottom_type()->is_oopptr();
1285         ciMethod* target = oop_ptr->const_oop()->as_method_handle()->get_vmtarget();
1286         const int vtable_index = Method::invalid_vtable_index;
1287 
1288         if (!ciMethod::is_consistent_info(callee, target)) {
1289           print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
1290                                  "signatures mismatch");
1291           return NULL;
1292         }
1293 
1294         CallGenerator* cg = C->call_generator(target, vtable_index,
1295                                               false /* call_does_dispatch */,
1296                                               jvms,
1297                                               allow_inline,
1298                                               PROB_ALWAYS,
1299                                               NULL,
1300                                               true);
1301         return cg;
1302       } else {
1303         print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
1304                                "receiver not constant");
1305       }
1306     }
1307     break;
1308 
1309   case vmIntrinsics::_linkToVirtual:
1310   case vmIntrinsics::_linkToStatic:
1311   case vmIntrinsics::_linkToSpecial:
1312   case vmIntrinsics::_linkToInterface:
1313     {
1314       int nargs = callee->arg_size();
1315       // Get MemberName argument:
1316       Node* member_name = kit.argument(nargs - 1);
1317       if (member_name->Opcode() == Op_ConP) {
1318         input_not_const = false;
1319         const TypeOopPtr* oop_ptr = member_name->bottom_type()->is_oopptr();
1320         ciMethod* target = oop_ptr->const_oop()->as_member_name()->get_vmtarget();
1321 
1322         if (!ciMethod::is_consistent_info(callee, target)) {
1323           print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
1324                                  "signatures mismatch");
1325           return NULL;
1326         }
1327 
1328         // In lambda forms we erase signature types to avoid resolving issues
1329         // involving class loaders.  When we optimize a method handle invoke
1330         // to a direct call we must cast the receiver and arguments to its
1331         // actual types.
1332         ciSignature* signature = target->signature();
1333         const int receiver_skip = target->is_static() ? 0 : 1;
1334         // Cast receiver to its type.
1335         if (!target->is_static()) {
1336           cast_argument(nargs, 0, signature->accessing_klass(), kit, false);
1337         }
1338         // Cast reference arguments to its type.
1339         for (int i = 0, j = 0; i < signature->count(); i++) {
1340           ciType* t = signature->type_at(i);
1341           if (t->is_klass()) {
1342             bool null_free = signature->is_null_free_at(i);
1343             cast_argument(nargs, receiver_skip + j, t, kit, null_free);
1344           }
1345           j += t->size();  // long and double take two slots
1346         }
1347 
1348         // Try to get the most accurate receiver type
1349         const bool is_virtual              = (iid == vmIntrinsics::_linkToVirtual);
1350         const bool is_virtual_or_interface = (is_virtual || iid == vmIntrinsics::_linkToInterface);
1351         int  vtable_index       = Method::invalid_vtable_index;
1352         bool call_does_dispatch = false;
1353 
1354         ciKlass* speculative_receiver_type = NULL;
1355         if (is_virtual_or_interface) {
1356           ciInstanceKlass* klass = target->holder();
1357           Node*             receiver_node = kit.argument(0);
1358           const TypeOopPtr* receiver_type = gvn.type(receiver_node)->isa_oopptr();
1359           // call_does_dispatch and vtable_index are out-parameters.  They might be changed.
1360           // optimize_virtual_call() takes 2 different holder
1361           // arguments for a corner case that doesn't apply here (see
1362           // Parse::do_call())
1363           target = C->optimize_virtual_call(caller, klass, klass,
1364                                             target, receiver_type, is_virtual,
1365                                             call_does_dispatch, vtable_index, // out-parameters
1366                                             false /* check_access */);
1367           // We lack profiling at this call but type speculation may
1368           // provide us with a type
1369           speculative_receiver_type = (receiver_type != NULL) ? receiver_type->speculative_type() : NULL;
1370         }
1371         CallGenerator* cg = C->call_generator(target, vtable_index, call_does_dispatch, jvms,
1372                                               allow_inline,
1373                                               PROB_ALWAYS,
1374                                               speculative_receiver_type,
1375                                               true);
1376         return cg;
1377       } else {
1378         print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
1379                                "member_name not constant");
1380       }
1381     }
1382     break;
1383 
1384     case vmIntrinsics::_linkToNative:
1385     {
1386       Node* addr_n = kit.argument(1); // target address
1387       Node* nep_n = kit.argument(callee->arg_size() - 1); // NativeEntryPoint
1388       // This check needs to be kept in sync with the one in CallStaticJavaNode::Ideal
1389       if (addr_n->Opcode() == Op_ConL && nep_n->Opcode() == Op_ConP) {
1390         input_not_const = false;
1391         const TypeLong* addr_t = addr_n->bottom_type()->is_long();
1392         const TypeOopPtr* nep_t = nep_n->bottom_type()->is_oopptr();
1393         address addr = (address) addr_t->get_con();
1394         ciNativeEntryPoint* nep = nep_t->const_oop()->as_native_entry_point();
1395         return new NativeCallGenerator(callee, addr, nep);
1396       } else {
1397         print_inlining_failure(C, callee, jvms->depth() - 1, jvms->bci(),
1398                                "NativeEntryPoint not constant");
1399       }
1400     }
1401     break;
1402 
1403   default:
1404     fatal("unexpected intrinsic %d: %s", vmIntrinsics::as_int(iid), vmIntrinsics::name_at(iid));
1405     break;
1406   }
1407   return NULL;
1408 }
1409 
1410 
1411 //------------------------PredicatedIntrinsicGenerator------------------------------
1412 // Internal class which handles all predicated Intrinsic calls.
1413 class PredicatedIntrinsicGenerator : public CallGenerator {
1414   CallGenerator* _intrinsic;
1415   CallGenerator* _cg;
1416 
1417 public:
1418   PredicatedIntrinsicGenerator(CallGenerator* intrinsic,
1419                                CallGenerator* cg)
1420     : CallGenerator(cg->method())
1421   {
1422     _intrinsic = intrinsic;
1423     _cg        = cg;
1424   }
1425 
1426   virtual bool      is_virtual()   const    { return true; }
1427   virtual bool      is_inline()    const    { return true; }
1428   virtual bool      is_intrinsic() const    { return true; }
1429 
1430   virtual JVMState* generate(JVMState* jvms);
1431 };
1432 
1433 
1434 CallGenerator* CallGenerator::for_predicated_intrinsic(CallGenerator* intrinsic,
1435                                                        CallGenerator* cg) {
1436   return new PredicatedIntrinsicGenerator(intrinsic, cg);
1437 }
1438 
1439 
1440 JVMState* PredicatedIntrinsicGenerator::generate(JVMState* jvms) {
1441   // The code we want to generate here is:
1442   //    if (receiver == NULL)
1443   //        uncommon_Trap
1444   //    if (predicate(0))
1445   //        do_intrinsic(0)
1446   //    else
1447   //    if (predicate(1))
1448   //        do_intrinsic(1)
1449   //    ...
1450   //    else
1451   //        do_java_comp
1452 
1453   GraphKit kit(jvms);
1454   PhaseGVN& gvn = kit.gvn();
1455 
1456   CompileLog* log = kit.C->log();
1457   if (log != NULL) {
1458     log->elem("predicated_intrinsic bci='%d' method='%d'",
1459               jvms->bci(), log->identify(method()));
1460   }
1461 
1462   if (!method()->is_static()) {
1463     // We need an explicit receiver null_check before checking its type in predicate.
1464     // We share a map with the caller, so his JVMS gets adjusted.
1465     kit.null_check_receiver_before_call(method());
1466     if (kit.stopped()) {
1467       return kit.transfer_exceptions_into_jvms();
1468     }
1469   }
1470 
1471   int n_predicates = _intrinsic->predicates_count();
1472   assert(n_predicates > 0, "sanity");
1473 
1474   JVMState** result_jvms = NEW_RESOURCE_ARRAY(JVMState*, (n_predicates+1));
1475 
1476   // Region for normal compilation code if intrinsic failed.
1477   Node* slow_region = new RegionNode(1);
1478 
1479   int results = 0;
1480   for (int predicate = 0; (predicate < n_predicates) && !kit.stopped(); predicate++) {
1481 #ifdef ASSERT
1482     JVMState* old_jvms = kit.jvms();
1483     SafePointNode* old_map = kit.map();
1484     Node* old_io  = old_map->i_o();
1485     Node* old_mem = old_map->memory();
1486     Node* old_exc = old_map->next_exception();
1487 #endif
1488     Node* else_ctrl = _intrinsic->generate_predicate(kit.sync_jvms(), predicate);
1489 #ifdef ASSERT
1490     // Assert(no_new_memory && no_new_io && no_new_exceptions) after generate_predicate.
1491     assert(old_jvms == kit.jvms(), "generate_predicate should not change jvm state");
1492     SafePointNode* new_map = kit.map();
1493     assert(old_io  == new_map->i_o(), "generate_predicate should not change i_o");
1494     assert(old_mem == new_map->memory(), "generate_predicate should not change memory");
1495     assert(old_exc == new_map->next_exception(), "generate_predicate should not add exceptions");
1496 #endif
1497     if (!kit.stopped()) {
1498       PreserveJVMState pjvms(&kit);
1499       // Generate intrinsic code:
1500       JVMState* new_jvms = _intrinsic->generate(kit.sync_jvms());
1501       if (new_jvms == NULL) {
1502         // Intrinsic failed, use normal compilation path for this predicate.
1503         slow_region->add_req(kit.control());
1504       } else {
1505         kit.add_exception_states_from(new_jvms);
1506         kit.set_jvms(new_jvms);
1507         if (!kit.stopped()) {
1508           result_jvms[results++] = kit.jvms();
1509         }
1510       }
1511     }
1512     if (else_ctrl == NULL) {
1513       else_ctrl = kit.C->top();
1514     }
1515     kit.set_control(else_ctrl);
1516   }
1517   if (!kit.stopped()) {
1518     // Final 'else' after predicates.
1519     slow_region->add_req(kit.control());
1520   }
1521   if (slow_region->req() > 1) {
1522     PreserveJVMState pjvms(&kit);
1523     // Generate normal compilation code:
1524     kit.set_control(gvn.transform(slow_region));
1525     JVMState* new_jvms = _cg->generate(kit.sync_jvms());
1526     if (kit.failing())
1527       return NULL;  // might happen because of NodeCountInliningCutoff
1528     assert(new_jvms != NULL, "must be");
1529     kit.add_exception_states_from(new_jvms);
1530     kit.set_jvms(new_jvms);
1531     if (!kit.stopped()) {
1532       result_jvms[results++] = kit.jvms();
1533     }
1534   }
1535 
1536   if (results == 0) {
1537     // All paths ended in uncommon traps.
1538     (void) kit.stop();
1539     return kit.transfer_exceptions_into_jvms();
1540   }
1541 
1542   if (results == 1) { // Only one path
1543     kit.set_jvms(result_jvms[0]);
1544     return kit.transfer_exceptions_into_jvms();
1545   }
1546 
1547   // Merge all paths.
1548   kit.C->set_has_split_ifs(true); // Has chance for split-if optimization
1549   RegionNode* region = new RegionNode(results + 1);
1550   Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO);
1551   for (int i = 0; i < results; i++) {
1552     JVMState* jvms = result_jvms[i];
1553     int path = i + 1;
1554     SafePointNode* map = jvms->map();
1555     region->init_req(path, map->control());
1556     iophi->set_req(path, map->i_o());
1557     if (i == 0) {
1558       kit.set_jvms(jvms);
1559     } else {
1560       kit.merge_memory(map->merged_memory(), region, path);
1561     }
1562   }
1563   kit.set_control(gvn.transform(region));
1564   kit.set_i_o(gvn.transform(iophi));
1565   // Transform new memory Phis.
1566   for (MergeMemStream mms(kit.merged_memory()); mms.next_non_empty();) {
1567     Node* phi = mms.memory();
1568     if (phi->is_Phi() && phi->in(0) == region) {
1569       mms.set_memory(gvn.transform(phi));
1570     }
1571   }
1572 
1573   // Merge debug info.
1574   Node** ins = NEW_RESOURCE_ARRAY(Node*, results);
1575   uint tos = kit.jvms()->stkoff() + kit.sp();
1576   Node* map = kit.map();
1577   uint limit = map->req();
1578   for (uint i = TypeFunc::Parms; i < limit; i++) {
1579     // Skip unused stack slots; fast forward to monoff();
1580     if (i == tos) {
1581       i = kit.jvms()->monoff();
1582       if( i >= limit ) break;
1583     }
1584     Node* n = map->in(i);
1585     ins[0] = n;
1586     const Type* t = gvn.type(n);
1587     bool needs_phi = false;
1588     for (int j = 1; j < results; j++) {
1589       JVMState* jvms = result_jvms[j];
1590       Node* jmap = jvms->map();
1591       Node* m = NULL;
1592       if (jmap->req() > i) {
1593         m = jmap->in(i);
1594         if (m != n) {
1595           needs_phi = true;
1596           t = t->meet_speculative(gvn.type(m));
1597         }
1598       }
1599       ins[j] = m;
1600     }
1601     if (needs_phi) {
1602       Node* phi = PhiNode::make(region, n, t);
1603       for (int j = 1; j < results; j++) {
1604         phi->set_req(j + 1, ins[j]);
1605       }
1606       map->set_req(i, gvn.transform(phi));
1607     }
1608   }
1609 
1610   return kit.transfer_exceptions_into_jvms();
1611 }
1612 
1613 //-------------------------UncommonTrapCallGenerator-----------------------------
1614 // Internal class which handles all out-of-line calls checking receiver type.
1615 class UncommonTrapCallGenerator : public CallGenerator {
1616   Deoptimization::DeoptReason _reason;
1617   Deoptimization::DeoptAction _action;
1618 
1619 public:
1620   UncommonTrapCallGenerator(ciMethod* m,
1621                             Deoptimization::DeoptReason reason,
1622                             Deoptimization::DeoptAction action)
1623     : CallGenerator(m)
1624   {
1625     _reason = reason;
1626     _action = action;
1627   }
1628 
1629   virtual bool      is_virtual() const          { ShouldNotReachHere(); return false; }
1630   virtual bool      is_trap() const             { return true; }
1631 
1632   virtual JVMState* generate(JVMState* jvms);
1633 };
1634 
1635 
1636 CallGenerator*
1637 CallGenerator::for_uncommon_trap(ciMethod* m,
1638                                  Deoptimization::DeoptReason reason,
1639                                  Deoptimization::DeoptAction action) {
1640   return new UncommonTrapCallGenerator(m, reason, action);
1641 }
1642 
1643 
1644 JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) {
1645   GraphKit kit(jvms);
1646   kit.C->print_inlining_update(this);
1647   // Take the trap with arguments pushed on the stack.  (Cf. null_check_receiver).
1648   // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
1649   // Use callsite signature always.
1650   ciMethod* declared_method = kit.method()->get_method_at_bci(kit.bci());
1651   int nargs = declared_method->arg_size();
1652   kit.inc_sp(nargs);
1653   assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed");
1654   if (_reason == Deoptimization::Reason_class_check &&
1655       _action == Deoptimization::Action_maybe_recompile) {
1656     // Temp fix for 6529811
1657     // Don't allow uncommon_trap to override our decision to recompile in the event
1658     // of a class cast failure for a monomorphic call as it will never let us convert
1659     // the call to either bi-morphic or megamorphic and can lead to unc-trap loops
1660     bool keep_exact_action = true;
1661     kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action);
1662   } else {
1663     kit.uncommon_trap(_reason, _action);
1664   }
1665   return kit.transfer_exceptions_into_jvms();
1666 }
1667 
1668 // (Note:  Moved hook_up_call to GraphKit::set_edges_for_java_call.)
1669 
1670 // (Node:  Merged hook_up_exits into ParseGenerator::generate.)