< prev index next >

src/hotspot/share/opto/parse1.cpp

Print this page

  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/method.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/c2compiler.hpp"
  32 #include "opto/castnode.hpp"

  33 #include "opto/idealGraphPrinter.hpp"

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

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






 109   Node *mem = memory(Compile::AliasIdxRaw);
 110   Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize );
 111   Node *ctl = control();
 112 
 113   // Very similar to LoadNode::make, except we handle un-aligned longs and
 114   // doubles on Sparc.  Intel can handle them just fine directly.
 115   Node *l = NULL;
 116   switch (bt) {                // Signature is flattened
 117   case T_INT:     l = new LoadINode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInt::INT,        MemNode::unordered); break;
 118   case T_FLOAT:   l = new LoadFNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::FLOAT,         MemNode::unordered); break;
 119   case T_ADDRESS: l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM,  MemNode::unordered); break;

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






 174     l = gen_checkcast(l, makecon(tp->as_klass_type()->cast_to_exactness(true)), &bad_type_ctrl);
 175     bad_type_exit->control()->add_req(bad_type_ctrl);
 176   }
 177 
 178   BasicType bt_l = _gvn.type(l)->basic_type();
 179   BasicType bt_t = type->basic_type();
 180   assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate");
 181   return l;
 182 }
 183 
 184 // Helper routine which sets up elements of the initial parser map when
 185 // performing a parse for on stack replacement.  Add values into map.
 186 // The only parameter contains the address of a interpreter arguments.
 187 void Parse::load_interpreter_state(Node* osr_buf) {
 188   int index;
 189   int max_locals = jvms()->loc_size();
 190   int max_stack  = jvms()->stk_size();
 191 
 192 
 193   // Mismatch between method and jvms can occur since map briefly held
 194   // an OSR entry state (which takes up one RawPtr word).
 195   assert(max_locals == method()->max_locals(), "sanity");
 196   assert(max_stack  >= method()->max_stack(),  "sanity");
 197   assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity");
 198   assert((int)jvms()->endoff() == (int)map()->req(), "sanity");
 199 
 200   // Find the start block.
 201   Block* osr_block = start_block();
 202   assert(osr_block->start() == osr_bci(), "sanity");
 203 
 204   // Set initial BCI.
 205   set_parse_bci(osr_block->start());
 206 
 207   // Set initial stack depth.
 208   set_sp(osr_block->start_sp());
 209 
 210   // Check bailouts.  We currently do not perform on stack replacement
 211   // of loops in catch blocks or loops which branch with a non-empty stack.
 212   if (sp() != 0) {
 213     C->record_method_not_compilable("OSR starts with non-empty stack");
 214     return;
 215   }
 216   // Do not OSR inside finally clauses:
 217   if (osr_block->has_trap_at(osr_block->start())) {
 218     C->record_method_not_compilable("OSR starts with an immediate trap");
 219     return;
 220   }
 221 
 222   // Commute monitors from interpreter frame to compiler frame.
 223   assert(jvms()->monitor_depth() == 0, "should be no active locks at beginning of osr");
 224   int mcnt = osr_block->flow()->monitor_count();
 225   Node *monitors_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals+mcnt*2-1)*wordSize);
 226   for (index = 0; index < mcnt; index++) {
 227     // Make a BoxLockNode for the monitor.
 228     Node *box = _gvn.transform(new BoxLockNode(next_monitor()));
 229 
 230 
 231     // Displaced headers and locked objects are interleaved in the
 232     // temp OSR buffer.  We only copy the locked objects out here.
 233     // Fetch the locked object from the OSR temp buffer and copy to our fastlock node.
 234     Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf);
 235     // Try and copy the displaced header to the BoxNode
 236     Node *displaced_hdr = fetch_interpreter_state((index*2) + 1, T_ADDRESS, monitors_addr, osr_buf);
 237 
 238 
 239     store_to_memory(control(), box, displaced_hdr, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered);
 240 
 241     // Build a bogus FastLockNode (no code will be generated) and push the
 242     // monitor into our debug info.
 243     const FastLockNode *flock = _gvn.transform(new FastLockNode( 0, lock_object, box ))->as_FastLock();
 244     map()->push_monitor(flock);
 245 
 246     // If the lock is our method synchronization lock, tuck it away in
 247     // _sync_lock for return and rethrow exit paths.
 248     if (index == 0 && method()->is_synchronized()) {
 249       _synch_lock = flock;
 250     }
 251   }
 252 
 253   // Use the raw liveness computation to make sure that unexpected
 254   // values don't propagate into the OSR frame.
 255   MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
 256   if (!live_locals.is_valid()) {
 257     // Degenerate or breakpointed method.

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

 580     do_method_entry();
 581   }
 582 
 583   if (depth() == 1 && !failing()) {
 584     if (C->clinit_barrier_on_entry()) {
 585       // Add check to deoptimize the nmethod once the holder class is fully initialized
 586       clinit_deopt();
 587     }
 588 
 589     // Add check to deoptimize the nmethod if RTM state was changed
 590     rtm_deopt();
 591   }
 592 
 593   // Check for bailouts during method entry or RTM state check setup.
 594   if (failing()) {
 595     if (log)  log->done("parse");
 596     C->set_default_node_notes(caller_nn);
 597     return;
 598   }
 599 





















 600   entry_map = map();  // capture any changes performed by method setup code
 601   assert(jvms()->endoff() == map()->req(), "map matches JVMS layout");
 602 
 603   // We begin parsing as if we have just encountered a jump to the
 604   // method entry.
 605   Block* entry_block = start_block();
 606   assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), "");
 607   set_map_clone(entry_map);
 608   merge_common(entry_block, entry_block->next_path_num());
 609 
 610 #ifndef PRODUCT
 611   BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C);
 612   set_parse_histogram( parse_histogram_obj );
 613 #endif
 614 
 615   // Parse all the basic blocks.
 616   do_all_blocks();
 617 
 618   C->set_default_node_notes(caller_nn);
 619 

 762 void Parse::build_exits() {
 763   // make a clone of caller to prevent sharing of side-effects
 764   _exits.set_map(_exits.clone_map());
 765   _exits.clean_stack(_exits.sp());
 766   _exits.sync_jvms();
 767 
 768   RegionNode* region = new RegionNode(1);
 769   record_for_igvn(region);
 770   gvn().set_type_bottom(region);
 771   _exits.set_control(region);
 772 
 773   // Note:  iophi and memphi are not transformed until do_exits.
 774   Node* iophi  = new PhiNode(region, Type::ABIO);
 775   Node* memphi = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 776   gvn().set_type_bottom(iophi);
 777   gvn().set_type_bottom(memphi);
 778   _exits.set_i_o(iophi);
 779   _exits.set_all_memory(memphi);
 780 
 781   // Add a return value to the exit state.  (Do not push it yet.)
 782   if (tf()->range()->cnt() > TypeFunc::Parms) {
 783     const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms);
 784     if (ret_type->isa_int()) {
 785       BasicType ret_bt = method()->return_type()->basic_type();
 786       if (ret_bt == T_BOOLEAN ||
 787           ret_bt == T_CHAR ||
 788           ret_bt == T_BYTE ||
 789           ret_bt == T_SHORT) {
 790         ret_type = TypeInt::INT;
 791       }
 792     }
 793 
 794     // Don't "bind" an unloaded return klass to the ret_phi. If the klass
 795     // becomes loaded during the subsequent parsing, the loaded and unloaded
 796     // types will not join when we transform and push in do_exits().
 797     const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr();
 798     if (ret_oop_type && !ret_oop_type->is_loaded()) {
 799       ret_type = TypeOopPtr::BOTTOM;
 800     }





 801     int         ret_size = type2size[ret_type->basic_type()];
 802     Node*       ret_phi  = new PhiNode(region, ret_type);
 803     gvn().set_type_bottom(ret_phi);
 804     _exits.ensure_stack(ret_size);
 805     assert((int)(tf()->range()->cnt() - TypeFunc::Parms) == ret_size, "good tf range");
 806     assert(method()->return_type()->size() == ret_size, "tf agrees w/ method");
 807     _exits.set_argument(0, ret_phi);  // here is where the parser finds it
 808     // Note:  ret_phi is not yet pushed, until do_exits.
 809   }
 810 }
 811 
 812 
 813 //----------------------------build_start_state-------------------------------
 814 // Construct a state which contains only the incoming arguments from an
 815 // unknown caller.  The method & bci will be NULL & InvocationEntryBci.
 816 JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) {
 817   int        arg_size = tf->domain()->cnt();
 818   int        max_size = MAX2(arg_size, (int)tf->range()->cnt());
 819   JVMState*  jvms     = new (this) JVMState(max_size - TypeFunc::Parms);
 820   SafePointNode* map  = new SafePointNode(max_size, jvms);

 821   record_for_igvn(map);
 822   assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size");
 823   Node_Notes* old_nn = default_node_notes();
 824   if (old_nn != NULL && has_method()) {
 825     Node_Notes* entry_nn = old_nn->clone(this);
 826     JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms());
 827     entry_jvms->set_offsets(0);
 828     entry_jvms->set_bci(entry_bci());
 829     entry_nn->set_jvms(entry_jvms);
 830     set_default_node_notes(entry_nn);
 831   }
 832   uint i;
 833   for (i = 0; i < (uint)arg_size; i++) {
 834     Node* parm = initial_gvn()->transform(new ParmNode(start, i));

















 835     map->init_req(i, parm);
 836     // Record all these guys for later GVN.
 837     record_for_igvn(parm);



 838   }
 839   for (; i < map->req(); i++) {
 840     map->init_req(i, top());
 841   }
 842   assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here");
 843   set_default_node_notes(old_nn);
 844   jvms->set_map(map);
 845   return jvms;
 846 }
 847 
 848 //-----------------------------make_node_notes---------------------------------
 849 Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) {
 850   if (caller_nn == NULL)  return NULL;
 851   Node_Notes* nn = caller_nn->clone(C);
 852   JVMState* caller_jvms = nn->jvms();
 853   JVMState* jvms = new (C) JVMState(method(), caller_jvms);
 854   jvms->set_offsets(0);
 855   jvms->set_bci(_entry_bci);
 856   nn->set_jvms(jvms);
 857   return nn;
 858 }
 859 
 860 
 861 //--------------------------return_values--------------------------------------
 862 void Compile::return_values(JVMState* jvms) {
 863   GraphKit kit(jvms);
 864   Node* ret = new ReturnNode(TypeFunc::Parms,
 865                              kit.control(),
 866                              kit.i_o(),
 867                              kit.reset_memory(),
 868                              kit.frameptr(),
 869                              kit.returnadr());
 870   // Add zero or 1 return values
 871   int ret_size = tf()->range()->cnt() - TypeFunc::Parms;
 872   if (ret_size > 0) {
 873     kit.inc_sp(-ret_size);  // pop the return value(s)
 874     kit.sync_jvms();
 875     ret->add_req(kit.argument(0));
 876     // Note:  The second dummy edge is not needed by a ReturnNode.
























 877   }
 878   // bind it to root
 879   root()->add_req(ret);
 880   record_for_igvn(ret);
 881   initial_gvn()->transform_no_reclaim(ret);
 882 }
 883 
 884 //------------------------rethrow_exceptions-----------------------------------
 885 // Bind all exception states in the list into a single RethrowNode.
 886 void Compile::rethrow_exceptions(JVMState* jvms) {
 887   GraphKit kit(jvms);
 888   if (!kit.has_exceptions())  return;  // nothing to generate
 889   // Load my combined exception state into the kit, with all phis transformed:
 890   SafePointNode* ex_map = kit.combine_and_pop_all_exception_states();
 891   Node* ex_oop = kit.use_exception_state(ex_map);
 892   RethrowNode* exit = new RethrowNode(kit.control(),
 893                                       kit.i_o(), kit.reset_memory(),
 894                                       kit.frameptr(), kit.returnadr(),
 895                                       // like a return but with exception input
 896                                       ex_oop);

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

1112 }
1113 
1114 //-----------------------------create_entry_map-------------------------------
1115 // Initialize our parser map to contain the types at method entry.
1116 // For OSR, the map contains a single RawPtr parameter.
1117 // Initial monitor locking for sync. methods is performed by do_method_entry.
1118 SafePointNode* Parse::create_entry_map() {
1119   // Check for really stupid bail-out cases.
1120   uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1121   if (len >= 32760) {
1122     C->record_method_not_compilable("too many local variables");
1123     return NULL;
1124   }
1125 
1126   // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1127   _caller->map()->delete_replaced_nodes();
1128 
1129   // If this is an inlined method, we may have to do a receiver null check.
1130   if (_caller->has_method() && is_normal_parse() && !method()->is_static()) {
1131     GraphKit kit(_caller);
1132     kit.null_check_receiver_before_call(method());
1133     _caller = kit.transfer_exceptions_into_jvms();
1134     if (kit.stopped()) {
1135       _exits.add_exception_states_from(_caller);
1136       _exits.set_jvms(_caller);
1137       return NULL;
1138     }
1139   }
1140 
1141   assert(method() != NULL, "parser must have a method");
1142 
1143   // Create an initial safepoint to hold JVM state during parsing
1144   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : NULL);
1145   set_map(new SafePointNode(len, jvms));
1146   jvms->set_map(map());
1147   record_for_igvn(map());
1148   assert(jvms->endoff() == len, "correct jvms sizing");
1149 
1150   SafePointNode* inmap = _caller->map();
1151   assert(inmap != NULL, "must have inmap");
1152   // In case of null check on receiver above
1153   map()->transfer_replaced_nodes_from(inmap, _new_idx);
1154 
1155   uint i;
1156 
1157   // Pass thru the predefined input parameters.
1158   for (i = 0; i < TypeFunc::Parms; i++) {
1159     map()->init_req(i, inmap->in(i));
1160   }
1161 
1162   if (depth() == 1) {
1163     assert(map()->memory()->Opcode() == Op_Parm, "");
1164     // Insert the memory aliasing node
1165     set_all_memory(reset_memory());
1166   }
1167   assert(merged_memory(), "");
1168 
1169   // Now add the locals which are initially bound to arguments:
1170   uint arg_size = tf()->domain()->cnt();
1171   ensure_stack(arg_size - TypeFunc::Parms);  // OSR methods have funny args
1172   for (i = TypeFunc::Parms; i < arg_size; i++) {
1173     map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms));
1174   }
1175 
1176   // Clear out the rest of the map (locals and stack)
1177   for (i = arg_size; i < len; i++) {
1178     map()->init_req(i, top());
1179   }
1180 
1181   SafePointNode* entry_map = stop();
1182   return entry_map;
1183 }
1184 
1185 //-----------------------------do_method_entry--------------------------------
1186 // Emit any code needed in the pseudo-block before BCI zero.
1187 // The main thing to do is lock the receiver of a synchronized method.
1188 void Parse::do_method_entry() {
1189   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1190   set_sp(0);                         // Java Stack Pointer

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

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

1635 //--------------------handle_missing_successor---------------------------------
1636 void Parse::handle_missing_successor(int target_bci) {
1637 #ifndef PRODUCT
1638   Block* b = block();
1639   int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1640   tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1641 #endif
1642   ShouldNotReachHere();
1643 }
1644 
1645 //--------------------------merge_common---------------------------------------
1646 void Parse::merge_common(Parse::Block* target, int pnum) {
1647   if (TraceOptoParse) {
1648     tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1649   }
1650 
1651   // Zap extra stack slots to top
1652   assert(sp() == target->start_sp(), "");
1653   clean_stack(sp());
1654 




































1655   if (!target->is_merged()) {   // No prior mapping at this bci
1656     if (TraceOptoParse) { tty->print(" with empty state");  }
1657 
1658     // If this path is dead, do not bother capturing it as a merge.
1659     // It is "as if" we had 1 fewer predecessors from the beginning.
1660     if (stopped()) {
1661       if (TraceOptoParse)  tty->print_cr(", but path is dead and doesn't count");
1662       return;
1663     }
1664 
1665     // Make a region if we know there are multiple or unpredictable inputs.
1666     // (Also, if this is a plain fall-through, we might see another region,
1667     // which must not be allowed into this block's map.)
1668     if (pnum > PhiNode::Input         // Known multiple inputs.
1669         || target->is_handler()       // These have unpredictable inputs.
1670         || target->is_loop_head()     // Known multiple inputs
1671         || control()->is_Region()) {  // We must hide this guy.
1672 
1673       int current_bci = bci();
1674       set_parse_bci(target->start()); // Set target bci

1688       gvn().set_type(r, Type::CONTROL);
1689       record_for_igvn(r);
1690       // zap all inputs to NULL for debugging (done in Node(uint) constructor)
1691       // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); }
1692       r->init_req(pnum, control());
1693       set_control(r);
1694       set_parse_bci(current_bci); // Restore bci
1695     }
1696 
1697     // Convert the existing Parser mapping into a mapping at this bci.
1698     store_state_to(target);
1699     assert(target->is_merged(), "do not come here twice");
1700 
1701   } else {                      // Prior mapping at this bci
1702     if (TraceOptoParse) {  tty->print(" with previous state"); }
1703 #ifdef ASSERT
1704     if (target->is_SEL_head()) {
1705       target->mark_merged_backedge(block());
1706     }
1707 #endif

1708     // We must not manufacture more phis if the target is already parsed.
1709     bool nophi = target->is_parsed();
1710 
1711     SafePointNode* newin = map();// Hang on to incoming mapping
1712     Block* save_block = block(); // Hang on to incoming block;
1713     load_state_from(target);    // Get prior mapping
1714 
1715     assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree");
1716     assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree");
1717     assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree");
1718     assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree");
1719 
1720     // Iterate over my current mapping and the old mapping.
1721     // Where different, insert Phi functions.
1722     // Use any existing Phi functions.
1723     assert(control()->is_Region(), "must be merging to a region");
1724     RegionNode* r = control()->as_Region();
1725 
1726     // Compute where to merge into
1727     // Merge incoming control path
1728     r->init_req(pnum, newin->control());
1729 
1730     if (pnum == 1) {            // Last merge for this Region?
1731       if (!block()->flow()->is_irreducible_entry()) {
1732         Node* result = _gvn.transform_no_reclaim(r);
1733         if (r != result && TraceOptoParse) {
1734           tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1735         }
1736       }
1737       record_for_igvn(r);
1738     }
1739 
1740     // Update all the non-control inputs to map:
1741     assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1742     bool check_elide_phi = target->is_SEL_backedge(save_block);

1743     for (uint j = 1; j < newin->req(); j++) {
1744       Node* m = map()->in(j);   // Current state of target.
1745       Node* n = newin->in(j);   // Incoming change to target state.
1746       PhiNode* phi;
1747       if (m->is_Phi() && m->as_Phi()->region() == r)
1748         phi = m->as_Phi();
1749       else


1750         phi = NULL;

1751       if (m != n) {             // Different; must merge
1752         switch (j) {
1753         // Frame pointer and Return Address never changes
1754         case TypeFunc::FramePtr:// Drop m, use the original value
1755         case TypeFunc::ReturnAdr:
1756           break;
1757         case TypeFunc::Memory:  // Merge inputs to the MergeMem node
1758           assert(phi == NULL, "the merge contains phis, not vice versa");
1759           merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1760           continue;
1761         default:                // All normal stuff
1762           if (phi == NULL) {
1763             const JVMState* jvms = map()->jvms();
1764             if (EliminateNestedLocks &&
1765                 jvms->is_mon(j) && jvms->is_monitor_box(j)) {
1766               // BoxLock nodes are not commoning.
1767               // Use old BoxLock node as merged box.
1768               assert(newin->jvms()->is_monitor_box(j), "sanity");
1769               // This assert also tests that nodes are BoxLock.
1770               assert(BoxLockNode::same_slot(n, m), "sanity");
1771               C->gvn_replace_by(n, m);
1772             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1773               phi = ensure_phi(j, nophi);
1774             }
1775           }
1776           break;
1777         }
1778       }
1779       // At this point, n might be top if:
1780       //  - there is no phi (because TypeFlow detected a conflict), or
1781       //  - the corresponding control edges is top (a dead incoming path)
1782       // It is a bug if we create a phi which sees a garbage value on a live path.
1783 
1784       if (phi != NULL) {























1785         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1786         assert(phi->region() == r, "");
1787         phi->set_req(pnum, n);  // Then add 'n' to the merge
1788         if (pnum == PhiNode::Input) {
1789           // Last merge for this Phi.
1790           // So far, Phis have had a reasonable type from ciTypeFlow.
1791           // Now _gvn will join that with the meet of current inputs.
1792           // BOTTOM is never permissible here, 'cause pessimistically
1793           // Phis of pointers cannot lose the basic pointer type.
1794           debug_only(const Type* bt1 = phi->bottom_type());
1795           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1796           map()->set_req(j, _gvn.transform_no_reclaim(phi));
1797           debug_only(const Type* bt2 = phi->bottom_type());
1798           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1799           record_for_igvn(phi);
1800         }
1801       }
1802     } // End of for all values to be merged
1803 
1804     if (pnum == PhiNode::Input &&
1805         !r->in(0)) {         // The occasional useless Region
1806       assert(control() == r, "");
1807       set_control(r->nonnull_req());
1808     }
1809 
1810     map()->merge_replaced_nodes_with(newin);
1811 
1812     // newin has been subsumed into the lazy merge, and is now dead.
1813     set_block(save_block);
1814 
1815     stop();                     // done with this guy, for now
1816   }
1817 
1818   if (TraceOptoParse) {
1819     tty->print_cr(" on path %d", pnum);
1820   }
1821 
1822   // Done with this parser state.
1823   assert(stopped(), "");
1824 }
1825 

1937 
1938   // Add new path to the region.
1939   uint pnum = r->req();
1940   r->add_req(NULL);
1941 
1942   for (uint i = 1; i < map->req(); i++) {
1943     Node* n = map->in(i);
1944     if (i == TypeFunc::Memory) {
1945       // Ensure a phi on all currently known memories.
1946       for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) {
1947         Node* phi = mms.memory();
1948         if (phi->is_Phi() && phi->as_Phi()->region() == r) {
1949           assert(phi->req() == pnum, "must be same size as region");
1950           phi->add_req(NULL);
1951         }
1952       }
1953     } else {
1954       if (n->is_Phi() && n->as_Phi()->region() == r) {
1955         assert(n->req() == pnum, "must be same size as region");
1956         n->add_req(NULL);


1957       }
1958     }
1959   }
1960 
1961   return pnum;
1962 }
1963 
1964 //------------------------------ensure_phi-------------------------------------
1965 // Turn the idx'th entry of the current map into a Phi
1966 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
1967   SafePointNode* map = this->map();
1968   Node* region = map->control();
1969   assert(region->is_Region(), "");
1970 
1971   Node* o = map->in(idx);
1972   assert(o != NULL, "");
1973 
1974   if (o == top())  return NULL; // TOP always merges into TOP
1975 
1976   if (o->is_Phi() && o->as_Phi()->region() == region) {
1977     return o->as_Phi();
1978   }




