< prev index next >

src/share/vm/opto/type.cpp

Print this page




 244     assert(type == ciTypeFlow::StateVector::null_type(), "");
 245     return TypePtr::NULL_PTR;
 246 
 247   case ciTypeFlow::StateVector::T_LONG2:
 248     // The ciTypeFlow pass pushes a long, then the half.
 249     // We do the same.
 250     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 251     return TypeInt::TOP;
 252 
 253   case ciTypeFlow::StateVector::T_DOUBLE2:
 254     // The ciTypeFlow pass pushes double, then the half.
 255     // Our convention is the same.
 256     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 257     return Type::TOP;
 258 
 259   case T_ADDRESS:
 260     assert(type->is_return_address(), "");
 261     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 262 
 263   case T_VALUETYPE:
 264     if (type == ciEnv::current()->___Value_klass()) {
 265       return TypeValueTypePtr::NOTNULL;
 266     } else {
 267       return TypeValueType::make(type->as_value_klass());
 268     }
 269 
 270   default:
 271     // make sure we did not mix up the cases:
 272     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 273     assert(type != ciTypeFlow::StateVector::top_type(), "");
 274     assert(type != ciTypeFlow::StateVector::null_type(), "");
 275     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 276     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 277     assert(!type->is_return_address(), "");
 278 
 279     return Type::get_const_type(type);
 280   }
 281 }
 282 
 283 
 284 //-----------------------make_from_constant------------------------------------


 620     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 621   } else
 622 #endif
 623   {
 624     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 625     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 626   }
 627   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 628   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 629   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 630   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 631   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 632   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 633   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 634 
 635   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 636   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 637   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 638   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 639   TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS;

 640   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 641   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 642   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 643   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 644   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 645   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 646   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 647   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 648 
 649   TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0) );
 650   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0) );
 651   TypeKlassPtr::BOTTOM = (EnableValhalla | EnableMVT) ? TypeKlassPtr::make(TypePtr::BotPTR, NULL, Offset(0)) : TypeKlassPtr::OBJECT_OR_NULL;
 652   TypeKlassPtr::VALUE = TypeKlassPtr::make(TypePtr::NotNull, current->env()->___Value_klass(), Offset(0));
 653 
 654   const Type **fi2c = TypeTuple::fields(2);
 655   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 656   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 657   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 658 
 659   const Type **intpair = TypeTuple::fields(2);


 670   intccpair[0] = TypeInt::INT;
 671   intccpair[1] = TypeInt::CC;
 672   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 673 
 674   const Type **longccpair = TypeTuple::fields(2);
 675   longccpair[0] = TypeLong::LONG;
 676   longccpair[1] = TypeInt::CC;
 677   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 678 
 679   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 680   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 681   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 682   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 683   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 684   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 685   _const_basic_type[T_INT]         = TypeInt::INT;
 686   _const_basic_type[T_LONG]        = TypeLong::LONG;
 687   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 688   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 689   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;

 690   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 691   _const_basic_type[T_VALUETYPE]   = TypeInstPtr::BOTTOM;
 692   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 693   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 694   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 695 
 696   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 697   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 698   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 699   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 700   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 701   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 702   _zero_type[T_INT]         = TypeInt::ZERO;
 703   _zero_type[T_LONG]        = TypeLong::ZERO;
 704   _zero_type[T_FLOAT]       = TypeF::ZERO;
 705   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 706   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;

 707   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 708   _zero_type[T_VALUETYPE]   = TypePtr::NULL_PTR;
 709   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 710   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 711 
 712   // get_zero_type() should not happen for T_CONFLICT
 713   _zero_type[T_CONFLICT]= NULL;
 714 
 715   // Vector predefined types, it needs initialized _const_basic_type[].
 716   if (Matcher::vector_size_supported(T_BYTE,4)) {
 717     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 718   }
 719   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 720     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 721   }
 722   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 723     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 724   }
 725   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 726     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);


