< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

1866   // See if already computed; if so return it
1867   if (derived_base_map[derived->_idx]) {
1868     return derived_base_map[derived->_idx];
1869   }
1870 
1871 #ifdef ASSERT
1872   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1873     // Bypass the verification node
1874     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1875     derived_base_map[derived->_idx] = base;
1876     return base;
1877   }
1878 #endif
1879 
1880   // See if this happens to be a base.
1881   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1882   // pointers derived from null!  These are always along paths that
1883   // can't happen at run-time but the optimizer cannot deduce it so
1884   // we have to handle it gracefully.
1885   assert(!derived->bottom_type()->isa_narrowoop() ||
1886           derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1887   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1888   // If its an OOP with a non-zero offset, then it is derived.
1889   if( tj == nullptr || tj->_offset == 0 ) {
1890     derived_base_map[derived->_idx] = derived;
1891     return derived;
1892   }
1893   // Derived is null+offset?  Base is null!
1894   if( derived->is_Con() ) {
1895     Node *base = _matcher.mach_null();
1896     assert(base != nullptr, "sanity");
1897     if (base->in(0) == nullptr) {
1898       // Initialize it once and make it shared:
1899       // set control to _root and place it into Start block
1900       // (where top() node is placed).
1901       base->init_req(0, _cfg.get_root_node());
1902       Block *startb = _cfg.get_block_for_node(C->top());
1903       uint node_pos = startb->find_node(C->top());
1904       startb->insert_node(base, node_pos);
1905       _cfg.map_node_to_block(base, startb);
1906       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1907 
1908       // The loadConP0 might have projection nodes depending on architecture
1909       // Add the projection nodes to the CFG

2035         // Copies do not define a new value and so do not interfere.
2036         // Remove the copies source from the liveout set before interfering.
2037         uint idx = n->is_Copy();
2038         if (idx) {
2039           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2040         }
2041       }
2042 
2043       // Found a safepoint?
2044       JVMState *jvms = n->jvms();
2045       if (jvms && !liveout.is_empty()) {
2046         // Now scan for a live derived pointer
2047         IndexSetIterator elements(&liveout);
2048         uint neighbor;
2049         while ((neighbor = elements.next()) != 0) {
2050           // Find reaching DEF for base and derived values
2051           // This works because we are still in SSA during this call.
2052           Node *derived = lrgs(neighbor)._def;
2053           const TypePtr *tj = derived->bottom_type()->isa_ptr();
2054           assert(!derived->bottom_type()->isa_narrowoop() ||
2055                   derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
2056           // If its an OOP with a non-zero offset, then it is derived.
2057           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
2058             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2059             assert(base->_idx < _lrg_map.size(), "");
2060             // Add reaching DEFs of derived pointer and base pointer as a
2061             // pair of inputs
2062             n->add_req(derived);
2063             n->add_req(base);
2064 
2065             // See if the base pointer is already live to this point.
2066             // Since I'm working on the SSA form, live-ness amounts to
2067             // reaching def's.  So if I find the base's live range then
2068             // I know the base's def reaches here.
2069             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2070                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2071                  (_lrg_map.live_range_id(base) > 0) && // not a constant
2072                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2073               // Base pointer is not currently live.  Since I stretched
2074               // the base pointer to here and it crosses basic-block
2075               // boundaries, the global live info is now incorrect.
2076               // Recompute live.
2077               must_recompute_live = true;

2327   return buf+strlen(buf);
2328 }
2329 
2330 void PhaseChaitin::dump_for_spill_split_recycle() const {
2331   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2332     // Display which live ranges need to be split and the allocator's state
2333     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2334     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2335       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2336         tty->print("L%d: ", bidx);
2337         lrgs(bidx).dump();
2338       }
2339     }
2340     tty->cr();
2341     dump();
2342   }
2343 }
2344 
2345 void PhaseChaitin::dump_frame() const {
2346   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2347   const TypeTuple *domain = C->tf()->domain();
2348   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2349 
2350   // Incoming arguments in registers dump
2351   for( int k = 0; k < argcnt; k++ ) {
2352     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2353     if( OptoReg::is_reg(parmreg))  {
2354       const char *reg_name = OptoReg::regname(parmreg);
2355       tty->print("#r%3.3d %s", parmreg, reg_name);
2356       parmreg = _matcher._parm_regs[k].second();
2357       if( OptoReg::is_reg(parmreg))  {
2358         tty->print(":%s", OptoReg::regname(parmreg));
2359       }
2360       tty->print("   : parm %d: ", k);
2361       domain->field_at(k + TypeFunc::Parms)->dump();
2362       tty->cr();
2363     }
2364   }
2365 
2366   // Check for un-owned padding above incoming args
2367   OptoReg::Name reg = _matcher._new_SP;

2536             // Check each derived/base pair
2537             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2538               Node* check = sfpt->in(idx);
2539               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2540               // search upwards through spills and spill phis for AddP
2541               worklist.clear();
2542               worklist.push(check);
2543               uint k = 0;
2544               while (k < worklist.size()) {
2545                 check = worklist.at(k);
2546                 assert(check, "Bad base or derived pointer");
2547                 // See PhaseChaitin::find_base_for_derived() for all cases.
2548                 int isc = check->is_Copy();
2549                 if (isc) {
2550                   worklist.push(check->in(isc));
2551                 } else if (check->is_Phi()) {
2552                   for (uint m = 1; m < check->req(); m++) {
2553                     worklist.push(check->in(m));
2554                   }
2555                 } else if (check->is_Con()) {
2556                   if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2557                     // Derived is null+non-zero offset, base must be null.
2558                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2559                   } else {
2560                     assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2561                     // Base either ConP(nullptr) or loadConP
2562                     if (check->is_Mach()) {
2563                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2564                     } else {
2565                       assert(check->Opcode() == Op_ConP &&
2566                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2567                     }
2568                   }
2569                 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2570                   if (check->is_Proj() || (check->is_Mach() &&
2571                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2572                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2573                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2574                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2575 #ifdef _LP64
2576                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2577                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2578                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2579 #endif // _LP64
2580                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2581                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2582                     // Valid nodes
2583                   } else {
2584                     check->dump();
2585                     assert(false, "Bad base or derived pointer");
2586                   }
2587                 } else {
2588                   assert(is_derived, "Bad base pointer");
2589                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");

1866   // See if already computed; if so return it
1867   if (derived_base_map[derived->_idx]) {
1868     return derived_base_map[derived->_idx];
1869   }
1870 
1871 #ifdef ASSERT
1872   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1873     // Bypass the verification node
1874     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1875     derived_base_map[derived->_idx] = base;
1876     return base;
1877   }
1878 #endif
1879 
1880   // See if this happens to be a base.
1881   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1882   // pointers derived from null!  These are always along paths that
1883   // can't happen at run-time but the optimizer cannot deduce it so
1884   // we have to handle it gracefully.
1885   assert(!derived->bottom_type()->isa_narrowoop() ||
1886          derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1887   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1888   // If its an OOP with a non-zero offset, then it is derived.
1889   if (tj == nullptr || tj->offset() == 0) {
1890     derived_base_map[derived->_idx] = derived;
1891     return derived;
1892   }
1893   // Derived is null+offset?  Base is null!
1894   if( derived->is_Con() ) {
1895     Node *base = _matcher.mach_null();
1896     assert(base != nullptr, "sanity");
1897     if (base->in(0) == nullptr) {
1898       // Initialize it once and make it shared:
1899       // set control to _root and place it into Start block
1900       // (where top() node is placed).
1901       base->init_req(0, _cfg.get_root_node());
1902       Block *startb = _cfg.get_block_for_node(C->top());
1903       uint node_pos = startb->find_node(C->top());
1904       startb->insert_node(base, node_pos);
1905       _cfg.map_node_to_block(base, startb);
1906       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1907 
1908       // The loadConP0 might have projection nodes depending on architecture
1909       // Add the projection nodes to the CFG

2035         // Copies do not define a new value and so do not interfere.
2036         // Remove the copies source from the liveout set before interfering.
2037         uint idx = n->is_Copy();
2038         if (idx) {
2039           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2040         }
2041       }
2042 
2043       // Found a safepoint?
2044       JVMState *jvms = n->jvms();
2045       if (jvms && !liveout.is_empty()) {
2046         // Now scan for a live derived pointer
2047         IndexSetIterator elements(&liveout);
2048         uint neighbor;
2049         while ((neighbor = elements.next()) != 0) {
2050           // Find reaching DEF for base and derived values
2051           // This works because we are still in SSA during this call.
2052           Node *derived = lrgs(neighbor)._def;
2053           const TypePtr *tj = derived->bottom_type()->isa_ptr();
2054           assert(!derived->bottom_type()->isa_narrowoop() ||
2055                  derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
2056           // If its an OOP with a non-zero offset, then it is derived.
2057           if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
2058             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2059             assert(base->_idx < _lrg_map.size(), "");
2060             // Add reaching DEFs of derived pointer and base pointer as a
2061             // pair of inputs
2062             n->add_req(derived);
2063             n->add_req(base);
2064 
2065             // See if the base pointer is already live to this point.
2066             // Since I'm working on the SSA form, live-ness amounts to
2067             // reaching def's.  So if I find the base's live range then
2068             // I know the base's def reaches here.
2069             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2070                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2071                  (_lrg_map.live_range_id(base) > 0) && // not a constant
2072                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2073               // Base pointer is not currently live.  Since I stretched
2074               // the base pointer to here and it crosses basic-block
2075               // boundaries, the global live info is now incorrect.
2076               // Recompute live.
2077               must_recompute_live = true;

2327   return buf+strlen(buf);
2328 }
2329 
2330 void PhaseChaitin::dump_for_spill_split_recycle() const {
2331   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2332     // Display which live ranges need to be split and the allocator's state
2333     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2334     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2335       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2336         tty->print("L%d: ", bidx);
2337         lrgs(bidx).dump();
2338       }
2339     }
2340     tty->cr();
2341     dump();
2342   }
2343 }
2344 
2345 void PhaseChaitin::dump_frame() const {
2346   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2347   const TypeTuple *domain = C->tf()->domain_cc();
2348   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2349 
2350   // Incoming arguments in registers dump
2351   for( int k = 0; k < argcnt; k++ ) {
2352     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2353     if( OptoReg::is_reg(parmreg))  {
2354       const char *reg_name = OptoReg::regname(parmreg);
2355       tty->print("#r%3.3d %s", parmreg, reg_name);
2356       parmreg = _matcher._parm_regs[k].second();
2357       if( OptoReg::is_reg(parmreg))  {
2358         tty->print(":%s", OptoReg::regname(parmreg));
2359       }
2360       tty->print("   : parm %d: ", k);
2361       domain->field_at(k + TypeFunc::Parms)->dump();
2362       tty->cr();
2363     }
2364   }
2365 
2366   // Check for un-owned padding above incoming args
2367   OptoReg::Name reg = _matcher._new_SP;

2536             // Check each derived/base pair
2537             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2538               Node* check = sfpt->in(idx);
2539               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2540               // search upwards through spills and spill phis for AddP
2541               worklist.clear();
2542               worklist.push(check);
2543               uint k = 0;
2544               while (k < worklist.size()) {
2545                 check = worklist.at(k);
2546                 assert(check, "Bad base or derived pointer");
2547                 // See PhaseChaitin::find_base_for_derived() for all cases.
2548                 int isc = check->is_Copy();
2549                 if (isc) {
2550                   worklist.push(check->in(isc));
2551                 } else if (check->is_Phi()) {
2552                   for (uint m = 1; m < check->req(); m++) {
2553                     worklist.push(check->in(m));
2554                   }
2555                 } else if (check->is_Con()) {
2556                   if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2557                     // Derived is null+non-zero offset, base must be null.
2558                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2559                   } else {
2560                     assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2561                     // Base either ConP(nullptr) or loadConP
2562                     if (check->is_Mach()) {
2563                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2564                     } else {
2565                       assert(check->Opcode() == Op_ConP &&
2566                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2567                     }
2568                   }
2569                 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2570                   if (check->is_Proj() || (check->is_Mach() &&
2571                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2572                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2573                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2574                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2575 #ifdef _LP64
2576                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2577                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2578                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2579 #endif // _LP64
2580                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2581                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2582                     // Valid nodes
2583                   } else {
2584                     check->dump();
2585                     assert(false, "Bad base or derived pointer");
2586                   }
2587                 } else {
2588                   assert(is_derived, "Bad base pointer");
2589                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
< prev index next >