< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

1793   // See if already computed; if so return it
1794   if (derived_base_map[derived->_idx]) {
1795     return derived_base_map[derived->_idx];
1796   }
1797 
1798 #ifdef ASSERT
1799   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1800     // Bypass the verification node
1801     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1802     derived_base_map[derived->_idx] = base;
1803     return base;
1804   }
1805 #endif
1806 
1807   // See if this happens to be a base.
1808   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1809   // pointers derived from null!  These are always along paths that
1810   // can't happen at run-time but the optimizer cannot deduce it so
1811   // we have to handle it gracefully.
1812   assert(!derived->bottom_type()->isa_narrowoop() ||
1813           derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1814   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1815   // If its an OOP with a non-zero offset, then it is derived.
1816   if( tj == nullptr || tj->_offset == 0 ) {
1817     derived_base_map[derived->_idx] = derived;
1818     return derived;
1819   }
1820   // Derived is null+offset?  Base is null!
1821   if( derived->is_Con() ) {
1822     Node *base = _matcher.mach_null();
1823     assert(base != nullptr, "sanity");
1824     if (base->in(0) == nullptr) {
1825       // Initialize it once and make it shared:
1826       // set control to _root and place it into Start block
1827       // (where top() node is placed).
1828       base->init_req(0, _cfg.get_root_node());
1829       Block *startb = _cfg.get_block_for_node(C->top());
1830       uint node_pos = startb->find_node(C->top());
1831       startb->insert_node(base, node_pos);
1832       _cfg.map_node_to_block(base, startb);
1833       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1834 
1835       // The loadConP0 might have projection nodes depending on architecture
1836       // Add the projection nodes to the CFG

1962         // Copies do not define a new value and so do not interfere.
1963         // Remove the copies source from the liveout set before interfering.
1964         uint idx = n->is_Copy();
1965         if (idx) {
1966           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1967         }
1968       }
1969 
1970       // Found a safepoint?
1971       JVMState *jvms = n->jvms();
1972       if (jvms && !liveout.is_empty()) {
1973         // Now scan for a live derived pointer
1974         IndexSetIterator elements(&liveout);
1975         uint neighbor;
1976         while ((neighbor = elements.next()) != 0) {
1977           // Find reaching DEF for base and derived values
1978           // This works because we are still in SSA during this call.
1979           Node *derived = lrgs(neighbor)._def;
1980           const TypePtr *tj = derived->bottom_type()->isa_ptr();
1981           assert(!derived->bottom_type()->isa_narrowoop() ||
1982                   derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1983           // If its an OOP with a non-zero offset, then it is derived.
1984           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
1985             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1986             assert(base->_idx < _lrg_map.size(), "");
1987             // Add reaching DEFs of derived pointer and base pointer as a
1988             // pair of inputs
1989             n->add_req(derived);
1990             n->add_req(base);
1991 
1992             // See if the base pointer is already live to this point.
1993             // Since I'm working on the SSA form, live-ness amounts to
1994             // reaching def's.  So if I find the base's live range then
1995             // I know the base's def reaches here.
1996             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1997                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1998                  (_lrg_map.live_range_id(base) > 0) && // not a constant
1999                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2000               // Base pointer is not currently live.  Since I stretched
2001               // the base pointer to here and it crosses basic-block
2002               // boundaries, the global live info is now incorrect.
2003               // Recompute live.
2004               must_recompute_live = true;

2254   return buf+strlen(buf);
2255 }
2256 
2257 void PhaseChaitin::dump_for_spill_split_recycle() const {
2258   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2259     // Display which live ranges need to be split and the allocator's state
2260     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2261     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2262       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2263         tty->print("L%d: ", bidx);
2264         lrgs(bidx).dump();
2265       }
2266     }
2267     tty->cr();
2268     dump();
2269   }
2270 }
2271 
2272 void PhaseChaitin::dump_frame() const {
2273   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2274   const TypeTuple *domain = C->tf()->domain();
2275   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2276 
2277   // Incoming arguments in registers dump
2278   for( int k = 0; k < argcnt; k++ ) {
2279     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2280     if( OptoReg::is_reg(parmreg))  {
2281       const char *reg_name = OptoReg::regname(parmreg);
2282       tty->print("#r%3.3d %s", parmreg, reg_name);
2283       parmreg = _matcher._parm_regs[k].second();
2284       if( OptoReg::is_reg(parmreg))  {
2285         tty->print(":%s", OptoReg::regname(parmreg));
2286       }
2287       tty->print("   : parm %d: ", k);
2288       domain->field_at(k + TypeFunc::Parms)->dump();
2289       tty->cr();
2290     }
2291   }
2292 
2293   // Check for un-owned padding above incoming args
2294   OptoReg::Name reg = _matcher._new_SP;

2463             // Check each derived/base pair
2464             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2465               Node* check = sfpt->in(idx);
2466               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2467               // search upwards through spills and spill phis for AddP
2468               worklist.clear();
2469               worklist.push(check);
2470               uint k = 0;
2471               while (k < worklist.size()) {
2472                 check = worklist.at(k);
2473                 assert(check, "Bad base or derived pointer");
2474                 // See PhaseChaitin::find_base_for_derived() for all cases.
2475                 int isc = check->is_Copy();
2476                 if (isc) {
2477                   worklist.push(check->in(isc));
2478                 } else if (check->is_Phi()) {
2479                   for (uint m = 1; m < check->req(); m++) {
2480                     worklist.push(check->in(m));
2481                   }
2482                 } else if (check->is_Con()) {
2483                   if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2484                     // Derived is null+non-zero offset, base must be null.
2485                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2486                   } else {
2487                     assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2488                     // Base either ConP(nullptr) or loadConP
2489                     if (check->is_Mach()) {
2490                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2491                     } else {
2492                       assert(check->Opcode() == Op_ConP &&
2493                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2494                     }
2495                   }
2496                 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2497                   if (check->is_Proj() || (check->is_Mach() &&
2498                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2499                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2500                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2501                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2502 #ifdef _LP64
2503                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2504                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2505                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2506 #endif // _LP64
2507                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2508                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2509                     // Valid nodes
2510                   } else {
2511                     check->dump();
2512                     assert(false, "Bad base or derived pointer");
2513                   }
2514                 } else {
2515                   assert(is_derived, "Bad base pointer");
2516                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");

1793   // See if already computed; if so return it
1794   if (derived_base_map[derived->_idx]) {
1795     return derived_base_map[derived->_idx];
1796   }
1797 
1798 #ifdef ASSERT
1799   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1800     // Bypass the verification node
1801     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1802     derived_base_map[derived->_idx] = base;
1803     return base;
1804   }
1805 #endif
1806 
1807   // See if this happens to be a base.
1808   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1809   // pointers derived from null!  These are always along paths that
1810   // can't happen at run-time but the optimizer cannot deduce it so
1811   // we have to handle it gracefully.
1812   assert(!derived->bottom_type()->isa_narrowoop() ||
1813          derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1814   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1815   // If its an OOP with a non-zero offset, then it is derived.
1816   if (tj == nullptr || tj->offset() == 0) {
1817     derived_base_map[derived->_idx] = derived;
1818     return derived;
1819   }
1820   // Derived is null+offset?  Base is null!
1821   if( derived->is_Con() ) {
1822     Node *base = _matcher.mach_null();
1823     assert(base != nullptr, "sanity");
1824     if (base->in(0) == nullptr) {
1825       // Initialize it once and make it shared:
1826       // set control to _root and place it into Start block
1827       // (where top() node is placed).
1828       base->init_req(0, _cfg.get_root_node());
1829       Block *startb = _cfg.get_block_for_node(C->top());
1830       uint node_pos = startb->find_node(C->top());
1831       startb->insert_node(base, node_pos);
1832       _cfg.map_node_to_block(base, startb);
1833       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1834 
1835       // The loadConP0 might have projection nodes depending on architecture
1836       // Add the projection nodes to the CFG

1962         // Copies do not define a new value and so do not interfere.
1963         // Remove the copies source from the liveout set before interfering.
1964         uint idx = n->is_Copy();
1965         if (idx) {
1966           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
1967         }
1968       }
1969 
1970       // Found a safepoint?
1971       JVMState *jvms = n->jvms();
1972       if (jvms && !liveout.is_empty()) {
1973         // Now scan for a live derived pointer
1974         IndexSetIterator elements(&liveout);
1975         uint neighbor;
1976         while ((neighbor = elements.next()) != 0) {
1977           // Find reaching DEF for base and derived values
1978           // This works because we are still in SSA during this call.
1979           Node *derived = lrgs(neighbor)._def;
1980           const TypePtr *tj = derived->bottom_type()->isa_ptr();
1981           assert(!derived->bottom_type()->isa_narrowoop() ||
1982                  derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1983           // If its an OOP with a non-zero offset, then it is derived.
1984           if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
1985             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
1986             assert(base->_idx < _lrg_map.size(), "");
1987             // Add reaching DEFs of derived pointer and base pointer as a
1988             // pair of inputs
1989             n->add_req(derived);
1990             n->add_req(base);
1991 
1992             // See if the base pointer is already live to this point.
1993             // Since I'm working on the SSA form, live-ness amounts to
1994             // reaching def's.  So if I find the base's live range then
1995             // I know the base's def reaches here.
1996             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
1997                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
1998                  (_lrg_map.live_range_id(base) > 0) && // not a constant
1999                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2000               // Base pointer is not currently live.  Since I stretched
2001               // the base pointer to here and it crosses basic-block
2002               // boundaries, the global live info is now incorrect.
2003               // Recompute live.
2004               must_recompute_live = true;

2254   return buf+strlen(buf);
2255 }
2256 
2257 void PhaseChaitin::dump_for_spill_split_recycle() const {
2258   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2259     // Display which live ranges need to be split and the allocator's state
2260     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2261     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2262       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2263         tty->print("L%d: ", bidx);
2264         lrgs(bidx).dump();
2265       }
2266     }
2267     tty->cr();
2268     dump();
2269   }
2270 }
2271 
2272 void PhaseChaitin::dump_frame() const {
2273   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2274   const TypeTuple *domain = C->tf()->domain_cc();
2275   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2276 
2277   // Incoming arguments in registers dump
2278   for( int k = 0; k < argcnt; k++ ) {
2279     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2280     if( OptoReg::is_reg(parmreg))  {
2281       const char *reg_name = OptoReg::regname(parmreg);
2282       tty->print("#r%3.3d %s", parmreg, reg_name);
2283       parmreg = _matcher._parm_regs[k].second();
2284       if( OptoReg::is_reg(parmreg))  {
2285         tty->print(":%s", OptoReg::regname(parmreg));
2286       }
2287       tty->print("   : parm %d: ", k);
2288       domain->field_at(k + TypeFunc::Parms)->dump();
2289       tty->cr();
2290     }
2291   }
2292 
2293   // Check for un-owned padding above incoming args
2294   OptoReg::Name reg = _matcher._new_SP;

2463             // Check each derived/base pair
2464             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2465               Node* check = sfpt->in(idx);
2466               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2467               // search upwards through spills and spill phis for AddP
2468               worklist.clear();
2469               worklist.push(check);
2470               uint k = 0;
2471               while (k < worklist.size()) {
2472                 check = worklist.at(k);
2473                 assert(check, "Bad base or derived pointer");
2474                 // See PhaseChaitin::find_base_for_derived() for all cases.
2475                 int isc = check->is_Copy();
2476                 if (isc) {
2477                   worklist.push(check->in(isc));
2478                 } else if (check->is_Phi()) {
2479                   for (uint m = 1; m < check->req(); m++) {
2480                     worklist.push(check->in(m));
2481                   }
2482                 } else if (check->is_Con()) {
2483                   if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2484                     // Derived is null+non-zero offset, base must be null.
2485                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2486                   } else {
2487                     assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2488                     // Base either ConP(nullptr) or loadConP
2489                     if (check->is_Mach()) {
2490                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2491                     } else {
2492                       assert(check->Opcode() == Op_ConP &&
2493                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2494                     }
2495                   }
2496                 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2497                   if (check->is_Proj() || (check->is_Mach() &&
2498                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2499                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2500                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2501                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2502 #ifdef _LP64
2503                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2504                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2505                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2506 #endif // _LP64
2507                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2508                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2509                     // Valid nodes
2510                   } else {
2511                     check->dump();
2512                     assert(false, "Bad base or derived pointer");
2513                   }
2514                 } else {
2515                   assert(is_derived, "Bad base pointer");
2516                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
< prev index next >