1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "oops/method.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/castnode.hpp"
  31 #include "opto/idealGraphPrinter.hpp"
  32 #include "opto/locknode.hpp"
  33 #include "opto/memnode.hpp"
  34 #include "opto/opaquenode.hpp"
  35 #include "opto/parse.hpp"
  36 #include "opto/rootnode.hpp"
  37 #include "opto/runtime.hpp"
  38 #include "runtime/arguments.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/sharedRuntime.hpp"
  41 #include "utilities/copy.hpp"
  42 
  43 // Static array so we can figure out which bytecodes stop us from compiling
  44 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
  45 // and eventually should be encapsulated in a proper class (gri 8/18/98).
  46 
  47 int nodes_created              = 0;
  48 int methods_parsed             = 0;
  49 int methods_seen               = 0;
  50 int blocks_parsed              = 0;
  51 int blocks_seen                = 0;
  52 
  53 int explicit_null_checks_inserted = 0;
  54 int explicit_null_checks_elided   = 0;
  55 int all_null_checks_found         = 0, implicit_null_checks              = 0;
  56 int implicit_null_throws          = 0;
  57 
  58 int reclaim_idx  = 0;
  59 int reclaim_in   = 0;
  60 int reclaim_node = 0;
  61 
  62 #ifndef PRODUCT
  63 bool Parse::BytecodeParseHistogram::_initialized = false;
  64 uint Parse::BytecodeParseHistogram::_bytecodes_parsed [Bytecodes::number_of_codes];
  65 uint Parse::BytecodeParseHistogram::_nodes_constructed[Bytecodes::number_of_codes];
  66 uint Parse::BytecodeParseHistogram::_nodes_transformed[Bytecodes::number_of_codes];
  67 uint Parse::BytecodeParseHistogram::_new_values       [Bytecodes::number_of_codes];
  68 #endif
  69 
  70 //------------------------------print_statistics-------------------------------
  71 #ifndef PRODUCT
  72 void Parse::print_statistics() {
  73   tty->print_cr("--- Compiler Statistics ---");
  74   tty->print("Methods seen: %d  Methods parsed: %d", methods_seen, methods_parsed);
  75   tty->print("  Nodes created: %d", nodes_created);
  76   tty->cr();
  77   if (methods_seen != methods_parsed)
  78     tty->print_cr("Reasons for parse failures (NOT cumulative):");
  79   tty->print_cr("Blocks parsed: %d  Blocks seen: %d", blocks_parsed, blocks_seen);
  80 
  81   if( explicit_null_checks_inserted )
  82     tty->print_cr("%d original NULL checks - %d elided (%2d%%); optimizer leaves %d,", explicit_null_checks_inserted, explicit_null_checks_elided, (100*explicit_null_checks_elided)/explicit_null_checks_inserted, all_null_checks_found);
  83   if( all_null_checks_found )
  84     tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks,
  85                   (100*implicit_null_checks)/all_null_checks_found);
  86   if( implicit_null_throws )
  87     tty->print_cr("%d implicit null exceptions at runtime",
  88                   implicit_null_throws);
  89 
  90   if( PrintParseStatistics && BytecodeParseHistogram::initialized() ) {
  91     BytecodeParseHistogram::print();
  92   }
  93 }
  94 #endif
  95 
  96 //------------------------------ON STACK REPLACEMENT---------------------------
  97 
  98 // Construct a node which can be used to get incoming state for
  99 // on stack replacement.
 100 Node *Parse::fetch_interpreter_state(int index,
 101                                      BasicType bt,
 102                                      Node *local_addrs,
 103                                      Node *local_addrs_base) {
 104   Node *mem = memory(Compile::AliasIdxRaw);
 105   Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize );
 106   Node *ctl = control();
 107 
 108   // Very similar to LoadNode::make, except we handle un-aligned longs and
 109   // doubles on Sparc.  Intel can handle them just fine directly.
 110   Node *l;
 111   switch (bt) {                // Signature is flattened
 112   case T_INT:     l = new LoadINode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInt::INT,        MemNode::unordered); break;
 113   case T_FLOAT:   l = new LoadFNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::FLOAT,         MemNode::unordered); break;
 114   case T_ADDRESS: l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM,  MemNode::unordered); break;
 115   case T_OBJECT:  l = new LoadPNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM, MemNode::unordered); break;
 116   case T_LONG:
 117   case T_DOUBLE: {
 118     // Since arguments are in reverse order, the argument address 'adr'
 119     // refers to the back half of the long/double.  Recompute adr.
 120     adr = basic_plus_adr(local_addrs_base, local_addrs, -(index+1)*wordSize);
 121     if (Matcher::misaligned_doubles_ok) {
 122       l = (bt == T_DOUBLE)
 123         ? (Node*)new LoadDNode(ctl, mem, adr, TypeRawPtr::BOTTOM, Type::DOUBLE, MemNode::unordered)
 124         : (Node*)new LoadLNode(ctl, mem, adr, TypeRawPtr::BOTTOM, TypeLong::LONG, MemNode::unordered);
 125     } else {
 126       l = (bt == T_DOUBLE)
 127         ? (Node*)new LoadD_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered)
 128         : (Node*)new LoadL_unalignedNode(ctl, mem, adr, TypeRawPtr::BOTTOM, MemNode::unordered);
 129     }
 130     break;
 131   }
 132   default: ShouldNotReachHere();
 133   }
 134   return _gvn.transform(l);
 135 }
 136 
 137 // Helper routine to prevent the interpreter from handing
 138 // unexpected typestate to an OSR method.
 139 // The Node l is a value newly dug out of the interpreter frame.
 140 // The type is the type predicted by ciTypeFlow.  Note that it is
 141 // not a general type, but can only come from Type::get_typeflow_type.
 142 // The safepoint is a map which will feed an uncommon trap.
 143 Node* Parse::check_interpreter_type(Node* l, const Type* type,
 144                                     SafePointNode* &bad_type_exit) {
 145 
 146   const TypeOopPtr* tp = type->isa_oopptr();
 147 
 148   // TypeFlow may assert null-ness if a type appears unloaded.
 149   if (type == TypePtr::NULL_PTR ||
 150       (tp != NULL && !tp->klass()->is_loaded())) {
 151     // Value must be null, not a real oop.
 152     Node* chk = _gvn.transform( new CmpPNode(l, null()) );
 153     Node* tst = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
 154     IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
 155     set_control(_gvn.transform( new IfTrueNode(iff) ));
 156     Node* bad_type = _gvn.transform( new IfFalseNode(iff) );
 157     bad_type_exit->control()->add_req(bad_type);
 158     l = null();
 159   }
 160 
 161   // Typeflow can also cut off paths from the CFG, based on
 162   // types which appear unloaded, or call sites which appear unlinked.
 163   // When paths are cut off, values at later merge points can rise
 164   // toward more specific classes.  Make sure these specific classes
 165   // are still in effect.
 166   if (tp != NULL && tp->klass() != C->env()->Object_klass()) {
 167     // TypeFlow asserted a specific object type.  Value must have that type.
 168     Node* bad_type_ctrl = NULL;
 169     l = gen_checkcast(l, makecon(TypeKlassPtr::make(tp->klass())), &bad_type_ctrl);
 170     bad_type_exit->control()->add_req(bad_type_ctrl);
 171   }
 172 
 173   BasicType bt_l = _gvn.type(l)->basic_type();
 174   BasicType bt_t = type->basic_type();
 175   assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate");
 176   return l;
 177 }
 178 
 179 // Helper routine which sets up elements of the initial parser map when
 180 // performing a parse for on stack replacement.  Add values into map.
 181 // The only parameter contains the address of a interpreter arguments.
 182 void Parse::load_interpreter_state(Node* osr_buf) {
 183   int index;
 184   int max_locals = jvms()->loc_size();
 185   int max_stack  = jvms()->stk_size();
 186 
 187 
 188   // Mismatch between method and jvms can occur since map briefly held
 189   // an OSR entry state (which takes up one RawPtr word).
 190   assert(max_locals == method()->max_locals(), "sanity");
 191   assert(max_stack  >= method()->max_stack(),  "sanity");
 192   assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity");
 193   assert((int)jvms()->endoff() == (int)map()->req(), "sanity");
 194 
 195   // Find the start block.
 196   Block* osr_block = start_block();
 197   assert(osr_block->start() == osr_bci(), "sanity");
 198 
 199   // Set initial BCI.
 200   set_parse_bci(osr_block->start());
 201 
 202   // Set initial stack depth.
 203   set_sp(osr_block->start_sp());
 204 
 205   // Check bailouts.  We currently do not perform on stack replacement
 206   // of loops in catch blocks or loops which branch with a non-empty stack.
 207   if (sp() != 0) {
 208     C->record_method_not_compilable("OSR starts with non-empty stack");
 209     return;
 210   }
 211   // Do not OSR inside finally clauses:
 212   if (osr_block->has_trap_at(osr_block->start())) {
 213     C->record_method_not_compilable("OSR starts with an immediate trap");
 214     return;
 215   }
 216 
 217   // Commute monitors from interpreter frame to compiler frame.
 218   assert(jvms()->monitor_depth() == 0, "should be no active locks at beginning of osr");
 219   int mcnt = osr_block->flow()->monitor_count();
 220   Node *monitors_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals+mcnt*2-1)*wordSize);
 221   for (index = 0; index < mcnt; index++) {
 222     // Make a BoxLockNode for the monitor.
 223     Node *box = _gvn.transform(new BoxLockNode(next_monitor()));
 224 
 225 
 226     // Displaced headers and locked objects are interleaved in the
 227     // temp OSR buffer.  We only copy the locked objects out here.
 228     // Fetch the locked object from the OSR temp buffer and copy to our fastlock node.
 229     Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf);
 230     // Try and copy the displaced header to the BoxNode
 231     Node *displaced_hdr = fetch_interpreter_state((index*2) + 1, T_ADDRESS, monitors_addr, osr_buf);
 232 
 233 
 234     store_to_memory(control(), box, displaced_hdr, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered);
 235 
 236     // Build a bogus FastLockNode (no code will be generated) and push the
 237     // monitor into our debug info.
 238     const FastLockNode *flock = _gvn.transform(new FastLockNode( 0, lock_object, box ))->as_FastLock();
 239     map()->push_monitor(flock);
 240 
 241     // If the lock is our method synchronization lock, tuck it away in
 242     // _sync_lock for return and rethrow exit paths.
 243     if (index == 0 && method()->is_synchronized()) {
 244       _synch_lock = flock;
 245     }
 246   }
 247 
 248   // Use the raw liveness computation to make sure that unexpected
 249   // values don't propagate into the OSR frame.
 250   MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci());
 251   if (!live_locals.is_valid()) {
 252     // Degenerate or breakpointed method.
 253     C->record_method_not_compilable("OSR in empty or breakpointed method");
 254     return;
 255   }
 256 
 257   // Extract the needed locals from the interpreter frame.
 258   Node *locals_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals-1)*wordSize);
 259 
 260   // find all the locals that the interpreter thinks contain live oops
 261   const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci());
 262   for (index = 0; index < max_locals; index++) {
 263 
 264     if (!live_locals.at(index)) {
 265       continue;
 266     }
 267 
 268     const Type *type = osr_block->local_type_at(index);
 269 
 270     if (type->isa_oopptr() != NULL) {
 271 
 272       // 6403625: Verify that the interpreter oopMap thinks that the oop is live
 273       // else we might load a stale oop if the MethodLiveness disagrees with the
 274       // result of the interpreter. If the interpreter says it is dead we agree
 275       // by making the value go to top.
 276       //
 277 
 278       if (!live_oops.at(index)) {
 279         if (C->log() != NULL) {
 280           C->log()->elem("OSR_mismatch local_index='%d'",index);
 281         }
 282         set_local(index, null());
 283         // and ignore it for the loads
 284         continue;
 285       }
 286     }
 287 
 288     // Filter out TOP, HALF, and BOTTOM.  (Cf. ensure_phi.)
 289     if (type == Type::TOP || type == Type::HALF) {
 290       continue;
 291     }
 292     // If the type falls to bottom, then this must be a local that
 293     // is mixing ints and oops or some such.  Forcing it to top
 294     // makes it go dead.
 295     if (type == Type::BOTTOM) {
 296       continue;
 297     }
 298     // Construct code to access the appropriate local.
 299     BasicType bt = type->basic_type();
 300     if (type == TypePtr::NULL_PTR) {
 301       // Ptr types are mixed together with T_ADDRESS but NULL is
 302       // really for T_OBJECT types so correct it.
 303       bt = T_OBJECT;
 304     }
 305     Node *value = fetch_interpreter_state(index, bt, locals_addr, osr_buf);
 306     set_local(index, value);
 307   }
 308 
 309   // Extract the needed stack entries from the interpreter frame.
 310   for (index = 0; index < sp(); index++) {
 311     const Type *type = osr_block->stack_type_at(index);
 312     if (type != Type::TOP) {
 313       // Currently the compiler bails out when attempting to on stack replace
 314       // at a bci with a non-empty stack.  We should not reach here.
 315       ShouldNotReachHere();
 316     }
 317   }
 318 
 319   // End the OSR migration
 320   make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(),
 321                     CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end),
 322                     "OSR_migration_end", TypeRawPtr::BOTTOM,
 323                     osr_buf);
 324 
 325   // Now that the interpreter state is loaded, make sure it will match
 326   // at execution time what the compiler is expecting now:
 327   SafePointNode* bad_type_exit = clone_map();
 328   bad_type_exit->set_control(new RegionNode(1));
 329 
 330   assert(osr_block->flow()->jsrs()->size() == 0, "should be no jsrs live at osr point");
 331   for (index = 0; index < max_locals; index++) {
 332     if (stopped())  break;
 333     Node* l = local(index);
 334     if (l->is_top())  continue;  // nothing here
 335     const Type *type = osr_block->local_type_at(index);
 336     if (type->isa_oopptr() != NULL) {
 337       if (!live_oops.at(index)) {
 338         // skip type check for dead oops
 339         continue;
 340       }
 341     }
 342     if (osr_block->flow()->local_type_at(index)->is_return_address()) {
 343       // In our current system it's illegal for jsr addresses to be
 344       // live into an OSR entry point because the compiler performs
 345       // inlining of jsrs.  ciTypeFlow has a bailout that detect this
 346       // case and aborts the compile if addresses are live into an OSR
 347       // entry point.  Because of that we can assume that any address
 348       // locals at the OSR entry point are dead.  Method liveness
 349       // isn't precise enought to figure out that they are dead in all
 350       // cases so simply skip checking address locals all
 351       // together. Any type check is guaranteed to fail since the
 352       // interpreter type is the result of a load which might have any
 353       // value and the expected type is a constant.
 354       continue;
 355     }
 356     set_local(index, check_interpreter_type(l, type, bad_type_exit));
 357   }
 358 
 359   for (index = 0; index < sp(); index++) {
 360     if (stopped())  break;
 361     Node* l = stack(index);
 362     if (l->is_top())  continue;  // nothing here
 363     const Type *type = osr_block->stack_type_at(index);
 364     set_stack(index, check_interpreter_type(l, type, bad_type_exit));
 365   }
 366 
 367   if (bad_type_exit->control()->req() > 1) {
 368     // Build an uncommon trap here, if any inputs can be unexpected.
 369     bad_type_exit->set_control(_gvn.transform( bad_type_exit->control() ));
 370     record_for_igvn(bad_type_exit->control());
 371     SafePointNode* types_are_good = map();
 372     set_map(bad_type_exit);
 373     // The unexpected type happens because a new edge is active
 374     // in the CFG, which typeflow had previously ignored.
 375     // E.g., Object x = coldAtFirst() && notReached()? "str": new Integer(123).
 376     // This x will be typed as Integer if notReached is not yet linked.
 377     // It could also happen due to a problem in ciTypeFlow analysis.
 378     uncommon_trap(Deoptimization::Reason_constraint,
 379                   Deoptimization::Action_reinterpret);
 380     set_map(types_are_good);
 381   }
 382 }
 383 
 384 //------------------------------Parse------------------------------------------
 385 // Main parser constructor.
 386 Parse::Parse(JVMState* caller, ciMethod* parse_method, float expected_uses)
 387   : _exits(caller)
 388 {
 389   // Init some variables
 390   _caller = caller;
 391   _method = parse_method;
 392   _expected_uses = expected_uses;
 393   _depth = 1 + (caller->has_method() ? caller->depth() : 0);
 394   _wrote_final = false;
 395   _wrote_volatile = false;
 396   _wrote_stable = false;
 397   _wrote_fields = false;
 398   _alloc_with_final = NULL;
 399   _entry_bci = InvocationEntryBci;
 400   _tf = NULL;
 401   _block = NULL;
 402   _first_return = true;
 403   _replaced_nodes_for_exceptions = false;
 404   _new_idx = C->unique();
 405   debug_only(_block_count = -1);
 406   debug_only(_blocks = (Block*)-1);
 407 #ifndef PRODUCT
 408   if (PrintCompilation || PrintOpto) {
 409     // Make sure I have an inline tree, so I can print messages about it.
 410     JVMState* ilt_caller = is_osr_parse() ? caller->caller() : caller;
 411     InlineTree::find_subtree_from_root(C->ilt(), ilt_caller, parse_method);
 412   }
 413   _max_switch_depth = 0;
 414   _est_switch_depth = 0;
 415 #endif
 416 
 417   _tf = TypeFunc::make(method());
 418   _iter.reset_to_method(method());
 419   _flow = method()->get_flow_analysis();
 420   if (_flow->failing()) {
 421     C->record_method_not_compilable_all_tiers(_flow->failure_reason());
 422   }
 423 
 424 #ifndef PRODUCT
 425   if (_flow->has_irreducible_entry()) {
 426     C->set_parsed_irreducible_loop(true);
 427   }
 428 #endif
 429 
 430   if (_expected_uses <= 0) {
 431     _prof_factor = 1;
 432   } else {
 433     float prof_total = parse_method->interpreter_invocation_count();
 434     if (prof_total <= _expected_uses) {
 435       _prof_factor = 1;
 436     } else {
 437       _prof_factor = _expected_uses / prof_total;
 438     }
 439   }
 440 
 441   CompileLog* log = C->log();
 442   if (log != NULL) {
 443     log->begin_head("parse method='%d' uses='%g'",
 444                     log->identify(parse_method), expected_uses);
 445     if (depth() == 1 && C->is_osr_compilation()) {
 446       log->print(" osr_bci='%d'", C->entry_bci());
 447     }
 448     log->stamp();
 449     log->end_head();
 450   }
 451 
 452   // Accumulate deoptimization counts.
 453   // (The range_check and store_check counts are checked elsewhere.)
 454   ciMethodData* md = method()->method_data();
 455   for (uint reason = 0; reason < md->trap_reason_limit(); reason++) {
 456     uint md_count = md->trap_count(reason);
 457     if (md_count != 0) {
 458       if (md_count == md->trap_count_limit())
 459         md_count += md->overflow_trap_count();
 460       uint total_count = C->trap_count(reason);
 461       uint old_count   = total_count;
 462       total_count += md_count;
 463       // Saturate the add if it overflows.
 464       if (total_count < old_count || total_count < md_count)
 465         total_count = (uint)-1;
 466       C->set_trap_count(reason, total_count);
 467       if (log != NULL)
 468         log->elem("observe trap='%s' count='%d' total='%d'",
 469                   Deoptimization::trap_reason_name(reason),
 470                   md_count, total_count);
 471     }
 472   }
 473   // Accumulate total sum of decompilations, also.
 474   C->set_decompile_count(C->decompile_count() + md->decompile_count());
 475 
 476   _count_invocations = C->do_count_invocations();
 477   _method_data_update = C->do_method_data_update();
 478 
 479   if (log != NULL && method()->has_exception_handlers()) {
 480     log->elem("observe that='has_exception_handlers'");
 481   }
 482 
 483   assert(method()->can_be_compiled(),       "Can not parse this method, cutout earlier");
 484   assert(method()->has_balanced_monitors(), "Can not parse unbalanced monitors, cutout earlier");
 485 
 486   // Always register dependence if JVMTI is enabled, because
 487   // either breakpoint setting or hotswapping of methods may
 488   // cause deoptimization.
 489   if (C->env()->jvmti_can_hotswap_or_post_breakpoint()) {
 490     C->dependencies()->assert_evol_method(method());
 491   }
 492 
 493   methods_seen++;
 494 
 495   // Do some special top-level things.
 496   if (depth() == 1 && C->is_osr_compilation()) {
 497     _entry_bci = C->entry_bci();
 498     _flow = method()->get_osr_flow_analysis(osr_bci());
 499     if (_flow->failing()) {
 500       C->record_method_not_compilable(_flow->failure_reason());
 501 #ifndef PRODUCT
 502       if (PrintOpto && (Verbose || WizardMode)) {
 503         tty->print_cr("OSR @%d type flow bailout: %s", _entry_bci, _flow->failure_reason());
 504         if (Verbose) {
 505           method()->print();
 506           method()->print_codes();
 507           _flow->print();
 508         }
 509       }
 510 #endif
 511     }
 512     _tf = C->tf();     // the OSR entry type is different
 513   }
 514 
 515 #ifdef ASSERT
 516   if (depth() == 1) {
 517     assert(C->is_osr_compilation() == this->is_osr_parse(), "OSR in sync");
 518     if (C->tf() != tf()) {
 519       MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
 520       assert(C->env()->system_dictionary_modification_counter_changed(),
 521              "Must invalidate if TypeFuncs differ");
 522     }
 523   } else {
 524     assert(!this->is_osr_parse(), "no recursive OSR");
 525   }
 526 #endif
 527 
 528   methods_parsed++;
 529 #ifndef PRODUCT
 530   // add method size here to guarantee that inlined methods are added too
 531   if (CITime)
 532     _total_bytes_compiled += method()->code_size();
 533 
 534   show_parse_info();
 535 #endif
 536 
 537   if (failing()) {
 538     if (log)  log->done("parse");
 539     return;
 540   }
 541 
 542   gvn().set_type(root(), root()->bottom_type());
 543   gvn().transform(top());
 544 
 545   // Import the results of the ciTypeFlow.
 546   init_blocks();
 547 
 548   // Merge point for all normal exits
 549   build_exits();
 550 
 551   // Setup the initial JVM state map.
 552   SafePointNode* entry_map = create_entry_map();
 553 
 554   // Check for bailouts during map initialization
 555   if (failing() || entry_map == NULL) {
 556     if (log)  log->done("parse");
 557     return;
 558   }
 559 
 560   Node_Notes* caller_nn = C->default_node_notes();
 561   // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls.
 562   if (DebugInlinedCalls || depth() == 1) {
 563     C->set_default_node_notes(make_node_notes(caller_nn));
 564   }
 565 
 566   if (is_osr_parse()) {
 567     Node* osr_buf = entry_map->in(TypeFunc::Parms+0);
 568     entry_map->set_req(TypeFunc::Parms+0, top());
 569     set_map(entry_map);
 570     load_interpreter_state(osr_buf);
 571   } else {
 572     set_map(entry_map);
 573     do_method_entry();
 574     if (depth() == 1 && C->age_code()) {
 575       decrement_age();
 576     }
 577   }
 578 
 579   if (depth() == 1 && !failing()) {
 580     // Add check to deoptimize the nmethod if RTM state was changed
 581     rtm_deopt();
 582   }
 583 
 584   // Check for bailouts during method entry or RTM state check setup.
 585   if (failing()) {
 586     if (log)  log->done("parse");
 587     C->set_default_node_notes(caller_nn);
 588     return;
 589   }
 590 
 591   entry_map = map();  // capture any changes performed by method setup code
 592   assert(jvms()->endoff() == map()->req(), "map matches JVMS layout");
 593 
 594   // We begin parsing as if we have just encountered a jump to the
 595   // method entry.
 596   Block* entry_block = start_block();
 597   assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), "");
 598   set_map_clone(entry_map);
 599   merge_common(entry_block, entry_block->next_path_num());
 600 
 601 #ifndef PRODUCT
 602   BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C);
 603   set_parse_histogram( parse_histogram_obj );
 604 #endif
 605 
 606   // Parse all the basic blocks.
 607   do_all_blocks();
 608 
 609   C->set_default_node_notes(caller_nn);
 610 
 611   // Check for bailouts during conversion to graph
 612   if (failing()) {
 613     if (log)  log->done("parse");
 614     return;
 615   }
 616 
 617   // Fix up all exiting control flow.
 618   set_map(entry_map);
 619   do_exits();
 620 
 621   if (log)  log->done("parse nodes='%d' live='%d' memory='" SIZE_FORMAT "'",
 622                       C->unique(), C->live_nodes(), C->node_arena()->used());
 623 }
 624 
 625 //---------------------------do_all_blocks-------------------------------------
 626 void Parse::do_all_blocks() {
 627   bool has_irreducible = flow()->has_irreducible_entry();
 628 
 629   // Walk over all blocks in Reverse Post-Order.
 630   while (true) {
 631     bool progress = false;
 632     for (int rpo = 0; rpo < block_count(); rpo++) {
 633       Block* block = rpo_at(rpo);
 634 
 635       if (block->is_parsed()) continue;
 636 
 637       if (!block->is_merged()) {
 638         // Dead block, no state reaches this block
 639         continue;
 640       }
 641 
 642       // Prepare to parse this block.
 643       load_state_from(block);
 644 
 645       if (stopped()) {
 646         // Block is dead.
 647         continue;
 648       }
 649 
 650       blocks_parsed++;
 651 
 652       progress = true;
 653       if (block->is_loop_head() || block->is_handler() || has_irreducible && !block->is_ready()) {
 654         // Not all preds have been parsed.  We must build phis everywhere.
 655         // (Note that dead locals do not get phis built, ever.)
 656         ensure_phis_everywhere();
 657 
 658         if (block->is_SEL_head() &&
 659             (UseLoopPredicate || LoopLimitCheck)) {
 660           // Add predicate to single entry (not irreducible) loop head.
 661           assert(!block->has_merged_backedge(), "only entry paths should be merged for now");
 662           // Need correct bci for predicate.
 663           // It is fine to set it here since do_one_block() will set it anyway.
 664           set_parse_bci(block->start());
 665           add_predicate();
 666           // Add new region for back branches.
 667           int edges = block->pred_count() - block->preds_parsed() + 1; // +1 for original region
 668           RegionNode *r = new RegionNode(edges+1);
 669           _gvn.set_type(r, Type::CONTROL);
 670           record_for_igvn(r);
 671           r->init_req(edges, control());
 672           set_control(r);
 673           // Add new phis.
 674           ensure_phis_everywhere();
 675         }
 676 
 677         // Leave behind an undisturbed copy of the map, for future merges.
 678         set_map(clone_map());
 679       }
 680 
 681       if (control()->is_Region() && !block->is_loop_head() && !has_irreducible && !block->is_handler()) {
 682         // In the absence of irreducible loops, the Region and Phis
 683         // associated with a merge that doesn't involve a backedge can
 684         // be simplified now since the RPO parsing order guarantees
 685         // that any path which was supposed to reach here has already
 686         // been parsed or must be dead.
 687         Node* c = control();
 688         Node* result = _gvn.transform_no_reclaim(control());
 689         if (c != result && TraceOptoParse) {
 690           tty->print_cr("Block #%d replace %d with %d", block->rpo(), c->_idx, result->_idx);
 691         }
 692         if (result != top()) {
 693           record_for_igvn(result);
 694         }
 695       }
 696 
 697       // Parse the block.
 698       do_one_block();
 699 
 700       // Check for bailouts.
 701       if (failing())  return;
 702     }
 703 
 704     // with irreducible loops multiple passes might be necessary to parse everything
 705     if (!has_irreducible || !progress) {
 706       break;
 707     }
 708   }
 709 
 710   blocks_seen += block_count();
 711 
 712 #ifndef PRODUCT
 713   // Make sure there are no half-processed blocks remaining.
 714   // Every remaining unprocessed block is dead and may be ignored now.
 715   for (int rpo = 0; rpo < block_count(); rpo++) {
 716     Block* block = rpo_at(rpo);
 717     if (!block->is_parsed()) {
 718       if (TraceOptoParse) {
 719         tty->print_cr("Skipped dead block %d at bci:%d", rpo, block->start());
 720       }
 721       assert(!block->is_merged(), "no half-processed blocks");
 722     }
 723   }
 724 #endif
 725 }
 726 
 727 //-------------------------------build_exits----------------------------------
 728 // Build normal and exceptional exit merge points.
 729 void Parse::build_exits() {
 730   // make a clone of caller to prevent sharing of side-effects
 731   _exits.set_map(_exits.clone_map());
 732   _exits.clean_stack(_exits.sp());
 733   _exits.sync_jvms();
 734 
 735   RegionNode* region = new RegionNode(1);
 736   record_for_igvn(region);
 737   gvn().set_type_bottom(region);
 738   _exits.set_control(region);
 739 
 740   // Note:  iophi and memphi are not transformed until do_exits.
 741   Node* iophi  = new PhiNode(region, Type::ABIO);
 742   Node* memphi = new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
 743   gvn().set_type_bottom(iophi);
 744   gvn().set_type_bottom(memphi);
 745   _exits.set_i_o(iophi);
 746   _exits.set_all_memory(memphi);
 747 
 748   // Add a return value to the exit state.  (Do not push it yet.)
 749   if (tf()->range()->cnt() > TypeFunc::Parms) {
 750     const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms);
 751     // Don't "bind" an unloaded return klass to the ret_phi. If the klass
 752     // becomes loaded during the subsequent parsing, the loaded and unloaded
 753     // types will not join when we transform and push in do_exits().
 754     const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr();
 755     if (ret_oop_type && !ret_oop_type->klass()->is_loaded()) {
 756       ret_type = TypeOopPtr::BOTTOM;
 757     }
 758     int         ret_size = type2size[ret_type->basic_type()];
 759     Node*       ret_phi  = new PhiNode(region, ret_type);
 760     gvn().set_type_bottom(ret_phi);
 761     _exits.ensure_stack(ret_size);
 762     assert((int)(tf()->range()->cnt() - TypeFunc::Parms) == ret_size, "good tf range");
 763     assert(method()->return_type()->size() == ret_size, "tf agrees w/ method");
 764     _exits.set_argument(0, ret_phi);  // here is where the parser finds it
 765     // Note:  ret_phi is not yet pushed, until do_exits.
 766   }
 767 }
 768 
 769 
 770 //----------------------------build_start_state-------------------------------
 771 // Construct a state which contains only the incoming arguments from an
 772 // unknown caller.  The method & bci will be NULL & InvocationEntryBci.
 773 JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) {
 774   int        arg_size = tf->domain()->cnt();
 775   int        max_size = MAX2(arg_size, (int)tf->range()->cnt());
 776   JVMState*  jvms     = new (this) JVMState(max_size - TypeFunc::Parms);
 777   SafePointNode* map  = new SafePointNode(max_size, NULL);
 778   record_for_igvn(map);
 779   assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size");
 780   Node_Notes* old_nn = default_node_notes();
 781   if (old_nn != NULL && has_method()) {
 782     Node_Notes* entry_nn = old_nn->clone(this);
 783     JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms());
 784     entry_jvms->set_offsets(0);
 785     entry_jvms->set_bci(entry_bci());
 786     entry_nn->set_jvms(entry_jvms);
 787     set_default_node_notes(entry_nn);
 788   }
 789   uint i;
 790   for (i = 0; i < (uint)arg_size; i++) {
 791     Node* parm = initial_gvn()->transform(new ParmNode(start, i));
 792     map->init_req(i, parm);
 793     // Record all these guys for later GVN.
 794     record_for_igvn(parm);
 795   }
 796   for (; i < map->req(); i++) {
 797     map->init_req(i, top());
 798   }
 799   assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here");
 800   set_default_node_notes(old_nn);
 801   map->set_jvms(jvms);
 802   jvms->set_map(map);
 803   return jvms;
 804 }
 805 
 806 //-----------------------------make_node_notes---------------------------------
 807 Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) {
 808   if (caller_nn == NULL)  return NULL;
 809   Node_Notes* nn = caller_nn->clone(C);
 810   JVMState* caller_jvms = nn->jvms();
 811   JVMState* jvms = new (C) JVMState(method(), caller_jvms);
 812   jvms->set_offsets(0);
 813   jvms->set_bci(_entry_bci);
 814   nn->set_jvms(jvms);
 815   return nn;
 816 }
 817 
 818 
 819 //--------------------------return_values--------------------------------------
 820 void Compile::return_values(JVMState* jvms) {
 821   GraphKit kit(jvms);
 822   Node* ret = new ReturnNode(TypeFunc::Parms,
 823                              kit.control(),
 824                              kit.i_o(),
 825                              kit.reset_memory(),
 826                              kit.frameptr(),
 827                              kit.returnadr());
 828   // Add zero or 1 return values
 829   int ret_size = tf()->range()->cnt() - TypeFunc::Parms;
 830   if (ret_size > 0) {
 831     kit.inc_sp(-ret_size);  // pop the return value(s)
 832     kit.sync_jvms();
 833     ret->add_req(kit.argument(0));
 834     // Note:  The second dummy edge is not needed by a ReturnNode.
 835   }
 836   // bind it to root
 837   root()->add_req(ret);
 838   record_for_igvn(ret);
 839   initial_gvn()->transform_no_reclaim(ret);
 840 }
 841 
 842 //------------------------rethrow_exceptions-----------------------------------
 843 // Bind all exception states in the list into a single RethrowNode.
 844 void Compile::rethrow_exceptions(JVMState* jvms) {
 845   GraphKit kit(jvms);
 846   if (!kit.has_exceptions())  return;  // nothing to generate
 847   // Load my combined exception state into the kit, with all phis transformed:
 848   SafePointNode* ex_map = kit.combine_and_pop_all_exception_states();
 849   Node* ex_oop = kit.use_exception_state(ex_map);
 850   RethrowNode* exit = new RethrowNode(kit.control(),
 851                                       kit.i_o(), kit.reset_memory(),
 852                                       kit.frameptr(), kit.returnadr(),
 853                                       // like a return but with exception input
 854                                       ex_oop);
 855   // bind to root
 856   root()->add_req(exit);
 857   record_for_igvn(exit);
 858   initial_gvn()->transform_no_reclaim(exit);
 859 }
 860 
 861 //---------------------------do_exceptions-------------------------------------
 862 // Process exceptions arising from the current bytecode.
 863 // Send caught exceptions to the proper handler within this method.
 864 // Unhandled exceptions feed into _exit.
 865 void Parse::do_exceptions() {
 866   if (!has_exceptions())  return;
 867 
 868   if (failing()) {
 869     // Pop them all off and throw them away.
 870     while (pop_exception_state() != NULL) ;
 871     return;
 872   }
 873 
 874   PreserveJVMState pjvms(this, false);
 875 
 876   SafePointNode* ex_map;
 877   while ((ex_map = pop_exception_state()) != NULL) {
 878     if (!method()->has_exception_handlers()) {
 879       // Common case:  Transfer control outward.
 880       // Doing it this early allows the exceptions to common up
 881       // even between adjacent method calls.
 882       throw_to_exit(ex_map);
 883     } else {
 884       // Have to look at the exception first.
 885       assert(stopped(), "catch_inline_exceptions trashes the map");
 886       catch_inline_exceptions(ex_map);
 887       stop_and_kill_map();      // we used up this exception state; kill it
 888     }
 889   }
 890 
 891   // We now return to our regularly scheduled program:
 892 }
 893 
 894 //---------------------------throw_to_exit-------------------------------------
 895 // Merge the given map into an exception exit from this method.
 896 // The exception exit will handle any unlocking of receiver.
 897 // The ex_oop must be saved within the ex_map, unlike merge_exception.
 898 void Parse::throw_to_exit(SafePointNode* ex_map) {
 899   // Pop the JVMS to (a copy of) the caller.
 900   GraphKit caller;
 901   caller.set_map_clone(_caller->map());
 902   caller.set_bci(_caller->bci());
 903   caller.set_sp(_caller->sp());
 904   // Copy out the standard machine state:
 905   for (uint i = 0; i < TypeFunc::Parms; i++) {
 906     caller.map()->set_req(i, ex_map->in(i));
 907   }
 908   if (ex_map->has_replaced_nodes()) {
 909     _replaced_nodes_for_exceptions = true;
 910   }
 911   caller.map()->transfer_replaced_nodes_from(ex_map, _new_idx);
 912   // ...and the exception:
 913   Node*          ex_oop        = saved_ex_oop(ex_map);
 914   SafePointNode* caller_ex_map = caller.make_exception_state(ex_oop);
 915   // Finally, collect the new exception state in my exits:
 916   _exits.add_exception_state(caller_ex_map);
 917 }
 918 
 919 //------------------------------do_exits---------------------------------------
 920 void Parse::do_exits() {
 921   set_parse_bci(InvocationEntryBci);
 922 
 923   // Now peephole on the return bits
 924   Node* region = _exits.control();
 925   _exits.set_control(gvn().transform(region));
 926 
 927   Node* iophi = _exits.i_o();
 928   _exits.set_i_o(gvn().transform(iophi));
 929 
 930   // Figure out if we need to emit the trailing barrier. The barrier is only
 931   // needed in the constructors, and only in three cases:
 932   //
 933   // 1. The constructor wrote a final. The effects of all initializations
 934   //    must be committed to memory before any code after the constructor
 935   //    publishes the reference to the newly constructed object. Rather
 936   //    than wait for the publication, we simply block the writes here.
 937   //    Rather than put a barrier on only those writes which are required
 938   //    to complete, we force all writes to complete.
 939   //
 940   // 2. On PPC64, also add MemBarRelease for constructors which write
 941   //    volatile fields. As support_IRIW_for_not_multiple_copy_atomic_cpu
 942   //    is set on PPC64, no sync instruction is issued after volatile
 943   //    stores. We want to guarantee the same behavior as on platforms
 944   //    with total store order, although this is not required by the Java
 945   //    memory model. So as with finals, we add a barrier here.
 946   //
 947   // 3. Experimental VM option is used to force the barrier if any field
 948   //    was written out in the constructor.
 949   //
 950   // "All bets are off" unless the first publication occurs after a
 951   // normal return from the constructor.  We do not attempt to detect
 952   // such unusual early publications.  But no barrier is needed on
 953   // exceptional returns, since they cannot publish normally.
 954   //
 955   if (method()->is_initializer() &&
 956         (wrote_final() ||
 957            PPC64_ONLY(wrote_volatile() ||)
 958            (AlwaysSafeConstructors && wrote_fields()))) {
 959     _exits.insert_mem_bar(Op_MemBarRelease, alloc_with_final());
 960 #ifndef PRODUCT
 961     if (PrintOpto && (Verbose || WizardMode)) {
 962       method()->print_name();
 963       tty->print_cr(" writes finals and needs a memory barrier");
 964     }
 965 #endif
 966   }
 967 
 968   // Any method can write a @Stable field; insert memory barriers after
 969   // those also. If there is a predecessor allocation node, bind the
 970   // barrier there.
 971   if (wrote_stable()) {
 972     _exits.insert_mem_bar(Op_MemBarRelease, alloc_with_final());
 973 #ifndef PRODUCT
 974     if (PrintOpto && (Verbose || WizardMode)) {
 975       method()->print_name();
 976       tty->print_cr(" writes @Stable and needs a memory barrier");
 977     }
 978 #endif
 979   }
 980 
 981   for (MergeMemStream mms(_exits.merged_memory()); mms.next_non_empty(); ) {
 982     // transform each slice of the original memphi:
 983     mms.set_memory(_gvn.transform(mms.memory()));
 984   }
 985 
 986   if (tf()->range()->cnt() > TypeFunc::Parms) {
 987     const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms);
 988     Node*       ret_phi  = _gvn.transform( _exits.argument(0) );
 989 #ifdef ASSERT 
 990     {
 991       // In case of concurrent class loading, the type we set for the
 992       // ret_phi in build_exits() may have been too optimistic and the
 993       // ret_phi may be top now.
 994       MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag);
 995       assert(_exits.control()->is_top() || !_gvn.type(ret_phi)->empty() ||
 996              (ret_type->isa_ptr() && C->env()->system_dictionary_modification_counter_changed()), "return value must be well defined");
 997     }
 998 #endif
 999     _exits.push_node(ret_type->basic_type(), ret_phi);
