< prev index next >

src/share/vm/opto/memnode.cpp

Print this page




 477   // They may both manifestly be allocations, and they should differ.
 478   // Or, if they are not both allocations, they can be distinct constants.
 479   // Otherwise, one is an allocation and the other a pre-existing value.
 480   if (a1 == NULL && a2 == NULL) {           // neither an allocation
 481     return (p1 != p2) && p1->is_Con() && p2->is_Con();
 482   } else if (a1 != NULL && a2 != NULL) {    // both allocations
 483     return (a1 != a2);
 484   } else if (a1 != NULL) {                  // one allocation a1
 485     // (Note:  p2->is_Con implies p2->in(0)->is_Root, which dominates.)
 486     return all_controls_dominate(p2, a1);
 487   } else { //(a2 != NULL)                   // one allocation a2
 488     return all_controls_dominate(p1, a2);
 489   }
 490   return false;
 491 }
 492 
 493 
 494 // Find an arraycopy that must have set (can_see_stored_value=true) or
 495 // could have set (can_see_stored_value=false) the value for this load
 496 Node* LoadNode::find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const {
 497   if (mem->is_Proj() && mem->in(0) != NULL && (mem->in(0)->Opcode() == Op_MemBarStoreStore ||
 498                                                mem->in(0)->Opcode() == Op_MemBarCPUOrder)) {
 499     Node* mb = mem->in(0);
 500     if (mb->in(0) != NULL && mb->in(0)->is_Proj() &&
 501         mb->in(0)->in(0) != NULL && mb->in(0)->in(0)->is_ArrayCopy()) {
 502       ArrayCopyNode* ac = mb->in(0)->in(0)->as_ArrayCopy();
 503       if (ac->is_clonebasic()) {
 504         intptr_t offset;
 505         AllocateNode* alloc = AllocateNode::Ideal_allocation(ac->in(ArrayCopyNode::Dest), phase, offset);
 506         assert(alloc != NULL && (!ReduceBulkZeroing || alloc->initialization()->is_complete_with_arraycopy()), "broken allocation");
 507         if (alloc == ld_alloc) {
 508           return ac;
 509         }
 510       }
 511     }
 512   } else if (mem->is_Proj() && mem->in(0) != NULL && mem->in(0)->is_ArrayCopy()) {
 513     ArrayCopyNode* ac = mem->in(0)->as_ArrayCopy();
 514 
 515     if (ac->is_arraycopy_validated() ||
 516         ac->is_copyof_validated() ||
 517         ac->is_copyofrange_validated()) {
 518       Node* ld_addp = in(MemNode::Address);


 717       // disregarding "null"-ness.
 718       // (We make an exception for TypeRawPtr::BOTTOM, which is a bit bucket.)
 719       const TypePtr* tp_notnull = tp->join(TypePtr::NOTNULL)->is_ptr();
 720       assert(cross_check->meet(tp_notnull) == cross_check->remove_speculative(),
 721              "real address must not escape from expected memory type");
 722     }
 723     #endif
 724     return tp;
 725   }
 726 }
 727 
 728 //=============================================================================
 729 // Should LoadNode::Ideal() attempt to remove control edges?
 730 bool LoadNode::can_remove_control() const {
 731   return true;
 732 }
 733 uint LoadNode::size_of() const { return sizeof(*this); }
 734 uint LoadNode::cmp( const Node &n ) const
 735 { return !Type::cmp( _type, ((LoadNode&)n)._type ); }
 736 const Type *LoadNode::bottom_type() const { return _type; }
 737 uint LoadNode::ideal_reg() const {
 738   return _type->ideal_reg();
 739 }
 740 
 741 #ifndef PRODUCT
 742 void LoadNode::dump_spec(outputStream *st) const {
 743   MemNode::dump_spec(st);
 744   if( !Verbose && !WizardMode ) {
 745     // standard dump does this in Verbose and WizardMode
 746     st->print(" #"); _type->dump_on(st);
 747   }
 748   if (!depends_only_on_test()) {
 749     st->print(" (does not depend only on test)");
 750   }
 751 }
 752 #endif
 753 
 754 #ifdef ASSERT
 755 //----------------------------is_immutable_value-------------------------------
 756 // Helper function to allow a raw load without control edge for some cases
 757 bool LoadNode::is_immutable_value(Node* adr) {
 758   return (adr->is_AddP() && adr->in(AddPNode::Base)->is_top() &&
 759           adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal &&
 760           (adr->in(AddPNode::Offset)->find_intptr_t_con(-1) ==
 761            in_bytes(JavaThread::osthread_offset())));
 762 }
 763 #endif
 764 
 765 //----------------------------LoadNode::make-----------------------------------
 766 // Polymorphic factory method:
 767 Node *LoadNode::make(PhaseGVN& gvn, Node *ctl, Node *mem, Node *adr, const TypePtr* adr_type, const Type *rt, BasicType bt, MemOrd mo,
 768                      ControlDependency control_dependency, bool unaligned, bool mismatched) {
 769   Compile* C = gvn.C;
 770 
 771   // sanity check the alias category against the created node type
 772   assert(!(adr_type->isa_oopptr() &&
 773            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
 774          "use LoadKlassNode instead");
 775   assert(!(adr_type->isa_aryptr() &&
 776            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 777          "use LoadRangeNode instead");
 778   // Check control edge of raw loads
 779   assert( ctl != NULL || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||


 793   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;
 794   case T_OBJECT:
 795 #ifdef _LP64
 796     if (adr->bottom_type()->is_ptr_to_narrowoop()) {
 797       load = new LoadNNode(ctl, mem, adr, adr_type, rt->make_narrowoop(), mo, control_dependency);
 798     } else
 799 #endif
 800     {
 801       assert(!adr->bottom_type()->is_ptr_to_narrowoop() && !adr->bottom_type()->is_ptr_to_narrowklass(), "should have got back a narrow oop");
 802       load = new LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr(), mo, control_dependency);
 803     }
 804     break;
 805   }
 806   assert(load != NULL, "LoadNode should have been created");
 807   if (unaligned) {
 808     load->set_unaligned_access();
 809   }
 810   if (mismatched) {
 811     load->set_mismatched_access();
 812   }
 813   if (load->Opcode() == Op_LoadN) {
 814     Node* ld = gvn.transform(load);
 815     return new DecodeNNode(ld, ld->bottom_type()->make_ptr());
 816   }
 817 
 818   return load;
 819 }
 820 
 821 LoadLNode* LoadLNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo,
 822                                   ControlDependency control_dependency, bool unaligned, bool mismatched) {
 823   bool require_atomic = true;
 824   LoadLNode* load = new LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic);
 825   if (unaligned) {
 826     load->set_unaligned_access();
 827   }
 828   if (mismatched) {
 829     load->set_mismatched_access();
 830   }
 831   return load;
 832 }
 833 


 933 // of aliasing.
 934 Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const {
 935   Node* ld_adr = in(MemNode::Address);
 936   intptr_t ld_off = 0;
 937   AllocateNode* ld_alloc = AllocateNode::Ideal_allocation(ld_adr, phase, ld_off);
 938   const TypeInstPtr* tp = phase->type(ld_adr)->isa_instptr();
 939   Compile::AliasType* atp = (tp != NULL) ? phase->C->alias_type(tp) : NULL;
 940   // This is more general than load from boxing objects.
 941   if (skip_through_membars(atp, tp, phase->C->eliminate_boxing())) {
 942     uint alias_idx = atp->index();
 943     bool final = !atp->is_rewritable();
 944     Node* result = NULL;
 945     Node* current = st;
 946     // Skip through chains of MemBarNodes checking the MergeMems for
 947     // new states for the slice of this load.  Stop once any other
 948     // kind of node is encountered.  Loads from final memory can skip
 949     // through any kind of MemBar but normal loads shouldn't skip
 950     // through MemBarAcquire since the could allow them to move out of
 951     // a synchronized region.
 952     while (current->is_Proj()) {
 953       int opc = current->in(0)->Opcode();
 954       if ((final && (opc == Op_MemBarAcquire ||
 955                      opc == Op_MemBarAcquireLock ||
 956                      opc == Op_LoadFence)) ||
 957           opc == Op_MemBarRelease ||
 958           opc == Op_StoreFence ||
 959           opc == Op_MemBarReleaseLock ||
 960           opc == Op_MemBarStoreStore ||
 961           opc == Op_MemBarCPUOrder) {
 962         Node* mem = current->in(0)->in(TypeFunc::Memory);
 963         if (mem->is_MergeMem()) {
 964           MergeMemNode* merge = mem->as_MergeMem();
 965           Node* new_st = merge->memory_at(alias_idx);
 966           if (new_st == merge->base_memory()) {
 967             // Keep searching
 968             current = new_st;
 969             continue;
 970           }
 971           // Save the new memory state for the slice and fall through
 972           // to exit.
 973           result = new_st;
 974         }
 975       }
 976       break;
 977     }
 978     if (result != NULL) {
 979       st = result;
 980     }
 981   }


1109       this_iid = base->_idx;
1110     }
1111     const Type* this_type = bottom_type();
1112     for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
1113       Node* phi = region->fast_out(i);
1114       if (phi->is_Phi() && phi != mem &&
1115           phi->as_Phi()->is_same_inst_field(this_type, this_iid, this_index, this_offset)) {
1116         return phi;
1117       }
1118     }
1119   }
1120 
1121   return this;
1122 }
1123 
1124 // Construct an equivalent unsigned load.
1125 Node* LoadNode::convert_to_unsigned_load(PhaseGVN& gvn) {
1126   BasicType bt = T_ILLEGAL;
1127   const Type* rt = NULL;
1128   switch (Opcode()) {
1129     case Op_LoadUB: return this;
1130     case Op_LoadUS: return this;
1131     case Op_LoadB: bt = T_BOOLEAN; rt = TypeInt::UBYTE; break;
1132     case Op_LoadS: bt = T_CHAR;    rt = TypeInt::CHAR;  break;
1133     default:
1134       assert(false, "no unsigned variant: %s", Name());
1135       return NULL;
1136   }
1137   return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address),
1138                         raw_adr_type(), rt, bt, _mo, _control_dependency,
1139                         is_unaligned_access(), is_mismatched_access());
1140 }
1141 
1142 // Construct an equivalent signed load.
1143 Node* LoadNode::convert_to_signed_load(PhaseGVN& gvn) {
1144   BasicType bt = T_ILLEGAL;
1145   const Type* rt = NULL;
1146   switch (Opcode()) {
1147     case Op_LoadUB: bt = T_BYTE;  rt = TypeInt::BYTE;  break;
1148     case Op_LoadUS: bt = T_SHORT; rt = TypeInt::SHORT; break;
1149     case Op_LoadB: // fall through
1150     case Op_LoadS: // fall through
1151     case Op_LoadI: // fall through
1152     case Op_LoadL: return this;
1153     default:
1154       assert(false, "no signed variant: %s", Name());
1155       return NULL;
1156   }
1157   return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address),
1158                         raw_adr_type(), rt, bt, _mo, _control_dependency,
1159                         is_unaligned_access(), is_mismatched_access());
1160 }
1161 
1162 // We're loading from an object which has autobox behaviour.
1163 // If this object is result of a valueOf call we'll have a phi
1164 // merging a newly allocated object and a load from the cache.
1165 // We want to replace this load with the original incoming
1166 // argument to the valueOf call.
1167 Node* LoadNode::eliminate_autobox(PhaseGVN* phase) {
1168   assert(phase->C->eliminate_boxing(), "sanity");
1169   intptr_t ignore = 0;
1170   Node* base = AddPNode::Ideal_base_and_offset(in(Address), phase, ignore);
1171   if ((base == NULL) || base->is_Phi()) {
1172     // Push the loads from the phi that comes from valueOf up


1183     if (base->is_DecodeN()) {
1184       base = base->in(1);
1185     }
1186     if (!base->in(Address)->is_AddP()) {
1187       return NULL; // Complex address
1188     }
1189     AddPNode* address = base->in(Address)->as_AddP();
1190     Node* cache_base = address->in(AddPNode::Base);
1191     if ((cache_base != NULL) && cache_base->is_DecodeN()) {
1192       // Get ConP node which is static 'cache' field.
1193       cache_base = cache_base->in(1);
1194     }
1195     if ((cache_base != NULL) && cache_base->is_Con()) {
1196       const TypeAryPtr* base_type = cache_base->bottom_type()->isa_aryptr();
1197       if ((base_type != NULL) && base_type->is_autobox_cache()) {
1198         Node* elements[4];
1199         int shift = exact_log2(type2aelembytes(T_OBJECT));
1200         int count = address->unpack_offsets(elements, ARRAY_SIZE(elements));
1201         if ((count >  0) && elements[0]->is_Con() &&
1202             ((count == 1) ||
1203              (count == 2) && elements[1]->Opcode() == Op_LShiftX &&
1204                              elements[1]->in(2) == phase->intcon(shift))) {
1205           ciObjArray* array = base_type->const_oop()->as_obj_array();
1206           // Fetch the box object cache[0] at the base of the array and get its value
1207           ciInstance* box = array->obj_at(0)->as_instance();
1208           ciInstanceKlass* ik = box->klass()->as_instance_klass();
1209           assert(ik->is_box_klass(), "sanity");
1210           assert(ik->nof_nonstatic_fields() == 1, "change following code");
1211           if (ik->nof_nonstatic_fields() == 1) {
1212             // This should be true nonstatic_field_at requires calling
1213             // nof_nonstatic_fields so check it anyway
1214             ciConstant c = box->field_value(ik->nonstatic_field_at(0));
1215             BasicType bt = c.basic_type();
1216             // Only integer types have boxing cache.
1217             assert(bt == T_BOOLEAN || bt == T_CHAR  ||
1218                    bt == T_BYTE    || bt == T_SHORT ||
1219                    bt == T_INT     || bt == T_LONG, "wrong type = %s", type2name(bt));
1220             jlong cache_low = (bt == T_LONG) ? c.as_long() : c.as_int();
1221             if (cache_low != (int)cache_low) {
1222               return NULL; // should not happen since cache is array indexed by value
1223             }
1224             jlong offset = arrayOopDesc::base_offset_in_bytes(T_OBJECT) - (cache_low << shift);
1225             if (offset != (int)offset) {
1226               return NULL; // should not happen since cache is array indexed by value
1227             }
1228            // Add up all the offsets making of the address of the load
1229             Node* result = elements[0];
1230             for (int i = 1; i < count; i++) {
1231               result = phase->transform(new AddXNode(result, elements[i]));
1232             }
1233             // Remove the constant offset from the address and then
1234             result = phase->transform(new AddXNode(result, phase->MakeConX(-(int)offset)));
1235             // remove the scaling of the offset to recover the original index.
1236             if (result->Opcode() == Op_LShiftX && result->in(2) == phase->intcon(shift)) {
1237               // Peel the shift off directly but wrap it in a dummy node
1238               // since Ideal can't return existing nodes
1239               result = new RShiftXNode(result->in(1), phase->intcon(0));
1240             } else if (result->is_Add() && result->in(2)->is_Con() &&
1241                        result->in(1)->Opcode() == Op_LShiftX &&
1242                        result->in(1)->in(2) == phase->intcon(shift)) {
1243               // We can't do general optimization: ((X<<Z) + Y) >> Z ==> X + (Y>>Z)
1244               // but for boxing cache access we know that X<<Z will not overflow
1245               // (there is range check) so we do this optimizatrion by hand here.
1246               Node* add_con = new RShiftXNode(result->in(2), phase->intcon(shift));
1247               result = new AddXNode(result->in(1)->in(1), phase->transform(add_con));
1248             } else {
1249               result = new RShiftXNode(result, phase->intcon(shift));
1250             }
1251 #ifdef _LP64
1252             if (bt != T_LONG) {
1253               result = new ConvL2INode(phase->transform(result));
1254             }
1255 #else
1256             if (bt == T_LONG) {
1257               result = new ConvI2LNode(phase->transform(result));
1258             }
1259 #endif
1260             // Boxing/unboxing can be done from signed & unsigned loads (e.g. LoadUB -> ... -> LoadB pair).
1261             // Need to preserve unboxing load type if it is unsigned.
1262             switch(this->Opcode()) {
1263               case Op_LoadUB:
1264                 result = new AndINode(phase->transform(result), phase->intcon(0xFF));
1265                 break;
1266               case Op_LoadUS:
1267                 result = new AndINode(phase->transform(result), phase->intcon(0xFFFF));
1268                 break;
1269             }
1270             return result;
1271           }
1272         }
1273       }
1274     }
1275   }
1276   return NULL;
1277 }
1278 
1279 static bool stable_phi(PhiNode* phi, PhaseGVN *phase) {
1280   Node* region = phi->in(0);
1281   if (region == NULL) {
1282     return false; // Wait stable graph
1283   }
1284   uint cnt = phi->req();
1285   for (uint i = 1; i < cnt; i++) {
1286     Node* rc = region->in(i);


1468   // Record Phi
1469   igvn->register_new_node_with_optimizer(phi);
1470   return phi;
1471 }
1472 
1473 //------------------------------Ideal------------------------------------------
1474 // If the load is from Field memory and the pointer is non-null, it might be possible to
1475 // zero out the control input.
1476 // If the offset is constant and the base is an object allocation,
1477 // try to hook me up to the exact initializing store.
1478 Node *LoadNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1479   Node* p = MemNode::Ideal_common(phase, can_reshape);
1480   if (p)  return (p == NodeSentinel) ? NULL : p;
1481 
1482   Node* ctrl    = in(MemNode::Control);
1483   Node* address = in(MemNode::Address);
1484   bool progress = false;
1485 
1486   // Skip up past a SafePoint control.  Cannot do this for Stores because
1487   // pointer stores & cardmarks must stay on the same side of a SafePoint.
1488   if( ctrl != NULL && ctrl->Opcode() == Op_SafePoint &&
1489       phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw ) {
1490     ctrl = ctrl->in(0);
1491     set_req(MemNode::Control,ctrl);
1492     progress = true;
1493   }
1494 
1495   intptr_t ignore = 0;
1496   Node*    base   = AddPNode::Ideal_base_and_offset(address, phase, ignore);
1497   if (base != NULL
1498       && phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw) {
1499     // Check for useless control edge in some common special cases
1500     if (in(MemNode::Control) != NULL
1501         && can_remove_control()
1502         && phase->type(base)->higher_equal(TypePtr::NOTNULL)
1503         && all_controls_dominate(base, phase->C->start())) {
1504       // A method-invariant, non-null address (constant or 'this' argument).
1505       set_req(MemNode::Control, NULL);
1506       progress = true;
1507     }
1508   }


1587     // Fold-up might require truncation (for LoadB/LoadS/LoadUS) or
1588     // just return a prior value, which is done by Identity calls.
1589     if (can_see_stored_value(prev_mem, phase)) {
1590       // Make ready for step (d):
1591       set_req(MemNode::Memory, prev_mem);
1592       return this;
1593     }
1594   }
1595 
1596   return progress ? this : NULL;
1597 }
1598 
1599 // Helper to recognize certain Klass fields which are invariant across
1600 // some group of array types (e.g., int[] or all T[] where T < Object).
1601 const Type*
1602 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
1603                                  ciKlass* klass) const {
1604   if (tkls->offset() == in_bytes(Klass::modifier_flags_offset())) {
1605     // The field is Klass::_modifier_flags.  Return its (constant) value.
1606     // (Folds up the 2nd indirection in aClassConstant.getModifiers().)
1607     assert(this->Opcode() == Op_LoadI, "must load an int from _modifier_flags");
1608     return TypeInt::make(klass->modifier_flags());
1609   }
1610   if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
1611     // The field is Klass::_access_flags.  Return its (constant) value.
1612     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1613     assert(this->Opcode() == Op_LoadI, "must load an int from _access_flags");
1614     return TypeInt::make(klass->access_flags());
1615   }
1616   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1617     // The field is Klass::_layout_helper.  Return its constant value if known.
1618     assert(this->Opcode() == Op_LoadI, "must load an int from _layout_helper");
1619     return TypeInt::make(klass->layout_helper());
1620   }
1621 
1622   // No match.
1623   return NULL;
1624 }
1625 
1626 //------------------------------Value-----------------------------------------
1627 const Type* LoadNode::Value(PhaseGVN* phase) const {
1628   // Either input is TOP ==> the result is TOP
1629   Node* mem = in(MemNode::Memory);
1630   const Type *t1 = phase->type(mem);
1631   if (t1 == Type::TOP)  return Type::TOP;
1632   Node* adr = in(MemNode::Address);
1633   const TypePtr* tp = phase->type(adr)->isa_ptr();
1634   if (tp == NULL || tp->empty())  return Type::TOP;
1635   int off = tp->offset();
1636   assert(off != Type::OffsetTop, "case covered by TypePtr::empty");
1637   Compile* C = phase->C;
1638 


1665       }
1666     }
1667 
1668     // Don't do this for integer types. There is only potential profit if
1669     // the element type t is lower than _type; that is, for int types, if _type is
1670     // more restrictive than t.  This only happens here if one is short and the other
1671     // char (both 16 bits), and in those cases we've made an intentional decision
1672     // to use one kind of load over the other. See AndINode::Ideal and 4965907.
1673     // Also, do not try to narrow the type for a LoadKlass, regardless of offset.
1674     //
1675     // Yes, it is possible to encounter an expression like (LoadKlass p1:(AddP x x 8))
1676     // where the _gvn.type of the AddP is wider than 8.  This occurs when an earlier
1677     // copy p0 of (AddP x x 8) has been proven equal to p1, and the p0 has been
1678     // subsumed by p1.  If p1 is on the worklist but has not yet been re-transformed,
1679     // it is possible that p1 will have a type like Foo*[int+]:NotNull*+any.
1680     // In fact, that could have been the original type of p1, and p1 could have
1681     // had an original form like p1:(AddP x x (LShiftL quux 3)), where the
1682     // expression (LShiftL quux 3) independently optimized to the constant 8.
1683     if ((t->isa_int() == NULL) && (t->isa_long() == NULL)
1684         && (_type->isa_vect() == NULL)
1685         && Opcode() != Op_LoadKlass && Opcode() != Op_LoadNKlass) {
1686       // t might actually be lower than _type, if _type is a unique
1687       // concrete subclass of abstract class t.
1688       if (off_beyond_header) {  // is the offset beyond the header?
1689         const Type* jt = t->join_speculative(_type);
1690         // In any case, do not allow the join, per se, to empty out the type.
1691         if (jt->empty() && !t->empty()) {
1692           // This can happen if a interface-typed array narrows to a class type.
1693           jt = _type;
1694         }
1695 #ifdef ASSERT
1696         if (phase->C->eliminate_boxing() && adr->is_AddP()) {
1697           // The pointers in the autobox arrays are always non-null
1698           Node* base = adr->in(AddPNode::Base);
1699           if ((base != NULL) && base->is_DecodeN()) {
1700             // Get LoadN node which loads IntegerCache.cache field
1701             base = base->in(1);
1702           }
1703           if ((base != NULL) && base->is_Con()) {
1704             const TypeAryPtr* base_type = base->bottom_type()->isa_aryptr();
1705             if ((base_type != NULL) && base_type->is_autobox_cache()) {


1720             // arrays can be cast to Objects
1721             tp->is_oopptr()->klass()->is_java_lang_Object() ||
1722             // unsafe field access may not have a constant offset
1723             C->has_unsafe_access(),
1724             "Field accesses must be precise" );
1725     // For oop loads, we expect the _type to be precise.
1726     // Optimizations for constant objects
1727     ciObject* const_oop = tinst->const_oop();
1728     if (const_oop != NULL && const_oop->is_instance()) {
1729       const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type());
1730       if (con_type != NULL) {
1731         return con_type;
1732       }
1733     }
1734   } else if (tp->base() == Type::KlassPtr) {
1735     assert( off != Type::OffsetBot ||
1736             // arrays can be cast to Objects
1737             tp->is_klassptr()->klass()->is_java_lang_Object() ||
1738             // also allow array-loading from the primary supertype
1739             // array during subtype checks
1740             Opcode() == Op_LoadKlass,
1741             "Field accesses must be precise" );
1742     // For klass/static loads, we expect the _type to be precise
1743   }
1744 
1745   const TypeKlassPtr *tkls = tp->isa_klassptr();
1746   if (tkls != NULL && !StressReflectiveCode) {
1747     ciKlass* klass = tkls->klass();
1748     if (klass->is_loaded() && tkls->klass_is_exact()) {
1749       // We are loading a field from a Klass metaobject whose identity
1750       // is known at compile time (the type is "exact" or "precise").
1751       // Check for fields we know are maintained as constants by the VM.
1752       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
1753         // The field is Klass::_super_check_offset.  Return its (constant) value.
1754         // (Folds up type checking code.)
1755         assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset");
1756         return TypeInt::make(klass->super_check_offset());
1757       }
1758       // Compute index into primary_supers array
1759       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
1760       // Check for overflowing; use unsigned compare to handle the negative case.
1761       if( depth < ciKlass::primary_super_limit() ) {
1762         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
1763         // (Folds up type checking code.)
1764         assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
1765         ciKlass *ss = klass->super_of_depth(depth);
1766         return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR;
1767       }
1768       const Type* aift = load_array_final_field(tkls, klass);
1769       if (aift != NULL)  return aift;
1770       if (tkls->offset() == in_bytes(Klass::java_mirror_offset())) {
1771         // The field is Klass::_java_mirror.  Return its (constant) value.
1772         // (Folds up the 2nd indirection in anObjConstant.getClass().)
1773         assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror");
1774         return TypeInstPtr::make(klass->java_mirror());
1775       }
1776     }
1777 
1778     // We can still check if we are loading from the primary_supers array at a
1779     // shallow enough depth.  Even though the klass is not exact, entries less
1780     // than or equal to its super depth are correct.
1781     if (klass->is_loaded() ) {
1782       ciType *inner = klass;
1783       while( inner->is_obj_array_klass() )
1784         inner = inner->as_obj_array_klass()->base_element_type();
1785       if( inner->is_instance_klass() &&
1786           !inner->as_instance_klass()->flags().is_interface() ) {
1787         // Compute index into primary_supers array
1788         juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
1789         // Check for overflowing; use unsigned compare to handle the negative case.
1790         if( depth < ciKlass::primary_super_limit() &&
1791             depth <= klass->super_depth() ) { // allow self-depth checks to handle self-check case
1792           // The field is an element of Klass::_primary_supers.  Return its (constant) value.
1793           // (Folds up type checking code.)
1794           assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
1795           ciKlass *ss = klass->super_of_depth(depth);
1796           return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR;
1797         }
1798       }
1799     }
1800 
1801     // If the type is enough to determine that the thing is not an array,
1802     // we can give the layout_helper a positive interval type.
1803     // This will help short-circuit some reflective code.
1804     if (tkls->offset() == in_bytes(Klass::layout_helper_offset())
1805         && !klass->is_array_klass() // not directly typed as an array
1806         && !klass->is_interface()  // specifically not Serializable & Cloneable
1807         && !klass->is_java_lang_Object()   // not the supertype of all T[]
1808         ) {
1809       // Note:  When interfaces are reliable, we can narrow the interface
1810       // test to (klass != Serializable && klass != Cloneable).
1811       assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
1812       jint min_size = Klass::instance_layout_helper(oopDesc::header_size(), false);
1813       // The key property of this type is that it folds up tests
1814       // for array-ness, since it proves that the layout_helper is positive.
1815       // Thus, a generic value like the basic object layout helper works fine.
1816       return TypeInt::make(min_size, max_jint, Type::WidenMin);
1817     }
1818   }
1819 
1820   // If we are loading from a freshly-allocated object, produce a zero,
1821   // if the load is provably beyond the header of the object.
1822   // (Also allow a variable load from a fresh array to produce zero.)
1823   const TypeOopPtr *tinst = tp->isa_oopptr();
1824   bool is_instance = (tinst != NULL) && tinst->is_known_instance_field();
1825   bool is_boxed_value = (tinst != NULL) && tinst->is_ptr_to_boxed_value();
1826   if (ReduceFieldZeroing || is_instance || is_boxed_value) {
1827     Node* value = can_see_stored_value(mem,phase);
1828     if (value != NULL && value->is_Con()) {
1829       assert(value->bottom_type()->higher_equal(_type),"sanity");
1830       return value->bottom_type();
1831     }


2372 // try to capture it into the initialization, or hoist it above.
2373 Node *StoreNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2374   Node* p = MemNode::Ideal_common(phase, can_reshape);
2375   if (p)  return (p == NodeSentinel) ? NULL : p;
2376 
2377   Node* mem     = in(MemNode::Memory);
2378   Node* address = in(MemNode::Address);
2379   // Back-to-back stores to same address?  Fold em up.  Generally
2380   // unsafe if I have intervening uses...  Also disallowed for StoreCM
2381   // since they must follow each StoreP operation.  Redundant StoreCMs
2382   // are eliminated just before matching in final_graph_reshape.
2383   {
2384     Node* st = mem;
2385     // If Store 'st' has more than one use, we cannot fold 'st' away.
2386     // For example, 'st' might be the final state at a conditional
2387     // return.  Or, 'st' might be used by some node which is live at
2388     // the same time 'st' is live, which might be unschedulable.  So,
2389     // require exactly ONE user until such time as we clone 'mem' for
2390     // each of 'mem's uses (thus making the exactly-1-user-rule hold
2391     // true).
2392     while (st->is_Store() && st->outcnt() == 1 && st->Opcode() != Op_StoreCM) {
2393       // Looking at a dead closed cycle of memory?
2394       assert(st != st->in(MemNode::Memory), "dead loop in StoreNode::Ideal");
2395       assert(Opcode() == st->Opcode() ||
2396              st->Opcode() == Op_StoreVector ||
2397              Opcode() == Op_StoreVector ||
2398              phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw ||
2399              (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || // expanded ClearArrayNode
2400              (is_mismatched_access() || st->as_Store()->is_mismatched_access()),
2401              "no mismatched stores, except on raw memory: %s %s", NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]);
2402 
2403       if (st->in(MemNode::Address)->eqv_uncast(address) &&
2404           st->as_Store()->memory_size() <= this->memory_size()) {
2405         Node* use = st->raw_out(0);
2406         phase->igvn_rehash_node_delayed(use);
2407         if (can_reshape) {
2408           use->set_req_X(MemNode::Memory, st->in(MemNode::Memory), phase->is_IterGVN());
2409         } else {
2410           // It's OK to do this in the parser, since DU info is always accurate,
2411           // and the parser always refers to nodes via SafePointNode maps.
2412           use->set_req(MemNode::Memory, st->in(MemNode::Memory));
2413         }
2414         return this;
2415       }
2416       st = st->in(MemNode::Memory);
2417     }
2418   }
2419 
2420 
2421   // Capture an unaliased, unconditional, simple store into an initializer.


2504 //------------------------------match_edge-------------------------------------
2505 // Do we Match on this edge index or not?  Match only memory & value
2506 uint StoreNode::match_edge(uint idx) const {
2507   return idx == MemNode::Address || idx == MemNode::ValueIn;
2508 }
2509 
2510 //------------------------------cmp--------------------------------------------
2511 // Do not common stores up together.  They generally have to be split
2512 // back up anyways, so do not bother.
2513 uint StoreNode::cmp( const Node &n ) const {
2514   return (&n == this);          // Always fail except on self
2515 }
2516 
2517 //------------------------------Ideal_masked_input-----------------------------
2518 // Check for a useless mask before a partial-word store
2519 // (StoreB ... (AndI valIn conIa) )
2520 // If (conIa & mask == mask) this simplifies to
2521 // (StoreB ... (valIn) )
2522 Node *StoreNode::Ideal_masked_input(PhaseGVN *phase, uint mask) {
2523   Node *val = in(MemNode::ValueIn);
2524   if( val->Opcode() == Op_AndI ) {
2525     const TypeInt *t = phase->type( val->in(2) )->isa_int();
2526     if( t && t->is_con() && (t->get_con() & mask) == mask ) {
2527       set_req(MemNode::ValueIn, val->in(1));
2528       return this;
2529     }
2530   }
2531   return NULL;
2532 }
2533 
2534 
2535 //------------------------------Ideal_sign_extended_input----------------------
2536 // Check for useless sign-extension before a partial-word store
2537 // (StoreB ... (RShiftI _ (LShiftI _ valIn conIL ) conIR) )
2538 // If (conIL == conIR && conIR <= num_bits)  this simplifies to
2539 // (StoreB ... (valIn) )
2540 Node *StoreNode::Ideal_sign_extended_input(PhaseGVN *phase, int num_bits) {
2541   Node *val = in(MemNode::ValueIn);
2542   if( val->Opcode() == Op_RShiftI ) {
2543     const TypeInt *t = phase->type( val->in(2) )->isa_int();
2544     if( t && t->is_con() && (t->get_con() <= num_bits) ) {
2545       Node *shl = val->in(1);
2546       if( shl->Opcode() == Op_LShiftI ) {
2547         const TypeInt *t2 = phase->type( shl->in(2) )->isa_int();
2548         if( t2 && t2->is_con() && (t2->get_con() == t->get_con()) ) {
2549           set_req(MemNode::ValueIn, shl->in(1));
2550           return this;
2551         }
2552       }
2553     }
2554   }
2555   return NULL;
2556 }
2557 
2558 //------------------------------value_never_loaded-----------------------------------
2559 // Determine whether there are any possible loads of the value stored.
2560 // For simplicity, we actually check if there are any loads from the
2561 // address stored to, not just for loads of the value stored by this node.
2562 //
2563 bool StoreNode::value_never_loaded( PhaseTransform *phase) const {
2564   Node *adr = in(Address);
2565   const TypeOopPtr *adr_oop = phase->type(adr)->isa_oopptr();
2566   if (adr_oop == NULL)


2658 //----------------------------------SCMemProjNode------------------------------
2659 const Type* SCMemProjNode::Value(PhaseGVN* phase) const
2660 {
2661   return bottom_type();
2662 }
2663 
2664 //=============================================================================
2665 //----------------------------------LoadStoreNode------------------------------
2666 LoadStoreNode::LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required )
2667   : Node(required),
2668     _type(rt),
2669     _adr_type(at)
2670 {
2671   init_req(MemNode::Control, c  );
2672   init_req(MemNode::Memory , mem);
2673   init_req(MemNode::Address, adr);
2674   init_req(MemNode::ValueIn, val);
2675   init_class_id(Class_LoadStore);
2676 }
2677 
2678 uint LoadStoreNode::ideal_reg() const {
2679   return _type->ideal_reg();
2680 }
2681 
2682 bool LoadStoreNode::result_not_used() const {
2683   for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
2684     Node *x = fast_out(i);
2685     if (x->Opcode() == Op_SCMemProj) continue;
2686     return false;
2687   }
2688   return true;
2689 }
2690 
2691 uint LoadStoreNode::size_of() const { return sizeof(*this); }
2692 
2693 //=============================================================================
2694 //----------------------------------LoadStoreConditionalNode--------------------
2695 LoadStoreConditionalNode::LoadStoreConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex ) : LoadStoreNode(c, mem, adr, val, NULL, TypeInt::BOOL, 5) {
2696   init_req(ExpectedIn, ex );
2697 }
2698 
2699 //=============================================================================
2700 //-------------------------------adr_type--------------------------------------
2701 const TypePtr* ClearArrayNode::adr_type() const {
2702   Node *adr = in(3);
2703   if (adr == NULL)  return NULL; // node is dead
2704   return MemNode::calculate_adr_type(adr->bottom_type());
2705 }


