src/share/vm/opto/memnode.cpp

changeset 598
885ed790ecf0
parent 590
723be81c1212
child 599
c436414a719e
     1.1 --- a/src/share/vm/opto/memnode.cpp	Tue May 20 06:32:58 2008 -0700
     1.2 +++ b/src/share/vm/opto/memnode.cpp	Wed May 21 10:45:07 2008 -0700
     1.3 @@ -133,7 +133,9 @@
     1.4      PhiNode *mphi = result->as_Phi();
     1.5      assert(mphi->bottom_type() == Type::MEMORY, "memory phi required");
     1.6      const TypePtr *t = mphi->adr_type();
     1.7 -    if (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM) {
     1.8 +    if (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||
     1.9 +        t->isa_oopptr() && !t->is_oopptr()->is_instance() &&
    1.10 +        t->is_oopptr()->cast_to_instance(t_oop->instance_id()) == t_oop) {
    1.11        // clone the Phi with our address type
    1.12        result = mphi->split_out_instance(t_adr, igvn);
    1.13      } else {
    1.14 @@ -263,7 +265,10 @@
    1.15    // of all its inputs dominate or equal to sub's control edge.
    1.16  
    1.17    // Currently 'sub' is either Allocate, Initialize or Start nodes.
    1.18 -  assert(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start(), "expecting only these nodes");
    1.19 +  // Or Region for the check in LoadNode::Ideal();
    1.20 +  // 'sub' should have sub->in(0) != NULL.
    1.21 +  assert(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() ||
    1.22 +         sub->is_Region(), "expecting only these nodes");
    1.23  
    1.24    // Get control edge of 'sub'.
    1.25    sub = sub->find_exact_control(sub->in(0));
    1.26 @@ -576,6 +581,9 @@
    1.27  // Find any cast-away of null-ness and keep its control.  Null cast-aways are
    1.28  // going away in this pass and we need to make this memory op depend on the
    1.29  // gating null check.
    1.30 +Node *MemNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
    1.31 +  return Ideal_common_DU_postCCP(ccp, this, in(MemNode::Address));
    1.32 +}
    1.33  
    1.34  // I tried to leave the CastPP's in.  This makes the graph more accurate in
    1.35  // some sense; we get to keep around the knowledge that an oop is not-null
    1.36 @@ -585,15 +593,14 @@
    1.37  // some of the more trivial cases in the optimizer.  Removing more useless
    1.38  // Phi's started allowing Loads to illegally float above null checks.  I gave
    1.39  // up on this approach.  CNC 10/20/2000
    1.40 -Node *MemNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
    1.41 -  Node *ctr = in(MemNode::Control);
    1.42 -  Node *mem = in(MemNode::Memory);
    1.43 -  Node *adr = in(MemNode::Address);
    1.44 +// This static method may be called not from MemNode (EncodePNode calls it).
    1.45 +// Only the control edge of the node 'n' might be updated.
    1.46 +Node *MemNode::Ideal_common_DU_postCCP( PhaseCCP *ccp, Node* n, Node* adr ) {
    1.47    Node *skipped_cast = NULL;
    1.48    // Need a null check?  Regular static accesses do not because they are
    1.49    // from constant addresses.  Array ops are gated by the range check (which
    1.50    // always includes a NULL check).  Just check field ops.
    1.51 -  if( !ctr ) {
    1.52 +  if( n->in(MemNode::Control) == NULL ) {
    1.53      // Scan upwards for the highest location we can place this memory op.
    1.54      while( true ) {
    1.55        switch( adr->Opcode() ) {
    1.56 @@ -618,10 +625,10 @@
    1.57          }
    1.58          // CastPP is going away in this pass!  We need this memory op to be
    1.59          // control-dependent on the test that is guarding the CastPP.
    1.60 -        ccp->hash_delete(this);
    1.61 -        set_req(MemNode::Control, adr->in(0));
    1.62 -        ccp->hash_insert(this);
    1.63 -        return this;
    1.64 +        ccp->hash_delete(n);
    1.65 +        n->set_req(MemNode::Control, adr->in(0));
    1.66 +        ccp->hash_insert(n);
    1.67 +        return n;
    1.68  
    1.69        case Op_Phi:
    1.70          // Attempt to float above a Phi to some dominating point.
    1.71 @@ -652,10 +659,10 @@
    1.72            adr = adr->in(1);
    1.73            continue;
    1.74          }
    1.75 -        ccp->hash_delete(this);
    1.76 -        set_req(MemNode::Control, adr->in(0));
    1.77 -        ccp->hash_insert(this);
    1.78 -        return this;
    1.79 +        ccp->hash_delete(n);
    1.80 +        n->set_req(MemNode::Control, adr->in(0));
    1.81 +        ccp->hash_insert(n);
    1.82 +        return n;
    1.83  
    1.84          // List of "safe" opcodes; those that implicitly block the memory
    1.85          // op below any null check.
    1.86 @@ -665,6 +672,7 @@
    1.87        case Op_LoadN:            // Loading from within a klass
    1.88        case Op_LoadKlass:        // Loading from within a klass
    1.89        case Op_ConP:             // Loading from a klass
    1.90 +      case Op_ConN:             // Loading from a klass
    1.91        case Op_CreateEx:         // Sucking up the guts of an exception oop
    1.92        case Op_Con:              // Reading from TLS
    1.93        case Op_CMoveP:           // CMoveP is pinned
    1.94 @@ -676,8 +684,8 @@
    1.95          {
    1.96            assert(adr->as_Proj()->_con == TypeFunc::Parms, "must be return value");
    1.97            const Node* call = adr->in(0);
    1.98 -          if (call->is_CallStaticJava()) {
    1.99 -            const CallStaticJavaNode* call_java = call->as_CallStaticJava();
   1.100 +          if (call->is_CallJava()) {
   1.101 +            const CallJavaNode* call_java = call->as_CallJava();
   1.102              const TypeTuple *r = call_java->tf()->range();
   1.103              assert(r->cnt() > TypeFunc::Parms, "must return value");
   1.104              const Type* ret_type = r->field_at(TypeFunc::Parms);
   1.105 @@ -749,7 +757,7 @@
   1.106    case T_ADDRESS: return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr()    );
   1.107    case T_OBJECT:
   1.108  #ifdef _LP64
   1.109 -    if (adr->bottom_type()->is_narrow()) {
   1.110 +    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
   1.111        const TypeNarrowOop* narrowtype;
   1.112        if (rt->isa_narrowoop()) {
   1.113          narrowtype = rt->is_narrowoop();
   1.114 @@ -761,10 +769,10 @@
   1.115        return DecodeNNode::decode(&gvn, load);
   1.116      } else
   1.117  #endif
   1.118 -      {
   1.119 -        assert(!adr->bottom_type()->is_narrow(), "should have got back a narrow oop");
   1.120 -        return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_oopptr());
   1.121 -      }
   1.122 +    {
   1.123 +      assert(!adr->bottom_type()->is_ptr_to_narrowoop(), "should have got back a narrow oop");
   1.124 +      return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_oopptr());
   1.125 +    }
   1.126    }
   1.127    ShouldNotReachHere();
   1.128    return (LoadNode*)NULL;
   1.129 @@ -1118,6 +1126,127 @@
   1.130    return NULL;
   1.131  }
   1.132  
   1.133 +//------------------------------split_through_phi------------------------------
   1.134 +// Split instance field load through Phi.
   1.135 +Node *LoadNode::split_through_phi(PhaseGVN *phase) {
   1.136 +  Node* mem     = in(MemNode::Memory);
   1.137 +  Node* address = in(MemNode::Address);
   1.138 +  const TypePtr *addr_t = phase->type(address)->isa_ptr();
   1.139 +  const TypeOopPtr *t_oop = addr_t->isa_oopptr();
   1.140 +
   1.141 +  assert(mem->is_Phi() && (t_oop != NULL) &&
   1.142 +         t_oop->is_instance_field(), "invalide conditions");
   1.143 +
   1.144 +  Node *region = mem->in(0);
   1.145 +  if (region == NULL) {
   1.146 +    return NULL; // Wait stable graph
   1.147 +  }
   1.148 +  uint cnt = mem->req();
   1.149 +  for( uint i = 1; i < cnt; i++ ) {
   1.150 +    Node *in = mem->in(i);
   1.151 +    if( in == NULL ) {
   1.152 +      return NULL; // Wait stable graph
   1.153 +    }
   1.154 +  }
   1.155 +  // Check for loop invariant.
   1.156 +  if (cnt == 3) {
   1.157 +    for( uint i = 1; i < cnt; i++ ) {
   1.158 +      Node *in = mem->in(i);
   1.159 +      Node* m = MemNode::optimize_memory_chain(in, addr_t, phase);
   1.160 +      if (m == mem) {
   1.161 +        set_req(MemNode::Memory, mem->in(cnt - i)); // Skip this phi.
   1.162 +        return this;
   1.163 +      }
   1.164 +    }
   1.165 +  }
   1.166 +  // Split through Phi (see original code in loopopts.cpp).
   1.167 +  assert(phase->C->have_alias_type(addr_t), "instance should have alias type");
   1.168 +
   1.169 +  // Do nothing here if Identity will find a value
   1.170 +  // (to avoid infinite chain of value phis generation).
   1.171 +  if ( !phase->eqv(this, this->Identity(phase)) )
   1.172 +    return NULL;
   1.173 +
   1.174 +  // Skip the split if the region dominates some control edge of the address.
   1.175 +  if (cnt == 3 && !MemNode::all_controls_dominate(address, region))
   1.176 +    return NULL;
   1.177 +
   1.178 +  const Type* this_type = this->bottom_type();
   1.179 +  int this_index  = phase->C->get_alias_index(addr_t);
   1.180 +  int this_offset = addr_t->offset();
   1.181 +  int this_iid    = addr_t->is_oopptr()->instance_id();
   1.182 +  int wins = 0;
   1.183 +  PhaseIterGVN *igvn = phase->is_IterGVN();
   1.184 +  Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset);
   1.185 +  for( uint i = 1; i < region->req(); i++ ) {
   1.186 +    Node *x;
   1.187 +    Node* the_clone = NULL;
   1.188 +    if( region->in(i) == phase->C->top() ) {
   1.189 +      x = phase->C->top();      // Dead path?  Use a dead data op
   1.190 +    } else {
   1.191 +      x = this->clone();        // Else clone up the data op
   1.192 +      the_clone = x;            // Remember for possible deletion.
   1.193 +      // Alter data node to use pre-phi inputs
   1.194 +      if( this->in(0) == region ) {
   1.195 +        x->set_req( 0, region->in(i) );
   1.196 +      } else {
   1.197 +        x->set_req( 0, NULL );
   1.198 +      }
   1.199 +      for( uint j = 1; j < this->req(); j++ ) {
   1.200 +        Node *in = this->in(j);
   1.201 +        if( in->is_Phi() && in->in(0) == region )
   1.202 +          x->set_req( j, in->in(i) ); // Use pre-Phi input for the clone
   1.203 +      }
   1.204 +    }
   1.205 +    // Check for a 'win' on some paths
   1.206 +    const Type *t = x->Value(igvn);
   1.207 +
   1.208 +    bool singleton = t->singleton();
   1.209 +
   1.210 +    // See comments in PhaseIdealLoop::split_thru_phi().
   1.211 +    if( singleton && t == Type::TOP ) {
   1.212 +      singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
   1.213 +    }
   1.214 +
   1.215 +    if( singleton ) {
   1.216 +      wins++;
   1.217 +      x = igvn->makecon(t);
   1.218 +    } else {
   1.219 +      // We now call Identity to try to simplify the cloned node.
   1.220 +      // Note that some Identity methods call phase->type(this).
   1.221 +      // Make sure that the type array is big enough for
   1.222 +      // our new node, even though we may throw the node away.
   1.223 +      // (This tweaking with igvn only works because x is a new node.)
   1.224 +      igvn->set_type(x, t);
   1.225 +      Node *y = x->Identity(igvn);
   1.226 +      if( y != x ) {
   1.227 +        wins++;
   1.228 +        x = y;
   1.229 +      } else {
   1.230 +        y = igvn->hash_find(x);
   1.231 +        if( y ) {
   1.232 +          wins++;
   1.233 +          x = y;
   1.234 +        } else {
   1.235 +          // Else x is a new node we are keeping
   1.236 +          // We do not need register_new_node_with_optimizer
   1.237 +          // because set_type has already been called.
   1.238 +          igvn->_worklist.push(x);
   1.239 +        }
   1.240 +      }
   1.241 +    }
   1.242 +    if (x != the_clone && the_clone != NULL)
   1.243 +      igvn->remove_dead_node(the_clone);
   1.244 +    phi->set_req(i, x);
   1.245 +  }
   1.246 +  if( wins > 0 ) {
   1.247 +    // Record Phi
   1.248 +    igvn->register_new_node_with_optimizer(phi);
   1.249 +    return phi;
   1.250 +  }
   1.251 +  igvn->remove_dead_node(phi);
   1.252 +  return NULL;
   1.253 +}
   1.254  
   1.255  //------------------------------Ideal------------------------------------------
   1.256  // If the load is from Field memory and the pointer is non-null, we can
   1.257 @@ -1175,112 +1304,9 @@
   1.258      const TypeOopPtr *t_oop = addr_t->isa_oopptr();
   1.259      if (can_reshape && opt_mem->is_Phi() &&
   1.260          (t_oop != NULL) && t_oop->is_instance_field()) {
   1.261 -      assert(t_oop->offset() != Type::OffsetBot && t_oop->offset() != Type::OffsetTop, "");
   1.262 -      Node *region = opt_mem->in(0);
   1.263 -      uint cnt = opt_mem->req();
   1.264 -      for( uint i = 1; i < cnt; i++ ) {
   1.265 -        Node *in = opt_mem->in(i);
   1.266 -        if( in == NULL ) {
   1.267 -          region = NULL; // Wait stable graph
   1.268 -          break;
   1.269 -        }
   1.270 -      }
   1.271 -      if (region != NULL) {
   1.272 -        // Check for loop invariant.
   1.273 -        if (cnt == 3) {
   1.274 -          for( uint i = 1; i < cnt; i++ ) {
   1.275 -            Node *in = opt_mem->in(i);
   1.276 -            Node* m = MemNode::optimize_memory_chain(in, addr_t, phase);
   1.277 -            if (m == opt_mem) {
   1.278 -              set_req(MemNode::Memory, opt_mem->in(cnt - i)); // Skip this phi.
   1.279 -              return this;
   1.280 -            }
   1.281 -          }
   1.282 -        }
   1.283 -        // Split through Phi (see original code in loopopts.cpp).
   1.284 -        assert(phase->C->have_alias_type(addr_t), "instance should have alias type");
   1.285 -
   1.286 -        // Do nothing here if Identity will find a value
   1.287 -        // (to avoid infinite chain of value phis generation).
   1.288 -        if ( !phase->eqv(this, this->Identity(phase)) )
   1.289 -          return NULL;
   1.290 -
   1.291 -        const Type* this_type = this->bottom_type();
   1.292 -        int this_index  = phase->C->get_alias_index(addr_t);
   1.293 -        int this_offset = addr_t->offset();
   1.294 -        int this_iid    = addr_t->is_oopptr()->instance_id();
   1.295 -        int wins = 0;
   1.296 -        PhaseIterGVN *igvn = phase->is_IterGVN();
   1.297 -        Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset);
   1.298 -        for( uint i = 1; i < region->req(); i++ ) {
   1.299 -          Node *x;
   1.300 -          Node* the_clone = NULL;
   1.301 -          if( region->in(i) == phase->C->top() ) {
   1.302 -            x = phase->C->top();      // Dead path?  Use a dead data op
   1.303 -          } else {
   1.304 -            x = this->clone();        // Else clone up the data op
   1.305 -            the_clone = x;            // Remember for possible deletion.
   1.306 -            // Alter data node to use pre-phi inputs
   1.307 -            if( this->in(0) == region ) {
   1.308 -              x->set_req( 0, region->in(i) );
   1.309 -            } else {
   1.310 -              x->set_req( 0, NULL );
   1.311 -            }
   1.312 -            for( uint j = 1; j < this->req(); j++ ) {
   1.313 -              Node *in = this->in(j);
   1.314 -              if( in->is_Phi() && in->in(0) == region )
   1.315 -                x->set_req( j, in->in(i) ); // Use pre-Phi input for the clone
   1.316 -            }
   1.317 -          }
   1.318 -          // Check for a 'win' on some paths
   1.319 -          const Type *t = x->Value(igvn);
   1.320 -
   1.321 -          bool singleton = t->singleton();
   1.322 -
   1.323 -          // See comments in PhaseIdealLoop::split_thru_phi().
   1.324 -          if( singleton && t == Type::TOP ) {
   1.325 -            singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
   1.326 -          }
   1.327 -
   1.328 -          if( singleton ) {
   1.329 -            wins++;
   1.330 -            x = igvn->makecon(t);
   1.331 -          } else {
   1.332 -            // We now call Identity to try to simplify the cloned node.
   1.333 -            // Note that some Identity methods call phase->type(this).
   1.334 -            // Make sure that the type array is big enough for
   1.335 -            // our new node, even though we may throw the node away.
   1.336 -            // (This tweaking with igvn only works because x is a new node.)
   1.337 -            igvn->set_type(x, t);
   1.338 -            Node *y = x->Identity(igvn);
   1.339 -            if( y != x ) {
   1.340 -              wins++;
   1.341 -              x = y;
   1.342 -            } else {
   1.343 -              y = igvn->hash_find(x);
   1.344 -              if( y ) {
   1.345 -                wins++;
   1.346 -                x = y;
   1.347 -              } else {
   1.348 -                // Else x is a new node we are keeping
   1.349 -                // We do not need register_new_node_with_optimizer
   1.350 -                // because set_type has already been called.
   1.351 -                igvn->_worklist.push(x);
   1.352 -              }
   1.353 -            }
   1.354 -          }
   1.355 -          if (x != the_clone && the_clone != NULL)
   1.356 -            igvn->remove_dead_node(the_clone);
   1.357 -          phi->set_req(i, x);
   1.358 -        }
   1.359 -        if( wins > 0 ) {
   1.360 -          // Record Phi
   1.361 -          igvn->register_new_node_with_optimizer(phi);
   1.362 -          return phi;
   1.363 -        } else {
   1.364 -          igvn->remove_dead_node(phi);
   1.365 -        }
   1.366 -      }
   1.367 +      // Split instance field load through Phi.
   1.368 +      Node* result = split_through_phi(phase);
   1.369 +      if (result != NULL) return result;
   1.370      }
   1.371    }
   1.372  
   1.373 @@ -1835,7 +1861,7 @@
   1.374    case T_ADDRESS:
   1.375    case T_OBJECT:
   1.376  #ifdef _LP64
   1.377 -    if (adr->bottom_type()->is_narrow() ||
   1.378 +    if (adr->bottom_type()->is_ptr_to_narrowoop() ||
   1.379          (UseCompressedOops && val->bottom_type()->isa_klassptr() &&
   1.380           adr->bottom_type()->isa_rawptr())) {
   1.381        const TypePtr* type = val->bottom_type()->is_ptr();

mercurial