1911   return _lo > _hi;
1912 }
1913 
1914 //=============================================================================
1915 // Convenience common pre-built types.
1916 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1917 const TypeTuple *TypeTuple::IFFALSE;
1918 const TypeTuple *TypeTuple::IFTRUE;
1919 const TypeTuple *TypeTuple::IFNEITHER;
1920 const TypeTuple *TypeTuple::LOOPBODY;
1921 const TypeTuple *TypeTuple::MEMBAR;
1922 const TypeTuple *TypeTuple::STORECONDITIONAL;
1923 const TypeTuple *TypeTuple::START_I2C;
1924 const TypeTuple *TypeTuple::INT_PAIR;
1925 const TypeTuple *TypeTuple::LONG_PAIR;
1926 const TypeTuple *TypeTuple::INT_CC_PAIR;
1927 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1928 
1929 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos) {
1930   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1931     ciField* f = vk->nonstatic_field_at(j);
1932     BasicType bt = f->type()->basic_type();
1933     assert(bt < T_VALUETYPE && bt >= T_BOOLEAN, "not yet supported");
1934     field_array[pos++] = Type::get_const_type(f->type());



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


1987     } else {
1988       field_array[TypeFunc::Parms] = get_const_type(return_type);
1989     }
1990     break;
1991   case T_VOID:
1992     break;
1993   default:
1994     ShouldNotReachHere();
1995   }
1996   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1997 }
1998 
1999 // Make a TypeTuple from the domain of a method signature
2000 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2001   uint arg_cnt = sig->size();
2002 
2003   int vt_extra = 0;
2004   if (vt_fields_as_args) {
2005     for (int i = 0; i < sig->count(); i++) {
2006       ciType* type = sig->type_at(i);
2007       if (type->basic_type() == T_VALUETYPE && type != ciEnv::current()->___Value_klass()) {
2008         assert(type->is_valuetype(), "inconsistent type");
2009         ciValueKlass* vk = (ciValueKlass*)type;
2010         vt_extra += vk->value_arg_slots()-1;
2011       }
2012     }
2013     assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2014   }
2015 
2016   uint pos = TypeFunc::Parms;
2017   const Type **field_array;
2018   if (recv != NULL) {
2019     arg_cnt++;
2020     bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype() &&
2021       recv != ciEnv::current()->___Value_klass();
2022     if (vt_fields_for_recv) {
2023       ciValueKlass* vk = (ciValueKlass*)recv;
2024       vt_extra += vk->value_arg_slots()-1;
2025     }
2026     field_array = fields(arg_cnt + vt_extra);
2027     // Use get_const_type here because it respects UseUniqueSubclasses:
2028     if (vt_fields_for_recv) {
2029       ciValueKlass* vk = (ciValueKlass*)recv;
2030       collect_value_fields(vk, field_array, pos);
2031     } else {
2032       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2033     }
2034   } else {
2035     field_array = fields(arg_cnt + vt_extra);
2036   }
2037 
2038   int i = 0;
2039   while (pos < TypeFunc::Parms + arg_cnt + vt_extra) {
2040     ciType* type = sig->type_at(i);
2041 


2045       field_array[pos++] = Type::HALF;
2046       break;
2047     case T_DOUBLE:
2048       field_array[pos++] = Type::DOUBLE;
2049       field_array[pos++] = Type::HALF;
2050       break;
2051     case T_OBJECT:
2052     case T_ARRAY:
2053     case T_FLOAT:
2054     case T_INT:
2055       field_array[pos++] = get_const_type(type);
2056       break;
2057     case T_BOOLEAN:
2058     case T_CHAR:
2059     case T_BYTE:
2060     case T_SHORT:
2061       field_array[pos++] = TypeInt::INT;
2062       break;
2063     case T_VALUETYPE: {
2064       assert(type->is_valuetype(), "inconsistent type");
2065       if (vt_fields_as_args && type != ciEnv::current()->___Value_klass()) {
2066         ciValueKlass* vk = (ciValueKlass*)type;
2067         collect_value_fields(vk, field_array, pos);
2068       } else {
2069         field_array[pos++] = get_const_type(type);
2070       }
2071       break;
2072     }
2073     default:
2074       ShouldNotReachHere();
2075     }
2076     i++;
2077   }
2078   assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2079 
2080   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2081 }
2082 
2083 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2084   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2085 }


