< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

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

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

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

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

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

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

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

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