< prev index next >

src/share/vm/ci/ciTypeFlow.cpp

Print this page




1571     _pred->successors()->at_put(_index, succ);
1572   } else {
1573     int idx = _index - succ_ct;
1574     _pred->exceptions()->at_put(idx, succ);
1575   }
1576 }
1577 
1578 // ciTypeFlow::Block
1579 //
1580 // A basic block.
1581 
1582 // ------------------------------------------------------------------
1583 // ciTypeFlow::Block::Block
1584 ciTypeFlow::Block::Block(ciTypeFlow* outer,
1585                          ciBlock *ciblk,
1586                          ciTypeFlow::JsrSet* jsrs) {
1587   _ciblock = ciblk;
1588   _exceptions = NULL;
1589   _exc_klasses = NULL;
1590   _successors = NULL;

1591   _state = new (outer->arena()) StateVector(outer);
1592   JsrSet* new_jsrs =
1593     new (outer->arena()) JsrSet(outer->arena(), jsrs->size());
1594   jsrs->copy_into(new_jsrs);
1595   _jsrs = new_jsrs;
1596   _next = NULL;
1597   _on_work_list = false;
1598   _backedge_copy = false;
1599   _has_monitorenter = false;
1600   _trap_bci = -1;
1601   _trap_index = 0;
1602   df_init();
1603 
1604   if (CITraceTypeFlow) {
1605     tty->print_cr(">> Created new block");
1606     print_on(tty);
1607   }
1608 
1609   assert(this->outer() == outer, "outer link set up");
1610   assert(!outer->have_block_count(), "must not have mapped blocks yet");


1754 
1755       case Bytecodes::_ret: {
1756         _successors =
1757           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1758 
1759         Cell local = state->local(str->get_index());
1760         ciType* return_address = state->type_at(local);
1761         assert(return_address->is_return_address(), "verify: wrong type");
1762         int bci = return_address->as_return_address()->bci();
1763         assert(_successors->length() == GOTO_TARGET, "");
1764         _successors->append(analyzer->block_at(bci, jsrs));
1765         break;
1766       }
1767 
1768       case Bytecodes::_wide:
1769       default:
1770         ShouldNotReachHere();
1771         break;
1772       }
1773     }






1774   }
1775   return _successors;
1776 }
1777 
1778 // ------------------------------------------------------------------
1779 // ciTypeFlow::Block:compute_exceptions
1780 //
1781 // Compute the exceptional successors and types for this Block.
1782 void ciTypeFlow::Block::compute_exceptions() {
1783   assert(_exceptions == NULL && _exc_klasses == NULL, "repeat");
1784 
1785   if (CITraceTypeFlow) {
1786     tty->print(">> Computing exceptions for block ");
1787     print_value_on(tty);
1788     tty->cr();
1789   }
1790 
1791   ciTypeFlow* analyzer = outer();
1792   Arena* arena = analyzer->arena();
1793 


1892     do {
1893       st->print(" %d<-%d", lp->head()->pre_order(),lp->tail()->pre_order());
1894       if (lp->is_irreducible()) st->print("(ir)");
1895       lp = lp->parent();
1896     } while (lp->parent() != NULL);
1897   }
1898   st->cr();
1899   _state->print_on(st);
1900   if (_successors == NULL) {
1901     st->print_cr("  No successor information");
1902   } else {
1903     int num_successors = _successors->length();
1904     st->print_cr("  Successors : %d", num_successors);
1905     for (int i = 0; i < num_successors; i++) {
1906       Block* successor = _successors->at(i);
1907       st->print("    ");
1908       successor->print_value_on(st);
1909       st->cr();
1910     }
1911   }












1912   if (_exceptions == NULL) {
1913     st->print_cr("  No exception information");
1914   } else {
1915     int num_exceptions = _exceptions->length();
1916     st->print_cr("  Exceptions : %d", num_exceptions);
1917     for (int i = 0; i < num_exceptions; i++) {
1918       Block* exc_succ = _exceptions->at(i);
1919       ciInstanceKlass* exc_klass = _exc_klasses->at(i);
1920       st->print("    ");
1921       exc_succ->print_value_on(st);
1922       st->print(" -- ");
1923       exc_klass->name()->print_symbol_on(st);
1924       st->cr();
1925     }
1926   }
1927   if (has_trap()) {
1928     st->print_cr("  Traps on %d with trap index %d", trap_bci(), trap_index());
1929   }
1930   st->print_cr("  ====================================================  ");
1931 }


2864     method()->print();
2865     if (is_osr_flow())  tty->print(" at OSR bci %d", start_bci());
2866     tty->cr();
2867     method()->print_codes();
2868   }
2869   if (CITraceTypeFlow) {
2870     tty->print_cr("Initial CI Blocks");
2871     print_on(tty);
2872   }
2873   flow_types();
2874   // Watch for bailouts.
2875   if (failing()) {
2876     return;
2877   }
2878 
2879   map_blocks();
2880 
2881   if (CIPrintTypeFlow || CITraceTypeFlow) {
2882     rpo_print_on(tty);
2883   }





























































