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