< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

1724 
1725     } // End of for all instructions
1726 
1727   } // End of for all blocks
1728 }
1729 
1730 // Helper to stretch above; recursively discover the base Node for a
1731 // given derived Node.  Easy for AddP-related machine nodes, but needs
1732 // to be recursive for derived Phis.
1733 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1734   // See if already computed; if so return it
1735   if( derived_base_map[derived->_idx] )
1736     return derived_base_map[derived->_idx];
1737 
1738   // See if this happens to be a base.
1739   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1740   // pointers derived from NULL!  These are always along paths that
1741   // can't happen at run-time but the optimizer cannot deduce it so
1742   // we have to handle it gracefully.
1743   assert(!derived->bottom_type()->isa_narrowoop() ||
1744           derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1745   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1746   // If its an OOP with a non-zero offset, then it is derived.
1747   if( tj == NULL || tj->_offset == 0 ) {
1748     derived_base_map[derived->_idx] = derived;
1749     return derived;
1750   }
1751   // Derived is NULL+offset?  Base is NULL!
1752   if( derived->is_Con() ) {
1753     Node *base = _matcher.mach_null();
1754     assert(base != NULL, "sanity");
1755     if (base->in(0) == NULL) {
1756       // Initialize it once and make it shared:
1757       // set control to _root and place it into Start block
1758       // (where top() node is placed).
1759       base->init_req(0, _cfg.get_root_node());
1760       Block *startb = _cfg.get_block_for_node(C->top());
1761       uint node_pos = startb->find_node(C->top());
1762       startb->insert_node(base, node_pos);
1763       _cfg.map_node_to_block(base, startb);
1764       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1765 
1766       // The loadConP0 might have projection nodes depending on architecture
1767       // Add the projection nodes to the CFG

1893         // Copies do not define a new value and so do not interfere.
1894         // Remove the copies source from the liveout set before interfering.
1895         uint idx = n->is_Copy();
1896         if (idx) {
1897           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1898         }
1899       }
1900 
1901       // Found a safepoint?
1902       JVMState *jvms = n->jvms();
1903       if (jvms && !liveout.is_empty()) {
1904         // Now scan for a live derived pointer
1905         IndexSetIterator elements(&liveout);
1906         uint neighbor;
1907         while ((neighbor = elements.next()) != 0) {
1908           // Find reaching DEF for base and derived values
1909           // This works because we are still in SSA during this call.
1910           Node *derived = lrgs(neighbor)._def;
1911           const TypePtr *tj = derived->bottom_type()->isa_ptr();
1912           assert(!derived->bottom_type()->isa_narrowoop() ||
1913                   derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1914           // If its an OOP with a non-zero offset, then it is derived.
1915           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1916             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1917             assert(base->_idx < _lrg_map.size(), "");
1918             // Add reaching DEFs of derived pointer and base pointer as a
1919             // pair of inputs
1920             n->add_req(derived);
1921             n->add_req(base);
1922 
1923             // See if the base pointer is already live to this point.
1924             // Since I'm working on the SSA form, live-ness amounts to
1925             // reaching def's.  So if I find the base's live range then
1926             // I know the base's def reaches here.
1927             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1928                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1929                  (_lrg_map.live_range_id(base) > 0) && // not a constant
1930                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
1931               // Base pointer is not currently live.  Since I stretched
1932               // the base pointer to here and it crosses basic-block
1933               // boundaries, the global live info is now incorrect.
1934               // Recompute live.
1935               must_recompute_live = true;

2185   return buf+strlen(buf);
2186 }
2187 
2188 void PhaseChaitin::dump_for_spill_split_recycle() const {
2189   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2190     // Display which live ranges need to be split and the allocator's state
2191     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2192     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2193       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2194         tty->print("L%d: ", bidx);
2195         lrgs(bidx).dump();
2196       }
2197     }
2198     tty->cr();
2199     dump();
2200   }
2201 }
2202 
2203 void PhaseChaitin::dump_frame() const {
2204   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2205   const TypeTuple *domain = C->tf()->domain();
2206   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2207 
2208   // Incoming arguments in registers dump
2209   for( int k = 0; k < argcnt; k++ ) {
2210     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2211     if( OptoReg::is_reg(parmreg))  {
2212       const char *reg_name = OptoReg::regname(parmreg);
2213       tty->print("#r%3.3d %s", parmreg, reg_name);
2214       parmreg = _matcher._parm_regs[k].second();
2215       if( OptoReg::is_reg(parmreg))  {
2216         tty->print(":%s", OptoReg::regname(parmreg));
2217       }
2218       tty->print("   : parm %d: ", k);
2219       domain->field_at(k + TypeFunc::Parms)->dump();
2220       tty->cr();
2221     }
2222   }
2223 
2224   // Check for un-owned padding above incoming args
2225   OptoReg::Name reg = _matcher._new_SP;

2394             // Check each derived/base pair
2395             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2396               Node* check = sfpt->in(idx);
2397               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2398               // search upwards through spills and spill phis for AddP
2399               worklist.clear();
2400               worklist.push(check);
2401               uint k = 0;
2402               while (k < worklist.size()) {
2403                 check = worklist.at(k);
2404                 assert(check, "Bad base or derived pointer");
2405                 // See PhaseChaitin::find_base_for_derived() for all cases.
2406                 int isc = check->is_Copy();
2407                 if (isc) {
2408                   worklist.push(check->in(isc));
2409                 } else if (check->is_Phi()) {
2410                   for (uint m = 1; m < check->req(); m++) {
2411                     worklist.push(check->in(m));
2412                   }
2413                 } else if (check->is_Con()) {
2414                   if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2415                     // Derived is NULL+non-zero offset, base must be NULL.
2416                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2417                   } else {
2418                     assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2419                     // Base either ConP(NULL) or loadConP
2420                     if (check->is_Mach()) {
2421                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2422                     } else {
2423                       assert(check->Opcode() == Op_ConP &&
2424                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2425                     }
2426                   }
2427                 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2428                   if (check->is_Proj() || (check->is_Mach() &&
2429                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2430                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2431                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2432                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2433 #ifdef _LP64
2434                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2435                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2436                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2437 #endif // _LP64
2438                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2439                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2440                     // Valid nodes
2441                   } else {
2442                     check->dump();
2443                     assert(false, "Bad base or derived pointer");
2444                   }
2445                 } else {
2446                   assert(is_derived, "Bad base pointer");
2447                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");

1724 
1725     } // End of for all instructions
1726 
1727   } // End of for all blocks
1728 }
1729 
1730 // Helper to stretch above; recursively discover the base Node for a
1731 // given derived Node.  Easy for AddP-related machine nodes, but needs
1732 // to be recursive for derived Phis.
1733 Node *PhaseChaitin::find_base_for_derived( Node **derived_base_map, Node *derived, uint &maxlrg ) {
1734   // See if already computed; if so return it
1735   if( derived_base_map[derived->_idx] )
1736     return derived_base_map[derived->_idx];
1737 
1738   // See if this happens to be a base.
1739   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1740   // pointers derived from NULL!  These are always along paths that
1741   // can't happen at run-time but the optimizer cannot deduce it so
1742   // we have to handle it gracefully.
1743   assert(!derived->bottom_type()->isa_narrowoop() ||
1744          derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1745   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1746   // If its an OOP with a non-zero offset, then it is derived.
1747   if (tj == NULL || tj->offset() == 0) {
1748     derived_base_map[derived->_idx] = derived;
1749     return derived;
1750   }
1751   // Derived is NULL+offset?  Base is NULL!
1752   if( derived->is_Con() ) {
1753     Node *base = _matcher.mach_null();
1754     assert(base != NULL, "sanity");
1755     if (base->in(0) == NULL) {
1756       // Initialize it once and make it shared:
1757       // set control to _root and place it into Start block
1758       // (where top() node is placed).
1759       base->init_req(0, _cfg.get_root_node());
1760       Block *startb = _cfg.get_block_for_node(C->top());
1761       uint node_pos = startb->find_node(C->top());
1762       startb->insert_node(base, node_pos);
1763       _cfg.map_node_to_block(base, startb);
1764       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1765 
1766       // The loadConP0 might have projection nodes depending on architecture
1767       // Add the projection nodes to the CFG

1893         // Copies do not define a new value and so do not interfere.
1894         // Remove the copies source from the liveout set before interfering.
1895         uint idx = n->is_Copy();
1896         if (idx) {
1897           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1898         }
1899       }
1900 
1901       // Found a safepoint?
1902       JVMState *jvms = n->jvms();
1903       if (jvms && !liveout.is_empty()) {
1904         // Now scan for a live derived pointer
1905         IndexSetIterator elements(&liveout);
1906         uint neighbor;
1907         while ((neighbor = elements.next()) != 0) {
1908           // Find reaching DEF for base and derived values
1909           // This works because we are still in SSA during this call.
1910           Node *derived = lrgs(neighbor)._def;
1911           const TypePtr *tj = derived->bottom_type()->isa_ptr();
1912           assert(!derived->bottom_type()->isa_narrowoop() ||
1913                  derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1914           // If its an OOP with a non-zero offset, then it is derived.
1915           if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
1916             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1917             assert(base->_idx < _lrg_map.size(), "");
1918             // Add reaching DEFs of derived pointer and base pointer as a
1919             // pair of inputs
1920             n->add_req(derived);
1921             n->add_req(base);
1922 
1923             // See if the base pointer is already live to this point.
1924             // Since I'm working on the SSA form, live-ness amounts to
1925             // reaching def's.  So if I find the base's live range then
1926             // I know the base's def reaches here.
1927             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1928                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1929                  (_lrg_map.live_range_id(base) > 0) && // not a constant
1930                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
1931               // Base pointer is not currently live.  Since I stretched
1932               // the base pointer to here and it crosses basic-block
1933               // boundaries, the global live info is now incorrect.
1934               // Recompute live.
1935               must_recompute_live = true;

2185   return buf+strlen(buf);
2186 }
2187 
2188 void PhaseChaitin::dump_for_spill_split_recycle() const {
2189   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2190     // Display which live ranges need to be split and the allocator's state
2191     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2192     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2193       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2194         tty->print("L%d: ", bidx);
2195         lrgs(bidx).dump();
2196       }
2197     }
2198     tty->cr();
2199     dump();
2200   }
2201 }
2202 
2203 void PhaseChaitin::dump_frame() const {
2204   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2205   const TypeTuple *domain = C->tf()->domain_cc();
2206   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2207 
2208   // Incoming arguments in registers dump
2209   for( int k = 0; k < argcnt; k++ ) {
2210     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2211     if( OptoReg::is_reg(parmreg))  {
2212       const char *reg_name = OptoReg::regname(parmreg);
2213       tty->print("#r%3.3d %s", parmreg, reg_name);
2214       parmreg = _matcher._parm_regs[k].second();
2215       if( OptoReg::is_reg(parmreg))  {
2216         tty->print(":%s", OptoReg::regname(parmreg));
2217       }
2218       tty->print("   : parm %d: ", k);
2219       domain->field_at(k + TypeFunc::Parms)->dump();
2220       tty->cr();
2221     }
2222   }
2223 
2224   // Check for un-owned padding above incoming args
2225   OptoReg::Name reg = _matcher._new_SP;

2394             // Check each derived/base pair
2395             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2396               Node* check = sfpt->in(idx);
2397               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2398               // search upwards through spills and spill phis for AddP
2399               worklist.clear();
2400               worklist.push(check);
2401               uint k = 0;
2402               while (k < worklist.size()) {
2403                 check = worklist.at(k);
2404                 assert(check, "Bad base or derived pointer");
2405                 // See PhaseChaitin::find_base_for_derived() for all cases.
2406                 int isc = check->is_Copy();
2407                 if (isc) {
2408                   worklist.push(check->in(isc));
2409                 } else if (check->is_Phi()) {
2410                   for (uint m = 1; m < check->req(); m++) {
2411                     worklist.push(check->in(m));
2412                   }
2413                 } else if (check->is_Con()) {
2414                   if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2415                     // Derived is NULL+non-zero offset, base must be NULL.
2416                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2417                   } else {
2418                     assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2419                     // Base either ConP(NULL) or loadConP
2420                     if (check->is_Mach()) {
2421                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2422                     } else {
2423                       assert(check->Opcode() == Op_ConP &&
2424                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2425                     }
2426                   }
2427                 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2428                   if (check->is_Proj() || (check->is_Mach() &&
2429                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2430                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2431                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2432                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2433 #ifdef _LP64
2434                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2435                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2436                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2437 #endif // _LP64
2438                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2439                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2440                     // Valid nodes
2441                   } else {
2442                     check->dump();
2443                     assert(false, "Bad base or derived pointer");
2444                   }
2445                 } else {
2446                   assert(is_derived, "Bad base pointer");
2447                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
< prev index next >