src/share/vm/opto/memnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6695810 Sdiff src/share/vm/opto

src/share/vm/opto/memnode.cpp

Print this page




 116       } else if (proj_in->is_MemBar()) {
 117         result = proj_in->in(TypeFunc::Memory);
 118       }
 119     } else if (result->is_MergeMem()) {
 120       result = step_through_mergemem(phase, result->as_MergeMem(), t_adr, NULL, tty);
 121     }
 122   }
 123   return result;
 124 }
 125 
 126 Node *MemNode::optimize_memory_chain(Node *mchain, const TypePtr *t_adr, PhaseGVN *phase) {
 127   const TypeOopPtr *t_oop = t_adr->isa_oopptr();
 128   bool is_instance = (t_oop != NULL) && t_oop->is_instance_field();
 129   PhaseIterGVN *igvn = phase->is_IterGVN();
 130   Node *result = mchain;
 131   result = optimize_simple_memory_chain(result, t_adr, phase);
 132   if (is_instance && igvn != NULL  && result->is_Phi()) {
 133     PhiNode *mphi = result->as_Phi();
 134     assert(mphi->bottom_type() == Type::MEMORY, "memory phi required");
 135     const TypePtr *t = mphi->adr_type();
 136     if (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM) {


 137       // clone the Phi with our address type
 138       result = mphi->split_out_instance(t_adr, igvn);
 139     } else {
 140       assert(phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr), "correct memory chain");
 141     }
 142   }
 143   return result;
 144 }
 145 
 146 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st) {
 147   uint alias_idx = phase->C->get_alias_index(tp);
 148   Node *mem = mmem;
 149 #ifdef ASSERT
 150   {
 151     // Check that current type is consistent with the alias index used during graph construction
 152     assert(alias_idx >= Compile::AliasIdxRaw, "must not be a bad alias_idx");
 153     bool consistent =  adr_check == NULL || adr_check->empty() ||
 154                        phase->C->must_alias(adr_check, alias_idx );
 155     // Sometimes dead array references collapse to a[-1], a[-2], or a[-3]
 156     if( !consistent && adr_check != NULL && !adr_check->empty() &&


 246 // is not a constant (dominated by the method's StartNode).
 247 // Used by MemNode::find_previous_store to prove that the
 248 // control input of a memory operation predates (dominates)
 249 // an allocation it wants to look past.
 250 bool MemNode::all_controls_dominate(Node* dom, Node* sub) {
 251   if (dom == NULL || dom->is_top() || sub == NULL || sub->is_top())
 252     return false; // Conservative answer for dead code
 253 
 254   // Check 'dom'.
 255   dom = dom->find_exact_control(dom);
 256   if (dom == NULL || dom->is_top())
 257     return false; // Conservative answer for dead code
 258 
 259   if (dom->is_Con() || dom->is_Start() || dom->is_Root() || dom == sub)
 260     return true;
 261 
 262   // 'dom' dominates 'sub' if its control edge and control edges
 263   // of all its inputs dominate or equal to sub's control edge.
 264 
 265   // Currently 'sub' is either Allocate, Initialize or Start nodes.
 266   assert(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start(), "expecting only these nodes");



 267 
 268   // Get control edge of 'sub'.
 269   sub = sub->find_exact_control(sub->in(0));
 270   if (sub == NULL || sub->is_top())
 271     return false; // Conservative answer for dead code
 272 
 273   assert(sub->is_CFG(), "expecting control");
 274 
 275   if (sub == dom)
 276     return true;
 277 
 278   if (sub->is_Start() || sub->is_Root())
 279     return false;
 280 
 281   {
 282     // Check all control edges of 'dom'.
 283 
 284     ResourceMark rm;
 285     Arena* arena = Thread::current()->resource_area();
 286     Node_List nlist(arena);


 559       if( n->is_ConstraintCast() ){
 560         worklist.push(n->in(1));
 561       } else if( n->is_Phi() ) {
 562         for( uint i = 1; i < n->req(); i++ ) {
 563           worklist.push(n->in(i));
 564         }
 565       } else {
 566         return false;
 567       }
 568     }
 569   }
 570 
 571   // Quit when the worklist is empty, and we've found no offending nodes.
 572   return true;
 573 }
 574 
 575 //------------------------------Ideal_DU_postCCP-------------------------------
 576 // Find any cast-away of null-ness and keep its control.  Null cast-aways are
 577 // going away in this pass and we need to make this memory op depend on the
 578 // gating null check.



 579 
 580 // I tried to leave the CastPP's in.  This makes the graph more accurate in
 581 // some sense; we get to keep around the knowledge that an oop is not-null
 582 // after some test.  Alas, the CastPP's interfere with GVN (some values are
 583 // the regular oop, some are the CastPP of the oop, all merge at Phi's which
 584 // cannot collapse, etc).  This cost us 10% on SpecJVM, even when I removed
 585 // some of the more trivial cases in the optimizer.  Removing more useless
 586 // Phi's started allowing Loads to illegally float above null checks.  I gave
 587 // up on this approach.  CNC 10/20/2000
 588 Node *MemNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
 589   Node *ctr = in(MemNode::Control);
 590   Node *mem = in(MemNode::Memory);
 591   Node *adr = in(MemNode::Address);
 592   Node *skipped_cast = NULL;
 593   // Need a null check?  Regular static accesses do not because they are
 594   // from constant addresses.  Array ops are gated by the range check (which
 595   // always includes a NULL check).  Just check field ops.
 596   if( !ctr ) {
 597     // Scan upwards for the highest location we can place this memory op.
 598     while( true ) {
 599       switch( adr->Opcode() ) {
 600 
 601       case Op_AddP:             // No change to NULL-ness, so peek thru AddP's
 602         adr = adr->in(AddPNode::Base);
 603         continue;
 604 
 605       case Op_DecodeN:         // No change to NULL-ness, so peek thru
 606         adr = adr->in(1);
 607         continue;
 608 
 609       case Op_CastPP:
 610         // If the CastPP is useless, just peek on through it.
 611         if( ccp->type(adr) == ccp->type(adr->in(1)) ) {
 612           // Remember the cast that we've peeked though. If we peek
 613           // through more than one, then we end up remembering the highest
 614           // one, that is, if in a loop, the one closest to the top.
 615           skipped_cast = adr;
 616           adr = adr->in(1);
 617           continue;
 618         }
 619         // CastPP is going away in this pass!  We need this memory op to be
 620         // control-dependent on the test that is guarding the CastPP.
 621         ccp->hash_delete(this);
 622         set_req(MemNode::Control, adr->in(0));
 623         ccp->hash_insert(this);
 624         return this;
 625 
 626       case Op_Phi:
 627         // Attempt to float above a Phi to some dominating point.
 628         if (adr->in(0) != NULL && adr->in(0)->is_CountedLoop()) {
 629           // If we've already peeked through a Cast (which could have set the
 630           // control), we can't float above a Phi, because the skipped Cast
 631           // may not be loop invariant.
 632           if (adr_phi_is_loop_invariant(adr, skipped_cast)) {
 633             adr = adr->in(1);
 634             continue;
 635           }
 636         }
 637 
 638         // Intentional fallthrough!
 639 
 640         // No obvious dominating point.  The mem op is pinned below the Phi
 641         // by the Phi itself.  If the Phi goes away (no true value is merged)
 642         // then the mem op can float, but not indefinitely.  It must be pinned
 643         // behind the controls leading to the Phi.
 644       case Op_CheckCastPP:
 645         // These usually stick around to change address type, however a
 646         // useless one can be elided and we still need to pick up a control edge
 647         if (adr->in(0) == NULL) {
 648           // This CheckCastPP node has NO control and is likely useless. But we
 649           // need check further up the ancestor chain for a control input to keep
 650           // the node in place. 4959717.
 651           skipped_cast = adr;
 652           adr = adr->in(1);
 653           continue;
 654         }
 655         ccp->hash_delete(this);
 656         set_req(MemNode::Control, adr->in(0));
 657         ccp->hash_insert(this);
 658         return this;
 659 
 660         // List of "safe" opcodes; those that implicitly block the memory
 661         // op below any null check.
 662       case Op_CastX2P:          // no null checks on native pointers
 663       case Op_Parm:             // 'this' pointer is not null
 664       case Op_LoadP:            // Loading from within a klass
 665       case Op_LoadN:            // Loading from within a klass
 666       case Op_LoadKlass:        // Loading from within a klass
 667       case Op_ConP:             // Loading from a klass

 668       case Op_CreateEx:         // Sucking up the guts of an exception oop
 669       case Op_Con:              // Reading from TLS
 670       case Op_CMoveP:           // CMoveP is pinned
 671         break;                  // No progress
 672 
 673       case Op_Proj:             // Direct call to an allocation routine
 674       case Op_SCMemProj:        // Memory state from store conditional ops
 675 #ifdef ASSERT
 676         {
 677           assert(adr->as_Proj()->_con == TypeFunc::Parms, "must be return value");
 678           const Node* call = adr->in(0);
 679           if (call->is_CallStaticJava()) {
 680             const CallStaticJavaNode* call_java = call->as_CallStaticJava();
 681             const TypeTuple *r = call_java->tf()->range();
 682             assert(r->cnt() > TypeFunc::Parms, "must return value");
 683             const Type* ret_type = r->field_at(TypeFunc::Parms);
 684             assert(ret_type && ret_type->isa_ptr(), "must return pointer");
 685             // We further presume that this is one of
 686             // new_instance_Java, new_array_Java, or
 687             // the like, but do not assert for this.
 688           } else if (call->is_Allocate()) {
 689             // similar case to new_instance_Java, etc.
 690           } else if (!call->is_CallLeaf()) {
 691             // Projections from fetch_oop (OSR) are allowed as well.
 692             ShouldNotReachHere();
 693           }
 694         }
 695 #endif
 696         break;
 697       default:
 698         ShouldNotReachHere();
 699       }
 700       break;


 732 
 733   // sanity check the alias category against the created node type
 734   assert(!(adr_type->isa_oopptr() &&
 735            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
 736          "use LoadKlassNode instead");
 737   assert(!(adr_type->isa_aryptr() &&
 738            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 739          "use LoadRangeNode instead");
 740   switch (bt) {
 741   case T_BOOLEAN:
 742   case T_BYTE:    return new (C, 3) LoadBNode(ctl, mem, adr, adr_type, rt->is_int()    );
 743   case T_INT:     return new (C, 3) LoadINode(ctl, mem, adr, adr_type, rt->is_int()    );
 744   case T_CHAR:    return new (C, 3) LoadCNode(ctl, mem, adr, adr_type, rt->is_int()    );
 745   case T_SHORT:   return new (C, 3) LoadSNode(ctl, mem, adr, adr_type, rt->is_int()    );
 746   case T_LONG:    return new (C, 3) LoadLNode(ctl, mem, adr, adr_type, rt->is_long()   );
 747   case T_FLOAT:   return new (C, 3) LoadFNode(ctl, mem, adr, adr_type, rt              );
 748   case T_DOUBLE:  return new (C, 3) LoadDNode(ctl, mem, adr, adr_type, rt              );
 749   case T_ADDRESS: return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr()    );
 750   case T_OBJECT:
 751 #ifdef _LP64
 752     if (adr->bottom_type()->is_narrow()) {
 753       const TypeNarrowOop* narrowtype;
 754       if (rt->isa_narrowoop()) {
 755         narrowtype = rt->is_narrowoop();
 756       } else {
 757         narrowtype = rt->is_oopptr()->make_narrowoop();
 758       }
 759       Node* load  = gvn.transform(new (C, 3) LoadNNode(ctl, mem, adr, adr_type, narrowtype));
 760 
 761       return DecodeNNode::decode(&gvn, load);
 762     } else
 763 #endif
 764       {
 765         assert(!adr->bottom_type()->is_narrow(), "should have got back a narrow oop");
 766         return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_oopptr());
 767       }
 768   }
 769   ShouldNotReachHere();
 770   return (LoadNode*)NULL;
 771 }
 772 
 773 LoadLNode* LoadLNode::make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt) {
 774   bool require_atomic = true;
 775   return new (C, 3) LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), require_atomic);
 776 }
 777 
 778 
 779 
 780 
 781 //------------------------------hash-------------------------------------------
 782 uint LoadNode::hash() const {
 783   // unroll addition of interesting fields
 784   return (uintptr_t)in(Control) + (uintptr_t)in(Memory) + (uintptr_t)in(Address);
 785 }