2732   // Clearing nothing uses the Identity call.
2733   // Negative clears are possible on dead ClearArrays
2734   // (see jck test stmt114.stmt11402.val).
2735   if (size <= 0 || size % unit != 0)  return NULL;
2736   intptr_t count = size / unit;
2737   // Length too long; communicate this to matchers and assemblers.
2738   // Assemblers are responsible to produce fast hardware clears for it.
2739   if (size > InitArrayShortSize) {
2740     return new ClearArrayNode(in(0), in(1), in(2), in(3), true);
2741   }
2742   Node *mem = in(1);
2743   if( phase->type(mem)==Type::TOP ) return NULL;
2744   Node *adr = in(3);
2745   const Type* at = phase->type(adr);
2746   if( at==Type::TOP ) return NULL;
2747   const TypePtr* atp = at->isa_ptr();
2748   // adjust atp to be the correct array element address type
2749   if (atp == NULL)  atp = TypePtr::BOTTOM;
2750   else              atp = atp->add_offset(Type::OffsetBot);
2751   // Get base for derived pointer purposes
2752   if( adr->Opcode() != Op_AddP ) Unimplemented();
2753   Node *base = adr->in(1);
2754 
2755   Node *zero = phase->makecon(TypeLong::ZERO);
2756   Node *off  = phase->MakeConX(BytesPerLong);
2757   mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false);
2758   count--;
2759   while( count-- ) {
2760     mem = phase->transform(mem);
2761     adr = phase->transform(new AddPNode(base,adr,off));
2762     mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false);
2763   }
2764   return mem;
2765 }
2766 
2767 //----------------------------step_through----------------------------------
2768 // Return allocation input memory edge if it is different instance
2769 // or itself if it is the one we are looking for.
2770 bool ClearArrayNode::step_through(Node** np, uint instance_id, PhaseTransform* phase) {
2771   Node* n = *np;
2772   assert(n->is_ClearArray(), "sanity");


2874 MemBarNode::MemBarNode(Compile* C, int alias_idx, Node* precedent)
2875   : MultiNode(TypeFunc::Parms + (precedent == NULL? 0: 1)),
2876     _adr_type(C->get_adr_type(alias_idx))
2877 {
2878   init_class_id(Class_MemBar);
2879   Node* top = C->top();
2880   init_req(TypeFunc::I_O,top);
2881   init_req(TypeFunc::FramePtr,top);
2882   init_req(TypeFunc::ReturnAdr,top);
2883   if (precedent != NULL)
2884     init_req(TypeFunc::Parms, precedent);
2885 }
2886 
2887 //------------------------------cmp--------------------------------------------
2888 uint MemBarNode::hash() const { return NO_HASH; }
2889 uint MemBarNode::cmp( const Node &n ) const {
2890   return (&n == this);          // Always fail except on self
2891 }
2892 
2893 //------------------------------make-------------------------------------------
2894 MemBarNode* MemBarNode::make(Compile* C, int opcode, int atp, Node* pn) {
2895   switch (opcode) {
2896   case Op_MemBarAcquire:     return new MemBarAcquireNode(C, atp, pn);
2897   case Op_LoadFence:         return new LoadFenceNode(C, atp, pn);
2898   case Op_MemBarRelease:     return new MemBarReleaseNode(C, atp, pn);
2899   case Op_StoreFence:        return new StoreFenceNode(C, atp, pn);
2900   case Op_MemBarAcquireLock: return new MemBarAcquireLockNode(C, atp, pn);
2901   case Op_MemBarReleaseLock: return new MemBarReleaseLockNode(C, atp, pn);
2902   case Op_MemBarVolatile:    return new MemBarVolatileNode(C, atp, pn);
2903   case Op_MemBarCPUOrder:    return new MemBarCPUOrderNode(C, atp, pn);
2904   case Op_OnSpinWait:        return new OnSpinWaitNode(C, atp, pn);
2905   case Op_Initialize:        return new InitializeNode(C, atp, pn);
2906   case Op_MemBarStoreStore:  return new MemBarStoreStoreNode(C, atp, pn);
2907   default: ShouldNotReachHere(); return NULL;
2908   }
2909 }
2910 
2911 //------------------------------Ideal------------------------------------------
2912 // Return a node which is more "ideal" than the current node.  Strip out
2913 // control copies
2914 Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2915   if (remove_dead_region(phase, can_reshape)) return this;
2916   // Don't bother trying to transform a dead node
2917   if (in(0) && in(0)->is_top()) {
2918     return NULL;
2919   }
2920 
2921   bool progress = false;
2922   // Eliminate volatile MemBars for scalar replaced objects.
2923   if (can_reshape && req() == (Precedent+1)) {
2924     bool eliminate = false;
2925     int opc = Opcode();
2926     if ((opc == Op_MemBarAcquire || opc == Op_MemBarVolatile)) {
2927       // Volatile field loads and stores.
2928       Node* my_mem = in(MemBarNode::Precedent);
2929       // The MembarAquire may keep an unused LoadNode alive through the Precedent edge
2930       if ((my_mem != NULL) && (opc == Op_MemBarAcquire) && (my_mem->outcnt() == 1)) {
2931         // if the Precedent is a decodeN and its input (a Load) is used at more than one place,
2932         // replace this Precedent (decodeN) with the Load instead.
2933         if ((my_mem->Opcode() == Op_DecodeN) && (my_mem->in(1)->outcnt() > 1))  {
2934           Node* load_node = my_mem->in(1);
2935           set_req(MemBarNode::Precedent, load_node);
2936           phase->is_IterGVN()->_worklist.push(my_mem);
2937           my_mem = load_node;
2938         } else {
2939           assert(my_mem->unique_out() == this, "sanity");
2940           del_req(Precedent);
2941           phase->is_IterGVN()->_worklist.push(my_mem); // remove dead node later
2942           my_mem = NULL;
2943         }
2944         progress = true;
2945       }
2946       if (my_mem != NULL && my_mem->is_Mem()) {
2947         const TypeOopPtr* t_oop = my_mem->in(MemNode::Address)->bottom_type()->isa_oopptr();
2948         // Check for scalar replaced object reference.
2949         if( t_oop != NULL && t_oop->is_known_instance_field() &&
2950             t_oop->offset() != Type::OffsetBot &&
2951             t_oop->offset() != Type::OffsetTop) {
2952           eliminate = true;
2953         }
2954       }
2955     } else if (opc == Op_MemBarRelease) {
2956       // Final field stores.
2957       Node* alloc = AllocateNode::Ideal_allocation(in(MemBarNode::Precedent), phase);
2958       if ((alloc != NULL) && alloc->is_Allocate() &&
2959           alloc->as_Allocate()->does_not_escape_thread()) {
2960         // The allocated object does not escape.
2961         eliminate = true;
2962       }
2963     }
2964     if (eliminate) {
2965       // Replace MemBar projections by its inputs.
2966       PhaseIterGVN* igvn = phase->is_IterGVN();
2967       igvn->replace_node(proj_out(TypeFunc::Memory), in(TypeFunc::Memory));
2968       igvn->replace_node(proj_out(TypeFunc::Control), in(TypeFunc::Control));
2969       // Must return either the original node (now dead) or a new node
2970       // (Do not return a top here, since that would break the uniqueness of top.)
2971       return new ConINode(TypeInt::ZERO);
2972     }
2973   }
2974   return progress ? this : NULL;
2975 }
2976 
2977 //------------------------------Value------------------------------------------
2978 const Type* MemBarNode::Value(PhaseGVN* phase) const {
2979   if( !in(0) ) return Type::TOP;
2980   if( phase->type(in(0)) == Type::TOP )
2981     return Type::TOP;
2982   return TypeTuple::MEMBAR;
2983 }
2984 
2985 //------------------------------match------------------------------------------
2986 // Construct projections for memory.
2987 Node *MemBarNode::match( const ProjNode *proj, const Matcher *m ) {
2988   switch (proj->_con) {
2989   case TypeFunc::Control:
2990   case TypeFunc::Memory:
2991     return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
2992   }
2993   ShouldNotReachHere();
2994   return NULL;
2995 }
2996 
2997 //===========================InitializeNode====================================
2998 // SUMMARY:
2999 // This node acts as a memory barrier on raw memory, after some raw stores.
3000 // The 'cooked' oop value feeds from the Initialize, not the Allocation.
3001 // The Initialize can 'capture' suitably constrained stores as raw inits.
3002 // It can coalesce related raw stores into larger units (called 'tiles').
3003 // It can avoid zeroing new storage for memory units which have raw inits.
3004 // At macro-expansion, it is marked 'complete', and does not optimize further.
3005 //
3006 // EXAMPLE:
3007 // The object 'new short[2]' occupies 16 bytes in a 32-bit machine.
3008 //   ctl = incoming control; mem* = incoming memory
3009 // (Note:  A star * on a memory edge denotes I/O and other standard edges.)
3010 // First allocate uninitialized memory and fill in the header:
3011 //   alloc = (Allocate ctl mem* 16 #short[].klass ...)