2415   return (intptr_t)_vk;
2416 }
2417 
2418 //------------------------------singleton--------------------------------------
2419 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2420 bool TypeValueType::singleton(void) const {
2421   // FIXME
2422   return false;
2423 }
2424 
2425 //------------------------------empty------------------------------------------
2426 // TRUE if Type is a type with no values, FALSE otherwise.
2427 bool TypeValueType::empty(void) const {
2428   // FIXME
2429   return false;
2430 }
2431 
2432 //------------------------------dump2------------------------------------------
2433 #ifndef PRODUCT
2434 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const {
2435   st->print("valuetype[%d]:{", _vk->field_count());
2436   st->print("%s", _vk->field_count() != 0 ? _vk->field_type_by_index(0)->name() : "empty");
2437   for (int i = 1; i < _vk->field_count(); ++i) {
2438     st->print(", %s", _vk->field_type_by_index(i)->name());

2439   }
2440   st->print("}");
2441 }
2442 #endif
2443 
2444 //==============================TypeVect=======================================
2445 // Convenience common pre-built types.
2446 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2447 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2448 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2449 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2450 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2451 
2452 //------------------------------make-------------------------------------------
2453 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2454   BasicType elem_bt = elem->array_element_basic_type();
2455   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2456   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2457   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2458   int size = length * type2aelembytes(elem_bt);


3160     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3161   }
3162 #ifdef _LP64
3163   if (this->offset() != 0) {
3164     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3165       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3166     } else if (klass() == NULL) {
3167       // Array with unknown body type
3168       assert(this->isa_aryptr(), "only arrays without klass");
3169       _is_ptr_to_narrowoop = UseCompressedOops;
3170     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3171       if (klass()->is_obj_array_klass()) {
3172         _is_ptr_to_narrowoop = true;
3173       } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3174         // Check if the field of the value type array element contains oops
3175         ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3176         int foffset = field_offset.get() + vk->first_field_offset();
3177         ciField* field = vk->get_field_by_offset(foffset, false);
3178         assert(field != NULL, "missing field");
3179         BasicType bt = field->layout_type();
3180         assert(bt != T_VALUETYPE, "should be flattened");
3181         _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY);
3182       }
3183     } else if (klass()->is_instance_klass()) {
3184       ciInstanceKlass* ik = klass()->as_instance_klass();
3185       ciField* field = NULL;
3186       if (this->isa_klassptr()) {
3187         // Perm objects don't use compressed references
3188       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3189         // unsafe access
3190         _is_ptr_to_narrowoop = UseCompressedOops;
3191       } else { // exclude unsafe ops
3192         assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr.");
3193 
3194         if (klass() == ciEnv::current()->Class_klass() &&
3195             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3196              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3197           // Special hidden fields from the Class.
3198           assert(this->isa_instptr(), "must be an instance ptr.");
3199           _is_ptr_to_narrowoop = false;
3200         } else if (klass() == ciEnv::current()->Class_klass() &&
3201                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3202           // Static fields
3203           assert(o != NULL, "must be constant");
3204           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3205           ciField* field = k->get_field_by_offset(this->offset(), true);
3206           assert(field != NULL, "missing field");
3207           BasicType basic_elem_type = field->layout_type();
3208           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3209                                                        basic_elem_type == T_ARRAY);
3210         } else {
3211           // Instance fields which contains a compressed oop references.
3212           field = ik->get_field_by_offset(this->offset(), false);
3213           if (field != NULL) {
3214             BasicType basic_elem_type = field->layout_type();
3215             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||

3216                                                          basic_elem_type == T_ARRAY);

3217           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3218             // Compile::find_alias_type() cast exactness on all types to verify
3219             // that it does not affect alias type.
3220             _is_ptr_to_narrowoop = UseCompressedOops;
3221           } else {
3222             // Type for the copy start in LibraryCallKit::inline_native_clone().
3223             _is_ptr_to_narrowoop = UseCompressedOops;
3224           }
3225         }
3226       }
3227     }
3228   }
3229 #endif
3230 }
3231 
3232 //------------------------------make-------------------------------------------
3233 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3234                                    const TypePtr* speculative, int inline_depth) {
3235   assert(ptr != Constant, "no constant generic pointers");
3236   ciKlass*  k = Compile::current()->env()->Object_klass();


4731   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, NULL, _inline_depth, _is_autobox_cache);
4732 }
4733 
4734 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4735   if (!UseInlineDepthForSpeculativeTypes) {
4736     return this;
4737   }
4738   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4739 }
4740 
4741 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4742   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, Offset(offset), _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4743 }
4744 
4745 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const {
4746   if (offset != Type::OffsetBot) {
4747     const Type* elemtype = elem();
4748     if (elemtype->isa_valuetype()) {
4749       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4750       if (offset >= (intptr_t)header) {

4751         ciKlass* arytype_klass = klass();
4752         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();

4753         int shift = vak->log2_element_size();
4754         intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4755 






4756         return with_field_offset(field_offset)->add_offset(offset - field_offset);
4757       }
4758     }
4759   }

4760   return add_offset(offset);
4761 }
4762 
4763 //=============================================================================
4764 
4765 
4766 //=============================================================================
4767 
4768 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4769 //------------------------------make-------------------------------------------
4770 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4771   return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4772 }
4773 
4774 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4775   return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4776 }
4777 
4778 //------------------------------cast_to_ptr_type-------------------------------
4779 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4780   if (ptr == _ptr) return this;
4781   return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4782 }
4783 
4784 //-----------------------------cast_to_instance_id----------------------------
4785 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4786   if (instance_id == _instance_id) return this;
4787   return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4788 }
4789 
4790 //------------------------------meet-------------------------------------------