2884 }
2885 
2886 // ------------------------------------------------------------------
2887 // ciTypeFlow::record_failure()
2888 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
2889 // This is required because there is not a 1-1 relation between the ciEnv and
2890 // the TypeFlow passes within a compilation task.  For example, if the compiler
2891 // is considering inlining a method, it will request a TypeFlow.  If that fails,
2892 // the compilation as a whole may continue without the inlining.  Some TypeFlow
2893 // requests are not optional; if they fail the requestor is responsible for
2894 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
2895 void ciTypeFlow::record_failure(const char* reason) {
2896   if (env()->log() != NULL) {
2897     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
2898   }
2899   if (_failure_reason == NULL) {
2900     // Record the first failure reason.
2901     _failure_reason = reason;
2902   }
2903 }




1571     _pred->successors()->at_put(_index, succ);
1572   } else {
1573     int idx = _index - succ_ct;
1574     _pred->exceptions()->at_put(idx, succ);
1575   }
1576 }
1577 
1578 // ciTypeFlow::Block
1579 //
1580 // A basic block.
1581 
1582 // ------------------------------------------------------------------
1583 // ciTypeFlow::Block::Block
1584 ciTypeFlow::Block::Block(ciTypeFlow* outer,
1585                          ciBlock *ciblk,
1586                          ciTypeFlow::JsrSet* jsrs) {
1587   _ciblock = ciblk;
1588   _exceptions = NULL;
1589   _exc_klasses = NULL;
1590   _successors = NULL;
1591   _predecessors = new (outer->arena()) GrowableArray<Block*>(outer->arena(), 1, 0, NULL);
1592   _state = new (outer->arena()) StateVector(outer);
1593   JsrSet* new_jsrs =
1594     new (outer->arena()) JsrSet(outer->arena(), jsrs->size());
1595   jsrs->copy_into(new_jsrs);
1596   _jsrs = new_jsrs;
1597   _next = NULL;
1598   _on_work_list = false;
1599   _backedge_copy = false;
1600   _has_monitorenter = false;
1601   _trap_bci = -1;
1602   _trap_index = 0;
1603   df_init();
1604 
1605   if (CITraceTypeFlow) {
1606     tty->print_cr(">> Created new block");
1607     print_on(tty);
1608   }
1609 
1610   assert(this->outer() == outer, "outer link set up");
1611   assert(!outer->have_block_count(), "must not have mapped blocks yet");


1755 
1756       case Bytecodes::_ret: {
1757         _successors =
1758           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1759 
1760         Cell local = state->local(str->get_index());
1761         ciType* return_address = state->type_at(local);
1762         assert(return_address->is_return_address(), "verify: wrong type");
1763         int bci = return_address->as_return_address()->bci();
1764         assert(_successors->length() == GOTO_TARGET, "");
1765         _successors->append(analyzer->block_at(bci, jsrs));
1766         break;
1767       }
1768 
1769       case Bytecodes::_wide:
1770       default:
1771         ShouldNotReachHere();
1772         break;
1773       }
1774     }
1775 
1776     // Set predecessor information
1777     for (int i = 0; i < _successors->length(); i++) {
1778       Block* block = _successors->at(i);
1779       block->predecessors()->append(this);
1780     }
1781   }
1782   return _successors;
1783 }
1784 
1785 // ------------------------------------------------------------------
1786 // ciTypeFlow::Block:compute_exceptions
1787 //
1788 // Compute the exceptional successors and types for this Block.
1789 void ciTypeFlow::Block::compute_exceptions() {
1790   assert(_exceptions == NULL && _exc_klasses == NULL, "repeat");
1791 
1792   if (CITraceTypeFlow) {
1793     tty->print(">> Computing exceptions for block ");
1794     print_value_on(tty);
1795     tty->cr();
1796   }
1797 
1798   ciTypeFlow* analyzer = outer();
1799   Arena* arena = analyzer->arena();
1800 


1899     do {
1900       st->print(" %d<-%d", lp->head()->pre_order(),lp->tail()->pre_order());
1901       if (lp->is_irreducible()) st->print("(ir)");
1902       lp = lp->parent();
1903     } while (lp->parent() != NULL);
1904   }
1905   st->cr();
1906   _state->print_on(st);
1907   if (_successors == NULL) {
1908     st->print_cr("  No successor information");
1909   } else {
1910     int num_successors = _successors->length();
1911     st->print_cr("  Successors : %d", num_successors);
1912     for (int i = 0; i < num_successors; i++) {
1913       Block* successor = _successors->at(i);
1914       st->print("    ");
1915       successor->print_value_on(st);
1916       st->cr();
1917     }
1918   }
1919   if (_predecessors == NULL) {
1920     st->print_cr("  No predecessor information");
1921   } else {
1922     int num_predecessors = _predecessors->length();
1923     st->print_cr("  Predecessors : %d", num_predecessors);
1924     for (int i = 0; i < num_predecessors; i++) {
1925       Block* predecessor = _predecessors->at(i);
1926       st->print("    ");
1927       predecessor->print_value_on(st);
1928       st->cr();
1929     }
1930   }
1931   if (_exceptions == NULL) {
1932     st->print_cr("  No exception information");
1933   } else {
1934     int num_exceptions = _exceptions->length();
1935     st->print_cr("  Exceptions : %d", num_exceptions);
1936     for (int i = 0; i < num_exceptions; i++) {
1937       Block* exc_succ = _exceptions->at(i);
1938       ciInstanceKlass* exc_klass = _exc_klasses->at(i);
1939       st->print("    ");
1940       exc_succ->print_value_on(st);
1941       st->print(" -- ");
1942       exc_klass->name()->print_symbol_on(st);
1943       st->cr();
1944     }
1945   }
1946   if (has_trap()) {
1947     st->print_cr("  Traps on %d with trap index %d", trap_bci(), trap_index());
1948   }
1949   st->print_cr("  ====================================================  ");
1950 }


