< prev index next >

src/hotspot/share/opto/parse1.cpp

Print this page

  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 "compiler/compileLog.hpp"
  26 #include "interpreter/linkResolver.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "oops/method.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/c2compiler.hpp"
  31 #include "opto/castnode.hpp"

  32 #include "opto/idealGraphPrinter.hpp"

  33 #include "opto/locknode.hpp"
  34 #include "opto/memnode.hpp"
  35 #include "opto/opaquenode.hpp"
  36 #include "opto/parse.hpp"
  37 #include "opto/rootnode.hpp"
  38 #include "opto/runtime.hpp"
  39 #include "opto/type.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/safepointMechanism.hpp"
  42 #include "runtime/sharedRuntime.hpp"
  43 #include "utilities/bitMap.inline.hpp"
  44 #include "utilities/copy.hpp"
  45 
  46 // Static array so we can figure out which bytecodes stop us from compiling
  47 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
  48 // and eventually should be encapsulated in a proper class (gri 8/18/98).
  49 
  50 #ifndef PRODUCT
  51 uint nodes_created             = 0;
  52 uint methods_parsed            = 0;

  84   }
  85   if (all_null_checks_found) {
  86     tty->print_cr("%u made implicit (%2u%%)", implicit_null_checks,
  87                   (100*implicit_null_checks)/all_null_checks_found);
  88   }
  89   if (SharedRuntime::_implicit_null_throws) {
  90     tty->print_cr("%u implicit null exceptions at runtime",
  91                   SharedRuntime::_implicit_null_throws);
  92   }
  93 
  94   if (PrintParseStatistics && BytecodeParseHistogram::initialized()) {
  95     BytecodeParseHistogram::print();
  96   }
  97 }
  98 #endif
  99 
 100 //------------------------------ON STACK REPLACEMENT---------------------------
 101 
 102 // Construct a node which can be used to get incoming state for
 103 // on stack replacement.
 104 Node *Parse::fetch_interpreter_state(int index,
 105                                      BasicType bt,
 106                                      Node *local_addrs,
 107                                      Node *local_addrs_base) {






 108   Node *mem = memory(Compile::AliasIdxRaw);
 109   Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize );
 110   Node *ctl = control();
 111 
 112   // Very similar to LoadNode::make, except we handle un-aligned longs and
 113   // doubles on Sparc.  Intel can handle them just fine directly.
 114   Node *l = nullptr;
 115   switch (bt) {                // Signature is flattened
 116   case T_INT:     l = new LoadINode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInt::INT,        MemNode::unordered); break;
 117   case T_FLOAT:   l = new LoadFNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::FLOAT,         MemNode::unordered); break;
 118   case T_ADDRESS: l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM,  MemNode::unordered); break;
 119   case T_OBJECT:  l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM, MemNode::unordered); break;
 120   case T_LONG:
 121   case T_DOUBLE: {
 122     // Since arguments are in reverse order, the argument address 'adr'
 123     // refers to the back half of the long/double.  Recompute adr.
 124     adr = basic_plus_adr(local_addrs_base, local_addrs, -(index+1)*wordSize);
 125     if (Matcher::misaligned_doubles_ok) {
 126       l = (bt == T_DOUBLE)
 127         ? (Node*)new LoadDNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::DOUBLE, MemNode::unordered)

 129     } else {
 130       l = (bt == T_DOUBLE)
 131         ? (Node*)new LoadD_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered)
 132         : (Node*)new LoadL_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered);
 133     }
 134     break;
 135   }
 136   default: ShouldNotReachHere();
 137   }
 138   return _gvn.transform(l);
 139 }
 140 
 141 // Helper routine to prevent the interpreter from handing
 142 // unexpected typestate to an OSR method.
 143 // The Node l is a value newly dug out of the interpreter frame.
 144 // The type is the type predicted by ciTypeFlow.  Note that it is
 145 // not a general type, but can only come from Type::get_typeflow_type.
 146 // The safepoint is a map which will feed an uncommon trap.
 147 Node* Parse::check_interpreter_type(Node* l, const Type* type,
 148                                     SafePointNode* &bad_type_exit) {
 149 
 150   const TypeOopPtr* tp = type->isa_oopptr();
 151 
 152   // TypeFlow may assert null-ness if a type appears unloaded.
 153   if (type == TypePtr::NULL_PTR ||
 154       (tp != nullptr && !tp->is_loaded())) {
 155     // Value must be null, not a real oop.
 156     Node* chk = _gvn.transform( new CmpPNode(l, null()) );
 157     Node* tst = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
 158     IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
 159     set_control(_gvn.transform( new IfTrueNode(iff) ));
 160     Node* bad_type = _gvn.transform( new IfFalseNode(iff) );
 161     bad_type_exit->control()->add_req(bad_type);
 162     l = null();
 163   }
 164 
 165   // Typeflow can also cut off paths from the CFG, based on
 166   // types which appear unloaded, or call sites which appear unlinked.
 167   // When paths are cut off, values at later merge points can rise
 168   // toward more specific classes.  Make sure these specific classes
 169   // are still in effect.
 170   if (tp != nullptr && !tp->is_same_java_type_as(TypeInstPtr::BOTTOM)) {
 171     // TypeFlow asserted a specific object type.  Value must have that type.
 172     Node* bad_type_ctrl = nullptr;






 173     l = gen_checkcast(l, makecon(tp->as_klass_type()->cast_to_exactness(true)), &bad_type_ctrl);
 174     bad_type_exit->control()->add_req(bad_type_ctrl);
 175   }
 176 
 177   assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate");
 178   return l;
 179 }
 180 
 181 // Helper routine which sets up elements of the initial parser map when
 182 // performing a parse for on stack replacement.  Add values into map.
 183 // The only parameter contains the address of a interpreter arguments.
 184 void Parse::load_interpreter_state(Node* osr_buf) {
 185   int index;
 186   int max_locals = jvms()->loc_size();
 187   int max_stack  = jvms()->stk_size();
 188 
 189 
 190   // Mismatch between method and jvms can occur since map briefly held
 191   // an OSR entry state (which takes up one RawPtr word).
 192   assert(max_locals == method()->max_locals(), "sanity");
 193   assert(max_stack  >= method()->max_stack(),  "sanity");
 194   assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity");
 195   assert((int)jvms()->endoff() == (int)map()->req(), "sanity");
 196 
 197   // Find the start block.
 198   Block* osr_block = start_block();
 199   assert(osr_block->start() == osr_bci(), "sanity");
 200 
 201   // Set initial BCI.
 202   set_parse_bci(osr_block->start());
 203 
 204   // Set initial stack depth.
 205   set_sp(osr_block->start_sp());
 206 
 207   // Check bailouts.  We currently do not perform on stack replacement
 208   // of loops in catch blocks or loops which branch with a non-empty stack.
 209   if (sp() != 0) {

 224   for (index = 0; index < mcnt; index++) {
 225     // Make a BoxLockNode for the monitor.
 226     BoxLockNode* osr_box = new BoxLockNode(next_monitor());
 227     // Check for bailout after new BoxLockNode
 228     if (failing()) { return; }
 229 
 230     // This OSR locking region is unbalanced because it does not have Lock node:
 231     // locking was done in Interpreter.
 232     // This is similar to Coarsened case when Lock node is eliminated
 233     // and as result the region is marked as Unbalanced.
 234 
 235     // Emulate Coarsened state transition from Regular to Unbalanced.
 236     osr_box->set_coarsened();
 237     osr_box->set_unbalanced();
 238 
 239     Node* box = _gvn.transform(osr_box);
 240 
 241     // Displaced headers and locked objects are interleaved in the
 242     // temp OSR buffer.  We only copy the locked objects out here.
 243     // Fetch the locked object from the OSR temp buffer and copy to our fastlock node.
 244     Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf);
 245     // Try and copy the displaced header to the BoxNode
 246     Node *displaced_hdr = fetch_interpreter_state((index*2) + 1, T_ADDRESS, monitors_addr, osr_buf);
 247 
 248 
 249     store_to_memory(control(), box, displaced_hdr, T_ADDRESS, MemNode::unordered);
 250 
 251     // Build a bogus FastLockNode (no code will be generated) and push the
 252     // monitor into our debug info.
 253     const FastLockNode *flock = _gvn.transform(new FastLockNode( nullptr, lock_object, box ))->as_FastLock();
 254     map()->push_monitor(flock);
 255 
 256     // If the lock is our method synchronization lock, tuck it away in
 257     // _sync_lock for return and rethrow exit paths.
 258     if (index == 0 && method()->is_synchronized()) {
 259       _synch_lock = flock;
 260     }
 261   }
 262 
 263   // Use the raw liveness computation to make sure that unexpected
 264   // values don't propagate into the OSR frame.
 265   MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
 266   if (!live_locals.is_valid()) {
 267     // Degenerate or breakpointed method.

 295         if (C->log() != nullptr) {
 296           C->log()->elem("OSR_mismatch local_index='%d'",index);
 297         }
 298         set_local(index, null());
 299         // and ignore it for the loads
 300         continue;
 301       }
 302     }
 303 
 304     // Filter out TOP, HALF, and BOTTOM.  (Cf. ensure_phi.)
 305     if (type == Type::TOP || type == Type::HALF) {
 306       continue;
 307     }
 308     // If the type falls to bottom, then this must be a local that
 309     // is mixing ints and oops or some such.  Forcing it to top
 310     // makes it go dead.
 311     if (type == Type::BOTTOM) {
 312       continue;
 313     }
 314     // Construct code to access the appropriate local.
 315     BasicType bt = type->basic_type();
 316     if (type == TypePtr::NULL_PTR) {
 317       // Ptr types are mixed together with T_ADDRESS but null is
 318       // really for T_OBJECT types so correct it.
 319       bt = T_OBJECT;
 320     }
 321     Node *value = fetch_interpreter_state(index, bt, locals_addr, osr_buf);
 322     set_local(index, value);
 323   }
 324 
 325   // Extract the needed stack entries from the interpreter frame.
 326   for (index = 0; index < sp(); index++) {
 327     const Type *type = osr_block->stack_type_at(index);
 328     if (type != Type::TOP) {
 329       // Currently the compiler bails out when attempting to on stack replace
 330       // at a bci with a non-empty stack.  We should not reach here.
 331       ShouldNotReachHere();
 332     }
 333   }
 334 
 335   // End the OSR migration
 336   make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(),
 337                     CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
 338                     "OSR_migration_end", TypeRawPtr::BOTTOM,
 339                     osr_buf);
 340 
 341   // Now that the interpreter state is loaded, make sure it will match

 501   // either breakpoint setting or hotswapping of methods may
 502   // cause deoptimization.
 503   if (C->env()->jvmti_can_hotswap_or_post_breakpoint()) {
 504     C->dependencies()->assert_evol_method(method());
 505   }
 506 
 507   NOT_PRODUCT(methods_seen++);
 508 
 509   // Do some special top-level things.
 510   if (depth() == 1 && C->is_osr_compilation()) {
 511     _tf = C->tf();     // the OSR entry type is different
 512     _entry_bci = C->entry_bci();
 513     _flow = method()->get_osr_flow_analysis(osr_bci());
 514   } else {
 515     _tf = TypeFunc::make(method());
 516     _entry_bci = InvocationEntryBci;
 517     _flow = method()->get_flow_analysis();
 518   }
 519 
 520   if (_flow->failing()) {
 521     assert(false, "type flow analysis failed during parsing");


 522     C->record_method_not_compilable(_flow->failure_reason());
 523 #ifndef PRODUCT
 524       if (PrintOpto && (Verbose || WizardMode)) {
 525         if (is_osr_parse()) {
 526           tty->print_cr("OSR @%d type flow bailout: %s", _entry_bci, _flow->failure_reason());
 527         } else {
 528           tty->print_cr("type flow bailout: %s", _flow->failure_reason());
 529         }
 530         if (Verbose) {
 531           method()->print();
 532           method()->print_codes();
 533           _flow->print();
 534         }
 535       }
 536 #endif
 537   }
 538 
 539 #ifdef ASSERT
 540   if (depth() == 1) {
 541     assert(C->is_osr_compilation() == this->is_osr_parse(), "OSR in sync");

 592     load_interpreter_state(osr_buf);
 593   } else {
 594     set_map(entry_map);
 595     do_method_entry();
 596   }
 597 
 598   if (depth() == 1 && !failing()) {
 599     if (C->clinit_barrier_on_entry()) {
 600       // Add check to deoptimize the nmethod once the holder class is fully initialized
 601       clinit_deopt();
 602     }
 603   }
 604 
 605   // Check for bailouts during method entry.
 606   if (failing()) {
 607     if (log)  log->done("parse");
 608     C->set_default_node_notes(caller_nn);
 609     return;
 610   }
 611 























 612   entry_map = map();  // capture any changes performed by method setup code
 613   assert(jvms()->endoff() == map()->req(), "map matches JVMS layout");
 614 
 615   // We begin parsing as if we have just encountered a jump to the
 616   // method entry.
 617   Block* entry_block = start_block();
 618   assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), "");
 619   set_map_clone(entry_map);
 620   merge_common(entry_block, entry_block->next_path_num());
 621 
 622 #ifndef PRODUCT
 623   BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C);
 624   set_parse_histogram( parse_histogram_obj );
 625 #endif
 626 
 627   // Parse all the basic blocks.
 628   do_all_blocks();
 629 
 630   // Check for bailouts during conversion to graph
 631   if (failing()) {

 777 void Parse::build_exits() {
 778   // make a clone of caller to prevent sharing of side-effects
 779   _exits.set_map(_exits.clone_map());
 780   _exits.clean_stack(_exits.sp());
 781   _exits.sync_jvms();
 782 
 783   RegionNode* region = new RegionNode(1);
 784   record_for_igvn(region);
 785   gvn().set_type_bottom(region);
 786   _exits.set_control(region);
 787 
 788   // Note:  iophi and memphi are not transformed until do_exits.
 789   Node* iophi  = new PhiNode(region, Type::ABIO);
 790   Node* memphi = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 791   gvn().set_type_bottom(iophi);
 792   gvn().set_type_bottom(memphi);
 793   _exits.set_i_o(iophi);
 794   _exits.set_all_memory(memphi);
 795 
 796   // Add a return value to the exit state.  (Do not push it yet.)
 797   if (tf()->range()->cnt() > TypeFunc::Parms) {
 798     const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms);
 799     if (ret_type->isa_int()) {
 800       BasicType ret_bt = method()->return_type()->basic_type();
 801       if (ret_bt == T_BOOLEAN ||
 802           ret_bt == T_CHAR ||
 803           ret_bt == T_BYTE ||
 804           ret_bt == T_SHORT) {
 805         ret_type = TypeInt::INT;
 806       }
 807     }
 808 
 809     // Don't "bind" an unloaded return klass to the ret_phi. If the klass
 810     // becomes loaded during the subsequent parsing, the loaded and unloaded
 811     // types will not join when we transform and push in do_exits().
 812     const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr();
 813     if (ret_oop_type && !ret_oop_type->is_loaded()) {
 814       ret_type = TypeOopPtr::BOTTOM;
 815     }
 816     int         ret_size = type2size[ret_type->basic_type()];
 817     Node*       ret_phi  = new PhiNode(region, ret_type);
 818     gvn().set_type_bottom(ret_phi);
 819     _exits.ensure_stack(ret_size);
 820     assert((int)(tf()->range()->cnt() - TypeFunc::Parms) == ret_size, "good tf range");
 821     assert(method()->return_type()->size() == ret_size, "tf agrees w/ method");
 822     _exits.set_argument(0, ret_phi);  // here is where the parser finds it
 823     // Note:  ret_phi is not yet pushed, until do_exits.
 824   }
 825 }
 826 
 827 
 828 //----------------------------build_start_state-------------------------------
 829 // Construct a state which contains only the incoming arguments from an
 830 // unknown caller.  The method & bci will be null & InvocationEntryBci.
 831 JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) {
 832   int        arg_size = tf->domain()->cnt();
 833   int        max_size = MAX2(arg_size, (int)tf->range()->cnt());
 834   JVMState*  jvms     = new (this) JVMState(max_size - TypeFunc::Parms);
 835   SafePointNode* map  = new SafePointNode(max_size, jvms);

 836   record_for_igvn(map);
 837   assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size");
 838   Node_Notes* old_nn = default_node_notes();
 839   if (old_nn != nullptr && has_method()) {
 840     Node_Notes* entry_nn = old_nn->clone(this);
 841     JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms());
 842     entry_jvms->set_offsets(0);
 843     entry_jvms->set_bci(entry_bci());
 844     entry_nn->set_jvms(entry_jvms);
 845     set_default_node_notes(entry_nn);
 846   }
 847   uint i;
 848   for (i = 0; i < (uint)arg_size; i++) {
 849     Node* parm = initial_gvn()->transform(new ParmNode(start, i));

















 850     map->init_req(i, parm);
 851     // Record all these guys for later GVN.
 852     record_for_igvn(parm);



 853   }
 854   for (; i < map->req(); i++) {
 855     map->init_req(i, top());
 856   }
 857   assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here");
 858   set_default_node_notes(old_nn);
 859   jvms->set_map(map);
 860   return jvms;
 861 }
 862 
 863 //-----------------------------make_node_notes---------------------------------
 864 Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) {
 865   if (caller_nn == nullptr)  return nullptr;
 866   Node_Notes* nn = caller_nn->clone(C);
 867   JVMState* caller_jvms = nn->jvms();
 868   JVMState* jvms = new (C) JVMState(method(), caller_jvms);
 869   jvms->set_offsets(0);
 870   jvms->set_bci(_entry_bci);
 871   nn->set_jvms(jvms);
 872   return nn;
 873 }
 874 
 875 
 876 //--------------------------return_values--------------------------------------
 877 void Compile::return_values(JVMState* jvms) {
 878   GraphKit kit(jvms);
 879   Node* ret = new ReturnNode(TypeFunc::Parms,
 880                              kit.control(),
 881                              kit.i_o(),
 882                              kit.reset_memory(),
 883                              kit.frameptr(),
 884                              kit.returnadr());
 885   // Add zero or 1 return values
 886   int ret_size = tf()->range()->cnt() - TypeFunc::Parms;
 887   if (ret_size > 0) {
 888     kit.inc_sp(-ret_size);  // pop the return value(s)
 889     kit.sync_jvms();
 890     ret->add_req(kit.argument(0));
 891     // Note:  The second dummy edge is not needed by a ReturnNode.






















 892   }
 893   // bind it to root
 894   root()->add_req(ret);
 895   record_for_igvn(ret);
 896   initial_gvn()->transform(ret);
 897 }
 898 
 899 //------------------------rethrow_exceptions-----------------------------------
 900 // Bind all exception states in the list into a single RethrowNode.
 901 void Compile::rethrow_exceptions(JVMState* jvms) {
 902   GraphKit kit(jvms);
 903   if (!kit.has_exceptions())  return;  // nothing to generate
 904   // Load my combined exception state into the kit, with all phis transformed:
 905   SafePointNode* ex_map = kit.combine_and_pop_all_exception_states();
 906   Node* ex_oop = kit.use_exception_state(ex_map);
 907   RethrowNode* exit = new RethrowNode(kit.control(),
 908                                       kit.i_o(), kit.reset_memory(),
 909                                       kit.frameptr(), kit.returnadr(),
 910                                       // like a return but with exception input
 911                                       ex_oop);

 995   //    to complete, we force all writes to complete.
 996   //
 997   // 2. Experimental VM option is used to force the barrier if any field
 998   //    was written out in the constructor.
 999   //
1000   // 3. On processors which are not CPU_MULTI_COPY_ATOMIC (e.g. PPC64),
1001   //    support_IRIW_for_not_multiple_copy_atomic_cpu selects that
1002   //    MemBarVolatile is used before volatile load instead of after volatile
1003   //    store, so there's no barrier after the store.
1004   //    We want to guarantee the same behavior as on platforms with total store
1005   //    order, although this is not required by the Java memory model.
1006   //    In this case, we want to enforce visibility of volatile field
1007   //    initializations which are performed in constructors.
1008   //    So as with finals, we add a barrier here.
1009   //
1010   // "All bets are off" unless the first publication occurs after a
1011   // normal return from the constructor.  We do not attempt to detect
1012   // such unusual early publications.  But no barrier is needed on
1013   // exceptional returns, since they cannot publish normally.
1014   //
1015   if (method()->is_object_initializer() &&
1016        (wrote_final() || wrote_stable() ||
1017          (AlwaysSafeConstructors && wrote_fields()) ||
1018          (support_IRIW_for_not_multiple_copy_atomic_cpu && wrote_volatile()))) {
1019     Node* recorded_alloc = alloc_with_final_or_stable();
1020     _exits.insert_mem_bar(UseStoreStoreForCtor ? Op_MemBarStoreStore : Op_MemBarRelease,
1021                           recorded_alloc);
1022 
1023     // If Memory barrier is created for final fields write
1024     // and allocation node does not escape the initialize method,
1025     // then barrier introduced by allocation node can be removed.
1026     if (DoEscapeAnalysis && (recorded_alloc != nullptr)) {
1027       AllocateNode* alloc = AllocateNode::Ideal_allocation(recorded_alloc);
1028       alloc->compute_MemBar_redundancy(method());
1029     }
1030     if (PrintOpto && (Verbose || WizardMode)) {
1031       method()->print_name();
1032       tty->print_cr(" writes finals/@Stable and needs a memory barrier");
1033     }
1034   }
1035 
1036   for (MergeMemStream mms(_exits.merged_memory()); mms.next_non_empty(); ) {
1037     // transform each slice of the original memphi:
1038     mms.set_memory(_gvn.transform(mms.memory()));
1039   }
1040   // Clean up input MergeMems created by transforming the slices
1041   _gvn.transform(_exits.merged_memory());
1042 
1043   if (tf()->range()->cnt() > TypeFunc::Parms) {
1044     const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms);
1045     Node*       ret_phi  = _gvn.transform( _exits.argument(0) );
1046     if (!_exits.control()->is_top() && _gvn.type(ret_phi)->empty()) {
1047       // If the type we set for the ret_phi in build_exits() is too optimistic and
1048       // the ret_phi is top now, there's an extremely small chance that it may be due to class
1049       // loading.  It could also be due to an error, so mark this method as not compilable because
1050       // otherwise this could lead to an infinite compile loop.
1051       // In any case, this code path is rarely (and never in my testing) reached.
1052       C->record_method_not_compilable("Can't determine return type.");
1053       return;
1054     }
1055     if (ret_type->isa_int()) {
1056       BasicType ret_bt = method()->return_type()->basic_type();
1057       ret_phi = mask_int_value(ret_phi, ret_bt, &_gvn);
1058     }
1059     _exits.push_node(ret_type->basic_type(), ret_phi);
1060   }
1061 
1062   // Note:  Logic for creating and optimizing the ReturnNode is in Compile.
1063 
1064   // Unlock along the exceptional paths.

