249 assert(type == ciTypeFlow::StateVector::null_type(), "");
250 return TypePtr::NULL_PTR;
251
252 case ciTypeFlow::StateVector::T_LONG2:
253 // The ciTypeFlow pass pushes a long, then the half.
254 // We do the same.
255 assert(type == ciTypeFlow::StateVector::long2_type(), "");
256 return TypeInt::TOP;
257
258 case ciTypeFlow::StateVector::T_DOUBLE2:
259 // The ciTypeFlow pass pushes double, then the half.
260 // Our convention is the same.
261 assert(type == ciTypeFlow::StateVector::double2_type(), "");
262 return Type::TOP;
263
264 case T_ADDRESS:
265 assert(type->is_return_address(), "");
266 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
267
268 case T_VALUETYPE:
269 if (type->is__Value()) {
270 return TypeValueTypePtr::NOTNULL;
271 } else {
272 return TypeValueType::make(type->as_value_klass());
273 }
274
275 default:
276 // make sure we did not mix up the cases:
277 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
278 assert(type != ciTypeFlow::StateVector::top_type(), "");
279 assert(type != ciTypeFlow::StateVector::null_type(), "");
280 assert(type != ciTypeFlow::StateVector::long2_type(), "");
281 assert(type != ciTypeFlow::StateVector::double2_type(), "");
282 assert(!type->is_return_address(), "");
283
284 return Type::get_const_type(type);
285 }
286 }
287
288
289 //-----------------------make_from_constant------------------------------------
290 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
291 int stable_dimension, bool is_narrow_oop,
292 bool is_autobox_cache) {
293 switch (constant.basic_type()) {
586 fsc[0] = TypeInt::CC;
587 fsc[1] = Type::MEMORY;
588 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
589
590 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
591 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
592 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
593 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
594 false, 0, Offset(oopDesc::mark_offset_in_bytes()));
595 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
596 false, 0, Offset(oopDesc::klass_offset_in_bytes()));
597 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
598
599 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
600
601 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
602 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
603
604 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
605
606 // TypeValueTypePtr::NOTNULL = EnableValhalla ? TypeValueTypePtr::make(TypePtr::NotNull, current->env()->Object_klass()) : NULL;
607 TypeValueTypePtr::NOTNULL = NULL;
608
609 mreg2type[Op_Node] = Type::BOTTOM;
610 mreg2type[Op_Set ] = 0;
611 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
612 mreg2type[Op_RegI] = TypeInt::INT;
613 mreg2type[Op_RegP] = TypePtr::BOTTOM;
614 mreg2type[Op_RegF] = Type::FLOAT;
615 mreg2type[Op_RegD] = Type::DOUBLE;
616 mreg2type[Op_RegL] = TypeLong::LONG;
617 mreg2type[Op_RegFlags] = TypeInt::CC;
618
619 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
620
621 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom);
622
623 #ifdef _LP64
624 if (UseCompressedOops) {
625 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
626 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
627 } else
628 #endif
943
944 // Meeting BOTTOM with anything?
945 if( _base == Bottom ) return BOTTOM;
946
947 // Current "this->_base" is one of: Bad, Multi, Control, Top,
948 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
949 switch (t->base()) { // Switch on original type
950
951 // Cut in half the number of cases I must handle. Only need cases for when
952 // the given enum "t->type" is less than or equal to the local enum "type".
953 case FloatCon:
954 case DoubleCon:
955 case Int:
956 case Long:
957 return t->xmeet(this);
958
959 case OopPtr:
960 return t->xmeet(this);
961
962 case InstPtr:
963 case ValueTypePtr:
964 return t->xmeet(this);
965
966 case MetadataPtr:
967 case KlassPtr:
968 return t->xmeet(this);
969
970 case AryPtr:
971 return t->xmeet(this);
972
973 case NarrowOop:
974 return t->xmeet(this);
975
976 case NarrowKlass:
977 return t->xmeet(this);
978
979 case ValueType:
980 return t->xmeet(this);
981
982 case Bad: // Type check
983 default: // Bogus type not in lattice
1175 const TypeF *TypeF::ONE; // Floating point one
1176
1177 //------------------------------make-------------------------------------------
1178 // Create a float constant
1179 const TypeF *TypeF::make(float f) {
1180 return (TypeF*)(new TypeF(f))->hashcons();
1181 }
1182
1183 //------------------------------meet-------------------------------------------
1184 // Compute the MEET of two types. It returns a new Type object.
1185 const Type *TypeF::xmeet( const Type *t ) const {
1186 // Perform a fast test for common case; meeting the same types together.
1187 if( this == t ) return this; // Meeting same type-rep?
1188
1189 // Current "this->_base" is FloatCon
1190 switch (t->base()) { // Switch on original type
1191 case AnyPtr: // Mixing with oops happens when javac
1192 case RawPtr: // reuses local variables
1193 case OopPtr:
1194 case InstPtr:
1195 case ValueTypePtr:
1196 case AryPtr:
1197 case MetadataPtr:
1198 case KlassPtr:
1199 case NarrowOop:
1200 case NarrowKlass:
1201 case Int:
1202 case Long:
1203 case DoubleTop:
1204 case DoubleCon:
1205 case DoubleBot:
1206 case Bottom: // Ye Olde Default
1207 return Type::BOTTOM;
1208
1209 case FloatBot:
1210 return t;
1211
1212 default: // All else is a mistake
1213 typerr(t);
1214
1215 case FloatCon: // Float-constant vs Float-constant?
1283 const TypeD *TypeD::ZERO; // Floating point zero
1284 const TypeD *TypeD::ONE; // Floating point one
1285
1286 //------------------------------make-------------------------------------------
1287 const TypeD *TypeD::make(double d) {
1288 return (TypeD*)(new TypeD(d))->hashcons();
1289 }
1290
1291 //------------------------------meet-------------------------------------------
1292 // Compute the MEET of two types. It returns a new Type object.
1293 const Type *TypeD::xmeet( const Type *t ) const {
1294 // Perform a fast test for common case; meeting the same types together.
1295 if( this == t ) return this; // Meeting same type-rep?
1296
1297 // Current "this->_base" is DoubleCon
1298 switch (t->base()) { // Switch on original type
1299 case AnyPtr: // Mixing with oops happens when javac
1300 case RawPtr: // reuses local variables
1301 case OopPtr:
1302 case InstPtr:
1303 case ValueTypePtr:
1304 case AryPtr:
1305 case MetadataPtr:
1306 case KlassPtr:
1307 case NarrowOop:
1308 case NarrowKlass:
1309 case Int:
1310 case Long:
1311 case FloatTop:
1312 case FloatCon:
1313 case FloatBot:
1314 case Bottom: // Ye Olde Default
1315 return Type::BOTTOM;
1316
1317 case DoubleBot:
1318 return t;
1319
1320 default: // All else is a mistake
1321 typerr(t);
1322
1323 case DoubleCon: // Double-constant vs Double-constant?
1429
1430 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1431 w = normalize_int_widen(lo, hi, w);
1432 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1433 }
1434
1435 //------------------------------meet-------------------------------------------
1436 // Compute the MEET of two types. It returns a new Type representation object
1437 // with reference count equal to the number of Types pointing at it.
1438 // Caller should wrap a Types around it.
1439 const Type *TypeInt::xmeet( const Type *t ) const {
1440 // Perform a fast test for common case; meeting the same types together.
1441 if( this == t ) return this; // Meeting same type?
1442
1443 // Currently "this->_base" is a TypeInt
1444 switch (t->base()) { // Switch on original type
1445 case AnyPtr: // Mixing with oops happens when javac
1446 case RawPtr: // reuses local variables
1447 case OopPtr:
1448 case InstPtr:
1449 case ValueTypePtr:
1450 case AryPtr:
1451 case MetadataPtr:
1452 case KlassPtr:
1453 case NarrowOop:
1454 case NarrowKlass:
1455 case Long:
1456 case FloatTop:
1457 case FloatCon:
1458 case FloatBot:
1459 case DoubleTop:
1460 case DoubleCon:
1461 case DoubleBot:
1462 case Bottom: // Ye Olde Default
1463 return Type::BOTTOM;
1464 default: // All else is a mistake
1465 typerr(t);
1466 case Top: // No change
1467 return this;
1468 case Int: // Int vs Int?
1469 break;
1689 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1690 w = normalize_long_widen(lo, hi, w);
1691 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1692 }
1693
1694
1695 //------------------------------meet-------------------------------------------
1696 // Compute the MEET of two types. It returns a new Type representation object
1697 // with reference count equal to the number of Types pointing at it.
1698 // Caller should wrap a Types around it.
1699 const Type *TypeLong::xmeet( const Type *t ) const {
1700 // Perform a fast test for common case; meeting the same types together.
1701 if( this == t ) return this; // Meeting same type?
1702
1703 // Currently "this->_base" is a TypeLong
1704 switch (t->base()) { // Switch on original type
1705 case AnyPtr: // Mixing with oops happens when javac
1706 case RawPtr: // reuses local variables
1707 case OopPtr:
1708 case InstPtr:
1709 case ValueTypePtr:
1710 case AryPtr:
1711 case MetadataPtr:
1712 case KlassPtr:
1713 case NarrowOop:
1714 case NarrowKlass:
1715 case Int:
1716 case FloatTop:
1717 case FloatCon:
1718 case FloatBot:
1719 case DoubleTop:
1720 case DoubleCon:
1721 case DoubleBot:
1722 case Bottom: // Ye Olde Default
1723 return Type::BOTTOM;
1724 default: // All else is a mistake
1725 typerr(t);
1726 case Top: // No change
1727 return this;
1728 case Long: // Long vs Long?
1729 break;
2006 //field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(TypePtr::NOTNULL);
2007 field_array[TypeFunc::Parms] = get_const_type(return_type);
2008 }
2009 break;
2010 case T_VOID:
2011 break;
2012 default:
2013 ShouldNotReachHere();
2014 }
2015 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2016 }
2017
2018 // Make a TypeTuple from the domain of a method signature
2019 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2020 uint arg_cnt = sig->size();
2021
2022 int vt_extra = 0;
2023 if (vt_fields_as_args) {
2024 for (int i = 0; i < sig->count(); i++) {
2025 ciType* type = sig->type_at(i);
2026 if (type->basic_type() == T_VALUETYPE && !type->is__Value()) {
2027 assert(type->is_valuetype(), "inconsistent type");
2028 ciValueKlass* vk = (ciValueKlass*)type;
2029 vt_extra += vk->value_arg_slots()-1;
2030 }
2031 }
2032 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2033 }
2034
2035 uint pos = TypeFunc::Parms;
2036 const Type **field_array;
2037 if (recv != NULL) {
2038 arg_cnt++;
2039 bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype() && !recv->is__Value();
2040 if (vt_fields_for_recv) {
2041 ciValueKlass* vk = (ciValueKlass*)recv;
2042 vt_extra += vk->value_arg_slots()-1;
2043 }
2044 field_array = fields(arg_cnt + vt_extra);
2045 // Use get_const_type here because it respects UseUniqueSubclasses:
2046 if (vt_fields_for_recv) {
2047 ciValueKlass* vk = (ciValueKlass*)recv;
2048 collect_value_fields(vk, field_array, pos);
2049 } else {
2050 if (recv->is_valuetype()) {
2051 // TODO For now, we just deoptimize if the value type receiver is null
2052 field_array[pos++] = get_const_type(recv);
2053 } else {
2054 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2055 }
2056 }
2057 } else {
2058 field_array = fields(arg_cnt + vt_extra);
2059 }
2068 field_array[pos++] = Type::HALF;
2069 break;
2070 case T_DOUBLE:
2071 field_array[pos++] = Type::DOUBLE;
2072 field_array[pos++] = Type::HALF;
2073 break;
2074 case T_OBJECT:
2075 case T_ARRAY:
2076 case T_FLOAT:
2077 case T_INT:
2078 field_array[pos++] = get_const_type(type);
2079 break;
2080 case T_BOOLEAN:
2081 case T_CHAR:
2082 case T_BYTE:
2083 case T_SHORT:
2084 field_array[pos++] = TypeInt::INT;
2085 break;
2086 case T_VALUETYPE: {
2087 assert(type->is_valuetype(), "inconsistent type");
2088 if (vt_fields_as_args && !type->is__Value()) {
2089 ciValueKlass* vk = (ciValueKlass*)type;
2090 collect_value_fields(vk, field_array, pos);
2091 } else {
2092 // Value types arguments cannot be NULL
2093 // field_array[pos++] = get_const_type(type)->join_speculative(TypePtr::NOTNULL);
2094 // TODO they can be NULL in LWorld
2095 field_array[pos++] = get_const_type(type);
2096 }
2097 break;
2098 }
2099 default:
2100 ShouldNotReachHere();
2101 }
2102 i++;
2103 }
2104 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2105
2106 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2107 }
2108
2220 }
2221 return false;
2222 }
2223
2224 //=============================================================================
2225 // Convenience common pre-built types.
2226
2227 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2228 // Certain normalizations keep us sane when comparing types.
2229 // We do not want arrayOop variables to differ only by the wideness
2230 // of their index types. Pick minimum wideness, since that is the
2231 // forced wideness of small ranges anyway.
2232 if (size->_widen != Type::WidenMin)
2233 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2234 else
2235 return size;
2236 }
2237
2238 //------------------------------make-------------------------------------------
2239 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2240 if (elem->isa_valuetypeptr()) {
2241 // Value type array elements cannot be NULL
2242 elem = elem->join_speculative(TypePtr::NOTNULL)->is_oopptr();
2243 }
2244 if (UseCompressedOops && elem->isa_oopptr()) {
2245 elem = elem->make_narrowoop();
2246 }
2247 size = normalize_array_size(size);
2248 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2249 }
2250
2251 //------------------------------meet-------------------------------------------
2252 // Compute the MEET of two types. It returns a new Type object.
2253 const Type *TypeAry::xmeet( const Type *t ) const {
2254 // Perform a fast test for common case; meeting the same types together.
2255 if( this == t ) return this; // Meeting same type-rep?
2256
2257 // Current "this->_base" is Ary
2258 switch (t->base()) { // switch on original type
2259
2260 case Bottom: // Ye Olde Default
2422 case DoubleCon:
2423 case DoubleBot:
2424 case NarrowKlass:
2425 case Bottom:
2426 return Type::BOTTOM;
2427
2428 case OopPtr:
2429 case MetadataPtr:
2430 case KlassPtr:
2431 case RawPtr:
2432 return TypePtr::BOTTOM;
2433
2434 case Top:
2435 return this;
2436
2437 case NarrowOop: {
2438 return t->make_ptr()->xmeet(this)->make_narrowoop();
2439 }
2440
2441 case AryPtr:
2442 case InstPtr:
2443 case ValueTypePtr: {
2444 return t->xmeet(this);
2445 }
2446
2447 case ValueType: {
2448 // All value types inherit from Object
2449 return TypeInstPtr::NOTNULL;
2450 }
2451
2452 default: // All else is a mistake
2453 typerr(t);
2454
2455 }
2456 return this;
2457 }
2458
2459 //------------------------------xdual------------------------------------------
2460 const Type* TypeValueType::xdual() const {
2461 return this;
2462 }
2463
2694 case FloatBot:
2695 case DoubleTop:
2696 case DoubleCon:
2697 case DoubleBot:
2698 case NarrowOop:
2699 case NarrowKlass:
2700 case Bottom: // Ye Olde Default
2701 return Type::BOTTOM;
2702 case Top:
2703 return this;
2704
2705 case AnyPtr: { // Meeting to AnyPtrs
2706 const TypePtr *tp = t->is_ptr();
2707 const TypePtr* speculative = xmeet_speculative(tp);
2708 int depth = meet_inline_depth(tp->inline_depth());
2709 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2710 }
2711 case RawPtr: // For these, flip the call around to cut down
2712 case OopPtr:
2713 case InstPtr: // on the cases I have to handle.
2714 case ValueTypePtr:
2715 case AryPtr:
2716 case MetadataPtr:
2717 case KlassPtr:
2718 return t->xmeet(this); // Call in reverse direction
2719 default: // All else is a mistake
2720 typerr(t);
2721
2722 }
2723 return this;
2724 }
2725
2726 //------------------------------meet_offset------------------------------------
2727 Type::Offset TypePtr::meet_offset(int offset) const {
2728 return _offset.meet(Offset(offset));
2729 }
2730
2731 //------------------------------dual_offset------------------------------------
2732 Type::Offset TypePtr::dual_offset() const {
2733 return _offset.dual();
2734 }
3106 switch( t->base() ) { // switch on original type
3107 case Bottom: // Ye Olde Default
3108 return t;
3109 case Top:
3110 return this;
3111 case AnyPtr: // Meeting to AnyPtrs
3112 break;
3113 case RawPtr: { // might be top, bot, any/not or constant
3114 enum PTR tptr = t->is_ptr()->ptr();
3115 enum PTR ptr = meet_ptr( tptr );
3116 if( ptr == Constant ) { // Cannot be equal constants, so...
3117 if( tptr == Constant && _ptr != Constant) return t;
3118 if( _ptr == Constant && tptr != Constant) return this;
3119 ptr = NotNull; // Fall down in lattice
3120 }
3121 return make( ptr );
3122 }
3123
3124 case OopPtr:
3125 case InstPtr:
3126 case ValueTypePtr:
3127 case AryPtr:
3128 case MetadataPtr:
3129 case KlassPtr:
3130 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3131 default: // All else is a mistake
3132 typerr(t);
3133 }
3134
3135 // Found an AnyPtr type vs self-RawPtr type
3136 const TypePtr *tp = t->is_ptr();
3137 switch (tp->ptr()) {
3138 case TypePtr::TopPTR: return this;
3139 case TypePtr::BotPTR: return t;
3140 case TypePtr::Null:
3141 if( _ptr == TypePtr::TopPTR ) return t;
3142 return TypeRawPtr::BOTTOM;
3143 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3144 case TypePtr::AnyNull:
3145 if( _ptr == TypePtr::Constant) return this;
3146 return make( meet_ptr(TypePtr::AnyNull) );
3228 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3229 if (klass()->is_obj_array_klass()) {
3230 _is_ptr_to_narrowoop = true;
3231 } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3232 // Check if the field of the value type array element contains oops
3233 ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3234 int foffset = field_offset.get() + vk->first_field_offset();
3235 ciField* field = vk->get_field_by_offset(foffset, false);
3236 assert(field != NULL, "missing field");
3237 BasicType bt = field->layout_type();
3238 assert(bt != T_VALUETYPEPTR, "unexpected type");
3239 _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE);
3240 }
3241 } else if (klass()->is_instance_klass()) {
3242 if (this->isa_klassptr()) {
3243 // Perm objects don't use compressed references
3244 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3245 // unsafe access
3246 _is_ptr_to_narrowoop = UseCompressedOops;
3247 } else { // exclude unsafe ops
3248 assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr.");
3249 if (klass() == ciEnv::current()->Class_klass() &&
3250 (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3251 this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3252 // Special hidden fields from the Class.
3253 assert(this->isa_instptr(), "must be an instance ptr.");
3254 _is_ptr_to_narrowoop = false;
3255 } else if (klass() == ciEnv::current()->Class_klass() &&
3256 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3257 // Static fields
3258 assert(o != NULL, "must be constant");
3259 ciInstanceKlass* ik = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3260 BasicType basic_elem_type;
3261 if (ik->is_valuetype() && this->offset() == ik->as_value_klass()->default_value_offset()) {
3262 // Special hidden field that contains the oop of the default value type
3263 basic_elem_type = T_VALUETYPE;
3264 } else {
3265 ciField* field = ik->get_field_by_offset(this->offset(), true);
3266 assert(field != NULL, "missing field");
3267 basic_elem_type = field->layout_type();
3268 }
3386 case AnyNull: {
3387 int instance_id = meet_instance_id(InstanceTop);
3388 return make(ptr, offset, instance_id, speculative, depth);
3389 }
3390 case BotPTR:
3391 case NotNull:
3392 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3393 default: typerr(t);
3394 }
3395 }
3396
3397 case OopPtr: { // Meeting to other OopPtrs
3398 const TypeOopPtr *tp = t->is_oopptr();
3399 int instance_id = meet_instance_id(tp->instance_id());
3400 const TypePtr* speculative = xmeet_speculative(tp);
3401 int depth = meet_inline_depth(tp->inline_depth());
3402 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3403 }
3404
3405 case InstPtr: // For these, flip the call around to cut down
3406 case ValueTypePtr:
3407 case AryPtr:
3408 return t->xmeet(this); // Call in reverse direction
3409
3410 } // End of switch
3411 return this; // Return the double constant
3412 }
3413
3414
3415 //------------------------------xdual------------------------------------------
3416 // Dual of a pure heap pointer. No relevant klass or oop information.
3417 const Type *TypeOopPtr::xdual() const {
3418 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3419 assert(const_oop() == NULL, "no constants here");
3420 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3421 }
3422
3423 //--------------------------make_from_klass_common-----------------------------
3424 // Computes the element-type given a klass.
3425 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3426 if (klass->is_valuetype()) {
3427 return TypeValueTypePtr::make(TypePtr::BotPTR, klass->as_value_klass());
3428 } else if (klass->is_instance_klass()) {
3429 Compile* C = Compile::current();
3430 Dependencies* deps = C->dependencies();
3431 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3432 // Element is an instance
3433 bool klass_is_exact = false;
3434 if (klass->is_loaded()) {
3435 // Try to set klass_is_exact.
3436 ciInstanceKlass* ik = klass->as_instance_klass();
3437 klass_is_exact = ik->is_final();
3438 if (!klass_is_exact && klass_change
3439 && deps != NULL && UseUniqueSubclasses) {
3440 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3441 if (sub != NULL) {
3442 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3443 klass = ik = sub;
3444 klass_is_exact = sub->is_final();
3445 }
3446 }
3447 if (!klass_is_exact && try_for_exact
3448 && deps != NULL && UseExactTypes) {
3471 // We used to pass NotNull in here, asserting that the array pointer
3472 // is not-null. That was not true in general.
3473 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3474 return arr;
3475 } else if (klass->is_value_array_klass()) {
3476 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3477 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3478 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3479 return arr;
3480 } else {
3481 ShouldNotReachHere();
3482 return NULL;
3483 }
3484 }
3485
3486 //------------------------------make_from_constant-----------------------------
3487 // Make a java pointer from an oop constant
3488 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3489 assert(!o->is_null_object(), "null object not yet handled here.");
3490 ciKlass* klass = o->klass();
3491 if (klass->is_valuetype()) {
3492 // Element is a value type
3493 if (require_constant) {
3494 if (!o->can_be_constant()) return NULL;
3495 } else if (!o->should_be_constant()) {
3496 return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass());
3497 }
3498 return TypeValueTypePtr::make(o);
3499 } else if (klass->is_instance_klass()) {
3500 // Element is an instance
3501 if (require_constant) {
3502 if (!o->can_be_constant()) return NULL;
3503 } else if (!o->should_be_constant()) {
3504 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3505 }
3506 return TypeInstPtr::make(o);
3507 } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) {
3508 // Element is an object array. Recursively call ourself.
3509 const TypeOopPtr *etype =
3510 TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3511 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3512 // We used to pass NotNull in here, asserting that the sub-arrays
3513 // are all not-null. This is not true in generally, as code can
3514 // slam NULLs down in the subarrays.
3515 if (require_constant) {
3516 if (!o->can_be_constant()) return NULL;
3517 } else if (!o->should_be_constant()) {
3518 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3519 }
3520 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4177 else if (above_centerline(tinst ->_ptr))
4178 o = this_oop;
4179 else
4180 ptr = NotNull;
4181 }
4182 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4183 } // Else classes are not equal
4184
4185 // Since klasses are different, we require a LCA in the Java
4186 // class hierarchy - which means we have to fall to at least NotNull.
4187 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4188 ptr = NotNull;
4189
4190 instance_id = InstanceBot;
4191
4192 // Now we find the LCA of Java classes
4193 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4194 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4195 } // End of case InstPtr
4196
4197 case ValueTypePtr: {
4198 // All value types inherit from Object
4199 const TypeValueTypePtr* tp = t->is_valuetypeptr();
4200 Offset offset = meet_offset(tp->offset());
4201 PTR ptr = meet_ptr(tp->ptr());
4202 int instance_id = meet_instance_id(tp->instance_id());
4203 const TypePtr* speculative = xmeet_speculative(tp);
4204 int depth = meet_inline_depth(tp->inline_depth());
4205 switch (ptr) {
4206 case TopPTR:
4207 case AnyNull: // Fall 'down' to dual of object klass
4208 // For instances when a subclass meets a superclass we fall
4209 // below the centerline when the superclass is exact. We need to
4210 // do the same here.
4211 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
4212 return TypeValueTypePtr::make(ptr, tp->value_klass(), NULL, offset, instance_id, speculative, depth);
4213 } else {
4214 // cannot subclass, so the meet has to fall badly below the centerline
4215 ptr = NotNull;
4216 instance_id = InstanceBot;
4217 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4218 }
4219 case Constant:
4220 case NotNull:
4221 case BotPTR: // Fall down to object klass
4222 // LCA is object_klass, but if we subclass from the top we can do better
4223 if (above_centerline(_ptr)) { // if( _ptr == TopPTR || _ptr == AnyNull )
4224 // If 'this' (InstPtr) is above the centerline and it is Object class
4225 // then we can subclass in the Java class hierarchy.
4226 // For instances when a subclass meets a superclass we fall
4227 // below the centerline when the superclass is exact. We need
4228 // to do the same here.
4229 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
4230 // that is, tp's value type is a subtype of my klass
4231 return TypeValueTypePtr::make(ptr, tp->value_klass(), (ptr == Constant ? tp->const_oop() : NULL), offset, instance_id, speculative, depth);
4232 }
4233 }
4234 // The other case cannot happen, since I cannot be a subtype of a value type.
4235 // The meet falls down to Object class below centerline.
4236 if (ptr == Constant) {
4237 ptr = NotNull;
4238 }
4239 instance_id = InstanceBot;
4240 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4241 default: typerr(t);
4242 }
4243 }
4244
4245 case ValueType: {
4246 // All value types inherit from Object
4247 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
4248 }
4249
4250 } // End of switch
4251 return this; // Return the double constant
4252 }
4253
4254
4255 //------------------------java_mirror_type--------------------------------------
4256 ciType* TypeInstPtr::java_mirror_type() const {
4257 // must be a singleton type
4258 if( const_oop() == NULL ) return NULL;
4259
4260 // must be of type java.lang.Class
4261 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
4262
4263 return const_oop()->as_instance()->java_mirror_type();
4264 }
4729 // that is, my array type is a subtype of 'tp' klass
4730 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4731 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4732 }
4733 }
4734 // The other case cannot happen, since t cannot be a subtype of an array.
4735 // The meet falls down to Object class below centerline.
4736 if( ptr == Constant )
4737 ptr = NotNull;
4738 instance_id = InstanceBot;
4739 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4740 default: typerr(t);
4741 }
4742 }
4743
4744 case ValueType: {
4745 // All value types inherit from Object
4746 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
4747 }
4748
4749 case ValueTypePtr: {
4750 const TypeValueTypePtr* tp = t->is_valuetypeptr();
4751 Offset offset = meet_offset(tp->offset());
4752 PTR ptr = meet_ptr(tp->ptr());
4753 int instance_id = meet_instance_id(tp->instance_id());
4754 const TypePtr* speculative = xmeet_speculative(tp);
4755 int depth = meet_inline_depth(tp->inline_depth());
4756 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4757 }
4758
4759 }
4760 return this; // Lint noise
4761 }
4762
4763 //------------------------------xdual------------------------------------------
4764 // Dual: compute field-by-field dual
4765 const Type *TypeAryPtr::xdual() const {
4766 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
4767 }
4768
4769 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
4770 return _field_offset.meet(offset);
4771 }
4772
4773 //------------------------------dual_offset------------------------------------
4774 Type::Offset TypeAryPtr::dual_field_offset() const {
4775 return _field_offset.dual();
4776 }
4777
4778 //----------------------interface_vs_oop---------------------------------------
4899 }
4900 }
4901 }
4902 }
4903 return add_offset(offset - adj);
4904 }
4905
4906 // Return offset incremented by field_offset for flattened value type arrays
4907 const int TypeAryPtr::flattened_offset() const {
4908 int offset = _offset.get();
4909 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
4910 _field_offset != Offset::bottom && _field_offset != Offset::top) {
4911 offset += _field_offset.get();
4912 }
4913 return offset;
4914 }
4915
4916 //=============================================================================
4917
4918
4919 //=============================================================================
4920
4921 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4922 //------------------------------make-------------------------------------------
4923 const TypeValueTypePtr* TypeValueTypePtr::make(PTR ptr, ciValueKlass* vk, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4924 return (TypeValueTypePtr*)(new TypeValueTypePtr(ptr, vk, o, offset, instance_id, speculative, inline_depth))->hashcons();
4925 }
4926
4927 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4928 return make(_ptr, value_klass(), _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4929 }
4930
4931 //------------------------------cast_to_ptr_type-------------------------------
4932 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4933 if (ptr == _ptr) return this;
4934 return make(ptr, value_klass(), _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4935 }
4936
4937 //-----------------------------cast_to_instance_id----------------------------
4938 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4939 if (instance_id == _instance_id) return this;
4940 return make(_ptr, value_klass(), _const_oop, _offset, instance_id, _speculative, _inline_depth);
4941 }
4942
4943 //------------------------------meet-------------------------------------------
4944 // Compute the MEET of two types. It returns a new Type object.
4945 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const {
4946 // Perform a fast test for common case; meeting the same types together.
4947 if (this == t) return this; // Meeting same type-rep?
4948
4949 switch (t->base()) { // switch on original type
4950 case Int: // Mixing ints & oops happens when javac
4951 case Long: // reuses local variables
4952 case FloatTop:
4953 case FloatCon:
4954 case FloatBot:
4955 case DoubleTop:
4956 case DoubleCon:
4957 case DoubleBot:
4958 case NarrowOop:
4959 case NarrowKlass:
4960 case Bottom: // Ye Olde Default
4961 return Type::BOTTOM;
4962
4963 case MetadataPtr:
4964 case KlassPtr:
4965 case RawPtr:
4966 return TypePtr::BOTTOM;
4967
4968 case Top:
4969 return this;
4970
4971 default: // All else is a mistake
4972 typerr(t);
4973
4974 case OopPtr: {
4975 // Found a OopPtr type vs self-ValueTypePtr type
4976 const TypeOopPtr* tp = t->is_oopptr();
4977 Offset offset = meet_offset(tp->offset());
4978 PTR ptr = meet_ptr(tp->ptr());
4979 int instance_id = meet_instance_id(tp->instance_id());
4980 const TypePtr* speculative = xmeet_speculative(tp);
4981 int depth = meet_inline_depth(tp->inline_depth());
4982 switch (tp->ptr()) {
4983 case TopPTR:
4984 case AnyNull: {
4985 return make(ptr, value_klass(), NULL, offset, instance_id, speculative, depth);
4986 }
4987 case NotNull:
4988 case BotPTR: {
4989 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4990 }
4991 default: typerr(t);
4992 }
4993 }
4994
4995 case AnyPtr: {
4996 // Found an AnyPtr type vs self-ValueTypePtr type
4997 const TypePtr* tp = t->is_ptr();
4998 Offset offset = meet_offset(tp->offset());
4999 PTR ptr = meet_ptr(tp->ptr());
5000 int instance_id = meet_instance_id(InstanceTop);
5001 const TypePtr* speculative = xmeet_speculative(tp);
5002 int depth = meet_inline_depth(tp->inline_depth());
5003 switch (tp->ptr()) {
5004 case Null:
5005 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5006 // else fall through to AnyNull
5007 case TopPTR:
5008 case AnyNull: {
5009 return make(ptr, value_klass(), NULL, offset, instance_id, speculative, depth);
5010 }
5011 case NotNull:
5012 case BotPTR:
5013 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5014 default: typerr(t);
5015 }
5016 }
5017
5018 case ValueTypePtr: {
5019 // Found an ValueTypePtr type vs self-ValueTypePtr type
5020 const TypeValueTypePtr* tp = t->is_valuetypeptr();
5021 Offset offset = meet_offset(tp->offset());
5022 PTR ptr = meet_ptr(tp->ptr());
5023 int instance_id = meet_instance_id(InstanceTop);
5024 const TypePtr* speculative = xmeet_speculative(tp);
5025 int depth = meet_inline_depth(tp->inline_depth());
5026 // Compute constant oop
5027 ciObject* o = NULL;
5028 ciObject* this_oop = const_oop();
5029 ciObject* tp_oop = tp->const_oop();
5030 ciKlass* klass = NULL;
5031 if (_klass != tp->_klass) {
5032 // All value types inherit from Object
5033 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, o, offset, instance_id, speculative, depth);
5034 } else {
5035 klass = _klass;
5036 }
5037 if (ptr == Constant) {
5038 if (this_oop != NULL && tp_oop != NULL &&
5039 this_oop->equals(tp_oop) ) {
5040 o = this_oop;
5041 } else if (above_centerline(this ->_ptr)) {
5042 o = tp_oop;
5043 } else if (above_centerline(tp ->_ptr)) {
5044 o = this_oop;
5045 } else {
5046 ptr = NotNull;
5047 }
5048 }
5049 return make(ptr, klass->as_value_klass(), o, offset, instance_id, speculative, depth);
5050 }
5051
5052 case InstPtr: {
5053 // All value types inherit from Object
5054 const TypeInstPtr* tp = t->is_instptr();
5055 Offset offset = meet_offset(tp->offset());
5056 PTR ptr = meet_ptr(tp->ptr());
5057 int instance_id = meet_instance_id(tp->instance_id());
5058 const TypePtr* speculative = xmeet_speculative(tp);
5059 int depth = meet_inline_depth(tp->inline_depth());
5060 switch (ptr) {
5061 case TopPTR:
5062 case AnyNull: // Fall 'down' to dual of object klass
5063 // For instances when a subclass meets a superclass we fall
5064 // below the centerline when the superclass is exact. We need to
5065 // do the same here.
5066 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5067 return make(ptr, _klass->as_value_klass(), NULL, offset, instance_id, speculative, depth);
5068 } else {
5069 // cannot subclass, so the meet has to fall badly below the centerline
5070 ptr = NotNull;
5071 instance_id = InstanceBot;
5072 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
5073 }
5074 case Constant:
5075 case NotNull:
5076 case BotPTR: // Fall down to object klass
5077 // LCA is object_klass, but if we subclass from the top we can do better
5078 if (above_centerline(tp->ptr())) {
5079 // If 'tp' is above the centerline and it is Object class
5080 // then we can subclass in the Java class hierarchy.
5081 // For instances when a subclass meets a superclass we fall
5082 // below the centerline when the superclass is exact. We need
5083 // to do the same here.
5084 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5085 // that is, my value type is a subtype of 'tp' klass
5086 return make(ptr, _klass->as_value_klass(), (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
5087 }
5088 }
5089 // The other case cannot happen, since t cannot be a subtype of a value type.
5090 // The meet falls down to Object class below centerline.
5091 if (ptr == Constant) {
5092 ptr = NotNull;
5093 }
5094 instance_id = InstanceBot;
5095 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
5096 default: typerr(t);
5097 }
5098 }
5099
5100 case ValueType: {
5101 // All value types inherit from Object
5102 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
5103 }
5104
5105 case AryPtr: {
5106 const TypeAryPtr* tp = t->is_aryptr();
5107 Offset offset = meet_offset(tp->offset());
5108 PTR ptr = meet_ptr(tp->ptr());
5109 int instance_id = meet_instance_id(tp->instance_id());
5110 const TypePtr* speculative = xmeet_speculative(tp);
5111 int depth = meet_inline_depth(tp->inline_depth());
5112 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
5113 }
5114
5115 }
5116 return this;
5117 }
5118
5119 // Dual: compute field-by-field dual
5120 const Type* TypeValueTypePtr::xdual() const {
5121 return new TypeValueTypePtr(dual_ptr(), value_klass(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
5122 }
5123
5124 //------------------------------eq---------------------------------------------
5125 // Structural equality check for Type representations
5126 bool TypeValueTypePtr::eq(const Type* t) const {
5127 const TypeValueTypePtr* p = t->is_valuetypeptr();
5128 return klass()->equals(p->klass()) && TypeOopPtr::eq(p);
5129 }
5130
5131 //------------------------------hash-------------------------------------------
5132 // Type-specific hashing function.
5133 int TypeValueTypePtr::hash(void) const {
5134 return java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
5135 }
5136
5137 //------------------------------is__Value--------------------------------------
5138 bool TypeValueTypePtr::is__Value() const {
5139 // FIXME
5140 return false;
5141 }
5142
5143 //------------------------------dump2------------------------------------------
5144 #ifndef PRODUCT
5145 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const {
5146 st->print("valuetype* ");
5147 klass()->print_name_on(st);
5148 st->print(":%s", ptr_msg[_ptr]);
5149 _offset.dump2(st);
5150 }
5151 #endif
5152
5153 //=============================================================================
5154
5155 //------------------------------hash-------------------------------------------
5156 // Type-specific hashing function.
5157 int TypeNarrowPtr::hash(void) const {
5158 return _ptrtype->hash() + 7;
5159 }
5160
5161 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5162 return _ptrtype->singleton();
5163 }
5164
5165 bool TypeNarrowPtr::empty(void) const {
5166 return _ptrtype->empty();
5167 }
5168
5169 intptr_t TypeNarrowPtr::get_con() const {
5170 return _ptrtype->get_con();
5171 }
5172
5173 bool TypeNarrowPtr::eq( const Type *t ) const {
5174 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5218 return make_hash_same_narrowptr(result->is_ptr());
5219 }
5220 return result;
5221 }
5222
5223 // Current "this->_base" is NarrowKlass or NarrowOop
5224 switch (t->base()) { // switch on original type
5225
5226 case Int: // Mixing ints & oops happens when javac
5227 case Long: // reuses local variables
5228 case FloatTop:
5229 case FloatCon:
5230 case FloatBot:
5231 case DoubleTop:
5232 case DoubleCon:
5233 case DoubleBot:
5234 case AnyPtr:
5235 case RawPtr:
5236 case OopPtr:
5237 case InstPtr:
5238 case ValueTypePtr:
5239 case AryPtr:
5240 case MetadataPtr:
5241 case KlassPtr:
5242 case NarrowOop:
5243 case NarrowKlass:
5244 case Bottom: // Ye Olde Default
5245 return Type::BOTTOM;
5246 case Top:
5247 return this;
5248
5249 case ValueType:
5250 return t->xmeet(this);
5251
5252 default: // All else is a mistake
5253 typerr(t);
5254
5255 } // End of switch
5256
5257 return this;
5258 }
5404 PTR ptr = meet_ptr(tp->ptr());
5405 switch (tp->ptr()) {
5406 case Null:
5407 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5408 // else fall through:
5409 case TopPTR:
5410 case AnyNull: {
5411 return make(ptr, _metadata, offset);
5412 }
5413 case BotPTR:
5414 case NotNull:
5415 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5416 default: typerr(t);
5417 }
5418 }
5419
5420 case RawPtr:
5421 case KlassPtr:
5422 case OopPtr:
5423 case InstPtr:
5424 case ValueTypePtr:
5425 case AryPtr:
5426 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5427
5428 case MetadataPtr: {
5429 const TypeMetadataPtr *tp = t->is_metadataptr();
5430 Offset offset = meet_offset(tp->offset());
5431 PTR tptr = tp->ptr();
5432 PTR ptr = meet_ptr(tptr);
5433 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5434 if (tptr == TopPTR || _ptr == TopPTR ||
5435 metadata()->equals(tp->metadata())) {
5436 return make(ptr, md, offset);
5437 }
5438 // metadata is different
5439 if( ptr == Constant ) { // Cannot be equal constants, so...
5440 if( tptr == Constant && _ptr != Constant) return t;
5441 if( _ptr == Constant && tptr != Constant) return this;
5442 ptr = NotNull; // Fall down in lattice
5443 }
5444 return make(ptr, NULL, offset);
5557 !ftkp->klass_is_exact() && // Keep exact interface klass
5558 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5559 return ktkp->cast_to_ptr_type(ftkp->ptr());
5560 }
5561
5562 return ft;
5563 }
5564
5565 //----------------------compute_klass------------------------------------------
5566 // Compute the defining klass for this class
5567 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5568 // Compute _klass based on element type.
5569 ciKlass* k_ary = NULL;
5570 const TypeAryPtr *tary;
5571 const Type* el = elem();
5572 if (el->isa_narrowoop()) {
5573 el = el->make_ptr();
5574 }
5575
5576 // Get element klass
5577 if (el->isa_instptr() || el->isa_valuetypeptr()) {
5578 // Compute object array klass from element klass
5579 k_ary = ciArrayKlass::make(el->is_oopptr()->klass());
5580 } else if (el->isa_valuetype()) {
5581 k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass());
5582 } else if ((tary = el->isa_aryptr()) != NULL) {
5583 // Compute array klass from element klass
5584 ciKlass* k_elem = tary->klass();
5585 // If element type is something like bottom[], k_elem will be null.
5586 if (k_elem != NULL)
5587 k_ary = ciObjArrayKlass::make(k_elem);
5588 } else if ((el->base() == Type::Top) ||
5589 (el->base() == Type::Bottom)) {
5590 // element type of Bottom occurs from meet of basic type
5591 // and object; Top occurs when doing join on Bottom.
5592 // Leave k_ary at NULL.
5593 } else {
5594 // Cannot compute array klass directly from basic type,
5595 // since subtypes of TypeInt all have basic type T_INT.
5596 #ifdef ASSERT
5597 if (verify && el->isa_int()) {
5722 PTR ptr = meet_ptr(tp->ptr());
5723 switch (tp->ptr()) {
5724 case TopPTR:
5725 return this;
5726 case Null:
5727 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5728 case AnyNull:
5729 return make( ptr, klass(), offset );
5730 case BotPTR:
5731 case NotNull:
5732 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5733 default: typerr(t);
5734 }
5735 }
5736
5737 case RawPtr:
5738 case MetadataPtr:
5739 case OopPtr:
5740 case AryPtr: // Meet with AryPtr
5741 case InstPtr: // Meet with InstPtr
5742 case ValueTypePtr:
5743 return TypePtr::BOTTOM;
5744
5745 //
5746 // A-top }
5747 // / | \ } Tops
5748 // B-top A-any C-top }
5749 // | / | \ | } Any-nulls
5750 // B-any | C-any }
5751 // | | |
5752 // B-con A-con C-con } constants; not comparable across classes
5753 // | | |
5754 // B-not | C-not }
5755 // | \ | / | } not-nulls
5756 // B-bot A-not C-bot }
5757 // \ | / } Bottoms
5758 // A-bot }
5759 //
5760
5761 case KlassPtr: { // Meet two KlassPtr types
5762 const TypeKlassPtr *tkls = t->is_klassptr();
|
249 assert(type == ciTypeFlow::StateVector::null_type(), "");
250 return TypePtr::NULL_PTR;
251
252 case ciTypeFlow::StateVector::T_LONG2:
253 // The ciTypeFlow pass pushes a long, then the half.
254 // We do the same.
255 assert(type == ciTypeFlow::StateVector::long2_type(), "");
256 return TypeInt::TOP;
257
258 case ciTypeFlow::StateVector::T_DOUBLE2:
259 // The ciTypeFlow pass pushes double, then the half.
260 // Our convention is the same.
261 assert(type == ciTypeFlow::StateVector::double2_type(), "");
262 return Type::TOP;
263
264 case T_ADDRESS:
265 assert(type->is_return_address(), "");
266 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
267
268 case T_VALUETYPE:
269 return TypeValueType::make(type->as_value_klass());
270
271 default:
272 // make sure we did not mix up the cases:
273 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
274 assert(type != ciTypeFlow::StateVector::top_type(), "");
275 assert(type != ciTypeFlow::StateVector::null_type(), "");
276 assert(type != ciTypeFlow::StateVector::long2_type(), "");
277 assert(type != ciTypeFlow::StateVector::double2_type(), "");
278 assert(!type->is_return_address(), "");
279
280 return Type::get_const_type(type);
281 }
282 }
283
284
285 //-----------------------make_from_constant------------------------------------
286 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
287 int stable_dimension, bool is_narrow_oop,
288 bool is_autobox_cache) {
289 switch (constant.basic_type()) {
582 fsc[0] = TypeInt::CC;
583 fsc[1] = Type::MEMORY;
584 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
585
586 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
587 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
588 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
589 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
590 false, 0, Offset(oopDesc::mark_offset_in_bytes()));
591 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
592 false, 0, Offset(oopDesc::klass_offset_in_bytes()));
593 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
594
595 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
596
597 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
598 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
599
600 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
601
602 mreg2type[Op_Node] = Type::BOTTOM;
603 mreg2type[Op_Set ] = 0;
604 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
605 mreg2type[Op_RegI] = TypeInt::INT;
606 mreg2type[Op_RegP] = TypePtr::BOTTOM;
607 mreg2type[Op_RegF] = Type::FLOAT;
608 mreg2type[Op_RegD] = Type::DOUBLE;
609 mreg2type[Op_RegL] = TypeLong::LONG;
610 mreg2type[Op_RegFlags] = TypeInt::CC;
611
612 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
613
614 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom);
615
616 #ifdef _LP64
617 if (UseCompressedOops) {
618 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
619 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
620 } else
621 #endif
936
937 // Meeting BOTTOM with anything?
938 if( _base == Bottom ) return BOTTOM;
939
940 // Current "this->_base" is one of: Bad, Multi, Control, Top,
941 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
942 switch (t->base()) { // Switch on original type
943
944 // Cut in half the number of cases I must handle. Only need cases for when
945 // the given enum "t->type" is less than or equal to the local enum "type".
946 case FloatCon:
947 case DoubleCon:
948 case Int:
949 case Long:
950 return t->xmeet(this);
951
952 case OopPtr:
953 return t->xmeet(this);
954
955 case InstPtr:
956 return t->xmeet(this);
957
958 case MetadataPtr:
959 case KlassPtr:
960 return t->xmeet(this);
961
962 case AryPtr:
963 return t->xmeet(this);
964
965 case NarrowOop:
966 return t->xmeet(this);
967
968 case NarrowKlass:
969 return t->xmeet(this);
970
971 case ValueType:
972 return t->xmeet(this);
973
974 case Bad: // Type check
975 default: // Bogus type not in lattice
1167 const TypeF *TypeF::ONE; // Floating point one
1168
1169 //------------------------------make-------------------------------------------
1170 // Create a float constant
1171 const TypeF *TypeF::make(float f) {
1172 return (TypeF*)(new TypeF(f))->hashcons();
1173 }
1174
1175 //------------------------------meet-------------------------------------------
1176 // Compute the MEET of two types. It returns a new Type object.
1177 const Type *TypeF::xmeet( const Type *t ) const {
1178 // Perform a fast test for common case; meeting the same types together.
1179 if( this == t ) return this; // Meeting same type-rep?
1180
1181 // Current "this->_base" is FloatCon
1182 switch (t->base()) { // Switch on original type
1183 case AnyPtr: // Mixing with oops happens when javac
1184 case RawPtr: // reuses local variables
1185 case OopPtr:
1186 case InstPtr:
1187 case AryPtr:
1188 case MetadataPtr:
1189 case KlassPtr:
1190 case NarrowOop:
1191 case NarrowKlass:
1192 case Int:
1193 case Long:
1194 case DoubleTop:
1195 case DoubleCon:
1196 case DoubleBot:
1197 case Bottom: // Ye Olde Default
1198 return Type::BOTTOM;
1199
1200 case FloatBot:
1201 return t;
1202
1203 default: // All else is a mistake
1204 typerr(t);
1205
1206 case FloatCon: // Float-constant vs Float-constant?
1274 const TypeD *TypeD::ZERO; // Floating point zero
1275 const TypeD *TypeD::ONE; // Floating point one
1276
1277 //------------------------------make-------------------------------------------
1278 const TypeD *TypeD::make(double d) {
1279 return (TypeD*)(new TypeD(d))->hashcons();
1280 }
1281
1282 //------------------------------meet-------------------------------------------
1283 // Compute the MEET of two types. It returns a new Type object.
1284 const Type *TypeD::xmeet( const Type *t ) const {
1285 // Perform a fast test for common case; meeting the same types together.
1286 if( this == t ) return this; // Meeting same type-rep?
1287
1288 // Current "this->_base" is DoubleCon
1289 switch (t->base()) { // Switch on original type
1290 case AnyPtr: // Mixing with oops happens when javac
1291 case RawPtr: // reuses local variables
1292 case OopPtr:
1293 case InstPtr:
1294 case AryPtr:
1295 case MetadataPtr:
1296 case KlassPtr:
1297 case NarrowOop:
1298 case NarrowKlass:
1299 case Int:
1300 case Long:
1301 case FloatTop:
1302 case FloatCon:
1303 case FloatBot:
1304 case Bottom: // Ye Olde Default
1305 return Type::BOTTOM;
1306
1307 case DoubleBot:
1308 return t;
1309
1310 default: // All else is a mistake
1311 typerr(t);
1312
1313 case DoubleCon: // Double-constant vs Double-constant?
1419
1420 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1421 w = normalize_int_widen(lo, hi, w);
1422 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1423 }
1424
1425 //------------------------------meet-------------------------------------------
1426 // Compute the MEET of two types. It returns a new Type representation object
1427 // with reference count equal to the number of Types pointing at it.
1428 // Caller should wrap a Types around it.
1429 const Type *TypeInt::xmeet( const Type *t ) const {
1430 // Perform a fast test for common case; meeting the same types together.
1431 if( this == t ) return this; // Meeting same type?
1432
1433 // Currently "this->_base" is a TypeInt
1434 switch (t->base()) { // Switch on original type
1435 case AnyPtr: // Mixing with oops happens when javac
1436 case RawPtr: // reuses local variables
1437 case OopPtr:
1438 case InstPtr:
1439 case AryPtr:
1440 case MetadataPtr:
1441 case KlassPtr:
1442 case NarrowOop:
1443 case NarrowKlass:
1444 case Long:
1445 case FloatTop:
1446 case FloatCon:
1447 case FloatBot:
1448 case DoubleTop:
1449 case DoubleCon:
1450 case DoubleBot:
1451 case Bottom: // Ye Olde Default
1452 return Type::BOTTOM;
1453 default: // All else is a mistake
1454 typerr(t);
1455 case Top: // No change
1456 return this;
1457 case Int: // Int vs Int?
1458 break;
1678 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1679 w = normalize_long_widen(lo, hi, w);
1680 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1681 }
1682
1683
1684 //------------------------------meet-------------------------------------------
1685 // Compute the MEET of two types. It returns a new Type representation object
1686 // with reference count equal to the number of Types pointing at it.
1687 // Caller should wrap a Types around it.
1688 const Type *TypeLong::xmeet( const Type *t ) const {
1689 // Perform a fast test for common case; meeting the same types together.
1690 if( this == t ) return this; // Meeting same type?
1691
1692 // Currently "this->_base" is a TypeLong
1693 switch (t->base()) { // Switch on original type
1694 case AnyPtr: // Mixing with oops happens when javac
1695 case RawPtr: // reuses local variables
1696 case OopPtr:
1697 case InstPtr:
1698 case AryPtr:
1699 case MetadataPtr:
1700 case KlassPtr:
1701 case NarrowOop:
1702 case NarrowKlass:
1703 case Int:
1704 case FloatTop:
1705 case FloatCon:
1706 case FloatBot:
1707 case DoubleTop:
1708 case DoubleCon:
1709 case DoubleBot:
1710 case Bottom: // Ye Olde Default
1711 return Type::BOTTOM;
1712 default: // All else is a mistake
1713 typerr(t);
1714 case Top: // No change
1715 return this;
1716 case Long: // Long vs Long?
1717 break;
1994 //field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(TypePtr::NOTNULL);
1995 field_array[TypeFunc::Parms] = get_const_type(return_type);
1996 }
1997 break;
1998 case T_VOID:
1999 break;
2000 default:
2001 ShouldNotReachHere();
2002 }
2003 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2004 }
2005
2006 // Make a TypeTuple from the domain of a method signature
2007 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2008 uint arg_cnt = sig->size();
2009
2010 int vt_extra = 0;
2011 if (vt_fields_as_args) {
2012 for (int i = 0; i < sig->count(); i++) {
2013 ciType* type = sig->type_at(i);
2014 if (type->basic_type() == T_VALUETYPE) {
2015 assert(type->is_valuetype(), "inconsistent type");
2016 ciValueKlass* vk = (ciValueKlass*)type;
2017 vt_extra += vk->value_arg_slots()-1;
2018 }
2019 }
2020 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2021 }
2022
2023 uint pos = TypeFunc::Parms;
2024 const Type **field_array;
2025 if (recv != NULL) {
2026 arg_cnt++;
2027 bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype();
2028 if (vt_fields_for_recv) {
2029 ciValueKlass* vk = (ciValueKlass*)recv;
2030 vt_extra += vk->value_arg_slots()-1;
2031 }
2032 field_array = fields(arg_cnt + vt_extra);
2033 // Use get_const_type here because it respects UseUniqueSubclasses:
2034 if (vt_fields_for_recv) {
2035 ciValueKlass* vk = (ciValueKlass*)recv;
2036 collect_value_fields(vk, field_array, pos);
2037 } else {
2038 if (recv->is_valuetype()) {
2039 // TODO For now, we just deoptimize if the value type receiver is null
2040 field_array[pos++] = get_const_type(recv);
2041 } else {
2042 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2043 }
2044 }
2045 } else {
2046 field_array = fields(arg_cnt + vt_extra);
2047 }
2056 field_array[pos++] = Type::HALF;
2057 break;
2058 case T_DOUBLE:
2059 field_array[pos++] = Type::DOUBLE;
2060 field_array[pos++] = Type::HALF;
2061 break;
2062 case T_OBJECT:
2063 case T_ARRAY:
2064 case T_FLOAT:
2065 case T_INT:
2066 field_array[pos++] = get_const_type(type);
2067 break;
2068 case T_BOOLEAN:
2069 case T_CHAR:
2070 case T_BYTE:
2071 case T_SHORT:
2072 field_array[pos++] = TypeInt::INT;
2073 break;
2074 case T_VALUETYPE: {
2075 assert(type->is_valuetype(), "inconsistent type");
2076 if (vt_fields_as_args) {
2077 ciValueKlass* vk = (ciValueKlass*)type;
2078 collect_value_fields(vk, field_array, pos);
2079 } else {
2080 // Value types arguments cannot be NULL
2081 // field_array[pos++] = get_const_type(type)->join_speculative(TypePtr::NOTNULL);
2082 // TODO they can be NULL in LWorld
2083 field_array[pos++] = get_const_type(type);
2084 }
2085 break;
2086 }
2087 default:
2088 ShouldNotReachHere();
2089 }
2090 i++;
2091 }
2092 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
2093
2094 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
2095 }
2096
2208 }
2209 return false;
2210 }
2211
2212 //=============================================================================
2213 // Convenience common pre-built types.
2214
2215 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2216 // Certain normalizations keep us sane when comparing types.
2217 // We do not want arrayOop variables to differ only by the wideness
2218 // of their index types. Pick minimum wideness, since that is the
2219 // forced wideness of small ranges anyway.
2220 if (size->_widen != Type::WidenMin)
2221 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2222 else
2223 return size;
2224 }
2225
2226 //------------------------------make-------------------------------------------
2227 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2228 if (elem->is_valuetypeptr()) {
2229 // Value type array elements cannot be NULL
2230 elem = elem->join_speculative(TypePtr::NOTNULL)->is_oopptr();
2231 }
2232 if (UseCompressedOops && elem->isa_oopptr()) {
2233 elem = elem->make_narrowoop();
2234 }
2235 size = normalize_array_size(size);
2236 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2237 }
2238
2239 //------------------------------meet-------------------------------------------
2240 // Compute the MEET of two types. It returns a new Type object.
2241 const Type *TypeAry::xmeet( const Type *t ) const {
2242 // Perform a fast test for common case; meeting the same types together.
2243 if( this == t ) return this; // Meeting same type-rep?
2244
2245 // Current "this->_base" is Ary
2246 switch (t->base()) { // switch on original type
2247
2248 case Bottom: // Ye Olde Default
2410 case DoubleCon:
2411 case DoubleBot:
2412 case NarrowKlass:
2413 case Bottom:
2414 return Type::BOTTOM;
2415
2416 case OopPtr:
2417 case MetadataPtr:
2418 case KlassPtr:
2419 case RawPtr:
2420 return TypePtr::BOTTOM;
2421
2422 case Top:
2423 return this;
2424
2425 case NarrowOop: {
2426 return t->make_ptr()->xmeet(this)->make_narrowoop();
2427 }
2428
2429 case AryPtr:
2430 case InstPtr: {
2431 return t->xmeet(this);
2432 }
2433
2434 case ValueType: {
2435 // All value types inherit from Object
2436 return TypeInstPtr::NOTNULL;
2437 }
2438
2439 default: // All else is a mistake
2440 typerr(t);
2441
2442 }
2443 return this;
2444 }
2445
2446 //------------------------------xdual------------------------------------------
2447 const Type* TypeValueType::xdual() const {
2448 return this;
2449 }
2450
2681 case FloatBot:
2682 case DoubleTop:
2683 case DoubleCon:
2684 case DoubleBot:
2685 case NarrowOop:
2686 case NarrowKlass:
2687 case Bottom: // Ye Olde Default
2688 return Type::BOTTOM;
2689 case Top:
2690 return this;
2691
2692 case AnyPtr: { // Meeting to AnyPtrs
2693 const TypePtr *tp = t->is_ptr();
2694 const TypePtr* speculative = xmeet_speculative(tp);
2695 int depth = meet_inline_depth(tp->inline_depth());
2696 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2697 }
2698 case RawPtr: // For these, flip the call around to cut down
2699 case OopPtr:
2700 case InstPtr: // on the cases I have to handle.
2701 case AryPtr:
2702 case MetadataPtr:
2703 case KlassPtr:
2704 return t->xmeet(this); // Call in reverse direction
2705 default: // All else is a mistake
2706 typerr(t);
2707
2708 }
2709 return this;
2710 }
2711
2712 //------------------------------meet_offset------------------------------------
2713 Type::Offset TypePtr::meet_offset(int offset) const {
2714 return _offset.meet(Offset(offset));
2715 }
2716
2717 //------------------------------dual_offset------------------------------------
2718 Type::Offset TypePtr::dual_offset() const {
2719 return _offset.dual();
2720 }
3092 switch( t->base() ) { // switch on original type
3093 case Bottom: // Ye Olde Default
3094 return t;
3095 case Top:
3096 return this;
3097 case AnyPtr: // Meeting to AnyPtrs
3098 break;
3099 case RawPtr: { // might be top, bot, any/not or constant
3100 enum PTR tptr = t->is_ptr()->ptr();
3101 enum PTR ptr = meet_ptr( tptr );
3102 if( ptr == Constant ) { // Cannot be equal constants, so...
3103 if( tptr == Constant && _ptr != Constant) return t;
3104 if( _ptr == Constant && tptr != Constant) return this;
3105 ptr = NotNull; // Fall down in lattice
3106 }
3107 return make( ptr );
3108 }
3109
3110 case OopPtr:
3111 case InstPtr:
3112 case AryPtr:
3113 case MetadataPtr:
3114 case KlassPtr:
3115 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3116 default: // All else is a mistake
3117 typerr(t);
3118 }
3119
3120 // Found an AnyPtr type vs self-RawPtr type
3121 const TypePtr *tp = t->is_ptr();
3122 switch (tp->ptr()) {
3123 case TypePtr::TopPTR: return this;
3124 case TypePtr::BotPTR: return t;
3125 case TypePtr::Null:
3126 if( _ptr == TypePtr::TopPTR ) return t;
3127 return TypeRawPtr::BOTTOM;
3128 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3129 case TypePtr::AnyNull:
3130 if( _ptr == TypePtr::Constant) return this;
3131 return make( meet_ptr(TypePtr::AnyNull) );
3213 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3214 if (klass()->is_obj_array_klass()) {
3215 _is_ptr_to_narrowoop = true;
3216 } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3217 // Check if the field of the value type array element contains oops
3218 ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3219 int foffset = field_offset.get() + vk->first_field_offset();
3220 ciField* field = vk->get_field_by_offset(foffset, false);
3221 assert(field != NULL, "missing field");
3222 BasicType bt = field->layout_type();
3223 assert(bt != T_VALUETYPEPTR, "unexpected type");
3224 _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE);
3225 }
3226 } else if (klass()->is_instance_klass()) {
3227 if (this->isa_klassptr()) {
3228 // Perm objects don't use compressed references
3229 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3230 // unsafe access
3231 _is_ptr_to_narrowoop = UseCompressedOops;
3232 } else { // exclude unsafe ops
3233 assert(this->isa_instptr(), "must be an instance ptr.");
3234 if (klass() == ciEnv::current()->Class_klass() &&
3235 (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3236 this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3237 // Special hidden fields from the Class.
3238 assert(this->isa_instptr(), "must be an instance ptr.");
3239 _is_ptr_to_narrowoop = false;
3240 } else if (klass() == ciEnv::current()->Class_klass() &&
3241 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3242 // Static fields
3243 assert(o != NULL, "must be constant");
3244 ciInstanceKlass* ik = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3245 BasicType basic_elem_type;
3246 if (ik->is_valuetype() && this->offset() == ik->as_value_klass()->default_value_offset()) {
3247 // Special hidden field that contains the oop of the default value type
3248 basic_elem_type = T_VALUETYPE;
3249 } else {
3250 ciField* field = ik->get_field_by_offset(this->offset(), true);
3251 assert(field != NULL, "missing field");
3252 basic_elem_type = field->layout_type();
3253 }
3371 case AnyNull: {
3372 int instance_id = meet_instance_id(InstanceTop);
3373 return make(ptr, offset, instance_id, speculative, depth);
3374 }
3375 case BotPTR:
3376 case NotNull:
3377 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3378 default: typerr(t);
3379 }
3380 }
3381
3382 case OopPtr: { // Meeting to other OopPtrs
3383 const TypeOopPtr *tp = t->is_oopptr();
3384 int instance_id = meet_instance_id(tp->instance_id());
3385 const TypePtr* speculative = xmeet_speculative(tp);
3386 int depth = meet_inline_depth(tp->inline_depth());
3387 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3388 }
3389
3390 case InstPtr: // For these, flip the call around to cut down
3391 case AryPtr:
3392 return t->xmeet(this); // Call in reverse direction
3393
3394 } // End of switch
3395 return this; // Return the double constant
3396 }
3397
3398
3399 //------------------------------xdual------------------------------------------
3400 // Dual of a pure heap pointer. No relevant klass or oop information.
3401 const Type *TypeOopPtr::xdual() const {
3402 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3403 assert(const_oop() == NULL, "no constants here");
3404 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3405 }
3406
3407 //--------------------------make_from_klass_common-----------------------------
3408 // Computes the element-type given a klass.
3409 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3410 if (klass->is_instance_klass() || klass->is_valuetype()) {
3411 Compile* C = Compile::current();
3412 Dependencies* deps = C->dependencies();
3413 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3414 // Element is an instance
3415 bool klass_is_exact = false;
3416 if (klass->is_loaded()) {
3417 // Try to set klass_is_exact.
3418 ciInstanceKlass* ik = klass->as_instance_klass();
3419 klass_is_exact = ik->is_final();
3420 if (!klass_is_exact && klass_change
3421 && deps != NULL && UseUniqueSubclasses) {
3422 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3423 if (sub != NULL) {
3424 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3425 klass = ik = sub;
3426 klass_is_exact = sub->is_final();
3427 }
3428 }
3429 if (!klass_is_exact && try_for_exact
3430 && deps != NULL && UseExactTypes) {
3453 // We used to pass NotNull in here, asserting that the array pointer
3454 // is not-null. That was not true in general.
3455 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3456 return arr;
3457 } else if (klass->is_value_array_klass()) {
3458 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3459 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3460 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3461 return arr;
3462 } else {
3463 ShouldNotReachHere();
3464 return NULL;
3465 }
3466 }
3467
3468 //------------------------------make_from_constant-----------------------------
3469 // Make a java pointer from an oop constant
3470 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3471 assert(!o->is_null_object(), "null object not yet handled here.");
3472 ciKlass* klass = o->klass();
3473 if (klass->is_instance_klass() || klass->is_valuetype()) {
3474 // Element is an instance or value type
3475 if (require_constant) {
3476 if (!o->can_be_constant()) return NULL;
3477 } else if (!o->should_be_constant()) {
3478 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3479 }
3480 return TypeInstPtr::make(o);
3481 } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) {
3482 // Element is an object array. Recursively call ourself.
3483 const TypeOopPtr *etype =
3484 TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3485 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3486 // We used to pass NotNull in here, asserting that the sub-arrays
3487 // are all not-null. This is not true in generally, as code can
3488 // slam NULLs down in the subarrays.
3489 if (require_constant) {
3490 if (!o->can_be_constant()) return NULL;
3491 } else if (!o->should_be_constant()) {
3492 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3493 }
3494 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4151 else if (above_centerline(tinst ->_ptr))
4152 o = this_oop;
4153 else
4154 ptr = NotNull;
4155 }
4156 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4157 } // Else classes are not equal
4158
4159 // Since klasses are different, we require a LCA in the Java
4160 // class hierarchy - which means we have to fall to at least NotNull.
4161 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4162 ptr = NotNull;
4163
4164 instance_id = InstanceBot;
4165
4166 // Now we find the LCA of Java classes
4167 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4168 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4169 } // End of case InstPtr
4170
4171 case ValueType: {
4172 // All value types inherit from Object
4173 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
4174 }
4175
4176 } // End of switch
4177 return this; // Return the double constant
4178 }
4179
4180
4181 //------------------------java_mirror_type--------------------------------------
4182 ciType* TypeInstPtr::java_mirror_type() const {
4183 // must be a singleton type
4184 if( const_oop() == NULL ) return NULL;
4185
4186 // must be of type java.lang.Class
4187 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
4188
4189 return const_oop()->as_instance()->java_mirror_type();
4190 }
4655 // that is, my array type is a subtype of 'tp' klass
4656 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4657 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4658 }
4659 }
4660 // The other case cannot happen, since t cannot be a subtype of an array.
4661 // The meet falls down to Object class below centerline.
4662 if( ptr == Constant )
4663 ptr = NotNull;
4664 instance_id = InstanceBot;
4665 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4666 default: typerr(t);
4667 }
4668 }
4669
4670 case ValueType: {
4671 // All value types inherit from Object
4672 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
4673 }
4674
4675 }
4676 return this; // Lint noise
4677 }
4678
4679 //------------------------------xdual------------------------------------------
4680 // Dual: compute field-by-field dual
4681 const Type *TypeAryPtr::xdual() const {
4682 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
4683 }
4684
4685 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
4686 return _field_offset.meet(offset);
4687 }
4688
4689 //------------------------------dual_offset------------------------------------
4690 Type::Offset TypeAryPtr::dual_field_offset() const {
4691 return _field_offset.dual();
4692 }
4693
4694 //----------------------interface_vs_oop---------------------------------------
4815 }
4816 }
4817 }
4818 }
4819 return add_offset(offset - adj);
4820 }
4821
4822 // Return offset incremented by field_offset for flattened value type arrays
4823 const int TypeAryPtr::flattened_offset() const {
4824 int offset = _offset.get();
4825 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
4826 _field_offset != Offset::bottom && _field_offset != Offset::top) {
4827 offset += _field_offset.get();
4828 }
4829 return offset;
4830 }
4831
4832 //=============================================================================
4833
4834
4835 //------------------------------hash-------------------------------------------
4836 // Type-specific hashing function.
4837 int TypeNarrowPtr::hash(void) const {
4838 return _ptrtype->hash() + 7;
4839 }
4840
4841 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
4842 return _ptrtype->singleton();
4843 }
4844
4845 bool TypeNarrowPtr::empty(void) const {
4846 return _ptrtype->empty();
4847 }
4848
4849 intptr_t TypeNarrowPtr::get_con() const {
4850 return _ptrtype->get_con();
4851 }
4852
4853 bool TypeNarrowPtr::eq( const Type *t ) const {
4854 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4898 return make_hash_same_narrowptr(result->is_ptr());
4899 }
4900 return result;
4901 }
4902
4903 // Current "this->_base" is NarrowKlass or NarrowOop
4904 switch (t->base()) { // switch on original type
4905
4906 case Int: // Mixing ints & oops happens when javac
4907 case Long: // reuses local variables
4908 case FloatTop:
4909 case FloatCon:
4910 case FloatBot:
4911 case DoubleTop:
4912 case DoubleCon:
4913 case DoubleBot:
4914 case AnyPtr:
4915 case RawPtr:
4916 case OopPtr:
4917 case InstPtr:
4918 case AryPtr:
4919 case MetadataPtr:
4920 case KlassPtr:
4921 case NarrowOop:
4922 case NarrowKlass:
4923 case Bottom: // Ye Olde Default
4924 return Type::BOTTOM;
4925 case Top:
4926 return this;
4927
4928 case ValueType:
4929 return t->xmeet(this);
4930
4931 default: // All else is a mistake
4932 typerr(t);
4933
4934 } // End of switch
4935
4936 return this;
4937 }
5083 PTR ptr = meet_ptr(tp->ptr());
5084 switch (tp->ptr()) {
5085 case Null:
5086 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5087 // else fall through:
5088 case TopPTR:
5089 case AnyNull: {
5090 return make(ptr, _metadata, offset);
5091 }
5092 case BotPTR:
5093 case NotNull:
5094 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5095 default: typerr(t);
5096 }
5097 }
5098
5099 case RawPtr:
5100 case KlassPtr:
5101 case OopPtr:
5102 case InstPtr:
5103 case AryPtr:
5104 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5105
5106 case MetadataPtr: {
5107 const TypeMetadataPtr *tp = t->is_metadataptr();
5108 Offset offset = meet_offset(tp->offset());
5109 PTR tptr = tp->ptr();
5110 PTR ptr = meet_ptr(tptr);
5111 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5112 if (tptr == TopPTR || _ptr == TopPTR ||
5113 metadata()->equals(tp->metadata())) {
5114 return make(ptr, md, offset);
5115 }
5116 // metadata is different
5117 if( ptr == Constant ) { // Cannot be equal constants, so...
5118 if( tptr == Constant && _ptr != Constant) return t;
5119 if( _ptr == Constant && tptr != Constant) return this;
5120 ptr = NotNull; // Fall down in lattice
5121 }
5122 return make(ptr, NULL, offset);
5235 !ftkp->klass_is_exact() && // Keep exact interface klass
5236 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5237 return ktkp->cast_to_ptr_type(ftkp->ptr());
5238 }
5239
5240 return ft;
5241 }
5242
5243 //----------------------compute_klass------------------------------------------
5244 // Compute the defining klass for this class
5245 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5246 // Compute _klass based on element type.
5247 ciKlass* k_ary = NULL;
5248 const TypeAryPtr *tary;
5249 const Type* el = elem();
5250 if (el->isa_narrowoop()) {
5251 el = el->make_ptr();
5252 }
5253
5254 // Get element klass
5255 if (el->isa_instptr()) {
5256 // Compute object array klass from element klass
5257 k_ary = ciArrayKlass::make(el->is_oopptr()->klass());
5258 } else if (el->isa_valuetype()) {
5259 k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass());
5260 } else if ((tary = el->isa_aryptr()) != NULL) {
5261 // Compute array klass from element klass
5262 ciKlass* k_elem = tary->klass();
5263 // If element type is something like bottom[], k_elem will be null.
5264 if (k_elem != NULL)
5265 k_ary = ciObjArrayKlass::make(k_elem);
5266 } else if ((el->base() == Type::Top) ||
5267 (el->base() == Type::Bottom)) {
5268 // element type of Bottom occurs from meet of basic type
5269 // and object; Top occurs when doing join on Bottom.
5270 // Leave k_ary at NULL.
5271 } else {
5272 // Cannot compute array klass directly from basic type,
5273 // since subtypes of TypeInt all have basic type T_INT.
5274 #ifdef ASSERT
5275 if (verify && el->isa_int()) {
5400 PTR ptr = meet_ptr(tp->ptr());
5401 switch (tp->ptr()) {
5402 case TopPTR:
5403 return this;
5404 case Null:
5405 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5406 case AnyNull:
5407 return make( ptr, klass(), offset );
5408 case BotPTR:
5409 case NotNull:
5410 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5411 default: typerr(t);
5412 }
5413 }
5414
5415 case RawPtr:
5416 case MetadataPtr:
5417 case OopPtr:
5418 case AryPtr: // Meet with AryPtr
5419 case InstPtr: // Meet with InstPtr
5420 return TypePtr::BOTTOM;
5421
5422 //
5423 // A-top }
5424 // / | \ } Tops
5425 // B-top A-any C-top }
5426 // | / | \ | } Any-nulls
5427 // B-any | C-any }
5428 // | | |
5429 // B-con A-con C-con } constants; not comparable across classes
5430 // | | |
5431 // B-not | C-not }
5432 // | \ | / | } not-nulls
5433 // B-bot A-not C-bot }
5434 // \ | / } Bottoms
5435 // A-bot }
5436 //
5437
5438 case KlassPtr: { // Meet two KlassPtr types
5439 const TypeKlassPtr *tkls = t->is_klassptr();
|