1979 
1980   // Now use a Phi here for merging
1981   assert(!nocreate, "Cannot build a phi for a block already parsed.");
1982   const JVMState* jvms = map->jvms();
1983   const Type* t = NULL;
1984   if (jvms->is_loc(idx)) {
1985     t = block()->local_type_at(idx - jvms->locoff());
1986   } else if (jvms->is_stk(idx)) {
1987     t = block()->stack_type_at(idx - jvms->stkoff());
1988   } else if (jvms->is_mon(idx)) {
1989     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
1990     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
1991   } else if ((uint)idx < TypeFunc::Parms) {
1992     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
1993   } else {
1994     assert(false, "no type information for this phi");
1995   }
1996 
1997   // If the type falls to bottom, then this must be a local that
1998   // is mixing ints and oops or some such.  Forcing it to top
1999   // makes it go dead.
2000   if (t == Type::BOTTOM) {
2001     map->set_req(idx, top());
2002     return NULL;
2003   }
2004 
2005   // Do not create phis for top either.
2006   // A top on a non-null control flow must be an unused even after the.phi.
2007   if (t == Type::TOP || t == Type::HALF) {
2008     map->set_req(idx, top());
2009     return NULL;
2010   }
2011 
2012   PhiNode* phi = PhiNode::make(region, o, t);
2013   gvn().set_type(phi, t);
2014   if (C->do_escape_analysis()) record_for_igvn(phi);
2015   map->set_req(idx, phi);
2016   return phi;