1118 
1119 //-----------------------------create_entry_map-------------------------------
1120 // Initialize our parser map to contain the types at method entry.
1121 // For OSR, the map contains a single RawPtr parameter.
1122 // Initial monitor locking for sync. methods is performed by do_method_entry.
1123 SafePointNode* Parse::create_entry_map() {
1124   // Check for really stupid bail-out cases.
1125   uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1126   if (len >= 32760) {
1127     // Bailout expected, this is a very rare edge case.
1128     C->record_method_not_compilable("too many local variables");
1129     return nullptr;
1130   }
1131 
1132   // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1133   _caller->map()->delete_replaced_nodes();
1134 
1135   // If this is an inlined method, we may have to do a receiver null check.
1136   if (_caller->has_method() && is_normal_parse() && !method()->is_static()) {
1137     GraphKit kit(_caller);
1138     kit.null_check_receiver_before_call(method());

1139     _caller = kit.transfer_exceptions_into_jvms();





1140     if (kit.stopped()) {
1141       _exits.add_exception_states_from(_caller);
1142       _exits.set_jvms(_caller);
1143       return nullptr;
1144     }
1145   }
1146 
1147   assert(method() != nullptr, "parser must have a method");
1148 
1149   // Create an initial safepoint to hold JVM state during parsing
1150   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1151   set_map(new SafePointNode(len, jvms));
1152   jvms->set_map(map());
1153   record_for_igvn(map());
1154   assert(jvms->endoff() == len, "correct jvms sizing");
1155 
1156   SafePointNode* inmap = _caller->map();
1157   assert(inmap != nullptr, "must have inmap");
1158   // In case of null check on receiver above
1159   map()->transfer_replaced_nodes_from(inmap, _new_idx);
1160 
1161   uint i;
1162 
1163   // Pass thru the predefined input parameters.
1164   for (i = 0; i < TypeFunc::Parms; i++) {
1165     map()->init_req(i, inmap->in(i));
1166   }
1167 
1168   if (depth() == 1) {
1169     assert(map()->memory()->Opcode() == Op_Parm, "");
1170     // Insert the memory aliasing node
1171     set_all_memory(reset_memory());
1172   }
1173   assert(merged_memory(), "");
1174 
1175   // Now add the locals which are initially bound to arguments:
1176   uint arg_size = tf()->domain()->cnt();
1177   ensure_stack(arg_size - TypeFunc::Parms);  // OSR methods have funny args
1178   for (i = TypeFunc::Parms; i < arg_size; i++) {
1179     map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms));
1180   }
1181 
1182   // Clear out the rest of the map (locals and stack)
1183   for (i = arg_size; i < len; i++) {
1184     map()->init_req(i, top());
1185   }
1186 
1187   SafePointNode* entry_map = stop();
1188   return entry_map;
1189 }
1190 
1191 //-----------------------------do_method_entry--------------------------------
1192 // Emit any code needed in the pseudo-block before BCI zero.
1193 // The main thing to do is lock the receiver of a synchronized method.
1194 void Parse::do_method_entry() {
1195   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1196   set_sp(0);                         // Java Stack Pointer

1230 
1231   // If the method is synchronized, we need to construct a lock node, attach
1232   // it to the Start node, and pin it there.
1233   if (method()->is_synchronized()) {
1234     // Insert a FastLockNode right after the Start which takes as arguments
1235     // the current thread pointer, the "this" pointer & the address of the
1236     // stack slot pair used for the lock.  The "this" pointer is a projection
1237     // off the start node, but the locking spot has to be constructed by
1238     // creating a ConLNode of 0, and boxing it with a BoxLockNode.  The BoxLockNode
1239     // becomes the second argument to the FastLockNode call.  The
1240     // FastLockNode becomes the new control parent to pin it to the start.
1241 
1242     // Setup Object Pointer
1243     Node *lock_obj = nullptr;
1244     if (method()->is_static()) {
1245       ciInstance* mirror = _method->holder()->java_mirror();
1246       const TypeInstPtr *t_lock = TypeInstPtr::make(mirror);
1247       lock_obj = makecon(t_lock);
1248     } else {                  // Else pass the "this" pointer,
1249       lock_obj = local(0);    // which is Parm0 from StartNode

1250     }
1251     // Clear out dead values from the debug info.
1252     kill_dead_locals();
1253     // Build the FastLockNode
1254     _synch_lock = shared_lock(lock_obj);
1255     // Check for bailout in shared_lock
1256     if (failing()) { return; }
1257   }
1258 
1259   // Feed profiling data for parameters to the type system so it can
1260   // propagate it as speculative types
1261   record_profiled_parameters_for_speculation();
1262 }
1263 
1264 //------------------------------init_blocks------------------------------------
1265 // Initialize our parser map to contain the types/monitors at method entry.
1266 void Parse::init_blocks() {
1267   // Create the blocks.
1268   _block_count = flow()->block_count();
1269   _blocks = NEW_RESOURCE_ARRAY(Block, _block_count);

1665 //--------------------handle_missing_successor---------------------------------
1666 void Parse::handle_missing_successor(int target_bci) {
1667 #ifndef PRODUCT
1668   Block* b = block();
1669   int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1670   tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1671 #endif
1672   ShouldNotReachHere();
1673 }
1674 
1675 //--------------------------merge_common---------------------------------------
1676 void Parse::merge_common(Parse::Block* target, int pnum) {
1677   if (TraceOptoParse) {
1678     tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1679   }
1680 
1681   // Zap extra stack slots to top
1682   assert(sp() == target->start_sp(), "");
1683   clean_stack(sp());
1684 




































1685   if (!target->is_merged()) {   // No prior mapping at this bci
1686     if (TraceOptoParse) { tty->print(" with empty state");  }
1687 
1688     // If this path is dead, do not bother capturing it as a merge.
1689     // It is "as if" we had 1 fewer predecessors from the beginning.
1690     if (stopped()) {
1691       if (TraceOptoParse)  tty->print_cr(", but path is dead and doesn't count");
1692       return;
1693     }
1694 
1695     // Make a region if we know there are multiple or unpredictable inputs.
1696     // (Also, if this is a plain fall-through, we might see another region,
1697     // which must not be allowed into this block's map.)
1698     if (pnum > PhiNode::Input         // Known multiple inputs.
1699         || target->is_handler()       // These have unpredictable inputs.
1700         || target->is_loop_head()     // Known multiple inputs
1701         || control()->is_Region()) {  // We must hide this guy.
1702 
1703       int current_bci = bci();
1704       set_parse_bci(target->start()); // Set target bci

1719       record_for_igvn(r);
1720       // zap all inputs to null for debugging (done in Node(uint) constructor)
1721       // for (int j = 1; j < edges+1; j++) { r->init_req(j, nullptr); }
1722       r->init_req(pnum, control());
1723       set_control(r);
1724       target->copy_irreducible_status_to(r, jvms());
1725       set_parse_bci(current_bci); // Restore bci
1726     }
1727 
1728     // Convert the existing Parser mapping into a mapping at this bci.
1729     store_state_to(target);
1730     assert(target->is_merged(), "do not come here twice");
1731 
1732   } else {                      // Prior mapping at this bci
1733     if (TraceOptoParse) {  tty->print(" with previous state"); }
1734 #ifdef ASSERT
1735     if (target->is_SEL_head()) {
1736       target->mark_merged_backedge(block());
1737     }
1738 #endif

1739     // We must not manufacture more phis if the target is already parsed.
1740     bool nophi = target->is_parsed();
1741 
1742     SafePointNode* newin = map();// Hang on to incoming mapping
1743     Block* save_block = block(); // Hang on to incoming block;
1744     load_state_from(target);    // Get prior mapping
1745 
1746     assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree");
1747     assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree");
1748     assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree");
1749     assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree");
1750 
1751     // Iterate over my current mapping and the old mapping.
1752     // Where different, insert Phi functions.
1753     // Use any existing Phi functions.
1754     assert(control()->is_Region(), "must be merging to a region");
1755     RegionNode* r = control()->as_Region();
1756 
1757     // Compute where to merge into
1758     // Merge incoming control path
1759     r->init_req(pnum, newin->control());
1760 
1761     if (pnum == 1) {            // Last merge for this Region?
1762       if (!block()->flow()->is_irreducible_loop_secondary_entry()) {
1763         Node* result = _gvn.transform(r);
1764         if (r != result && TraceOptoParse) {
1765           tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1766         }
1767       }
1768       record_for_igvn(r);
1769     }
1770 
1771     // Update all the non-control inputs to map:
1772     assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1773     bool check_elide_phi = target->is_SEL_backedge(save_block);

1774     for (uint j = 1; j < newin->req(); j++) {
1775       Node* m = map()->in(j);   // Current state of target.
1776       Node* n = newin->in(j);   // Incoming change to target state.
1777       PhiNode* phi;
1778       if (m->is_Phi() && m->as_Phi()->region() == r)
1779         phi = m->as_Phi();
1780       else


1781         phi = nullptr;

1782       if (m != n) {             // Different; must merge
1783         switch (j) {
1784         // Frame pointer and Return Address never changes
1785         case TypeFunc::FramePtr:// Drop m, use the original value
1786         case TypeFunc::ReturnAdr:
1787           break;
1788         case TypeFunc::Memory:  // Merge inputs to the MergeMem node
1789           assert(phi == nullptr, "the merge contains phis, not vice versa");
1790           merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1791           continue;
1792         default:                // All normal stuff
1793           if (phi == nullptr) {
1794             const JVMState* jvms = map()->jvms();
1795             if (EliminateNestedLocks &&
1796                 jvms->is_mon(j) && jvms->is_monitor_box(j)) {
1797               // BoxLock nodes are not commoning when EliminateNestedLocks is on.
1798               // Use old BoxLock node as merged box.
1799               assert(newin->jvms()->is_monitor_box(j), "sanity");
1800               // This assert also tests that nodes are BoxLock.
1801               assert(BoxLockNode::same_slot(n, m), "sanity");

1808                 // Incremental Inlining before EA and Macro nodes elimination.
1809                 //
1810                 // Incremental Inlining is executed after IGVN optimizations
1811                 // during which BoxLock can be marked as Coarsened.
1812                 old_box->set_coarsened(); // Verifies state
1813                 old_box->set_unbalanced();
1814               }
1815               C->gvn_replace_by(n, m);
1816             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1817               phi = ensure_phi(j, nophi);
1818             }
1819           }
1820           break;
1821         }
1822       }
1823       // At this point, n might be top if:
1824       //  - there is no phi (because TypeFlow detected a conflict), or
1825       //  - the corresponding control edges is top (a dead incoming path)
1826       // It is a bug if we create a phi which sees a garbage value on a live path.
1827 
1828       if (phi != nullptr) {























1829         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1830         assert(phi->region() == r, "");
1831         phi->set_req(pnum, n);  // Then add 'n' to the merge
1832         if (pnum == PhiNode::Input) {
1833           // Last merge for this Phi.
1834           // So far, Phis have had a reasonable type from ciTypeFlow.
1835           // Now _gvn will join that with the meet of current inputs.
1836           // BOTTOM is never permissible here, 'cause pessimistically
1837           // Phis of pointers cannot lose the basic pointer type.
1838           debug_only(const Type* bt1 = phi->bottom_type());
1839           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1840           map()->set_req(j, _gvn.transform(phi));
1841           debug_only(const Type* bt2 = phi->bottom_type());
1842           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1843           record_for_igvn(phi);
1844         }
1845       }
1846     } // End of for all values to be merged
1847 
1848     if (pnum == PhiNode::Input &&
1849         !r->in(0)) {         // The occasional useless Region
1850       assert(control() == r, "");
1851       set_control(r->nonnull_req());
1852     }
1853 
1854     map()->merge_replaced_nodes_with(newin);
1855 
1856     // newin has been subsumed into the lazy merge, and is now dead.
1857     set_block(save_block);
1858 
1859     stop();                     // done with this guy, for now
1860   }
1861 
1862   if (TraceOptoParse) {
1863     tty->print_cr(" on path %d", pnum);
1864   }
1865 
1866   // Done with this parser state.
1867   assert(stopped(), "");
1868 }
1869 

