< prev index next >

src/hotspot/share/opto/type.cpp

Print this page




1917 //=============================================================================
1918 // Convenience common pre-built types.
1919 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1920 const TypeTuple *TypeTuple::IFFALSE;
1921 const TypeTuple *TypeTuple::IFTRUE;
1922 const TypeTuple *TypeTuple::IFNEITHER;
1923 const TypeTuple *TypeTuple::LOOPBODY;
1924 const TypeTuple *TypeTuple::MEMBAR;
1925 const TypeTuple *TypeTuple::STORECONDITIONAL;
1926 const TypeTuple *TypeTuple::START_I2C;
1927 const TypeTuple *TypeTuple::INT_PAIR;
1928 const TypeTuple *TypeTuple::LONG_PAIR;
1929 const TypeTuple *TypeTuple::INT_CC_PAIR;
1930 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1931 
1932 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos) {
1933   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1934     ciField* field = vk->nonstatic_field_at(j);
1935     BasicType bt = field->type()->basic_type();
1936     const Type* ft = Type::get_const_type(field->type());
1937     if (bt == T_VALUETYPE) {
1938       ft = ft->isa_valuetypeptr()->cast_to_ptr_type(TypePtr::BotPTR);
1939     }
1940     field_array[pos++] = ft;
1941     if (bt == T_LONG || bt == T_DOUBLE) {
1942       field_array[pos++] = Type::HALF;
1943     }
1944   }
1945 }
1946 
1947 //------------------------------make-------------------------------------------
1948 // Make a TypeTuple from the range of a method signature
1949 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1950   ciType* return_type = sig->return_type();
1951   return make_range(return_type, ret_vt_fields);
1952 }
1953 
1954 const TypeTuple *TypeTuple::make_range(ciType* return_type, bool ret_vt_fields) {
1955   uint arg_cnt = 0;
1956   if (ret_vt_fields) {
1957     ret_vt_fields = return_type->is_valuetype() && ((ciValueKlass*)return_type)->can_be_returned_as_fields();
1958   }
1959   if (ret_vt_fields) {


1974     field_array[TypeFunc::Parms+1] = Type::HALF;
1975     break;
1976   case T_OBJECT:
1977   case T_ARRAY:
1978   case T_BOOLEAN:
1979   case T_CHAR:
1980   case T_FLOAT:
1981   case T_BYTE:
1982   case T_SHORT:
1983   case T_INT:
1984     field_array[TypeFunc::Parms] = get_const_type(return_type);
1985     break;
1986   case T_VALUETYPE:
1987     if (ret_vt_fields) {
1988       ciValueKlass* vk = (ciValueKlass*)return_type;
1989       uint pos = TypeFunc::Parms;
1990       field_array[pos] = TypePtr::BOTTOM;
1991       pos++;
1992       collect_value_fields(vk, field_array, pos);
1993     } else {
1994       field_array[TypeFunc::Parms] = get_const_type(return_type);

1995     }
1996     break;
1997   case T_VOID:
1998     break;
1999   default:
2000     ShouldNotReachHere();
2001   }
2002   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2003 }
2004 
2005 // Make a TypeTuple from the domain of a method signature
2006 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2007   uint arg_cnt = sig->size();
2008 
2009   int vt_extra = 0;
2010   if (vt_fields_as_args) {
2011     for (int i = 0; i < sig->count(); i++) {
2012       ciType* type = sig->type_at(i);
2013       if (type->basic_type() == T_VALUETYPE && !type->is__Value()) {
2014         assert(type->is_valuetype(), "inconsistent type");


2054       field_array[pos++] = Type::HALF;
2055       break;
2056     case T_OBJECT:
2057     case T_ARRAY:
2058     case T_FLOAT:
2059     case T_INT:
2060       field_array[pos++] = get_const_type(type);
2061       break;
2062     case T_BOOLEAN:
2063     case T_CHAR:
2064     case T_BYTE:
2065     case T_SHORT:
2066       field_array[pos++] = TypeInt::INT;
2067       break;
2068     case T_VALUETYPE: {
2069       assert(type->is_valuetype(), "inconsistent type");
2070       if (vt_fields_as_args && !type->is__Value()) {
2071         ciValueKlass* vk = (ciValueKlass*)type;
2072         collect_value_fields(vk, field_array, pos);
2073       } else {
2074         field_array[pos++] = get_const_type(type);

2075       }
2076       break;
2077     }
2078     default:
2079       ShouldNotReachHere();
2080     }
2081     i++;
2082   }
2083   assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2084 
2085   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2086 }
2087 
2088 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2089   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2090 }
2091 
2092 //------------------------------fields-----------------------------------------
2093 // Subroutine call type with space allocated for argument types
2094 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly


2199   }
2200   return false;
2201 }
2202 
2203 //=============================================================================
2204 // Convenience common pre-built types.
2205 
2206 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2207   // Certain normalizations keep us sane when comparing types.
2208   // We do not want arrayOop variables to differ only by the wideness
2209   // of their index types.  Pick minimum wideness, since that is the
2210   // forced wideness of small ranges anyway.
2211   if (size->_widen != Type::WidenMin)
2212     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2213   else
2214     return size;
2215 }
2216 
2217 //------------------------------make-------------------------------------------
2218 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {




2219   if (UseCompressedOops && elem->isa_oopptr()) {
2220     elem = elem->make_narrowoop();
2221   }
2222   size = normalize_array_size(size);
2223   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2224 }
2225 
2226 //------------------------------meet-------------------------------------------
2227 // Compute the MEET of two types.  It returns a new Type object.
2228 const Type *TypeAry::xmeet( const Type *t ) const {
2229   // Perform a fast test for common case; meeting the same types together.
2230   if( this == t ) return this;  // Meeting same type-rep?
2231 
2232   // Current "this->_base" is Ary
2233   switch (t->base()) {          // switch on original type
2234 
2235   case Bottom:                  // Ye Olde Default
2236     return t;
2237 
2238   default:                      // All else is a mistake


3350   case AryPtr:
3351     return t->xmeet(this);      // Call in reverse direction
3352 
3353   } // End of switch
3354   return this;                  // Return the double constant
3355 }
3356 
3357 
3358 //------------------------------xdual------------------------------------------
3359 // Dual of a pure heap pointer.  No relevant klass or oop information.
3360 const Type *TypeOopPtr::xdual() const {
3361   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3362   assert(const_oop() == NULL,             "no constants here");
3363   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3364 }
3365 
3366 //--------------------------make_from_klass_common-----------------------------
3367 // Computes the element-type given a klass.
3368 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3369   if (klass->is_valuetype()) {
3370     return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3371   } else if (klass->is_instance_klass()) {
3372     Compile* C = Compile::current();
3373     Dependencies* deps = C->dependencies();
3374     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3375     // Element is an instance
3376     bool klass_is_exact = false;
3377     if (klass->is_loaded()) {
3378       // Try to set klass_is_exact.
3379       ciInstanceKlass* ik = klass->as_instance_klass();
3380       klass_is_exact = ik->is_final();
3381       if (!klass_is_exact && klass_change
3382           && deps != NULL && UseUniqueSubclasses) {
3383         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3384         if (sub != NULL) {
3385           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3386           klass = ik = sub;
3387           klass_is_exact = sub->is_final();
3388         }
3389       }
3390       if (!klass_is_exact && try_for_exact


3400   } else if (klass->is_obj_array_klass()) {
3401     // Element is an object or value array. Recursively call ourself.
3402     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3403     bool xk = etype->klass_is_exact();
3404     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3405     // We used to pass NotNull in here, asserting that the sub-arrays
3406     // are all not-null.  This is not true in generally, as code can
3407     // slam NULLs down in the subarrays.
3408     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3409     return arr;
3410   } else if (klass->is_type_array_klass()) {
3411     // Element is an typeArray
3412     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3413     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3414     // We used to pass NotNull in here, asserting that the array pointer
3415     // is not-null. That was not true in general.
3416     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3417     return arr;
3418   } else if (klass->is_value_array_klass()) {
3419     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3420     const Type* etype = NULL;
3421     bool xk = false;
3422     if (vk->flatten_array()) {
3423       etype = TypeValueType::make(vk);
3424       xk = true;
3425     } else {
3426       const TypeOopPtr* etype_oop = TypeOopPtr::make_from_klass_common(vk, false, try_for_exact);
3427       xk = etype_oop->klass_is_exact();
3428       etype = etype_oop;
3429     }
3430     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3431     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3432     return arr;
3433   } else {
3434     ShouldNotReachHere();
3435     return NULL;
3436   }
3437 }
3438 
3439 //------------------------------make_from_constant-----------------------------
3440 // Make a java pointer from an oop constant
3441 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3442   assert(!o->is_null_object(), "null object not yet handled here.");
3443   ciKlass* klass = o->klass();
3444   if (klass->is_valuetype()) {
3445     // Element is a value type
3446     if (require_constant) {
3447       if (!o->can_be_constant())  return NULL;
3448     } else if (!o->should_be_constant()) {
3449       return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3450     }
3451     return TypeValueTypePtr::make(o);


4767         if (field == NULL) {
4768           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
4769           return add_offset(offset);
4770         } else {
4771           assert(_field_offset.get() <= 0, "should not have field_offset");
4772           return with_field_offset(field_offset)->add_offset(offset - field_offset);
4773         }
4774       }
4775     }
4776   }
4777   return add_offset(offset);
4778 }
4779 
4780 //=============================================================================
4781 
4782 
4783 //=============================================================================
4784 
4785 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4786 //------------------------------make-------------------------------------------
4787 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth, bool narrow) {
4788   return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4789 }
4790 
4791 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4792   return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4793 }
4794 
4795 //------------------------------cast_to_ptr_type-------------------------------
4796 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4797   if (ptr == _ptr) return this;
4798   return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4799 }
4800 
4801 //-----------------------------cast_to_instance_id----------------------------
4802 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4803   if (instance_id == _instance_id) return this;
4804   return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4805 }
4806 
4807 //------------------------------meet-------------------------------------------
4808 // Compute the MEET of two types.  It returns a new Type object.
4809 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const {
4810   // Perform a fast test for common case; meeting the same types together.
4811   if (this == t) return this;  // Meeting same type-rep?
4812 
4813   switch (t->base()) {          // switch on original type
4814     case Int:                     // Mixing ints & oops happens when javac
4815     case Long:                    // reuses local variables
4816     case FloatTop:
4817     case FloatCon:
4818     case FloatBot:
4819     case DoubleTop:
4820     case DoubleCon:
4821     case DoubleBot:
4822     case NarrowOop:
4823     case NarrowKlass:
4824     case Bottom:                  // Ye Olde Default


4831     case InstPtr:
4832       return TypePtr::BOTTOM;
4833 
4834     case Top:
4835       return this;
4836 
4837     default:                      // All else is a mistake
4838       typerr(t);
4839 
4840     case OopPtr: {
4841       // Found a OopPtr type vs self-ValueTypePtr type
4842       const TypeOopPtr* tp = t->is_oopptr();
4843       Offset offset = meet_offset(tp->offset());
4844       PTR ptr = meet_ptr(tp->ptr());
4845       int instance_id = meet_instance_id(tp->instance_id());
4846       const TypePtr* speculative = xmeet_speculative(tp);
4847       int depth = meet_inline_depth(tp->inline_depth());
4848       switch (tp->ptr()) {
4849       case TopPTR:
4850       case AnyNull: {
4851         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4852       }
4853       case NotNull:
4854       case BotPTR: {
4855         return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4856       }
4857       default: typerr(t);
4858       }
4859     }
4860 
4861     case AnyPtr: {
4862       // Found an AnyPtr type vs self-ValueTypePtr type
4863       const TypePtr* tp = t->is_ptr();
4864       Offset offset = meet_offset(tp->offset());
4865       PTR ptr = meet_ptr(tp->ptr());
4866       int instance_id = meet_instance_id(InstanceTop);
4867       const TypePtr* speculative = xmeet_speculative(tp);
4868       int depth = meet_inline_depth(tp->inline_depth());
4869       switch (tp->ptr()) {
4870       case Null:
4871         if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4872         // else fall through to AnyNull
4873       case TopPTR:
4874       case AnyNull: {
4875         return make(_vt, ptr, NULL, offset, instance_id, speculative, depth);
4876       }
4877       case NotNull:
4878       case BotPTR:
4879         return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4880       default: typerr(t);
4881       }
4882     }
4883 
4884     case ValueTypePtr: {
4885       // Found an ValueTypePtr type vs self-ValueTypePtr type
4886       const TypeValueTypePtr* tp = t->is_valuetypeptr();
4887       Offset offset = meet_offset(tp->offset());
4888       PTR ptr = meet_ptr(tp->ptr());
4889       int instance_id = meet_instance_id(InstanceTop);
4890       const TypePtr* speculative = xmeet_speculative(tp);
4891       int depth = meet_inline_depth(tp->inline_depth());
4892       // Compute constant oop
4893       ciObject* o = NULL;
4894       ciObject* this_oop  = const_oop();
4895       ciObject* tp_oop = tp->const_oop();
4896       const TypeValueType* vt = NULL;
4897       if (_vt != tp->_vt) {
4898         assert(is__Value() || tp->is__Value(), "impossible meet");
4899         if (above_centerline(ptr)) {
4900           vt = is__Value() ? tp->_vt : _vt;
4901         } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4902           vt = tp->_vt;
4903         } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4904           vt = _vt;
4905         } else {
4906           vt = is__Value() ? _vt : tp->_vt;
4907         }
4908       } else {
4909         vt = _vt;
4910       }
4911       if (ptr == Constant) {
4912         if (this_oop != NULL && tp_oop != NULL &&
4913             this_oop->equals(tp_oop) ) {
4914           o = this_oop;
4915         } else if (above_centerline(this ->_ptr)) {
4916           o = tp_oop;
4917         } else if (above_centerline(tp ->_ptr)) {
4918           o = this_oop;
4919         } else {
4920           ptr = NotNull;
4921         }
4922       }
4923       return make(vt, ptr, o, offset, instance_id, speculative, depth);
4924     }
4925     }
4926 }
4927 
4928 // Dual: compute field-by-field dual
4929 const Type* TypeValueTypePtr::xdual() const {
4930   return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4931 }
4932 
4933 //------------------------------eq---------------------------------------------
4934 // Structural equality check for Type representations
4935 bool TypeValueTypePtr::eq(const Type* t) const {
4936   const TypeValueTypePtr* p = t->is_valuetypeptr();
4937   return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4938 }
4939 
4940 //------------------------------hash-------------------------------------------
4941 // Type-specific hashing function.
4942 int TypeValueTypePtr::hash(void) const {
4943   return java_add(_vt->hash(), TypeOopPtr::hash());
4944 }
4945 
4946 //------------------------------is__Value--------------------------------------
4947 bool TypeValueTypePtr::is__Value() const {
4948   return klass()->equals(TypeKlassPtr::VALUE->klass());
4949 }
4950 
4951 //------------------------------dump2------------------------------------------
4952 #ifndef PRODUCT
4953 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
4954   st->print("valuetype* ");
4955   klass()->print_name_on(st);
4956   st->print(":%s", ptr_msg[_ptr]);
4957   _offset.dump2(st);
4958 }
4959 #endif
4960 
4961 //=============================================================================
4962 
4963 //------------------------------hash-------------------------------------------




