172 return Type::TOP;
173
174 case T_ADDRESS:
175 assert(type->is_return_address(), "");
176 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
177
178 default:
179 // make sure we did not mix up the cases:
180 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
181 assert(type != ciTypeFlow::StateVector::top_type(), "");
182 assert(type != ciTypeFlow::StateVector::null_type(), "");
183 assert(type != ciTypeFlow::StateVector::long2_type(), "");
184 assert(type != ciTypeFlow::StateVector::double2_type(), "");
185 assert(!type->is_return_address(), "");
186
187 return Type::get_const_type(type);
188 }
189 }
190
191
192 //------------------------------make-------------------------------------------
193 // Create a simple Type, with default empty symbol sets. Then hashcons it
194 // and look for an existing copy in the type dictionary.
195 const Type *Type::make( enum TYPES t ) {
196 return (new Type(t))->hashcons();
197 }
198
199 //------------------------------cmp--------------------------------------------
200 int Type::cmp( const Type *const t1, const Type *const t2 ) {
201 if( t1->_base != t2->_base )
202 return 1; // Missed badly
203 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
204 return !t1->eq(t2); // Return ZERO if equal
205 }
206
207 //------------------------------hash-------------------------------------------
208 int Type::uhash( const Type *const t ) {
209 return t->hash();
210 }
211
1807 if (_fields[i]->empty()) return true;
1808 }
1809 return false;
1810 }
1811
1812 //=============================================================================
1813 // Convenience common pre-built types.
1814
1815 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1816 // Certain normalizations keep us sane when comparing types.
1817 // We do not want arrayOop variables to differ only by the wideness
1818 // of their index types. Pick minimum wideness, since that is the
1819 // forced wideness of small ranges anyway.
1820 if (size->_widen != Type::WidenMin)
1821 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1822 else
1823 return size;
1824 }
1825
1826 //------------------------------make-------------------------------------------
1827 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
1828 if (UseCompressedOops && elem->isa_oopptr()) {
1829 elem = elem->make_narrowoop();
1830 }
1831 size = normalize_array_size(size);
1832 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
1833 }
1834
1835 //------------------------------meet-------------------------------------------
1836 // Compute the MEET of two types. It returns a new Type object.
1837 const Type *TypeAry::xmeet( const Type *t ) const {
1838 // Perform a fast test for common case; meeting the same types together.
1839 if( this == t ) return this; // Meeting same type-rep?
1840
1841 // Current "this->_base" is Ary
1842 switch (t->base()) { // switch on original type
1843
1844 case Bottom: // Ye Olde Default
1845 return t;
1846
1847 default: // All else is a mistake
1848 typerr(t);
1849
1850 case Array: { // Meeting 2 arrays?
1851 const TypeAry *a = t->is_ary();
1852 return TypeAry::make(_elem->meet(a->_elem),
1853 _size->xmeet(a->_size)->is_int());
1854 }
1855 case Top:
1856 break;
1857 }
1858 return this; // Return the double constant
1859 }
1860
1861 //------------------------------xdual------------------------------------------
1862 // Dual: compute field-by-field dual
1863 const Type *TypeAry::xdual() const {
1864 const TypeInt* size_dual = _size->dual()->is_int();
1865 size_dual = normalize_array_size(size_dual);
1866 return new TypeAry( _elem->dual(), size_dual);
1867 }
1868
1869 //------------------------------eq---------------------------------------------
1870 // Structural equality check for Type representations
1871 bool TypeAry::eq( const Type *t ) const {
1872 const TypeAry *a = (const TypeAry*)t;
1873 return _elem == a->_elem &&
1874 _size == a->_size;
1875 }
1876
1877 //------------------------------hash-------------------------------------------
1878 // Type-specific hashing function.
1879 int TypeAry::hash(void) const {
1880 return (intptr_t)_elem + (intptr_t)_size;
1881 }
1882
1883 //----------------------interface_vs_oop---------------------------------------
1884 #ifdef ASSERT
1885 bool TypeAry::interface_vs_oop(const Type *t) const {
1886 const TypeAry* t_ary = t->is_ary();
1887 if (t_ary) {
1888 return _elem->interface_vs_oop(t_ary->_elem);
1889 }
1890 return false;
1891 }
1892 #endif
1893
1894 //------------------------------dump2------------------------------------------
1895 #ifndef PRODUCT
1896 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1897 _elem->dump2(d, depth, st);
1898 st->print("[");
1899 _size->dump2(d, depth, st);
1900 st->print("]");
1901 }
1902 #endif
1903
1904 //------------------------------singleton--------------------------------------
1905 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1906 // constants (Ldi nodes). Singletons are integer, float or double constants
1907 // or a single symbol.
1908 bool TypeAry::singleton(void) const {
1909 return false; // Never a singleton
1910 }
1911
1912 bool TypeAry::empty(void) const {
1913 return _elem->empty() || _size->empty();
1914 }
1915
1916 //--------------------------ary_must_be_exact----------------------------------
3440 if (hi > max_hi) {
3441 hi = max_hi;
3442 if (size->is_con()) {
3443 lo = hi;
3444 }
3445 chg = true;
3446 }
3447 // Negative length arrays will produce weird intermediate dead fast-path code
3448 if (lo > hi)
3449 return TypeInt::ZERO;
3450 if (!chg)
3451 return size;
3452 return TypeInt::make(lo, hi, Type::WidenMin);
3453 }
3454
3455 //-------------------------------cast_to_size----------------------------------
3456 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3457 assert(new_size != NULL, "");
3458 new_size = narrow_size_type(new_size);
3459 if (new_size == size()) return this;
3460 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3461 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3462 }
3463
3464
3465 //------------------------------eq---------------------------------------------
3466 // Structural equality check for Type representations
3467 bool TypeAryPtr::eq( const Type *t ) const {
3468 const TypeAryPtr *p = t->is_aryptr();
3469 return
3470 _ary == p->_ary && // Check array
3471 TypeOopPtr::eq(p); // Check sub-parts
3472 }
3473
3474 //------------------------------hash-------------------------------------------
3475 // Type-specific hashing function.
3476 int TypeAryPtr::hash(void) const {
3477 return (intptr_t)_ary + TypeOopPtr::hash();
3478 }
3479
3480 //------------------------------meet-------------------------------------------
3481 // Compute the MEET of two types. It returns a new Type object.
3482 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3483 // Perform a fast test for common case; meeting the same types together.
3553 case RawPtr: return TypePtr::BOTTOM;
3554
3555 case AryPtr: { // Meeting 2 references?
3556 const TypeAryPtr *tap = t->is_aryptr();
3557 int off = meet_offset(tap->offset());
3558 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3559 PTR ptr = meet_ptr(tap->ptr());
3560 int instance_id = meet_instance_id(tap->instance_id());
3561 ciKlass* lazy_klass = NULL;
3562 if (tary->_elem->isa_int()) {
3563 // Integral array element types have irrelevant lattice relations.
3564 // It is the klass that determines array layout, not the element type.
3565 if (_klass == NULL)
3566 lazy_klass = tap->_klass;
3567 else if (tap->_klass == NULL || tap->_klass == _klass) {
3568 lazy_klass = _klass;
3569 } else {
3570 // Something like byte[int+] meets char[int+].
3571 // This must fall to bottom, not (int[-128..65535])[int+].
3572 instance_id = InstanceBot;
3573 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3574 }
3575 } else // Non integral arrays.
3576 // Must fall to bottom if exact klasses in upper lattice
3577 // are not equal or super klass is exact.
3578 if ( above_centerline(ptr) && klass() != tap->klass() &&
3579 // meet with top[] and bottom[] are processed further down:
3580 tap ->_klass != NULL && this->_klass != NULL &&
3581 // both are exact and not equal:
3582 ((tap ->_klass_is_exact && this->_klass_is_exact) ||
3583 // 'tap' is exact and super or unrelated:
3584 (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3585 // 'this' is exact and super or unrelated:
3586 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3587 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3588 return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
3589 }
3590
3591 bool xk = false;
3592 switch (tap->ptr()) {
3593 case AnyNull:
3594 case TopPTR:
3595 // Compute new klass on demand, do not use tap->_klass
3596 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3597 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3598 case Constant: {
3599 ciObject* o = const_oop();
3600 if( _ptr == Constant ) {
3601 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3602 xk = (klass() == tap->klass());
3603 ptr = NotNull;
3604 o = NULL;
3605 instance_id = InstanceBot;
3606 } else {
3607 xk = true;
|
172 return Type::TOP;
173
174 case T_ADDRESS:
175 assert(type->is_return_address(), "");
176 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
177
178 default:
179 // make sure we did not mix up the cases:
180 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
181 assert(type != ciTypeFlow::StateVector::top_type(), "");
182 assert(type != ciTypeFlow::StateVector::null_type(), "");
183 assert(type != ciTypeFlow::StateVector::long2_type(), "");
184 assert(type != ciTypeFlow::StateVector::double2_type(), "");
185 assert(!type->is_return_address(), "");
186
187 return Type::get_const_type(type);
188 }
189 }
190
191
192 //-----------------------make_from_constant------------------------------------
193 const Type* Type::make_from_constant(ciConstant constant,
194 bool require_constant, bool is_autobox_cache) {
195 switch (constant.basic_type()) {
196 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
197 case T_CHAR: return TypeInt::make(constant.as_char());
198 case T_BYTE: return TypeInt::make(constant.as_byte());
199 case T_SHORT: return TypeInt::make(constant.as_short());
200 case T_INT: return TypeInt::make(constant.as_int());
201 case T_LONG: return TypeLong::make(constant.as_long());
202 case T_FLOAT: return TypeF::make(constant.as_float());
203 case T_DOUBLE: return TypeD::make(constant.as_double());
204 case T_ARRAY:
205 case T_OBJECT:
206 {
207 // cases:
208 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0)
209 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
210 // An oop is not scavengable if it is in the perm gen.
211 ciObject* oop_constant = constant.as_object();
212 if (oop_constant->is_null_object()) {
213 return Type::get_zero_type(T_OBJECT);
214 } else if (require_constant || oop_constant->should_be_constant()) {
215 return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
216 }
217 }
218 }
219 // Fall through to failure
220 return NULL;
221 }
222
223
224 //------------------------------make-------------------------------------------
225 // Create a simple Type, with default empty symbol sets. Then hashcons it
226 // and look for an existing copy in the type dictionary.
227 const Type *Type::make( enum TYPES t ) {
228 return (new Type(t))->hashcons();
229 }
230
231 //------------------------------cmp--------------------------------------------
232 int Type::cmp( const Type *const t1, const Type *const t2 ) {
233 if( t1->_base != t2->_base )
234 return 1; // Missed badly
235 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
236 return !t1->eq(t2); // Return ZERO if equal
237 }
238
239 //------------------------------hash-------------------------------------------
240 int Type::uhash( const Type *const t ) {
241 return t->hash();
242 }
243
1839 if (_fields[i]->empty()) return true;
1840 }
1841 return false;
1842 }
1843
1844 //=============================================================================
1845 // Convenience common pre-built types.
1846
1847 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1848 // Certain normalizations keep us sane when comparing types.
1849 // We do not want arrayOop variables to differ only by the wideness
1850 // of their index types. Pick minimum wideness, since that is the
1851 // forced wideness of small ranges anyway.
1852 if (size->_widen != Type::WidenMin)
1853 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1854 else
1855 return size;
1856 }
1857
1858 //------------------------------make-------------------------------------------
1859 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
1860 if (UseCompressedOops && elem->isa_oopptr()) {
1861 elem = elem->make_narrowoop();
1862 }
1863 size = normalize_array_size(size);
1864 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
1865 }
1866
1867 //------------------------------meet-------------------------------------------
1868 // Compute the MEET of two types. It returns a new Type object.
1869 const Type *TypeAry::xmeet( const Type *t ) const {
1870 // Perform a fast test for common case; meeting the same types together.
1871 if( this == t ) return this; // Meeting same type-rep?
1872
1873 // Current "this->_base" is Ary
1874 switch (t->base()) { // switch on original type
1875
1876 case Bottom: // Ye Olde Default
1877 return t;
1878
1879 default: // All else is a mistake
1880 typerr(t);
1881
1882 case Array: { // Meeting 2 arrays?
1883 const TypeAry *a = t->is_ary();
1884 return TypeAry::make(_elem->meet(a->_elem),
1885 _size->xmeet(a->_size)->is_int(),
1886 _stable & a->_stable);
1887 }
1888 case Top:
1889 break;
1890 }
1891 return this; // Return the double constant
1892 }
1893
1894 //------------------------------xdual------------------------------------------
1895 // Dual: compute field-by-field dual
1896 const Type *TypeAry::xdual() const {
1897 const TypeInt* size_dual = _size->dual()->is_int();
1898 size_dual = normalize_array_size(size_dual);
1899 return new TypeAry(_elem->dual(), size_dual, !_stable);
1900 }
1901
1902 //------------------------------eq---------------------------------------------
1903 // Structural equality check for Type representations
1904 bool TypeAry::eq( const Type *t ) const {
1905 const TypeAry *a = (const TypeAry*)t;
1906 return _elem == a->_elem &&
1907 _stable == a->_stable &&
1908 _size == a->_size;
1909 }
1910
1911 //------------------------------hash-------------------------------------------
1912 // Type-specific hashing function.
1913 int TypeAry::hash(void) const {
1914 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1915 }
1916
1917 //----------------------interface_vs_oop---------------------------------------
1918 #ifdef ASSERT
1919 bool TypeAry::interface_vs_oop(const Type *t) const {
1920 const TypeAry* t_ary = t->is_ary();
1921 if (t_ary) {
1922 return _elem->interface_vs_oop(t_ary->_elem);
1923 }
1924 return false;
1925 }
1926 #endif
1927
1928 //------------------------------dump2------------------------------------------
1929 #ifndef PRODUCT
1930 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1931 if (_stable) st->print("stable:");
1932 _elem->dump2(d, depth, st);
1933 st->print("[");
1934 _size->dump2(d, depth, st);
1935 st->print("]");
1936 }
1937 #endif
1938
1939 //------------------------------singleton--------------------------------------
1940 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1941 // constants (Ldi nodes). Singletons are integer, float or double constants
1942 // or a single symbol.
1943 bool TypeAry::singleton(void) const {
1944 return false; // Never a singleton
1945 }
1946
1947 bool TypeAry::empty(void) const {
1948 return _elem->empty() || _size->empty();
1949 }
1950
1951 //--------------------------ary_must_be_exact----------------------------------
3475 if (hi > max_hi) {
3476 hi = max_hi;
3477 if (size->is_con()) {
3478 lo = hi;
3479 }
3480 chg = true;
3481 }
3482 // Negative length arrays will produce weird intermediate dead fast-path code
3483 if (lo > hi)
3484 return TypeInt::ZERO;
3485 if (!chg)
3486 return size;
3487 return TypeInt::make(lo, hi, Type::WidenMin);
3488 }
3489
3490 //-------------------------------cast_to_size----------------------------------
3491 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3492 assert(new_size != NULL, "");
3493 new_size = narrow_size_type(new_size);
3494 if (new_size == size()) return this;
3495 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3496 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3497 }
3498
3499
3500 //------------------------------cast_to_stable---------------------------------
3501 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3502 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3503 return this;
3504
3505 const Type* elem = this->elem();
3506 const TypePtr* elem_ptr = elem->make_ptr();
3507
3508 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3509 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3510 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3511 }
3512
3513 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3514
3515 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3516 }
3517
3518 //-----------------------------stable_dimension--------------------------------
3519 int TypeAryPtr::stable_dimension() const {
3520 if (!is_stable()) return 0;
3521 int dim = 1;
3522 const TypePtr* elem_ptr = elem()->make_ptr();
3523 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
3524 dim += elem_ptr->is_aryptr()->stable_dimension();
3525 return dim;
3526 }
3527
3528 //------------------------------eq---------------------------------------------
3529 // Structural equality check for Type representations
3530 bool TypeAryPtr::eq( const Type *t ) const {
3531 const TypeAryPtr *p = t->is_aryptr();
3532 return
3533 _ary == p->_ary && // Check array
3534 TypeOopPtr::eq(p); // Check sub-parts
3535 }
3536
3537 //------------------------------hash-------------------------------------------
3538 // Type-specific hashing function.
3539 int TypeAryPtr::hash(void) const {
3540 return (intptr_t)_ary + TypeOopPtr::hash();
3541 }
3542
3543 //------------------------------meet-------------------------------------------
3544 // Compute the MEET of two types. It returns a new Type object.
3545 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3546 // Perform a fast test for common case; meeting the same types together.
3616 case RawPtr: return TypePtr::BOTTOM;
3617
3618 case AryPtr: { // Meeting 2 references?
3619 const TypeAryPtr *tap = t->is_aryptr();
3620 int off = meet_offset(tap->offset());
3621 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3622 PTR ptr = meet_ptr(tap->ptr());
3623 int instance_id = meet_instance_id(tap->instance_id());
3624 ciKlass* lazy_klass = NULL;
3625 if (tary->_elem->isa_int()) {
3626 // Integral array element types have irrelevant lattice relations.
3627 // It is the klass that determines array layout, not the element type.
3628 if (_klass == NULL)
3629 lazy_klass = tap->_klass;
3630 else if (tap->_klass == NULL || tap->_klass == _klass) {
3631 lazy_klass = _klass;
3632 } else {
3633 // Something like byte[int+] meets char[int+].
3634 // This must fall to bottom, not (int[-128..65535])[int+].
3635 instance_id = InstanceBot;
3636 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3637 }
3638 } else // Non integral arrays.
3639 // Must fall to bottom if exact klasses in upper lattice
3640 // are not equal or super klass is exact.
3641 if ( above_centerline(ptr) && klass() != tap->klass() &&
3642 // meet with top[] and bottom[] are processed further down:
3643 tap ->_klass != NULL && this->_klass != NULL &&
3644 // both are exact and not equal:
3645 ((tap ->_klass_is_exact && this->_klass_is_exact) ||
3646 // 'tap' is exact and super or unrelated:
3647 (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3648 // 'this' is exact and super or unrelated:
3649 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3650 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3651 return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
3652 }
3653
3654 bool xk = false;
3655 switch (tap->ptr()) {
3656 case AnyNull:
3657 case TopPTR:
3658 // Compute new klass on demand, do not use tap->_klass
3659 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3660 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3661 case Constant: {
3662 ciObject* o = const_oop();
3663 if( _ptr == Constant ) {
3664 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3665 xk = (klass() == tap->klass());
3666 ptr = NotNull;
3667 o = NULL;
3668 instance_id = InstanceBot;
3669 } else {
3670 xk = true;
|