1981 
1982   // Add new path to the region.
1983   uint pnum = r->req();
1984   r->add_req(nullptr);
1985 
1986   for (uint i = 1; i < map->req(); i++) {
1987     Node* n = map->in(i);
1988     if (i == TypeFunc::Memory) {
1989       // Ensure a phi on all currently known memories.
1990       for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) {
1991         Node* phi = mms.memory();
1992         if (phi->is_Phi() && phi->as_Phi()->region() == r) {
1993           assert(phi->req() == pnum, "must be same size as region");
1994           phi->add_req(nullptr);
1995         }
1996       }
1997     } else {
1998       if (n->is_Phi() && n->as_Phi()->region() == r) {
1999         assert(n->req() == pnum, "must be same size as region");
2000         n->add_req(nullptr);


2001       }
2002     }
2003   }
2004 
2005   return pnum;
2006 }
2007 
2008 //------------------------------ensure_phi-------------------------------------
2009 // Turn the idx'th entry of the current map into a Phi
2010 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
2011   SafePointNode* map = this->map();
2012   Node* region = map->control();
2013   assert(region->is_Region(), "");
2014 
2015   Node* o = map->in(idx);
2016   assert(o != nullptr, "");
2017 
2018   if (o == top())  return nullptr; // TOP always merges into TOP
2019 
2020   if (o->is_Phi() && o->as_Phi()->region() == region) {
2021     return o->as_Phi();
2022   }