3086 // reasonable limit on the complexity of optimized initializations.
3087 
3088 //---------------------------InitializeNode------------------------------------
3089 InitializeNode::InitializeNode(Compile* C, int adr_type, Node* rawoop)
3090   : _is_complete(Incomplete), _does_not_escape(false),
3091     MemBarNode(C, adr_type, rawoop)
3092 {
3093   init_class_id(Class_Initialize);
3094 
3095   assert(adr_type == Compile::AliasIdxRaw, "only valid atp");
3096   assert(in(RawAddress) == rawoop, "proper init");
3097   // Note:  allocation() can be NULL, for secondary initialization barriers
3098 }
3099 
3100 // Since this node is not matched, it will be processed by the
3101 // register allocator.  Declare that there are no constraints
3102 // on the allocation of the RawAddress edge.
3103 const RegMask &InitializeNode::in_RegMask(uint idx) const {
3104   // This edge should be set to top, by the set_complete.  But be conservative.
3105   if (idx == InitializeNode::RawAddress)
3106     return *(Compile::current()->matcher()->idealreg2spillmask[in(idx)->ideal_reg()]);
3107   return RegMask::Empty;
3108 }
3109 
3110 Node* InitializeNode::memory(uint alias_idx) {
3111   Node* mem = in(Memory);
3112   if (mem->is_MergeMem()) {
3113     return mem->as_MergeMem()->memory_at(alias_idx);
3114   } else {
3115     // incoming raw memory is not split
3116     return mem;
3117   }
3118 }
3119 
3120 bool InitializeNode::is_non_zero() {
3121   if (is_complete())  return false;
3122   remove_extra_zeroes();
3123   return (req() > RawStores);
3124 }
3125 
3126 void InitializeNode::set_complete(PhaseGVN* phase) {


3568     if (st_off + st_size > size_limit)    break;
3569 
3570     // Record which bytes are touched, whether by constant or not.
3571     if (!store_constant(inits, num_tiles, st_off, st_size, (jlong) -1))
3572       continue;                 // skip (strange store size)
3573 
3574     const Type* val = phase->type(st->in(MemNode::ValueIn));
3575     if (!val->singleton())                continue; //skip (non-con store)
3576     BasicType type = val->basic_type();
3577 
3578     jlong con = 0;
3579     switch (type) {
3580     case T_INT:    con = val->is_int()->get_con();  break;
3581     case T_LONG:   con = val->is_long()->get_con(); break;
3582     case T_FLOAT:  con = jint_cast(val->getf());    break;
3583     case T_DOUBLE: con = jlong_cast(val->getd());   break;
3584     default:                              continue; //skip (odd store type)
3585     }
3586 
3587     if (type == T_LONG && Matcher::isSimpleConstant64(con) &&
3588         st->Opcode() == Op_StoreL) {
3589       continue;                 // This StoreL is already optimal.
3590     }
3591 
3592     // Store down the constant.
3593     store_constant(tiles, num_tiles, st_off, st_size, con);
3594 
3595     intptr_t j = st_off >> LogBytesPerLong;
3596 
3597     if (type == T_INT && st_size == BytesPerInt
3598         && (st_off & BytesPerInt) == BytesPerInt) {
3599       jlong lcon = tiles[j];
3600       if (!Matcher::isSimpleConstant64(lcon) &&
3601           st->Opcode() == Op_StoreI) {
3602         // This StoreI is already optimal by itself.
3603         jint* intcon = (jint*) &tiles[j];
3604         intcon[1] = 0;  // undo the store_constant()
3605 
3606         // If the previous store is also optimal by itself, back up and
3607         // undo the action of the previous loop iteration... if we can.
3608         // But if we can't, just let the previous half take care of itself.
3609         st = nodes[j];
3610         st_off -= BytesPerInt;
3611         con = intcon[0];
3612         if (con != 0 && st != NULL && st->Opcode() == Op_StoreI) {
3613           assert(st_off >= header_size, "still ignoring header");
3614           assert(get_store_offset(st, phase) == st_off, "must be");
3615           assert(in(i-1) == zmem, "must be");
3616           DEBUG_ONLY(const Type* tcon = phase->type(st->in(MemNode::ValueIn)));
3617           assert(con == tcon->is_int()->get_con(), "must be");
3618           // Undo the effects of the previous loop trip, which swallowed st:
3619           intcon[0] = 0;        // undo store_constant()
3620           set_req(i-1, st);     // undo set_req(i, zmem)
3621           nodes[j] = NULL;      // undo nodes[j] = st
3622           --old_subword;        // undo ++old_subword
3623         }
3624         continue;               // This StoreI is already optimal.
3625       }
3626     }
3627 
3628     // This store is not needed.
3629     set_req(i, zmem);
3630     nodes[j] = st;              // record for the moment
3631     if (st_size < BytesPerLong) // something has changed
3632           ++old_subword;        // includes int/float, but who's counting...


3915       last_tile_end = MAX2(last_tile_end, next_init_off);
3916     } else {
3917       intptr_t st_tile_end = align_size_up(next_init_off, BytesPerLong);
3918       assert(st_tile_end >= last_tile_end, "inits stay with tiles");
3919       assert(st_off      >= last_init_end, "inits do not overlap");
3920       last_init_end = next_init_off;  // it's a non-tile
3921     }
3922     #endif //ASSERT
3923   }
3924 
3925   remove_extra_zeroes();        // clear out all the zmems left over
3926   add_req(inits);
3927 
3928   if (!(UseTLAB && ZeroTLAB)) {
3929     // If anything remains to be zeroed, zero it all now.
3930     zeroes_done = align_size_down(zeroes_done, BytesPerInt);
3931     // if it is the last unused 4 bytes of an instance, forget about it
3932     intptr_t size_limit = phase->find_intptr_t_con(size_in_bytes, max_jint);
3933     if (zeroes_done + BytesPerLong >= size_limit) {
3934       assert(allocation() != NULL, "");
3935       if (allocation()->Opcode() == Op_Allocate) {
3936         Node* klass_node = allocation()->in(AllocateNode::KlassNode);
3937         ciKlass* k = phase->type(klass_node)->is_klassptr()->klass();
3938         if (zeroes_done == k->layout_helper())
3939           zeroes_done = size_limit;
3940       }
3941     }
3942     if (zeroes_done < size_limit) {
3943       rawmem = ClearArrayNode::clear_memory(rawctl, rawmem, rawptr,
3944                                             zeroes_done, size_in_bytes, phase);
3945     }
3946   }
3947 
3948   set_complete(phase);
3949   return rawmem;
3950 }
3951 
3952 
3953 #ifdef ASSERT
3954 bool InitializeNode::stores_are_sane(PhaseTransform* phase) {
3955   if (is_complete())




 477   // They may both manifestly be allocations, and they should differ.
 478   // Or, if they are not both allocations, they can be distinct constants.
 479   // Otherwise, one is an allocation and the other a pre-existing value.
 480   if (a1 == NULL && a2 == NULL) {           // neither an allocation
 481     return (p1 != p2) && p1->is_Con() && p2->is_Con();
 482   } else if (a1 != NULL && a2 != NULL) {    // both allocations
 483     return (a1 != a2);
 484   } else if (a1 != NULL) {                  // one allocation a1
 485     // (Note:  p2->is_Con implies p2->in(0)->is_Root, which dominates.)
 486     return all_controls_dominate(p2, a1);
 487   } else { //(a2 != NULL)                   // one allocation a2
 488     return all_controls_dominate(p1, a2);
 489   }
 490   return false;
 491 }
 492 
 493 
 494 // Find an arraycopy that must have set (can_see_stored_value=true) or
 495 // could have set (can_see_stored_value=false) the value for this load
 496 Node* LoadNode::find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const {
 497   if (mem->is_Proj() && mem->in(0) != NULL && (mem->in(0)->Opcode() == Opcodes::Op_MemBarStoreStore ||
 498                                                mem->in(0)->Opcode() == Opcodes::Op_MemBarCPUOrder)) {
 499     Node* mb = mem->in(0);
 500     if (mb->in(0) != NULL && mb->in(0)->is_Proj() &&
 501         mb->in(0)->in(0) != NULL && mb->in(0)->in(0)->is_ArrayCopy()) {
 502       ArrayCopyNode* ac = mb->in(0)->in(0)->as_ArrayCopy();
 503       if (ac->is_clonebasic()) {
 504         intptr_t offset;
 505         AllocateNode* alloc = AllocateNode::Ideal_allocation(ac->in(ArrayCopyNode::Dest), phase, offset);
 506         assert(alloc != NULL && (!ReduceBulkZeroing || alloc->initialization()->is_complete_with_arraycopy()), "broken allocation");
 507         if (alloc == ld_alloc) {
 508           return ac;
 509         }
 510       }
 511     }
 512   } else if (mem->is_Proj() && mem->in(0) != NULL && mem->in(0)->is_ArrayCopy()) {
 513     ArrayCopyNode* ac = mem->in(0)->as_ArrayCopy();
 514 
 515     if (ac->is_arraycopy_validated() ||
 516         ac->is_copyof_validated() ||
 517         ac->is_copyofrange_validated()) {
 518       Node* ld_addp = in(MemNode::Address);


 717       // disregarding "null"-ness.
 718       // (We make an exception for TypeRawPtr::BOTTOM, which is a bit bucket.)
 719       const TypePtr* tp_notnull = tp->join(TypePtr::NOTNULL)->is_ptr();
 720       assert(cross_check->meet(tp_notnull) == cross_check->remove_speculative(),
 721              "real address must not escape from expected memory type");
 722     }
 723     #endif
 724     return tp;
 725   }
 726 }
 727 
 728 //=============================================================================
 729 // Should LoadNode::Ideal() attempt to remove control edges?
 730 bool LoadNode::can_remove_control() const {
 731   return true;
 732 }
 733 uint LoadNode::size_of() const { return sizeof(*this); }
 734 uint LoadNode::cmp( const Node &n ) const
 735 { return !Type::cmp( _type, ((LoadNode&)n)._type ); }
 736 const Type *LoadNode::bottom_type() const { return _type; }
 737 Opcodes LoadNode::ideal_reg() const {
 738   return _type->ideal_reg();
 739 }
 740 
 741 #ifndef PRODUCT
 742 void LoadNode::dump_spec(outputStream *st) const {
 743   MemNode::dump_spec(st);
 744   if( !Verbose && !WizardMode ) {
 745     // standard dump does this in Verbose and WizardMode
 746     st->print(" #"); _type->dump_on(st);
 747   }
 748   if (!depends_only_on_test()) {
 749     st->print(" (does not depend only on test)");
 750   }
 751 }
 752 #endif
 753 
 754 #ifdef ASSERT
 755 //----------------------------is_immutable_value-------------------------------
 756 // Helper function to allow a raw load without control edge for some cases
 757 bool LoadNode::is_immutable_value(Node* adr) {
 758   return (adr->is_AddP() && adr->in(AddPNode::Base)->is_top() &&
 759           adr->in(AddPNode::Address)->Opcode() == Opcodes::Op_ThreadLocal &&
 760           (adr->in(AddPNode::Offset)->find_intptr_t_con(-1) ==
 761            in_bytes(JavaThread::osthread_offset())));
 762 }
 763 #endif
 764 
 765 //----------------------------LoadNode::make-----------------------------------
 766 // Polymorphic factory method:
 767 Node *LoadNode::make(PhaseGVN& gvn, Node *ctl, Node *mem, Node *adr, const TypePtr* adr_type, const Type *rt, BasicType bt, MemOrd mo,
 768                      ControlDependency control_dependency, bool unaligned, bool mismatched) {
 769   Compile* C = gvn.C;
 770 
 771   // sanity check the alias category against the created node type
 772   assert(!(adr_type->isa_oopptr() &&
 773            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
 774          "use LoadKlassNode instead");
 775   assert(!(adr_type->isa_aryptr() &&
 776            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 777          "use LoadRangeNode instead");
 778   // Check control edge of raw loads
 779   assert( ctl != NULL || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||


 793   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;
 794   case T_OBJECT:
 795 #ifdef _LP64
 796     if (adr->bottom_type()->is_ptr_to_narrowoop()) {
 797       load = new LoadNNode(ctl, mem, adr, adr_type, rt->make_narrowoop(), mo, control_dependency);
 798     } else
 799 #endif
 800     {
 801       assert(!adr->bottom_type()->is_ptr_to_narrowoop() && !adr->bottom_type()->is_ptr_to_narrowklass(), "should have got back a narrow oop");
 802       load = new LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr(), mo, control_dependency);
 803     }
 804     break;
 805   }
 806   assert(load != NULL, "LoadNode should have been created");
 807   if (unaligned) {
 808     load->set_unaligned_access();
 809   }
 810   if (mismatched) {
 811     load->set_mismatched_access();
 812   }
 813   if (load->Opcode() == Opcodes::Op_LoadN) {
 814     Node* ld = gvn.transform(load);
 815     return new DecodeNNode(ld, ld->bottom_type()->make_ptr());
 816   }
 817 
 818   return load;
 819 }
 820 
 821 LoadLNode* LoadLNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo,
 822                                   ControlDependency control_dependency, bool unaligned, bool mismatched) {
 823   bool require_atomic = true;
 824   LoadLNode* load = new LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic);
 825   if (unaligned) {
 826     load->set_unaligned_access();
 827   }
 828   if (mismatched) {
 829     load->set_mismatched_access();
 830   }
 831   return load;
 832 }
 833 


 933 // of aliasing.
 934 Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const {
 935   Node* ld_adr = in(MemNode::Address);
 936   intptr_t ld_off = 0;
 937   AllocateNode* ld_alloc = AllocateNode::Ideal_allocation(ld_adr, phase, ld_off);
 938   const TypeInstPtr* tp = phase->type(ld_adr)->isa_instptr();
 939   Compile::AliasType* atp = (tp != NULL) ? phase->C->alias_type(tp) : NULL;
 940   // This is more general than load from boxing objects.
 941   if (skip_through_membars(atp, tp, phase->C->eliminate_boxing())) {
 942     uint alias_idx = atp->index();
 943     bool final = !atp->is_rewritable();
 944     Node* result = NULL;
 945     Node* current = st;
 946     // Skip through chains of MemBarNodes checking the MergeMems for
 947     // new states for the slice of this load.  Stop once any other
 948     // kind of node is encountered.  Loads from final memory can skip
 949     // through any kind of MemBar but normal loads shouldn't skip
 950     // through MemBarAcquire since the could allow them to move out of
 951     // a synchronized region.
 952     while (current->is_Proj()) {
 953       Opcodes opc = current->in(0)->Opcode();
 954       if ((final && (opc == Opcodes::Op_MemBarAcquire ||
 955                      opc == Opcodes::Op_MemBarAcquireLock ||
 956                      opc == Opcodes::Op_LoadFence)) ||
 957           opc == Opcodes::Op_MemBarRelease ||
 958           opc == Opcodes::Op_StoreFence ||
 959           opc == Opcodes::Op_MemBarReleaseLock ||
 960           opc == Opcodes::Op_MemBarStoreStore ||
 961           opc == Opcodes::Op_MemBarCPUOrder) {
 962         Node* mem = current->in(0)->in(TypeFunc::Memory);
 963         if (mem->is_MergeMem()) {
 964           MergeMemNode* merge = mem->as_MergeMem();
 965           Node* new_st = merge->memory_at(alias_idx);
 966           if (new_st == merge->base_memory()) {
 967             // Keep searching
 968             current = new_st;
 969             continue;
 970           }
 971           // Save the new memory state for the slice and fall through
 972           // to exit.
 973           result = new_st;
 974         }
 975       }
 976       break;
 977     }
 978     if (result != NULL) {
 979       st = result;
 980     }
 981   }


1109       this_iid = base->_idx;
1110     }
1111     const Type* this_type = bottom_type();
1112     for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
1113       Node* phi = region->fast_out(i);
1114       if (phi->is_Phi() && phi != mem &&
1115           phi->as_Phi()->is_same_inst_field(this_type, this_iid, this_index, this_offset)) {
1116         return phi;
1117       }
1118     }
1119   }
1120 
1121   return this;
1122 }
1123 
1124 // Construct an equivalent unsigned load.
1125 Node* LoadNode::convert_to_unsigned_load(PhaseGVN& gvn) {
1126   BasicType bt = T_ILLEGAL;
1127   const Type* rt = NULL;
1128   switch (Opcode()) {
1129     case Opcodes::Op_LoadUB: return this;
1130     case Opcodes::Op_LoadUS: return this;
1131     case Opcodes::Op_LoadB: bt = T_BOOLEAN; rt = TypeInt::UBYTE; break;
1132     case Opcodes::Op_LoadS: bt = T_CHAR;    rt = TypeInt::CHAR;  break;
1133     default:
1134       assert(false, "no unsigned variant: %s", Name());
1135       return NULL;
1136   }
1137   return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address),
1138                         raw_adr_type(), rt, bt, _mo, _control_dependency,
1139                         is_unaligned_access(), is_mismatched_access());
1140 }
1141 
1142 // Construct an equivalent signed load.
1143 Node* LoadNode::convert_to_signed_load(PhaseGVN& gvn) {
1144   BasicType bt = T_ILLEGAL;
1145   const Type* rt = NULL;
1146   switch (Opcode()) {
1147     case Opcodes::Op_LoadUB: bt = T_BYTE;  rt = TypeInt::BYTE;  break;
1148     case Opcodes::Op_LoadUS: bt = T_SHORT; rt = TypeInt::SHORT; break;
1149     case Opcodes::Op_LoadB: // fall through
1150     case Opcodes::Op_LoadS: // fall through
1151     case Opcodes::Op_LoadI: // fall through
1152     case Opcodes::Op_LoadL: return this;
1153     default:
1154       assert(false, "no signed variant: %s", Name());
1155       return NULL;
1156   }
1157   return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address),
1158                         raw_adr_type(), rt, bt, _mo, _control_dependency,
1159                         is_unaligned_access(), is_mismatched_access());
1160 }
1161 
1162 // We're loading from an object which has autobox behaviour.
1163 // If this object is result of a valueOf call we'll have a phi
1164 // merging a newly allocated object and a load from the cache.
1165 // We want to replace this load with the original incoming
1166 // argument to the valueOf call.
1167 Node* LoadNode::eliminate_autobox(PhaseGVN* phase) {
1168   assert(phase->C->eliminate_boxing(), "sanity");
1169   intptr_t ignore = 0;
1170   Node* base = AddPNode::Ideal_base_and_offset(in(Address), phase, ignore);
1171   if ((base == NULL) || base->is_Phi()) {
1172     // Push the loads from the phi that comes from valueOf up


1183     if (base->is_DecodeN()) {
1184       base = base->in(1);
1185     }
1186     if (!base->in(Address)->is_AddP()) {
1187       return NULL; // Complex address
1188     }
1189     AddPNode* address = base->in(Address)->as_AddP();
1190     Node* cache_base = address->in(AddPNode::Base);
1191     if ((cache_base != NULL) && cache_base->is_DecodeN()) {
1192       // Get ConP node which is static 'cache' field.
1193       cache_base = cache_base->in(1);
1194     }
1195     if ((cache_base != NULL) && cache_base->is_Con()) {
1196       const TypeAryPtr* base_type = cache_base->bottom_type()->isa_aryptr();
1197       if ((base_type != NULL) && base_type->is_autobox_cache()) {
1198         Node* elements[4];
1199         int shift = exact_log2(type2aelembytes(T_OBJECT));
1200         int count = address->unpack_offsets(elements, ARRAY_SIZE(elements));
1201         if ((count >  0) && elements[0]->is_Con() &&
1202             ((count == 1) ||
1203              (count == 2) && elements[1]->Opcode() == Opcodes::Op_LShiftX &&
1204                              elements[1]->in(2) == phase->intcon(shift))) {
1205           ciObjArray* array = base_type->const_oop()->as_obj_array();
1206           // Fetch the box object cache[0] at the base of the array and get its value
1207           ciInstance* box = array->obj_at(0)->as_instance();
1208           ciInstanceKlass* ik = box->klass()->as_instance_klass();
1209           assert(ik->is_box_klass(), "sanity");
1210           assert(ik->nof_nonstatic_fields() == 1, "change following code");
1211           if (ik->nof_nonstatic_fields() == 1) {
1212             // This should be true nonstatic_field_at requires calling
1213             // nof_nonstatic_fields so check it anyway
1214             ciConstant c = box->field_value(ik->nonstatic_field_at(0));
1215             BasicType bt = c.basic_type();
1216             // Only integer types have boxing cache.
1217             assert(bt == T_BOOLEAN || bt == T_CHAR  ||
1218                    bt == T_BYTE    || bt == T_SHORT ||
1219                    bt == T_INT     || bt == T_LONG, "wrong type = %s", type2name(bt));
1220             jlong cache_low = (bt == T_LONG) ? c.as_long() : c.as_int();
1221             if (cache_low != (int)cache_low) {
1222               return NULL; // should not happen since cache is array indexed by value
1223             }
1224             jlong offset = arrayOopDesc::base_offset_in_bytes(T_OBJECT) - (cache_low << shift);
1225             if (offset != (int)offset) {
1226               return NULL; // should not happen since cache is array indexed by value
1227             }
1228            // Add up all the offsets making of the address of the load
1229             Node* result = elements[0];
1230             for (int i = 1; i < count; i++) {
1231               result = phase->transform(new AddXNode(result, elements[i]));
1232             }
1233             // Remove the constant offset from the address and then
1234             result = phase->transform(new AddXNode(result, phase->MakeConX(-(int)offset)));
1235             // remove the scaling of the offset to recover the original index.
1236             if (result->Opcode() == Opcodes::Op_LShiftX && result->in(2) == phase->intcon(shift)) {
1237               // Peel the shift off directly but wrap it in a dummy node
1238               // since Ideal can't return existing nodes
1239               result = new RShiftXNode(result->in(1), phase->intcon(0));
1240             } else if (result->is_Add() && result->in(2)->is_Con() &&
1241                        result->in(1)->Opcode() == Opcodes::Op_LShiftX &&
1242                        result->in(1)->in(2) == phase->intcon(shift)) {
1243               // We can't do general optimization: ((X<<Z) + Y) >> Z ==> X + (Y>>Z)
1244               // but for boxing cache access we know that X<<Z will not overflow
1245               // (there is range check) so we do this optimizatrion by hand here.
1246               Node* add_con = new RShiftXNode(result->in(2), phase->intcon(shift));
1247               result = new AddXNode(result->in(1)->in(1), phase->transform(add_con));
1248             } else {
1249               result = new RShiftXNode(result, phase->intcon(shift));
1250             }
1251 #ifdef _LP64
1252             if (bt != T_LONG) {
1253               result = new ConvL2INode(phase->transform(result));
1254             }
1255 #else
1256             if (bt == T_LONG) {
1257               result = new ConvI2LNode(phase->transform(result));
1258             }
1259 #endif
1260             // Boxing/unboxing can be done from signed & unsigned loads (e.g. LoadUB -> ... -> LoadB pair).
1261             // Need to preserve unboxing load type if it is unsigned.
1262             switch(this->Opcode()) {
1263               case Opcodes::Op_LoadUB:
1264                 result = new AndINode(phase->transform(result), phase->intcon(0xFF));
1265                 break;
1266               case Opcodes::Op_LoadUS:
1267                 result = new AndINode(phase->transform(result), phase->intcon(0xFFFF));
1268                 break;
1269             }
1270             return result;
1271           }
1272         }
1273       }
1274     }
1275   }
1276   return NULL;
1277 }
1278 
1279 static bool stable_phi(PhiNode* phi, PhaseGVN *phase) {
1280   Node* region = phi->in(0);
1281   if (region == NULL) {
1282     return false; // Wait stable graph
1283   }
1284   uint cnt = phi->req();
1285   for (uint i = 1; i < cnt; i++) {
1286     Node* rc = region->in(i);


1468   // Record Phi
1469   igvn->register_new_node_with_optimizer(phi);
1470   return phi;
1471 }
1472 
1473 //------------------------------Ideal------------------------------------------
1474 // If the load is from Field memory and the pointer is non-null, it might be possible to
1475 // zero out the control input.
1476 // If the offset is constant and the base is an object allocation,
1477 // try to hook me up to the exact initializing store.
1478 Node *LoadNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1479   Node* p = MemNode::Ideal_common(phase, can_reshape);
1480   if (p)  return (p == NodeSentinel) ? NULL : p;
1481 
1482   Node* ctrl    = in(MemNode::Control);
1483   Node* address = in(MemNode::Address);
1484   bool progress = false;
1485 
1486   // Skip up past a SafePoint control.  Cannot do this for Stores because
1487   // pointer stores & cardmarks must stay on the same side of a SafePoint.
1488   if( ctrl != NULL && ctrl->Opcode() == Opcodes::Op_SafePoint &&
1489       phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw ) {
1490     ctrl = ctrl->in(0);
1491     set_req(MemNode::Control,ctrl);
1492     progress = true;
1493   }
1494 
1495   intptr_t ignore = 0;
1496   Node*    base   = AddPNode::Ideal_base_and_offset(address, phase, ignore);
1497   if (base != NULL
1498       && phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw) {
1499     // Check for useless control edge in some common special cases
1500     if (in(MemNode::Control) != NULL
1501         && can_remove_control()
1502         && phase->type(base)->higher_equal(TypePtr::NOTNULL)
1503         && all_controls_dominate(base, phase->C->start())) {
1504       // A method-invariant, non-null address (constant or 'this' argument).
1505       set_req(MemNode::Control, NULL);
1506       progress = true;
1507     }
1508   }


1587     // Fold-up might require truncation (for LoadB/LoadS/LoadUS) or
1588     // just return a prior value, which is done by Identity calls.
1589     if (can_see_stored_value(prev_mem, phase)) {
1590       // Make ready for step (d):
1591       set_req(MemNode::Memory, prev_mem);
1592       return this;
1593     }
1594   }
1595 
1596   return progress ? this : NULL;
1597 }
1598 
1599 // Helper to recognize certain Klass fields which are invariant across
1600 // some group of array types (e.g., int[] or all T[] where T < Object).
1601 const Type*
1602 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
1603                                  ciKlass* klass) const {
1604   if (tkls->offset() == in_bytes(Klass::modifier_flags_offset())) {
1605     // The field is Klass::_modifier_flags.  Return its (constant) value.
1606     // (Folds up the 2nd indirection in aClassConstant.getModifiers().)
1607     assert(this->Opcode() == Opcodes::Op_LoadI, "must load an int from _modifier_flags");
1608     return TypeInt::make(klass->modifier_flags());
1609   }
1610   if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
1611     // The field is Klass::_access_flags.  Return its (constant) value.
1612     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1613     assert(this->Opcode() == Opcodes::Op_LoadI, "must load an int from _access_flags");
1614     return TypeInt::make(klass->access_flags());
1615   }
1616   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1617     // The field is Klass::_layout_helper.  Return its constant value if known.
1618     assert(this->Opcode() == Opcodes::Op_LoadI, "must load an int from _layout_helper");
1619     return TypeInt::make(klass->layout_helper());
1620   }
1621 
1622   // No match.
1623   return NULL;
1624 }
1625 
1626 //------------------------------Value-----------------------------------------
1627 const Type* LoadNode::Value(PhaseGVN* phase) const {
1628   // Either input is TOP ==> the result is TOP
1629   Node* mem = in(MemNode::Memory);
1630   const Type *t1 = phase->type(mem);
1631   if (t1 == Type::TOP)  return Type::TOP;
1632   Node* adr = in(MemNode::Address);
1633   const TypePtr* tp = phase->type(adr)->isa_ptr();
1634   if (tp == NULL || tp->empty())  return Type::TOP;
1635   int off = tp->offset();
1636   assert(off != Type::OffsetTop, "case covered by TypePtr::empty");
1637   Compile* C = phase->C;
1638 


1665       }
1666     }
1667 
1668     // Don't do this for integer types. There is only potential profit if
1669     // the element type t is lower than _type; that is, for int types, if _type is
1670     // more restrictive than t.  This only happens here if one is short and the other
1671     // char (both 16 bits), and in those cases we've made an intentional decision
1672     // to use one kind of load over the other. See AndINode::Ideal and 4965907.
1673     // Also, do not try to narrow the type for a LoadKlass, regardless of offset.
1674     //
1675     // Yes, it is possible to encounter an expression like (LoadKlass p1:(AddP x x 8))
1676     // where the _gvn.type of the AddP is wider than 8.  This occurs when an earlier
1677     // copy p0 of (AddP x x 8) has been proven equal to p1, and the p0 has been
1678     // subsumed by p1.  If p1 is on the worklist but has not yet been re-transformed,
1679     // it is possible that p1 will have a type like Foo*[int+]:NotNull*+any.
1680     // In fact, that could have been the original type of p1, and p1 could have
1681     // had an original form like p1:(AddP x x (LShiftL quux 3)), where the
1682     // expression (LShiftL quux 3) independently optimized to the constant 8.
1683     if ((t->isa_int() == NULL) && (t->isa_long() == NULL)
1684         && (_type->isa_vect() == NULL)
1685         && Opcode() != Opcodes::Op_LoadKlass && Opcode() != Opcodes::Op_LoadNKlass) {
1686       // t might actually be lower than _type, if _type is a unique
1687       // concrete subclass of abstract class t.
1688       if (off_beyond_header) {  // is the offset beyond the header?
1689         const Type* jt = t->join_speculative(_type);
1690         // In any case, do not allow the join, per se, to empty out the type.
1691         if (jt->empty() && !t->empty()) {
1692           // This can happen if a interface-typed array narrows to a class type.
1693           jt = _type;
1694         }
1695 #ifdef ASSERT
1696         if (phase->C->eliminate_boxing() && adr->is_AddP()) {
1697           // The pointers in the autobox arrays are always non-null
1698           Node* base = adr->in(AddPNode::Base);
1699           if ((base != NULL) && base->is_DecodeN()) {
1700             // Get LoadN node which loads IntegerCache.cache field
1701             base = base->in(1);
1702           }
1703           if ((base != NULL) && base->is_Con()) {
1704             const TypeAryPtr* base_type = base->bottom_type()->isa_aryptr();
1705             if ((base_type != NULL) && base_type->is_autobox_cache()) {


1720             // arrays can be cast to Objects
1721             tp->is_oopptr()->klass()->is_java_lang_Object() ||
1722             // unsafe field access may not have a constant offset
1723             C->has_unsafe_access(),
1724             "Field accesses must be precise" );
1725     // For oop loads, we expect the _type to be precise.
1726     // Optimizations for constant objects
1727     ciObject* const_oop = tinst->const_oop();
1728     if (const_oop != NULL && const_oop->is_instance()) {
1729       const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type());
1730       if (con_type != NULL) {
1731         return con_type;
1732       }
1733     }
1734   } else if (tp->base() == Type::KlassPtr) {
1735     assert( off != Type::OffsetBot ||
1736             // arrays can be cast to Objects
1737             tp->is_klassptr()->klass()->is_java_lang_Object() ||
1738             // also allow array-loading from the primary supertype
1739             // array during subtype checks
1740             Opcode() == Opcodes::Op_LoadKlass,
1741             "Field accesses must be precise" );
1742     // For klass/static loads, we expect the _type to be precise
1743   }
1744 
1745   const TypeKlassPtr *tkls = tp->isa_klassptr();
1746   if (tkls != NULL && !StressReflectiveCode) {
1747     ciKlass* klass = tkls->klass();
1748     if (klass->is_loaded() && tkls->klass_is_exact()) {
1749       // We are loading a field from a Klass metaobject whose identity
1750       // is known at compile time (the type is "exact" or "precise").
1751       // Check for fields we know are maintained as constants by the VM.
1752       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
1753         // The field is Klass::_super_check_offset.  Return its (constant) value.
1754         // (Folds up type checking code.)
1755         assert(Opcode() == Opcodes::Op_LoadI, "must load an int from _super_check_offset");
1756         return TypeInt::make(klass->super_check_offset());
1757       }
1758       // Compute index into primary_supers array
1759       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
1760       // Check for overflowing; use unsigned compare to handle the negative case.
1761       if( depth < ciKlass::primary_super_limit() ) {
1762         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
1763         // (Folds up type checking code.)
1764         assert(Opcode() == Opcodes::Op_LoadKlass, "must load a klass from _primary_supers");
1765         ciKlass *ss = klass->super_of_depth(depth);
1766         return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR;
1767       }
1768       const Type* aift = load_array_final_field(tkls, klass);
1769       if (aift != NULL)  return aift;
1770       if (tkls->offset() == in_bytes(Klass::java_mirror_offset())) {
1771         // The field is Klass::_java_mirror.  Return its (constant) value.
1772         // (Folds up the 2nd indirection in anObjConstant.getClass().)
1773         assert(Opcode() == Opcodes::Op_LoadP, "must load an oop from _java_mirror");
1774         return TypeInstPtr::make(klass->java_mirror());
1775       }
1776     }
1777 
1778     // We can still check if we are loading from the primary_supers array at a
1779     // shallow enough depth.  Even though the klass is not exact, entries less
1780     // than or equal to its super depth are correct.
1781     if (klass->is_loaded() ) {
1782       ciType *inner = klass;
1783       while( inner->is_obj_array_klass() )
1784         inner = inner->as_obj_array_klass()->base_element_type();
1785       if( inner->is_instance_klass() &&
1786           !inner->as_instance_klass()->flags().is_interface() ) {
1787         // Compute index into primary_supers array
1788         juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
1789         // Check for overflowing; use unsigned compare to handle the negative case.
1790         if( depth < ciKlass::primary_super_limit() &&
1791             depth <= klass->super_depth() ) { // allow self-depth checks to handle self-check case
1792           // The field is an element of Klass::_primary_supers.  Return its (constant) value.
1793           // (Folds up type checking code.)
1794           assert(Opcode() == Opcodes::Op_LoadKlass, "must load a klass from _primary_supers");
1795           ciKlass *ss = klass->super_of_depth(depth);
1796           return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR;
1797         }
1798       }
1799     }
1800 
1801     // If the type is enough to determine that the thing is not an array,
1802     // we can give the layout_helper a positive interval type.
1803     // This will help short-circuit some reflective code.
1804     if (tkls->offset() == in_bytes(Klass::layout_helper_offset())
1805         && !klass->is_array_klass() // not directly typed as an array
1806         && !klass->is_interface()  // specifically not Serializable & Cloneable
1807         && !klass->is_java_lang_Object()   // not the supertype of all T[]
1808         ) {
1809       // Note:  When interfaces are reliable, we can narrow the interface
1810       // test to (klass != Serializable && klass != Cloneable).
1811       assert(Opcode() == Opcodes::Op_LoadI, "must load an int from _layout_helper");
1812       jint min_size = Klass::instance_layout_helper(oopDesc::header_size(), false);
1813       // The key property of this type is that it folds up tests
1814       // for array-ness, since it proves that the layout_helper is positive.
1815       // Thus, a generic value like the basic object layout helper works fine.
1816       return TypeInt::make(min_size, max_jint, Type::WidenMin);
1817     }
1818   }
1819 
1820   // If we are loading from a freshly-allocated object, produce a zero,
1821   // if the load is provably beyond the header of the object.
1822   // (Also allow a variable load from a fresh array to produce zero.)
1823   const TypeOopPtr *tinst = tp->isa_oopptr();
1824   bool is_instance = (tinst != NULL) && tinst->is_known_instance_field();
1825   bool is_boxed_value = (tinst != NULL) && tinst->is_ptr_to_boxed_value();
1826   if (ReduceFieldZeroing || is_instance || is_boxed_value) {
1827     Node* value = can_see_stored_value(mem,phase);
1828     if (value != NULL && value->is_Con()) {
1829       assert(value->bottom_type()->higher_equal(_type),"sanity");
1830       return value->bottom_type();
1831     }


2372 // try to capture it into the initialization, or hoist it above.
2373 Node *StoreNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2374   Node* p = MemNode::Ideal_common(phase, can_reshape);
2375   if (p)  return (p == NodeSentinel) ? NULL : p;
2376 
2377   Node* mem     = in(MemNode::Memory);
2378   Node* address = in(MemNode::Address);
2379   // Back-to-back stores to same address?  Fold em up.  Generally
2380   // unsafe if I have intervening uses...  Also disallowed for StoreCM
2381   // since they must follow each StoreP operation.  Redundant StoreCMs
2382   // are eliminated just before matching in final_graph_reshape.
2383   {
2384     Node* st = mem;
2385     // If Store 'st' has more than one use, we cannot fold 'st' away.
2386     // For example, 'st' might be the final state at a conditional
2387     // return.  Or, 'st' might be used by some node which is live at
2388     // the same time 'st' is live, which might be unschedulable.  So,
2389     // require exactly ONE user until such time as we clone 'mem' for
2390     // each of 'mem's uses (thus making the exactly-1-user-rule hold
2391     // true).
2392     while (st->is_Store() && st->outcnt() == 1 && st->Opcode() != Opcodes::Op_StoreCM) {
2393       // Looking at a dead closed cycle of memory?
2394       assert(st != st->in(MemNode::Memory), "dead loop in StoreNode::Ideal");
2395       assert(Opcode() == st->Opcode() ||
2396              st->Opcode() == Opcodes::Op_StoreVector ||
2397              Opcode() == Opcodes::Op_StoreVector ||
2398              phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw ||
2399              (Opcode() == Opcodes::Op_StoreL && st->Opcode() == Opcodes::Op_StoreI) || // expanded ClearArrayNode
2400              (is_mismatched_access() || st->as_Store()->is_mismatched_access()),
2401              "no mismatched stores, except on raw memory: %s %s", NodeClassNames[static_cast<uint>(Opcode())], NodeClassNames[static_cast<uint>(st->Opcode())]);
2402 
2403       if (st->in(MemNode::Address)->eqv_uncast(address) &&
2404           st->as_Store()->memory_size() <= this->memory_size()) {
2405         Node* use = st->raw_out(0);
2406         phase->igvn_rehash_node_delayed(use);
2407         if (can_reshape) {
2408           use->set_req_X(MemNode::Memory, st->in(MemNode::Memory), phase->is_IterGVN());
2409         } else {
2410           // It's OK to do this in the parser, since DU info is always accurate,
2411           // and the parser always refers to nodes via SafePointNode maps.
2412           use->set_req(MemNode::Memory, st->in(MemNode::Memory));
2413         }
2414         return this;
2415       }
2416       st = st->in(MemNode::Memory);
2417     }
2418   }
2419 
2420 
2421   // Capture an unaliased, unconditional, simple store into an initializer.


2504 //------------------------------match_edge-------------------------------------
2505 // Do we Match on this edge index or not?  Match only memory & value
2506 uint StoreNode::match_edge(uint idx) const {
2507   return idx == MemNode::Address || idx == MemNode::ValueIn;
2508 }
2509 
2510 //------------------------------cmp--------------------------------------------
2511 // Do not common stores up together.  They generally have to be split
2512 // back up anyways, so do not bother.
2513 uint StoreNode::cmp( const Node &n ) const {
2514   return (&n == this);          // Always fail except on self
2515 }
2516 
2517 //------------------------------Ideal_masked_input-----------------------------
2518 // Check for a useless mask before a partial-word store
2519 // (StoreB ... (AndI valIn conIa) )
2520 // If (conIa & mask == mask) this simplifies to
2521 // (StoreB ... (valIn) )
2522 Node *StoreNode::Ideal_masked_input(PhaseGVN *phase, uint mask) {
2523   Node *val = in(MemNode::ValueIn);
2524   if( val->Opcode() == Opcodes::Op_AndI ) {
2525     const TypeInt *t = phase->type( val->in(2) )->isa_int();
2526     if( t && t->is_con() && (t->get_con() & mask) == mask ) {
2527       set_req(MemNode::ValueIn, val->in(1));
2528       return this;
2529     }
2530   }
2531   return NULL;
2532 }
2533 
2534 
2535 //------------------------------Ideal_sign_extended_input----------------------
2536 // Check for useless sign-extension before a partial-word store
2537 // (StoreB ... (RShiftI _ (LShiftI _ valIn conIL ) conIR) )
2538 // If (conIL == conIR && conIR <= num_bits)  this simplifies to
2539 // (StoreB ... (valIn) )
2540 Node *StoreNode::Ideal_sign_extended_input(PhaseGVN *phase, int num_bits) {
2541   Node *val = in(MemNode::ValueIn);
2542   if( val->Opcode() == Opcodes::Op_RShiftI ) {
2543     const TypeInt *t = phase->type( val->in(2) )->isa_int();
2544     if( t && t->is_con() && (t->get_con() <= num_bits) ) {
2545       Node *shl = val->in(1);
2546       if( shl->Opcode() == Opcodes::Op_LShiftI ) {
2547         const TypeInt *t2 = phase->type( shl->in(2) )->isa_int();
2548         if( t2 && t2->is_con() && (t2->get_con() == t->get_con()) ) {
2549           set_req(MemNode::ValueIn, shl->in(1));
2550           return this;
2551         }
2552       }
2553     }
2554   }
2555   return NULL;
2556 }
2557 
2558 //------------------------------value_never_loaded-----------------------------------
2559 // Determine whether there are any possible loads of the value stored.
2560 // For simplicity, we actually check if there are any loads from the
2561 // address stored to, not just for loads of the value stored by this node.
2562 //
2563 bool StoreNode::value_never_loaded( PhaseTransform *phase) const {
2564   Node *adr = in(Address);
2565   const TypeOopPtr *adr_oop = phase->type(adr)->isa_oopptr();
2566   if (adr_oop == NULL)


2658 //----------------------------------SCMemProjNode------------------------------
2659 const Type* SCMemProjNode::Value(PhaseGVN* phase) const
2660 {
2661   return bottom_type();
2662 }
2663 
2664 //=============================================================================
2665 //----------------------------------LoadStoreNode------------------------------
2666 LoadStoreNode::LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required )
2667   : Node(required),
2668     _type(rt),
2669     _adr_type(at)
2670 {
2671   init_req(MemNode::Control, c  );
2672   init_req(MemNode::Memory , mem);
2673   init_req(MemNode::Address, adr);
2674   init_req(MemNode::ValueIn, val);
2675   init_class_id(Class_LoadStore);
2676 }
2677 
2678 Opcodes LoadStoreNode::ideal_reg() const {
2679   return _type->ideal_reg();
2680 }
2681 
2682 bool LoadStoreNode::result_not_used() const {
2683   for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
2684     Node *x = fast_out(i);
2685     if (x->Opcode() == Opcodes::Op_SCMemProj) continue;
2686     return false;
2687   }
2688   return true;
2689 }
2690 
2691 uint LoadStoreNode::size_of() const { return sizeof(*this); }
2692 
2693 //=============================================================================
2694 //----------------------------------LoadStoreConditionalNode--------------------
2695 LoadStoreConditionalNode::LoadStoreConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex ) : LoadStoreNode(c, mem, adr, val, NULL, TypeInt::BOOL, 5) {
2696   init_req(ExpectedIn, ex );
2697 }
2698 
2699 //=============================================================================
2700 //-------------------------------adr_type--------------------------------------
2701 const TypePtr* ClearArrayNode::adr_type() const {
2702   Node *adr = in(3);
2703   if (adr == NULL)  return NULL; // node is dead
2704   return MemNode::calculate_adr_type(adr->bottom_type());
2705 }