1188       if (region != NULL) {
1189         // Check for loop invariant.
1190         if (cnt == 3) {
1191           for( uint i = 1; i < cnt; i++ ) {
1192             Node *in = opt_mem->in(i);
1193             Node* m = MemNode::optimize_memory_chain(in, addr_t, phase);
1194             if (m == opt_mem) {
1195               set_req(MemNode::Memory, opt_mem->in(cnt - i)); // Skip this phi.
1196               return this;
1197             }
1198           }
1199         }
1200         // Split through Phi (see original code in loopopts.cpp).
1201         assert(phase->C->have_alias_type(addr_t), "instance should have alias type");
1202 
1203         // Do nothing here if Identity will find a value
1204         // (to avoid infinite chain of value phis generation).
1205         if ( !phase->eqv(this, this->Identity(phase)) )
1206           return NULL;
1207 





1208         const Type* this_type = this->bottom_type();
1209         int this_index  = phase->C->get_alias_index(addr_t);
1210         int this_offset = addr_t->offset();
1211         int this_iid    = addr_t->is_oopptr()->instance_id();
1212         int wins = 0;
1213         PhaseIterGVN *igvn = phase->is_IterGVN();
1214         Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset);
1215         for( uint i = 1; i < region->req(); i++ ) {
1216           Node *x;
1217           Node* the_clone = NULL;
1218           if( region->in(i) == phase->C->top() ) {
1219             x = phase->C->top();      // Dead path?  Use a dead data op
1220           } else {
1221             x = this->clone();        // Else clone up the data op
1222             the_clone = x;            // Remember for possible deletion.
1223             // Alter data node to use pre-phi inputs
1224             if( this->in(0) == region ) {
1225               x->set_req( 0, region->in(i) );
1226             } else {
1227               x->set_req( 0, NULL );


1266                 // We do not need register_new_node_with_optimizer
1267                 // because set_type has already been called.
1268                 igvn->_worklist.push(x);
1269               }
1270             }
1271           }
1272           if (x != the_clone && the_clone != NULL)
1273             igvn->remove_dead_node(the_clone);
1274           phi->set_req(i, x);
1275         }
1276         if( wins > 0 ) {
1277           // Record Phi
1278           igvn->register_new_node_with_optimizer(phi);
1279           return phi;
1280         } else {
1281           igvn->remove_dead_node(phi);
1282         }
1283       }
1284     }
1285   }
1286 
1287   // Check for prior store with a different base or offset; make Load
1288   // independent.  Skip through any number of them.  Bail out if the stores
1289   // are in an endless dead cycle and report no progress.  This is a key
1290   // transform for Reflection.  However, if after skipping through the Stores
1291   // we can't then fold up against a prior store do NOT do the transform as
1292   // this amounts to using the 'Oracle' model of aliasing.  It leaves the same
1293   // array memory alive twice: once for the hoisted Load and again after the
1294   // bypassed Store.  This situation only works if EVERYBODY who does
1295   // anti-dependence work knows how to bypass.  I.e. we need all
1296   // anti-dependence checks to ask the same Oracle.  Right now, that Oracle is
1297   // the alias index stuff.  So instead, peek through Stores and IFF we can
1298   // fold up, do so.
1299   Node* prev_mem = find_previous_store(phase);
1300   // Steps (a), (b):  Walk past independent stores to find an exact match.
1301   if (prev_mem != NULL && prev_mem != in(MemNode::Memory)) {
1302     // (c) See if we can fold up on the spot, but don't fold up here.
1303     // Fold-up might require truncation (for LoadB/LoadS/LoadC) or
1304     // just return a prior value, which is done by Identity calls.
1305     if (can_see_stored_value(prev_mem, phase)) {
1306       // Make ready for step (d):


1818 
1819 }
1820 //=============================================================================
1821 //---------------------------StoreNode::make-----------------------------------
1822 // Polymorphic factory method:
1823 StoreNode* StoreNode::make( PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, BasicType bt ) {
1824   Compile* C = gvn.C;
1825 
1826   switch (bt) {
1827   case T_BOOLEAN:
1828   case T_BYTE:    return new (C, 4) StoreBNode(ctl, mem, adr, adr_type, val);
1829   case T_INT:     return new (C, 4) StoreINode(ctl, mem, adr, adr_type, val);
1830   case T_CHAR:
1831   case T_SHORT:   return new (C, 4) StoreCNode(ctl, mem, adr, adr_type, val);
1832   case T_LONG:    return new (C, 4) StoreLNode(ctl, mem, adr, adr_type, val);
1833   case T_FLOAT:   return new (C, 4) StoreFNode(ctl, mem, adr, adr_type, val);
1834   case T_DOUBLE:  return new (C, 4) StoreDNode(ctl, mem, adr, adr_type, val);
1835   case T_ADDRESS:
1836   case T_OBJECT:
1837 #ifdef _LP64
1838     if (adr->bottom_type()->is_narrow() ||
1839         (UseCompressedOops && val->bottom_type()->isa_klassptr() &&
1840          adr->bottom_type()->isa_rawptr())) {
1841       const TypePtr* type = val->bottom_type()->is_ptr();
1842       Node* cp = EncodePNode::encode(&gvn, val);
1843       return new (C, 4) StoreNNode(ctl, mem, adr, adr_type, cp);
1844     } else
1845 #endif
1846       {
1847         return new (C, 4) StorePNode(ctl, mem, adr, adr_type, val);
1848       }
1849   }
1850   ShouldNotReachHere();
1851   return (StoreNode*)NULL;
1852 }
1853 
1854 StoreLNode* StoreLNode::make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val) {
1855   bool require_atomic = true;
1856   return new (C, 4) StoreLNode(ctl, mem, adr, adr_type, val, require_atomic);
1857 }
1858 




 116       } else if (proj_in->is_MemBar()) {
 117         result = proj_in->in(TypeFunc::Memory);
 118       }
 119     } else if (result->is_MergeMem()) {
 120       result = step_through_mergemem(phase, result->as_MergeMem(), t_adr, NULL, tty);
 121     }
 122   }
 123   return result;
 124 }
 125 
 126 Node *MemNode::optimize_memory_chain(Node *mchain, const TypePtr *t_adr, PhaseGVN *phase) {
 127   const TypeOopPtr *t_oop = t_adr->isa_oopptr();
 128   bool is_instance = (t_oop != NULL) && t_oop->is_instance_field();
 129   PhaseIterGVN *igvn = phase->is_IterGVN();
 130   Node *result = mchain;
 131   result = optimize_simple_memory_chain(result, t_adr, phase);
 132   if (is_instance && igvn != NULL  && result->is_Phi()) {
 133     PhiNode *mphi = result->as_Phi();
 134     assert(mphi->bottom_type() == Type::MEMORY, "memory phi required");
 135     const TypePtr *t = mphi->adr_type();
 136     if (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM ||
 137         t->isa_oopptr() && !t->is_oopptr()->is_instance() &&
 138         t->is_oopptr()->cast_to_instance(t_oop->instance_id()) == t_oop) {
 139       // clone the Phi with our address type
 140       result = mphi->split_out_instance(t_adr, igvn);
 141     } else {
 142       assert(phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr), "correct memory chain");
 143     }
 144   }
 145   return result;
 146 }
 147 
 148 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st) {
 149   uint alias_idx = phase->C->get_alias_index(tp);
 150   Node *mem = mmem;
 151 #ifdef ASSERT
 152   {
 153     // Check that current type is consistent with the alias index used during graph construction
 154     assert(alias_idx >= Compile::AliasIdxRaw, "must not be a bad alias_idx");
 155     bool consistent =  adr_check == NULL || adr_check->empty() ||
 156                        phase->C->must_alias(adr_check, alias_idx );
 157     // Sometimes dead array references collapse to a[-1], a[-2], or a[-3]
 158     if( !consistent && adr_check != NULL && !adr_check->empty() &&


 248 // is not a constant (dominated by the method's StartNode).
 249 // Used by MemNode::find_previous_store to prove that the
 250 // control input of a memory operation predates (dominates)
 251 // an allocation it wants to look past.
 252 bool MemNode::all_controls_dominate(Node* dom, Node* sub) {
 253   if (dom == NULL || dom->is_top() || sub == NULL || sub->is_top())
 254     return false; // Conservative answer for dead code
 255 
 256   // Check 'dom'.
 257   dom = dom->find_exact_control(dom);
 258   if (dom == NULL || dom->is_top())
 259     return false; // Conservative answer for dead code
 260 
 261   if (dom->is_Con() || dom->is_Start() || dom->is_Root() || dom == sub)
 262     return true;
 263 
 264   // 'dom' dominates 'sub' if its control edge and control edges
 265   // of all its inputs dominate or equal to sub's control edge.
 266 
 267   // Currently 'sub' is either Allocate, Initialize or Start nodes.
 268   // Or Region for the check in LoadNode::Ideal();
 269   // 'sub' should have sub->in(0) != NULL.
 270   assert(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() ||
 271          sub->is_Region(), "expecting only these nodes");
 272 
 273   // Get control edge of 'sub'.
 274   sub = sub->find_exact_control(sub->in(0));
 275   if (sub == NULL || sub->is_top())
 276     return false; // Conservative answer for dead code
 277 
 278   assert(sub->is_CFG(), "expecting control");
 279 
 280   if (sub == dom)
 281     return true;
 282 
 283   if (sub->is_Start() || sub->is_Root())
 284     return false;
 285 
 286   {
 287     // Check all control edges of 'dom'.
 288 
 289     ResourceMark rm;
 290     Arena* arena = Thread::current()->resource_area();
 291     Node_List nlist(arena);


 564       if( n->is_ConstraintCast() ){
 565         worklist.push(n->in(1));
 566       } else if( n->is_Phi() ) {
 567         for( uint i = 1; i < n->req(); i++ ) {
 568           worklist.push(n->in(i));
 569         }
 570       } else {
 571         return false;
 572       }
 573     }
 574   }
 575 
 576   // Quit when the worklist is empty, and we've found no offending nodes.
 577   return true;
 578 }
 579 
 580 //------------------------------Ideal_DU_postCCP-------------------------------
 581 // Find any cast-away of null-ness and keep its control.  Null cast-aways are
 582 // going away in this pass and we need to make this memory op depend on the
 583 // gating null check.
 584 Node *MemNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
 585   return Ideal_common_DU_postCCP(ccp, this, in(MemNode::Address));
 586 }
 587 
 588 // I tried to leave the CastPP's in.  This makes the graph more accurate in
 589 // some sense; we get to keep around the knowledge that an oop is not-null
 590 // after some test.  Alas, the CastPP's interfere with GVN (some values are
 591 // the regular oop, some are the CastPP of the oop, all merge at Phi's which
 592 // cannot collapse, etc).  This cost us 10% on SpecJVM, even when I removed
 593 // some of the more trivial cases in the optimizer.  Removing more useless
 594 // Phi's started allowing Loads to illegally float above null checks.  I gave
 595 // up on this approach.  CNC 10/20/2000
 596 Node *MemNode::Ideal_common_DU_postCCP( PhaseCCP *ccp, Node* n, Node* adr ) {



 597   Node *skipped_cast = NULL;
 598   // Need a null check?  Regular static accesses do not because they are
 599   // from constant addresses.  Array ops are gated by the range check (which
 600   // always includes a NULL check).  Just check field ops.
 601   if( n->in(MemNode::Control) == NULL ) {
 602     // Scan upwards for the highest location we can place this memory op.
 603     while( true ) {
 604       switch( adr->Opcode() ) {
 605 
 606       case Op_AddP:             // No change to NULL-ness, so peek thru AddP's
 607         adr = adr->in(AddPNode::Base);
 608         continue;
 609 
 610       case Op_DecodeN:         // No change to NULL-ness, so peek thru
 611         adr = adr->in(1);
 612         continue;
 613 
 614       case Op_CastPP:
 615         // If the CastPP is useless, just peek on through it.
 616         if( ccp->type(adr) == ccp->type(adr->in(1)) ) {
 617           // Remember the cast that we've peeked though. If we peek
 618           // through more than one, then we end up remembering the highest
 619           // one, that is, if in a loop, the one closest to the top.
 620           skipped_cast = adr;
 621           adr = adr->in(1);
 622           continue;
 623         }
 624         // CastPP is going away in this pass!  We need this memory op to be
 625         // control-dependent on the test that is guarding the CastPP.
 626         ccp->hash_delete(n);
 627         n->set_req(MemNode::Control, adr->in(0));
 628         ccp->hash_insert(n);
 629         return n;
 630 
 631       case Op_Phi:
 632         // Attempt to float above a Phi to some dominating point.
 633         if (adr->in(0) != NULL && adr->in(0)->is_CountedLoop()) {
 634           // If we've already peeked through a Cast (which could have set the
 635           // control), we can't float above a Phi, because the skipped Cast
 636           // may not be loop invariant.
 637           if (adr_phi_is_loop_invariant(adr, skipped_cast)) {
 638             adr = adr->in(1);
 639             continue;
 640           }
 641         }
 642 
 643         // Intentional fallthrough!
 644 
 645         // No obvious dominating point.  The mem op is pinned below the Phi
 646         // by the Phi itself.  If the Phi goes away (no true value is merged)
 647         // then the mem op can float, but not indefinitely.  It must be pinned
 648         // behind the controls leading to the Phi.
 649       case Op_CheckCastPP:
 650         // These usually stick around to change address type, however a
 651         // useless one can be elided and we still need to pick up a control edge
 652         if (adr->in(0) == NULL) {
 653           // This CheckCastPP node has NO control and is likely useless. But we
 654           // need check further up the ancestor chain for a control input to keep
 655           // the node in place. 4959717.
 656           skipped_cast = adr;
 657           adr = adr->in(1);
 658           continue;
 659         }
 660         ccp->hash_delete(n);
 661         n->set_req(MemNode::Control, adr->in(0));
 662         ccp->hash_insert(n);
 663         return n;
 664 
 665         // List of "safe" opcodes; those that implicitly block the memory
 666         // op below any null check.
 667       case Op_CastX2P:          // no null checks on native pointers
 668       case Op_Parm:             // 'this' pointer is not null
 669       case Op_LoadP:            // Loading from within a klass
 670       case Op_LoadN:            // Loading from within a klass
 671       case Op_LoadKlass:        // Loading from within a klass
 672       case Op_ConP:             // Loading from a klass
 673       case Op_ConN:             // Loading from a klass
 674       case Op_CreateEx:         // Sucking up the guts of an exception oop
 675       case Op_Con:              // Reading from TLS
 676       case Op_CMoveP:           // CMoveP is pinned
 677         break;                  // No progress
 678 
 679       case Op_Proj:             // Direct call to an allocation routine
 680       case Op_SCMemProj:        // Memory state from store conditional ops
 681 #ifdef ASSERT
 682         {
 683           assert(adr->as_Proj()->_con == TypeFunc::Parms, "must be return value");
 684           const Node* call = adr->in(0);
 685           if (call->is_CallJava()) {
 686             const CallJavaNode* call_java = call->as_CallJava();
 687             const TypeTuple *r = call_java->tf()->range();
 688             assert(r->cnt() > TypeFunc::Parms, "must return value");
 689             const Type* ret_type = r->field_at(TypeFunc::Parms);
 690             assert(ret_type && ret_type->isa_ptr(), "must return pointer");
 691             // We further presume that this is one of
 692             // new_instance_Java, new_array_Java, or
 693             // the like, but do not assert for this.
 694           } else if (call->is_Allocate()) {
 695             // similar case to new_instance_Java, etc.
 696           } else if (!call->is_CallLeaf()) {
 697             // Projections from fetch_oop (OSR) are allowed as well.
 698             ShouldNotReachHere();
 699           }
 700         }
 701 #endif
 702         break;
 703       default:
 704         ShouldNotReachHere();
 705       }
 706       break;


 738 
 739   // sanity check the alias category against the created node type
 740   assert(!(adr_type->isa_oopptr() &&
 741            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
 742          "use LoadKlassNode instead");
 743   assert(!(adr_type->isa_aryptr() &&
 744            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 745          "use LoadRangeNode instead");
 746   switch (bt) {
 747   case T_BOOLEAN:
 748   case T_BYTE:    return new (C, 3) LoadBNode(ctl, mem, adr, adr_type, rt->is_int()    );
 749   case T_INT:     return new (C, 3) LoadINode(ctl, mem, adr, adr_type, rt->is_int()    );
 750   case T_CHAR:    return new (C, 3) LoadCNode(ctl, mem, adr, adr_type, rt->is_int()    );
 751   case T_SHORT:   return new (C, 3) LoadSNode(ctl, mem, adr, adr_type, rt->is_int()    );
 752   case T_LONG:    return new (C, 3) LoadLNode(ctl, mem, adr, adr_type, rt->is_long()   );
 753   case T_FLOAT:   return new (C, 3) LoadFNode(ctl, mem, adr, adr_type, rt              );
 754   case T_DOUBLE:  return new (C, 3) LoadDNode(ctl, mem, adr, adr_type, rt              );
 755   case T_ADDRESS: return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr()    );
 756   case T_OBJECT:
 757 #ifdef _LP64
 758     if (adr->bottom_type()->is_ptr_to_narrowoop()) {
 759       const TypeNarrowOop* narrowtype;
 760       if (rt->isa_narrowoop()) {
 761         narrowtype = rt->is_narrowoop();
 762       } else {
 763         narrowtype = rt->is_oopptr()->make_narrowoop();
 764       }
 765       Node* load  = gvn.transform(new (C, 3) LoadNNode(ctl, mem, adr, adr_type, narrowtype));
 766 
 767       return DecodeNNode::decode(&gvn, load);
 768     } else
 769 #endif
 770     {
 771       assert(!adr->bottom_type()->is_ptr_to_narrowoop(), "should have got back a narrow oop");
 772       return new (C, 3) LoadPNode(ctl, mem, adr, adr_type, rt->is_oopptr());
 773     }
 774   }
 775   ShouldNotReachHere();
 776   return (LoadNode*)NULL;
 777 }
 778 
 779 LoadLNode* LoadLNode::make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt) {
 780   bool require_atomic = true;
 781   return new (C, 3) LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), require_atomic);
 782 }
 783 
 784 
 785 
 786 
 787 //------------------------------hash-------------------------------------------
 788 uint LoadNode::hash() const {
 789   // unroll addition of interesting fields
 790   return (uintptr_t)in(Control) + (uintptr_t)in(Memory) + (uintptr_t)in(Address);
 791 }


1194       if (region != NULL) {
1195         // Check for loop invariant.
1196         if (cnt == 3) {
1197           for( uint i = 1; i < cnt; i++ ) {
1198             Node *in = opt_mem->in(i);
1199             Node* m = MemNode::optimize_memory_chain(in, addr_t, phase);
1200             if (m == opt_mem) {
1201               set_req(MemNode::Memory, opt_mem->in(cnt - i)); // Skip this phi.
1202               return this;
1203             }
1204           }
1205         }
1206         // Split through Phi (see original code in loopopts.cpp).
1207         assert(phase->C->have_alias_type(addr_t), "instance should have alias type");
1208 
1209         // Do nothing here if Identity will find a value
1210         // (to avoid infinite chain of value phis generation).
1211         if ( !phase->eqv(this, this->Identity(phase)) )
1212           return NULL;
1213 
1214         // Skip the split if the loop head dominates some control edges
1215         // of the address.
1216         if (cnt == 3 && !MemNode::all_controls_dominate(address, region))
1217           goto find_store;
1218 
1219         const Type* this_type = this->bottom_type();
1220         int this_index  = phase->C->get_alias_index(addr_t);
1221         int this_offset = addr_t->offset();
1222         int this_iid    = addr_t->is_oopptr()->instance_id();
1223         int wins = 0;
1224         PhaseIterGVN *igvn = phase->is_IterGVN();
1225         Node *phi = new (igvn->C, region->req()) PhiNode(region, this_type, NULL, this_iid, this_index, this_offset);
1226         for( uint i = 1; i < region->req(); i++ ) {
1227           Node *x;
1228           Node* the_clone = NULL;
1229           if( region->in(i) == phase->C->top() ) {
1230             x = phase->C->top();      // Dead path?  Use a dead data op
1231           } else {
1232             x = this->clone();        // Else clone up the data op
1233             the_clone = x;            // Remember for possible deletion.
1234             // Alter data node to use pre-phi inputs
1235             if( this->in(0) == region ) {
1236               x->set_req( 0, region->in(i) );
1237             } else {
1238               x->set_req( 0, NULL );


1277                 // We do not need register_new_node_with_optimizer
1278                 // because set_type has already been called.
1279                 igvn->_worklist.push(x);
1280               }
1281             }
1282           }
1283           if (x != the_clone && the_clone != NULL)
1284             igvn->remove_dead_node(the_clone);
1285           phi->set_req(i, x);
1286         }
1287         if( wins > 0 ) {
1288           // Record Phi
1289           igvn->register_new_node_with_optimizer(phi);
1290           return phi;
1291         } else {
1292           igvn->remove_dead_node(phi);
1293         }
1294       }
1295     }
1296   }
1297 find_store:
1298   // Check for prior store with a different base or offset; make Load
1299   // independent.  Skip through any number of them.  Bail out if the stores
1300   // are in an endless dead cycle and report no progress.  This is a key
1301   // transform for Reflection.  However, if after skipping through the Stores
1302   // we can't then fold up against a prior store do NOT do the transform as
1303   // this amounts to using the 'Oracle' model of aliasing.  It leaves the same
1304   // array memory alive twice: once for the hoisted Load and again after the
1305   // bypassed Store.  This situation only works if EVERYBODY who does
1306   // anti-dependence work knows how to bypass.  I.e. we need all
1307   // anti-dependence checks to ask the same Oracle.  Right now, that Oracle is
1308   // the alias index stuff.  So instead, peek through Stores and IFF we can
1309   // fold up, do so.
1310   Node* prev_mem = find_previous_store(phase);
1311   // Steps (a), (b):  Walk past independent stores to find an exact match.
1312   if (prev_mem != NULL && prev_mem != in(MemNode::Memory)) {
1313     // (c) See if we can fold up on the spot, but don't fold up here.
1314     // Fold-up might require truncation (for LoadB/LoadS/LoadC) or
1315     // just return a prior value, which is done by Identity calls.
1316     if (can_see_stored_value(prev_mem, phase)) {
1317       // Make ready for step (d):


1829 
1830 }
1831 //=============================================================================
1832 //---------------------------StoreNode::make-----------------------------------
1833 // Polymorphic factory method:
1834 StoreNode* StoreNode::make( PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, BasicType bt ) {
1835   Compile* C = gvn.C;
1836 
1837   switch (bt) {
1838   case T_BOOLEAN:
1839   case T_BYTE:    return new (C, 4) StoreBNode(ctl, mem, adr, adr_type, val);
1840   case T_INT:     return new (C, 4) StoreINode(ctl, mem, adr, adr_type, val);
1841   case T_CHAR:
1842   case T_SHORT:   return new (C, 4) StoreCNode(ctl, mem, adr, adr_type, val);
1843   case T_LONG:    return new (C, 4) StoreLNode(ctl, mem, adr, adr_type, val);
1844   case T_FLOAT:   return new (C, 4) StoreFNode(ctl, mem, adr, adr_type, val);
1845   case T_DOUBLE:  return new (C, 4) StoreDNode(ctl, mem, adr, adr_type, val);
1846   case T_ADDRESS:
1847   case T_OBJECT:
1848 #ifdef _LP64
1849     if (adr->bottom_type()->is_ptr_to_narrowoop() ||
1850         (UseCompressedOops && val->bottom_type()->isa_klassptr() &&
1851          adr->bottom_type()->isa_rawptr())) {
1852       const TypePtr* type = val->bottom_type()->is_ptr();
1853       Node* cp = EncodePNode::encode(&gvn, val);
1854       return new (C, 4) StoreNNode(ctl, mem, adr, adr_type, cp);
1855     } else
1856 #endif
1857       {
1858         return new (C, 4) StorePNode(ctl, mem, adr, adr_type, val);
1859       }
1860   }
1861   ShouldNotReachHere();
1862   return (StoreNode*)NULL;
1863 }
1864 
1865 StoreLNode* StoreLNode::make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val) {
1866   bool require_atomic = true;
1867   return new (C, 4) StoreLNode(ctl, mem, adr, adr_type, val, require_atomic);
1868 }
1869 


src/share/vm/opto/memnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File