2023 
2024   // Now use a Phi here for merging
2025   assert(!nocreate, "Cannot build a phi for a block already parsed.");
2026   const JVMState* jvms = map->jvms();
2027   const Type* t = nullptr;
2028   if (jvms->is_loc(idx)) {
2029     t = block()->local_type_at(idx - jvms->locoff());
2030   } else if (jvms->is_stk(idx)) {
2031     t = block()->stack_type_at(idx - jvms->stkoff());
2032   } else if (jvms->is_mon(idx)) {
2033     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
2034     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
2035   } else if ((uint)idx < TypeFunc::Parms) {
2036     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
2037   } else {
2038     assert(false, "no type information for this phi");
2039   }
2040 
2041   // If the type falls to bottom, then this must be a local that
2042   // is mixing ints and oops or some such.  Forcing it to top
2043   // makes it go dead.
2044   if (t == Type::BOTTOM) {
2045     map->set_req(idx, top());
2046     return nullptr;
2047   }
2048 
2049   // Do not create phis for top either.
2050   // A top on a non-null control flow must be an unused even after the.phi.
2051   if (t == Type::TOP || t == Type::HALF) {
2052     map->set_req(idx, top());
2053     return nullptr;
2054   }
2055 
2056   PhiNode* phi = PhiNode::make(region, o, t);
2057   gvn().set_type(phi, t);
2058   if (C->do_escape_analysis()) record_for_igvn(phi);
2059   map->set_req(idx, phi);
2060   return phi;