1000   }
1001 
1002   // Note:  Logic for creating and optimizing the ReturnNode is in Compile.
1003 
1004   // Unlock along the exceptional paths.
1005   // This is done late so that we can common up equivalent exceptions
1006   // (e.g., null checks) arising from multiple points within this method.
1007   // See GraphKit::add_exception_state, which performs the commoning.
1008   bool do_synch = method()->is_synchronized() && GenerateSynchronizationCode;
1009 
1010   // record exit from a method if compiled while Dtrace is turned on.
1011   if (do_synch || C->env()->dtrace_method_probes() || _replaced_nodes_for_exceptions) {
1012     // First move the exception list out of _exits:
1013     GraphKit kit(_exits.transfer_exceptions_into_jvms());
1014     SafePointNode* normal_map = kit.map();  // keep this guy safe
1015     // Now re-collect the exceptions into _exits:
1016     SafePointNode* ex_map;
1017     while ((ex_map = kit.pop_exception_state()) != NULL) {
1018       Node* ex_oop = kit.use_exception_state(ex_map);
1019       // Force the exiting JVM state to have this method at InvocationEntryBci.
1020       // The exiting JVM state is otherwise a copy of the calling JVMS.
1021       JVMState* caller = kit.jvms();
1022       JVMState* ex_jvms = caller->clone_shallow(C);
1023       ex_jvms->set_map(kit.clone_map());
1024       ex_jvms->map()->set_jvms(ex_jvms);
1025       ex_jvms->set_bci(   InvocationEntryBci);
1026       kit.set_jvms(ex_jvms);
1027       if (do_synch) {
1028         // Add on the synchronized-method box/object combo
1029         kit.map()->push_monitor(_synch_lock);
1030         // Unlock!
1031         kit.shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
1032       }
1033       if (C->env()->dtrace_method_probes()) {
1034         kit.make_dtrace_method_exit(method());
1035       }
1036       if (_replaced_nodes_for_exceptions) {
1037         kit.map()->apply_replaced_nodes();
1038       }
1039       // Done with exception-path processing.
1040       ex_map = kit.make_exception_state(ex_oop);
1041       assert(ex_jvms->same_calls_as(ex_map->jvms()), "sanity");
1042       // Pop the last vestige of this method:
1043       ex_map->set_jvms(caller->clone_shallow(C));
1044       ex_map->jvms()->set_map(ex_map);
1045       _exits.push_exception_state(ex_map);
1046     }
1047     assert(_exits.map() == normal_map, "keep the same return state");
1048   }
1049 
1050   {
1051     // Capture very early exceptions (receiver null checks) from caller JVMS
1052     GraphKit caller(_caller);
1053     SafePointNode* ex_map;
1054     while ((ex_map = caller.pop_exception_state()) != NULL) {
1055       _exits.add_exception_state(ex_map);
1056     }
1057   }
1058   _exits.map()->apply_replaced_nodes();
1059 }
1060 
1061 //-----------------------------create_entry_map-------------------------------
1062 // Initialize our parser map to contain the types at method entry.
1063 // For OSR, the map contains a single RawPtr parameter.
1064 // Initial monitor locking for sync. methods is performed by do_method_entry.
1065 SafePointNode* Parse::create_entry_map() {
1066   // Check for really stupid bail-out cases.
1067   uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack();
1068   if (len >= 32760) {
1069     C->record_method_not_compilable_all_tiers("too many local variables");
1070     return NULL;
1071   }
1072 
1073   // clear current replaced nodes that are of no use from here on (map was cloned in build_exits).
1074   _caller->map()->delete_replaced_nodes();
1075 
1076   // If this is an inlined method, we may have to do a receiver null check.
1077   if (_caller->has_method() && is_normal_parse() && !method()->is_static()) {
1078     GraphKit kit(_caller);
1079     kit.null_check_receiver_before_call(method());
1080     _caller = kit.transfer_exceptions_into_jvms();
1081     if (kit.stopped()) {
1082       _exits.add_exception_states_from(_caller);
1083       _exits.set_jvms(_caller);
1084       return NULL;
1085     }
1086   }
1087 
1088   assert(method() != NULL, "parser must have a method");
1089 
1090   // Create an initial safepoint to hold JVM state during parsing
1091   JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : NULL);
1092   set_map(new SafePointNode(len, jvms));
1093   jvms->set_map(map());
1094   record_for_igvn(map());
1095   assert(jvms->endoff() == len, "correct jvms sizing");
1096 
1097   SafePointNode* inmap = _caller->map();
1098   assert(inmap != NULL, "must have inmap");
1099   // In case of null check on receiver above
1100   map()->transfer_replaced_nodes_from(inmap, _new_idx);
1101 
1102   uint i;
1103 
1104   // Pass thru the predefined input parameters.
1105   for (i = 0; i < TypeFunc::Parms; i++) {
1106     map()->init_req(i, inmap->in(i));
1107   }
1108 
1109   if (depth() == 1) {
1110     assert(map()->memory()->Opcode() == Op_Parm, "");
1111     // Insert the memory aliasing node
1112     set_all_memory(reset_memory());
1113   }
1114   assert(merged_memory(), "");
1115 
1116   // Now add the locals which are initially bound to arguments:
1117   uint arg_size = tf()->domain()->cnt();
1118   ensure_stack(arg_size - TypeFunc::Parms);  // OSR methods have funny args
1119   for (i = TypeFunc::Parms; i < arg_size; i++) {
1120     map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms));
1121   }
1122 
1123   // Clear out the rest of the map (locals and stack)
1124   for (i = arg_size; i < len; i++) {
1125     map()->init_req(i, top());
1126   }
1127 
1128   SafePointNode* entry_map = stop();
1129   return entry_map;
1130 }
1131 
1132 //-----------------------------do_method_entry--------------------------------
1133 // Emit any code needed in the pseudo-block before BCI zero.
1134 // The main thing to do is lock the receiver of a synchronized method.
1135 void Parse::do_method_entry() {
1136   set_parse_bci(InvocationEntryBci); // Pseudo-BCP
1137   set_sp(0);                      // Java Stack Pointer
1138 
1139   NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); )
1140 
1141   if (C->env()->dtrace_method_probes()) {
1142     make_dtrace_method_entry(method());
1143   }
1144 
1145   // If the method is synchronized, we need to construct a lock node, attach
1146   // it to the Start node, and pin it there.
1147   if (method()->is_synchronized()) {
1148     // Insert a FastLockNode right after the Start which takes as arguments
1149     // the current thread pointer, the "this" pointer & the address of the
1150     // stack slot pair used for the lock.  The "this" pointer is a projection
1151     // off the start node, but the locking spot has to be constructed by
1152     // creating a ConLNode of 0, and boxing it with a BoxLockNode.  The BoxLockNode
1153     // becomes the second argument to the FastLockNode call.  The
1154     // FastLockNode becomes the new control parent to pin it to the start.
1155 
1156     // Setup Object Pointer
1157     Node *lock_obj = NULL;
1158     if(method()->is_static()) {
1159       ciInstance* mirror = _method->holder()->java_mirror();
1160       const TypeInstPtr *t_lock = TypeInstPtr::make(mirror);
1161       lock_obj = makecon(t_lock);
1162     } else {                  // Else pass the "this" pointer,
1163       lock_obj = local(0);    // which is Parm0 from StartNode
1164     }
1165     // Clear out dead values from the debug info.
1166     kill_dead_locals();
1167     // Build the FastLockNode
1168     _synch_lock = shared_lock(lock_obj);
1169   }
1170 
1171   // Feed profiling data for parameters to the type system so it can
1172   // propagate it as speculative types
1173   record_profiled_parameters_for_speculation();
1174 
1175   if (depth() == 1) {
1176     increment_and_test_invocation_counter(Tier2CompileThreshold);
1177   }
1178 }
1179 
1180 //------------------------------init_blocks------------------------------------
1181 // Initialize our parser map to contain the types/monitors at method entry.
1182 void Parse::init_blocks() {
1183   // Create the blocks.
1184   _block_count = flow()->block_count();
1185   _blocks = NEW_RESOURCE_ARRAY(Block, _block_count);
1186   Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count);
1187 
1188   int rpo;
1189 
1190   // Initialize the structs.
1191   for (rpo = 0; rpo < block_count(); rpo++) {
1192     Block* block = rpo_at(rpo);
1193     block->init_node(this, rpo);
1194   }
1195 
1196   // Collect predecessor and successor information.
1197   for (rpo = 0; rpo < block_count(); rpo++) {
1198     Block* block = rpo_at(rpo);
1199     block->init_graph(this);
1200   }
1201 }
1202 
1203 //-------------------------------init_node-------------------------------------
1204 void Parse::Block::init_node(Parse* outer, int rpo) {
1205   _flow = outer->flow()->rpo_at(rpo);
1206   _pred_count = 0;
1207   _preds_parsed = 0;
1208   _count = 0;
1209   assert(pred_count() == 0 && preds_parsed() == 0, "sanity");
1210   assert(!(is_merged() || is_parsed() || is_handler() || has_merged_backedge()), "sanity");
1211   assert(_live_locals.size() == 0, "sanity");
1212 
1213   // entry point has additional predecessor
1214   if (flow()->is_start())  _pred_count++;
1215   assert(flow()->is_start() == (this == outer->start_block()), "");
1216 }
1217 
1218 //-------------------------------init_graph------------------------------------
1219 void Parse::Block::init_graph(Parse* outer) {
1220   // Create the successor list for this parser block.
1221   GrowableArray<ciTypeFlow::Block*>* tfs = flow()->successors();
1222   GrowableArray<ciTypeFlow::Block*>* tfe = flow()->exceptions();
1223   int ns = tfs->length();
1224   int ne = tfe->length();
1225   _num_successors = ns;
1226   _all_successors = ns+ne;
1227   _successors = (ns+ne == 0) ? NULL : NEW_RESOURCE_ARRAY(Block*, ns+ne);
1228   int p = 0;
1229   for (int i = 0; i < ns+ne; i++) {
1230     ciTypeFlow::Block* tf2 = (i < ns) ? tfs->at(i) : tfe->at(i-ns);
1231     Block* block2 = outer->rpo_at(tf2->rpo());
1232     _successors[i] = block2;
1233 
1234     // Accumulate pred info for the other block, too.
1235     if (i < ns) {
1236       block2->_pred_count++;
1237     } else {
1238       block2->_is_handler = true;
1239     }
1240 
1241     #ifdef ASSERT
1242     // A block's successors must be distinguishable by BCI.
1243     // That is, no bytecode is allowed to branch to two different
1244     // clones of the same code location.
1245     for (int j = 0; j < i; j++) {
1246       Block* block1 = _successors[j];
1247       if (block1 == block2)  continue;  // duplicates are OK
1248       assert(block1->start() != block2->start(), "successors have unique bcis");
1249     }
1250     #endif
1251   }
1252 
1253   // Note: We never call next_path_num along exception paths, so they
1254   // never get processed as "ready".  Also, the input phis of exception
1255   // handlers get specially processed, so that
1256 }
1257 
1258 //---------------------------successor_for_bci---------------------------------
1259 Parse::Block* Parse::Block::successor_for_bci(int bci) {
1260   for (int i = 0; i < all_successors(); i++) {
1261     Block* block2 = successor_at(i);
1262     if (block2->start() == bci)  return block2;
1263   }
1264   // We can actually reach here if ciTypeFlow traps out a block
1265   // due to an unloaded class, and concurrently with compilation the
1266   // class is then loaded, so that a later phase of the parser is
1267   // able to see more of the bytecode CFG.  Or, the flow pass and
1268   // the parser can have a minor difference of opinion about executability
1269   // of bytecodes.  For example, "obj.field = null" is executable even
1270   // if the field's type is an unloaded class; the flow pass used to
1271   // make a trap for such code.
1272   return NULL;
1273 }
1274 
1275 
1276 //-----------------------------stack_type_at-----------------------------------
1277 const Type* Parse::Block::stack_type_at(int i) const {
1278   return get_type(flow()->stack_type_at(i));
1279 }
1280 
1281 
1282 //-----------------------------local_type_at-----------------------------------
1283 const Type* Parse::Block::local_type_at(int i) const {
1284   // Make dead locals fall to bottom.
1285   if (_live_locals.size() == 0) {
1286     MethodLivenessResult live_locals = flow()->outer()->method()->liveness_at_bci(start());
1287     // This bitmap can be zero length if we saw a breakpoint.
1288     // In such cases, pretend they are all live.
1289     ((Block*)this)->_live_locals = live_locals;
1290   }
1291   if (_live_locals.size() > 0 && !_live_locals.at(i))
1292     return Type::BOTTOM;
1293 
1294   return get_type(flow()->local_type_at(i));
1295 }
1296 
1297 
1298 #ifndef PRODUCT
1299 
1300 //----------------------------name_for_bc--------------------------------------
1301 // helper method for BytecodeParseHistogram
1302 static const char* name_for_bc(int i) {
1303   return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx";
1304 }
1305 
1306 //----------------------------BytecodeParseHistogram------------------------------------
1307 Parse::BytecodeParseHistogram::BytecodeParseHistogram(Parse *p, Compile *c) {
1308   _parser   = p;
1309   _compiler = c;
1310   if( ! _initialized ) { _initialized = true; reset(); }
1311 }
1312 
1313 //----------------------------current_count------------------------------------
1314 int Parse::BytecodeParseHistogram::current_count(BPHType bph_type) {
1315   switch( bph_type ) {
1316   case BPH_transforms: { return _parser->gvn().made_progress(); }
1317   case BPH_values:     { return _parser->gvn().made_new_values(); }
1318   default: { ShouldNotReachHere(); return 0; }
1319   }
1320 }
1321 
1322 //----------------------------initialized--------------------------------------
1323 bool Parse::BytecodeParseHistogram::initialized() { return _initialized; }
1324 
1325 //----------------------------reset--------------------------------------------
1326 void Parse::BytecodeParseHistogram::reset() {
1327   int i = Bytecodes::number_of_codes;
1328   while (i-- > 0) { _bytecodes_parsed[i] = 0; _nodes_constructed[i] = 0; _nodes_transformed[i] = 0; _new_values[i] = 0; }
1329 }
1330 
1331 //----------------------------set_initial_state--------------------------------
1332 // Record info when starting to parse one bytecode
1333 void Parse::BytecodeParseHistogram::set_initial_state( Bytecodes::Code bc ) {
1334   if( PrintParseStatistics && !_parser->is_osr_parse() ) {
1335     _initial_bytecode    = bc;
1336     _initial_node_count  = _compiler->unique();
1337     _initial_transforms  = current_count(BPH_transforms);
1338     _initial_values      = current_count(BPH_values);
1339   }
1340 }
1341 
1342 //----------------------------record_change--------------------------------
1343 // Record results of parsing one bytecode
1344 void Parse::BytecodeParseHistogram::record_change() {
1345   if( PrintParseStatistics && !_parser->is_osr_parse() ) {
1346     ++_bytecodes_parsed[_initial_bytecode];
1347     _nodes_constructed [_initial_bytecode] += (_compiler->unique() - _initial_node_count);
1348     _nodes_transformed [_initial_bytecode] += (current_count(BPH_transforms) - _initial_transforms);
1349     _new_values        [_initial_bytecode] += (current_count(BPH_values)     - _initial_values);
1350   }
1351 }
1352 
1353 
1354 //----------------------------print--------------------------------------------
1355 void Parse::BytecodeParseHistogram::print(float cutoff) {
1356   ResourceMark rm;
1357   // print profile
1358   int total  = 0;
1359   int i      = 0;
1360   for( i = 0; i < Bytecodes::number_of_codes; ++i ) { total += _bytecodes_parsed[i]; }
1361   int abs_sum = 0;
1362   tty->cr();   //0123456789012345678901234567890123456789012345678901234567890123456789
1363   tty->print_cr("Histogram of %d parsed bytecodes:", total);
1364   if( total == 0 ) { return; }
1365   tty->cr();
1366   tty->print_cr("absolute:  count of compiled bytecodes of this type");
1367   tty->print_cr("relative:  percentage contribution to compiled nodes");
1368   tty->print_cr("nodes   :  Average number of nodes constructed per bytecode");
1369   tty->print_cr("rnodes  :  Significance towards total nodes constructed, (nodes*relative)");
1370   tty->print_cr("transforms: Average amount of tranform progress per bytecode compiled");
1371   tty->print_cr("values  :  Average number of node values improved per bytecode");
1372   tty->print_cr("name    :  Bytecode name");
1373   tty->cr();
1374   tty->print_cr("  absolute  relative   nodes  rnodes  transforms  values   name");
1375   tty->print_cr("----------------------------------------------------------------------");
1376   while (--i > 0) {
1377     int       abs = _bytecodes_parsed[i];
1378     float     rel = abs * 100.0F / total;
1379     float   nodes = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_constructed[i])/_bytecodes_parsed[i];
1380     float  rnodes = _bytecodes_parsed[i] == 0 ? 0 :  rel * nodes;
1381     float  xforms = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_transformed[i])/_bytecodes_parsed[i];
1382     float  values = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _new_values       [i])/_bytecodes_parsed[i];
1383     if (cutoff <= rel) {
1384       tty->print_cr("%10d  %7.2f%%  %6.1f  %6.2f   %6.1f   %6.1f     %s", abs, rel, nodes, rnodes, xforms, values, name_for_bc(i));
1385       abs_sum += abs;
1386     }
1387   }
1388   tty->print_cr("----------------------------------------------------------------------");
1389   float rel_sum = abs_sum * 100.0F / total;
1390   tty->print_cr("%10d  %7.2f%%    (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff);
1391   tty->print_cr("----------------------------------------------------------------------");
1392   tty->cr();
1393 }
1394 #endif
1395 
1396 //----------------------------load_state_from----------------------------------
1397 // Load block/map/sp.  But not do not touch iter/bci.
1398 void Parse::load_state_from(Block* block) {
1399   set_block(block);
1400   // load the block's JVM state:
1401   set_map(block->start_map());
1402   set_sp( block->start_sp());
1403 }
1404 
1405 
1406 //-----------------------------record_state------------------------------------
1407 void Parse::Block::record_state(Parse* p) {
1408   assert(!is_merged(), "can only record state once, on 1st inflow");
1409   assert(start_sp() == p->sp(), "stack pointer must agree with ciTypeFlow");
1410   set_start_map(p->stop());
1411 }
1412 
1413 
1414 //------------------------------do_one_block-----------------------------------
1415 void Parse::do_one_block() {
1416   if (TraceOptoParse) {
1417     Block *b = block();
1418     int ns = b->num_successors();
1419     int nt = b->all_successors();
1420 
1421     tty->print("Parsing block #%d at bci [%d,%d), successors: ",
1422                   block()->rpo(), block()->start(), block()->limit());
1423     for (int i = 0; i < nt; i++) {
1424       tty->print((( i < ns) ? " %d" : " %d(e)"), b->successor_at(i)->rpo());
1425     }
1426     if (b->is_loop_head()) tty->print("  lphd");
1427     tty->cr();
1428   }
1429 
1430   assert(block()->is_merged(), "must be merged before being parsed");
1431   block()->mark_parsed();
1432   ++_blocks_parsed;
1433 
1434   // Set iterator to start of block.
1435   iter().reset_to_bci(block()->start());
1436 
1437   CompileLog* log = C->log();
1438 
1439   // Parse bytecodes
1440   while (!stopped() && !failing()) {
1441     iter().next();
1442 
1443     // Learn the current bci from the iterator:
1444     set_parse_bci(iter().cur_bci());
1445 
1446     if (bci() == block()->limit()) {
1447       // Do not walk into the next block until directed by do_all_blocks.
1448       merge(bci());
1449       break;
1450     }
1451     assert(bci() < block()->limit(), "bci still in block");
1452 
1453     if (log != NULL) {
1454       // Output an optional context marker, to help place actions
1455       // that occur during parsing of this BC.  If there is no log
1456       // output until the next context string, this context string
1457       // will be silently ignored.
1458       log->set_context("bc code='%d' bci='%d'", (int)bc(), bci());
1459     }
1460 
1461     if (block()->has_trap_at(bci())) {
1462       // We must respect the flow pass's traps, because it will refuse
1463       // to produce successors for trapping blocks.
1464       int trap_index = block()->flow()->trap_index();
1465       assert(trap_index != 0, "trap index must be valid");
1466       uncommon_trap(trap_index);
1467       break;
1468     }
1469 
1470     NOT_PRODUCT( parse_histogram()->set_initial_state(bc()); );
1471 
1472 #ifdef ASSERT
1473     int pre_bc_sp = sp();
1474     int inputs, depth;
1475     bool have_se = !stopped() && compute_stack_effects(inputs, depth);
1476     assert(!have_se || pre_bc_sp >= inputs, err_msg_res("have enough stack to execute this BC: pre_bc_sp=%d, inputs=%d", pre_bc_sp, inputs));
1477 #endif //ASSERT
1478 
1479     do_one_bytecode();
1480 
1481     assert(!have_se || stopped() || failing() || (sp() - pre_bc_sp) == depth,
1482            err_msg_res("incorrect depth prediction: sp=%d, pre_bc_sp=%d, depth=%d", sp(), pre_bc_sp, depth));
1483 
1484     do_exceptions();
1485 
1486     NOT_PRODUCT( parse_histogram()->record_change(); );
1487 
1488     if (log != NULL)
1489       log->clear_context();  // skip marker if nothing was printed
1490 
1491     // Fall into next bytecode.  Each bytecode normally has 1 sequential
1492     // successor which is typically made ready by visiting this bytecode.
1493     // If the successor has several predecessors, then it is a merge
1494     // point, starts a new basic block, and is handled like other basic blocks.
1495   }
1496 }
1497 
1498 
1499 //------------------------------merge------------------------------------------
1500 void Parse::set_parse_bci(int bci) {
1501   set_bci(bci);
1502   Node_Notes* nn = C->default_node_notes();
1503   if (nn == NULL)  return;
1504 
1505   // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls.
1506   if (!DebugInlinedCalls && depth() > 1) {
1507     return;
1508   }
1509 
1510   // Update the JVMS annotation, if present.
1511   JVMState* jvms = nn->jvms();
1512   if (jvms != NULL && jvms->bci() != bci) {
1513     // Update the JVMS.
1514     jvms = jvms->clone_shallow(C);
1515     jvms->set_bci(bci);
1516     nn->set_jvms(jvms);
1517   }
1518 }
1519 
1520 //------------------------------merge------------------------------------------
1521 // Merge the current mapping into the basic block starting at bci
1522 void Parse::merge(int target_bci) {
1523   Block* target = successor_for_bci(target_bci);
1524   if (target == NULL) { handle_missing_successor(target_bci); return; }
1525   assert(!target->is_ready(), "our arrival must be expected");
1526   int pnum = target->next_path_num();
1527   merge_common(target, pnum);
1528 }
1529 
1530 //-------------------------merge_new_path--------------------------------------
1531 // Merge the current mapping into the basic block, using a new path
1532 void Parse::merge_new_path(int target_bci) {
1533   Block* target = successor_for_bci(target_bci);
1534   if (target == NULL) { handle_missing_successor(target_bci); return; }
1535   assert(!target->is_ready(), "new path into frozen graph");
1536   int pnum = target->add_new_path();
1537   merge_common(target, pnum);
1538 }
1539 
1540 //-------------------------merge_exception-------------------------------------
1541 // Merge the current mapping into the basic block starting at bci
1542 // The ex_oop must be pushed on the stack, unlike throw_to_exit.
1543 void Parse::merge_exception(int target_bci) {
1544   assert(sp() == 1, "must have only the throw exception on the stack");
1545   Block* target = successor_for_bci(target_bci);
1546   if (target == NULL) { handle_missing_successor(target_bci); return; }
1547   assert(target->is_handler(), "exceptions are handled by special blocks");
1548   int pnum = target->add_new_path();
1549   merge_common(target, pnum);
1550 }
1551 
1552 //--------------------handle_missing_successor---------------------------------
1553 void Parse::handle_missing_successor(int target_bci) {
1554 #ifndef PRODUCT
1555   Block* b = block();
1556   int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1557   tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1558 #endif
1559   ShouldNotReachHere();
1560 }
1561 
1562 //--------------------------merge_common---------------------------------------
1563 void Parse::merge_common(Parse::Block* target, int pnum) {
1564   if (TraceOptoParse) {
1565     tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1566   }
1567 
1568   // Zap extra stack slots to top
1569   assert(sp() == target->start_sp(), "");
1570   clean_stack(sp());
1571 
1572   if (!target->is_merged()) {   // No prior mapping at this bci
1573     if (TraceOptoParse) { tty->print(" with empty state");  }
1574 
1575     // If this path is dead, do not bother capturing it as a merge.
1576     // It is "as if" we had 1 fewer predecessors from the beginning.
1577     if (stopped()) {
1578       if (TraceOptoParse)  tty->print_cr(", but path is dead and doesn't count");
1579       return;
1580     }
1581 
1582     // Record that a new block has been merged.
1583     ++_blocks_merged;
1584 
1585     // Make a region if we know there are multiple or unpredictable inputs.
1586     // (Also, if this is a plain fall-through, we might see another region,
1587     // which must not be allowed into this block's map.)
1588     if (pnum > PhiNode::Input         // Known multiple inputs.
1589         || target->is_handler()       // These have unpredictable inputs.
1590         || target->is_loop_head()     // Known multiple inputs
1591         || control()->is_Region()) {  // We must hide this guy.
1592 
1593       int current_bci = bci();
1594       set_parse_bci(target->start()); // Set target bci
1595       if (target->is_SEL_head()) {
1596         DEBUG_ONLY( target->mark_merged_backedge(block()); )
1597         if (target->start() == 0) {
1598           // Add loop predicate for the special case when
1599           // there are backbranches to the method entry.
1600           add_predicate();
1601         }
1602       }
1603       // Add a Region to start the new basic block.  Phis will be added
1604       // later lazily.
1605       int edges = target->pred_count();
1606       if (edges < pnum)  edges = pnum;  // might be a new path!
1607       RegionNode *r = new RegionNode(edges+1);
1608       gvn().set_type(r, Type::CONTROL);
1609       record_for_igvn(r);
1610       // zap all inputs to NULL for debugging (done in Node(uint) constructor)
1611       // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); }
1612       r->init_req(pnum, control());
1613       set_control(r);
1614       set_parse_bci(current_bci); // Restore bci
1615     }
1616 
1617     // Convert the existing Parser mapping into a mapping at this bci.
1618     store_state_to(target);
1619     assert(target->is_merged(), "do not come here twice");
1620 
1621   } else {                      // Prior mapping at this bci
1622     if (TraceOptoParse) {  tty->print(" with previous state"); }
1623 #ifdef ASSERT
1624     if (target->is_SEL_head()) {
1625       target->mark_merged_backedge(block());
1626     }
1627 #endif
1628     // We must not manufacture more phis if the target is already parsed.
1629     bool nophi = target->is_parsed();
1630 
1631     SafePointNode* newin = map();// Hang on to incoming mapping
1632     Block* save_block = block(); // Hang on to incoming block;
1633     load_state_from(target);    // Get prior mapping
1634 
1635     assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree");
1636     assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree");
1637     assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree");
1638     assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree");
1639 
1640     // Iterate over my current mapping and the old mapping.
1641     // Where different, insert Phi functions.
1642     // Use any existing Phi functions.
1643     assert(control()->is_Region(), "must be merging to a region");
1644     RegionNode* r = control()->as_Region();
1645 
1646     // Compute where to merge into
1647     // Merge incoming control path
1648     r->init_req(pnum, newin->control());
1649 
1650     if (pnum == 1) {            // Last merge for this Region?
1651       if (!block()->flow()->is_irreducible_entry()) {
1652         Node* result = _gvn.transform_no_reclaim(r);
1653         if (r != result && TraceOptoParse) {
1654           tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1655         }
1656       }
1657       record_for_igvn(r);
1658     }
1659 
1660     // Update all the non-control inputs to map:
1661     assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1662     bool check_elide_phi = target->is_SEL_backedge(save_block);
1663     for (uint j = 1; j < newin->req(); j++) {
1664       Node* m = map()->in(j);   // Current state of target.
1665       Node* n = newin->in(j);   // Incoming change to target state.
1666       PhiNode* phi;
1667       if (m->is_Phi() && m->as_Phi()->region() == r)
1668         phi = m->as_Phi();
1669       else
1670         phi = NULL;
1671       if (m != n) {             // Different; must merge
1672         switch (j) {
1673         // Frame pointer and Return Address never changes
1674         case TypeFunc::FramePtr:// Drop m, use the original value
1675         case TypeFunc::ReturnAdr:
1676           break;
1677         case TypeFunc::Memory:  // Merge inputs to the MergeMem node
1678           assert(phi == NULL, "the merge contains phis, not vice versa");
1679           merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1680           continue;
1681         default:                // All normal stuff
1682           if (phi == NULL) {
1683             const JVMState* jvms = map()->jvms();
1684             if (EliminateNestedLocks &&
1685                 jvms->is_mon(j) && jvms->is_monitor_box(j)) {
1686               // BoxLock nodes are not commoning.
1687               // Use old BoxLock node as merged box.
1688               assert(newin->jvms()->is_monitor_box(j), "sanity");
1689               // This assert also tests that nodes are BoxLock.
1690               assert(BoxLockNode::same_slot(n, m), "sanity");
1691               C->gvn_replace_by(n, m);
1692             } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1693               phi = ensure_phi(j, nophi);
1694             }
1695           }
1696           break;
1697         }
1698       }
1699       // At this point, n might be top if:
1700       //  - there is no phi (because TypeFlow detected a conflict), or
1701       //  - the corresponding control edges is top (a dead incoming path)
1702       // It is a bug if we create a phi which sees a garbage value on a live path.
1703 
1704       if (phi != NULL) {
1705         assert(n != top() || r->in(pnum) == top(), "live value must not be garbage");
1706         assert(phi->region() == r, "");
1707         phi->set_req(pnum, n);  // Then add 'n' to the merge
1708         if (pnum == PhiNode::Input) {
1709           // Last merge for this Phi.
1710           // So far, Phis have had a reasonable type from ciTypeFlow.
1711           // Now _gvn will join that with the meet of current inputs.
1712           // BOTTOM is never permissible here, 'cause pessimistically
1713           // Phis of pointers cannot lose the basic pointer type.
1714           debug_only(const Type* bt1 = phi->bottom_type());
1715           assert(bt1 != Type::BOTTOM, "should not be building conflict phis");
1716           map()->set_req(j, _gvn.transform_no_reclaim(phi));
1717           debug_only(const Type* bt2 = phi->bottom_type());
1718           assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow");
1719           record_for_igvn(phi);
1720         }
1721       }
1722     } // End of for all values to be merged
1723 
1724     if (pnum == PhiNode::Input &&
1725         !r->in(0)) {         // The occasional useless Region
1726       assert(control() == r, "");
1727       set_control(r->nonnull_req());
1728     }
1729 
1730     map()->merge_replaced_nodes_with(newin);
1731 
1732     // newin has been subsumed into the lazy merge, and is now dead.
1733     set_block(save_block);
1734 
1735     stop();                     // done with this guy, for now
1736   }
1737 
1738   if (TraceOptoParse) {
1739     tty->print_cr(" on path %d", pnum);
1740   }
1741 
1742   // Done with this parser state.
1743   assert(stopped(), "");
1744 }
1745 
1746 
1747 //--------------------------merge_memory_edges---------------------------------
1748 void Parse::merge_memory_edges(MergeMemNode* n, int pnum, bool nophi) {
1749   // (nophi means we must not create phis, because we already parsed here)
1750   assert(n != NULL, "");
1751   // Merge the inputs to the MergeMems
1752   MergeMemNode* m = merged_memory();
1753 
1754   assert(control()->is_Region(), "must be merging to a region");
1755   RegionNode* r = control()->as_Region();
1756 
1757   PhiNode* base = NULL;
1758   MergeMemNode* remerge = NULL;
1759   for (MergeMemStream mms(m, n); mms.next_non_empty2(); ) {
1760     Node *p = mms.force_memory();
1761     Node *q = mms.memory2();
1762     if (mms.is_empty() && nophi) {
1763       // Trouble:  No new splits allowed after a loop body is parsed.
1764       // Instead, wire the new split into a MergeMem on the backedge.
1765       // The optimizer will sort it out, slicing the phi.
1766       if (remerge == NULL) {
1767         assert(base != NULL, "");
1768         assert(base->in(0) != NULL, "should not be xformed away");
1769         remerge = MergeMemNode::make(base->in(pnum));
1770         gvn().set_type(remerge, Type::MEMORY);
1771         base->set_req(pnum, remerge);
1772       }
1773       remerge->set_memory_at(mms.alias_idx(), q);
1774       continue;
1775     }
1776     assert(!q->is_MergeMem(), "");
1777     PhiNode* phi;
1778     if (p != q) {
1779       phi = ensure_memory_phi(mms.alias_idx(), nophi);
1780     } else {
1781       if (p->is_Phi() && p->as_Phi()->region() == r)
1782         phi = p->as_Phi();
1783       else
1784         phi = NULL;
1785     }
1786     // Insert q into local phi
1787     if (phi != NULL) {
1788       assert(phi->region() == r, "");
1789       p = phi;
1790       phi->set_req(pnum, q);
1791       if (mms.at_base_memory()) {
1792         base = phi;  // delay transforming it
1793       } else if (pnum == 1) {
1794         record_for_igvn(phi);
1795         p = _gvn.transform_no_reclaim(phi);
1796       }
1797       mms.set_memory(p);// store back through the iterator
1798     }
1799   }
1800   // Transform base last, in case we must fiddle with remerging.
1801   if (base != NULL && pnum == 1) {
1802     record_for_igvn(base);
1803     m->set_base_memory( _gvn.transform_no_reclaim(base) );
1804   }
1805 }
1806 
1807 
1808 //------------------------ensure_phis_everywhere-------------------------------
1809 void Parse::ensure_phis_everywhere() {
1810   ensure_phi(TypeFunc::I_O);
1811 
1812   // Ensure a phi on all currently known memories.
1813   for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) {
1814     ensure_memory_phi(mms.alias_idx());
1815     debug_only(mms.set_memory());  // keep the iterator happy
1816   }
1817 
1818   // Note:  This is our only chance to create phis for memory slices.
1819   // If we miss a slice that crops up later, it will have to be
1820   // merged into the base-memory phi that we are building here.
1821   // Later, the optimizer will comb out the knot, and build separate
1822   // phi-loops for each memory slice that matters.
1823 
1824   // Monitors must nest nicely and not get confused amongst themselves.
1825   // Phi-ify everything up to the monitors, though.
1826   uint monoff = map()->jvms()->monoff();
1827   uint nof_monitors = map()->jvms()->nof_monitors();
1828 
1829   assert(TypeFunc::Parms == map()->jvms()->locoff(), "parser map should contain only youngest jvms");
1830   bool check_elide_phi = block()->is_SEL_head();
1831   for (uint i = TypeFunc::Parms; i < monoff; i++) {
1832     if (!check_elide_phi || !block()->can_elide_SEL_phi(i)) {
1833       ensure_phi(i);
1834     }
1835   }
1836 
1837   // Even monitors need Phis, though they are well-structured.
1838   // This is true for OSR methods, and also for the rare cases where
1839   // a monitor object is the subject of a replace_in_map operation.
1840   // See bugs 4426707 and 5043395.
1841   for (uint m = 0; m < nof_monitors; m++) {
1842     ensure_phi(map()->jvms()->monitor_obj_offset(m));
1843   }
1844 }
1845 
1846 
1847 //-----------------------------add_new_path------------------------------------
1848 // Add a previously unaccounted predecessor to this block.
1849 int Parse::Block::add_new_path() {
1850   // If there is no map, return the lowest unused path number.
1851   if (!is_merged())  return pred_count()+1;  // there will be a map shortly
1852 
1853   SafePointNode* map = start_map();
1854   if (!map->control()->is_Region())
1855     return pred_count()+1;  // there may be a region some day
1856   RegionNode* r = map->control()->as_Region();
1857 
1858   // Add new path to the region.
1859   uint pnum = r->req();
1860   r->add_req(NULL);
1861 
1862   for (uint i = 1; i < map->req(); i++) {
1863     Node* n = map->in(i);
1864     if (i == TypeFunc::Memory) {
1865       // Ensure a phi on all currently known memories.
1866       for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) {
1867         Node* phi = mms.memory();
1868         if (phi->is_Phi() && phi->as_Phi()->region() == r) {
1869           assert(phi->req() == pnum, "must be same size as region");
1870           phi->add_req(NULL);
1871         }
1872       }
1873     } else {
1874       if (n->is_Phi() && n->as_Phi()->region() == r) {
1875         assert(n->req() == pnum, "must be same size as region");
1876         n->add_req(NULL);
1877       }
1878     }
1879   }
1880 
1881   return pnum;
1882 }
1883 
1884 //------------------------------ensure_phi-------------------------------------
1885 // Turn the idx'th entry of the current map into a Phi
1886 PhiNode *Parse::ensure_phi(int idx, bool nocreate) {
1887   SafePointNode* map = this->map();
1888   Node* region = map->control();
1889   assert(region->is_Region(), "");
1890 
1891   Node* o = map->in(idx);
1892   assert(o != NULL, "");
1893 
1894   if (o == top())  return NULL; // TOP always merges into TOP
1895 
1896   if (o->is_Phi() && o->as_Phi()->region() == region) {
1897     return o->as_Phi();
1898   }
1899 
1900   // Now use a Phi here for merging
1901   assert(!nocreate, "Cannot build a phi for a block already parsed.");
1902   const JVMState* jvms = map->jvms();
1903   const Type* t;
1904   if (jvms->is_loc(idx)) {
1905     t = block()->local_type_at(idx - jvms->locoff());
1906   } else if (jvms->is_stk(idx)) {
1907     t = block()->stack_type_at(idx - jvms->stkoff());
1908   } else if (jvms->is_mon(idx)) {
1909     assert(!jvms->is_monitor_box(idx), "no phis for boxes");
1910     t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object
1911   } else if ((uint)idx < TypeFunc::Parms) {
1912     t = o->bottom_type();  // Type::RETURN_ADDRESS or such-like.
1913   } else {
1914     assert(false, "no type information for this phi");
1915   }
1916 
1917   // If the type falls to bottom, then this must be a local that
1918   // is mixing ints and oops or some such.  Forcing it to top
1919   // makes it go dead.
1920   if (t == Type::BOTTOM) {
1921     map->set_req(idx, top());
1922     return NULL;
1923   }
1924 
1925   // Do not create phis for top either.
1926   // A top on a non-null control flow must be an unused even after the.phi.
1927   if (t == Type::TOP || t == Type::HALF) {
1928     map->set_req(idx, top());
1929     return NULL;
1930   }
1931 
1932   PhiNode* phi = PhiNode::make(region, o, t);
1933   gvn().set_type(phi, t);
1934   if (C->do_escape_analysis()) record_for_igvn(phi);
1935   map->set_req(idx, phi);
1936   return phi;
1937 }
1938 
1939 //--------------------------ensure_memory_phi----------------------------------
1940 // Turn the idx'th slice of the current memory into a Phi
1941 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) {
1942   MergeMemNode* mem = merged_memory();
1943   Node* region = control();
1944   assert(region->is_Region(), "");
1945 
1946   Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx);
1947   assert(o != NULL && o != top(), "");
1948 
1949   PhiNode* phi;
1950   if (o->is_Phi() && o->as_Phi()->region() == region) {
1951     phi = o->as_Phi();
1952     if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) {
1953       // clone the shared base memory phi to make a new memory split
1954       assert(!nocreate, "Cannot build a phi for a block already parsed.");
1955       const Type* t = phi->bottom_type();
1956       const TypePtr* adr_type = C->get_adr_type(idx);
1957       phi = phi->slice_memory(adr_type);
1958       gvn().set_type(phi, t);
1959     }
1960     return phi;
1961   }
1962 
1963   // Now use a Phi here for merging
1964   assert(!nocreate, "Cannot build a phi for a block already parsed.");
1965   const Type* t = o->bottom_type();
1966   const TypePtr* adr_type = C->get_adr_type(idx);
1967   phi = PhiNode::make(region, o, t, adr_type);
1968   gvn().set_type(phi, t);
1969   if (idx == Compile::AliasIdxBot)
1970     mem->set_base_memory(phi);
1971   else
1972     mem->set_memory_at(idx, phi);
1973   return phi;
1974 }
1975 
1976 //------------------------------call_register_finalizer-----------------------
1977 // Check the klass of the receiver and call register_finalizer if the
1978 // class need finalization.
1979 void Parse::call_register_finalizer() {
1980   Node* receiver = local(0);
1981   assert(receiver != NULL && receiver->bottom_type()->isa_instptr() != NULL,
1982          "must have non-null instance type");
1983 
1984   const TypeInstPtr *tinst = receiver->bottom_type()->isa_instptr();
1985   if (tinst != NULL && tinst->klass()->is_loaded() && !tinst->klass_is_exact()) {
1986     // The type isn't known exactly so see if CHA tells us anything.
1987     ciInstanceKlass* ik = tinst->klass()->as_instance_klass();
1988     if (!Dependencies::has_finalizable_subclass(ik)) {
1989       // No finalizable subclasses so skip the dynamic check.
1990       C->dependencies()->assert_has_no_finalizable_subclasses(ik);
1991       return;
1992     }
1993   }
1994 
1995   // Insert a dynamic test for whether the instance needs
1996   // finalization.  In general this will fold up since the concrete
1997   // class is often visible so the access flags are constant.
1998   Node* klass_addr = basic_plus_adr( receiver, receiver, oopDesc::klass_offset_in_bytes() );
1999   Node* klass = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), klass_addr, TypeInstPtr::KLASS));
2000 
2001   Node* access_flags_addr = basic_plus_adr(klass, klass, in_bytes(Klass::access_flags_offset()));
2002   Node* access_flags = make_load(NULL, access_flags_addr, TypeInt::INT, T_INT, MemNode::unordered);
2003 
2004   Node* mask  = _gvn.transform(new AndINode(access_flags, intcon(JVM_ACC_HAS_FINALIZER)));
2005   Node* check = _gvn.transform(new CmpINode(mask, intcon(0)));
2006   Node* test  = _gvn.transform(new BoolNode(check, BoolTest::ne));
2007 
2008   IfNode* iff = create_and_map_if(control(), test, PROB_MAX, COUNT_UNKNOWN);
2009 
2010   RegionNode* result_rgn = new RegionNode(3);
2011   record_for_igvn(result_rgn);
2012 
2013   Node *skip_register = _gvn.transform(new IfFalseNode(iff));
2014   result_rgn->init_req(1, skip_register);
2015 
2016   Node *needs_register = _gvn.transform(new IfTrueNode(iff));
2017   set_control(needs_register);
2018   if (stopped()) {
2019     // There is no slow path.
2020     result_rgn->init_req(2, top());
2021   } else {
2022     Node *call = make_runtime_call(RC_NO_LEAF,
2023                                    OptoRuntime::register_finalizer_Type(),
2024                                    OptoRuntime::register_finalizer_Java(),
2025                                    NULL, TypePtr::BOTTOM,
2026                                    receiver);
2027     make_slow_call_ex(call, env()->Throwable_klass(), true);
2028 
2029     Node* fast_io  = call->in(TypeFunc::I_O);
2030     Node* fast_mem = call->in(TypeFunc::Memory);
2031     // These two phis are pre-filled with copies of of the fast IO and Memory
2032     Node* io_phi   = PhiNode::make(result_rgn, fast_io,  Type::ABIO);
2033     Node* mem_phi  = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
2034 
2035     result_rgn->init_req(2, control());
2036     io_phi    ->init_req(2, i_o());
2037     mem_phi   ->init_req(2, reset_memory());
2038 
2039     set_all_memory( _gvn.transform(mem_phi) );
2040     set_i_o(        _gvn.transform(io_phi) );
2041   }
2042 
2043   set_control( _gvn.transform(result_rgn) );
2044 }
2045 
2046 // Add check to deoptimize if RTM state is not ProfileRTM
2047 void Parse::rtm_deopt() {
2048 #if INCLUDE_RTM_OPT
2049   if (C->profile_rtm()) {
2050     assert(C->method() != NULL, "only for normal compilations");
2051     assert(!C->method()->method_data()->is_empty(), "MDO is needed to record RTM state");
2052     assert(depth() == 1, "generate check only for main compiled method");
2053 
2054     // Set starting bci for uncommon trap.
2055     set_parse_bci(is_osr_parse() ? osr_bci() : 0);
2056 
2057     // Load the rtm_state from the MethodData.
2058     const TypePtr* adr_type = TypeMetadataPtr::make(C->method()->method_data());
2059     Node* mdo = makecon(adr_type);
2060     int offset = MethodData::rtm_state_offset_in_bytes();
2061     Node* adr_node = basic_plus_adr(mdo, mdo, offset);
2062     Node* rtm_state = make_load(control(), adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
2063 
2064     // Separate Load from Cmp by Opaque.
2065     // In expand_macro_nodes() it will be replaced either
2066     // with this load when there are locks in the code
2067     // or with ProfileRTM (cmp->in(2)) otherwise so that
2068     // the check will fold.
2069     Node* profile_state = makecon(TypeInt::make(ProfileRTM));
2070     Node* opq   = _gvn.transform( new Opaque3Node(C, rtm_state, Opaque3Node::RTM_OPT) );
2071     Node* chk   = _gvn.transform( new CmpINode(opq, profile_state) );
2072     Node* tst   = _gvn.transform( new BoolNode(chk, BoolTest::eq) );
2073     // Branch to failure if state was changed
2074     { BuildCutout unless(this, tst, PROB_ALWAYS);
2075       uncommon_trap(Deoptimization::Reason_rtm_state_change,
2076                     Deoptimization::Action_make_not_entrant);
2077     }
2078   }
2079 #endif
2080 }
2081 
2082 void Parse::decrement_age() {
2083   MethodCounters* mc = method()->ensure_method_counters();
2084   if (mc == NULL) {
2085     C->record_failure("Must have MCs");
2086     return;
2087   }
2088   assert(!is_osr_parse(), "Not doing this for OSRs");
2089 
2090   // Set starting bci for uncommon trap.
2091   set_parse_bci(0);
2092 
2093   const TypePtr* adr_type = TypeRawPtr::make((address)mc);
2094   Node* mc_adr = makecon(adr_type);
2095   Node* cnt_adr = basic_plus_adr(mc_adr, mc_adr, in_bytes(MethodCounters::nmethod_age_offset()));
2096   Node* cnt = make_load(control(), cnt_adr, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
2097   Node* decr = _gvn.transform(new SubINode(cnt, makecon(TypeInt::ONE)));
2098   store_to_memory(control(), cnt_adr, decr, T_INT, adr_type, MemNode::unordered);
2099   Node *chk   = _gvn.transform(new CmpINode(decr, makecon(TypeInt::ZERO)));
2100   Node* tst   = _gvn.transform(new BoolNode(chk, BoolTest::gt));
2101   { BuildCutout unless(this, tst, PROB_ALWAYS);
2102     uncommon_trap(Deoptimization::Reason_tenured,
2103                   Deoptimization::Action_make_not_entrant);
2104   }
2105 }
2106 
2107 //------------------------------return_current---------------------------------
2108 // Append current _map to _exit_return
2109 void Parse::return_current(Node* value) {
2110   if (RegisterFinalizersAtInit &&
2111       method()->intrinsic_id() == vmIntrinsics::_Object_init) {
2112     call_register_finalizer();
2113   }
2114 
2115   // Do not set_parse_bci, so that return goo is credited to the return insn.
2116   set_bci(InvocationEntryBci);
2117   if (method()->is_synchronized() && GenerateSynchronizationCode) {
2118     shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node());
2119   }
2120   if (C->env()->dtrace_method_probes()) {
2121     make_dtrace_method_exit(method());
2122   }
2123   SafePointNode* exit_return = _exits.map();
2124   exit_return->in( TypeFunc::Control  )->add_req( control() );
2125   exit_return->in( TypeFunc::I_O      )->add_req( i_o    () );
2126   Node *mem = exit_return->in( TypeFunc::Memory   );
2127   for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) {
2128     if (mms.is_empty()) {
2129       // get a copy of the base memory, and patch just this one input
2130       const TypePtr* adr_type = mms.adr_type(C);
2131       Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type);
2132       assert(phi->as_Phi()->region() == mms.base_memory()->in(0), "");
2133       gvn().set_type_bottom(phi);
2134       phi->del_req(phi->req()-1);  // prepare to re-patch
2135       mms.set_memory(phi);
2136     }
2137     mms.memory()->add_req(mms.memory2());
2138   }
2139 
2140   // frame pointer is always same, already captured
2141   if (value != NULL) {
2142     // If returning oops to an interface-return, there is a silent free
2143     // cast from oop to interface allowed by the Verifier.  Make it explicit
2144     // here.
2145     Node* phi = _exits.argument(0);
2146     const TypeInstPtr *tr = phi->bottom_type()->isa_instptr();
2147     if( tr && tr->klass()->is_loaded() &&
2148         tr->klass()->is_interface() ) {
2149       const TypeInstPtr *tp = value->bottom_type()->isa_instptr();
2150       if (tp && tp->klass()->is_loaded() &&
2151           !tp->klass()->is_interface()) {
2152         // sharpen the type eagerly; this eases certain assert checking
2153         if (tp->higher_equal(TypeInstPtr::NOTNULL))
2154           tr = tr->join_speculative(TypeInstPtr::NOTNULL)->is_instptr();
2155         value = _gvn.transform(new CheckCastPPNode(0,value,tr));
2156       }
2157     }
2158     phi->add_req(value);
2159   }
2160 
2161   if (_first_return) {
2162     _exits.map()->transfer_replaced_nodes_from(map(), _new_idx);
2163     _first_return = false;
2164   } else {
2165     _exits.map()->merge_replaced_nodes_with(map());
2166   }
2167 
2168   stop_and_kill_map();          // This CFG path dies here
2169 }
2170 
2171 
2172 //------------------------------add_safepoint----------------------------------
2173 void Parse::add_safepoint() {
2174   // See if we can avoid this safepoint.  No need for a SafePoint immediately
2175   // after a Call (except Leaf Call) or another SafePoint.
2176   Node *proj = control();
2177   bool add_poll_param = SafePointNode::needs_polling_address_input();
2178   uint parms = add_poll_param ? TypeFunc::Parms+1 : TypeFunc::Parms;
2179   if( proj->is_Proj() ) {
2180     Node *n0 = proj->in(0);
2181     if( n0->is_Catch() ) {
2182       n0 = n0->in(0)->in(0);
2183       assert( n0->is_Call(), "expect a call here" );
2184     }
2185     if( n0->is_Call() ) {
2186       if( n0->as_Call()->guaranteed_safepoint() )
2187         return;
2188     } else if( n0->is_SafePoint() && n0->req() >= parms ) {
2189       return;
2190     }
2191   }
2192 
2193   // Clear out dead values from the debug info.
2194   kill_dead_locals();
2195 
2196   // Clone the JVM State
2197   SafePointNode *sfpnt = new SafePointNode(parms, NULL);
2198 
2199   // Capture memory state BEFORE a SafePoint.  Since we can block at a
2200   // SafePoint we need our GC state to be safe; i.e. we need all our current
2201   // write barriers (card marks) to not float down after the SafePoint so we
2202   // must read raw memory.  Likewise we need all oop stores to match the card
2203   // marks.  If deopt can happen, we need ALL stores (we need the correct JVM
2204   // state on a deopt).
2205 
2206   // We do not need to WRITE the memory state after a SafePoint.  The control
2207   // edge will keep card-marks and oop-stores from floating up from below a
2208   // SafePoint and our true dependency added here will keep them from floating
2209   // down below a SafePoint.
2210 
2211   // Clone the current memory state
2212   Node* mem = MergeMemNode::make(map()->memory());
2213 
2214   mem = _gvn.transform(mem);
2215 
2216   // Pass control through the safepoint
2217   sfpnt->init_req(TypeFunc::Control  , control());
2218   // Fix edges normally used by a call
2219   sfpnt->init_req(TypeFunc::I_O      , top() );
2220   sfpnt->init_req(TypeFunc::Memory   , mem   );
2221   sfpnt->init_req(TypeFunc::ReturnAdr, top() );
2222   sfpnt->init_req(TypeFunc::FramePtr , top() );
2223 
2224   // Create a node for the polling address
2225   if( add_poll_param ) {
2226     Node *polladr = ConPNode::make((address)os::get_polling_page());
2227     sfpnt->init_req(TypeFunc::Parms+0, _gvn.transform(polladr));
2228   }
2229 
2230   // Fix up the JVM State edges
2231   add_safepoint_edges(sfpnt);
2232   Node *transformed_sfpnt = _gvn.transform(sfpnt);
2233   set_control(transformed_sfpnt);
2234 
2235   // Provide an edge from root to safepoint.  This makes the safepoint
2236   // appear useful until the parse has completed.
2237   if( OptoRemoveUseless && transformed_sfpnt->is_SafePoint() ) {
2238     assert(C->root() != NULL, "Expect parse is still valid");
2239     C->root()->add_prec(transformed_sfpnt);
2240   }
2241 }
2242 
2243 #ifndef PRODUCT
2244 //------------------------show_parse_info--------------------------------------
2245 void Parse::show_parse_info() {
2246   InlineTree* ilt = NULL;
2247   if (C->ilt() != NULL) {
2248     JVMState* caller_jvms = is_osr_parse() ? caller()->caller() : caller();
2249     ilt = InlineTree::find_subtree_from_root(C->ilt(), caller_jvms, method());
2250   }
2251   if (PrintCompilation && Verbose) {
2252     if (depth() == 1) {
2253       if( ilt->count_inlines() ) {
2254         tty->print("    __inlined %d (%d bytes)", ilt->count_inlines(),
2255                      ilt->count_inline_bcs());
2256         tty->cr();
2257       }
2258     } else {
2259       if (method()->is_synchronized())         tty->print("s");
2260       if (method()->has_exception_handlers())  tty->print("!");
2261       // Check this is not the final compiled version
2262       if (C->trap_can_recompile()) {
2263         tty->print("-");
2264       } else {
2265         tty->print(" ");
2266       }
2267       method()->print_short_name();
2268       if (is_osr_parse()) {
2269         tty->print(" @ %d", osr_bci());
2270       }
2271       tty->print(" (%d bytes)",method()->code_size());
2272       if (ilt->count_inlines()) {
2273         tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(),
2274                    ilt->count_inline_bcs());
2275       }
2276       tty->cr();
2277     }
2278   }
2279   if (PrintOpto && (depth() == 1 || PrintOptoInlining)) {
2280     // Print that we succeeded; suppress this message on the first osr parse.
2281 
2282     if (method()->is_synchronized())         tty->print("s");
2283     if (method()->has_exception_handlers())  tty->print("!");
2284     // Check this is not the final compiled version
2285     if (C->trap_can_recompile() && depth() == 1) {
2286       tty->print("-");
2287     } else {
2288       tty->print(" ");
2289     }
2290     if( depth() != 1 ) { tty->print("   "); }  // missing compile count
2291     for (int i = 1; i < depth(); ++i) { tty->print("  "); }
2292     method()->print_short_name();
2293     if (is_osr_parse()) {
2294       tty->print(" @ %d", osr_bci());
2295     }
2296     if (ilt->caller_bci() != -1) {
2297       tty->print(" @ %d", ilt->caller_bci());
2298     }
2299     tty->print(" (%d bytes)",method()->code_size());
2300     if (ilt->count_inlines()) {
2301       tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(),
2302                  ilt->count_inline_bcs());
2303     }
2304     tty->cr();
2305   }
2306 }
2307 
2308 
2309 //------------------------------dump-------------------------------------------
2310 // Dump information associated with the bytecodes of current _method
2311 void Parse::dump() {
2312   if( method() != NULL ) {
2313     // Iterate over bytecodes
2314     ciBytecodeStream iter(method());
2315     for( Bytecodes::Code bc = iter.next(); bc != ciBytecodeStream::EOBC() ; bc = iter.next() ) {
2316       dump_bci( iter.cur_bci() );
2317       tty->cr();
2318     }
2319   }
2320 }
2321 
2322 // Dump information associated with a byte code index, 'bci'
2323 void Parse::dump_bci(int bci) {
2324   // Output info on merge-points, cloning, and within _jsr..._ret
2325   // NYI
2326   tty->print(" bci:%d", bci);
2327 }
2328 
2329 #endif