2732   // Clearing nothing uses the Identity call.
2733   // Negative clears are possible on dead ClearArrays
2734   // (see jck test stmt114.stmt11402.val).
2735   if (size <= 0 || size % unit != 0)  return NULL;
2736   intptr_t count = size / unit;
2737   // Length too long; communicate this to matchers and assemblers.
2738   // Assemblers are responsible to produce fast hardware clears for it.
2739   if (size > InitArrayShortSize) {
2740     return new ClearArrayNode(in(0), in(1), in(2), in(3), true);
2741   }
2742   Node *mem = in(1);
2743   if( phase->type(mem)==Type::TOP ) return NULL;
2744   Node *adr = in(3);
2745   const Type* at = phase->type(adr);
2746   if( at==Type::TOP ) return NULL;
2747   const TypePtr* atp = at->isa_ptr();
2748   // adjust atp to be the correct array element address type
2749   if (atp == NULL)  atp = TypePtr::BOTTOM;
2750   else              atp = atp->add_offset(Type::OffsetBot);
2751   // Get base for derived pointer purposes
2752   if( adr->Opcode() != Opcodes::Op_AddP ) Unimplemented();
2753   Node *base = adr->in(1);
2754 
2755   Node *zero = phase->makecon(TypeLong::ZERO);
2756   Node *off  = phase->MakeConX(BytesPerLong);
2757   mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false);
2758   count--;
2759   while( count-- ) {
2760     mem = phase->transform(mem);
2761     adr = phase->transform(new AddPNode(base,adr,off));
2762     mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false);
2763   }
2764   return mem;
2765 }
2766 
2767 //----------------------------step_through----------------------------------
2768 // Return allocation input memory edge if it is different instance
2769 // or itself if it is the one we are looking for.
2770 bool ClearArrayNode::step_through(Node** np, uint instance_id, PhaseTransform* phase) {
2771   Node* n = *np;
2772   assert(n->is_ClearArray(), "sanity");


2874 MemBarNode::MemBarNode(Compile* C, int alias_idx, Node* precedent)
2875   : MultiNode(TypeFunc::Parms + (precedent == NULL? 0: 1)),
2876     _adr_type(C->get_adr_type(alias_idx))
2877 {
2878   init_class_id(Class_MemBar);
2879   Node* top = C->top();
2880   init_req(TypeFunc::I_O,top);
2881   init_req(TypeFunc::FramePtr,top);
2882   init_req(TypeFunc::ReturnAdr,top);
2883   if (precedent != NULL)
2884     init_req(TypeFunc::Parms, precedent);
2885 }
2886 
2887 //------------------------------cmp--------------------------------------------
2888 uint MemBarNode::hash() const { return NO_HASH; }
2889 uint MemBarNode::cmp( const Node &n ) const {
2890   return (&n == this);          // Always fail except on self
2891 }
2892 
2893 //------------------------------make-------------------------------------------
2894 MemBarNode* MemBarNode::make(Compile* C, Opcodes opcode, int atp, Node* pn) {
2895   switch (opcode) {
2896   case Opcodes::Op_MemBarAcquire:     return new MemBarAcquireNode(C, atp, pn);
2897   case Opcodes::Op_LoadFence:         return new LoadFenceNode(C, atp, pn);
2898   case Opcodes::Op_MemBarRelease:     return new MemBarReleaseNode(C, atp, pn);
2899   case Opcodes::Op_StoreFence:        return new StoreFenceNode(C, atp, pn);
2900   case Opcodes::Op_MemBarAcquireLock: return new MemBarAcquireLockNode(C, atp, pn);
2901   case Opcodes::Op_MemBarReleaseLock: return new MemBarReleaseLockNode(C, atp, pn);
2902   case Opcodes::Op_MemBarVolatile:    return new MemBarVolatileNode(C, atp, pn);
2903   case Opcodes::Op_MemBarCPUOrder:    return new MemBarCPUOrderNode(C, atp, pn);
2904   case Opcodes::Op_OnSpinWait:        return new OnSpinWaitNode(C, atp, pn);
2905   case Opcodes::Op_Initialize:        return new InitializeNode(C, atp, pn);
2906   case Opcodes::Op_MemBarStoreStore:  return new MemBarStoreStoreNode(C, atp, pn);
2907   default: ShouldNotReachHere(); return NULL;
2908   }
2909 }
2910 
2911 //------------------------------Ideal------------------------------------------
2912 // Return a node which is more "ideal" than the current node.  Strip out
2913 // control copies
2914 Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2915   if (remove_dead_region(phase, can_reshape)) return this;
2916   // Don't bother trying to transform a dead node
2917   if (in(0) && in(0)->is_top()) {
2918     return NULL;
2919   }
2920 
2921   bool progress = false;
2922   // Eliminate volatile MemBars for scalar replaced objects.
2923   if (can_reshape && req() == (Precedent+1)) {
2924     bool eliminate = false;
2925     Opcodes opc = Opcode();
2926     if ((opc == Opcodes::Op_MemBarAcquire || opc == Opcodes::Op_MemBarVolatile)) {
2927       // Volatile field loads and stores.
2928       Node* my_mem = in(MemBarNode::Precedent);
2929       // The MembarAquire may keep an unused LoadNode alive through the Precedent edge
2930       if ((my_mem != NULL) && (opc == Opcodes::Op_MemBarAcquire) && (my_mem->outcnt() == 1)) {
2931         // if the Precedent is a decodeN and its input (a Load) is used at more than one place,
2932         // replace this Precedent (decodeN) with the Load instead.
2933         if ((my_mem->Opcode() == Opcodes::Op_DecodeN) && (my_mem->in(1)->outcnt() > 1))  {
2934           Node* load_node = my_mem->in(1);
2935           set_req(MemBarNode::Precedent, load_node);
2936           phase->is_IterGVN()->_worklist.push(my_mem);
2937           my_mem = load_node;
2938         } else {
2939           assert(my_mem->unique_out() == this, "sanity");
2940           del_req(Precedent);
2941           phase->is_IterGVN()->_worklist.push(my_mem); // remove dead node later
2942           my_mem = NULL;
2943         }
2944         progress = true;
2945       }
2946       if (my_mem != NULL && my_mem->is_Mem()) {
2947         const TypeOopPtr* t_oop = my_mem->in(MemNode::Address)->bottom_type()->isa_oopptr();
2948         // Check for scalar replaced object reference.
2949         if( t_oop != NULL && t_oop->is_known_instance_field() &&
2950             t_oop->offset() != Type::OffsetBot &&
2951             t_oop->offset() != Type::OffsetTop) {
2952           eliminate = true;
2953         }
2954       }
2955     } else if (opc == Opcodes::Op_MemBarRelease) {
2956       // Final field stores.
2957       Node* alloc = AllocateNode::Ideal_allocation(in(MemBarNode::Precedent), phase);
2958       if ((alloc != NULL) && alloc->is_Allocate() &&
2959           alloc->as_Allocate()->does_not_escape_thread()) {
2960         // The allocated object does not escape.
2961         eliminate = true;
2962       }
2963     }
2964     if (eliminate) {
2965       // Replace MemBar projections by its inputs.
2966       PhaseIterGVN* igvn = phase->is_IterGVN();
2967       igvn->replace_node(proj_out(TypeFunc::Memory), in(TypeFunc::Memory));
2968       igvn->replace_node(proj_out(TypeFunc::Control), in(TypeFunc::Control));
2969       // Must return either the original node (now dead) or a new node
2970       // (Do not return a top here, since that would break the uniqueness of top.)
2971       return new ConINode(TypeInt::ZERO);
2972     }
2973   }
2974   return progress ? this : NULL;
2975 }
2976 
2977 //------------------------------Value------------------------------------------
2978 const Type* MemBarNode::Value(PhaseGVN* phase) const {
2979   if( !in(0) ) return Type::TOP;
2980   if( phase->type(in(0)) == Type::TOP )
2981     return Type::TOP;
2982   return TypeTuple::MEMBAR;
2983 }
2984 
2985 //------------------------------match------------------------------------------
2986 // Construct projections for memory.
2987 Node *MemBarNode::match( const ProjNode *proj, const Matcher *m ) {
2988   switch (proj->_con) {
2989   case TypeFunc::Control:
2990   case TypeFunc::Memory:
2991     return new MachProjNode(this,proj->_con,RegMask::Empty,static_cast<Opcodes>(MachProjNode::projType::unmatched_proj));
2992   }
2993   ShouldNotReachHere();
2994   return NULL;
2995 }
2996 
2997 //===========================InitializeNode====================================
2998 // SUMMARY:
2999 // This node acts as a memory barrier on raw memory, after some raw stores.
3000 // The 'cooked' oop value feeds from the Initialize, not the Allocation.
3001 // The Initialize can 'capture' suitably constrained stores as raw inits.
3002 // It can coalesce related raw stores into larger units (called 'tiles').
3003 // It can avoid zeroing new storage for memory units which have raw inits.
3004 // At macro-expansion, it is marked 'complete', and does not optimize further.
3005 //
3006 // EXAMPLE:
3007 // The object 'new short[2]' occupies 16 bytes in a 32-bit machine.
3008 //   ctl = incoming control; mem* = incoming memory
3009 // (Note:  A star * on a memory edge denotes I/O and other standard edges.)
3010 // First allocate uninitialized memory and fill in the header:
3011 //   alloc = (Allocate ctl mem* 16 #short[].klass ...)