2061 }
2062 
2063 //--------------------------ensure_memory_phi----------------------------------
2064 // Turn the idx'th slice of the current memory into a Phi
2065 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2066   MergeMemNode* mem = merged_memory();
2067   Node* region = control();
2068   assert(region->is_Region(), "");
2069 
2070   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2071   assert(o != nullptr && o != top(), "");
2072 
2073   PhiNode* phi;
2074   if (o->is_Phi() && o->as_Phi()->region() == region) {
2075     phi = o->as_Phi();
2076     if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) {
2077       // clone the shared base memory phi to make a new memory split
2078       assert(!nocreate, "Cannot build a phi for a block already parsed.");
2079       const Type* t = phi->bottom_type();
2080       const TypePtr* adr_type = C->get_adr_type(idx);

2170 // Add check to deoptimize once holder klass is fully initialized.
2171 void Parse::clinit_deopt() {
2172   assert(C->has_method(), "only for normal compilations");
2173   assert(depth() == 1, "only for main compiled method");
2174   assert(is_normal_parse(), "no barrier needed on osr entry");
2175   assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2176 
2177   set_parse_bci(0);
2178 
2179   Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2180   guard_klass_being_initialized(holder);
2181 }
2182 
2183 //------------------------------return_current---------------------------------
2184 // Append current _map to _exit_return
2185 void Parse::return_current(Node* value) {
2186   if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2187     call_register_finalizer();
2188   }
2189 



































2190   // Do not set_parse_bci, so that return goo is credited to the return insn.
2191   set_bci(InvocationEntryBci);
2192   if (method()->is_synchronized() && GenerateSynchronizationCode) {
2193     shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
2194   }
2195   if (C->env()->dtrace_method_probes()) {
2196     make_dtrace_method_exit(method());
2197   }

2198   SafePointNode* exit_return = _exits.map();
2199   exit_return->in( TypeFunc::Control  )->add_req( control() );
2200   exit_return->in( TypeFunc::I_O      )->add_req( i_o    () );
2201   Node *mem = exit_return->in( TypeFunc::Memory   );
2202   for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) {
2203     if (mms.is_empty()) {
2204       // get a copy of the base memory, and patch just this one input
2205       const TypePtr* adr_type = mms.adr_type(C);
2206       Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type);
2207       assert(phi->as_Phi()->region() == mms.base_memory()->in(0), "");
2208       gvn().set_type_bottom(phi);
2209       phi->del_req(phi->req()-1);  // prepare to re-patch
2210       mms.set_memory(phi);
2211     }
2212     mms.memory()->add_req(mms.memory2());
2213   }
2214 
2215   // frame pointer is always same, already captured
2216   if (value != nullptr) {
2217     // If returning oops to an interface-return, there is a silent free
2218     // cast from oop to interface allowed by the Verifier.  Make it explicit
2219     // here.
2220     Node* phi = _exits.argument(0);
2221     phi->add_req(value);
2222   }
2223 
2224   if (_first_return) {
2225     _exits.map()->transfer_replaced_nodes_from(map(), _new_idx);
2226     _first_return = false;
2227   } else {
2228     _exits.map()->merge_replaced_nodes_with(map());
2229   }
2230 
2231   stop_and_kill_map();          // This CFG path dies here
2232 }
2233 
2234 
2235 //------------------------------add_safepoint----------------------------------
2236 void Parse::add_safepoint() {
2237   uint parms = TypeFunc::Parms+1;
2238 
2239   // Clear out dead values from the debug info.
2240   kill_dead_locals();
2241 
2242   // Clone the JVM State
2243   SafePointNode *sfpnt = new SafePointNode(parms, nullptr);

  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 "compiler/compileLog.hpp"
  26 #include "interpreter/linkResolver.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "oops/method.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/c2compiler.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/convertnode.hpp"
  33 #include "opto/idealGraphPrinter.hpp"
  34 #include "opto/inlinetypenode.hpp"
  35 #include "opto/locknode.hpp"
  36 #include "opto/memnode.hpp"
  37 #include "opto/opaquenode.hpp"
  38 #include "opto/parse.hpp"
  39 #include "opto/rootnode.hpp"
  40 #include "opto/runtime.hpp"
  41 #include "opto/type.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/safepointMechanism.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "utilities/bitMap.inline.hpp"
  46 #include "utilities/copy.hpp"
  47 
  48 // Static array so we can figure out which bytecodes stop us from compiling
  49 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
  50 // and eventually should be encapsulated in a proper class (gri 8/18/98).
  51 
  52 #ifndef PRODUCT
  53 uint nodes_created             = 0;
  54 uint methods_parsed            = 0;

  86   }
  87   if (all_null_checks_found) {
  88     tty->print_cr("%u made implicit (%2u%%)", implicit_null_checks,
  89                   (100*implicit_null_checks)/all_null_checks_found);
  90   }
  91   if (SharedRuntime::_implicit_null_throws) {
  92     tty->print_cr("%u implicit null exceptions at runtime",
  93                   SharedRuntime::_implicit_null_throws);
  94   }
  95 
  96   if (PrintParseStatistics && BytecodeParseHistogram::initialized()) {
  97     BytecodeParseHistogram::print();
  98   }
  99 }
 100 #endif
 101 
 102 //------------------------------ON STACK REPLACEMENT---------------------------
 103 
 104 // Construct a node which can be used to get incoming state for
 105 // on stack replacement.
 106 Node* Parse::fetch_interpreter_state(int index,
 107                                      const Type* type,
 108                                      Node* local_addrs,
 109                                      Node* local_addrs_base) {
 110   BasicType bt = type->basic_type();
 111   if (type == TypePtr::NULL_PTR) {
 112     // Ptr types are mixed together with T_ADDRESS but nullptr is
 113     // really for T_OBJECT types so correct it.
 114     bt = T_OBJECT;
 115   }
 116   Node *mem = memory(Compile::AliasIdxRaw);
 117   Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize );
 118   Node *ctl = control();
 119 
 120   // Very similar to LoadNode::make, except we handle un-aligned longs and
 121   // doubles on Sparc.  Intel can handle them just fine directly.
 122   Node *l = nullptr;
 123   switch (bt) {                // Signature is flattened
 124   case T_INT:     l = new LoadINode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInt::INT,        MemNode::unordered); break;
 125   case T_FLOAT:   l = new LoadFNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::FLOAT,         MemNode::unordered); break;
 126   case T_ADDRESS: l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM,  MemNode::unordered); break;
 127   case T_OBJECT:  l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM, MemNode::unordered); break;
 128   case T_LONG:
 129   case T_DOUBLE: {
 130     // Since arguments are in reverse order, the argument address 'adr'
 131     // refers to the back half of the long/double.  Recompute adr.
 132     adr = basic_plus_adr(local_addrs_base, local_addrs, -(index+1)*wordSize);
 133     if (Matcher::misaligned_doubles_ok) {
 134       l = (bt == T_DOUBLE)
 135         ? (Node*)new LoadDNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::DOUBLE, MemNode::unordered)

 137     } else {
 138       l = (bt == T_DOUBLE)
 139         ? (Node*)new LoadD_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered)
 140         : (Node*)new LoadL_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered);
 141     }
 142     break;
 143   }
 144   default: ShouldNotReachHere();
 145   }
 146   return _gvn.transform(l);
 147 }
 148 
 149 // Helper routine to prevent the interpreter from handing
 150 // unexpected typestate to an OSR method.
 151 // The Node l is a value newly dug out of the interpreter frame.
 152 // The type is the type predicted by ciTypeFlow.  Note that it is
 153 // not a general type, but can only come from Type::get_typeflow_type.
 154 // The safepoint is a map which will feed an uncommon trap.
 155 Node* Parse::check_interpreter_type(Node* l, const Type* type,
 156                                     SafePointNode* &bad_type_exit) {

 157   const TypeOopPtr* tp = type->isa_oopptr();
 158 
 159   // TypeFlow may assert null-ness if a type appears unloaded.
 160   if (type == TypePtr::NULL_PTR ||
 161       (tp != nullptr && !tp->is_loaded())) {
 162     // Value must be null, not a real oop.
 163     Node* chk = _gvn.transform( new CmpPNode(l, null()) );
 164     Node* tst = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
 165     IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
 166     set_control(_gvn.transform( new IfTrueNode(iff) ));
 167     Node* bad_type = _gvn.transform( new IfFalseNode(iff) );
 168     bad_type_exit->control()->add_req(bad_type);
 169     l = null();
 170   }
 171 
 172   // Typeflow can also cut off paths from the CFG, based on
 173   // types which appear unloaded, or call sites which appear unlinked.
 174   // When paths are cut off, values at later merge points can rise
 175   // toward more specific classes.  Make sure these specific classes
 176   // are still in effect.
 177   if (tp != nullptr && !tp->is_same_java_type_as(TypeInstPtr::BOTTOM)) {
 178     // TypeFlow asserted a specific object type.  Value must have that type.
 179     Node* bad_type_ctrl = nullptr;
 180     if (tp->is_inlinetypeptr() && !tp->maybe_null()) {
 181       // Check inline types for null here to prevent checkcast from adding an
 182       // exception state before the bytecode entry (use 'bad_type_ctrl' instead).
 183       l = null_check_oop(l, &bad_type_ctrl);
 184       bad_type_exit->control()->add_req(bad_type_ctrl);
 185     }
 186     l = gen_checkcast(l, makecon(tp->as_klass_type()->cast_to_exactness(true)), &bad_type_ctrl);
 187     bad_type_exit->control()->add_req(bad_type_ctrl);
 188   }
 189 
 190   assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate");
 191   return l;
 192 }
 193 
 194 // Helper routine which sets up elements of the initial parser map when
 195 // performing a parse for on stack replacement.  Add values into map.
 196 // The only parameter contains the address of a interpreter arguments.
 197 void Parse::load_interpreter_state(Node* osr_buf) {
 198   int index;
 199   int max_locals = jvms()->loc_size();
 200   int max_stack  = jvms()->stk_size();
 201 

 202   // Mismatch between method and jvms can occur since map briefly held
 203   // an OSR entry state (which takes up one RawPtr word).
 204   assert(max_locals == method()->max_locals(), "sanity");
 205   assert(max_stack  >= method()->max_stack(),  "sanity");
 206   assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity");
 207   assert((int)jvms()->endoff() == (int)map()->req(), "sanity");
 208 
 209   // Find the start block.
 210   Block* osr_block = start_block();
 211   assert(osr_block->start() == osr_bci(), "sanity");
 212 
 213   // Set initial BCI.
 214   set_parse_bci(osr_block->start());
 215 
 216   // Set initial stack depth.
 217   set_sp(osr_block->start_sp());
 218 
 219   // Check bailouts.  We currently do not perform on stack replacement
 220   // of loops in catch blocks or loops which branch with a non-empty stack.
 221   if (sp() != 0) {

 236   for (index = 0; index < mcnt; index++) {
 237     // Make a BoxLockNode for the monitor.
 238     BoxLockNode* osr_box = new BoxLockNode(next_monitor());
 239     // Check for bailout after new BoxLockNode
 240     if (failing()) { return; }
 241 
 242     // This OSR locking region is unbalanced because it does not have Lock node:
 243     // locking was done in Interpreter.
 244     // This is similar to Coarsened case when Lock node is eliminated
 245     // and as result the region is marked as Unbalanced.
 246 
 247     // Emulate Coarsened state transition from Regular to Unbalanced.
 248     osr_box->set_coarsened();
 249     osr_box->set_unbalanced();
 250 
 251     Node* box = _gvn.transform(osr_box);
 252 
 253     // Displaced headers and locked objects are interleaved in the
 254     // temp OSR buffer.  We only copy the locked objects out here.
 255     // Fetch the locked object from the OSR temp buffer and copy to our fastlock node.
 256     Node* lock_object = fetch_interpreter_state(index*2, Type::get_const_basic_type(T_OBJECT), monitors_addr, osr_buf);
 257     // Try and copy the displaced header to the BoxNode
 258     Node* displaced_hdr = fetch_interpreter_state((index*2) + 1, Type::get_const_basic_type(T_ADDRESS), monitors_addr, osr_buf);

 259 
 260     store_to_memory(control(), box, displaced_hdr, T_ADDRESS, MemNode::unordered);
 261 
 262     // Build a bogus FastLockNode (no code will be generated) and push the
 263     // monitor into our debug info.
 264     const FastLockNode *flock = _gvn.transform(new FastLockNode( nullptr, lock_object, box ))->as_FastLock();
 265     map()->push_monitor(flock);
 266 
 267     // If the lock is our method synchronization lock, tuck it away in
 268     // _sync_lock for return and rethrow exit paths.
 269     if (index == 0 && method()->is_synchronized()) {
 270       _synch_lock = flock;
 271     }
 272   }
 273 
 274   // Use the raw liveness computation to make sure that unexpected
 275   // values don't propagate into the OSR frame.
 276   MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
 277   if (!live_locals.is_valid()) {
 278     // Degenerate or breakpointed method.

 306         if (C->log() != nullptr) {
 307           C->log()->elem("OSR_mismatch local_index='%d'",index);
 308         }
 309         set_local(index, null());
 310         // and ignore it for the loads
 311         continue;
 312       }
 313     }
 314 
 315     // Filter out TOP, HALF, and BOTTOM.  (Cf. ensure_phi.)
 316     if (type == Type::TOP || type == Type::HALF) {
 317       continue;
 318     }
 319     // If the type falls to bottom, then this must be a local that
 320     // is mixing ints and oops or some such.  Forcing it to top
 321     // makes it go dead.
 322     if (type == Type::BOTTOM) {
 323       continue;
 324     }
 325     // Construct code to access the appropriate local.
 326     Node* value = fetch_interpreter_state(index, type, locals_addr, osr_buf);






 327     set_local(index, value);
 328   }
 329 
 330   // Extract the needed stack entries from the interpreter frame.
 331   for (index = 0; index < sp(); index++) {
 332     const Type *type = osr_block->stack_type_at(index);
 333     if (type != Type::TOP) {
 334       // Currently the compiler bails out when attempting to on stack replace
 335       // at a bci with a non-empty stack.  We should not reach here.
 336       ShouldNotReachHere();
 337     }
 338   }
 339 
 340   // End the OSR migration
 341   make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(),
 342                     CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
 343                     "OSR_migration_end", TypeRawPtr::BOTTOM,
 344                     osr_buf);
 345 
 346   // Now that the interpreter state is loaded, make sure it will match

 506   // either breakpoint setting or hotswapping of methods may
 507   // cause deoptimization.
 508   if (C->env()->jvmti_can_hotswap_or_post_breakpoint()) {
 509     C->dependencies()->assert_evol_method(method());
 510   }
 511 
 512   NOT_PRODUCT(methods_seen++);
 513 
 514   // Do some special top-level things.
 515   if (depth() == 1 && C->is_osr_compilation()) {
 516     _tf = C->tf();     // the OSR entry type is different
 517     _entry_bci = C->entry_bci();
 518     _flow = method()->get_osr_flow_analysis(osr_bci());
 519   } else {
 520     _tf = TypeFunc::make(method());
 521     _entry_bci = InvocationEntryBci;
 522     _flow = method()->get_flow_analysis();
 523   }
 524 
 525   if (_flow->failing()) {
 526     // TODO Adding a trap due to an unloaded return type in ciTypeFlow::StateVector::do_invoke
 527     // can lead to this. Re-enable once 8284443 is fixed.
 528     //assert(false, "type flow analysis failed during parsing");
 529     C->record_method_not_compilable(_flow->failure_reason());
 530 #ifndef PRODUCT
 531       if (PrintOpto && (Verbose || WizardMode)) {
 532         if (is_osr_parse()) {
 533           tty->print_cr("OSR @%d type flow bailout: %s", _entry_bci, _flow->failure_reason());
 534         } else {
 535           tty->print_cr("type flow bailout: %s", _flow->failure_reason());
 536         }
 537         if (Verbose) {
 538           method()->print();
 539           method()->print_codes();
 540           _flow->print();
 541         }
 542       }
 543 #endif
 544   }
 545 
 546 #ifdef ASSERT
 547   if (depth() == 1) {
 548     assert(C->is_osr_compilation() == this->is_osr_parse(), "OSR in sync");

 599     load_interpreter_state(osr_buf);
 600   } else {
 601     set_map(entry_map);
 602     do_method_entry();
 603   }
 604 
 605   if (depth() == 1 && !failing()) {
 606     if (C->clinit_barrier_on_entry()) {
 607       // Add check to deoptimize the nmethod once the holder class is fully initialized
 608       clinit_deopt();
 609     }
 610   }
 611 
 612   // Check for bailouts during method entry.
 613   if (failing()) {
 614     if (log)  log->done("parse");
 615     C->set_default_node_notes(caller_nn);
 616     return;
 617   }
 618 
 619   // Handle inline type arguments
 620   int arg_size = method()->arg_size();
 621   for (int i = 0; i < arg_size; i++) {
 622     Node* parm = local(i);
 623     const Type* t = _gvn.type(parm);
 624     if (t->is_inlinetypeptr()) {
 625       // Create InlineTypeNode from the oop and replace the parameter
 626       bool is_larval = (i == 0) && method()->is_object_constructor() && !method()->holder()->is_java_lang_Object();
 627       Node* vt = InlineTypeNode::make_from_oop(this, parm, t->inline_klass(), is_larval);
 628       replace_in_map(parm, vt);
 629     } else if (UseTypeSpeculation && (i == (arg_size - 1)) && !is_osr_parse() && method()->has_vararg() &&
 630                t->isa_aryptr() != nullptr && !t->is_aryptr()->is_null_free() && !t->is_aryptr()->is_flat() &&
 631                (!t->is_aryptr()->is_not_null_free() || !t->is_aryptr()->is_not_flat())) {
 632       // Speculate on varargs Object array being not null-free and not flat
 633       const TypePtr* spec_type = t->speculative();
 634       spec_type = (spec_type != nullptr && spec_type->isa_aryptr() != nullptr) ? spec_type : t->is_aryptr();
 635       spec_type = spec_type->remove_speculative()->is_aryptr()->cast_to_not_null_free()->cast_to_not_flat();
 636       spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::Offset::bottom, TypeOopPtr::InstanceBot, spec_type);
 637       Node* cast = _gvn.transform(new CheckCastPPNode(control(), parm, t->join_speculative(spec_type)));
 638       replace_in_map(parm, cast);
 639     }
 640   }
 641 
 642   entry_map = map();  // capture any changes performed by method setup code
 643   assert(jvms()->endoff() == map()->req(), "map matches JVMS layout");
 644 
 645   // We begin parsing as if we have just encountered a jump to the
 646   // method entry.
 647   Block* entry_block = start_block();
 648   assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), "");
 649   set_map_clone(entry_map);
 650   merge_common(entry_block, entry_block->next_path_num());
 651 
 652 #ifndef PRODUCT
 653   BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C);
 654   set_parse_histogram( parse_histogram_obj );
 655 #endif
 656 
 657   // Parse all the basic blocks.
 658   do_all_blocks();
 659 
 660   // Check for bailouts during conversion to graph
 661   if (failing()) {

 807 void Parse::build_exits() {
 808   // make a clone of caller to prevent sharing of side-effects
 809   _exits.set_map(_exits.clone_map());
 810   _exits.clean_stack(_exits.sp());
 811   _exits.sync_jvms();
 812 
 813   RegionNode* region = new RegionNode(1);
 814   record_for_igvn(region);
 815   gvn().set_type_bottom(region);
 816   _exits.set_control(region);
 817 
 818   // Note:  iophi and memphi are not transformed until do_exits.
 819   Node* iophi  = new PhiNode(region, Type::ABIO);
 820   Node* memphi = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 821   gvn().set_type_bottom(iophi);
 822   gvn().set_type_bottom(memphi);
 823   _exits.set_i_o(iophi);
 824   _exits.set_all_memory(memphi);
 825 
 826   // Add a return value to the exit state.  (Do not push it yet.)
 827   if (tf()->range_sig()->cnt() > TypeFunc::Parms) {
 828     const Type* ret_type = tf()->range_sig()->field_at(TypeFunc::Parms);
 829     if (ret_type->isa_int()) {
 830       BasicType ret_bt = method()->return_type()->basic_type();
 831       if (ret_bt == T_BOOLEAN ||
 832           ret_bt == T_CHAR ||
 833           ret_bt == T_BYTE ||
 834           ret_bt == T_SHORT) {
 835         ret_type = TypeInt::INT;
 836       }
 837     }
 838 
 839     // Don't "bind" an unloaded return klass to the ret_phi. If the klass
 840     // becomes loaded during the subsequent parsing, the loaded and unloaded
 841     // types will not join when we transform and push in do_exits().
 842     const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr();
 843     if (ret_oop_type && !ret_oop_type->is_loaded()) {
 844       ret_type = TypeOopPtr::BOTTOM;
 845     }
 846     int         ret_size = type2size[ret_type->basic_type()];
 847     Node*       ret_phi  = new PhiNode(region, ret_type);
 848     gvn().set_type_bottom(ret_phi);
 849     _exits.ensure_stack(ret_size);
 850     assert((int)(tf()->range_sig()->cnt() - TypeFunc::Parms) == ret_size, "good tf range");
 851     assert(method()->return_type()->size() == ret_size, "tf agrees w/ method");
 852     _exits.set_argument(0, ret_phi);  // here is where the parser finds it
 853     // Note:  ret_phi is not yet pushed, until do_exits.
 854   }
 855 }
 856 

 857 //----------------------------build_start_state-------------------------------
 858 // Construct a state which contains only the incoming arguments from an
 859 // unknown caller.  The method & bci will be null & InvocationEntryBci.
 860 JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) {
 861   int        arg_size = tf->domain_sig()->cnt();
 862   int        max_size = MAX2(arg_size, (int)tf->range_cc()->cnt());
 863   JVMState*  jvms     = new (this) JVMState(max_size - TypeFunc::Parms);
 864   SafePointNode* map  = new SafePointNode(max_size, jvms);
 865   jvms->set_map(map);
 866   record_for_igvn(map);
 867   assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size");
 868   Node_Notes* old_nn = default_node_notes();
 869   if (old_nn != nullptr && has_method()) {
 870     Node_Notes* entry_nn = old_nn->clone(this);
 871     JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms());
 872     entry_jvms->set_offsets(0);
 873     entry_jvms->set_bci(entry_bci());
 874     entry_nn->set_jvms(entry_jvms);
 875     set_default_node_notes(entry_nn);
 876   }
 877   PhaseGVN& gvn = *initial_gvn();
 878   uint i = 0;
 879   int arg_num = 0;
 880   for (uint j = 0; i < (uint)arg_size; i++) {
 881     const Type* t = tf->domain_sig()->field_at(i);
 882     Node* parm = nullptr;
 883     if (t->is_inlinetypeptr() && method()->is_scalarized_arg(arg_num)) {
 884       // Inline type arguments are not passed by reference: we get an argument per
 885       // field of the inline type. Build InlineTypeNodes from the inline type arguments.
 886       GraphKit kit(jvms, &gvn);
 887       kit.set_control(map->control());
 888       Node* old_mem = map->memory();
 889       // Use immutable memory for inline type loads and restore it below
 890       kit.set_all_memory(C->immutable_memory());
 891       parm = InlineTypeNode::make_from_multi(&kit, start, t->inline_klass(), j, /* in= */ true, /* null_free= */ !t->maybe_null());
 892       map->set_control(kit.control());
 893       map->set_memory(old_mem);
 894     } else {
 895       parm = gvn.transform(new ParmNode(start, j++));
 896     }
 897     map->init_req(i, parm);
 898     // Record all these guys for later GVN.
 899     record_for_igvn(parm);
 900     if (i >= TypeFunc::Parms && t != Type::HALF) {
 901       arg_num++;
 902     }
 903   }
 904   for (; i < map->req(); i++) {
 905     map->init_req(i, top());
 906   }
 907   assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here");
 908   set_default_node_notes(old_nn);

 909   return jvms;
 910 }
 911 
 912 //-----------------------------make_node_notes---------------------------------
 913 Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) {
 914   if (caller_nn == nullptr)  return nullptr;
 915   Node_Notes* nn = caller_nn->clone(C);
 916   JVMState* caller_jvms = nn->jvms();
 917   JVMState* jvms = new (C) JVMState(method(), caller_jvms);
 918   jvms->set_offsets(0);
 919   jvms->set_bci(_entry_bci);
 920   nn->set_jvms(jvms);
 921   return nn;
 922 }
 923 
 924 
 925 //--------------------------return_values--------------------------------------
 926 void Compile::return_values(JVMState* jvms) {
 927   GraphKit kit(jvms);
 928   Node* ret = new ReturnNode(TypeFunc::Parms,
 929                              kit.control(),
 930                              kit.i_o(),
 931                              kit.reset_memory(),
 932                              kit.frameptr(),
 933                              kit.returnadr());
 934   // Add zero or 1 return values
 935   int ret_size = tf()->range_sig()->cnt() - TypeFunc::Parms;
 936   if (ret_size > 0) {
 937     kit.inc_sp(-ret_size);  // pop the return value(s)
 938     kit.sync_jvms();
 939     Node* res = kit.argument(0);
 940     if (tf()->returns_inline_type_as_fields()) {
 941       // Multiple return values (inline type fields): add as many edges
 942       // to the Return node as returned values.
 943       InlineTypeNode* vt = res->as_InlineType();
 944       ret->add_req_batch(nullptr, tf()->range_cc()->cnt() - TypeFunc::Parms);
 945       if (vt->is_allocated(&kit.gvn()) && !StressCallingConvention) {
 946         ret->init_req(TypeFunc::Parms, vt);
 947       } else {
 948         // Return the tagged klass pointer to signal scalarization to the caller
 949         Node* tagged_klass = vt->tagged_klass(kit.gvn());
 950         // Return null if the inline type is null (IsInit field is not set)
 951         Node* conv   = kit.gvn().transform(new ConvI2LNode(vt->get_is_init()));
 952         Node* shl    = kit.gvn().transform(new LShiftLNode(conv, kit.intcon(63)));
 953         Node* shr    = kit.gvn().transform(new RShiftLNode(shl, kit.intcon(63)));
 954         tagged_klass = kit.gvn().transform(new AndLNode(tagged_klass, shr));
 955         ret->init_req(TypeFunc::Parms, tagged_klass);
 956       }
 957       uint idx = TypeFunc::Parms + 1;
 958       vt->pass_fields(&kit, ret, idx, false, false);
 959     } else {
 960       ret->add_req(res);
 961       // Note:  The second dummy edge is not needed by a ReturnNode.
 962     }
 963   }
 964   // bind it to root
 965   root()->add_req(ret);
 966   record_for_igvn(ret);
 967   initial_gvn()->transform(ret);
 968 }
 969 
 970 //------------------------rethrow_exceptions-----------------------------------
 971 // Bind all exception states in the list into a single RethrowNode.
 972 void Compile::rethrow_exceptions(JVMState* jvms) {
 973   GraphKit kit(jvms);
 974   if (!kit.has_exceptions())  return;  // nothing to generate
 975   // Load my combined exception state into the kit, with all phis transformed:
 976   SafePointNode* ex_map = kit.combine_and_pop_all_exception_states();
 977   Node* ex_oop = kit.use_exception_state(ex_map);
 978   RethrowNode* exit = new RethrowNode(kit.control(),
 979                                       kit.i_o(), kit.reset_memory(),
 980                                       kit.frameptr(), kit.returnadr(),
 981                                       // like a return but with exception input
 982                                       ex_oop);

1066   //    to complete, we force all writes to complete.
1067   //
1068   // 2. Experimental VM option is used to force the barrier if any field
1069   //    was written out in the constructor.
1070   //
1071   // 3. On processors which are not CPU_MULTI_COPY_ATOMIC (e.g. PPC64),
1072   //    support_IRIW_for_not_multiple_copy_atomic_cpu selects that
1073   //    MemBarVolatile is used before volatile load instead of after volatile
1074   //    store, so there's no barrier after the store.
1075   //    We want to guarantee the same behavior as on platforms with total store
1076   //    order, although this is not required by the Java memory model.
1077   //    In this case, we want to enforce visibility of volatile field
1078   //    initializations which are performed in constructors.
1079   //    So as with finals, we add a barrier here.
1080   //
1081   // "All bets are off" unless the first publication occurs after a
1082   // normal return from the constructor.  We do not attempt to detect
1083   // such unusual early publications.  But no barrier is needed on
1084   // exceptional returns, since they cannot publish normally.
1085   //
1086   if ((method()->is_object_constructor() || method()->is_class_initializer()) &&
1087        (wrote_final() || wrote_stable() ||
1088          (AlwaysSafeConstructors && wrote_fields()) ||
1089          (support_IRIW_for_not_multiple_copy_atomic_cpu && wrote_volatile()))) {
1090     Node* recorded_alloc = alloc_with_final_or_stable();
1091     _exits.insert_mem_bar(UseStoreStoreForCtor ? Op_MemBarStoreStore : Op_MemBarRelease,
1092                           recorded_alloc);
1093 
1094     // If Memory barrier is created for final fields write
1095     // and allocation node does not escape the initialize method,
1096     // then barrier introduced by allocation node can be removed.
1097     if (DoEscapeAnalysis && (recorded_alloc != nullptr)) {
1098       AllocateNode* alloc = AllocateNode::Ideal_allocation(recorded_alloc);
1099       alloc->compute_MemBar_redundancy(method());
1100     }
1101     if (PrintOpto && (Verbose || WizardMode)) {
1102       method()->print_name();
1103       tty->print_cr(" writes finals/@Stable and needs a memory barrier");
1104     }
1105   }
1106 
1107   for (MergeMemStream mms(_exits.merged_memory()); mms.next_non_empty(); ) {
1108     // transform each slice of the original memphi:
1109     mms.set_memory(_gvn.transform(mms.memory()));
1110   }
1111   // Clean up input MergeMems created by transforming the slices
1112   _gvn.transform(_exits.merged_memory());
1113 
1114   if (tf()->range_sig()->cnt() > TypeFunc::Parms) {
1115     const Type* ret_type = tf()->range_sig()->field_at(TypeFunc::Parms);
1116     Node*       ret_phi  = _gvn.transform( _exits.argument(0) );
1117     if (!_exits.control()->is_top() && _gvn.type(ret_phi)->empty()) {
1118       // If the type we set for the ret_phi in build_exits() is too optimistic and
1119       // the ret_phi is top now, there's an extremely small chance that it may be due to class
1120       // loading.  It could also be due to an error, so mark this method as not compilable because
1121       // otherwise this could lead to an infinite compile loop.
1122       // In any case, this code path is rarely (and never in my testing) reached.
1123       C->record_method_not_compilable("Can't determine return type.");
1124       return;
1125     }
1126     if (ret_type->isa_int()) {
1127       BasicType ret_bt = method()->return_type()->basic_type();
1128       ret_phi = mask_int_value(ret_phi, ret_bt, &_gvn);
1129     }
1130     _exits.push_node(ret_type->basic_type(), ret_phi);
1131   }
1132 
1133   // Note:  Logic for creating and optimizing the ReturnNode is in Compile.
1134 
1135   // Unlock along the exceptional paths.

1189 
1190 //-----------------------------create_entry_map-------------------------------
1191 // Initialize our parser map to contain the types at method entry.
1192 // For OSR, the map contains a single RawPtr parameter.
1193 // Initial monitor locking for sync. methods is performed by do_method_entry.
1194 SafePointNode* Parse::create_entry_map() {
1195   // Check for really stupid bail-out cases.
1196   uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1197   if (len >= 32760) {
1198     // Bailout expected, this is a very rare edge case.
1199     C->record_method_not_compilable("too many local variables");
1200     return nullptr;
1201   }
1202 
1203   // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1204   _caller->map()->delete_replaced_nodes();
1205 
1206   // If this is an inlined method, we may have to do a receiver null check.
1207   if (_caller->has_method() && is_normal_parse() && !method()->is_static()) {
1208     GraphKit kit(_caller);
1209     Node* receiver = kit.argument(0);
1210     Node* null_free = kit.null_check_receiver_before_call(method());
1211     _caller = kit.transfer_exceptions_into_jvms();
1212     if (receiver->is_InlineType() && receiver->as_InlineType()->is_larval()) {
1213       // Replace the larval inline type receiver in the exit map as well to make sure that
1214       // we can find and update it in Parse::do_call when we are done with the initialization.
1215       _exits.map()->replace_edge(receiver, null_free);
1216     }
1217     if (kit.stopped()) {
1218       _exits.add_exception_states_from(_caller);
1219       _exits.set_jvms(_caller);
1220       return nullptr;
1221     }
1222   }
1223 
1224   assert(method() != nullptr, "parser must have a method");
1225 
1226   // Create an initial safepoint to hold JVM state during parsing
1227   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : nullptr);
1228   set_map(new SafePointNode(len, jvms));
1229   jvms->set_map(map());
1230   record_for_igvn(map());
1231   assert(jvms->endoff() == len, "correct jvms sizing");
1232 
1233   SafePointNode* inmap = _caller->map();
1234   assert(inmap != nullptr, "must have inmap");
1235   // In case of null check on receiver above
1236   map()->transfer_replaced_nodes_from(inmap, _new_idx);
1237 
1238   uint i;
1239 
1240   // Pass thru the predefined input parameters.
1241   for (i = 0; i < TypeFunc::Parms; i++) {
1242     map()->init_req(i, inmap->in(i));
1243   }
1244 
1245   if (depth() == 1) {
1246     assert(map()->memory()->Opcode() == Op_Parm, "");
1247     // Insert the memory aliasing node
1248     set_all_memory(reset_memory());
1249   }
1250   assert(merged_memory(), "");
1251 
1252   // Now add the locals which are initially bound to arguments:
1253   uint arg_size = tf()->domain_sig()->cnt();
1254   ensure_stack(arg_size - TypeFunc::Parms);  // OSR methods have funny args
1255   for (i = TypeFunc::Parms; i < arg_size; i++) {
1256     map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms));
1257   }
1258 
1259   // Clear out the rest of the map (locals and stack)
1260   for (i = arg_size; i < len; i++) {
1261     map()->init_req(i, top());
1262   }
1263 
1264   SafePointNode* entry_map = stop();
1265   return entry_map;
1266 }
1267 
1268 //-----------------------------do_method_entry--------------------------------
1269 // Emit any code needed in the pseudo-block before BCI zero.
1270 // The main thing to do is lock the receiver of a synchronized method.
1271 void Parse::do_method_entry() {
1272   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1273   set_sp(0);                         // Java Stack Pointer

1307 
1308   // If the method is synchronized, we need to construct a lock node, attach
1309   // it to the Start node, and pin it there.
1310   if (method()->is_synchronized()) {
1311     // Insert a FastLockNode right after the Start which takes as arguments
1312     // the current thread pointer, the "this" pointer & the address of the
1313     // stack slot pair used for the lock.  The "this" pointer is a projection
1314     // off the start node, but the locking spot has to be constructed by
1315     // creating a ConLNode of 0, and boxing it with a BoxLockNode.  The BoxLockNode
1316     // becomes the second argument to the FastLockNode call.  The
1317     // FastLockNode becomes the new control parent to pin it to the start.
1318 
1319     // Setup Object Pointer
1320     Node *lock_obj = nullptr;
1321     if (method()->is_static()) {
1322       ciInstance* mirror = _method->holder()->java_mirror();
1323       const TypeInstPtr *t_lock = TypeInstPtr::make(mirror);
1324       lock_obj = makecon(t_lock);
1325     } else {                  // Else pass the "this" pointer,
1326       lock_obj = local(0);    // which is Parm0 from StartNode
1327       assert(!_gvn.type(lock_obj)->make_oopptr()->can_be_inline_type(), "can't be an inline type");
1328     }
1329     // Clear out dead values from the debug info.
1330     kill_dead_locals();
1331     // Build the FastLockNode
1332     _synch_lock = shared_lock(lock_obj);
1333     // Check for bailout in shared_lock
1334     if (failing()) { return; }
1335   }
1336 
1337   // Feed profiling data for parameters to the type system so it can
1338   // propagate it as speculative types
1339   record_profiled_parameters_for_speculation();
1340 }
1341 
1342 //------------------------------init_blocks------------------------------------
1343 // Initialize our parser map to contain the types/monitors at method entry.
1344 void Parse::init_blocks() {
1345   // Create the blocks.
1346   _block_count = flow()->block_count();
1347   _blocks = NEW_RESOURCE_ARRAY(Block, _block_count);

1743 //--------------------handle_missing_successor---------------------------------
1744 void Parse::handle_missing_successor(int target_bci) {
1745 #ifndef PRODUCT
1746   Block* b = block();
1747   int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1748   tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1749 #endif
1750   ShouldNotReachHere();
1751 }
1752 
1753 //--------------------------merge_common---------------------------------------
1754 void Parse::merge_common(Parse::Block* target, int pnum) {
1755   if (TraceOptoParse) {
1756     tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1757   }
1758 
1759   // Zap extra stack slots to top
1760   assert(sp() == target->start_sp(), "");
1761   clean_stack(sp());
1762 
1763   // Check for merge conflicts involving inline types
1764   JVMState* old_jvms = map()->jvms();
1765   int old_bci = bci();
1766   JVMState* tmp_jvms = old_jvms->clone_shallow(C);
1767   tmp_jvms->set_should_reexecute(true);
1768   tmp_jvms->bind_map(map());
1769   // Execution needs to restart a the next bytecode (entry of next
1770   // block)
1771   if (target->is_merged() ||
1772       pnum > PhiNode::Input ||
1773       target->is_handler() ||
1774       target->is_loop_head()) {
1775     set_parse_bci(target->start());
1776     for (uint j = TypeFunc::Parms; j < map()->req(); j++) {
1777       Node* n = map()->in(j);                 // Incoming change to target state.
1778       const Type* t = nullptr;
1779       if (tmp_jvms->is_loc(j)) {
1780         t = target->local_type_at(j - tmp_jvms->locoff());
1781       } else if (tmp_jvms->is_stk(j) && j < (uint)sp() + tmp_jvms->stkoff()) {
1782         t = target->stack_type_at(j - tmp_jvms->stkoff());
1783       }
1784       if (t != nullptr && t != Type::BOTTOM) {
1785         if (n->is_InlineType() && !t->is_inlinetypeptr()) {
1786           // Allocate inline type in src block to be able to merge it with oop in target block
1787           map()->set_req(j, n->as_InlineType()->buffer(this));
1788         } else if (!n->is_InlineType() && t->is_inlinetypeptr()) {
1789           // Scalarize null in src block to be able to merge it with inline type in target block
1790           assert(gvn().type(n)->is_zero_type(), "Should have been scalarized");
1791           map()->set_req(j, InlineTypeNode::make_null(gvn(), t->inline_klass()));
1792         }
1793       }
1794     }
1795   }
1796   old_jvms->bind_map(map());
1797   set_parse_bci(old_bci);
1798 
1799   if (!target->is_merged()) {   // No prior mapping at this bci
1800     if (TraceOptoParse) { tty->print(" with empty state");  }
1801 
1802     // If this path is dead, do not bother capturing it as a merge.
1803     // It is "as if" we had 1 fewer predecessors from the beginning.
1804     if (stopped()) {
1805       if (TraceOptoParse)  tty->print_cr(", but path is dead and doesn't count");
1806       return;
1807     }
1808 
1809     // Make a region if we know there are multiple or unpredictable inputs.
1810     // (Also, if this is a plain fall-through, we might see another region,
1811     // which must not be allowed into this block's map.)
1812     if (pnum > PhiNode::Input         // Known multiple inputs.
1813         || target->is_handler()       // These have unpredictable inputs.
1814         || target->is_loop_head()     // Known multiple inputs
1815         || control()->is_Region()) {  // We must hide this guy.
1816 
1817       int current_bci = bci();
1818       set_parse_bci(target->start()); // Set target bci

1833       record_for_igvn(r);
1834       // zap all inputs to null for debugging (done in Node(uint) constructor)
1835       // for (int j = 1; j < edges+1; j++) { r->init_req(j, nullptr); }
1836       r->init_req(pnum, control());
1837       set_control(r);
1838       target->copy_irreducible_status_to(r, jvms());
1839       set_parse_bci(current_bci); // Restore bci
1840     }
1841 
1842     // Convert the existing Parser mapping into a mapping at this bci.
1843     store_state_to(target);
1844     assert(target->is_merged(), "do not come here twice");
1845 
1846   } else {                      // Prior mapping at this bci
1847     if (TraceOptoParse) {  tty->print(" with previous state"); }
1848 #ifdef ASSERT
1849     if (target->is_SEL_head()) {
1850       target->mark_merged_backedge(block());
1851     }
1852 #endif
1853 
1854     // We must not manufacture more phis if the target is already parsed.
1855     bool nophi = target->is_parsed();
1856 
1857     SafePointNode* newin = map();// Hang on to incoming mapping
1858     Block* save_block = block(); // Hang on to incoming block;
1859     load_state_from(target);    // Get prior mapping
1860 
1861     assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree");
1862     assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree");
1863     assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree");
1864     assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree");
1865 
1866     // Iterate over my current mapping and the old mapping.
1867     // Where different, insert Phi functions.
1868     // Use any existing Phi functions.
1869     assert(control()->is_Region(), "must be merging to a region");
1870     RegionNode* r = control()->as_Region();
1871 
1872     // Compute where to merge into
1873     // Merge incoming control path
1874     r->init_req(pnum, newin->control());
1875 
1876     if (pnum == 1) {            // Last merge for this Region?
1877       if (!block()->flow()->is_irreducible_loop_secondary_entry()) {
1878         Node* result = _gvn.transform(r);
1879         if (r != result && TraceOptoParse) {
1880           tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1881         }
1882       }
1883       record_for_igvn(r);
1884     }
1885 
1886     // Update all the non-control inputs to map:
1887     assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1888     bool check_elide_phi = target->is_SEL_backedge(save_block);
1889     bool last_merge = (pnum == PhiNode::Input);
1890     for (uint j = 1; j < newin->req(); j++) {
1891       Node* m = map()->in(j);   // Current state of target.
1892       Node* n = newin->in(j);   // Incoming change to target state.
1893       PhiNode* phi;
1894       if (m->is_Phi() && m->as_Phi()->region() == r) {
1895         phi = m->as_Phi();
1896       } else if (m->is_InlineType() && m->as_InlineType()->has_phi_inputs(r)) {
1897         phi = m->as_InlineType()->get_oop()->as_Phi();
1898       } else {
1899         phi = nullptr;
1900       }
1901       if (m != n) {             // Different; must merge
1902         switch (j) {
1903         // Frame pointer and Return Address never changes
1904         case TypeFunc::FramePtr:// Drop m, use the original value
1905         case TypeFunc::ReturnAdr:
1906           break;
1907         case TypeFunc::Memory:  // Merge inputs to the MergeMem node
1908           assert(phi == nullptr, "the merge contains phis, not vice versa");
1909           merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1910           continue;
1911         default:                // All normal stuff
1912           if (phi == nullptr) {
1913             const JVMState* jvms = map()->jvms();
1914             if (EliminateNestedLocks &&
1915                 jvms->is_mon(j) && jvms->is_monitor_box(j)) {
1916               // BoxLock nodes are not commoning when EliminateNestedLocks is on.
1917               // Use old BoxLock node as merged box.
1918               assert(newin->jvms()->is_monitor_box(j), "sanity");
1919               // This assert also tests that nodes are BoxLock.
1920               assert(BoxLockNode::same_slot(n, m), "sanity");

1927                 // Incremental Inlining before EA and Macro nodes elimination.
1928                 //
1929                 // Incremental Inlining is executed after IGVN optimizations
1930                 // during which BoxLock can be marked as Coarsened.
1931                 old_box->set_coarsened(); // Verifies state
1932                 old_box->set_unbalanced();
1933               }
1934               C->gvn_replace_by(n, m);
1935             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1936               phi = ensure_phi(j, nophi);
1937             }
1938           }
1939           break;
1940         }
1941       }
1942       // At this point, n might be top if:
1943       //  - there is no phi (because TypeFlow detected a conflict), or
1944       //  - the corresponding control edges is top (a dead incoming path)
1945       // It is a bug if we create a phi which sees a garbage value on a live path.
1946 
1947       // Merging two inline types?
1948       if (phi != nullptr && phi->bottom_type()->is_inlinetypeptr()) {
1949         // Reload current state because it may have been updated by ensure_phi
1950         m = map()->in(j);
1951         InlineTypeNode* vtm = m->as_InlineType(); // Current inline type
1952         InlineTypeNode* vtn = n->as_InlineType(); // Incoming inline type
1953         assert(vtm->get_oop() == phi, "Inline type should have Phi input");
1954         if (TraceOptoParse) {
1955 #ifdef ASSERT
1956           tty->print_cr("\nMerging inline types");
1957           tty->print_cr("Current:");
1958           vtm->dump(2);
1959           tty->print_cr("Incoming:");
1960           vtn->dump(2);
1961           tty->cr();
1962 #endif
1963         }
1964         // Do the merge
1965         vtm->merge_with(&_gvn, vtn, pnum, last_merge);
1966         if (last_merge) {
1967           map()->set_req(j, _gvn.transform(vtm));
1968           record_for_igvn(vtm);
1969         }
1970       } else if (phi != nullptr) {
1971         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1972         assert(phi->region() == r, "");
1973         phi->set_req(pnum, n);  // Then add 'n' to the merge
1974         if (last_merge) {
1975           // Last merge for this Phi.
1976           // So far, Phis have had a reasonable type from ciTypeFlow.
1977           // Now _gvn will join that with the meet of current inputs.
1978           // BOTTOM is never permissible here, 'cause pessimistically
1979           // Phis of pointers cannot lose the basic pointer type.
1980           debug_only(const Type* bt1 = phi->bottom_type());
1981           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1982           map()->set_req(j, _gvn.transform(phi));
1983           debug_only(const Type* bt2 = phi->bottom_type());
1984           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1985           record_for_igvn(phi);
1986         }
1987       }
1988     } // End of for all values to be merged
1989 
1990     if (last_merge && !r->in(0)) {         // The occasional useless Region

1991       assert(control() == r, "");
1992       set_control(r->nonnull_req());
1993     }
1994 
1995     map()->merge_replaced_nodes_with(newin);
1996 
1997     // newin has been subsumed into the lazy merge, and is now dead.
1998     set_block(save_block);
1999 
2000     stop();                     // done with this guy, for now
2001   }
2002 
2003   if (TraceOptoParse) {
2004     tty->print_cr(" on path %d", pnum);
2005   }
2006 
2007   // Done with this parser state.
2008   assert(stopped(), "");
2009 }
2010 