4861       case BotPTR:
4862         return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4863       default: typerr(t);
4864       }
4865     }
4866 
4867     case ValueTypePtr: {
4868       // Found an ValueTypePtr type vs self-ValueTypePtr type
4869       const TypeValueTypePtr* tp = t->is_valuetypeptr();
4870       Offset offset = meet_offset(tp->offset());
4871       PTR ptr = meet_ptr(tp->ptr());
4872       int instance_id = meet_instance_id(InstanceTop);
4873       const TypePtr* speculative = xmeet_speculative(tp);
4874       int depth = meet_inline_depth(tp->inline_depth());
4875       // Compute constant oop
4876       ciObject* o = NULL;
4877       ciObject* this_oop  = const_oop();
4878       ciObject* tp_oop = tp->const_oop();
4879       const TypeValueType* vt = NULL;
4880       if (_vt != tp->_vt) {
4881         ciKlass* __value_klass = ciEnv::current()->___Value_klass();
4882         assert(klass() == __value_klass || tp->klass() == __value_klass, "impossible meet");
4883         if (above_centerline(ptr)) {
4884           vt = klass() == __value_klass ? tp->_vt : _vt;
4885         } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4886           vt = tp->_vt;
4887         } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4888           vt = _vt;
4889         } else {
4890           vt = klass() == __value_klass ? _vt : tp->_vt;
4891         }
4892       } else {
4893         vt = _vt;
4894       }
4895       if (ptr == Constant) {
4896         if (this_oop != NULL && tp_oop != NULL &&
4897             this_oop->equals(tp_oop) ) {
4898           o = this_oop;
4899         } else if (above_centerline(this ->_ptr)) {
4900           o = tp_oop;
4901         } else if (above_centerline(tp ->_ptr)) {
4902           o = this_oop;
4903         } else {
4904           ptr = NotNull;
4905         }
4906       }
4907       return make(vt, ptr, o, offset, instance_id, speculative, depth);
4908     }
4909     }
4910 }
4911 
4912 // Dual: compute field-by-field dual
4913 const Type* TypeValueTypePtr::xdual() const {
4914   return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4915 }
4916 
4917 //------------------------------eq---------------------------------------------
4918 // Structural equality check for Type representations
4919 bool TypeValueTypePtr::eq(const Type* t) const {
4920   const TypeValueTypePtr* p = t->is_valuetypeptr();
4921   return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4922 }
4923 
4924 //------------------------------hash-------------------------------------------
4925 // Type-specific hashing function.
4926 int TypeValueTypePtr::hash(void) const {
4927   return java_add(_vt->hash(), TypeOopPtr::hash());
4928 }
4929 
4930 //------------------------------empty------------------------------------------
4931 // TRUE if Type is a type with no values, FALSE otherwise.
4932 bool TypeValueTypePtr::empty(void) const {
4933   // FIXME
4934   return false;
4935 }
4936 
4937 //------------------------------dump2------------------------------------------
4938 #ifndef PRODUCT
4939 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
4940   st->print("valuetype* ");
4941   klass()->print_name_on(st);
4942   st->print(":%s", ptr_msg[_ptr]);
4943   _offset.dump2(st);
4944 }
4945 #endif
4946 
4947 //=============================================================================
4948 
4949 //------------------------------hash-------------------------------------------
4950 // Type-specific hashing function.
4951 int TypeNarrowPtr::hash(void) const {
4952   return _ptrtype->hash() + 7;
4953 }
4954 