3086 // reasonable limit on the complexity of optimized initializations.
3087 
3088 //---------------------------InitializeNode------------------------------------
3089 InitializeNode::InitializeNode(Compile* C, int adr_type, Node* rawoop)
3090   : _is_complete(Incomplete), _does_not_escape(false),
3091     MemBarNode(C, adr_type, rawoop)
3092 {
3093   init_class_id(Class_Initialize);
3094 
3095   assert(adr_type == Compile::AliasIdxRaw, "only valid atp");
3096   assert(in(RawAddress) == rawoop, "proper init");
3097   // Note:  allocation() can be NULL, for secondary initialization barriers
3098 }
3099 
3100 // Since this node is not matched, it will be processed by the
3101 // register allocator.  Declare that there are no constraints
3102 // on the allocation of the RawAddress edge.
3103 const RegMask &InitializeNode::in_RegMask(uint idx) const {
3104   // This edge should be set to top, by the set_complete.  But be conservative.
3105   if (idx == InitializeNode::RawAddress)
3106     return *(Compile::current()->matcher()->idealreg2spillmask[static_cast<uint>(in(idx)->ideal_reg())]);
3107   return RegMask::Empty;
3108 }
3109 
3110 Node* InitializeNode::memory(uint alias_idx) {
3111   Node* mem = in(Memory);
3112   if (mem->is_MergeMem()) {
3113     return mem->as_MergeMem()->memory_at(alias_idx);
3114   } else {
3115     // incoming raw memory is not split
3116     return mem;
3117   }
3118 }
3119 
3120 bool InitializeNode::is_non_zero() {
3121   if (is_complete())  return false;
3122   remove_extra_zeroes();
3123   return (req() > RawStores);
3124 }
3125 
3126 void InitializeNode::set_complete(PhaseGVN* phase) {


3568     if (st_off + st_size > size_limit)    break;
3569 
3570     // Record which bytes are touched, whether by constant or not.
3571     if (!store_constant(inits, num_tiles, st_off, st_size, (jlong) -1))
3572       continue;                 // skip (strange store size)
3573 
3574     const Type* val = phase->type(st->in(MemNode::ValueIn));
3575     if (!val->singleton())                continue; //skip (non-con store)
3576     BasicType type = val->basic_type();
3577 
3578     jlong con = 0;
3579     switch (type) {
3580     case T_INT:    con = val->is_int()->get_con();  break;
3581     case T_LONG:   con = val->is_long()->get_con(); break;
3582     case T_FLOAT:  con = jint_cast(val->getf());    break;
3583     case T_DOUBLE: con = jlong_cast(val->getd());   break;
3584     default:                              continue; //skip (odd store type)
3585     }
3586 
3587     if (type == T_LONG && Matcher::isSimpleConstant64(con) &&
3588         st->Opcode() == Opcodes::Op_StoreL) {
3589       continue;                 // This StoreL is already optimal.
3590     }
3591 
3592     // Store down the constant.
3593     store_constant(tiles, num_tiles, st_off, st_size, con);
3594 
3595     intptr_t j = st_off >> LogBytesPerLong;
3596 
3597     if (type == T_INT && st_size == BytesPerInt
3598         && (st_off & BytesPerInt) == BytesPerInt) {
3599       jlong lcon = tiles[j];
3600       if (!Matcher::isSimpleConstant64(lcon) &&
3601           st->Opcode() == Opcodes::Op_StoreI) {
3602         // This StoreI is already optimal by itself.
3603         jint* intcon = (jint*) &tiles[j];
3604         intcon[1] = 0;  // undo the store_constant()
3605 
3606         // If the previous store is also optimal by itself, back up and
3607         // undo the action of the previous loop iteration... if we can.
3608         // But if we can't, just let the previous half take care of itself.
3609         st = nodes[j];
3610         st_off -= BytesPerInt;
3611         con = intcon[0];
3612         if (con != 0 && st != NULL && st->Opcode() == Opcodes::Op_StoreI) {
3613           assert(st_off >= header_size, "still ignoring header");
3614           assert(get_store_offset(st, phase) == st_off, "must be");
3615           assert(in(i-1) == zmem, "must be");
3616           DEBUG_ONLY(const Type* tcon = phase->type(st->in(MemNode::ValueIn)));
3617           assert(con == tcon->is_int()->get_con(), "must be");
3618           // Undo the effects of the previous loop trip, which swallowed st:
3619           intcon[0] = 0;        // undo store_constant()
3620           set_req(i-1, st);     // undo set_req(i, zmem)
3621           nodes[j] = NULL;      // undo nodes[j] = st
3622           --old_subword;        // undo ++old_subword
3623         }
3624         continue;               // This StoreI is already optimal.
3625       }
3626     }
3627 
3628     // This store is not needed.
3629     set_req(i, zmem);
3630     nodes[j] = st;              // record for the moment
3631     if (st_size < BytesPerLong) // something has changed
3632           ++old_subword;        // includes int/float, but who's counting...


3915       last_tile_end = MAX2(last_tile_end, next_init_off);
3916     } else {
3917       intptr_t st_tile_end = align_size_up(next_init_off, BytesPerLong);
3918       assert(st_tile_end >= last_tile_end, "inits stay with tiles");
3919       assert(st_off      >= last_init_end, "inits do not overlap");
3920       last_init_end = next_init_off;  // it's a non-tile
3921     }
3922     #endif //ASSERT
3923   }
3924 
3925   remove_extra_zeroes();        // clear out all the zmems left over
3926   add_req(inits);
3927 
3928   if (!(UseTLAB && ZeroTLAB)) {
3929     // If anything remains to be zeroed, zero it all now.
3930     zeroes_done = align_size_down(zeroes_done, BytesPerInt);
3931     // if it is the last unused 4 bytes of an instance, forget about it
3932     intptr_t size_limit = phase->find_intptr_t_con(size_in_bytes, max_jint);
3933     if (zeroes_done + BytesPerLong >= size_limit) {
3934       assert(allocation() != NULL, "");
3935       if (allocation()->Opcode() == Opcodes::Op_Allocate) {
3936         Node* klass_node = allocation()->in(AllocateNode::KlassNode);
3937         ciKlass* k = phase->type(klass_node)->is_klassptr()->klass();
3938         if (zeroes_done == k->layout_helper())
3939           zeroes_done = size_limit;
3940       }
3941     }
3942     if (zeroes_done < size_limit) {
3943       rawmem = ClearArrayNode::clear_memory(rawctl, rawmem, rawptr,
3944                                             zeroes_done, size_in_bytes, phase);
3945     }
3946   }
3947 
3948   set_complete(phase);
3949   return rawmem;
3950 }
3951 
3952 
3953 #ifdef ASSERT
3954 bool InitializeNode::stores_are_sane(PhaseTransform* phase) {
3955   if (is_complete())


< prev index next >