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