5696 //------------------------------make-------------------------------------------
5697 const TypeFunc *TypeFunc::make(ciMethod* method) {
5698   Compile* C = Compile::current();
5699   const TypeFunc* tf = C->last_tf(method); // check cache
5700   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5701   const TypeTuple *domain_sig, *domain_cc;
5702   // Value type arguments are not passed by reference, instead each
5703   // field of the value type is passed as an argument. We maintain 2
5704   // views of the argument list here: one based on the signature (with
5705   // a value type argument as a single slot), one based on the actual
5706   // calling convention (with a value type argument as a list of its
5707   // fields).
5708   if (method->is_static()) {
5709     domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5710     domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5711   } else {
5712     domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5713     domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5714   }
5715   const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false);
5716   bool as_fields = ValueTypeReturnedAsFields;
5717   const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), as_fields);
5718   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5719   C->set_last_tf(method, tf);  // fill cache
5720   return tf;
5721 }
5722 
5723 //------------------------------meet-------------------------------------------
5724 // Compute the MEET of two types.  It returns a new Type object.
5725 const Type *TypeFunc::xmeet( const Type *t ) const {
5726   // Perform a fast test for common case; meeting the same types together.
5727   if( this == t ) return this;  // Meeting same type-rep?
5728 
5729   // Current "this->_base" is Func
5730   switch (t->base()) {          // switch on original type
5731 
5732   case Bottom:                  // Ye Olde Default
5733     return t;
5734 
5735   default:                      // All else is a mistake
5736     typerr(t);
5737 




 244     assert(type == ciTypeFlow::StateVector::null_type(), "");
 245     return TypePtr::NULL_PTR;
 246 
 247   case ciTypeFlow::StateVector::T_LONG2:
 248     // The ciTypeFlow pass pushes a long, then the half.
 249     // We do the same.
 250     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 251     return TypeInt::TOP;
 252 
 253   case ciTypeFlow::StateVector::T_DOUBLE2:
 254     // The ciTypeFlow pass pushes double, then the half.
 255     // Our convention is the same.
 256     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 257     return Type::TOP;
 258 
 259   case T_ADDRESS:
 260     assert(type->is_return_address(), "");
 261     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 262 
 263   case T_VALUETYPE:
 264     if (type->is__Value()) {
 265       return TypeValueTypePtr::NOTNULL;
 266     } else {
 267       return TypeValueType::make(type->as_value_klass());
 268     }
 269 
 270   default:
 271     // make sure we did not mix up the cases:
 272     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 273     assert(type != ciTypeFlow::StateVector::top_type(), "");
 274     assert(type != ciTypeFlow::StateVector::null_type(), "");
 275     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 276     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 277     assert(!type->is_return_address(), "");
 278 
 279     return Type::get_const_type(type);
 280   }
 281 }
 282 
 283 
 284 //-----------------------make_from_constant------------------------------------


 620     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 621   } else
 622 #endif
 623   {
 624     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 625     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 626   }
 627   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 628   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 629   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 630   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 631   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 632   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 633   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 634 
 635   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 636   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 637   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 638   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 639   TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS;
 640   TypeAryPtr::_array_body_type[T_VALUETYPEPTR] = NULL;
 641   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 642   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 643   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 644   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 645   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 646   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 647   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 648   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 649 
 650   TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0) );
 651   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0) );
 652   TypeKlassPtr::BOTTOM = (EnableValhalla | EnableMVT) ? TypeKlassPtr::make(TypePtr::BotPTR, NULL, Offset(0)) : TypeKlassPtr::OBJECT_OR_NULL;
 653   TypeKlassPtr::VALUE = TypeKlassPtr::make(TypePtr::NotNull, current->env()->___Value_klass(), Offset(0));
 654 
 655   const Type **fi2c = TypeTuple::fields(2);
 656   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 657   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 658   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 659 
 660   const Type **intpair = TypeTuple::fields(2);


 671   intccpair[0] = TypeInt::INT;
 672   intccpair[1] = TypeInt::CC;
 673   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 674 
 675   const Type **longccpair = TypeTuple::fields(2);
 676   longccpair[0] = TypeLong::LONG;
 677   longccpair[1] = TypeInt::CC;
 678   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 679 
 680   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 681   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 682   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 683   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 684   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 685   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 686   _const_basic_type[T_INT]         = TypeInt::INT;
 687   _const_basic_type[T_LONG]        = TypeLong::LONG;
 688   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 689   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 690   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 691   _const_basic_type[T_VALUETYPEPTR]= TypeInstPtr::BOTTOM;
 692   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 693   _const_basic_type[T_VALUETYPE]   = TypeInstPtr::BOTTOM;
 694   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 695   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 696   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 697 
 698   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 699   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 700   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 701   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 702   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 703   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 704   _zero_type[T_INT]         = TypeInt::ZERO;
 705   _zero_type[T_LONG]        = TypeLong::ZERO;
 706   _zero_type[T_FLOAT]       = TypeF::ZERO;
 707   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 708   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 709   _zero_type[T_VALUETYPEPTR]= TypePtr::NULL_PTR;
 710   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 711   _zero_type[T_VALUETYPE]   = TypePtr::NULL_PTR;
 712   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 713   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 714 
 715   // get_zero_type() should not happen for T_CONFLICT
 716   _zero_type[T_CONFLICT]= NULL;
 717 
 718   // Vector predefined types, it needs initialized _const_basic_type[].
 719   if (Matcher::vector_size_supported(T_BYTE,4)) {
 720     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 721   }
 722   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 723     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 724   }
 725   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 726     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 727   }
 728   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 729     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);


