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