comparison src/share/vm/opto/parse1.cpp @ 367:194b8e3a2fc4

6384206: Phis which are later unneeded are impairing our ability to inline based on static types Reviewed-by: rasbold, jrose
author never
date Wed, 17 Sep 2008 12:59:52 -0700
parents d1605aabd0a1
children 98cb887364d3
comparison
equal deleted inserted replaced
366:8261ee795323 367:194b8e3a2fc4
27 27
28 // Static array so we can figure out which bytecodes stop us from compiling 28 // Static array so we can figure out which bytecodes stop us from compiling
29 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp 29 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp
30 // and eventually should be encapsulated in a proper class (gri 8/18/98). 30 // and eventually should be encapsulated in a proper class (gri 8/18/98).
31 31
32 int nodes_created = 0; int nodes_created_old = 0; 32 int nodes_created = 0;
33 int methods_parsed = 0; int methods_parsed_old = 0; 33 int methods_parsed = 0;
34 int methods_seen = 0; int methods_seen_old = 0; 34 int methods_seen = 0;
35 35 int blocks_parsed = 0;
36 int explicit_null_checks_inserted = 0, explicit_null_checks_inserted_old = 0; 36 int blocks_seen = 0;
37 int explicit_null_checks_elided = 0, explicit_null_checks_elided_old = 0; 37
38 int explicit_null_checks_inserted = 0;
39 int explicit_null_checks_elided = 0;
38 int all_null_checks_found = 0, implicit_null_checks = 0; 40 int all_null_checks_found = 0, implicit_null_checks = 0;
39 int implicit_null_throws = 0; 41 int implicit_null_throws = 0;
40 42
41 int parse_idx = 0;
42 size_t parse_arena = 0;
43 int reclaim_idx = 0; 43 int reclaim_idx = 0;
44 int reclaim_in = 0; 44 int reclaim_in = 0;
45 int reclaim_node = 0; 45 int reclaim_node = 0;
46 46
47 #ifndef PRODUCT 47 #ifndef PRODUCT
59 tty->print("Methods seen: %d Methods parsed: %d", methods_seen, methods_parsed); 59 tty->print("Methods seen: %d Methods parsed: %d", methods_seen, methods_parsed);
60 tty->print(" Nodes created: %d", nodes_created); 60 tty->print(" Nodes created: %d", nodes_created);
61 tty->cr(); 61 tty->cr();
62 if (methods_seen != methods_parsed) 62 if (methods_seen != methods_parsed)
63 tty->print_cr("Reasons for parse failures (NOT cumulative):"); 63 tty->print_cr("Reasons for parse failures (NOT cumulative):");
64 tty->print_cr("Blocks parsed: %d Blocks seen: %d", blocks_parsed, blocks_seen);
64 65
65 if( explicit_null_checks_inserted ) 66 if( explicit_null_checks_inserted )
66 tty->print_cr("%d original NULL checks - %d elided (%2d%%); optimizer leaves %d,", explicit_null_checks_inserted, explicit_null_checks_elided, (100*explicit_null_checks_elided)/explicit_null_checks_inserted, all_null_checks_found); 67 tty->print_cr("%d original NULL checks - %d elided (%2d%%); optimizer leaves %d,", explicit_null_checks_inserted, explicit_null_checks_elided, (100*explicit_null_checks_elided)/explicit_null_checks_inserted, all_null_checks_found);
67 if( all_null_checks_found ) 68 if( all_null_checks_found )
68 tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks, 69 tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks,
371 _flow = method()->get_flow_analysis(); 372 _flow = method()->get_flow_analysis();
372 if (_flow->failing()) { 373 if (_flow->failing()) {
373 C->record_method_not_compilable_all_tiers(_flow->failure_reason()); 374 C->record_method_not_compilable_all_tiers(_flow->failure_reason());
374 } 375 }
375 376
377 #ifndef PRODUCT
378 if (_flow->has_irreducible_entry()) {
379 C->set_parsed_irreducible_loop(true);
380 }
381 #endif
382
376 if (_expected_uses <= 0) { 383 if (_expected_uses <= 0) {
377 _prof_factor = 1; 384 _prof_factor = 1;
378 } else { 385 } else {
379 float prof_total = parse_method->interpreter_invocation_count(); 386 float prof_total = parse_method->interpreter_invocation_count();
380 if (prof_total <= _expected_uses) { 387 if (prof_total <= _expected_uses) {
554 561
555 // Fix up all exiting control flow. 562 // Fix up all exiting control flow.
556 set_map(entry_map); 563 set_map(entry_map);
557 do_exits(); 564 do_exits();
558 565
559 // Collect a few more statistics.
560 parse_idx += C->unique();
561 parse_arena += C->node_arena()->used();
562
563 if (log) log->done("parse nodes='%d' memory='%d'", 566 if (log) log->done("parse nodes='%d' memory='%d'",
564 C->unique(), C->node_arena()->used()); 567 C->unique(), C->node_arena()->used());
565 } 568 }
566 569
567 //---------------------------do_all_blocks------------------------------------- 570 //---------------------------do_all_blocks-------------------------------------
568 void Parse::do_all_blocks() { 571 void Parse::do_all_blocks() {
569 _blocks_merged = 0; 572 bool has_irreducible = flow()->has_irreducible_entry();
570 _blocks_parsed = 0; 573
571 574 // Walk over all blocks in Reverse Post-Order.
572 int old_blocks_merged = -1; 575 while (true) {
573 int old_blocks_parsed = -1; 576 bool progress = false;
574 577 for (int rpo = 0; rpo < block_count(); rpo++) {
575 for (int tries = 0; ; tries++) { 578 Block* block = rpo_at(rpo);
576 visit_blocks(); 579
577 if (failing()) return; // Check for bailout 580 if (block->is_parsed()) continue;
578 581
579 // No need for a work list. The outer loop is hardly ever repeated. 582 if (!block->is_merged()) {
580 // The following loop traverses the blocks in a reasonable pre-order, 583 // Dead block, no state reaches this block
581 // as produced by the ciTypeFlow pass. 584 continue;
582
583 // This loop can be taken more than once if there are two entries to
584 // a loop (irreduceable CFG), and the edge which ciTypeFlow chose
585 // as the first predecessor to the loop goes dead in the parser,
586 // due to parse-time optimization. (Could happen with obfuscated code.)
587
588 // Look for progress, or the lack of it:
589 if (_blocks_parsed == block_count()) {
590 // That's all, folks.
591 if (TraceOptoParse) {
592 tty->print_cr("All blocks parsed.");
593 } 585 }
586
587 // Prepare to parse this block.
588 load_state_from(block);
589
590 if (stopped()) {
591 // Block is dead.
592 continue;
593 }
594
595 blocks_parsed++;
596
597 progress = true;
598 if (block->is_loop_head() || block->is_handler() || has_irreducible && !block->is_ready()) {
599 // Not all preds have been parsed. We must build phis everywhere.
600 // (Note that dead locals do not get phis built, ever.)
601 ensure_phis_everywhere();
602
603 // Leave behind an undisturbed copy of the map, for future merges.
604 set_map(clone_map());
605 }
606
607 if (control()->is_Region() && !block->is_loop_head() && !has_irreducible && !block->is_handler()) {
608 // In the absence of irreducible loops, the Region and Phis
609 // associated with a merge that doesn't involve a backedge can
610 // be simplfied now since the RPO parsing order guarantees
611 // that any path which was supposed to reach here has already
612 // been parsed or must be dead.
613 Node* c = control();
614 Node* result = _gvn.transform_no_reclaim(control());
615 if (c != result && TraceOptoParse) {
616 tty->print_cr("Block #%d replace %d with %d", block->rpo(), c->_idx, result->_idx);
617 }
618 if (result != top()) {
619 record_for_igvn(result);
620 }
621 }
622
623 // Parse the block.
624 do_one_block();
625
626 // Check for bailouts.
627 if (failing()) return;
628 }
629
630 // with irreducible loops multiple passes might be necessary to parse everything
631 if (!has_irreducible || !progress) {
594 break; 632 break;
595 } 633 }
596 634 }
597 // How much work was done this time around? 635
598 int new_blocks_merged = _blocks_merged - old_blocks_merged; 636 blocks_seen += block_count();
599 int new_blocks_parsed = _blocks_parsed - old_blocks_parsed;
600 if (new_blocks_merged == 0) {
601 if (TraceOptoParse) {
602 tty->print_cr("All live blocks parsed; %d dead blocks.", block_count() - _blocks_parsed);
603 }
604 // No new blocks have become parseable. Some blocks are just dead.
605 break;
606 }
607 assert(new_blocks_parsed > 0, "must make progress");
608 assert(tries < block_count(), "the pre-order cannot be this bad!");
609
610 old_blocks_merged = _blocks_merged;
611 old_blocks_parsed = _blocks_parsed;
612 }
613 637
614 #ifndef PRODUCT 638 #ifndef PRODUCT
615 // Make sure there are no half-processed blocks remaining. 639 // Make sure there are no half-processed blocks remaining.
616 // Every remaining unprocessed block is dead and may be ignored now. 640 // Every remaining unprocessed block is dead and may be ignored now.
617 for (int po = 0; po < block_count(); po++) { 641 for (int rpo = 0; rpo < block_count(); rpo++) {
618 Block* block = pre_order_at(po); 642 Block* block = rpo_at(rpo);
619 if (!block->is_parsed()) { 643 if (!block->is_parsed()) {
620 if (TraceOptoParse) { 644 if (TraceOptoParse) {
621 tty->print("Skipped dead block %d at bci:%d", po, block->start()); 645 tty->print_cr("Skipped dead block %d at bci:%d", rpo, block->start());
622 assert(!block->is_merged(), "no half-processed blocks");
623 } 646 }
647 assert(!block->is_merged(), "no half-processed blocks");
624 } 648 }
625 } 649 }
626 #endif 650 #endif
627 }
628
629 //---------------------------visit_blocks--------------------------------------
630 void Parse::visit_blocks() {
631 // Walk over all blocks, parsing every one that has been reached (merged).
632 for (int po = 0; po < block_count(); po++) {
633 Block* block = pre_order_at(po);
634
635 if (block->is_parsed()) {
636 // Do not parse twice.
637 continue;
638 }
639
640 if (!block->is_merged()) {
641 // No state on this block. It had not yet been reached.
642 // Delay reaching it until later.
643 continue;
644 }
645
646 // Prepare to parse this block.
647 load_state_from(block);
648
649 if (stopped()) {
650 // Block is dead.
651 continue;
652 }
653
654 if (!block->is_ready() || block->is_handler()) {
655 // Not all preds have been parsed. We must build phis everywhere.
656 // (Note that dead locals do not get phis built, ever.)
657 ensure_phis_everywhere();
658
659 // Leave behind an undisturbed copy of the map, for future merges.
660 set_map(clone_map());
661 }
662
663 // Ready or not, parse the block.
664 do_one_block();
665
666 // Check for bailouts.
667 if (failing()) return;
668 }
669 } 651 }
670 652
671 //-------------------------------build_exits---------------------------------- 653 //-------------------------------build_exits----------------------------------
672 // Build normal and exceptional exit merge points. 654 // Build normal and exceptional exit merge points.
673 void Parse::build_exits() { 655 void Parse::build_exits() {
1132 // Create the blocks. 1114 // Create the blocks.
1133 _block_count = flow()->block_count(); 1115 _block_count = flow()->block_count();
1134 _blocks = NEW_RESOURCE_ARRAY(Block, _block_count); 1116 _blocks = NEW_RESOURCE_ARRAY(Block, _block_count);
1135 Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count); 1117 Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count);
1136 1118
1137 int po; 1119 int rpo;
1138 1120
1139 // Initialize the structs. 1121 // Initialize the structs.
1140 for (po = 0; po < block_count(); po++) { 1122 for (rpo = 0; rpo < block_count(); rpo++) {
1141 Block* block = pre_order_at(po); 1123 Block* block = rpo_at(rpo);
1142 block->init_node(this, po); 1124 block->init_node(this, rpo);
1143 } 1125 }
1144 1126
1145 // Collect predecessor and successor information. 1127 // Collect predecessor and successor information.
1146 for (po = 0; po < block_count(); po++) { 1128 for (rpo = 0; rpo < block_count(); rpo++) {
1147 Block* block = pre_order_at(po); 1129 Block* block = rpo_at(rpo);
1148 block->init_graph(this); 1130 block->init_graph(this);
1149 } 1131 }
1150 } 1132 }
1151 1133
1152 //-------------------------------init_node------------------------------------- 1134 //-------------------------------init_node-------------------------------------
1153 void Parse::Block::init_node(Parse* outer, int po) { 1135 void Parse::Block::init_node(Parse* outer, int rpo) {
1154 _flow = outer->flow()->pre_order_at(po); 1136 _flow = outer->flow()->rpo_at(rpo);
1155 _pred_count = 0; 1137 _pred_count = 0;
1156 _preds_parsed = 0; 1138 _preds_parsed = 0;
1157 _count = 0; 1139 _count = 0;
1158 assert(pred_count() == 0 && preds_parsed() == 0, "sanity"); 1140 assert(pred_count() == 0 && preds_parsed() == 0, "sanity");
1159 assert(!(is_merged() || is_parsed() || is_handler()), "sanity"); 1141 assert(!(is_merged() || is_parsed() || is_handler()), "sanity");
1175 _all_successors = ns+ne; 1157 _all_successors = ns+ne;
1176 _successors = (ns+ne == 0) ? NULL : NEW_RESOURCE_ARRAY(Block*, ns+ne); 1158 _successors = (ns+ne == 0) ? NULL : NEW_RESOURCE_ARRAY(Block*, ns+ne);
1177 int p = 0; 1159 int p = 0;
1178 for (int i = 0; i < ns+ne; i++) { 1160 for (int i = 0; i < ns+ne; i++) {
1179 ciTypeFlow::Block* tf2 = (i < ns) ? tfs->at(i) : tfe->at(i-ns); 1161 ciTypeFlow::Block* tf2 = (i < ns) ? tfs->at(i) : tfe->at(i-ns);
1180 Block* block2 = outer->pre_order_at(tf2->pre_order()); 1162 Block* block2 = outer->rpo_at(tf2->rpo());
1181 _successors[i] = block2; 1163 _successors[i] = block2;
1182 1164
1183 // Accumulate pred info for the other block, too. 1165 // Accumulate pred info for the other block, too.
1184 if (i < ns) { 1166 if (i < ns) {
1185 block2->_pred_count++; 1167 block2->_pred_count++;
1366 Block *b = block(); 1348 Block *b = block();
1367 int ns = b->num_successors(); 1349 int ns = b->num_successors();
1368 int nt = b->all_successors(); 1350 int nt = b->all_successors();
1369 1351
1370 tty->print("Parsing block #%d at bci [%d,%d), successors: ", 1352 tty->print("Parsing block #%d at bci [%d,%d), successors: ",
1371 block()->pre_order(), block()->start(), block()->limit()); 1353 block()->rpo(), block()->start(), block()->limit());
1372 for (int i = 0; i < nt; i++) { 1354 for (int i = 0; i < nt; i++) {
1373 tty->print((( i < ns) ? " %d" : " %d(e)"), b->successor_at(i)->pre_order()); 1355 tty->print((( i < ns) ? " %d" : " %d(e)"), b->successor_at(i)->rpo());
1374 } 1356 }
1357 if (b->is_loop_head()) tty->print(" lphd");
1375 tty->print_cr(""); 1358 tty->print_cr("");
1376 } 1359 }
1377 1360
1378 assert(block()->is_merged(), "must be merged before being parsed"); 1361 assert(block()->is_merged(), "must be merged before being parsed");
1379 block()->mark_parsed(); 1362 block()->mark_parsed();
1499 //--------------------handle_missing_successor--------------------------------- 1482 //--------------------handle_missing_successor---------------------------------
1500 void Parse::handle_missing_successor(int target_bci) { 1483 void Parse::handle_missing_successor(int target_bci) {
1501 #ifndef PRODUCT 1484 #ifndef PRODUCT
1502 Block* b = block(); 1485 Block* b = block();
1503 int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1; 1486 int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1;
1504 tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->pre_order(), trap_bci); 1487 tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci);
1505 #endif 1488 #endif
1506 ShouldNotReachHere(); 1489 ShouldNotReachHere();
1507 } 1490 }
1508 1491
1509 //--------------------------merge_common--------------------------------------- 1492 //--------------------------merge_common---------------------------------------
1510 void Parse::merge_common(Parse::Block* target, int pnum) { 1493 void Parse::merge_common(Parse::Block* target, int pnum) {
1511 if (TraceOptoParse) { 1494 if (TraceOptoParse) {
1512 tty->print("Merging state at block #%d bci:%d", target->pre_order(), target->start()); 1495 tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start());
1513 } 1496 }
1514 1497
1515 // Zap extra stack slots to top 1498 // Zap extra stack slots to top
1516 assert(sp() == target->start_sp(), ""); 1499 assert(sp() == target->start_sp(), "");
1517 clean_stack(sp()); 1500 clean_stack(sp());
1532 // Make a region if we know there are multiple or unpredictable inputs. 1515 // Make a region if we know there are multiple or unpredictable inputs.
1533 // (Also, if this is a plain fall-through, we might see another region, 1516 // (Also, if this is a plain fall-through, we might see another region,
1534 // which must not be allowed into this block's map.) 1517 // which must not be allowed into this block's map.)
1535 if (pnum > PhiNode::Input // Known multiple inputs. 1518 if (pnum > PhiNode::Input // Known multiple inputs.
1536 || target->is_handler() // These have unpredictable inputs. 1519 || target->is_handler() // These have unpredictable inputs.
1520 || target->is_loop_head() // Known multiple inputs
1537 || control()->is_Region()) { // We must hide this guy. 1521 || control()->is_Region()) { // We must hide this guy.
1538 // Add a Region to start the new basic block. Phis will be added 1522 // Add a Region to start the new basic block. Phis will be added
1539 // later lazily. 1523 // later lazily.
1540 int edges = target->pred_count(); 1524 int edges = target->pred_count();
1541 if (edges < pnum) edges = pnum; // might be a new path! 1525 if (edges < pnum) edges = pnum; // might be a new path!
1573 assert(control()->is_Region(), "must be merging to a region"); 1557 assert(control()->is_Region(), "must be merging to a region");
1574 RegionNode* r = control()->as_Region(); 1558 RegionNode* r = control()->as_Region();
1575 1559
1576 // Compute where to merge into 1560 // Compute where to merge into
1577 // Merge incoming control path 1561 // Merge incoming control path
1578 r->set_req(pnum, newin->control()); 1562 r->init_req(pnum, newin->control());
1579 1563
1580 if (pnum == 1) { // Last merge for this Region? 1564 if (pnum == 1) { // Last merge for this Region?
1581 _gvn.transform_no_reclaim(r); 1565 if (!block()->flow()->is_irreducible_entry()) {
1566 Node* result = _gvn.transform_no_reclaim(r);
1567 if (r != result && TraceOptoParse) {
1568 tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx);
1569 }
1570 }
1582 record_for_igvn(r); 1571 record_for_igvn(r);
1583 } 1572 }
1584 1573
1585 // Update all the non-control inputs to map: 1574 // Update all the non-control inputs to map:
1586 assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms"); 1575 assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms");
1576 bool check_elide_phi = target->is_SEL_backedge(save_block);
1587 for (uint j = 1; j < newin->req(); j++) { 1577 for (uint j = 1; j < newin->req(); j++) {
1588 Node* m = map()->in(j); // Current state of target. 1578 Node* m = map()->in(j); // Current state of target.
1589 Node* n = newin->in(j); // Incoming change to target state. 1579 Node* n = newin->in(j); // Incoming change to target state.
1590 PhiNode* phi; 1580 PhiNode* phi;
1591 if (m->is_Phi() && m->as_Phi()->region() == r) 1581 if (m->is_Phi() && m->as_Phi()->region() == r)
1601 case TypeFunc::Memory: // Merge inputs to the MergeMem node 1591 case TypeFunc::Memory: // Merge inputs to the MergeMem node
1602 assert(phi == NULL, "the merge contains phis, not vice versa"); 1592 assert(phi == NULL, "the merge contains phis, not vice versa");
1603 merge_memory_edges(n->as_MergeMem(), pnum, nophi); 1593 merge_memory_edges(n->as_MergeMem(), pnum, nophi);
1604 continue; 1594 continue;
1605 default: // All normal stuff 1595 default: // All normal stuff
1606 if (phi == NULL) phi = ensure_phi(j, nophi); 1596 if (phi == NULL) {
1597 if (!check_elide_phi || !target->can_elide_SEL_phi(j)) {
1598 phi = ensure_phi(j, nophi);
1599 }
1600 }
1607 break; 1601 break;
1608 } 1602 }
1609 } 1603 }
1610 // At this point, n might be top if: 1604 // At this point, n might be top if:
1611 // - there is no phi (because TypeFlow detected a conflict), or 1605 // - there is no phi (because TypeFlow detected a conflict), or
1734 // Phi-ify everything up to the monitors, though. 1728 // Phi-ify everything up to the monitors, though.
1735 uint monoff = map()->jvms()->monoff(); 1729 uint monoff = map()->jvms()->monoff();
1736 uint nof_monitors = map()->jvms()->nof_monitors(); 1730 uint nof_monitors = map()->jvms()->nof_monitors();
1737 1731
1738 assert(TypeFunc::Parms == map()->jvms()->locoff(), "parser map should contain only youngest jvms"); 1732 assert(TypeFunc::Parms == map()->jvms()->locoff(), "parser map should contain only youngest jvms");
1733 bool check_elide_phi = block()->is_SEL_head();
1739 for (uint i = TypeFunc::Parms; i < monoff; i++) { 1734 for (uint i = TypeFunc::Parms; i < monoff; i++) {
1740 ensure_phi(i); 1735 if (!check_elide_phi || !block()->can_elide_SEL_phi(i)) {
1741 } 1736 ensure_phi(i);
1737 }
1738 }
1739
1742 // Even monitors need Phis, though they are well-structured. 1740 // Even monitors need Phis, though they are well-structured.
1743 // This is true for OSR methods, and also for the rare cases where 1741 // This is true for OSR methods, and also for the rare cases where
1744 // a monitor object is the subject of a replace_in_map operation. 1742 // a monitor object is the subject of a replace_in_map operation.
1745 // See bugs 4426707 and 5043395. 1743 // See bugs 4426707 and 5043395.
1746 for (uint m = 0; m < nof_monitors; m++) { 1744 for (uint m = 0; m < nof_monitors; m++) {