1917 //=============================================================================
1918 // Convenience common pre-built types.
1919 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1920 const TypeTuple *TypeTuple::IFFALSE;
1921 const TypeTuple *TypeTuple::IFTRUE;
1922 const TypeTuple *TypeTuple::IFNEITHER;
1923 const TypeTuple *TypeTuple::LOOPBODY;
1924 const TypeTuple *TypeTuple::MEMBAR;
1925 const TypeTuple *TypeTuple::STORECONDITIONAL;
1926 const TypeTuple *TypeTuple::START_I2C;
1927 const TypeTuple *TypeTuple::INT_PAIR;
1928 const TypeTuple *TypeTuple::LONG_PAIR;
1929 const TypeTuple *TypeTuple::INT_CC_PAIR;
1930 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1931 
1932 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos) {
1933   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1934     ciField* field = vk->nonstatic_field_at(j);
1935     BasicType bt = field->type()->basic_type();
1936     const Type* ft = Type::get_const_type(field->type());



1937     field_array[pos++] = ft;
1938     if (bt == T_LONG || bt == T_DOUBLE) {
1939       field_array[pos++] = Type::HALF;
1940     }
1941   }
1942 }
1943 
1944 //------------------------------make-------------------------------------------
1945 // Make a TypeTuple from the range of a method signature
1946 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1947   ciType* return_type = sig->return_type();
1948   return make_range(return_type, ret_vt_fields);
1949 }
1950 
1951 const TypeTuple *TypeTuple::make_range(ciType* return_type, bool ret_vt_fields) {
1952   uint arg_cnt = 0;
1953   if (ret_vt_fields) {
1954     ret_vt_fields = return_type->is_valuetype() && ((ciValueKlass*)return_type)->can_be_returned_as_fields();
1955   }
1956   if (ret_vt_fields) {


1971     field_array[TypeFunc::Parms+1] = Type::HALF;
1972     break;
1973   case T_OBJECT:
1974   case T_ARRAY:
1975   case T_BOOLEAN:
1976   case T_CHAR:
1977   case T_FLOAT:
1978   case T_BYTE:
1979   case T_SHORT:
1980   case T_INT:
1981     field_array[TypeFunc::Parms] = get_const_type(return_type);
1982     break;
1983   case T_VALUETYPE:
1984     if (ret_vt_fields) {
1985       ciValueKlass* vk = (ciValueKlass*)return_type;
1986       uint pos = TypeFunc::Parms;
1987       field_array[pos] = TypePtr::BOTTOM;
1988       pos++;
1989       collect_value_fields(vk, field_array, pos);
1990     } else {
1991       // Value type returns cannot be NULL
1992       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(TypePtr::NOTNULL);
1993     }
1994     break;
1995   case T_VOID:
1996     break;
1997   default:
1998     ShouldNotReachHere();
1999   }
2000   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2001 }
2002 
2003 // Make a TypeTuple from the domain of a method signature
2004 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2005   uint arg_cnt = sig->size();
2006 
2007   int vt_extra = 0;
2008   if (vt_fields_as_args) {
2009     for (int i = 0; i < sig->count(); i++) {
2010       ciType* type = sig->type_at(i);
2011       if (type->basic_type() == T_VALUETYPE && !type->is__Value()) {
2012         assert(type->is_valuetype(), "inconsistent type");


2052       field_array[pos++] = Type::HALF;
2053       break;
2054     case T_OBJECT:
2055     case T_ARRAY:
2056     case T_FLOAT:
2057     case T_INT:
2058       field_array[pos++] = get_const_type(type);
2059       break;
2060     case T_BOOLEAN:
2061     case T_CHAR:
2062     case T_BYTE:
2063     case T_SHORT:
2064       field_array[pos++] = TypeInt::INT;
2065       break;
2066     case T_VALUETYPE: {
2067       assert(type->is_valuetype(), "inconsistent type");
2068       if (vt_fields_as_args && !type->is__Value()) {
2069         ciValueKlass* vk = (ciValueKlass*)type;
2070         collect_value_fields(vk, field_array, pos);
2071       } else {
2072         // Value types arguments cannot be NULL
2073         field_array[pos++] = get_const_type(type)->join_speculative(TypePtr::NOTNULL);
2074       }
2075       break;
2076     }
2077     default:
2078       ShouldNotReachHere();
2079     }
2080     i++;
2081   }
2082   assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2083 
2084   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2085 }
2086 
2087 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2088   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2089 }
2090 
2091 //------------------------------fields-----------------------------------------
2092 // Subroutine call type with space allocated for argument types
2093 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly


2198   }
2199   return false;
2200 }
2201 
2202 //=============================================================================
2203 // Convenience common pre-built types.
2204 
2205 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2206   // Certain normalizations keep us sane when comparing types.
2207   // We do not want arrayOop variables to differ only by the wideness
2208   // of their index types.  Pick minimum wideness, since that is the
2209   // forced wideness of small ranges anyway.
2210   if (size->_widen != Type::WidenMin)
2211     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2212   else
2213     return size;
2214 }
2215 
2216 //------------------------------make-------------------------------------------
2217 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2218   if (elem->isa_valuetypeptr()) {
2219     // Value type array elements cannot be NULL
2220     elem = elem->join_speculative(TypePtr::NOTNULL)->is_oopptr();
2221   }
2222   if (UseCompressedOops && elem->isa_oopptr()) {
2223     elem = elem->make_narrowoop();
2224   }
2225   size = normalize_array_size(size);
2226   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2227 }
2228 
2229 //------------------------------meet-------------------------------------------
2230 // Compute the MEET of two types.  It returns a new Type object.
2231 const Type *TypeAry::xmeet( const Type *t ) const {
2232   // Perform a fast test for common case; meeting the same types together.
2233   if( this == t ) return this;  // Meeting same type-rep?
2234 
2235   // Current "this->_base" is Ary
2236   switch (t->base()) {          // switch on original type
2237 
2238   case Bottom:                  // Ye Olde Default
2239     return t;
2240 
2241   default:                      // All else is a mistake


3353   case AryPtr:
3354     return t->xmeet(this);      // Call in reverse direction
3355 
3356   } // End of switch
3357   return this;                  // Return the double constant
3358 }
3359 
3360 
3361 //------------------------------xdual------------------------------------------
3362 // Dual of a pure heap pointer.  No relevant klass or oop information.
3363 const Type *TypeOopPtr::xdual() const {
3364   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3365   assert(const_oop() == NULL,             "no constants here");
3366   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3367 }
3368 
3369 //--------------------------make_from_klass_common-----------------------------
3370 // Computes the element-type given a klass.
3371 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3372   if (klass->is_valuetype()) {
3373     return TypeValueTypePtr::make(TypePtr::BotPTR, klass->as_value_klass());
3374   } else if (klass->is_instance_klass()) {
3375     Compile* C = Compile::current();
3376     Dependencies* deps = C->dependencies();
3377     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3378     // Element is an instance
3379     bool klass_is_exact = false;
3380     if (klass->is_loaded()) {
3381       // Try to set klass_is_exact.
3382       ciInstanceKlass* ik = klass->as_instance_klass();
3383       klass_is_exact = ik->is_final();
3384       if (!klass_is_exact && klass_change
3385           && deps != NULL && UseUniqueSubclasses) {
3386         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3387         if (sub != NULL) {
3388           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3389           klass = ik = sub;
3390           klass_is_exact = sub->is_final();
3391         }
3392       }
3393       if (!klass_is_exact && try_for_exact


3403   } else if (klass->is_obj_array_klass()) {
3404     // Element is an object or value array. Recursively call ourself.
3405     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3406     bool xk = etype->klass_is_exact();
3407     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3408     // We used to pass NotNull in here, asserting that the sub-arrays
3409     // are all not-null.  This is not true in generally, as code can
3410     // slam NULLs down in the subarrays.
3411     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3412     return arr;
3413   } else if (klass->is_type_array_klass()) {
3414     // Element is an typeArray
3415     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3416     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3417     // We used to pass NotNull in here, asserting that the array pointer
3418     // is not-null. That was not true in general.
3419     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3420     return arr;
3421   } else if (klass->is_value_array_klass()) {
3422     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3423     const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3424     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));










3425     return arr;
3426   } else {
3427     ShouldNotReachHere();
3428     return NULL;
3429   }
3430 }
3431 
3432 //------------------------------make_from_constant-----------------------------
3433 // Make a java pointer from an oop constant
3434 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3435   assert(!o->is_null_object(), "null object not yet handled here.");
3436   ciKlass* klass = o->klass();
3437   if (klass->is_valuetype()) {
3438     // Element is a value type
3439     if (require_constant) {
3440       if (!o->can_be_constant())  return NULL;
3441     } else if (!o->should_be_constant()) {
3442       return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3443     }
3444     return TypeValueTypePtr::make(o);


4760         if (field == NULL) {
4761           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
4762           return add_offset(offset);
4763         } else {
4764           assert(_field_offset.get() <= 0, "should not have field_offset");
4765           return with_field_offset(field_offset)->add_offset(offset - field_offset);
4766         }
4767       }
4768     }
4769   }
4770   return add_offset(offset);
4771 }
4772 
4773 //=============================================================================
4774 
4775 
4776 //=============================================================================
4777 
4778 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4779 //------------------------------make-------------------------------------------
4780 const TypeValueTypePtr* TypeValueTypePtr::make(PTR ptr, ciValueKlass* vk, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth, bool narrow) {
4781   return (TypeValueTypePtr*)(new TypeValueTypePtr(ptr, vk, o, offset, instance_id, speculative, inline_depth))->hashcons();
4782 }
4783 
4784 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4785   return make(_ptr, value_klass(), _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4786 }
4787 
4788 //------------------------------cast_to_ptr_type-------------------------------
4789 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4790   if (ptr == _ptr) return this;
4791   return make(ptr, value_klass(), _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4792 }
4793 
4794 //-----------------------------cast_to_instance_id----------------------------
4795 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4796   if (instance_id == _instance_id) return this;
4797   return make(_ptr, value_klass(), _const_oop, _offset, instance_id, _speculative, _inline_depth);
4798 }
4799 
4800 //------------------------------meet-------------------------------------------
4801 // Compute the MEET of two types.  It returns a new Type object.
4802 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const {
4803   // Perform a fast test for common case; meeting the same types together.
4804   if (this == t) return this;  // Meeting same type-rep?
4805 
4806   switch (t->base()) {          // switch on original type
4807     case Int:                     // Mixing ints & oops happens when javac
4808     case Long:                    // reuses local variables
4809     case FloatTop:
4810     case FloatCon:
4811     case FloatBot:
4812     case DoubleTop:
4813     case DoubleCon:
4814     case DoubleBot:
4815     case NarrowOop:
4816     case NarrowKlass:
4817     case Bottom:                  // Ye Olde Default


4824     case InstPtr:
4825       return TypePtr::BOTTOM;
4826 
4827     case Top:
4828       return this;
4829 
4830     default:                      // All else is a mistake
4831       typerr(t);
4832 
4833     case OopPtr: {
4834       // Found a OopPtr type vs self-ValueTypePtr type
4835       const TypeOopPtr* tp = t->is_oopptr();
4836       Offset offset = meet_offset(tp->offset());
4837       PTR ptr = meet_ptr(tp->ptr());
4838       int instance_id = meet_instance_id(tp->instance_id());
4839       const TypePtr* speculative = xmeet_speculative(tp);
4840       int depth = meet_inline_depth(tp->inline_depth());
4841       switch (tp->ptr()) {
4842       case TopPTR:
4843       case AnyNull: {
4844         return make(ptr, value_klass(), NULL, offset, instance_id, speculative, depth);
4845       }
4846       case NotNull:
4847       case BotPTR: {
4848         return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4849       }
4850       default: typerr(t);
4851       }
4852     }
4853 
4854     case AnyPtr: {
4855       // Found an AnyPtr type vs self-ValueTypePtr type
4856       const TypePtr* tp = t->is_ptr();
4857       Offset offset = meet_offset(tp->offset());
4858       PTR ptr = meet_ptr(tp->ptr());
4859       int instance_id = meet_instance_id(InstanceTop);
4860       const TypePtr* speculative = xmeet_speculative(tp);
4861       int depth = meet_inline_depth(tp->inline_depth());
4862       switch (tp->ptr()) {
4863       case Null:
4864         if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4865         // else fall through to AnyNull
4866       case TopPTR:
4867       case AnyNull: {
4868         return make(ptr, value_klass(), NULL, offset, instance_id, speculative, depth);
4869       }
4870       case NotNull:
4871       case BotPTR:
4872         return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4873       default: typerr(t);
4874       }
4875     }
4876 
4877     case ValueTypePtr: {
4878       // Found an ValueTypePtr type vs self-ValueTypePtr type
4879       const TypeValueTypePtr* tp = t->is_valuetypeptr();
4880       Offset offset = meet_offset(tp->offset());
4881       PTR ptr = meet_ptr(tp->ptr());
4882       int instance_id = meet_instance_id(InstanceTop);
4883       const TypePtr* speculative = xmeet_speculative(tp);
4884       int depth = meet_inline_depth(tp->inline_depth());
4885       // Compute constant oop
4886       ciObject* o = NULL;
4887       ciObject* this_oop  = const_oop();
4888       ciObject* tp_oop = tp->const_oop();
4889       ciKlass* klass = NULL;
4890       if (_klass != tp->_klass) {
4891         assert(is__Value() || tp->is__Value(), "impossible meet");
4892         if (above_centerline(ptr)) {
4893           klass = is__Value() ? tp->_klass : _klass;
4894         } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4895           klass = tp->_klass;
4896         } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4897           klass = _klass;
4898         } else {
4899           klass = is__Value() ? _klass : tp->_klass;
4900         }
4901       } else {
4902         klass = _klass;
4903       }
4904       if (ptr == Constant) {
4905         if (this_oop != NULL && tp_oop != NULL &&
4906             this_oop->equals(tp_oop) ) {
4907           o = this_oop;
4908         } else if (above_centerline(this ->_ptr)) {
4909           o = tp_oop;
4910         } else if (above_centerline(tp ->_ptr)) {
4911           o = this_oop;
4912         } else {
4913           ptr = NotNull;
4914         }
4915       }
4916       return make(ptr, klass->as_value_klass(), o, offset, instance_id, speculative, depth);
4917     }
4918     }
4919 }
4920 
4921 // Dual: compute field-by-field dual
4922 const Type* TypeValueTypePtr::xdual() const {
4923   return new TypeValueTypePtr(dual_ptr(), value_klass(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4924 }
4925 
4926 //------------------------------eq---------------------------------------------
4927 // Structural equality check for Type representations
4928 bool TypeValueTypePtr::eq(const Type* t) const {
4929   const TypeValueTypePtr* p = t->is_valuetypeptr();
4930   return klass()->equals(p->klass()) && TypeOopPtr::eq(p);
4931 }
4932 
4933 //------------------------------hash-------------------------------------------
4934 // Type-specific hashing function.
4935 int TypeValueTypePtr::hash(void) const {
4936   return java_add(klass()->hash(), TypeOopPtr::hash());
4937 }
4938 
4939 //------------------------------is__Value--------------------------------------
4940 bool TypeValueTypePtr::is__Value() const {
4941   return klass()->equals(TypeKlassPtr::VALUE->klass());
4942 }
4943 
4944 //------------------------------dump2------------------------------------------
4945 #ifndef PRODUCT
4946 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
4947   st->print("valuetype* ");
4948   klass()->print_name_on(st);
4949   st->print(":%s", ptr_msg[_ptr]);
4950   _offset.dump2(st);
4951 }
4952 #endif
4953 
4954 //=============================================================================
4955 
4956 //------------------------------hash-------------------------------------------


< prev index next >