2017 }
2018 
2019 //--------------------------ensure_memory_phi----------------------------------
2020 // Turn the idx'th slice of the current memory into a Phi
2021 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2022   MergeMemNode* mem = merged_memory();
2023   Node* region = control();
2024   assert(region->is_Region(), "");
2025 
2026   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2027   assert(o != NULL && o != top(), "");
2028 
2029   PhiNode* phi;
2030   if (o->is_Phi() && o->as_Phi()->region() == region) {
2031     phi = o->as_Phi();
2032     if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) {
2033       // clone the shared base memory phi to make a new memory split
2034       assert(!nocreate, "Cannot build a phi for a block already parsed.");
2035       const Type* t = phi->bottom_type();
2036       const TypePtr* adr_type = C->get_adr_type(idx);

2164     Node* chk   = _gvn.transform( new CmpINode(opq, profile_state) );
2165     Node* tst   = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
2166     // Branch to failure if state was changed
2167     { BuildCutout unless(this, tst, PROB_ALWAYS);
2168       uncommon_trap(Deoptimization::Reason_rtm_state_change,
2169                     Deoptimization::Action_make_not_entrant);
2170     }
2171   }
2172 #endif
2173 }
2174 
2175 //------------------------------return_current---------------------------------
2176 // Append current _map to _exit_return
2177 void Parse::return_current(Node* value) {
2178   if (RegisterFinalizersAtInit &&
2179       method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2180     call_register_finalizer();
2181   }
2182 
2183   // Do not set_parse_bci, so that return goo is credited to the return insn.
2184   set_bci(InvocationEntryBci);



2185   if (method()->is_synchronized() && GenerateSynchronizationCode) {
2186     shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
2187   }
2188   if (C->env()->dtrace_method_probes()) {
2189     make_dtrace_method_exit(method());
2190   }
2191   SafePointNode* exit_return = _exits.map();
2192   exit_return->in( TypeFunc::Control  )->add_req( control() );
2193   exit_return->in( TypeFunc::I_O      )->add_req( i_o    () );
2194   Node *mem = exit_return->in( TypeFunc::Memory   );
2195   for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) {
2196     if (mms.is_empty()) {
2197       // get a copy of the base memory, and patch just this one input
2198       const TypePtr* adr_type = mms.adr_type(C);
2199       Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type);
2200       assert(phi->as_Phi()->region() == mms.base_memory()->in(0), "");
2201       gvn().set_type_bottom(phi);
2202       phi->del_req(phi->req()-1);  // prepare to re-patch
2203       mms.set_memory(phi);
2204     }
2205     mms.memory()->add_req(mms.memory2());
2206   }
2207 
2208   // frame pointer is always same, already captured
2209   if (value != NULL) {
2210     // If returning oops to an interface-return, there is a silent free
2211     // cast from oop to interface allowed by the Verifier.  Make it explicit
2212     // here.
2213     Node* phi = _exits.argument(0);
2214     const TypeInstPtr *tr = phi->bottom_type()->isa_instptr();
2215     if (tr && tr->is_loaded() &&
2216         tr->is_interface()) {
2217       const TypeInstPtr *tp = value->bottom_type()->isa_instptr();
2218       if (tp && tp->is_loaded() &&
2219           !tp->is_interface()) {























2220         // sharpen the type eagerly; this eases certain assert checking
2221         if (tp->higher_equal(TypeInstPtr::NOTNULL))
2222           tr = tr->join_speculative(TypeInstPtr::NOTNULL)->is_instptr();

2223         value = _gvn.transform(new CheckCastPPNode(0, value, tr));
2224       }
2225     } else {
2226       // Also handle returns of oop-arrays to an arrays-of-interface return
2227       const TypeInstPtr* phi_tip;
2228       const TypeInstPtr* val_tip;
2229       Type::get_arrays_base_elements(phi->bottom_type(), value->bottom_type(), &phi_tip, &val_tip);
2230       if (phi_tip != NULL && phi_tip->is_loaded() && phi_tip->is_interface() &&
2231           val_tip != NULL && val_tip->is_loaded() && !val_tip->is_interface()) {
2232         value = _gvn.transform(new CheckCastPPNode(0, value, phi->bottom_type()));
2233       }
2234     }
2235     phi->add_req(value);
2236   }
2237 

