1914   return _lo > _hi;
1915 }
1916 
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) {
1960     ciValueKlass* vk = (ciValueKlass*)return_type;


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");
2015         ciValueKlass* vk = (ciValueKlass*)type;
2016         vt_extra += vk->value_arg_slots()-1;
2017       }
2018     }
2019     assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2020   }
2021 
2022   uint pos = TypeFunc::Parms;
2023   const Type **field_array;
2024   if (recv != NULL) {
2025     arg_cnt++;
2026     bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype() && !recv->is__Value();

2027     if (vt_fields_for_recv) {
2028       ciValueKlass* vk = (ciValueKlass*)recv;
2029       vt_extra += vk->value_arg_slots()-1;
2030     }
2031     field_array = fields(arg_cnt + vt_extra);
2032     // Use get_const_type here because it respects UseUniqueSubclasses:
2033     if (vt_fields_for_recv) {
2034       ciValueKlass* vk = (ciValueKlass*)recv;
2035       collect_value_fields(vk, field_array, pos);
2036     } else {
2037       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2038     }
2039   } else {
2040     field_array = fields(arg_cnt + vt_extra);
2041   }
2042 
2043   int i = 0;
2044   while (pos < TypeFunc::Parms + arg_cnt + vt_extra) {
2045     ciType* type = sig->type_at(i);
2046 


2050       field_array[pos++] = Type::HALF;
2051       break;
2052     case T_DOUBLE:
2053       field_array[pos++] = Type::DOUBLE;
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 }


