hotspot/src/share/vm/opto/type.cpp
changeset 1398 342890a5d031
parent 1068 720698d9c89b
child 1497 cd3234c89e59
equal deleted inserted replaced
1137:26c7642c3642 1398:342890a5d031
  3155   return res;
  3155   return res;
  3156 }
  3156 }
  3157 
  3157 
  3158 // Narrow the given size type to the index range for the given array base type.
  3158 // Narrow the given size type to the index range for the given array base type.
  3159 // Return NULL if the resulting int type becomes empty.
  3159 // Return NULL if the resulting int type becomes empty.
  3160 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size, BasicType elem) {
  3160 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3161   jint hi = size->_hi;
  3161   jint hi = size->_hi;
  3162   jint lo = size->_lo;
  3162   jint lo = size->_lo;
  3163   jint min_lo = 0;
  3163   jint min_lo = 0;
  3164   jint max_hi = max_array_length(elem);
  3164   jint max_hi = max_array_length(elem()->basic_type());
  3165   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3165   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3166   bool chg = false;
  3166   bool chg = false;
  3167   if (lo < min_lo) { lo = min_lo; chg = true; }
  3167   if (lo < min_lo) { lo = min_lo; chg = true; }
  3168   if (hi > max_hi) { hi = max_hi; chg = true; }
  3168   if (hi > max_hi) { hi = max_hi; chg = true; }
       
  3169   // Negative length arrays will produce weird intermediate dead fath-path code
  3169   if (lo > hi)
  3170   if (lo > hi)
  3170     return NULL;
  3171     return TypeInt::ZERO;
  3171   if (!chg)
  3172   if (!chg)
  3172     return size;
  3173     return size;
  3173   return TypeInt::make(lo, hi, Type::WidenMin);
  3174   return TypeInt::make(lo, hi, Type::WidenMin);
  3174 }
  3175 }
  3175 
  3176 
  3176 //-------------------------------cast_to_size----------------------------------
  3177 //-------------------------------cast_to_size----------------------------------
  3177 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3178 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3178   assert(new_size != NULL, "");
  3179   assert(new_size != NULL, "");
  3179   new_size = narrow_size_type(new_size, elem()->basic_type());
  3180   new_size = narrow_size_type(new_size);
  3180   if (new_size == NULL)       // Negative length arrays will produce weird
       
  3181     new_size = TypeInt::ZERO; // intermediate dead fast-path goo
       
  3182   if (new_size == size())  return this;
  3181   if (new_size == size())  return this;
  3183   const TypeAry* new_ary = TypeAry::make(elem(), new_size);
  3182   const TypeAry* new_ary = TypeAry::make(elem(), new_size);
  3184   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3183   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3185 }
  3184 }
  3186 
  3185