< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

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

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

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

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

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

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

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

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