2238   if (_first_return) {
2239     _exits.map()->transfer_replaced_nodes_from(map(), _new_idx);
2240     _first_return = false;
2241   } else {
2242     _exits.map()->merge_replaced_nodes_with(map());
2243   }
2244 
2245   stop_and_kill_map();          // This CFG path dies here
2246 }
2247 
2248 
2249 //------------------------------add_safepoint----------------------------------
2250 void Parse::add_safepoint() {
2251   uint parms = TypeFunc::Parms+1;
2252 
2253   // Clear out dead values from the debug info.
2254   kill_dead_locals();
2255 
2256   // Clone the JVM State
2257   SafePointNode *sfpnt = new SafePointNode(parms, NULL);

  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/method.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/c2compiler.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/convertnode.hpp"
  34 #include "opto/idealGraphPrinter.hpp"
  35 #include "opto/inlinetypenode.hpp"
  36 #include "opto/locknode.hpp"
  37 #include "opto/memnode.hpp"
  38 #include "opto/opaquenode.hpp"
  39 #include "opto/parse.hpp"
  40 #include "opto/rootnode.hpp"
  41 #include "opto/runtime.hpp"
  42 #include "opto/type.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/safepointMechanism.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 #include "utilities/bitMap.inline.hpp"
  47 #include "utilities/copy.hpp"
  48 
  49 // Static array so we can figure out which bytecodes stop us from compiling
  50 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
  51 // and eventually should be encapsulated in a proper class (gri 8/18/98).
  52 
  53 #ifndef PRODUCT
  54 int nodes_created              = 0;
  55 int methods_parsed             = 0;

  87   }
  88   if (all_null_checks_found) {
  89     tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks,
  90                   (100*implicit_null_checks)/all_null_checks_found);
  91   }
  92   if (SharedRuntime::_implicit_null_throws) {
  93     tty->print_cr("%d implicit null exceptions at runtime",
  94                   SharedRuntime::_implicit_null_throws);
  95   }
  96 
  97   if (PrintParseStatistics && BytecodeParseHistogram::initialized()) {
  98     BytecodeParseHistogram::print();
  99   }
 100 }
 101 #endif
 102 
 103 //------------------------------ON STACK REPLACEMENT---------------------------
 104 
 105 // Construct a node which can be used to get incoming state for
 106 // on stack replacement.
 107 Node* Parse::fetch_interpreter_state(int index,
 108                                      const Type* type,
 109                                      Node* local_addrs,
 110                                      Node* local_addrs_base) {
 111   BasicType bt = type->basic_type();
 112   if (type == TypePtr::NULL_PTR) {
 113     // Ptr types are mixed together with T_ADDRESS but NULL is
 114     // really for T_OBJECT types so correct it.
 115     bt = T_OBJECT;
 116   }
 117   Node *mem = memory(Compile::AliasIdxRaw);
 118   Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize );
 119   Node *ctl = control();
 120 
 121   // Very similar to LoadNode::make, except we handle un-aligned longs and
 122   // doubles on Sparc.  Intel can handle them just fine directly.
 123   Node *l = NULL;
 124   switch (bt) {                // Signature is flattened
 125   case T_INT:     l = new LoadINode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInt::INT,        MemNode::unordered); break;
 126   case T_FLOAT:   l = new LoadFNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::FLOAT,         MemNode::unordered); break;
 127   case T_ADDRESS: l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM,  MemNode::unordered); break;
 128   case T_PRIMITIVE_OBJECT:
 129   case T_OBJECT:  l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM, MemNode::unordered); break;
 130   case T_LONG:
 131   case T_DOUBLE: {
 132     // Since arguments are in reverse order, the argument address 'adr'
 133     // refers to the back half of the long/double.  Recompute adr.
 134     adr = basic_plus_adr(local_addrs_base, local_addrs, -(index+1)*wordSize);
 135     if (Matcher::misaligned_doubles_ok) {
 136       l = (bt == T_DOUBLE)
 137         ? (Node*)new LoadDNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::DOUBLE, MemNode::unordered)
 138         : (Node*)new LoadLNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeLong::LONG, MemNode::unordered);
 139     } else {
 140       l = (bt == T_DOUBLE)
 141         ? (Node*)new LoadD_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered)
 142         : (Node*)new LoadL_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered);
 143     }
 144     break;
 145   }
 146   default: ShouldNotReachHere();
 147   }
 148   return _gvn.transform(l);
 149 }
 150 
 151 // Helper routine to prevent the interpreter from handing
 152 // unexpected typestate to an OSR method.
 153 // The Node l is a value newly dug out of the interpreter frame.
 154 // The type is the type predicted by ciTypeFlow.  Note that it is
 155 // not a general type, but can only come from Type::get_typeflow_type.
 156 // The safepoint is a map which will feed an uncommon trap.
 157 Node* Parse::check_interpreter_type(Node* l, const Type* type,
 158                                     SafePointNode* &bad_type_exit) {

 159   const TypeOopPtr* tp = type->isa_oopptr();
 160 
 161   // TypeFlow may assert null-ness if a type appears unloaded.
 162   if (type == TypePtr::NULL_PTR ||
 163       (tp != NULL && !tp->is_loaded())) {
 164     // Value must be null, not a real oop.
 165     Node* chk = _gvn.transform( new CmpPNode(l, null()) );
 166     Node* tst = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
 167     IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
 168     set_control(_gvn.transform( new IfTrueNode(iff) ));
 169     Node* bad_type = _gvn.transform( new IfFalseNode(iff) );
 170     bad_type_exit->control()->add_req(bad_type);
 171     l = null();
 172   }
 173 
 174   // Typeflow can also cut off paths from the CFG, based on
 175   // types which appear unloaded, or call sites which appear unlinked.
 176   // When paths are cut off, values at later merge points can rise
 177   // toward more specific classes.  Make sure these specific classes
 178   // are still in effect.
 179   if (tp != NULL && !tp->is_same_java_type_as(TypeInstPtr::BOTTOM)) {
 180     // TypeFlow asserted a specific object type.  Value must have that type.
 181     Node* bad_type_ctrl = NULL;
 182     if (tp->is_inlinetypeptr() && !tp->maybe_null()) {
 183       // Check inline types for null here to prevent checkcast from adding an
 184       // exception state before the bytecode entry (use 'bad_type_ctrl' instead).
 185       l = null_check_oop(l, &bad_type_ctrl);
 186       bad_type_exit->control()->add_req(bad_type_ctrl);
 187     }
 188     l = gen_checkcast(l, makecon(tp->as_klass_type()->cast_to_exactness(true)), &bad_type_ctrl);
 189     bad_type_exit->control()->add_req(bad_type_ctrl);
 190   }



 191   assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate");
 192   return l;
 193 }
 194 
 195 // Helper routine which sets up elements of the initial parser map when
 196 // performing a parse for on stack replacement.  Add values into map.
 197 // The only parameter contains the address of a interpreter arguments.
 198 void Parse::load_interpreter_state(Node* osr_buf) {
 199   int index;
 200   int max_locals = jvms()->loc_size();
 201   int max_stack  = jvms()->stk_size();
 202 

 203   // Mismatch between method and jvms can occur since map briefly held
 204   // an OSR entry state (which takes up one RawPtr word).
 205   assert(max_locals == method()->max_locals(), "sanity");
 206   assert(max_stack  >= method()->max_stack(),  "sanity");
 207   assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity");
 208   assert((int)jvms()->endoff() == (int)map()->req(), "sanity");
 209 
 210   // Find the start block.
 211   Block* osr_block = start_block();
 212   assert(osr_block->start() == osr_bci(), "sanity");
 213 
 214   // Set initial BCI.
 215   set_parse_bci(osr_block->start());
 216 
 217   // Set initial stack depth.
 218   set_sp(osr_block->start_sp());
 219 
 220   // Check bailouts.  We currently do not perform on stack replacement
 221   // of loops in catch blocks or loops which branch with a non-empty stack.
 222   if (sp() != 0) {
 223     C->record_method_not_compilable("OSR starts with non-empty stack");
 224     return;
 225   }
 226   // Do not OSR inside finally clauses:
 227   if (osr_block->has_trap_at(osr_block->start())) {
 228     C->record_method_not_compilable("OSR starts with an immediate trap");
 229     return;
 230   }
 231 
 232   // Commute monitors from interpreter frame to compiler frame.
 233   assert(jvms()->monitor_depth() == 0, "should be no active locks at beginning of osr");
 234   int mcnt = osr_block->flow()->monitor_count();
 235   Node *monitors_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals+mcnt*2-1)*wordSize);
 236   for (index = 0; index < mcnt; index++) {
 237     // Make a BoxLockNode for the monitor.
 238     Node *box = _gvn.transform(new BoxLockNode(next_monitor()));
 239 

 240     // Displaced headers and locked objects are interleaved in the
 241     // temp OSR buffer.  We only copy the locked objects out here.
 242     // Fetch the locked object from the OSR temp buffer and copy to our fastlock node.
 243     Node* lock_object = fetch_interpreter_state(index*2, Type::get_const_basic_type(T_OBJECT), monitors_addr, osr_buf);
 244     // Try and copy the displaced header to the BoxNode
 245     Node* displaced_hdr = fetch_interpreter_state((index*2) + 1, Type::get_const_basic_type(T_ADDRESS), monitors_addr, osr_buf);

 246 
 247     store_to_memory(control(), box, displaced_hdr, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered);
 248 
 249     // Build a bogus FastLockNode (no code will be generated) and push the
 250     // monitor into our debug info.
 251     const FastLockNode *flock = _gvn.transform(new FastLockNode( 0, lock_object, box ))->as_FastLock();
 252     map()->push_monitor(flock);
 253 
 254     // If the lock is our method synchronization lock, tuck it away in
 255     // _sync_lock for return and rethrow exit paths.
 256     if (index == 0 && method()->is_synchronized()) {
 257       _synch_lock = flock;
 258     }
 259   }
 260 
 261   // Use the raw liveness computation to make sure that unexpected
 262   // values don't propagate into the OSR frame.
 263   MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
 264   if (!live_locals.is_valid()) {
 265     // Degenerate or breakpointed method.

 292         if (C->log() != NULL) {
 293           C->log()->elem("OSR_mismatch local_index='%d'",index);
 294         }
 295         set_local(index, null());
 296         // and ignore it for the loads
 297         continue;
 298       }
 299     }
 300 
 301     // Filter out TOP, HALF, and BOTTOM.  (Cf. ensure_phi.)
 302     if (type == Type::TOP || type == Type::HALF) {
 303       continue;
 304     }
 305     // If the type falls to bottom, then this must be a local that
 306     // is mixing ints and oops or some such.  Forcing it to top
 307     // makes it go dead.
 308     if (type == Type::BOTTOM) {
 309       continue;
 310     }
 311     // Construct code to access the appropriate local.
 312     Node* value = fetch_interpreter_state(index, type, locals_addr, osr_buf);






 313     set_local(index, value);
 314   }
 315 
 316   // Extract the needed stack entries from the interpreter frame.
 317   for (index = 0; index < sp(); index++) {
 318     const Type *type = osr_block->stack_type_at(index);
 319     if (type != Type::TOP) {
 320       // Currently the compiler bails out when attempting to on stack replace
 321       // at a bci with a non-empty stack.  We should not reach here.
 322       ShouldNotReachHere();
 323     }
 324   }
 325 
 326   // End the OSR migration
 327   make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(),
 328                     CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
 329                     "OSR_migration_end", TypeRawPtr::BOTTOM,
 330                     osr_buf);
 331 
 332   // Now that the interpreter state is loaded, make sure it will match

 582     do_method_entry();
 583   }
 584 
 585   if (depth() == 1 && !failing()) {
 586     if (C->clinit_barrier_on_entry()) {
 587       // Add check to deoptimize the nmethod once the holder class is fully initialized
 588       clinit_deopt();
 589     }
 590 
 591     // Add check to deoptimize the nmethod if RTM state was changed
 592     rtm_deopt();
 593   }
 594 
 595   // Check for bailouts during method entry or RTM state check setup.
 596   if (failing()) {
 597     if (log)  log->done("parse");
 598     C->set_default_node_notes(caller_nn);
 599     return;
 600   }
 601 
 602   // Handle inline type arguments
 603   int arg_size = method()->arg_size();
 604   for (int i = 0; i < arg_size; i++) {
 605     Node* parm = local(i);
 606     const Type* t = _gvn.type(parm);
 607     if (t->is_inlinetypeptr()) {
 608       // Create InlineTypeNode from the oop and replace the parameter
 609       Node* vt = InlineTypeNode::make_from_oop(this, parm, t->inline_klass(), !t->maybe_null());
 610       set_local(i, vt);
 611     } else if (UseTypeSpeculation && (i == (arg_size - 1)) && !is_osr_parse() &&
 612                method()->has_vararg() && t->isa_aryptr() != NULL && !t->is_aryptr()->is_not_null_free()) {
 613       // Speculate on varargs Object array being not null-free (and therefore also not flattened)
 614       const TypePtr* spec_type = t->speculative();
 615       spec_type = (spec_type != NULL && spec_type->isa_aryptr() != NULL) ? spec_type : t->is_aryptr();
 616       spec_type = spec_type->remove_speculative()->is_aryptr()->cast_to_not_null_free();
 617       spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::Offset::bottom, TypeOopPtr::InstanceBot, spec_type);
 618       Node* cast = _gvn.transform(new CheckCastPPNode(control(), parm, t->join_speculative(spec_type)));
 619       set_local(i, cast);
 620     }
 621   }
 622 
 623   entry_map = map();  // capture any changes performed by method setup code
 624   assert(jvms()->endoff() == map()->req(), "map matches JVMS layout");
 625 
 626   // We begin parsing as if we have just encountered a jump to the
 627   // method entry.
 628   Block* entry_block = start_block();
 629   assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), "");
 630   set_map_clone(entry_map);
 631   merge_common(entry_block, entry_block->next_path_num());
 632 
 633 #ifndef PRODUCT
 634   BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C);
 635   set_parse_histogram( parse_histogram_obj );
 636 #endif
 637 
 638   // Parse all the basic blocks.
 639   do_all_blocks();
 640 
 641   C->set_default_node_notes(caller_nn);
 642 

 785 void Parse::build_exits() {
 786   // make a clone of caller to prevent sharing of side-effects
 787   _exits.set_map(_exits.clone_map());
 788   _exits.clean_stack(_exits.sp());
 789   _exits.sync_jvms();
 790 
 791   RegionNode* region = new RegionNode(1);
 792   record_for_igvn(region);
 793   gvn().set_type_bottom(region);
 794   _exits.set_control(region);
 795 
 796   // Note:  iophi and memphi are not transformed until do_exits.
 797   Node* iophi  = new PhiNode(region, Type::ABIO);
 798   Node* memphi = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 799   gvn().set_type_bottom(iophi);
 800   gvn().set_type_bottom(memphi);
 801   _exits.set_i_o(iophi);
 802   _exits.set_all_memory(memphi);
 803 
 804   // Add a return value to the exit state.  (Do not push it yet.)
 805   if (tf()->range_sig()->cnt() > TypeFunc::Parms) {
 806     const Type* ret_type = tf()->range_sig()->field_at(TypeFunc::Parms);
 807     if (ret_type->isa_int()) {
 808       BasicType ret_bt = method()->return_type()->basic_type();
 809       if (ret_bt == T_BOOLEAN ||
 810           ret_bt == T_CHAR ||
 811           ret_bt == T_BYTE ||
 812           ret_bt == T_SHORT) {
 813         ret_type = TypeInt::INT;
 814       }
 815     }
 816 
 817     // Don't "bind" an unloaded return klass to the ret_phi. If the klass
 818     // becomes loaded during the subsequent parsing, the loaded and unloaded
 819     // types will not join when we transform and push in do_exits().
 820     const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr();
 821     if (ret_oop_type && !ret_oop_type->is_loaded()) {
 822       ret_type = TypeOopPtr::BOTTOM;
 823     }
 824     // Scalarize inline type when returning as fields or inlining non-incrementally
 825     if ((tf()->returns_inline_type_as_fields() || (_caller->has_method() && !Compile::current()->inlining_incrementally())) &&
 826         ret_type->is_inlinetypeptr()) {
 827       ret_type = TypeInlineType::make(ret_type->inline_klass());
 828     }
 829     int         ret_size = type2size[ret_type->basic_type()];
 830     Node*       ret_phi  = new PhiNode(region, ret_type);
 831     gvn().set_type_bottom(ret_phi);
 832     _exits.ensure_stack(ret_size);
 833     assert((int)(tf()->range_sig()->cnt() - TypeFunc::Parms) == ret_size, "good tf range");
 834     assert(method()->return_type()->size() == ret_size, "tf agrees w/ method");
 835     _exits.set_argument(0, ret_phi);  // here is where the parser finds it
 836     // Note:  ret_phi is not yet pushed, until do_exits.
 837   }
 838 }
 839 

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

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

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

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

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

