2202 if (_fields[i]->empty()) return true;
2203 }
2204 return false;
2205 }
2206
2207 //=============================================================================
2208 // Convenience common pre-built types.
2209
2210 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2211 // Certain normalizations keep us sane when comparing types.
2212 // We do not want arrayOop variables to differ only by the wideness
2213 // of their index types. Pick minimum wideness, since that is the
2214 // forced wideness of small ranges anyway.
2215 if (size->_widen != Type::WidenMin)
2216 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2217 else
2218 return size;
2219 }
2220
2221 //------------------------------make-------------------------------------------
2222 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2223 if (UseCompressedOops && elem->isa_oopptr()) {
2224 elem = elem->make_narrowoop();
2225 }
2226 size = normalize_array_size(size);
2227 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2228 }
2229
2230 //------------------------------meet-------------------------------------------
2231 // Compute the MEET of two types. It returns a new Type object.
2232 const Type *TypeAry::xmeet( const Type *t ) const {
2233 // Perform a fast test for common case; meeting the same types together.
2234 if( this == t ) return this; // Meeting same type-rep?
2235
2236 // Current "this->_base" is Ary
2237 switch (t->base()) { // switch on original type
2238
2239 case Bottom: // Ye Olde Default
2240 return t;
2241
2242 default: // All else is a mistake
2243 typerr(t);
2244
2245 case Array: { // Meeting 2 arrays?
2246 const TypeAry *a = t->is_ary();
2247 return TypeAry::make(_elem->meet_speculative(a->_elem),
2248 _size->xmeet(a->_size)->is_int(),
2249 _stable && a->_stable);
2250 }
2251 case Top:
2252 break;
2253 }
2254 return this; // Return the double constant
2255 }
2256
2257 //------------------------------xdual------------------------------------------
2258 // Dual: compute field-by-field dual
2259 const Type *TypeAry::xdual() const {
2260 const TypeInt* size_dual = _size->dual()->is_int();
2261 size_dual = normalize_array_size(size_dual);
2262 return new TypeAry(_elem->dual(), size_dual, !_stable);
2263 }
2264
2265 //------------------------------eq---------------------------------------------
2266 // Structural equality check for Type representations
2267 bool TypeAry::eq( const Type *t ) const {
2268 const TypeAry *a = (const TypeAry*)t;
2269 return _elem == a->_elem &&
2270 _stable == a->_stable &&
2271 _size == a->_size;
2272 }
2273
2274 //------------------------------hash-------------------------------------------
2275 // Type-specific hashing function.
2276 int TypeAry::hash(void) const {
2277 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2278 }
2279
2280 /**
2281 * Return same type without a speculative part in the element
2282 */
2283 const Type* TypeAry::remove_speculative() const {
2284 return make(_elem->remove_speculative(), _size, _stable);
2285 }
2286
2287 /**
2288 * Return same type with cleaned up speculative part of element
2289 */
2290 const Type* TypeAry::cleanup_speculative() const {
2291 return make(_elem->cleanup_speculative(), _size, _stable);
2292 }
2293
2294 /**
2295 * Return same type but with a different inline depth (used for speculation)
2296 *
2297 * @param depth depth to meet with
2298 */
2299 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2300 if (!UseInlineDepthForSpeculativeTypes) {
2301 return this;
2302 }
2303 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2304 }
2305
2306 //----------------------interface_vs_oop---------------------------------------
2307 #ifdef ASSERT
2308 bool TypeAry::interface_vs_oop(const Type *t) const {
2309 const TypeAry* t_ary = t->is_ary();
2310 if (t_ary) {
2311 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2312 const TypePtr* t_ptr = t_ary->_elem->make_ptr();
2313 if(this_ptr != NULL && t_ptr != NULL) {
2314 return this_ptr->interface_vs_oop(t_ptr);
2315 }
2316 }
2317 return false;
2318 }
2319 #endif
2320
2321 //------------------------------dump2------------------------------------------
2322 #ifndef PRODUCT
2323 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2324 if (_stable) st->print("stable:");
2325 _elem->dump2(d, depth, st);
2326 st->print("[");
2327 _size->dump2(d, depth, st);
2328 st->print("]");
2329 }
2330 #endif
2331
2332 //------------------------------singleton--------------------------------------
2333 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2334 // constants (Ldi nodes). Singletons are integer, float or double constants
2335 // or a single symbol.
2336 bool TypeAry::singleton(void) const {
2337 return false; // Never a singleton
2338 }
2339
2340 bool TypeAry::empty(void) const {
2341 return _elem->empty() || _size->empty();
2342 }
2343
2344 //--------------------------ary_must_be_exact----------------------------------
2348 // if the element type is either a primitive or a final instance class.
2349 // In such cases, an array built on this ary must have no subclasses.
2350 if (_elem == BOTTOM) return false; // general array not exact
2351 if (_elem == TOP ) return false; // inverted general array not exact
2352 const TypeOopPtr* toop = NULL;
2353 if (UseCompressedOops && _elem->isa_narrowoop()) {
2354 toop = _elem->make_ptr()->isa_oopptr();
2355 } else {
2356 toop = _elem->isa_oopptr();
2357 }
2358 if (!toop) return true; // a primitive type, like int
2359 ciKlass* tklass = toop->klass();
2360 if (tklass == NULL) return false; // unloaded class
2361 if (!tklass->is_loaded()) return false; // unloaded class
2362 const TypeInstPtr* tinst;
2363 if (_elem->isa_narrowoop())
2364 tinst = _elem->make_ptr()->isa_instptr();
2365 else
2366 tinst = _elem->isa_instptr();
2367 if (tinst) {
2368 // [V? has a subtype: [V. So eventhough V is final, [V? is not exact.
2369 if (tklass->as_instance_klass()->is_final()) {
2370 if (tinst->is_valuetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2371 return false;
2372 }
2373 return true;
2374 }
2375 return false;
2376 }
2377 const TypeAryPtr* tap;
2378 if (_elem->isa_narrowoop())
2379 tap = _elem->make_ptr()->isa_aryptr();
2380 else
2381 tap = _elem->isa_aryptr();
2382 if (tap)
2383 return tap->ary()->ary_must_be_exact();
2384 return false;
2385 }
2386
2387 //==============================TypeValueType=======================================
2388
3447 if (sub != NULL) {
3448 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3449 klass = ik = sub;
3450 klass_is_exact = sub->is_final();
3451 }
3452 }
3453 if (!klass_is_exact && try_for_exact
3454 && deps != NULL && UseExactTypes) {
3455 if (!ik->is_interface() && !ik->has_subklass()) {
3456 // Add a dependence; if concrete subclass added we need to recompile
3457 deps->assert_leaf_type(ik);
3458 klass_is_exact = true;
3459 }
3460 }
3461 }
3462 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3463 } else if (klass->is_obj_array_klass()) {
3464 // Element is an object or value array. Recursively call ourself.
3465 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3466 bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3467 if (null_free && etype->is_valuetypeptr()) {
3468 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3469 }
3470 // [V? has a subtype: [V. So eventhough V is final, [V? is not exact.
3471 bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3472 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3473 // We used to pass NotNull in here, asserting that the sub-arrays
3474 // are all not-null. This is not true in generally, as code can
3475 // slam NULLs down in the subarrays.
3476 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3477 return arr;
3478 } else if (klass->is_type_array_klass()) {
3479 // Element is an typeArray
3480 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3481 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3482 // We used to pass NotNull in here, asserting that the array pointer
3483 // is not-null. That was not true in general.
3484 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3485 return arr;
3486 } else if (klass->is_value_array_klass()) {
3487 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3488 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3489 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3490 return arr;
3491 } else {
3492 ShouldNotReachHere();
3493 return NULL;
3494 }
3495 }
3496
3497 //------------------------------make_from_constant-----------------------------
3498 // Make a java pointer from an oop constant
3499 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3500 assert(!o->is_null_object(), "null object not yet handled here.");
3501
3502 const bool make_constant = require_constant || o->should_be_constant();
3503
3504 ciKlass* klass = o->klass();
3505 if (klass->is_instance_klass() || klass->is_valuetype()) {
3506 // Element is an instance or value type
3507 if (make_constant) {
3508 return TypeInstPtr::make(o);
3509 } else {
3510 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3511 }
3512 } else if (klass->is_obj_array_klass()) {
3513 // Element is an object array. Recursively call ourself.
3514 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3515 bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3516 if (null_free && etype->is_valuetypeptr()) {
3517 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3518 }
3519 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3520 // We used to pass NotNull in here, asserting that the sub-arrays
3521 // are all not-null. This is not true in generally, as code can
3522 // slam NULLs down in the subarrays.
3523 if (make_constant) {
3524 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3525 } else {
3526 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3527 }
3528 } else if (klass->is_type_array_klass()) {
3529 // Element is an typeArray
3530 const Type* etype =
3531 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3532 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3533 // We used to pass NotNull in here, asserting that the array pointer
3534 // is not-null. That was not true in general.
3535 if (make_constant) {
3536 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3537 } else {
3538 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3539 }
3540 } else if (klass->is_value_array_klass()) {
3541 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3542 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::make(o->as_array()->length()));
3543 // We used to pass NotNull in here, asserting that the sub-arrays
3544 // are all not-null. This is not true in generally, as code can
3545 // slam NULLs down in the subarrays.
3546 if (make_constant) {
3547 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3548 } else {
3549 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3550 }
3551 }
3552
4459 if (hi > max_hi) {
4460 hi = max_hi;
4461 if (size->is_con()) {
4462 lo = hi;
4463 }
4464 chg = true;
4465 }
4466 // Negative length arrays will produce weird intermediate dead fast-path code
4467 if (lo > hi)
4468 return TypeInt::ZERO;
4469 if (!chg)
4470 return size;
4471 return TypeInt::make(lo, hi, Type::WidenMin);
4472 }
4473
4474 //-------------------------------cast_to_size----------------------------------
4475 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4476 assert(new_size != NULL, "");
4477 new_size = narrow_size_type(new_size);
4478 if (new_size == size()) return this;
4479 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4480 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4481 }
4482
4483 //------------------------------cast_to_stable---------------------------------
4484 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4485 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4486 return this;
4487
4488 const Type* elem = this->elem();
4489 const TypePtr* elem_ptr = elem->make_ptr();
4490
4491 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4492 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4493 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4494 }
4495
4496 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4497
4498 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4499 }
4500
4501 //-----------------------------stable_dimension--------------------------------
4502 int TypeAryPtr::stable_dimension() const {
4503 if (!is_stable()) return 0;
4504 int dim = 1;
4505 const TypePtr* elem_ptr = elem()->make_ptr();
4506 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4507 dim += elem_ptr->is_aryptr()->stable_dimension();
4508 return dim;
4509 }
4510
4511 //----------------------cast_to_autobox_cache-----------------------------------
4512 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4513 if (is_autobox_cache() == cache) return this;
4514 const TypeOopPtr* etype = elem()->make_oopptr();
4515 if (etype == NULL) return this;
4516 // The pointers in the autobox arrays are always non-null.
4517 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4518 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4519 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4520 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4521 }
4522
4523 //------------------------------eq---------------------------------------------
4524 // Structural equality check for Type representations
4525 bool TypeAryPtr::eq( const Type *t ) const {
4526 const TypeAryPtr *p = t->is_aryptr();
4527 return
4528 _ary == p->_ary && // Check array
4529 TypeOopPtr::eq(p) &&// Check sub-parts
4530 _field_offset == p->_field_offset;
4531 }
4532
4533 //------------------------------hash-------------------------------------------
4534 // Type-specific hashing function.
4535 int TypeAryPtr::hash(void) const {
4536 return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4537 }
4538
4539 //------------------------------meet-------------------------------------------
4619 const TypeAryPtr *tap = t->is_aryptr();
4620 Offset off = meet_offset(tap->offset());
4621 Offset field_off = meet_field_offset(tap->field_offset());
4622 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4623 PTR ptr = meet_ptr(tap->ptr());
4624 int instance_id = meet_instance_id(tap->instance_id());
4625 const TypePtr* speculative = xmeet_speculative(tap);
4626 int depth = meet_inline_depth(tap->inline_depth());
4627 ciKlass* lazy_klass = NULL;
4628 if (tary->_elem->isa_int()) {
4629 // Integral array element types have irrelevant lattice relations.
4630 // It is the klass that determines array layout, not the element type.
4631 if (_klass == NULL)
4632 lazy_klass = tap->_klass;
4633 else if (tap->_klass == NULL || tap->_klass == _klass) {
4634 lazy_klass = _klass;
4635 } else {
4636 // Something like byte[int+] meets char[int+].
4637 // This must fall to bottom, not (int[-128..65535])[int+].
4638 instance_id = InstanceBot;
4639 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4640 }
4641 } else if (klass() != NULL && tap->klass() != NULL &&
4642 klass()->as_array_klass()->storage_properties().value() != tap->klass()->as_array_klass()->storage_properties().value()) {
4643 // Meeting value type arrays with conflicting storage properties
4644 if (tary->_elem->isa_valuetype()) {
4645 // Result is flattened
4646 off = Offset(elem()->isa_valuetype() ? offset() : tap->offset());
4647 field_off = elem()->isa_valuetype() ? field_offset() : tap->field_offset();
4648 } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4649 // Result is non-flattened
4650 off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4651 field_off = Offset::bottom;
4652 }
4653 } else // Non integral arrays.
4654 // Must fall to bottom if exact klasses in upper lattice
4655 // are not equal or super klass is exact.
4656 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4657 // meet with top[] and bottom[] are processed further down:
4658 tap->_klass != NULL && this->_klass != NULL &&
4659 // both are exact and not equal:
4660 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4661 // 'tap' is exact and super or unrelated:
4662 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4663 // 'this' is exact and super or unrelated:
4664 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4665 if (above_centerline(ptr)) {
4666 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4667 }
4668 return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4669 }
4670
4671 bool xk = false;
4672 switch (tap->ptr()) {
4673 case AnyNull:
4674 case TopPTR:
4675 // Compute new klass on demand, do not use tap->_klass
4676 if (below_centerline(this->_ptr)) {
4677 xk = this->_klass_is_exact;
4678 } else {
4679 xk = (tap->_klass_is_exact || this->_klass_is_exact);
4680 }
4681 return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4682 case Constant: {
4683 ciObject* o = const_oop();
4684 if( _ptr == Constant ) {
4685 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4686 xk = (klass() == tap->klass());
4848 dump_speculative(st);
4849 }
4850 #endif
4851
4852 bool TypeAryPtr::empty(void) const {
4853 if (_ary->empty()) return true;
4854 return TypeOopPtr::empty();
4855 }
4856
4857 //------------------------------add_offset-------------------------------------
4858 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4859 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _field_offset, _instance_id, add_offset_speculative(offset), _inline_depth, _is_autobox_cache);
4860 }
4861
4862 const Type *TypeAryPtr::remove_speculative() const {
4863 if (_speculative == NULL) {
4864 return this;
4865 }
4866 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4867 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);
4868 }
4869
4870 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4871 if (!UseInlineDepthForSpeculativeTypes) {
4872 return this;
4873 }
4874 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4875 }
4876
4877 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4878 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);
4879 }
4880
4881 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
4882 int adj = 0;
4883 if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
4884 const Type* elemtype = elem();
4885 if (elemtype->isa_valuetype()) {
4886 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
4887 adj = _offset.get();
|
2202 if (_fields[i]->empty()) return true;
2203 }
2204 return false;
2205 }
2206
2207 //=============================================================================
2208 // Convenience common pre-built types.
2209
2210 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2211 // Certain normalizations keep us sane when comparing types.
2212 // We do not want arrayOop variables to differ only by the wideness
2213 // of their index types. Pick minimum wideness, since that is the
2214 // forced wideness of small ranges anyway.
2215 if (size->_widen != Type::WidenMin)
2216 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2217 else
2218 return size;
2219 }
2220
2221 //------------------------------make-------------------------------------------
2222 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2223 bool not_flat, bool not_null_free) {
2224 if (UseCompressedOops && elem->isa_oopptr()) {
2225 elem = elem->make_narrowoop();
2226 }
2227 size = normalize_array_size(size);
2228 return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2229 }
2230
2231 //------------------------------meet-------------------------------------------
2232 // Compute the MEET of two types. It returns a new Type object.
2233 const Type *TypeAry::xmeet( const Type *t ) const {
2234 // Perform a fast test for common case; meeting the same types together.
2235 if( this == t ) return this; // Meeting same type-rep?
2236
2237 // Current "this->_base" is Ary
2238 switch (t->base()) { // switch on original type
2239
2240 case Bottom: // Ye Olde Default
2241 return t;
2242
2243 default: // All else is a mistake
2244 typerr(t);
2245
2246 case Array: { // Meeting 2 arrays?
2247 const TypeAry *a = t->is_ary();
2248 return TypeAry::make(_elem->meet_speculative(a->_elem),
2249 _size->xmeet(a->_size)->is_int(),
2250 _stable && a->_stable,
2251 _not_flat && a->_not_flat,
2252 _not_null_free && a->_not_null_free);
2253 }
2254 case Top:
2255 break;
2256 }
2257 return this; // Return the double constant
2258 }
2259
2260 //------------------------------xdual------------------------------------------
2261 // Dual: compute field-by-field dual
2262 const Type *TypeAry::xdual() const {
2263 const TypeInt* size_dual = _size->dual()->is_int();
2264 size_dual = normalize_array_size(size_dual);
2265 return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2266 }
2267
2268 //------------------------------eq---------------------------------------------
2269 // Structural equality check for Type representations
2270 bool TypeAry::eq( const Type *t ) const {
2271 const TypeAry *a = (const TypeAry*)t;
2272 return _elem == a->_elem &&
2273 _stable == a->_stable &&
2274 _size == a->_size &&
2275 _not_flat == a->_not_flat &&
2276 _not_null_free == a->_not_null_free;
2277
2278 }
2279
2280 //------------------------------hash-------------------------------------------
2281 // Type-specific hashing function.
2282 int TypeAry::hash(void) const {
2283 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2284 }
2285
2286 /**
2287 * Return same type without a speculative part in the element
2288 */
2289 const Type* TypeAry::remove_speculative() const {
2290 return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2291 }
2292
2293 /**
2294 * Return same type with cleaned up speculative part of element
2295 */
2296 const Type* TypeAry::cleanup_speculative() const {
2297 return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2298 }
2299
2300 /**
2301 * Return same type but with a different inline depth (used for speculation)
2302 *
2303 * @param depth depth to meet with
2304 */
2305 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2306 if (!UseInlineDepthForSpeculativeTypes) {
2307 return this;
2308 }
2309 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2310 }
2311
2312 //----------------------interface_vs_oop---------------------------------------
2313 #ifdef ASSERT
2314 bool TypeAry::interface_vs_oop(const Type *t) const {
2315 const TypeAry* t_ary = t->is_ary();
2316 if (t_ary) {
2317 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2318 const TypePtr* t_ptr = t_ary->_elem->make_ptr();
2319 if(this_ptr != NULL && t_ptr != NULL) {
2320 return this_ptr->interface_vs_oop(t_ptr);
2321 }
2322 }
2323 return false;
2324 }
2325 #endif
2326
2327 //------------------------------dump2------------------------------------------
2328 #ifndef PRODUCT
2329 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2330 if (_stable) st->print("stable:");
2331 if (Verbose) {
2332 if (_not_flat) st->print("not flat:");
2333 if (_not_null_free) st->print("not null free:");
2334 }
2335 _elem->dump2(d, depth, st);
2336 st->print("[");
2337 _size->dump2(d, depth, st);
2338 st->print("]");
2339 }
2340 #endif
2341
2342 //------------------------------singleton--------------------------------------
2343 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2344 // constants (Ldi nodes). Singletons are integer, float or double constants
2345 // or a single symbol.
2346 bool TypeAry::singleton(void) const {
2347 return false; // Never a singleton
2348 }
2349
2350 bool TypeAry::empty(void) const {
2351 return _elem->empty() || _size->empty();
2352 }
2353
2354 //--------------------------ary_must_be_exact----------------------------------
2358 // if the element type is either a primitive or a final instance class.
2359 // In such cases, an array built on this ary must have no subclasses.
2360 if (_elem == BOTTOM) return false; // general array not exact
2361 if (_elem == TOP ) return false; // inverted general array not exact
2362 const TypeOopPtr* toop = NULL;
2363 if (UseCompressedOops && _elem->isa_narrowoop()) {
2364 toop = _elem->make_ptr()->isa_oopptr();
2365 } else {
2366 toop = _elem->isa_oopptr();
2367 }
2368 if (!toop) return true; // a primitive type, like int
2369 ciKlass* tklass = toop->klass();
2370 if (tklass == NULL) return false; // unloaded class
2371 if (!tklass->is_loaded()) return false; // unloaded class
2372 const TypeInstPtr* tinst;
2373 if (_elem->isa_narrowoop())
2374 tinst = _elem->make_ptr()->isa_instptr();
2375 else
2376 tinst = _elem->isa_instptr();
2377 if (tinst) {
2378 // [V? has a subtype: [V. So even though V is final, [V? is not exact.
2379 if (tklass->as_instance_klass()->is_final()) {
2380 if (tinst->is_valuetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2381 return false;
2382 }
2383 return true;
2384 }
2385 return false;
2386 }
2387 const TypeAryPtr* tap;
2388 if (_elem->isa_narrowoop())
2389 tap = _elem->make_ptr()->isa_aryptr();
2390 else
2391 tap = _elem->isa_aryptr();
2392 if (tap)
2393 return tap->ary()->ary_must_be_exact();
2394 return false;
2395 }
2396
2397 //==============================TypeValueType=======================================
2398
3457 if (sub != NULL) {
3458 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3459 klass = ik = sub;
3460 klass_is_exact = sub->is_final();
3461 }
3462 }
3463 if (!klass_is_exact && try_for_exact
3464 && deps != NULL && UseExactTypes) {
3465 if (!ik->is_interface() && !ik->has_subklass()) {
3466 // Add a dependence; if concrete subclass added we need to recompile
3467 deps->assert_leaf_type(ik);
3468 klass_is_exact = true;
3469 }
3470 }
3471 }
3472 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3473 } else if (klass->is_obj_array_klass()) {
3474 // Element is an object or value array. Recursively call ourself.
3475 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3476 bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3477 if (null_free) {
3478 assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3479 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3480 }
3481 // [V? has a subtype: [V. So even though V is final, [V? is not exact.
3482 bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3483 bool not_flat = !ValueArrayFlatten || xk || !etype->can_be_value_type() || (etype->is_valuetypeptr() && !etype->value_klass()->flatten_array());
3484 bool not_null_free = !etype->can_be_value_type();
3485 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
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 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3490 return arr;
3491 } else if (klass->is_type_array_klass()) {
3492 // Element is an typeArray
3493 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3494 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3495 /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3496 // We used to pass NotNull in here, asserting that the array pointer
3497 // is not-null. That was not true in general.
3498 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3499 return arr;
3500 } else if (klass->is_value_array_klass()) {
3501 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3502 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3503 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3504 return arr;
3505 } else {
3506 ShouldNotReachHere();
3507 return NULL;
3508 }
3509 }
3510
3511 //------------------------------make_from_constant-----------------------------
3512 // Make a java pointer from an oop constant
3513 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3514 assert(!o->is_null_object(), "null object not yet handled here.");
3515
3516 const bool make_constant = require_constant || o->should_be_constant();
3517
3518 ciKlass* klass = o->klass();
3519 if (klass->is_instance_klass() || klass->is_valuetype()) {
3520 // Element is an instance or value type
3521 if (make_constant) {
3522 return TypeInstPtr::make(o);
3523 } else {
3524 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3525 }
3526 } else if (klass->is_obj_array_klass()) {
3527 // Element is an object array. Recursively call ourself.
3528 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3529 bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3530 if (null_free) {
3531 assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3532 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3533 }
3534 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3535 /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3536 // We used to pass NotNull in here, asserting that the sub-arrays
3537 // are all not-null. This is not true in generally, as code can
3538 // slam NULLs down in the subarrays.
3539 if (make_constant) {
3540 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3541 } else {
3542 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3543 }
3544 } else if (klass->is_type_array_klass()) {
3545 // Element is an typeArray
3546 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3547 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3548 /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3549 // We used to pass NotNull in here, asserting that the array pointer
3550 // is not-null. That was not true in general.
3551 if (make_constant) {
3552 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3553 } else {
3554 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3555 }
3556 } else if (klass->is_value_array_klass()) {
3557 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3558 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::make(o->as_array()->length()));
3559 // We used to pass NotNull in here, asserting that the sub-arrays
3560 // are all not-null. This is not true in generally, as code can
3561 // slam NULLs down in the subarrays.
3562 if (make_constant) {
3563 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3564 } else {
3565 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3566 }
3567 }
3568
4475 if (hi > max_hi) {
4476 hi = max_hi;
4477 if (size->is_con()) {
4478 lo = hi;
4479 }
4480 chg = true;
4481 }
4482 // Negative length arrays will produce weird intermediate dead fast-path code
4483 if (lo > hi)
4484 return TypeInt::ZERO;
4485 if (!chg)
4486 return size;
4487 return TypeInt::make(lo, hi, Type::WidenMin);
4488 }
4489
4490 //-------------------------------cast_to_size----------------------------------
4491 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4492 assert(new_size != NULL, "");
4493 new_size = narrow_size_type(new_size);
4494 if (new_size == size()) return this;
4495 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4496 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4497 }
4498
4499 //-------------------------------cast_to_not_flat------------------------------
4500 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4501 if (not_flat == is_not_flat()) {
4502 return this;
4503 }
4504 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4505 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4506 }
4507
4508 //-------------------------------cast_to_not_null_free-------------------------
4509 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4510 if (not_null_free == is_not_null_free()) {
4511 return this;
4512 }
4513 // Not null free implies not flat
4514 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4515 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4516 }
4517
4518 //------------------------------cast_to_stable---------------------------------
4519 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4520 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4521 return this;
4522
4523 const Type* elem = this->elem();
4524 const TypePtr* elem_ptr = elem->make_ptr();
4525
4526 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4527 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4528 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4529 }
4530
4531 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4532
4533 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4534 }
4535
4536 //-----------------------------stable_dimension--------------------------------
4537 int TypeAryPtr::stable_dimension() const {
4538 if (!is_stable()) return 0;
4539 int dim = 1;
4540 const TypePtr* elem_ptr = elem()->make_ptr();
4541 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4542 dim += elem_ptr->is_aryptr()->stable_dimension();
4543 return dim;
4544 }
4545
4546 //----------------------cast_to_autobox_cache-----------------------------------
4547 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4548 if (is_autobox_cache() == cache) return this;
4549 const TypeOopPtr* etype = elem()->make_oopptr();
4550 if (etype == NULL) return this;
4551 // The pointers in the autobox arrays are always non-null.
4552 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4553 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4554 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4555 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4556 }
4557
4558 //------------------------------eq---------------------------------------------
4559 // Structural equality check for Type representations
4560 bool TypeAryPtr::eq( const Type *t ) const {
4561 const TypeAryPtr *p = t->is_aryptr();
4562 return
4563 _ary == p->_ary && // Check array
4564 TypeOopPtr::eq(p) &&// Check sub-parts
4565 _field_offset == p->_field_offset;
4566 }
4567
4568 //------------------------------hash-------------------------------------------
4569 // Type-specific hashing function.
4570 int TypeAryPtr::hash(void) const {
4571 return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4572 }
4573
4574 //------------------------------meet-------------------------------------------
4654 const TypeAryPtr *tap = t->is_aryptr();
4655 Offset off = meet_offset(tap->offset());
4656 Offset field_off = meet_field_offset(tap->field_offset());
4657 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4658 PTR ptr = meet_ptr(tap->ptr());
4659 int instance_id = meet_instance_id(tap->instance_id());
4660 const TypePtr* speculative = xmeet_speculative(tap);
4661 int depth = meet_inline_depth(tap->inline_depth());
4662 ciKlass* lazy_klass = NULL;
4663 if (tary->_elem->isa_int()) {
4664 // Integral array element types have irrelevant lattice relations.
4665 // It is the klass that determines array layout, not the element type.
4666 if (_klass == NULL)
4667 lazy_klass = tap->_klass;
4668 else if (tap->_klass == NULL || tap->_klass == _klass) {
4669 lazy_klass = _klass;
4670 } else {
4671 // Something like byte[int+] meets char[int+].
4672 // This must fall to bottom, not (int[-128..65535])[int+].
4673 instance_id = InstanceBot;
4674 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable, tary->_not_flat, tary->_not_null_free);
4675 }
4676 } else if (klass() != NULL && tap->klass() != NULL &&
4677 klass()->as_array_klass()->storage_properties().value() != tap->klass()->as_array_klass()->storage_properties().value()) {
4678 // Meeting value type arrays with conflicting storage properties
4679 if (tary->_elem->isa_valuetype()) {
4680 // Result is flattened
4681 off = Offset(elem()->isa_valuetype() ? offset() : tap->offset());
4682 field_off = elem()->isa_valuetype() ? field_offset() : tap->field_offset();
4683 } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4684 // Result is non-flattened
4685 off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4686 field_off = Offset::bottom;
4687 }
4688 } else // Non integral arrays.
4689 // Must fall to bottom if exact klasses in upper lattice
4690 // are not equal or super klass is exact.
4691 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4692 // meet with top[] and bottom[] are processed further down:
4693 tap->_klass != NULL && this->_klass != NULL &&
4694 // both are exact and not equal:
4695 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4696 // 'tap' is exact and super or unrelated:
4697 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4698 // 'this' is exact and super or unrelated:
4699 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4700 if (above_centerline(ptr)) {
4701 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable, tary->_not_flat, tary->_not_null_free);
4702 }
4703 return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4704 }
4705
4706 bool xk = false;
4707 switch (tap->ptr()) {
4708 case AnyNull:
4709 case TopPTR:
4710 // Compute new klass on demand, do not use tap->_klass
4711 if (below_centerline(this->_ptr)) {
4712 xk = this->_klass_is_exact;
4713 } else {
4714 xk = (tap->_klass_is_exact || this->_klass_is_exact);
4715 }
4716 return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4717 case Constant: {
4718 ciObject* o = const_oop();
4719 if( _ptr == Constant ) {
4720 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4721 xk = (klass() == tap->klass());
4883 dump_speculative(st);
4884 }
4885 #endif
4886
4887 bool TypeAryPtr::empty(void) const {
4888 if (_ary->empty()) return true;
4889 return TypeOopPtr::empty();
4890 }
4891
4892 //------------------------------add_offset-------------------------------------
4893 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4894 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _field_offset, _instance_id, add_offset_speculative(offset), _inline_depth, _is_autobox_cache);
4895 }
4896
4897 const Type *TypeAryPtr::remove_speculative() const {
4898 if (_speculative == NULL) {
4899 return this;
4900 }
4901 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4902 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);
4903 }
4904
4905 const Type* TypeAryPtr::cleanup_speculative() const {
4906 if (speculative() == NULL) {
4907 return this;
4908 }
4909 // Keep speculative part if it contains information about flat-/nullability
4910 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
4911 if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
4912 return this;
4913 }
4914 return TypeOopPtr::cleanup_speculative();
4915 }
4916
4917 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4918 if (!UseInlineDepthForSpeculativeTypes) {
4919 return this;
4920 }
4921 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4922 }
4923
4924 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4925 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);
4926 }
4927
4928 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
4929 int adj = 0;
4930 if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
4931 const Type* elemtype = elem();
4932 if (elemtype->isa_valuetype()) {
4933 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
4934 adj = _offset.get();
|