< prev index next >

src/hotspot/share/opto/chaitin.cpp

Print this page

1924   // See if already computed; if so return it
1925   if (derived_base_map[derived->_idx]) {
1926     return derived_base_map[derived->_idx];
1927   }
1928 
1929 #ifdef ASSERT
1930   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1931     // Bypass the verification node
1932     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1933     derived_base_map[derived->_idx] = base;
1934     return base;
1935   }
1936 #endif
1937 
1938   // See if this happens to be a base.
1939   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1940   // pointers derived from null!  These are always along paths that
1941   // can't happen at run-time but the optimizer cannot deduce it so
1942   // we have to handle it gracefully.
1943   assert(!derived->bottom_type()->isa_narrowoop() ||
1944           derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1945   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1946   // If its an OOP with a non-zero offset, then it is derived.
1947   if( tj == nullptr || tj->_offset == 0 ) {
1948     derived_base_map[derived->_idx] = derived;
1949     return derived;
1950   }
1951   // Derived is null+offset?  Base is null!
1952   if( derived->is_Con() ) {
1953     Node *base = _matcher.mach_null();
1954     assert(base != nullptr, "sanity");
1955     if (base->in(0) == nullptr) {
1956       // Initialize it once and make it shared:
1957       // set control to _root and place it into Start block
1958       // (where top() node is placed).
1959       base->init_req(0, _cfg.get_root_node());
1960       Block *startb = _cfg.get_block_for_node(C->top());
1961       uint node_pos = startb->find_node(C->top());
1962       startb->insert_node(base, node_pos);
1963       _cfg.map_node_to_block(base, startb);
1964       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1965 
1966       // The loadConP0 might have projection nodes depending on architecture
1967       // Add the projection nodes to the CFG

2093         // Copies do not define a new value and so do not interfere.
2094         // Remove the copies source from the liveout set before interfering.
2095         uint idx = n->is_Copy();
2096         if (idx) {
2097           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2098         }
2099       }
2100 
2101       // Found a safepoint?
2102       JVMState *jvms = n->jvms();
2103       if (jvms && !liveout.is_empty()) {
2104         // Now scan for a live derived pointer
2105         IndexSetIterator elements(&liveout);
2106         uint neighbor;
2107         while ((neighbor = elements.next()) != 0) {
2108           // Find reaching DEF for base and derived values
2109           // This works because we are still in SSA during this call.
2110           Node *derived = lrgs(neighbor)._def;
2111           const TypePtr *tj = derived->bottom_type()->isa_ptr();
2112           assert(!derived->bottom_type()->isa_narrowoop() ||
2113                   derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
2114           // If its an OOP with a non-zero offset, then it is derived.
2115           if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
2116             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2117             assert(base->_idx < _lrg_map.size(), "");
2118             // Add reaching DEFs of derived pointer and base pointer as a
2119             // pair of inputs
2120             n->add_req(derived);
2121             n->add_req(base);
2122 
2123             // See if the base pointer is already live to this point.
2124             // Since I'm working on the SSA form, live-ness amounts to
2125             // reaching def's.  So if I find the base's live range then
2126             // I know the base's def reaches here.
2127             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2128                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2129                  (_lrg_map.live_range_id(base) > 0) && // not a constant
2130                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2131               // Base pointer is not currently live.  Since I stretched
2132               // the base pointer to here and it crosses basic-block
2133               // boundaries, the global live info is now incorrect.
2134               // Recompute live.
2135               must_recompute_live = true;

2385   return buf+strlen(buf);
2386 }
2387 
2388 void PhaseChaitin::dump_for_spill_split_recycle() const {
2389   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2390     // Display which live ranges need to be split and the allocator's state
2391     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2392     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2393       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2394         tty->print("L%d: ", bidx);
2395         lrgs(bidx).dump();
2396       }
2397     }
2398     tty->cr();
2399     dump();
2400   }
2401 }
2402 
2403 void PhaseChaitin::dump_frame() const {
2404   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2405   const TypeTuple *domain = C->tf()->domain();
2406   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2407 
2408   // Incoming arguments in registers dump
2409   for( int k = 0; k < argcnt; k++ ) {
2410     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2411     if( OptoReg::is_reg(parmreg))  {
2412       const char *reg_name = OptoReg::regname(parmreg);
2413       tty->print("#r%3.3d %s", parmreg, reg_name);
2414       parmreg = _matcher._parm_regs[k].second();
2415       if( OptoReg::is_reg(parmreg))  {
2416         tty->print(":%s", OptoReg::regname(parmreg));
2417       }
2418       tty->print("   : parm %d: ", k);
2419       domain->field_at(k + TypeFunc::Parms)->dump();
2420       tty->cr();
2421     }
2422   }
2423 
2424   // Check for un-owned padding above incoming args
2425   OptoReg::Name reg = _matcher._new_SP;

2594             // Check each derived/base pair
2595             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2596               Node* check = sfpt->in(idx);
2597               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2598               // search upwards through spills and spill phis for AddP
2599               worklist.clear();
2600               worklist.push(check);
2601               uint k = 0;
2602               while (k < worklist.size()) {
2603                 check = worklist.at(k);
2604                 assert(check, "Bad base or derived pointer");
2605                 // See PhaseChaitin::find_base_for_derived() for all cases.
2606                 int isc = check->is_Copy();
2607                 if (isc) {
2608                   worklist.push(check->in(isc));
2609                 } else if (check->is_Phi()) {
2610                   for (uint m = 1; m < check->req(); m++) {
2611                     worklist.push(check->in(m));
2612                   }
2613                 } else if (check->is_Con()) {
2614                   if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2615                     // Derived is null+non-zero offset, base must be null.
2616                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2617                   } else {
2618                     assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2619                     // Base either ConP(nullptr) or loadConP
2620                     if (check->is_Mach()) {
2621                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2622                     } else {
2623                       assert(check->Opcode() == Op_ConP &&
2624                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2625                     }
2626                   }
2627                 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2628                   if (check->is_Proj() || (check->is_Mach() &&
2629                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2630                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2631                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2632                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2633 #ifdef _LP64
2634                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2635                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2636                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2637 #endif // _LP64
2638                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2639                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2640                     // Valid nodes
2641                   } else {
2642                     check->dump();
2643                     assert(false, "Bad base or derived pointer");
2644                   }
2645                 } else {
2646                   assert(is_derived, "Bad base pointer");
2647                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");

1924   // See if already computed; if so return it
1925   if (derived_base_map[derived->_idx]) {
1926     return derived_base_map[derived->_idx];
1927   }
1928 
1929 #ifdef ASSERT
1930   if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1931     // Bypass the verification node
1932     Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1933     derived_base_map[derived->_idx] = base;
1934     return base;
1935   }
1936 #endif
1937 
1938   // See if this happens to be a base.
1939   // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1940   // pointers derived from null!  These are always along paths that
1941   // can't happen at run-time but the optimizer cannot deduce it so
1942   // we have to handle it gracefully.
1943   assert(!derived->bottom_type()->isa_narrowoop() ||
1944          derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1945   const TypePtr *tj = derived->bottom_type()->isa_ptr();
1946   // If its an OOP with a non-zero offset, then it is derived.
1947   if (tj == nullptr || tj->offset() == 0) {
1948     derived_base_map[derived->_idx] = derived;
1949     return derived;
1950   }
1951   // Derived is null+offset?  Base is null!
1952   if( derived->is_Con() ) {
1953     Node *base = _matcher.mach_null();
1954     assert(base != nullptr, "sanity");
1955     if (base->in(0) == nullptr) {
1956       // Initialize it once and make it shared:
1957       // set control to _root and place it into Start block
1958       // (where top() node is placed).
1959       base->init_req(0, _cfg.get_root_node());
1960       Block *startb = _cfg.get_block_for_node(C->top());
1961       uint node_pos = startb->find_node(C->top());
1962       startb->insert_node(base, node_pos);
1963       _cfg.map_node_to_block(base, startb);
1964       assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1965 
1966       // The loadConP0 might have projection nodes depending on architecture
1967       // Add the projection nodes to the CFG

2093         // Copies do not define a new value and so do not interfere.
2094         // Remove the copies source from the liveout set before interfering.
2095         uint idx = n->is_Copy();
2096         if (idx) {
2097           liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2098         }
2099       }
2100 
2101       // Found a safepoint?
2102       JVMState *jvms = n->jvms();
2103       if (jvms && !liveout.is_empty()) {
2104         // Now scan for a live derived pointer
2105         IndexSetIterator elements(&liveout);
2106         uint neighbor;
2107         while ((neighbor = elements.next()) != 0) {
2108           // Find reaching DEF for base and derived values
2109           // This works because we are still in SSA during this call.
2110           Node *derived = lrgs(neighbor)._def;
2111           const TypePtr *tj = derived->bottom_type()->isa_ptr();
2112           assert(!derived->bottom_type()->isa_narrowoop() ||
2113                  derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
2114           // If its an OOP with a non-zero offset, then it is derived.
2115           if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
2116             Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2117             assert(base->_idx < _lrg_map.size(), "");
2118             // Add reaching DEFs of derived pointer and base pointer as a
2119             // pair of inputs
2120             n->add_req(derived);
2121             n->add_req(base);
2122 
2123             // See if the base pointer is already live to this point.
2124             // Since I'm working on the SSA form, live-ness amounts to
2125             // reaching def's.  So if I find the base's live range then
2126             // I know the base's def reaches here.
2127             if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2128                  !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2129                  (_lrg_map.live_range_id(base) > 0) && // not a constant
2130                  _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2131               // Base pointer is not currently live.  Since I stretched
2132               // the base pointer to here and it crosses basic-block
2133               // boundaries, the global live info is now incorrect.
2134               // Recompute live.
2135               must_recompute_live = true;

2385   return buf+strlen(buf);
2386 }
2387 
2388 void PhaseChaitin::dump_for_spill_split_recycle() const {
2389   if( WizardMode && (PrintCompilation || PrintOpto) ) {
2390     // Display which live ranges need to be split and the allocator's state
2391     tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2392     for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2393       if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2394         tty->print("L%d: ", bidx);
2395         lrgs(bidx).dump();
2396       }
2397     }
2398     tty->cr();
2399     dump();
2400   }
2401 }
2402 
2403 void PhaseChaitin::dump_frame() const {
2404   const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2405   const TypeTuple *domain = C->tf()->domain_cc();
2406   const int        argcnt = domain->cnt() - TypeFunc::Parms;
2407 
2408   // Incoming arguments in registers dump
2409   for( int k = 0; k < argcnt; k++ ) {
2410     OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2411     if( OptoReg::is_reg(parmreg))  {
2412       const char *reg_name = OptoReg::regname(parmreg);
2413       tty->print("#r%3.3d %s", parmreg, reg_name);
2414       parmreg = _matcher._parm_regs[k].second();
2415       if( OptoReg::is_reg(parmreg))  {
2416         tty->print(":%s", OptoReg::regname(parmreg));
2417       }
2418       tty->print("   : parm %d: ", k);
2419       domain->field_at(k + TypeFunc::Parms)->dump();
2420       tty->cr();
2421     }
2422   }
2423 
2424   // Check for un-owned padding above incoming args
2425   OptoReg::Name reg = _matcher._new_SP;

2594             // Check each derived/base pair
2595             for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2596               Node* check = sfpt->in(idx);
2597               bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2598               // search upwards through spills and spill phis for AddP
2599               worklist.clear();
2600               worklist.push(check);
2601               uint k = 0;
2602               while (k < worklist.size()) {
2603                 check = worklist.at(k);
2604                 assert(check, "Bad base or derived pointer");
2605                 // See PhaseChaitin::find_base_for_derived() for all cases.
2606                 int isc = check->is_Copy();
2607                 if (isc) {
2608                   worklist.push(check->in(isc));
2609                 } else if (check->is_Phi()) {
2610                   for (uint m = 1; m < check->req(); m++) {
2611                     worklist.push(check->in(m));
2612                   }
2613                 } else if (check->is_Con()) {
2614                   if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2615                     // Derived is null+non-zero offset, base must be null.
2616                     assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2617                   } else {
2618                     assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2619                     // Base either ConP(nullptr) or loadConP
2620                     if (check->is_Mach()) {
2621                       assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2622                     } else {
2623                       assert(check->Opcode() == Op_ConP &&
2624                              check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2625                     }
2626                   }
2627                 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2628                   if (check->is_Proj() || (check->is_Mach() &&
2629                      (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2630                       check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2631                       check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2632                       check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2633 #ifdef _LP64
2634                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2635                       (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2636                       (UseCompressedClassPointers && check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2637 #endif // _LP64
2638                       check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2639                       check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2640                     // Valid nodes
2641                   } else {
2642                     check->dump();
2643                     assert(false, "Bad base or derived pointer");
2644                   }
2645                 } else {
2646                   assert(is_derived, "Bad base pointer");
2647                   assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
< prev index next >