1707 //--------------------handle_missing_successor---------------------------------
1708 void Parse::handle_missing_successor(int target_bci) {
1709 #ifndef PRODUCT
1710   Block* b = block();
1711   int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1712   tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1713 #endif
1714   ShouldNotReachHere();
1715 }
1716 
1717 //--------------------------merge_common---------------------------------------
1718 void Parse::merge_common(Parse::Block* target, int pnum) {
1719   if (TraceOptoParse) {
1720     tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1721   }
1722 
1723   // Zap extra stack slots to top
1724   assert(sp() == target->start_sp(), "");
1725   clean_stack(sp());
1726 
1727   // Check for merge conflicts involving inline types
1728   JVMState* old_jvms = map()->jvms();
1729   int old_bci = bci();
1730   JVMState* tmp_jvms = old_jvms->clone_shallow(C);
1731   tmp_jvms->set_should_reexecute(true);
1732   tmp_jvms->bind_map(map());
1733   // Execution needs to restart a the next bytecode (entry of next
1734   // block)
1735   if (target->is_merged() ||
1736       pnum > PhiNode::Input ||
1737       target->is_handler() ||
1738       target->is_loop_head()) {
1739     set_parse_bci(target->start());
1740     for (uint j = TypeFunc::Parms; j < map()->req(); j++) {
1741       Node* n = map()->in(j);                 // Incoming change to target state.
1742       const Type* t = NULL;
1743       if (tmp_jvms->is_loc(j)) {
1744         t = target->local_type_at(j - tmp_jvms->locoff());
1745       } else if (tmp_jvms->is_stk(j) && j < (uint)sp() + tmp_jvms->stkoff()) {
1746         t = target->stack_type_at(j - tmp_jvms->stkoff());
1747       }
1748       if (t != NULL && t != Type::BOTTOM) {
1749         if (n->is_InlineType() && !t->is_inlinetypeptr()) {
1750           // Allocate inline type in src block to be able to merge it with oop in target block
1751           map()->set_req(j, n->as_InlineType()->buffer(this));
1752         } else if (!n->is_InlineType() && t->is_inlinetypeptr()) {
1753           // Scalarize null in src block to be able to merge it with inline type in target block
1754           assert(gvn().type(n)->is_zero_type(), "Should have been scalarized");
1755           map()->set_req(j, InlineTypeNode::make_null(gvn(), t->inline_klass()));
1756         }
1757       }
1758     }
1759   }
1760   old_jvms->bind_map(map());
1761   set_parse_bci(old_bci);
1762 
1763   if (!target->is_merged()) {   // No prior mapping at this bci
1764     if (TraceOptoParse) { tty->print(" with empty state");  }
1765 
1766     // If this path is dead, do not bother capturing it as a merge.
1767     // It is "as if" we had 1 fewer predecessors from the beginning.
1768     if (stopped()) {
1769       if (TraceOptoParse)  tty->print_cr(", but path is dead and doesn't count");
1770       return;
1771     }
1772 
1773     // Make a region if we know there are multiple or unpredictable inputs.
1774     // (Also, if this is a plain fall-through, we might see another region,
1775     // which must not be allowed into this block's map.)
1776     if (pnum > PhiNode::Input         // Known multiple inputs.
1777         || target->is_handler()       // These have unpredictable inputs.
1778         || target->is_loop_head()     // Known multiple inputs
1779         || control()->is_Region()) {  // We must hide this guy.
1780 
1781       int current_bci = bci();
1782       set_parse_bci(target->start()); // Set target bci

1796       gvn().set_type(r, Type::CONTROL);
1797       record_for_igvn(r);
1798       // zap all inputs to NULL for debugging (done in Node(uint) constructor)
1799       // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); }
1800       r->init_req(pnum, control());
1801       set_control(r);
1802       set_parse_bci(current_bci); // Restore bci
1803     }
1804 
1805     // Convert the existing Parser mapping into a mapping at this bci.
1806     store_state_to(target);
1807     assert(target->is_merged(), "do not come here twice");
1808 
1809   } else {                      // Prior mapping at this bci
1810     if (TraceOptoParse) {  tty->print(" with previous state"); }
1811 #ifdef ASSERT
1812     if (target->is_SEL_head()) {
1813       target->mark_merged_backedge(block());
1814     }
1815 #endif
1816 
1817     // We must not manufacture more phis if the target is already parsed.
1818     bool nophi = target->is_parsed();
1819 
1820     SafePointNode* newin = map();// Hang on to incoming mapping
1821     Block* save_block = block(); // Hang on to incoming block;
1822     load_state_from(target);    // Get prior mapping
1823 
1824     assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree");
1825     assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree");
1826     assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree");
1827     assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree");
1828 
1829     // Iterate over my current mapping and the old mapping.
1830     // Where different, insert Phi functions.
1831     // Use any existing Phi functions.
1832     assert(control()->is_Region(), "must be merging to a region");
1833     RegionNode* r = control()->as_Region();
1834 
1835     // Compute where to merge into
1836     // Merge incoming control path
1837     r->init_req(pnum, newin->control());
1838 
1839     if (pnum == 1) {            // Last merge for this Region?
1840       if (!block()->flow()->is_irreducible_entry()) {
1841         Node* result = _gvn.transform_no_reclaim(r);
1842         if (r != result && TraceOptoParse) {
1843           tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1844         }
1845       }
1846       record_for_igvn(r);
1847     }
1848 
1849     // Update all the non-control inputs to map:
1850     assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1851     bool check_elide_phi = target->is_SEL_backedge(save_block);
1852     bool last_merge = (pnum == PhiNode::Input);
1853     for (uint j = 1; j < newin->req(); j++) {
1854       Node* m = map()->in(j);   // Current state of target.
1855       Node* n = newin->in(j);   // Incoming change to target state.
1856       PhiNode* phi;
1857       if (m->is_Phi() && m->as_Phi()->region() == r) {
1858         phi = m->as_Phi();
1859       } else if (m->is_InlineType() && m->as_InlineType()->has_phi_inputs(r)) {
1860         phi = m->as_InlineType()->get_oop()->as_Phi();
1861       } else {
1862         phi = NULL;
1863       }
1864       if (m != n) {             // Different; must merge
1865         switch (j) {
1866         // Frame pointer and Return Address never changes
1867         case TypeFunc::FramePtr:// Drop m, use the original value
1868         case TypeFunc::ReturnAdr:
1869           break;
1870         case TypeFunc::Memory:  // Merge inputs to the MergeMem node
1871           assert(phi == NULL, "the merge contains phis, not vice versa");
1872           merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1873           continue;
1874         default:                // All normal stuff
1875           if (phi == NULL) {
1876             const JVMState* jvms = map()->jvms();
1877             if (EliminateNestedLocks &&
1878                 jvms->is_mon(j) && jvms->is_monitor_box(j)) {
1879               // BoxLock nodes are not commoning.
1880               // Use old BoxLock node as merged box.
1881               assert(newin->jvms()->is_monitor_box(j), "sanity");
1882               // This assert also tests that nodes are BoxLock.
1883               assert(BoxLockNode::same_slot(n, m), "sanity");
1884               C->gvn_replace_by(n, m);
1885             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1886               phi = ensure_phi(j, nophi);
1887             }
1888           }
1889           break;
1890         }
1891       }
1892       // At this point, n might be top if:
1893       //  - there is no phi (because TypeFlow detected a conflict), or
1894       //  - the corresponding control edges is top (a dead incoming path)
1895       // It is a bug if we create a phi which sees a garbage value on a live path.
1896 
1897       // Merging two inline types?
1898       if (phi != NULL && phi->bottom_type()->is_inlinetypeptr()) {
1899         // Reload current state because it may have been updated by ensure_phi
1900         m = map()->in(j);
1901         InlineTypeNode* vtm = m->as_InlineType(); // Current inline type
1902         InlineTypeNode* vtn = n->as_InlineType(); // Incoming inline type
1903         assert(vtm->get_oop() == phi, "Inline type should have Phi input");
1904         if (TraceOptoParse) {
1905 #ifdef ASSERT
1906           tty->print_cr("\nMerging inline types");
1907           tty->print_cr("Current:");
1908           vtm->dump(2);
1909           tty->print_cr("Incoming:");
1910           vtn->dump(2);
1911           tty->cr();
1912 #endif
1913         }
1914         // Do the merge
1915         vtm->merge_with(&_gvn, vtn, pnum, last_merge);
1916         if (last_merge) {
1917           map()->set_req(j, _gvn.transform_no_reclaim(vtm));
1918           record_for_igvn(vtm);
1919         }
1920       } else if (phi != NULL) {
1921         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1922         assert(phi->region() == r, "");
1923         phi->set_req(pnum, n);  // Then add 'n' to the merge
1924         if (last_merge) {
1925           // Last merge for this Phi.
1926           // So far, Phis have had a reasonable type from ciTypeFlow.
1927           // Now _gvn will join that with the meet of current inputs.
1928           // BOTTOM is never permissible here, 'cause pessimistically
1929           // Phis of pointers cannot lose the basic pointer type.
1930           debug_only(const Type* bt1 = phi->bottom_type());
1931           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1932           map()->set_req(j, _gvn.transform_no_reclaim(phi));
1933           debug_only(const Type* bt2 = phi->bottom_type());
1934           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1935           record_for_igvn(phi);
1936         }
1937       }
1938     } // End of for all values to be merged
1939 
1940     if (last_merge && !r->in(0)) {         // The occasional useless Region

1941       assert(control() == r, "");
1942       set_control(r->nonnull_req());
1943     }
1944 
1945     map()->merge_replaced_nodes_with(newin);
1946 
1947     // newin has been subsumed into the lazy merge, and is now dead.
1948     set_block(save_block);
1949 
1950     stop();                     // done with this guy, for now
1951   }
1952 
1953   if (TraceOptoParse) {
1954     tty->print_cr(" on path %d", pnum);
1955   }
1956 
1957   // Done with this parser state.
1958   assert(stopped(), "");
1959 }
1960 