2883     method()->print();
2884     if (is_osr_flow())  tty->print(" at OSR bci %d", start_bci());
2885     tty->cr();
2886     method()->print_codes();
2887   }
2888   if (CITraceTypeFlow) {
2889     tty->print_cr("Initial CI Blocks");
2890     print_on(tty);
2891   }
2892   flow_types();
2893   // Watch for bailouts.
2894   if (failing()) {
2895     return;
2896   }
2897 
2898   map_blocks();
2899 
2900   if (CIPrintTypeFlow || CITraceTypeFlow) {
2901     rpo_print_on(tty);
2902   }
2903 }
2904 
2905 // ------------------------------------------------------------------
2906 // ciTypeFlow::is_dominated_by
2907 //
2908 // Determine if the instruction at bci is dominated by the instruction at dom_bci.
2909 bool ciTypeFlow::is_dominated_by(int bci, int dom_bci) {
2910   ResourceMark rm;
2911   JsrSet* jsrs = new ciTypeFlow::JsrSet(NULL);
2912   int        index = _methodBlocks->block_containing(bci)->index();
2913   int    dom_index = _methodBlocks->block_containing(dom_bci)->index();
2914   Block*     block = get_block_for(index, jsrs, ciTypeFlow::no_create);
2915   Block* dom_block = get_block_for(dom_index, jsrs, ciTypeFlow::no_create);
2916 
2917   // Start block dominates all other blocks
2918   if (start_block()->rpo() == dom_block->rpo()) {
2919     return true;
2920   }
2921 
2922   // Dominated[i] is true if block i is dominated by dom_block
2923   int num_blocks = _methodBlocks->num_blocks();
2924   bool* dominated = NEW_RESOURCE_ARRAY(bool, num_blocks);
2925   for (int i = 0; i < num_blocks; ++i) {
2926     dominated[i] = true;
2927   }
2928   dominated[start_block()->rpo()] = false;
2929 
2930   // Iterative dominator algorithm
2931   bool changed = true;
2932   while (changed) {
2933     changed = false;
2934     // Use reverse postorder iteration
2935     for (Block* blk = _rpo_list; blk != NULL; blk = blk->rpo_next()) {
2936       if (blk->is_start()) {
2937         // Ignore start block
2938         continue;
2939       }
2940       // The block is dominated if it is the dominating block
2941       // itself or if all predecessors are dominated.
2942       int index = blk->rpo();
2943       bool dom = (index == dom_block->rpo());
2944       if (!dom) {
2945         // Check if all predecessors are dominated
2946         dom = true;
2947         for (int i = 0; i < blk->predecessors()->length(); ++i) {
2948           Block* pred = blk->predecessors()->at(i);
2949           if (!dominated[pred->rpo()]) {
2950             dom = false;
2951             break;
2952           }
2953         }
2954       }
2955       // Update dominator information
2956       if (dominated[index] != dom) {
2957         changed = true;
2958         dominated[index] = dom;
2959       }
2960     }
2961   }
2962   // block dominated by dom_block?
2963   return dominated[block->rpo()];
2964 }
2965 
2966 // ------------------------------------------------------------------
2967 // ciTypeFlow::record_failure()
2968 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
2969 // This is required because there is not a 1-1 relation between the ciEnv and
2970 // the TypeFlow passes within a compilation task.  For example, if the compiler
2971 // is considering inlining a method, it will request a TypeFlow.  If that fails,
2972 // the compilation as a whole may continue without the inlining.  Some TypeFlow
2973 // requests are not optional; if they fail the requestor is responsible for
2974 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
2975 void ciTypeFlow::record_failure(const char* reason) {
2976   if (env()->log() != NULL) {
2977     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
2978   }
2979   if (_failure_reason == NULL) {
2980     // Record the first failure reason.
2981     _failure_reason = reason;
2982   }
2983 }


< prev index next >