2122 
2123   // Add new path to the region.
2124   uint pnum = r->req();
2125   r->add_req(nullptr);
2126 
2127   for (uint i = 1; i < map->req(); i++) {
2128     Node* n = map->in(i);
2129     if (i == TypeFunc::Memory) {
2130       // Ensure a phi on all currently known memories.
2131       for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) {
2132         Node* phi = mms.memory();
2133         if (phi->is_Phi() && phi->as_Phi()->region() == r) {
2134           assert(phi->req() == pnum, "must be same size as region");
2135           phi->add_req(nullptr);
2136         }
2137       }
2138     } else {
2139       if (n->is_Phi() && n->as_Phi()->region() == r) {
2140         assert(n->req() == pnum, "must be same size as region");
2141         n->add_req(nullptr);
2142       } else if (n->is_InlineType() && n->as_InlineType()->has_phi_inputs(r)) {
2143         n->as_InlineType()->add_new_path(r);
2144       }
2145     }
2146   }
2147 
2148   return pnum;
2149 }
2150 
2151 //------------------------------ensure_phi-------------------------------------
2152 // Turn the idx'th entry of the current map into a Phi
2153 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
2154   SafePointNode* map = this->map();
2155   Node* region = map->control();
2156   assert(region->is_Region(), "");
2157 
2158   Node* o = map->in(idx);
2159   assert(o != nullptr, "");
2160 
2161   if (o == top())  return nullptr; // TOP always merges into TOP
2162 
2163   if (o->is_Phi() && o->as_Phi()->region() == region) {
2164     return o->as_Phi();
2165   }
2166   InlineTypeNode* vt = o->isa_InlineType();
2167   if (vt != nullptr && vt->has_phi_inputs(region)) {
2168     return vt->get_oop()->as_Phi();
2169   }
2170 
2171   // Now use a Phi here for merging
2172   assert(!nocreate, "Cannot build a phi for a block already parsed.");
2173   const JVMState* jvms = map->jvms();
2174   const Type* t = nullptr;
2175   if (jvms->is_loc(idx)) {
2176     t = block()->local_type_at(idx - jvms->locoff());
2177   } else if (jvms->is_stk(idx)) {
2178     t = block()->stack_type_at(idx - jvms->stkoff());
2179   } else if (jvms->is_mon(idx)) {
2180     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
2181     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
2182   } else if ((uint)idx < TypeFunc::Parms) {
2183     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
2184   } else {
2185     assert(false, "no type information for this phi");
2186   }
2187 
2188   // If the type falls to bottom, then this must be a local that
2189   // is already dead or is mixing ints and oops or some such.
2190   // Forcing it to top makes it go dead.
2191   if (t == Type::BOTTOM) {
2192     map->set_req(idx, top());
2193     return nullptr;
2194   }
2195 
2196   // Do not create phis for top either.
2197   // A top on a non-null control flow must be an unused even after the.phi.
2198   if (t == Type::TOP || t == Type::HALF) {
2199     map->set_req(idx, top());
2200     return nullptr;
2201   }
2202 
2203   if (vt != nullptr && t->is_inlinetypeptr()) {
2204     // Inline types are merged by merging their field values.
2205     // Create a cloned InlineTypeNode with phi inputs that
2206     // represents the merged inline type and update the map.
2207     vt = vt->clone_with_phis(&_gvn, region);
2208     map->set_req(idx, vt);
2209     return vt->get_oop()->as_Phi();
2210   } else {
2211     PhiNode* phi = PhiNode::make(region, o, t);
2212     gvn().set_type(phi, t);
2213     if (C->do_escape_analysis()) record_for_igvn(phi);
2214     map->set_req(idx, phi);
2215     return phi;
2216   }
2217 }
2218 
2219 //--------------------------ensure_memory_phi----------------------------------
2220 // Turn the idx'th slice of the current memory into a Phi
2221 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2222   MergeMemNode* mem = merged_memory();
2223   Node* region = control();
2224   assert(region->is_Region(), "");
2225 
2226   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2227   assert(o != nullptr && o != top(), "");
2228 
2229   PhiNode* phi;
2230   if (o->is_Phi() && o->as_Phi()->region() == region) {
2231     phi = o->as_Phi();
2232     if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) {
2233       // clone the shared base memory phi to make a new memory split
2234       assert(!nocreate, "Cannot build a phi for a block already parsed.");
2235       const Type* t = phi->bottom_type();
2236       const TypePtr* adr_type = C->get_adr_type(idx);

2326 // Add check to deoptimize once holder klass is fully initialized.
2327 void Parse::clinit_deopt() {
2328   assert(C->has_method(), "only for normal compilations");
2329   assert(depth() == 1, "only for main compiled method");
2330   assert(is_normal_parse(), "no barrier needed on osr entry");
2331   assert(!method()->holder()->is_not_initialized(), "initialization should have been started");
2332 
2333   set_parse_bci(0);
2334 
2335   Node* holder = makecon(TypeKlassPtr::make(method()->holder(), Type::trust_interfaces));
2336   guard_klass_being_initialized(holder);
2337 }
2338 
2339 //------------------------------return_current---------------------------------
2340 // Append current _map to _exit_return
2341 void Parse::return_current(Node* value) {
2342   if (method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2343     call_register_finalizer();
2344   }
2345 
2346   // frame pointer is always same, already captured
2347   if (value != nullptr) {
2348     Node* phi = _exits.argument(0);
2349     const Type* return_type = phi->bottom_type();
2350     const TypeInstPtr* tr = return_type->isa_instptr();
2351     assert(!value->is_InlineType() || !value->as_InlineType()->is_larval(), "returning a larval");
2352     if ((tf()->returns_inline_type_as_fields() || (_caller->has_method() && !Compile::current()->inlining_incrementally())) &&
2353         return_type->is_inlinetypeptr()) {
2354       // Inline type is returned as fields, make sure it is scalarized
2355       if (!value->is_InlineType()) {
2356         value = InlineTypeNode::make_from_oop(this, value, return_type->inline_klass());
2357       }
2358       if (!_caller->has_method() || Compile::current()->inlining_incrementally()) {
2359         // Returning from root or an incrementally inlined method. Make sure all non-flat
2360         // fields are buffered and re-execute if allocation triggers deoptimization.
2361         PreserveReexecuteState preexecs(this);
2362         assert(tf()->returns_inline_type_as_fields(), "must be returned as fields");
2363         jvms()->set_should_reexecute(true);
2364         inc_sp(1);
2365         value = value->as_InlineType()->allocate_fields(this);
2366       }
2367     } else if (value->is_InlineType()) {
2368       // Inline type is returned as oop, make sure it is buffered and re-execute
2369       // if allocation triggers deoptimization.
2370       PreserveReexecuteState preexecs(this);
2371       jvms()->set_should_reexecute(true);
2372       inc_sp(1);
2373       value = value->as_InlineType()->buffer(this);
2374     }
2375     // ...else
2376     // If returning oops to an interface-return, there is a silent free
2377     // cast from oop to interface allowed by the Verifier. Make it explicit here.
2378     phi->add_req(value);
2379   }
2380 
2381   // Do not set_parse_bci, so that return goo is credited to the return insn.
2382   set_bci(InvocationEntryBci);
2383   if (method()->is_synchronized() && GenerateSynchronizationCode) {
2384     shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
2385   }
2386   if (C->env()->dtrace_method_probes()) {
2387     make_dtrace_method_exit(method());
2388   }
2389 
2390   SafePointNode* exit_return = _exits.map();
2391   exit_return->in( TypeFunc::Control  )->add_req( control() );
2392   exit_return->in( TypeFunc::I_O      )->add_req( i_o    () );
2393   Node *mem = exit_return->in( TypeFunc::Memory   );
2394   for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) {
2395     if (mms.is_empty()) {
2396       // get a copy of the base memory, and patch just this one input
2397       const TypePtr* adr_type = mms.adr_type(C);
2398       Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type);
2399       assert(phi->as_Phi()->region() == mms.base_memory()->in(0), "");
2400       gvn().set_type_bottom(phi);
2401       phi->del_req(phi->req()-1);  // prepare to re-patch
2402       mms.set_memory(phi);
2403     }
2404     mms.memory()->add_req(mms.memory2());
2405   }
2406 









2407   if (_first_return) {
2408     _exits.map()->transfer_replaced_nodes_from(map(), _new_idx);
2409     _first_return = false;
2410   } else {
2411     _exits.map()->merge_replaced_nodes_with(map());
2412   }
2413 
2414   stop_and_kill_map();          // This CFG path dies here
2415 }
2416 
2417 
2418 //------------------------------add_safepoint----------------------------------
2419 void Parse::add_safepoint() {
2420   uint parms = TypeFunc::Parms+1;
2421 
2422   // Clear out dead values from the debug info.
2423   kill_dead_locals();
2424 
2425   // Clone the JVM State
2426   SafePointNode *sfpnt = new SafePointNode(parms, nullptr);
< prev index next >