2072 
2073   // Add new path to the region.
2074   uint pnum = r->req();
2075   r->add_req(NULL);
2076 
2077   for (uint i = 1; i < map->req(); i++) {
2078     Node* n = map->in(i);
2079     if (i == TypeFunc::Memory) {
2080       // Ensure a phi on all currently known memories.
2081       for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) {
2082         Node* phi = mms.memory();
2083         if (phi->is_Phi() && phi->as_Phi()->region() == r) {
2084           assert(phi->req() == pnum, "must be same size as region");
2085           phi->add_req(NULL);
2086         }
2087       }
2088     } else {
2089       if (n->is_Phi() && n->as_Phi()->region() == r) {
2090         assert(n->req() == pnum, "must be same size as region");
2091         n->add_req(NULL);
2092       } else if (n->is_InlineType() && n->as_InlineType()->has_phi_inputs(r)) {
2093         n->as_InlineType()->add_new_path(r);
2094       }
2095     }
2096   }
2097 
2098   return pnum;
2099 }
2100 
2101 //------------------------------ensure_phi-------------------------------------
2102 // Turn the idx'th entry of the current map into a Phi
2103 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
2104   SafePointNode* map = this->map();
2105   Node* region = map->control();
2106   assert(region->is_Region(), "");
2107 
2108   Node* o = map->in(idx);
2109   assert(o != NULL, "");
2110 
2111   if (o == top())  return NULL; // TOP always merges into TOP
2112 
2113   if (o->is_Phi() && o->as_Phi()->region() == region) {
2114     return o->as_Phi();
2115   }
2116   InlineTypeNode* vt = o->isa_InlineType();
2117   if (vt != NULL && vt->has_phi_inputs(region)) {
2118     return vt->get_oop()->as_Phi();
2119   }
2120 
2121   // Now use a Phi here for merging
2122   assert(!nocreate, "Cannot build a phi for a block already parsed.");
2123   const JVMState* jvms = map->jvms();
2124   const Type* t = NULL;
2125   if (jvms->is_loc(idx)) {
2126     t = block()->local_type_at(idx - jvms->locoff());
2127   } else if (jvms->is_stk(idx)) {
2128     t = block()->stack_type_at(idx - jvms->stkoff());
2129   } else if (jvms->is_mon(idx)) {
2130     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
2131     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
2132   } else if ((uint)idx < TypeFunc::Parms) {
2133     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
2134   } else {
2135     assert(false, "no type information for this phi");
2136   }
2137 
2138   // If the type falls to bottom, then this must be a local that
2139   // is already dead or is mixing ints and oops or some such.
2140   // Forcing it to top makes it go dead.
2141   if (t == Type::BOTTOM) {
2142     map->set_req(idx, top());
2143     return NULL;
2144   }
2145 
2146   // Do not create phis for top either.
2147   // A top on a non-null control flow must be an unused even after the.phi.
2148   if (t == Type::TOP || t == Type::HALF) {
2149     map->set_req(idx, top());
2150     return NULL;
2151   }
2152 
2153   if (vt != NULL && t->is_inlinetypeptr()) {
2154     // Inline types are merged by merging their field values.
2155     // Create a cloned InlineTypeNode with phi inputs that
2156     // represents the merged inline type and update the map.
2157     vt = vt->clone_with_phis(&_gvn, region);
2158     map->set_req(idx, vt);
2159     return vt->get_oop()->as_Phi();
2160   } else {
2161     PhiNode* phi = PhiNode::make(region, o, t);
2162     gvn().set_type(phi, t);
2163     if (C->do_escape_analysis()) record_for_igvn(phi);
2164     map->set_req(idx, phi);
2165     return phi;
2166   }
2167 }
2168 
2169 //--------------------------ensure_memory_phi----------------------------------
2170 // Turn the idx'th slice of the current memory into a Phi
2171 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
2172   MergeMemNode* mem = merged_memory();
2173   Node* region = control();
2174   assert(region->is_Region(), "");
2175 
2176   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
2177   assert(o != NULL && o != top(), "");
2178 
2179   PhiNode* phi;
2180   if (o->is_Phi() && o->as_Phi()->region() == region) {
2181     phi = o->as_Phi();
2182     if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) {
2183       // clone the shared base memory phi to make a new memory split
2184       assert(!nocreate, "Cannot build a phi for a block already parsed.");
2185       const Type* t = phi->bottom_type();
2186       const TypePtr* adr_type = C->get_adr_type(idx);

2314     Node* chk   = _gvn.transform( new CmpINode(opq, profile_state) );
2315     Node* tst   = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
2316     // Branch to failure if state was changed
2317     { BuildCutout unless(this, tst, PROB_ALWAYS);
2318       uncommon_trap(Deoptimization::Reason_rtm_state_change,
2319                     Deoptimization::Action_make_not_entrant);
2320     }
2321   }
2322 #endif
2323 }
2324 
2325 //------------------------------return_current---------------------------------
2326 // Append current _map to _exit_return
2327 void Parse::return_current(Node* value) {
2328   if (RegisterFinalizersAtInit &&
2329       method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2330     call_register_finalizer();
2331   }
2332 
2333   // Do not set_parse_bci, so that return goo is credited to the return insn.
2334   // vreturn can trigger an allocation so vreturn can throw. Setting
2335   // the bci here breaks exception handling. Commenting this out
2336   // doesn't seem to break anything.
2337   //  set_bci(InvocationEntryBci);
2338   if (method()->is_synchronized() && GenerateSynchronizationCode) {
2339     shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
2340   }
2341   if (C->env()->dtrace_method_probes()) {
2342     make_dtrace_method_exit(method());
2343   }

















2344   // frame pointer is always same, already captured
2345   if (value != NULL) {



2346     Node* phi = _exits.argument(0);
2347     const Type* return_type = phi->bottom_type();
2348     const TypeInstPtr* tr = return_type->isa_instptr();
2349     // The return_type is set in Parse::build_exits().
2350     if (return_type->isa_inlinetype()) {
2351       // Inline type is returned as fields, make sure it is scalarized
2352       if (!value->is_InlineType()) {
2353         value = InlineTypeNode::make_from_oop(this, value, return_type->inline_klass(), method()->signature()->returns_null_free_inline_type());
2354       }
2355       if (!_caller->has_method() || Compile::current()->inlining_incrementally()) {
2356         // Returning from root or an incrementally inlined method. Make sure all non-flattened
2357         // fields are buffered and re-execute if allocation triggers deoptimization.
2358         PreserveReexecuteState preexecs(this);
2359         assert(tf()->returns_inline_type_as_fields(), "must be returned as fields");
2360         jvms()->set_should_reexecute(true);
2361         inc_sp(1);
2362         value = value->as_InlineType()->allocate_fields(this);
2363       }
2364     } else if (value->is_InlineType()) {
2365       // Inline type is returned as oop, make sure it is buffered and re-execute
2366       // if allocation triggers deoptimization.
2367       PreserveReexecuteState preexecs(this);
2368       jvms()->set_should_reexecute(true);
2369       inc_sp(1);
2370       value = value->as_InlineType()->buffer(this);
2371     } else if (tr && tr->isa_instptr() && tr->is_loaded() && tr->is_interface()) {
2372       // If returning oops to an interface-return, there is a silent free
2373       // cast from oop to interface allowed by the Verifier. Make it explicit here.
2374       const TypeInstPtr* tp = value->bottom_type()->isa_instptr();
2375       if (tp && tp->is_loaded() && !tp->is_interface()) {
2376         // sharpen the type eagerly; this eases certain assert checking
2377         if (tp->higher_equal(TypeInstPtr::NOTNULL)) {
2378           tr = tr->join_speculative(TypeInstPtr::NOTNULL)->is_instptr();
2379         }
2380         value = _gvn.transform(new CheckCastPPNode(0, value, tr));
2381       }
2382     } else {
2383       // Handle returns of oop-arrays to an arrays-of-interface return
2384       const TypeInstPtr* phi_tip;
2385       const TypeInstPtr* val_tip;
2386       Type::get_arrays_base_elements(return_type, value->bottom_type(), &phi_tip, &val_tip);
2387       if (phi_tip != NULL && phi_tip->is_loaded() && phi_tip->is_interface() &&
2388           val_tip != NULL && val_tip->is_loaded() && !val_tip->is_interface()) {
2389         value = _gvn.transform(new CheckCastPPNode(0, value, return_type));
2390       }
2391     }
2392     phi->add_req(value);
2393   }
2394 
2395   SafePointNode* exit_return = _exits.map();
2396   exit_return->in( TypeFunc::Control  )->add_req( control() );
2397   exit_return->in( TypeFunc::I_O      )->add_req( i_o    () );
2398   Node *mem = exit_return->in( TypeFunc::Memory   );
2399   for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) {
2400     if (mms.is_empty()) {
2401       // get a copy of the base memory, and patch just this one input
2402       const TypePtr* adr_type = mms.adr_type(C);
2403       Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type);
2404       assert(phi->as_Phi()->region() == mms.base_memory()->in(0), "");
2405       gvn().set_type_bottom(phi);
2406       phi->del_req(phi->req()-1);  // prepare to re-patch
2407       mms.set_memory(phi);
2408     }
2409     mms.memory()->add_req(mms.memory2());
2410   }
2411 
2412   if (_first_return) {
2413     _exits.map()->transfer_replaced_nodes_from(map(), _new_idx);
2414     _first_return = false;
2415   } else {
2416     _exits.map()->merge_replaced_nodes_with(map());
2417   }
2418 
2419   stop_and_kill_map();          // This CFG path dies here
2420 }
2421 
2422 
2423 //------------------------------add_safepoint----------------------------------
2424 void Parse::add_safepoint() {
2425   uint parms = TypeFunc::Parms+1;
2426 
2427   // Clear out dead values from the debug info.
2428   kill_dead_locals();
2429 
2430   // Clone the JVM State
2431   SafePointNode *sfpnt = new SafePointNode(parms, NULL);
< prev index next >