691 //------------------------------meet-------------------------------------------
692 // Compute the MEET of two types. NOT virtual. It enforces that meet is
693 // commutative and the lattice is symmetric.
694 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
695 if (isa_narrowoop() && t->isa_narrowoop()) {
696 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
697 return result->make_narrowoop();
698 }
699 if (isa_narrowklass() && t->isa_narrowklass()) {
700 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
701 return result->make_narrowklass();
702 }
703
704 const Type *this_t = maybe_remove_speculative(include_speculative);
705 t = t->maybe_remove_speculative(include_speculative);
706
707 const Type *mt = this_t->xmeet(t);
708 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
709 if (isa_narrowklass() || t->isa_narrowklass()) return mt;
710 #ifdef ASSERT
711 assert(mt == t->xmeet(this_t), "meet not commutative");
712 const Type* dual_join = mt->_dual;
713 const Type *t2t = dual_join->xmeet(t->_dual);
714 const Type *t2this = dual_join->xmeet(this_t->_dual);
715
716 // Interface meet Oop is Not Symmetric:
717 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
718 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
719
720 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
721 tty->print_cr("=== Meet Not Symmetric ===");
722 tty->print("t = "); t->dump(); tty->cr();
723 tty->print("this= "); this_t->dump(); tty->cr();
724 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
725
726 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
727 tty->print("this_dual= "); this_t->_dual->dump(); tty->cr();
728 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
729
730 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
731 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
732
733 fatal("meet not symmetric" );
734 }
735 #endif
736 return mt;
737 }
738
2012 return make(_elem->cleanup_speculative(), _size, _stable);
2013 }
2014
2015 /**
2016 * Return same type but with a different inline depth (used for speculation)
2017 *
2018 * @param depth depth to meet with
2019 */
2020 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2021 if (!UseInlineDepthForSpeculativeTypes) {
2022 return this;
2023 }
2024 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2025 }
2026
2027 //----------------------interface_vs_oop---------------------------------------
2028 #ifdef ASSERT
2029 bool TypeAry::interface_vs_oop(const Type *t) const {
2030 const TypeAry* t_ary = t->is_ary();
2031 if (t_ary) {
2032 return _elem->interface_vs_oop(t_ary->_elem);
2033 }
2034 return false;
2035 }
2036 #endif
2037
2038 //------------------------------dump2------------------------------------------
2039 #ifndef PRODUCT
2040 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2041 if (_stable) st->print("stable:");
2042 _elem->dump2(d, depth, st);
2043 st->print("[");
2044 _size->dump2(d, depth, st);
2045 st->print("]");
2046 }
2047 #endif
2048
2049 //------------------------------singleton--------------------------------------
2050 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2051 // constants (Ldi nodes). Singletons are integer, float or double constants
2052 // or a single symbol.
3117
3118
3119 //-----------------------------filter------------------------------------------
3120 // Do not allow interface-vs.-noninterface joins to collapse to top.
3121 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3122
3123 const Type* ft = join_helper(kills, include_speculative);
3124 const TypeInstPtr* ftip = ft->isa_instptr();
3125 const TypeInstPtr* ktip = kills->isa_instptr();
3126
3127 if (ft->empty()) {
3128 // Check for evil case of 'this' being a class and 'kills' expecting an
3129 // interface. This can happen because the bytecodes do not contain
3130 // enough type info to distinguish a Java-level interface variable
3131 // from a Java-level object variable. If we meet 2 classes which
3132 // both implement interface I, but their meet is at 'j/l/O' which
3133 // doesn't implement I, we have no way to tell if the result should
3134 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
3135 // into a Phi which "knows" it's an Interface type we'll have to
3136 // uplift the type.
3137 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
3138 return kills; // Uplift to interface
3139
3140 return Type::TOP; // Canonical empty value
3141 }
3142
3143 // If we have an interface-typed Phi or cast and we narrow to a class type,
3144 // the join should report back the class. However, if we have a J/L/Object
3145 // class-typed Phi and an interface flows in, it's possible that the meet &
3146 // join report an interface back out. This isn't possible but happens
3147 // because the type system doesn't interact well with interfaces.
3148 if (ftip != NULL && ktip != NULL &&
3149 ftip->is_loaded() && ftip->klass()->is_interface() &&
3150 ktip->is_loaded() && !ktip->klass()->is_interface()) {
3151 assert(!ftip->klass_is_exact(), "interface could not be exact");
3152 return ktip->cast_to_ptr_type(ftip->ptr());
3153 }
3154
3155 return ft;
3156 }
3157
3158 //------------------------------eq---------------------------------------------
4125 else if (tap->_klass == NULL || tap->_klass == _klass) {
4126 lazy_klass = _klass;
4127 } else {
4128 // Something like byte[int+] meets char[int+].
4129 // This must fall to bottom, not (int[-128..65535])[int+].
4130 instance_id = InstanceBot;
4131 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4132 }
4133 } else // Non integral arrays.
4134 // Must fall to bottom if exact klasses in upper lattice
4135 // are not equal or super klass is exact.
4136 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4137 // meet with top[] and bottom[] are processed further down:
4138 tap->_klass != NULL && this->_klass != NULL &&
4139 // both are exact and not equal:
4140 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4141 // 'tap' is exact and super or unrelated:
4142 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4143 // 'this' is exact and super or unrelated:
4144 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4145 if (above_centerline(ptr)) {
4146 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4147 }
4148 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4149 }
4150
4151 bool xk = false;
4152 switch (tap->ptr()) {
4153 case AnyNull:
4154 case TopPTR:
4155 // Compute new klass on demand, do not use tap->_klass
4156 if (below_centerline(this->_ptr)) {
4157 xk = this->_klass_is_exact;
4158 } else {
4159 xk = (tap->_klass_is_exact | this->_klass_is_exact);
4160 }
4161 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4162 case Constant: {
4163 ciObject* o = const_oop();
4164 if( _ptr == Constant ) {
4165 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4166 xk = (klass() == tap->klass());
4167 ptr = NotNull;
|
691 //------------------------------meet-------------------------------------------
692 // Compute the MEET of two types. NOT virtual. It enforces that meet is
693 // commutative and the lattice is symmetric.
694 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
695 if (isa_narrowoop() && t->isa_narrowoop()) {
696 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
697 return result->make_narrowoop();
698 }
699 if (isa_narrowklass() && t->isa_narrowklass()) {
700 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
701 return result->make_narrowklass();
702 }
703
704 const Type *this_t = maybe_remove_speculative(include_speculative);
705 t = t->maybe_remove_speculative(include_speculative);
706
707 const Type *mt = this_t->xmeet(t);
708 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
709 if (isa_narrowklass() || t->isa_narrowklass()) return mt;
710 #ifdef ASSERT
711 if (mt != t->xmeet(this_t)) {
712 // Array of Interface meet Array of Oop is Not Commutative.
713 if (!(this_t->make_ptr() && this_t->make_ptr()->isa_aryptr() &&
714 t->make_ptr() && t->make_ptr()->isa_aryptr() &&
715 interface_vs_oop(t))) {
716 fatal("meet not commutative");
717 }
718 }
719 const Type* dual_join = mt->_dual;
720 const Type *t2t = dual_join->xmeet(t->_dual);
721 const Type *t2this = dual_join->xmeet(this_t->_dual);
722
723 // Interface meet Oop is Not Symmetric:
724 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
725 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
726 // Array of Interface meet Array of Oop is also Not Symmetric.
727
728 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
729 tty->print_cr("=== Meet Not Symmetric ===");
730 tty->print("t = "); t->dump(); tty->cr();
731 tty->print("this= "); this_t->dump(); tty->cr();
732 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
733
734 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
735 tty->print("this_dual= "); this_t->_dual->dump(); tty->cr();
736 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
737
738 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
739 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
740
741 fatal("meet not symmetric" );
742 }
743 #endif
744 return mt;
745 }
746
2020 return make(_elem->cleanup_speculative(), _size, _stable);
2021 }
2022
2023 /**
2024 * Return same type but with a different inline depth (used for speculation)
2025 *
2026 * @param depth depth to meet with
2027 */
2028 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2029 if (!UseInlineDepthForSpeculativeTypes) {
2030 return this;
2031 }
2032 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2033 }
2034
2035 //----------------------interface_vs_oop---------------------------------------
2036 #ifdef ASSERT
2037 bool TypeAry::interface_vs_oop(const Type *t) const {
2038 const TypeAry* t_ary = t->is_ary();
2039 if (t_ary) {
2040 const TypePtr* this_ptr = _elem->make_ptr(); // In case it is narrow_oop
2041 const TypePtr* t_ptr = t_ary->_elem->make_ptr();
2042 if(this_ptr != NULL && t_ptr != NULL) {
2043 return this_ptr->interface_vs_oop(t_ptr);
2044 }
2045 }
2046 return false;
2047 }
2048 #endif
2049
2050 //------------------------------dump2------------------------------------------
2051 #ifndef PRODUCT
2052 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2053 if (_stable) st->print("stable:");
2054 _elem->dump2(d, depth, st);
2055 st->print("[");
2056 _size->dump2(d, depth, st);
2057 st->print("]");
2058 }
2059 #endif
2060
2061 //------------------------------singleton--------------------------------------
2062 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2063 // constants (Ldi nodes). Singletons are integer, float or double constants
2064 // or a single symbol.
3129
3130
3131 //-----------------------------filter------------------------------------------
3132 // Do not allow interface-vs.-noninterface joins to collapse to top.
3133 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3134
3135 const Type* ft = join_helper(kills, include_speculative);
3136 const TypeInstPtr* ftip = ft->isa_instptr();
3137 const TypeInstPtr* ktip = kills->isa_instptr();
3138
3139 if (ft->empty()) {
3140 // Check for evil case of 'this' being a class and 'kills' expecting an
3141 // interface. This can happen because the bytecodes do not contain
3142 // enough type info to distinguish a Java-level interface variable
3143 // from a Java-level object variable. If we meet 2 classes which
3144 // both implement interface I, but their meet is at 'j/l/O' which
3145 // doesn't implement I, we have no way to tell if the result should
3146 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
3147 // into a Phi which "knows" it's an Interface type we'll have to
3148 // uplift the type.
3149 if (!empty()) {
3150 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3151 return kills; // Uplift to interface
3152 }
3153 const TypeAryPtr* ftap = ft->isa_aryptr();
3154 const TypeAryPtr* ktap = kills->isa_aryptr();
3155 if (ftap != NULL && ktap != NULL) {
3156 // Handle multidimensional arrays
3157 const TypePtr* ftp = ftap->elem()->make_ptr();
3158 const TypePtr* ktp = ktap->elem()->make_ptr();
3159 while (ftp && ftp->isa_aryptr() && ktp && ktp->isa_aryptr()) {
3160 ftap = ftp->is_aryptr();
3161 ktap = ktp->is_aryptr();
3162 ftp = ftap->elem()->make_ptr();
3163 ktp = ktap->elem()->make_ptr();
3164 }
3165 ktip = ktp ? ktp->isa_instptr() : NULL;
3166 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3167 return kills; // Uplift to array of interface
3168 }
3169 }
3170 }
3171
3172 return Type::TOP; // Canonical empty value
3173 }
3174
3175 // If we have an interface-typed Phi or cast and we narrow to a class type,
3176 // the join should report back the class. However, if we have a J/L/Object
3177 // class-typed Phi and an interface flows in, it's possible that the meet &
3178 // join report an interface back out. This isn't possible but happens
3179 // because the type system doesn't interact well with interfaces.
3180 if (ftip != NULL && ktip != NULL &&
3181 ftip->is_loaded() && ftip->klass()->is_interface() &&
3182 ktip->is_loaded() && !ktip->klass()->is_interface()) {
3183 assert(!ftip->klass_is_exact(), "interface could not be exact");
3184 return ktip->cast_to_ptr_type(ftip->ptr());
3185 }
3186
3187 return ft;
3188 }
3189
3190 //------------------------------eq---------------------------------------------
4157 else if (tap->_klass == NULL || tap->_klass == _klass) {
4158 lazy_klass = _klass;
4159 } else {
4160 // Something like byte[int+] meets char[int+].
4161 // This must fall to bottom, not (int[-128..65535])[int+].
4162 instance_id = InstanceBot;
4163 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4164 }
4165 } else // Non integral arrays.
4166 // Must fall to bottom if exact klasses in upper lattice
4167 // are not equal or super klass is exact.
4168 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4169 // meet with top[] and bottom[] are processed further down:
4170 tap->_klass != NULL && this->_klass != NULL &&
4171 // both are exact and not equal:
4172 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4173 // 'tap' is exact and super or unrelated:
4174 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4175 // 'this' is exact and super or unrelated:
4176 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4177
4178 const TypeAry* tta = tap->_ary;
4179 const TypeAry* mta = tary;
4180 // Handle multidimensional arrays
4181 const TypePtr* ftp = mta->_elem->make_ptr();
4182 const TypePtr* ktp = tta->_elem->make_ptr();
4183 while (ftp && ftp->isa_aryptr() && ktp && ktp->isa_aryptr()) {
4184 mta = ftp->is_aryptr()->_ary;
4185 tta = ktp->is_aryptr()->_ary;
4186 ftp = mta->_elem->make_ptr();
4187 ktp = tta->_elem->make_ptr();
4188 }
4189 const TypeInstPtr* ktip = ktp ? ktp->isa_instptr() : NULL;
4190 if (ktip == NULL || !ktip->is_loaded() || !ktip->klass()->is_interface()) {
4191 if (above_centerline(ptr)) {
4192 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4193 }
4194 }
4195 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4196 }
4197
4198 bool xk = false;
4199 switch (tap->ptr()) {
4200 case AnyNull:
4201 case TopPTR:
4202 // Compute new klass on demand, do not use tap->_klass
4203 if (below_centerline(this->_ptr)) {
4204 xk = this->_klass_is_exact;
4205 } else {
4206 xk = (tap->_klass_is_exact | this->_klass_is_exact);
4207 }
4208 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4209 case Constant: {
4210 ciObject* o = const_oop();
4211 if( _ptr == Constant ) {
4212 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4213 xk = (klass() == tap->klass());
4214 ptr = NotNull;
|