2420   return (intptr_t)_vk;
2421 }
2422 
2423 //------------------------------singleton--------------------------------------
2424 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2425 bool TypeValueType::singleton(void) const {
2426   // FIXME
2427   return false;
2428 }
2429 
2430 //------------------------------empty------------------------------------------
2431 // TRUE if Type is a type with no values, FALSE otherwise.
2432 bool TypeValueType::empty(void) const {
2433   // FIXME
2434   return false;
2435 }
2436 
2437 //------------------------------dump2------------------------------------------
2438 #ifndef PRODUCT
2439 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const {
2440   int count = _vk->nof_declared_nonstatic_fields();
2441   st->print("valuetype[%d]:{", count);
2442   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2443   for (int i = 1; i < count; ++i) {
2444     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2445   }
2446   st->print("}");
2447 }
2448 #endif
2449 
2450 //==============================TypeVect=======================================
2451 // Convenience common pre-built types.
2452 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2453 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2454 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2455 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2456 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2457 
2458 //------------------------------make-------------------------------------------
2459 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2460   BasicType elem_bt = elem->array_element_basic_type();
2461   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2462   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2463   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2464   int size = length * type2aelembytes(elem_bt);


3166     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3167   }
3168 #ifdef _LP64
3169   if (this->offset() != 0) {
3170     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3171       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3172     } else if (klass() == NULL) {
3173       // Array with unknown body type
3174       assert(this->isa_aryptr(), "only arrays without klass");
3175       _is_ptr_to_narrowoop = UseCompressedOops;
3176     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3177       if (klass()->is_obj_array_klass()) {
3178         _is_ptr_to_narrowoop = true;
3179       } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3180         // Check if the field of the value type array element contains oops
3181         ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3182         int foffset = field_offset.get() + vk->first_field_offset();
3183         ciField* field = vk->get_field_by_offset(foffset, false);
3184         assert(field != NULL, "missing field");
3185         BasicType bt = field->layout_type();
3186         assert(bt != T_VALUETYPEPTR, "unexpected type");
3187         _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE);
3188       }
3189     } else if (klass()->is_instance_klass()) {
3190       ciInstanceKlass* ik = klass()->as_instance_klass();
3191       ciField* field = NULL;
3192       if (this->isa_klassptr()) {
3193         // Perm objects don't use compressed references
3194       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3195         // unsafe access
3196         _is_ptr_to_narrowoop = UseCompressedOops;
3197       } else { // exclude unsafe ops
3198         assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr.");
3199 
3200         if (klass() == ciEnv::current()->Class_klass() &&
3201             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3202              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3203           // Special hidden fields from the Class.
3204           assert(this->isa_instptr(), "must be an instance ptr.");
3205           _is_ptr_to_narrowoop = false;
3206         } else if (klass() == ciEnv::current()->Class_klass() &&
3207                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3208           // Static fields
3209           assert(o != NULL, "must be constant");
3210           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3211           ciField* field = k->get_field_by_offset(this->offset(), true);
3212           assert(field != NULL, "missing field");
3213           BasicType basic_elem_type = field->layout_type();
3214           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3215                                                        basic_elem_type == T_ARRAY);
3216         } else {
3217           // Instance fields which contains a compressed oop references.
3218           field = ik->get_field_by_offset(this->offset(), false);
3219           if (field != NULL) {
3220             BasicType basic_elem_type = field->layout_type();
3221             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3222                                                          basic_elem_type == T_VALUETYPE ||
3223                                                          basic_elem_type == T_ARRAY);
3224             assert(basic_elem_type != T_VALUETYPEPTR, "unexpected type");
3225           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3226             // Compile::find_alias_type() cast exactness on all types to verify
3227             // that it does not affect alias type.
3228             _is_ptr_to_narrowoop = UseCompressedOops;
3229           } else {
3230             // Type for the copy start in LibraryCallKit::inline_native_clone().
3231             _is_ptr_to_narrowoop = UseCompressedOops;
3232           }
3233         }
3234       }
3235     }
3236   }
3237 #endif
3238 }
3239 
3240 //------------------------------make-------------------------------------------
3241 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3242                                    const TypePtr* speculative, int inline_depth) {
3243   assert(ptr != Constant, "no constant generic pointers");
3244   ciKlass*  k = Compile::current()->env()->Object_klass();


4739   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, NULL, _inline_depth, _is_autobox_cache);
4740 }
4741 
4742 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4743   if (!UseInlineDepthForSpeculativeTypes) {
4744     return this;
4745   }
4746   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4747 }
4748 
4749 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4750   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, Offset(offset), _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4751 }
4752 
4753 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const {
4754   if (offset != Type::OffsetBot) {
4755     const Type* elemtype = elem();
4756     if (elemtype->isa_valuetype()) {
4757       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4758       if (offset >= (intptr_t)header) {
4759         // Try to get the field of the value type array element we are pointing to
4760         ciKlass* arytype_klass = klass();
4761         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4762         ciValueKlass* vk = vak->element_klass()->as_value_klass();
4763         int shift = vak->log2_element_size();
4764         int mask = (1 << shift) - 1;
4765         intptr_t field_offset = ((offset - header) & mask);
4766         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
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-------------------------------------------


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-------------------------------------------
4964 // Type-specific hashing function.
4965 int TypeNarrowPtr::hash(void) const {
4966   return _ptrtype->hash() + 7;
4967 }
4968 


5710 //------------------------------make-------------------------------------------
5711 const TypeFunc *TypeFunc::make(ciMethod* method) {
5712   Compile* C = Compile::current();
5713   const TypeFunc* tf = C->last_tf(method); // check cache
5714   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5715   const TypeTuple *domain_sig, *domain_cc;
5716   // Value type arguments are not passed by reference, instead each
5717   // field of the value type is passed as an argument. We maintain 2
5718   // views of the argument list here: one based on the signature (with
5719   // a value type argument as a single slot), one based on the actual
5720   // calling convention (with a value type argument as a list of its
5721   // fields).
5722   if (method->is_static()) {
5723     domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5724     domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5725   } else {
5726     domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5727     domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5728   }
5729   const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false);
5730   const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);

5731   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5732   C->set_last_tf(method, tf);  // fill cache
5733   return tf;
5734 }
5735 
5736 //------------------------------meet-------------------------------------------
5737 // Compute the MEET of two types.  It returns a new Type object.
5738 const Type *TypeFunc::xmeet( const Type *t ) const {
5739   // Perform a fast test for common case; meeting the same types together.
5740   if( this == t ) return this;  // Meeting same type-rep?
5741 
5742   // Current "this->_base" is Func
5743   switch (t->base()) {          // switch on original type
5744 
5745   case Bottom:                  // Ye Olde Default
5746     return t;
5747 
5748   default:                      // All else is a mistake
5749     typerr(t);
5750 


< prev index next >