6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "ci/ciTypeFlow.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "libadt/dict.hpp"
32 #include "memory/oopFactory.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/instanceMirrorKlass.hpp"
36 #include "oops/objArrayKlass.hpp"
37 #include "oops/typeArrayKlass.hpp"
38 #include "opto/matcher.hpp"
39 #include "opto/node.hpp"
40 #include "opto/opcodes.hpp"
41 #include "opto/type.hpp"
42 #include "utilities/checkedCast.hpp"
43 #include "utilities/powerOfTwo.hpp"
44 #include "utilities/stringUtils.hpp"
45
46 // Portions of code courtesy of Clifford Click
47
48 // Optimization - Graph Style
49
50 // Dictionary of types shared among compilations.
51 Dict* Type::_shared_type_dict = nullptr;
52
53 // Array which maps compiler types to Basic Types
54 const Type::TypeInfo Type::_type_info[Type::lastype] = {
55 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
56 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
57 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
58 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
59 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
60 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
61 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
62 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
63 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
64 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
65 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
66
67 #if defined(PPC64)
68 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
69 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
70 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
71 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
206 case ciTypeFlow::StateVector::T_NULL:
207 assert(type == ciTypeFlow::StateVector::null_type(), "");
208 return TypePtr::NULL_PTR;
209
210 case ciTypeFlow::StateVector::T_LONG2:
211 // The ciTypeFlow pass pushes a long, then the half.
212 // We do the same.
213 assert(type == ciTypeFlow::StateVector::long2_type(), "");
214 return TypeInt::TOP;
215
216 case ciTypeFlow::StateVector::T_DOUBLE2:
217 // The ciTypeFlow pass pushes double, then the half.
218 // Our convention is the same.
219 assert(type == ciTypeFlow::StateVector::double2_type(), "");
220 return Type::TOP;
221
222 case T_ADDRESS:
223 assert(type->is_return_address(), "");
224 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
225
226 default:
227 // make sure we did not mix up the cases:
228 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
229 assert(type != ciTypeFlow::StateVector::top_type(), "");
230 assert(type != ciTypeFlow::StateVector::null_type(), "");
231 assert(type != ciTypeFlow::StateVector::long2_type(), "");
232 assert(type != ciTypeFlow::StateVector::double2_type(), "");
233 assert(!type->is_return_address(), "");
234
235 return Type::get_const_type(type);
236 }
237 }
238
239
240 //-----------------------make_from_constant------------------------------------
241 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
242 int stable_dimension, bool is_narrow_oop,
243 bool is_autobox_cache) {
244 switch (constant.basic_type()) {
245 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
518 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
519 ffalse[0] = Type::CONTROL;
520 ffalse[1] = Type::TOP;
521 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
522
523 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
524 fneither[0] = Type::TOP;
525 fneither[1] = Type::TOP;
526 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
527
528 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
529 ftrue[0] = Type::TOP;
530 ftrue[1] = Type::CONTROL;
531 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
532
533 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
534 floop[0] = Type::CONTROL;
535 floop[1] = TypeInt::INT;
536 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
537
538 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
539 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
540 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
541
542 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
543 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
544
545 const Type **fmembar = TypeTuple::fields(0);
546 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
547
548 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
549 fsc[0] = TypeInt::CC;
550 fsc[1] = Type::MEMORY;
551 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
552
553 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
554 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
555 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
556 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
557 false, nullptr, oopDesc::mark_offset_in_bytes());
558 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
559 false, nullptr, oopDesc::klass_offset_in_bytes());
560 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
561
562 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
563
564 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
565 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
566
567 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
568
569 mreg2type[Op_Node] = Type::BOTTOM;
570 mreg2type[Op_Set ] = nullptr;
571 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
572 mreg2type[Op_RegI] = TypeInt::INT;
573 mreg2type[Op_RegP] = TypePtr::BOTTOM;
574 mreg2type[Op_RegF] = Type::FLOAT;
575 mreg2type[Op_RegD] = Type::DOUBLE;
576 mreg2type[Op_RegL] = TypeLong::LONG;
577 mreg2type[Op_RegFlags] = TypeInt::CC;
578
579 GrowableArray<ciInstanceKlass*> array_interfaces;
580 array_interfaces.push(current->env()->Cloneable_klass());
581 array_interfaces.push(current->env()->Serializable_klass());
582 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
583 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
584
585 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
586
587 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
588
589 #ifdef _LP64
590 if (UseCompressedOops) {
591 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
592 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
593 } else
594 #endif
595 {
596 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
597 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
598 }
599 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
600 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
601 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
602 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
603 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
604 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
605 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
606
607 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
608 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
609 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
610 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
611 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
612 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
613 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
614 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
615 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
616 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
617 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
618 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
619
620 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
621 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
622
623 const Type **fi2c = TypeTuple::fields(2);
624 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
625 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
626 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
627
628 const Type **intpair = TypeTuple::fields(2);
629 intpair[0] = TypeInt::INT;
630 intpair[1] = TypeInt::INT;
631 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
632
633 const Type **longpair = TypeTuple::fields(2);
634 longpair[0] = TypeLong::LONG;
635 longpair[1] = TypeLong::LONG;
636 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
637
638 const Type **intccpair = TypeTuple::fields(2);
639 intccpair[0] = TypeInt::INT;
640 intccpair[1] = TypeInt::CC;
641 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
642
643 const Type **longccpair = TypeTuple::fields(2);
644 longccpair[0] = TypeLong::LONG;
645 longccpair[1] = TypeInt::CC;
646 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
647
648 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
649 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
650 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
651 _const_basic_type[T_CHAR] = TypeInt::CHAR;
652 _const_basic_type[T_BYTE] = TypeInt::BYTE;
653 _const_basic_type[T_SHORT] = TypeInt::SHORT;
654 _const_basic_type[T_INT] = TypeInt::INT;
655 _const_basic_type[T_LONG] = TypeLong::LONG;
656 _const_basic_type[T_FLOAT] = Type::FLOAT;
657 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
658 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
659 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
660 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
661 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
662 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
663
664 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
665 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
666 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
667 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
668 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
669 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
670 _zero_type[T_INT] = TypeInt::ZERO;
671 _zero_type[T_LONG] = TypeLong::ZERO;
672 _zero_type[T_FLOAT] = TypeF::ZERO;
673 _zero_type[T_DOUBLE] = TypeD::ZERO;
674 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
675 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
676 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
677 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
678
679 // get_zero_type() should not happen for T_CONFLICT
680 _zero_type[T_CONFLICT]= nullptr;
681
682 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
683 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
684
685 if (Matcher::supports_scalable_vector()) {
686 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
687 }
688
689 // Vector predefined types, it needs initialized _const_basic_type[].
690 if (Matcher::vector_size_supported(T_BYTE,4)) {
691 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
692 }
693 if (Matcher::vector_size_supported(T_FLOAT,2)) {
694 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
695 }
926 ~VerifyMeet() {
927 assert(_C->_type_verify->_depth != 0, "");
928 _C->_type_verify->_depth--;
929 if (_C->_type_verify->_depth == 0) {
930 _C->_type_verify->_cache.trunc_to(0);
931 }
932 }
933
934 const Type* meet(const Type* t1, const Type* t2) const {
935 return _C->_type_verify->meet(t1, t2);
936 }
937
938 void add(const Type* t1, const Type* t2, const Type* res) const {
939 _C->_type_verify->add(t1, t2, res);
940 }
941 };
942
943 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
944 Compile* C = Compile::current();
945 const Type* mt2 = verify.meet(t, this);
946 if (mt != mt2) {
947 tty->print_cr("=== Meet Not Commutative ===");
948 tty->print("t = "); t->dump(); tty->cr();
949 tty->print("this = "); dump(); tty->cr();
950 tty->print("t meet this = "); mt2->dump(); tty->cr();
951 tty->print("this meet t = "); mt->dump(); tty->cr();
952 fatal("meet not commutative");
953 }
954 const Type* dual_join = mt->_dual;
955 const Type* t2t = verify.meet(dual_join,t->_dual);
956 const Type* t2this = verify.meet(dual_join,this->_dual);
957
958 // Interface meet Oop is Not Symmetric:
959 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
960 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
961
962 if (t2t != t->_dual || t2this != this->_dual) {
963 tty->print_cr("=== Meet Not Symmetric ===");
964 tty->print("t = "); t->dump(); tty->cr();
965 tty->print("this= "); dump(); tty->cr();
966 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
967
968 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
969 tty->print("this_dual= "); _dual->dump(); tty->cr();
970 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
971
972 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
973 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
974
975 fatal("meet not symmetric");
976 }
977 }
978 #endif
979
980 //------------------------------meet-------------------------------------------
981 // Compute the MEET of two types. NOT virtual. It enforces that meet is
2112
2113 bool TypeLong::empty(void) const {
2114 return _lo > _hi;
2115 }
2116
2117 //=============================================================================
2118 // Convenience common pre-built types.
2119 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2120 const TypeTuple *TypeTuple::IFFALSE;
2121 const TypeTuple *TypeTuple::IFTRUE;
2122 const TypeTuple *TypeTuple::IFNEITHER;
2123 const TypeTuple *TypeTuple::LOOPBODY;
2124 const TypeTuple *TypeTuple::MEMBAR;
2125 const TypeTuple *TypeTuple::STORECONDITIONAL;
2126 const TypeTuple *TypeTuple::START_I2C;
2127 const TypeTuple *TypeTuple::INT_PAIR;
2128 const TypeTuple *TypeTuple::LONG_PAIR;
2129 const TypeTuple *TypeTuple::INT_CC_PAIR;
2130 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2131
2132 //------------------------------make-------------------------------------------
2133 // Make a TypeTuple from the range of a method signature
2134 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2135 ciType* return_type = sig->return_type();
2136 uint arg_cnt = return_type->size();
2137 const Type **field_array = fields(arg_cnt);
2138 switch (return_type->basic_type()) {
2139 case T_LONG:
2140 field_array[TypeFunc::Parms] = TypeLong::LONG;
2141 field_array[TypeFunc::Parms+1] = Type::HALF;
2142 break;
2143 case T_DOUBLE:
2144 field_array[TypeFunc::Parms] = Type::DOUBLE;
2145 field_array[TypeFunc::Parms+1] = Type::HALF;
2146 break;
2147 case T_OBJECT:
2148 case T_ARRAY:
2149 case T_BOOLEAN:
2150 case T_CHAR:
2151 case T_FLOAT:
2152 case T_BYTE:
2153 case T_SHORT:
2154 case T_INT:
2155 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2156 break;
2157 case T_VOID:
2158 break;
2159 default:
2160 ShouldNotReachHere();
2161 }
2162 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2163 }
2164
2165 // Make a TypeTuple from the domain of a method signature
2166 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2167 uint arg_cnt = sig->size();
2168
2169 uint pos = TypeFunc::Parms;
2170 const Type **field_array;
2171 if (recv != nullptr) {
2172 arg_cnt++;
2173 field_array = fields(arg_cnt);
2174 // Use get_const_type here because it respects UseUniqueSubclasses:
2175 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2176 } else {
2177 field_array = fields(arg_cnt);
2178 }
2179
2180 int i = 0;
2181 while (pos < TypeFunc::Parms + arg_cnt) {
2182 ciType* type = sig->type_at(i);
2183
2184 switch (type->basic_type()) {
2185 case T_LONG:
2186 field_array[pos++] = TypeLong::LONG;
2187 field_array[pos++] = Type::HALF;
2188 break;
2189 case T_DOUBLE:
2190 field_array[pos++] = Type::DOUBLE;
2191 field_array[pos++] = Type::HALF;
2192 break;
2193 case T_OBJECT:
2194 case T_ARRAY:
2195 case T_FLOAT:
2196 case T_INT:
2197 field_array[pos++] = get_const_type(type, interface_handling);
2198 break;
2199 case T_BOOLEAN:
2200 case T_CHAR:
2201 case T_BYTE:
2202 case T_SHORT:
2203 field_array[pos++] = TypeInt::INT;
2204 break;
2205 default:
2206 ShouldNotReachHere();
2207 }
2208 i++;
2209 }
2210
2211 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2212 }
2213
2214 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2215 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2216 }
2217
2218 //------------------------------fields-----------------------------------------
2219 // Subroutine call type with space allocated for argument types
2220 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2221 const Type **TypeTuple::fields( uint arg_cnt ) {
2222 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2223 flds[TypeFunc::Control ] = Type::CONTROL;
2224 flds[TypeFunc::I_O ] = Type::ABIO;
2225 flds[TypeFunc::Memory ] = Type::MEMORY;
2226 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2227 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2228
2229 return flds;
2324 if (_fields[i]->empty()) return true;
2325 }
2326 return false;
2327 }
2328
2329 //=============================================================================
2330 // Convenience common pre-built types.
2331
2332 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2333 // Certain normalizations keep us sane when comparing types.
2334 // We do not want arrayOop variables to differ only by the wideness
2335 // of their index types. Pick minimum wideness, since that is the
2336 // forced wideness of small ranges anyway.
2337 if (size->_widen != Type::WidenMin)
2338 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2339 else
2340 return size;
2341 }
2342
2343 //------------------------------make-------------------------------------------
2344 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2345 if (UseCompressedOops && elem->isa_oopptr()) {
2346 elem = elem->make_narrowoop();
2347 }
2348 size = normalize_array_size(size);
2349 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2350 }
2351
2352 //------------------------------meet-------------------------------------------
2353 // Compute the MEET of two types. It returns a new Type object.
2354 const Type *TypeAry::xmeet( const Type *t ) const {
2355 // Perform a fast test for common case; meeting the same types together.
2356 if( this == t ) return this; // Meeting same type-rep?
2357
2358 // Current "this->_base" is Ary
2359 switch (t->base()) { // switch on original type
2360
2361 case Bottom: // Ye Olde Default
2362 return t;
2363
2364 default: // All else is a mistake
2365 typerr(t);
2366
2367 case Array: { // Meeting 2 arrays?
2368 const TypeAry *a = t->is_ary();
2369 return TypeAry::make(_elem->meet_speculative(a->_elem),
2370 _size->xmeet(a->_size)->is_int(),
2371 _stable && a->_stable);
2372 }
2373 case Top:
2374 break;
2375 }
2376 return this; // Return the double constant
2377 }
2378
2379 //------------------------------xdual------------------------------------------
2380 // Dual: compute field-by-field dual
2381 const Type *TypeAry::xdual() const {
2382 const TypeInt* size_dual = _size->dual()->is_int();
2383 size_dual = normalize_array_size(size_dual);
2384 return new TypeAry(_elem->dual(), size_dual, !_stable);
2385 }
2386
2387 //------------------------------eq---------------------------------------------
2388 // Structural equality check for Type representations
2389 bool TypeAry::eq( const Type *t ) const {
2390 const TypeAry *a = (const TypeAry*)t;
2391 return _elem == a->_elem &&
2392 _stable == a->_stable &&
2393 _size == a->_size;
2394 }
2395
2396 //------------------------------hash-------------------------------------------
2397 // Type-specific hashing function.
2398 uint TypeAry::hash(void) const {
2399 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2400 }
2401
2402 /**
2403 * Return same type without a speculative part in the element
2404 */
2405 const TypeAry* TypeAry::remove_speculative() const {
2406 return make(_elem->remove_speculative(), _size, _stable);
2407 }
2408
2409 /**
2410 * Return same type with cleaned up speculative part of element
2411 */
2412 const Type* TypeAry::cleanup_speculative() const {
2413 return make(_elem->cleanup_speculative(), _size, _stable);
2414 }
2415
2416 /**
2417 * Return same type but with a different inline depth (used for speculation)
2418 *
2419 * @param depth depth to meet with
2420 */
2421 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2422 if (!UseInlineDepthForSpeculativeTypes) {
2423 return this;
2424 }
2425 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2426 }
2427
2428 //------------------------------dump2------------------------------------------
2429 #ifndef PRODUCT
2430 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2431 if (_stable) st->print("stable:");
2432 _elem->dump2(d, depth, st);
2433 st->print("[");
2434 _size->dump2(d, depth, st);
2435 st->print("]");
2436 }
2437 #endif
2438
2439 //------------------------------singleton--------------------------------------
2440 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2441 // constants (Ldi nodes). Singletons are integer, float or double constants
2442 // or a single symbol.
2443 bool TypeAry::singleton(void) const {
2444 return false; // Never a singleton
2445 }
2446
2447 bool TypeAry::empty(void) const {
2448 return _elem->empty() || _size->empty();
2449 }
2450
2451 //--------------------------ary_must_be_exact----------------------------------
2452 bool TypeAry::ary_must_be_exact() const {
2453 // This logic looks at the element type of an array, and returns true
2454 // if the element type is either a primitive or a final instance class.
2455 // In such cases, an array built on this ary must have no subclasses.
2456 if (_elem == BOTTOM) return false; // general array not exact
2457 if (_elem == TOP ) return false; // inverted general array not exact
2458 const TypeOopPtr* toop = nullptr;
2459 if (UseCompressedOops && _elem->isa_narrowoop()) {
2460 toop = _elem->make_ptr()->isa_oopptr();
2461 } else {
2462 toop = _elem->isa_oopptr();
2463 }
2464 if (!toop) return true; // a primitive type, like int
2465 if (!toop->is_loaded()) return false; // unloaded class
2466 const TypeInstPtr* tinst;
2467 if (_elem->isa_narrowoop())
2468 tinst = _elem->make_ptr()->isa_instptr();
2469 else
2470 tinst = _elem->isa_instptr();
2471 if (tinst)
2472 return tinst->instance_klass()->is_final();
2473 const TypeAryPtr* tap;
2474 if (_elem->isa_narrowoop())
2475 tap = _elem->make_ptr()->isa_aryptr();
2476 else
2477 tap = _elem->isa_aryptr();
2478 if (tap)
2479 return tap->ary()->ary_must_be_exact();
2480 return false;
2481 }
2482
2483 //==============================TypeVect=======================================
2484 // Convenience common pre-built types.
2485 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2486 const TypeVect *TypeVect::VECTS = nullptr; // 32-bit vectors
2487 const TypeVect *TypeVect::VECTD = nullptr; // 64-bit vectors
2488 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2489 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2490 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2491 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2492
2648
2649 //=============================================================================
2650 // Convenience common pre-built types.
2651 const TypePtr *TypePtr::NULL_PTR;
2652 const TypePtr *TypePtr::NOTNULL;
2653 const TypePtr *TypePtr::BOTTOM;
2654
2655 //------------------------------meet-------------------------------------------
2656 // Meet over the PTR enum
2657 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2658 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2659 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2660 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2661 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2662 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2663 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2664 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2665 };
2666
2667 //------------------------------make-------------------------------------------
2668 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2669 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2670 }
2671
2672 //------------------------------cast_to_ptr_type-------------------------------
2673 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2674 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2675 if( ptr == _ptr ) return this;
2676 return make(_base, ptr, _offset, _speculative, _inline_depth);
2677 }
2678
2679 //------------------------------get_con----------------------------------------
2680 intptr_t TypePtr::get_con() const {
2681 assert( _ptr == Null, "" );
2682 return _offset;
2683 }
2684
2685 //------------------------------meet-------------------------------------------
2686 // Compute the MEET of two types. It returns a new Type object.
2687 const Type *TypePtr::xmeet(const Type *t) const {
2688 const Type* res = xmeet_helper(t);
2689 if (res->isa_ptr() == nullptr) {
2690 return res;
2691 }
2692
2693 const TypePtr* res_ptr = res->is_ptr();
2694 if (res_ptr->speculative() != nullptr) {
2695 // type->speculative() is null means that speculation is no better
2696 // than type, i.e. type->speculative() == type. So there are 2
2697 // ways to represent the fact that we have no useful speculative
2698 // data and we should use a single one to be able to test for
2699 // equality between types. Check whether type->speculative() ==
2700 // type and set speculative to null if it is the case.
2701 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2702 return res_ptr->remove_speculative();
2733 int depth = meet_inline_depth(tp->inline_depth());
2734 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2735 }
2736 case RawPtr: // For these, flip the call around to cut down
2737 case OopPtr:
2738 case InstPtr: // on the cases I have to handle.
2739 case AryPtr:
2740 case MetadataPtr:
2741 case KlassPtr:
2742 case InstKlassPtr:
2743 case AryKlassPtr:
2744 return t->xmeet(this); // Call in reverse direction
2745 default: // All else is a mistake
2746 typerr(t);
2747
2748 }
2749 return this;
2750 }
2751
2752 //------------------------------meet_offset------------------------------------
2753 int TypePtr::meet_offset( int offset ) const {
2754 // Either is 'TOP' offset? Return the other offset!
2755 if( _offset == OffsetTop ) return offset;
2756 if( offset == OffsetTop ) return _offset;
2757 // If either is different, return 'BOTTOM' offset
2758 if( _offset != offset ) return OffsetBot;
2759 return _offset;
2760 }
2761
2762 //------------------------------dual_offset------------------------------------
2763 int TypePtr::dual_offset( ) const {
2764 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2765 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2766 return _offset; // Map everything else into self
2767 }
2768
2769 //------------------------------xdual------------------------------------------
2770 // Dual: compute field-by-field dual
2771 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2772 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2773 };
2774 const Type *TypePtr::xdual() const {
2775 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2776 }
2777
2778 //------------------------------xadd_offset------------------------------------
2779 int TypePtr::xadd_offset( intptr_t offset ) const {
2780 // Adding to 'TOP' offset? Return 'TOP'!
2781 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2782 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2783 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2784 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2785 offset += (intptr_t)_offset;
2786 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2787
2788 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2789 // It is possible to construct a negative offset during PhaseCCP
2790
2791 return (int)offset; // Sum valid offsets
2792 }
2793
2794 //------------------------------add_offset-------------------------------------
2795 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2796 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2797 }
2798
2799 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2800 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2801 }
2802
2803 //------------------------------eq---------------------------------------------
2804 // Structural equality check for Type representations
2805 bool TypePtr::eq( const Type *t ) const {
2806 const TypePtr *a = (const TypePtr*)t;
2807 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2808 }
2809
2810 //------------------------------hash-------------------------------------------
2811 // Type-specific hashing function.
2812 uint TypePtr::hash(void) const {
2813 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2814 }
2815
2816 /**
2817 * Return same type without a speculative part
2818 */
2819 const TypePtr* TypePtr::remove_speculative() const {
2820 if (_speculative == nullptr) {
2821 return this;
2822 }
2823 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2824 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2825 }
2826
2827 /**
2828 * Return same type but drop speculative part if we know we won't use
2829 * it
2830 */
2831 const Type* TypePtr::cleanup_speculative() const {
2832 if (speculative() == nullptr) {
2833 return this;
3059 }
3060 // We already know the speculative type is always null
3061 if (speculative_always_null()) {
3062 return false;
3063 }
3064 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3065 return false;
3066 }
3067 return true;
3068 }
3069
3070 //------------------------------dump2------------------------------------------
3071 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3072 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3073 };
3074
3075 #ifndef PRODUCT
3076 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3077 if( _ptr == Null ) st->print("null");
3078 else st->print("%s *", ptr_msg[_ptr]);
3079 if( _offset == OffsetTop ) st->print("+top");
3080 else if( _offset == OffsetBot ) st->print("+bot");
3081 else if( _offset ) st->print("+%d", _offset);
3082 dump_inline_depth(st);
3083 dump_speculative(st);
3084 }
3085
3086 /**
3087 *dump the speculative part of the type
3088 */
3089 void TypePtr::dump_speculative(outputStream *st) const {
3090 if (_speculative != nullptr) {
3091 st->print(" (speculative=");
3092 _speculative->dump_on(st);
3093 st->print(")");
3094 }
3095 }
3096
3097 /**
3098 *dump the inline depth of the type
3099 */
3100 void TypePtr::dump_inline_depth(outputStream *st) const {
3101 if (_inline_depth != InlineDepthBottom) {
3102 if (_inline_depth == InlineDepthTop) {
3103 st->print(" (inline_depth=InlineDepthTop)");
3104 } else {
3105 st->print(" (inline_depth=%d)", _inline_depth);
3106 }
3107 }
3108 }
3109 #endif
3110
3111 //------------------------------singleton--------------------------------------
3112 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3113 // constants
3114 bool TypePtr::singleton(void) const {
3115 // TopPTR, Null, AnyNull, Constant are all singletons
3116 return (_offset != OffsetBot) && !below_centerline(_ptr);
3117 }
3118
3119 bool TypePtr::empty(void) const {
3120 return (_offset == OffsetTop) || above_centerline(_ptr);
3121 }
3122
3123 //=============================================================================
3124 // Convenience common pre-built types.
3125 const TypeRawPtr *TypeRawPtr::BOTTOM;
3126 const TypeRawPtr *TypeRawPtr::NOTNULL;
3127
3128 //------------------------------make-------------------------------------------
3129 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3130 assert( ptr != Constant, "what is the constant?" );
3131 assert( ptr != Null, "Use TypePtr for null" );
3132 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3133 }
3134
3135 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3136 assert( bits, "Use TypePtr for null" );
3137 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3138 }
3139
3140 //------------------------------cast_to_ptr_type-------------------------------
3492 void TypeInterfaces::verify_is_loaded() const {
3493 for (int i = 0; i < _list.length(); i++) {
3494 ciKlass* interface = _list.at(i);
3495 assert(interface->is_loaded(), "Interface not loaded");
3496 }
3497 }
3498 #endif
3499
3500 // Can't be implemented because there's no way to know if the type is above or below the center line.
3501 const Type* TypeInterfaces::xmeet(const Type* t) const {
3502 ShouldNotReachHere();
3503 return Type::xmeet(t);
3504 }
3505
3506 bool TypeInterfaces::singleton(void) const {
3507 ShouldNotReachHere();
3508 return Type::singleton();
3509 }
3510
3511 //------------------------------TypeOopPtr-------------------------------------
3512 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3513 int instance_id, const TypePtr* speculative, int inline_depth)
3514 : TypePtr(t, ptr, offset, speculative, inline_depth),
3515 _const_oop(o), _klass(k),
3516 _interfaces(interfaces),
3517 _klass_is_exact(xk),
3518 _is_ptr_to_narrowoop(false),
3519 _is_ptr_to_narrowklass(false),
3520 _is_ptr_to_boxed_value(false),
3521 _instance_id(instance_id) {
3522 #ifdef ASSERT
3523 if (klass() != nullptr && klass()->is_loaded()) {
3524 interfaces->verify_is_loaded();
3525 }
3526 #endif
3527 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3528 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3529 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3530 }
3531 #ifdef _LP64
3532 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3533 if (_offset == oopDesc::klass_offset_in_bytes()) {
3534 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3535 } else if (klass() == nullptr) {
3536 // Array with unknown body type
3537 assert(this->isa_aryptr(), "only arrays without klass");
3538 _is_ptr_to_narrowoop = UseCompressedOops;
3539 } else if (this->isa_aryptr()) {
3540 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3541 _offset != arrayOopDesc::length_offset_in_bytes());
3542 } else if (klass()->is_instance_klass()) {
3543 ciInstanceKlass* ik = klass()->as_instance_klass();
3544 if (this->isa_klassptr()) {
3545 // Perm objects don't use compressed references
3546 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3547 // unsafe access
3548 _is_ptr_to_narrowoop = UseCompressedOops;
3549 } else {
3550 assert(this->isa_instptr(), "must be an instance ptr.");
3551
3552 if (klass() == ciEnv::current()->Class_klass() &&
3553 (_offset == java_lang_Class::klass_offset() ||
3554 _offset == java_lang_Class::array_klass_offset())) {
3555 // Special hidden fields from the Class.
3556 assert(this->isa_instptr(), "must be an instance ptr.");
3557 _is_ptr_to_narrowoop = false;
3558 } else if (klass() == ciEnv::current()->Class_klass() &&
3559 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3560 // Static fields
3561 ciField* field = nullptr;
3562 if (const_oop() != nullptr) {
3563 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3564 field = k->get_field_by_offset(_offset, true);
3565 }
3566 if (field != nullptr) {
3567 BasicType basic_elem_type = field->layout_type();
3568 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3569 } else {
3570 // unsafe access
3571 _is_ptr_to_narrowoop = UseCompressedOops;
3572 }
3573 } else {
3574 // Instance fields which contains a compressed oop references.
3575 ciField* field = ik->get_field_by_offset(_offset, false);
3576 if (field != nullptr) {
3577 BasicType basic_elem_type = field->layout_type();
3578 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3579 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3580 // Compile::find_alias_type() cast exactness on all types to verify
3581 // that it does not affect alias type.
3582 _is_ptr_to_narrowoop = UseCompressedOops;
3583 } else {
3584 // Type for the copy start in LibraryCallKit::inline_native_clone().
3585 _is_ptr_to_narrowoop = UseCompressedOops;
3586 }
3587 }
3588 }
3589 }
3590 }
3591 #endif
3592 }
3593
3594 //------------------------------make-------------------------------------------
3595 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3596 const TypePtr* speculative, int inline_depth) {
3597 assert(ptr != Constant, "no constant generic pointers");
3598 ciKlass* k = Compile::current()->env()->Object_klass();
3599 bool xk = false;
3600 ciObject* o = nullptr;
3601 const TypeInterfaces* interfaces = TypeInterfaces::make();
3602 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3603 }
3604
3605
3606 //------------------------------cast_to_ptr_type-------------------------------
3607 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3608 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3609 if( ptr == _ptr ) return this;
3610 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3611 }
3612
3613 //-----------------------------cast_to_instance_id----------------------------
3614 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3615 // There are no instances of a general oop.
3616 // Return self unchanged.
3617 return this;
3618 }
3619
3620 //-----------------------------cast_to_exactness-------------------------------
3621 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3622 // There is no such thing as an exact general oop.
3623 // Return self unchanged.
3624 return this;
3625 }
3626
3627
3628 //------------------------------as_klass_type----------------------------------
3629 // Return the klass type corresponding to this instance or array type.
3630 // It is the type that is loaded from an object of this type.
3631 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3632 ShouldNotReachHere();
3633 return nullptr;
3634 }
3635
3636 //------------------------------meet-------------------------------------------
3637 // Compute the MEET of two types. It returns a new Type object.
3638 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3639 // Perform a fast test for common case; meeting the same types together.
3640 if( this == t ) return this; // Meeting same type-rep?
3641
3642 // Current "this->_base" is OopPtr
3643 switch (t->base()) { // switch on original type
3644
3645 case Int: // Mixing ints & oops happens when javac
3646 case Long: // reuses local variables
3647 case FloatTop:
3653 case NarrowOop:
3654 case NarrowKlass:
3655 case Bottom: // Ye Olde Default
3656 return Type::BOTTOM;
3657 case Top:
3658 return this;
3659
3660 default: // All else is a mistake
3661 typerr(t);
3662
3663 case RawPtr:
3664 case MetadataPtr:
3665 case KlassPtr:
3666 case InstKlassPtr:
3667 case AryKlassPtr:
3668 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3669
3670 case AnyPtr: {
3671 // Found an AnyPtr type vs self-OopPtr type
3672 const TypePtr *tp = t->is_ptr();
3673 int offset = meet_offset(tp->offset());
3674 PTR ptr = meet_ptr(tp->ptr());
3675 const TypePtr* speculative = xmeet_speculative(tp);
3676 int depth = meet_inline_depth(tp->inline_depth());
3677 switch (tp->ptr()) {
3678 case Null:
3679 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3680 // else fall through:
3681 case TopPTR:
3682 case AnyNull: {
3683 int instance_id = meet_instance_id(InstanceTop);
3684 return make(ptr, offset, instance_id, speculative, depth);
3685 }
3686 case BotPTR:
3687 case NotNull:
3688 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3689 default: typerr(t);
3690 }
3691 }
3692
3693 case OopPtr: { // Meeting to other OopPtrs
3695 int instance_id = meet_instance_id(tp->instance_id());
3696 const TypePtr* speculative = xmeet_speculative(tp);
3697 int depth = meet_inline_depth(tp->inline_depth());
3698 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3699 }
3700
3701 case InstPtr: // For these, flip the call around to cut down
3702 case AryPtr:
3703 return t->xmeet(this); // Call in reverse direction
3704
3705 } // End of switch
3706 return this; // Return the double constant
3707 }
3708
3709
3710 //------------------------------xdual------------------------------------------
3711 // Dual of a pure heap pointer. No relevant klass or oop information.
3712 const Type *TypeOopPtr::xdual() const {
3713 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3714 assert(const_oop() == nullptr, "no constants here");
3715 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3716 }
3717
3718 //--------------------------make_from_klass_common-----------------------------
3719 // Computes the element-type given a klass.
3720 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3721 if (klass->is_instance_klass()) {
3722 Compile* C = Compile::current();
3723 Dependencies* deps = C->dependencies();
3724 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3725 // Element is an instance
3726 bool klass_is_exact = false;
3727 if (klass->is_loaded()) {
3728 // Try to set klass_is_exact.
3729 ciInstanceKlass* ik = klass->as_instance_klass();
3730 klass_is_exact = ik->is_final();
3731 if (!klass_is_exact && klass_change
3732 && deps != nullptr && UseUniqueSubclasses) {
3733 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3734 if (sub != nullptr) {
3735 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3736 klass = ik = sub;
3737 klass_is_exact = sub->is_final();
3738 }
3739 }
3740 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3741 !ik->is_interface() && !ik->has_subklass()) {
3742 // Add a dependence; if concrete subclass added we need to recompile
3743 deps->assert_leaf_type(ik);
3744 klass_is_exact = true;
3745 }
3746 }
3747 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3748 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3749 } else if (klass->is_obj_array_klass()) {
3750 // Element is an object array. Recursively call ourself.
3751 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3752 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3753 bool xk = etype->klass_is_exact();
3754 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3755 // We used to pass NotNull in here, asserting that the sub-arrays
3756 // are all not-null. This is not true in generally, as code can
3757 // slam nulls down in the subarrays.
3758 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3759 return arr;
3760 } else if (klass->is_type_array_klass()) {
3761 // Element is an typeArray
3762 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3763 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3764 // We used to pass NotNull in here, asserting that the array pointer
3765 // is not-null. That was not true in general.
3766 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3767 return arr;
3768 } else {
3769 ShouldNotReachHere();
3770 return nullptr;
3771 }
3772 }
3773
3774 //------------------------------make_from_constant-----------------------------
3775 // Make a java pointer from an oop constant
3776 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3777 assert(!o->is_null_object(), "null object not yet handled here.");
3778
3779 const bool make_constant = require_constant || o->should_be_constant();
3780
3781 ciKlass* klass = o->klass();
3782 if (klass->is_instance_klass()) {
3783 // Element is an instance
3784 if (make_constant) {
3785 return TypeInstPtr::make(o);
3786 } else {
3787 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3788 }
3789 } else if (klass->is_obj_array_klass()) {
3790 // Element is an object array. Recursively call ourself.
3791 const TypeOopPtr *etype =
3792 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3793 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3794 // We used to pass NotNull in here, asserting that the sub-arrays
3795 // are all not-null. This is not true in generally, as code can
3796 // slam nulls down in the subarrays.
3797 if (make_constant) {
3798 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3799 } else {
3800 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3801 }
3802 } else if (klass->is_type_array_klass()) {
3803 // Element is an typeArray
3804 const Type* etype =
3805 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3806 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3807 // We used to pass NotNull in here, asserting that the array pointer
3808 // is not-null. That was not true in general.
3809 if (make_constant) {
3810 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3811 } else {
3812 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3813 }
3814 }
3815
3816 fatal("unhandled object type");
3817 return nullptr;
3818 }
3819
3820 //------------------------------get_con----------------------------------------
3821 intptr_t TypeOopPtr::get_con() const {
3822 assert( _ptr == Null || _ptr == Constant, "" );
3823 assert( _offset >= 0, "" );
3824
3825 if (_offset != 0) {
3826 // After being ported to the compiler interface, the compiler no longer
3827 // directly manipulates the addresses of oops. Rather, it only has a pointer
3828 // to a handle at compile time. This handle is embedded in the generated
3829 // code and dereferenced at the time the nmethod is made. Until that time,
3830 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3831 // have access to the addresses!). This does not seem to currently happen,
3832 // but this assertion here is to help prevent its occurrence.
3833 tty->print_cr("Found oop constant with non-zero offset");
3834 ShouldNotReachHere();
3835 }
3836
3837 return (intptr_t)const_oop()->constant_encoding();
3838 }
3839
3840
3841 //-----------------------------filter------------------------------------------
3842 // Do not allow interface-vs.-noninterface joins to collapse to top.
3843 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3844
3845 const Type* ft = join_helper(kills, include_speculative);
3866 } else {
3867 return one->equals(two) && TypePtr::eq(t);
3868 }
3869 }
3870
3871 //------------------------------hash-------------------------------------------
3872 // Type-specific hashing function.
3873 uint TypeOopPtr::hash(void) const {
3874 return
3875 (uint)(const_oop() ? const_oop()->hash() : 0) +
3876 (uint)_klass_is_exact +
3877 (uint)_instance_id + TypePtr::hash();
3878 }
3879
3880 //------------------------------dump2------------------------------------------
3881 #ifndef PRODUCT
3882 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3883 st->print("oopptr:%s", ptr_msg[_ptr]);
3884 if( _klass_is_exact ) st->print(":exact");
3885 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3886 switch( _offset ) {
3887 case OffsetTop: st->print("+top"); break;
3888 case OffsetBot: st->print("+any"); break;
3889 case 0: break;
3890 default: st->print("+%d",_offset); break;
3891 }
3892 if (_instance_id == InstanceTop)
3893 st->print(",iid=top");
3894 else if (_instance_id != InstanceBot)
3895 st->print(",iid=%d",_instance_id);
3896
3897 dump_inline_depth(st);
3898 dump_speculative(st);
3899 }
3900 #endif
3901
3902 //------------------------------singleton--------------------------------------
3903 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3904 // constants
3905 bool TypeOopPtr::singleton(void) const {
3906 // detune optimizer to not generate constant oop + constant offset as a constant!
3907 // TopPTR, Null, AnyNull, Constant are all singletons
3908 return (_offset == 0) && !below_centerline(_ptr);
3909 }
3910
3911 //------------------------------add_offset-------------------------------------
3912 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3913 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3914 }
3915
3916 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3917 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3918 }
3919
3920 /**
3921 * Return same type without a speculative part
3922 */
3923 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3924 if (_speculative == nullptr) {
3925 return this;
3926 }
3927 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3928 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3929 }
3930
3931 /**
3932 * Return same type but drop speculative part if we know we won't use
3933 * it
3934 */
3935 const Type* TypeOopPtr::cleanup_speculative() const {
3936 // If the klass is exact and the ptr is not null then there's
3937 // nothing that the speculative type can help us with
4010 const TypeInstPtr *TypeInstPtr::BOTTOM;
4011 const TypeInstPtr *TypeInstPtr::MIRROR;
4012 const TypeInstPtr *TypeInstPtr::MARK;
4013 const TypeInstPtr *TypeInstPtr::KLASS;
4014
4015 // Is there a single ciKlass* that can represent that type?
4016 ciKlass* TypeInstPtr::exact_klass_helper() const {
4017 if (_interfaces->empty()) {
4018 return _klass;
4019 }
4020 if (_klass != ciEnv::current()->Object_klass()) {
4021 if (_interfaces->eq(_klass->as_instance_klass())) {
4022 return _klass;
4023 }
4024 return nullptr;
4025 }
4026 return _interfaces->exact_klass();
4027 }
4028
4029 //------------------------------TypeInstPtr-------------------------------------
4030 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4031 int instance_id, const TypePtr* speculative, int inline_depth)
4032 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4033 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4034 assert(k != nullptr &&
4035 (k->is_loaded() || o == nullptr),
4036 "cannot have constants with non-loaded klass");
4037 };
4038
4039 //------------------------------make-------------------------------------------
4040 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4041 ciKlass* k,
4042 const TypeInterfaces* interfaces,
4043 bool xk,
4044 ciObject* o,
4045 int offset,
4046 int instance_id,
4047 const TypePtr* speculative,
4048 int inline_depth) {
4049 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4050 // Either const_oop() is null or else ptr is Constant
4051 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4052 "constant pointers must have a value supplied" );
4053 // Ptr is never Null
4054 assert( ptr != Null, "null pointers are not typed" );
4055
4056 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4057 if (ptr == Constant) {
4058 // Note: This case includes meta-object constants, such as methods.
4059 xk = true;
4060 } else if (k->is_loaded()) {
4061 ciInstanceKlass* ik = k->as_instance_klass();
4062 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4063 assert(!ik->is_interface(), "no interface here");
4064 if (xk && ik->is_interface()) xk = false; // no exact interface
4065 }
4066
4067 // Now hash this baby
4068 TypeInstPtr *result =
4069 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4070
4071 return result;
4072 }
4073
4074 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4075 if (k->is_instance_klass()) {
4076 if (k->is_loaded()) {
4077 if (k->is_interface() && interface_handling == ignore_interfaces) {
4078 assert(interface, "no interface expected");
4079 k = ciEnv::current()->Object_klass();
4080 const TypeInterfaces* interfaces = TypeInterfaces::make();
4081 return interfaces;
4082 }
4083 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4084 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4085 if (k->is_interface()) {
4086 assert(interface, "no interface expected");
4087 k = ciEnv::current()->Object_klass();
4088 } else {
4089 assert(klass, "no instance klass expected");
4115 switch (bt) {
4116 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4117 case T_INT: return TypeInt::make(constant.as_int());
4118 case T_CHAR: return TypeInt::make(constant.as_char());
4119 case T_BYTE: return TypeInt::make(constant.as_byte());
4120 case T_SHORT: return TypeInt::make(constant.as_short());
4121 case T_FLOAT: return TypeF::make(constant.as_float());
4122 case T_DOUBLE: return TypeD::make(constant.as_double());
4123 case T_LONG: return TypeLong::make(constant.as_long());
4124 default: break;
4125 }
4126 fatal("Invalid boxed value type '%s'", type2name(bt));
4127 return nullptr;
4128 }
4129
4130 //------------------------------cast_to_ptr_type-------------------------------
4131 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4132 if( ptr == _ptr ) return this;
4133 // Reconstruct _sig info here since not a problem with later lazy
4134 // construction, _sig will show up on demand.
4135 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4136 }
4137
4138
4139 //-----------------------------cast_to_exactness-------------------------------
4140 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4141 if( klass_is_exact == _klass_is_exact ) return this;
4142 if (!_klass->is_loaded()) return this;
4143 ciInstanceKlass* ik = _klass->as_instance_klass();
4144 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4145 assert(!ik->is_interface(), "no interface here");
4146 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4147 }
4148
4149 //-----------------------------cast_to_instance_id----------------------------
4150 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4151 if( instance_id == _instance_id ) return this;
4152 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4153 }
4154
4155 //------------------------------xmeet_unloaded---------------------------------
4156 // Compute the MEET of two InstPtrs when at least one is unloaded.
4157 // Assume classes are different since called after check for same name/class-loader
4158 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4159 int off = meet_offset(tinst->offset());
4160 PTR ptr = meet_ptr(tinst->ptr());
4161 int instance_id = meet_instance_id(tinst->instance_id());
4162 const TypePtr* speculative = xmeet_speculative(tinst);
4163 int depth = meet_inline_depth(tinst->inline_depth());
4164
4165 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4166 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4167 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4168 //
4169 // Meet unloaded class with java/lang/Object
4170 //
4171 // Meet
4172 // | Unloaded Class
4173 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4174 // ===================================================================
4175 // TOP | ..........................Unloaded......................|
4176 // AnyNull | U-AN |................Unloaded......................|
4177 // Constant | ... O-NN .................................. | O-BOT |
4178 // NotNull | ... O-NN .................................. | O-BOT |
4179 // BOTTOM | ........................Object-BOTTOM ..................|
4180 //
4181 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4182 //
4183 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4184 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4185 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4186 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4187 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4188 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4189 }
4190 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4191
4192 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4193 }
4194
4195 // Both are unloaded, not the same class, not Object
4196 // Or meet unloaded with a different loaded class, not java/lang/Object
4197 if (ptr != TypePtr::BotPTR) {
4198 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4199 }
4200 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4201 }
4202
4203
4204 //------------------------------meet-------------------------------------------
4225 case Top:
4226 return this;
4227
4228 default: // All else is a mistake
4229 typerr(t);
4230
4231 case MetadataPtr:
4232 case KlassPtr:
4233 case InstKlassPtr:
4234 case AryKlassPtr:
4235 case RawPtr: return TypePtr::BOTTOM;
4236
4237 case AryPtr: { // All arrays inherit from Object class
4238 // Call in reverse direction to avoid duplication
4239 return t->is_aryptr()->xmeet_helper(this);
4240 }
4241
4242 case OopPtr: { // Meeting to OopPtrs
4243 // Found a OopPtr type vs self-InstPtr type
4244 const TypeOopPtr *tp = t->is_oopptr();
4245 int offset = meet_offset(tp->offset());
4246 PTR ptr = meet_ptr(tp->ptr());
4247 switch (tp->ptr()) {
4248 case TopPTR:
4249 case AnyNull: {
4250 int instance_id = meet_instance_id(InstanceTop);
4251 const TypePtr* speculative = xmeet_speculative(tp);
4252 int depth = meet_inline_depth(tp->inline_depth());
4253 return make(ptr, klass(), _interfaces, klass_is_exact(),
4254 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4255 }
4256 case NotNull:
4257 case BotPTR: {
4258 int instance_id = meet_instance_id(tp->instance_id());
4259 const TypePtr* speculative = xmeet_speculative(tp);
4260 int depth = meet_inline_depth(tp->inline_depth());
4261 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4262 }
4263 default: typerr(t);
4264 }
4265 }
4266
4267 case AnyPtr: { // Meeting to AnyPtrs
4268 // Found an AnyPtr type vs self-InstPtr type
4269 const TypePtr *tp = t->is_ptr();
4270 int offset = meet_offset(tp->offset());
4271 PTR ptr = meet_ptr(tp->ptr());
4272 int instance_id = meet_instance_id(InstanceTop);
4273 const TypePtr* speculative = xmeet_speculative(tp);
4274 int depth = meet_inline_depth(tp->inline_depth());
4275 switch (tp->ptr()) {
4276 case Null:
4277 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4278 // else fall through to AnyNull
4279 case TopPTR:
4280 case AnyNull: {
4281 return make(ptr, klass(), _interfaces, klass_is_exact(),
4282 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4283 }
4284 case NotNull:
4285 case BotPTR:
4286 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4287 default: typerr(t);
4288 }
4289 }
4290
4291 /*
4292 A-top }
4293 / | \ } Tops
4294 B-top A-any C-top }
4295 | / | \ | } Any-nulls
4296 B-any | C-any }
4297 | | |
4298 B-con A-con C-con } constants; not comparable across classes
4299 | | |
4300 B-not | C-not }
4301 | \ | / | } not-nulls
4302 B-bot A-not C-bot }
4303 \ | / } Bottoms
4304 A-bot }
4305 */
4306
4307 case InstPtr: { // Meeting 2 Oops?
4308 // Found an InstPtr sub-type vs self-InstPtr type
4309 const TypeInstPtr *tinst = t->is_instptr();
4310 int off = meet_offset(tinst->offset());
4311 PTR ptr = meet_ptr(tinst->ptr());
4312 int instance_id = meet_instance_id(tinst->instance_id());
4313 const TypePtr* speculative = xmeet_speculative(tinst);
4314 int depth = meet_inline_depth(tinst->inline_depth());
4315 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4316
4317 ciKlass* tinst_klass = tinst->klass();
4318 ciKlass* this_klass = klass();
4319
4320 ciKlass* res_klass = nullptr;
4321 bool res_xk = false;
4322 const Type* res;
4323 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4324
4325 if (kind == UNLOADED) {
4326 // One of these classes has not been loaded
4327 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4328 #ifndef PRODUCT
4329 if (PrintOpto && Verbose) {
4330 tty->print("meet of unloaded classes resulted in: ");
4331 unloaded_meet->dump();
4332 tty->cr();
4333 tty->print(" this == ");
4334 dump();
4335 tty->cr();
4336 tty->print(" tinst == ");
4337 tinst->dump();
4338 tty->cr();
4339 }
4340 #endif
4341 res = unloaded_meet;
4342 } else {
4343 if (kind == NOT_SUBTYPE && instance_id > 0) {
4344 instance_id = InstanceBot;
4345 } else if (kind == LCA) {
4346 instance_id = InstanceBot;
4347 }
4348 ciObject* o = nullptr; // Assume not constant when done
4349 ciObject* this_oop = const_oop();
4350 ciObject* tinst_oop = tinst->const_oop();
4351 if (ptr == Constant) {
4352 if (this_oop != nullptr && tinst_oop != nullptr &&
4353 this_oop->equals(tinst_oop))
4354 o = this_oop;
4355 else if (above_centerline(_ptr)) {
4356 assert(!tinst_klass->is_interface(), "");
4357 o = tinst_oop;
4358 } else if (above_centerline(tinst->_ptr)) {
4359 assert(!this_klass->is_interface(), "");
4360 o = this_oop;
4361 } else
4362 ptr = NotNull;
4363 }
4364 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4365 }
4366
4367 return res;
4368
4369 } // End of case InstPtr
4370
4371 } // End of switch
4372 return this; // Return the double constant
4373 }
4374
4375 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4376 ciKlass*& res_klass, bool& res_xk) {
4377 ciKlass* this_klass = this_type->klass();
4378 ciKlass* other_klass = other_type->klass();
4379 bool this_xk = this_type->klass_is_exact();
4380 bool other_xk = other_type->klass_is_exact();
4381 PTR this_ptr = this_type->ptr();
4382 PTR other_ptr = other_type->ptr();
4383 const TypeInterfaces* this_interfaces = this_type->interfaces();
4384 const TypeInterfaces* other_interfaces = other_type->interfaces();
4385 // Check for easy case; klasses are equal (and perhaps not loaded!)
4386 // If we have constants, then we created oops so classes are loaded
4387 // and we can handle the constants further down. This case handles
4388 // both-not-loaded or both-loaded classes
4389 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4390 res_klass = this_klass;
4391 res_xk = this_xk;
4392 return QUICK;
4393 }
4394
4395 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4396 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4397 return UNLOADED;
4398 }
4399
4400 // !!! Here's how the symmetry requirement breaks down into invariants:
4401 // If we split one up & one down AND they subtype, take the down man.
4402 // If we split one up & one down AND they do NOT subtype, "fall hard".
4403 // If both are up and they subtype, take the subtype class.
4404 // If both are up and they do NOT subtype, "fall hard".
4405 // If both are down and they subtype, take the supertype class.
4406 // If both are down and they do NOT subtype, "fall hard".
4407 // Constants treated as down.
4408
4409 // Now, reorder the above list; observe that both-down+subtype is also
4410 // "fall hard"; "fall hard" becomes the default case:
4411 // If we split one up & one down AND they subtype, take the down man.
4412 // If both are up and they subtype, take the subtype class.
4413
4414 // If both are down and they subtype, "fall hard".
4415 // If both are down and they do NOT subtype, "fall hard".
4416 // If both are up and they do NOT subtype, "fall hard".
4417 // If we split one up & one down AND they do NOT subtype, "fall hard".
4418
4419 // If a proper subtype is exact, and we return it, we return it exactly.
4420 // If a proper supertype is exact, there can be no subtyping relationship!
4421 // If both types are equal to the subtype, exactness is and-ed below the
4422 // centerline and or-ed above it. (N.B. Constants are always exact.)
4423
4424 // Check for subtyping:
4425 const T* subtype = nullptr;
4426 bool subtype_exact = false;
4427 if (this_type->is_same_java_type_as(other_type)) {
4428 subtype = this_type;
4429 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4430 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4431 subtype = this_type; // Pick subtyping class
4432 subtype_exact = this_xk;
4433 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4434 subtype = other_type; // Pick subtyping class
4435 subtype_exact = other_xk;
4436 }
4437
4438 if (subtype) {
4439 if (above_centerline(ptr)) { // both are up?
4440 this_type = other_type = subtype;
4441 this_xk = other_xk = subtype_exact;
4442 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4443 this_type = other_type; // tinst is down; keep down man
4444 this_xk = other_xk;
4445 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4446 other_type = this_type; // this is down; keep down man
4447 other_xk = this_xk;
4448 } else {
4449 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4450 }
4451 }
4452
4453 // Check for classes now being equal
4454 if (this_type->is_same_java_type_as(other_type)) {
4455 // If the klasses are equal, the constants may still differ. Fall to
4456 // NotNull if they do (neither constant is null; that is a special case
4457 // handled elsewhere).
4458 res_klass = this_type->klass();
4459 res_xk = this_xk;
4460 return SUBTYPE;
4461 } // Else classes are not equal
4462
4463 // Since klasses are different, we require a LCA in the Java
4464 // class hierarchy - which means we have to fall to at least NotNull.
4465 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4466 ptr = NotNull;
4467 }
4468
4469 interfaces = this_interfaces->intersection_with(other_interfaces);
4470
4471 // Now we find the LCA of Java classes
4472 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4473
4474 res_klass = k;
4475 res_xk = false;
4476
4477 return LCA;
4478 }
4479
4480 //------------------------java_mirror_type--------------------------------------
4481 ciType* TypeInstPtr::java_mirror_type() const {
4482 // must be a singleton type
4483 if( const_oop() == nullptr ) return nullptr;
4484
4485 // must be of type java.lang.Class
4486 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4487
4488 return const_oop()->as_instance()->java_mirror_type();
4489 }
4490
4491
4492 //------------------------------xdual------------------------------------------
4493 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4494 // inheritance mechanism.
4495 const Type *TypeInstPtr::xdual() const {
4496 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4497 }
4498
4499 //------------------------------eq---------------------------------------------
4500 // Structural equality check for Type representations
4501 bool TypeInstPtr::eq( const Type *t ) const {
4502 const TypeInstPtr *p = t->is_instptr();
4503 return
4504 klass()->equals(p->klass()) &&
4505 _interfaces->eq(p->_interfaces) &&
4506 TypeOopPtr::eq(p); // Check sub-type stuff
4507 }
4508
4509 //------------------------------hash-------------------------------------------
4510 // Type-specific hashing function.
4511 uint TypeInstPtr::hash(void) const {
4512 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4513 }
4514
4515 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4516 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4517 }
4518
4519
4520 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4521 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4522 }
4523
4524 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4525 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4526 }
4527
4528
4529 //------------------------------dump2------------------------------------------
4530 // Dump oop Type
4531 #ifndef PRODUCT
4532 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4546 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4547 char* buf = ss.as_string(/* c_heap= */false);
4548 StringUtils::replace_no_expand(buf, "\n", "");
4549 st->print_raw(buf);
4550 }
4551 case BotPTR:
4552 if (!WizardMode && !Verbose) {
4553 if( _klass_is_exact ) st->print(":exact");
4554 break;
4555 }
4556 case TopPTR:
4557 case AnyNull:
4558 case NotNull:
4559 st->print(":%s", ptr_msg[_ptr]);
4560 if( _klass_is_exact ) st->print(":exact");
4561 break;
4562 default:
4563 break;
4564 }
4565
4566 if( _offset ) { // Dump offset, if any
4567 if( _offset == OffsetBot ) st->print("+any");
4568 else if( _offset == OffsetTop ) st->print("+unknown");
4569 else st->print("+%d", _offset);
4570 }
4571
4572 st->print(" *");
4573 if (_instance_id == InstanceTop)
4574 st->print(",iid=top");
4575 else if (_instance_id != InstanceBot)
4576 st->print(",iid=%d",_instance_id);
4577
4578 dump_inline_depth(st);
4579 dump_speculative(st);
4580 }
4581 #endif
4582
4583 //------------------------------add_offset-------------------------------------
4584 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4585 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4586 _instance_id, add_offset_speculative(offset), _inline_depth);
4587 }
4588
4589 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4590 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4591 _instance_id, with_offset_speculative(offset), _inline_depth);
4592 }
4593
4594 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4595 if (_speculative == nullptr) {
4596 return this;
4597 }
4598 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4599 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4600 _instance_id, nullptr, _inline_depth);
4601 }
4602
4603 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4604 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4605 }
4606
4607 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4608 if (!UseInlineDepthForSpeculativeTypes) {
4609 return this;
4610 }
4611 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4612 }
4613
4614 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4615 assert(is_known_instance(), "should be known");
4616 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4617 }
4618
4619 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4620 bool xk = klass_is_exact();
4621 ciInstanceKlass* ik = klass()->as_instance_klass();
4622 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4623 if (_interfaces->eq(ik)) {
4624 Compile* C = Compile::current();
4625 Dependencies* deps = C->dependencies();
4626 deps->assert_leaf_type(ik);
4627 xk = true;
4628 }
4629 }
4630 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4631 }
4632
4633 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4634 static_assert(std::is_base_of<T2, T1>::value, "");
4635
4636 if (!this_one->is_instance_type(other)) {
4637 return false;
4638 }
4639
4640 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4641 return true;
4642 }
4643
4644 return this_one->klass()->is_subtype_of(other->klass()) &&
4645 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4646 }
4647
4648
4649 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4650 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4655 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4656 return true;
4657 }
4658
4659 if (this_one->is_instance_type(other)) {
4660 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4661 }
4662
4663 int dummy;
4664 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4665 if (this_top_or_bottom) {
4666 return false;
4667 }
4668
4669 const T1* other_ary = this_one->is_array_type(other);
4670 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4671 const TypePtr* this_elem = this_one->elem()->make_ptr();
4672 if (other_elem != nullptr && this_elem != nullptr) {
4673 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4674 }
4675
4676 if (other_elem == nullptr && this_elem == nullptr) {
4677 return this_one->klass()->is_subtype_of(other->klass());
4678 }
4679
4680 return false;
4681 }
4682
4683 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4684 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4685 }
4686
4687 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4688 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4689 }
4690
4691 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4692 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4693 }
4694
4695 //=============================================================================
4696 // Convenience common pre-built types.
4697 const TypeAryPtr *TypeAryPtr::RANGE;
4698 const TypeAryPtr *TypeAryPtr::OOPS;
4699 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4700 const TypeAryPtr *TypeAryPtr::BYTES;
4701 const TypeAryPtr *TypeAryPtr::SHORTS;
4702 const TypeAryPtr *TypeAryPtr::CHARS;
4703 const TypeAryPtr *TypeAryPtr::INTS;
4704 const TypeAryPtr *TypeAryPtr::LONGS;
4705 const TypeAryPtr *TypeAryPtr::FLOATS;
4706 const TypeAryPtr *TypeAryPtr::DOUBLES;
4707
4708 //------------------------------make-------------------------------------------
4709 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4710 int instance_id, const TypePtr* speculative, int inline_depth) {
4711 assert(!(k == nullptr && ary->_elem->isa_int()),
4712 "integral arrays must be pre-equipped with a class");
4713 if (!xk) xk = ary->ary_must_be_exact();
4714 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4715 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4716 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4717 k = nullptr;
4718 }
4719 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4720 }
4721
4722 //------------------------------make-------------------------------------------
4723 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4724 int instance_id, const TypePtr* speculative, int inline_depth,
4725 bool is_autobox_cache) {
4726 assert(!(k == nullptr && ary->_elem->isa_int()),
4727 "integral arrays must be pre-equipped with a class");
4728 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4729 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4730 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4731 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4732 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4733 k = nullptr;
4734 }
4735 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4736 }
4737
4738 //------------------------------cast_to_ptr_type-------------------------------
4739 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4740 if( ptr == _ptr ) return this;
4741 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4742 }
4743
4744
4745 //-----------------------------cast_to_exactness-------------------------------
4746 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4747 if( klass_is_exact == _klass_is_exact ) return this;
4748 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4749 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4750 }
4751
4752 //-----------------------------cast_to_instance_id----------------------------
4753 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4754 if( instance_id == _instance_id ) return this;
4755 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4756 }
4757
4758
4759 //-----------------------------max_array_length-------------------------------
4760 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4761 jint TypeAryPtr::max_array_length(BasicType etype) {
4762 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4763 if (etype == T_NARROWOOP) {
4764 etype = T_OBJECT;
4765 } else if (etype == T_ILLEGAL) { // bottom[]
4766 etype = T_BYTE; // will produce conservatively high value
4767 } else {
4768 fatal("not an element type: %s", type2name(etype));
4769 }
4770 }
4771 return arrayOopDesc::max_array_length(etype);
4772 }
4773
4774 //-----------------------------narrow_size_type-------------------------------
4775 // Narrow the given size type to the index range for the given array base type.
4791 if (hi > max_hi) {
4792 hi = max_hi;
4793 if (size->is_con()) {
4794 lo = hi;
4795 }
4796 chg = true;
4797 }
4798 // Negative length arrays will produce weird intermediate dead fast-path code
4799 if (lo > hi)
4800 return TypeInt::ZERO;
4801 if (!chg)
4802 return size;
4803 return TypeInt::make(lo, hi, Type::WidenMin);
4804 }
4805
4806 //-------------------------------cast_to_size----------------------------------
4807 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4808 assert(new_size != nullptr, "");
4809 new_size = narrow_size_type(new_size);
4810 if (new_size == size()) return this;
4811 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4812 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4813 }
4814
4815 //------------------------------cast_to_stable---------------------------------
4816 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4817 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4818 return this;
4819
4820 const Type* elem = this->elem();
4821 const TypePtr* elem_ptr = elem->make_ptr();
4822
4823 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4824 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4825 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4826 }
4827
4828 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4829
4830 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4831 }
4832
4833 //-----------------------------stable_dimension--------------------------------
4834 int TypeAryPtr::stable_dimension() const {
4835 if (!is_stable()) return 0;
4836 int dim = 1;
4837 const TypePtr* elem_ptr = elem()->make_ptr();
4838 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4839 dim += elem_ptr->is_aryptr()->stable_dimension();
4840 return dim;
4841 }
4842
4843 //----------------------cast_to_autobox_cache-----------------------------------
4844 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4845 if (is_autobox_cache()) return this;
4846 const TypeOopPtr* etype = elem()->make_oopptr();
4847 if (etype == nullptr) return this;
4848 // The pointers in the autobox arrays are always non-null.
4849 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4850 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4851 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4852 }
4853
4854 //------------------------------eq---------------------------------------------
4855 // Structural equality check for Type representations
4856 bool TypeAryPtr::eq( const Type *t ) const {
4857 const TypeAryPtr *p = t->is_aryptr();
4858 return
4859 _ary == p->_ary && // Check array
4860 TypeOopPtr::eq(p); // Check sub-parts
4861 }
4862
4863 //------------------------------hash-------------------------------------------
4864 // Type-specific hashing function.
4865 uint TypeAryPtr::hash(void) const {
4866 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4867 }
4868
4869 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4870 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4871 }
4872
4873 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4874 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4875 }
4876
4877 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4878 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4879 }
4880 //------------------------------meet-------------------------------------------
4881 // Compute the MEET of two types. It returns a new Type object.
4882 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4883 // Perform a fast test for common case; meeting the same types together.
4884 if( this == t ) return this; // Meeting same type-rep?
4885 // Current "this->_base" is Pointer
4886 switch (t->base()) { // switch on original type
4890 case Long:
4891 case FloatTop:
4892 case FloatCon:
4893 case FloatBot:
4894 case DoubleTop:
4895 case DoubleCon:
4896 case DoubleBot:
4897 case NarrowOop:
4898 case NarrowKlass:
4899 case Bottom: // Ye Olde Default
4900 return Type::BOTTOM;
4901 case Top:
4902 return this;
4903
4904 default: // All else is a mistake
4905 typerr(t);
4906
4907 case OopPtr: { // Meeting to OopPtrs
4908 // Found a OopPtr type vs self-AryPtr type
4909 const TypeOopPtr *tp = t->is_oopptr();
4910 int offset = meet_offset(tp->offset());
4911 PTR ptr = meet_ptr(tp->ptr());
4912 int depth = meet_inline_depth(tp->inline_depth());
4913 const TypePtr* speculative = xmeet_speculative(tp);
4914 switch (tp->ptr()) {
4915 case TopPTR:
4916 case AnyNull: {
4917 int instance_id = meet_instance_id(InstanceTop);
4918 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4919 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4920 }
4921 case BotPTR:
4922 case NotNull: {
4923 int instance_id = meet_instance_id(tp->instance_id());
4924 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4925 }
4926 default: ShouldNotReachHere();
4927 }
4928 }
4929
4930 case AnyPtr: { // Meeting two AnyPtrs
4931 // Found an AnyPtr type vs self-AryPtr type
4932 const TypePtr *tp = t->is_ptr();
4933 int offset = meet_offset(tp->offset());
4934 PTR ptr = meet_ptr(tp->ptr());
4935 const TypePtr* speculative = xmeet_speculative(tp);
4936 int depth = meet_inline_depth(tp->inline_depth());
4937 switch (tp->ptr()) {
4938 case TopPTR:
4939 return this;
4940 case BotPTR:
4941 case NotNull:
4942 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4943 case Null:
4944 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4945 // else fall through to AnyNull
4946 case AnyNull: {
4947 int instance_id = meet_instance_id(InstanceTop);
4948 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4949 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4950 }
4951 default: ShouldNotReachHere();
4952 }
4953 }
4954
4955 case MetadataPtr:
4956 case KlassPtr:
4957 case InstKlassPtr:
4958 case AryKlassPtr:
4959 case RawPtr: return TypePtr::BOTTOM;
4960
4961 case AryPtr: { // Meeting 2 references?
4962 const TypeAryPtr *tap = t->is_aryptr();
4963 int off = meet_offset(tap->offset());
4964 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4965 PTR ptr = meet_ptr(tap->ptr());
4966 int instance_id = meet_instance_id(tap->instance_id());
4967 const TypePtr* speculative = xmeet_speculative(tap);
4968 int depth = meet_inline_depth(tap->inline_depth());
4969
4970 ciKlass* res_klass = nullptr;
4971 bool res_xk = false;
4972 const Type* elem = tary->_elem;
4973 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4974 instance_id = InstanceBot;
4975 }
4976
4977 ciObject* o = nullptr; // Assume not constant when done
4978 ciObject* this_oop = const_oop();
4979 ciObject* tap_oop = tap->const_oop();
4980 if (ptr == Constant) {
4981 if (this_oop != nullptr && tap_oop != nullptr &&
4982 this_oop->equals(tap_oop)) {
4983 o = tap_oop;
4984 } else if (above_centerline(_ptr)) {
4985 o = tap_oop;
4986 } else if (above_centerline(tap->_ptr)) {
4987 o = this_oop;
4988 } else {
4989 ptr = NotNull;
4990 }
4991 }
4992 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4993 }
4994
4995 // All arrays inherit from Object class
4996 case InstPtr: {
4997 const TypeInstPtr *tp = t->is_instptr();
4998 int offset = meet_offset(tp->offset());
4999 PTR ptr = meet_ptr(tp->ptr());
5000 int instance_id = meet_instance_id(tp->instance_id());
5001 const TypePtr* speculative = xmeet_speculative(tp);
5002 int depth = meet_inline_depth(tp->inline_depth());
5003 const TypeInterfaces* interfaces = meet_interfaces(tp);
5004 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5005 const TypeInterfaces* this_interfaces = _interfaces;
5006
5007 switch (ptr) {
5008 case TopPTR:
5009 case AnyNull: // Fall 'down' to dual of object klass
5010 // For instances when a subclass meets a superclass we fall
5011 // below the centerline when the superclass is exact. We need to
5012 // do the same here.
5013 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5014 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5015 } else {
5016 // cannot subclass, so the meet has to fall badly below the centerline
5017 ptr = NotNull;
5018 instance_id = InstanceBot;
5019 interfaces = this_interfaces->intersection_with(tp_interfaces);
5020 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5021 }
5022 case Constant:
5023 case NotNull:
5024 case BotPTR: // Fall down to object klass
5025 // LCA is object_klass, but if we subclass from the top we can do better
5026 if (above_centerline(tp->ptr())) {
5027 // If 'tp' is above the centerline and it is Object class
5028 // then we can subclass in the Java class hierarchy.
5029 // For instances when a subclass meets a superclass we fall
5030 // below the centerline when the superclass is exact. We need
5031 // to do the same here.
5032 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5033 // that is, my array type is a subtype of 'tp' klass
5034 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5035 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5036 }
5037 }
5038 // The other case cannot happen, since t cannot be a subtype of an array.
5039 // The meet falls down to Object class below centerline.
5040 if (ptr == Constant) {
5041 ptr = NotNull;
5042 }
5043 if (instance_id > 0) {
5044 instance_id = InstanceBot;
5045 }
5046 interfaces = this_interfaces->intersection_with(tp_interfaces);
5047 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5048 default: typerr(t);
5049 }
5050 }
5051 }
5052 return this; // Lint noise
5053 }
5054
5055
5056 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5057 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5058 int dummy;
5059 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5060 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5061 ciKlass* this_klass = this_ary->klass();
5062 ciKlass* other_klass = other_ary->klass();
5063 bool this_xk = this_ary->klass_is_exact();
5064 bool other_xk = other_ary->klass_is_exact();
5065 PTR this_ptr = this_ary->ptr();
5066 PTR other_ptr = other_ary->ptr();
5067 res_klass = nullptr;
5068 MeetResult result = SUBTYPE;
5069 if (elem->isa_int()) {
5070 // Integral array element types have irrelevant lattice relations.
5071 // It is the klass that determines array layout, not the element type.
5072 if (this_top_or_bottom)
5073 res_klass = other_klass;
5074 else if (other_top_or_bottom || other_klass == this_klass) {
5075 res_klass = this_klass;
5076 } else {
5077 // Something like byte[int+] meets char[int+].
5078 // This must fall to bottom, not (int[-128..65535])[int+].
5079 // instance_id = InstanceBot;
5080 elem = Type::BOTTOM;
5081 result = NOT_SUBTYPE;
5082 if (above_centerline(ptr) || ptr == Constant) {
5083 ptr = NotNull;
5084 res_xk = false;
5085 return NOT_SUBTYPE;
5086 }
5087 }
5088 } else {// Non integral arrays.
5089 // Must fall to bottom if exact klasses in upper lattice
5090 // are not equal or super klass is exact.
5091 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5092 // meet with top[] and bottom[] are processed further down:
5093 !this_top_or_bottom && !other_top_or_bottom &&
5094 // both are exact and not equal:
5096 // 'tap' is exact and super or unrelated:
5097 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5098 // 'this' is exact and super or unrelated:
5099 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5100 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5101 elem = Type::BOTTOM;
5102 }
5103 ptr = NotNull;
5104 res_xk = false;
5105 return NOT_SUBTYPE;
5106 }
5107 }
5108
5109 res_xk = false;
5110 switch (other_ptr) {
5111 case AnyNull:
5112 case TopPTR:
5113 // Compute new klass on demand, do not use tap->_klass
5114 if (below_centerline(this_ptr)) {
5115 res_xk = this_xk;
5116 } else {
5117 res_xk = (other_xk || this_xk);
5118 }
5119 return result;
5120 case Constant: {
5121 if (this_ptr == Constant) {
5122 res_xk = true;
5123 } else if(above_centerline(this_ptr)) {
5124 res_xk = true;
5125 } else {
5126 // Only precise for identical arrays
5127 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5128 }
5129 return result;
5130 }
5131 case NotNull:
5132 case BotPTR:
5133 // Compute new klass on demand, do not use tap->_klass
5134 if (above_centerline(this_ptr)) {
5135 res_xk = other_xk;
5136 } else {
5137 res_xk = (other_xk && this_xk) &&
5138 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5139 }
5140 return result;
5141 default: {
5142 ShouldNotReachHere();
5143 return result;
5144 }
5145 }
5146 return result;
5147 }
5148
5149
5150 //------------------------------xdual------------------------------------------
5151 // Dual: compute field-by-field dual
5152 const Type *TypeAryPtr::xdual() const {
5153 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5154 }
5155
5156 //------------------------------dump2------------------------------------------
5157 #ifndef PRODUCT
5158 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5159 _ary->dump2(d,depth,st);
5160 _interfaces->dump(st);
5161
5162 switch( _ptr ) {
5163 case Constant:
5164 const_oop()->print(st);
5165 break;
5166 case BotPTR:
5167 if (!WizardMode && !Verbose) {
5168 if( _klass_is_exact ) st->print(":exact");
5169 break;
5170 }
5171 case TopPTR:
5172 case AnyNull:
5173 case NotNull:
5174 st->print(":%s", ptr_msg[_ptr]);
5175 if( _klass_is_exact ) st->print(":exact");
5176 break;
5177 default:
5178 break;
5179 }
5180
5181 if( _offset != 0 ) {
5182 BasicType basic_elem_type = elem()->basic_type();
5183 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5184 if( _offset == OffsetTop ) st->print("+undefined");
5185 else if( _offset == OffsetBot ) st->print("+any");
5186 else if( _offset < header_size ) st->print("+%d", _offset);
5187 else {
5188 if (basic_elem_type == T_ILLEGAL) {
5189 st->print("+any");
5190 } else {
5191 int elem_size = type2aelembytes(basic_elem_type);
5192 st->print("[%d]", (_offset - header_size)/elem_size);
5193 }
5194 }
5195 }
5196 st->print(" *");
5197 if (_instance_id == InstanceTop)
5198 st->print(",iid=top");
5199 else if (_instance_id != InstanceBot)
5200 st->print(",iid=%d",_instance_id);
5201
5202 dump_inline_depth(st);
5203 dump_speculative(st);
5204 }
5205 #endif
5206
5207 bool TypeAryPtr::empty(void) const {
5208 if (_ary->empty()) return true;
5209 return TypeOopPtr::empty();
5210 }
5211
5212 //------------------------------add_offset-------------------------------------
5213 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5214 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5215 }
5216
5217 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5218 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5219 }
5220
5221 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5222 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5223 }
5224
5225 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5226 if (_speculative == nullptr) {
5227 return this;
5228 }
5229 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5230 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5231 }
5232
5233 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5234 if (!UseInlineDepthForSpeculativeTypes) {
5235 return this;
5236 }
5237 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5238 }
5239
5240 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5241 assert(is_known_instance(), "should be known");
5242 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5243 }
5244
5245 //=============================================================================
5246
5247 //------------------------------hash-------------------------------------------
5248 // Type-specific hashing function.
5249 uint TypeNarrowPtr::hash(void) const {
5250 return _ptrtype->hash() + 7;
5251 }
5252
5253 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5254 return _ptrtype->singleton();
5255 }
5256
5257 bool TypeNarrowPtr::empty(void) const {
5258 return _ptrtype->empty();
5259 }
5260
5261 intptr_t TypeNarrowPtr::get_con() const {
5262 return _ptrtype->get_con();
5263 }
5264
5265 bool TypeNarrowPtr::eq( const Type *t ) const {
5266 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5317
5318 case Int: // Mixing ints & oops happens when javac
5319 case Long: // reuses local variables
5320 case FloatTop:
5321 case FloatCon:
5322 case FloatBot:
5323 case DoubleTop:
5324 case DoubleCon:
5325 case DoubleBot:
5326 case AnyPtr:
5327 case RawPtr:
5328 case OopPtr:
5329 case InstPtr:
5330 case AryPtr:
5331 case MetadataPtr:
5332 case KlassPtr:
5333 case InstKlassPtr:
5334 case AryKlassPtr:
5335 case NarrowOop:
5336 case NarrowKlass:
5337
5338 case Bottom: // Ye Olde Default
5339 return Type::BOTTOM;
5340 case Top:
5341 return this;
5342
5343 default: // All else is a mistake
5344 typerr(t);
5345
5346 } // End of switch
5347
5348 return this;
5349 }
5350
5351 #ifndef PRODUCT
5352 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5353 _ptrtype->dump2(d, depth, st);
5354 }
5355 #endif
5356
5357 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5401 return (one == two) && TypePtr::eq(t);
5402 } else {
5403 return one->equals(two) && TypePtr::eq(t);
5404 }
5405 }
5406
5407 //------------------------------hash-------------------------------------------
5408 // Type-specific hashing function.
5409 uint TypeMetadataPtr::hash(void) const {
5410 return
5411 (metadata() ? metadata()->hash() : 0) +
5412 TypePtr::hash();
5413 }
5414
5415 //------------------------------singleton--------------------------------------
5416 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5417 // constants
5418 bool TypeMetadataPtr::singleton(void) const {
5419 // detune optimizer to not generate constant metadata + constant offset as a constant!
5420 // TopPTR, Null, AnyNull, Constant are all singletons
5421 return (_offset == 0) && !below_centerline(_ptr);
5422 }
5423
5424 //------------------------------add_offset-------------------------------------
5425 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5426 return make( _ptr, _metadata, xadd_offset(offset));
5427 }
5428
5429 //-----------------------------filter------------------------------------------
5430 // Do not allow interface-vs.-noninterface joins to collapse to top.
5431 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5432 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5433 if (ft == nullptr || ft->empty())
5434 return Type::TOP; // Canonical empty value
5435 return ft;
5436 }
5437
5438 //------------------------------get_con----------------------------------------
5439 intptr_t TypeMetadataPtr::get_con() const {
5440 assert( _ptr == Null || _ptr == Constant, "" );
5441 assert( _offset >= 0, "" );
5442
5443 if (_offset != 0) {
5444 // After being ported to the compiler interface, the compiler no longer
5445 // directly manipulates the addresses of oops. Rather, it only has a pointer
5446 // to a handle at compile time. This handle is embedded in the generated
5447 // code and dereferenced at the time the nmethod is made. Until that time,
5448 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5449 // have access to the addresses!). This does not seem to currently happen,
5450 // but this assertion here is to help prevent its occurrence.
5451 tty->print_cr("Found oop constant with non-zero offset");
5452 ShouldNotReachHere();
5453 }
5454
5455 return (intptr_t)metadata()->constant_encoding();
5456 }
5457
5458 //------------------------------cast_to_ptr_type-------------------------------
5459 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5460 if( ptr == _ptr ) return this;
5461 return make(ptr, metadata(), _offset);
5462 }
5463
5474 case Long: // reuses local variables
5475 case FloatTop:
5476 case FloatCon:
5477 case FloatBot:
5478 case DoubleTop:
5479 case DoubleCon:
5480 case DoubleBot:
5481 case NarrowOop:
5482 case NarrowKlass:
5483 case Bottom: // Ye Olde Default
5484 return Type::BOTTOM;
5485 case Top:
5486 return this;
5487
5488 default: // All else is a mistake
5489 typerr(t);
5490
5491 case AnyPtr: {
5492 // Found an AnyPtr type vs self-OopPtr type
5493 const TypePtr *tp = t->is_ptr();
5494 int offset = meet_offset(tp->offset());
5495 PTR ptr = meet_ptr(tp->ptr());
5496 switch (tp->ptr()) {
5497 case Null:
5498 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5499 // else fall through:
5500 case TopPTR:
5501 case AnyNull: {
5502 return make(ptr, _metadata, offset);
5503 }
5504 case BotPTR:
5505 case NotNull:
5506 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5507 default: typerr(t);
5508 }
5509 }
5510
5511 case RawPtr:
5512 case KlassPtr:
5513 case InstKlassPtr:
5514 case AryKlassPtr:
5515 case OopPtr:
5516 case InstPtr:
5517 case AryPtr:
5518 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5519
5520 case MetadataPtr: {
5521 const TypeMetadataPtr *tp = t->is_metadataptr();
5522 int offset = meet_offset(tp->offset());
5523 PTR tptr = tp->ptr();
5524 PTR ptr = meet_ptr(tptr);
5525 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5526 if (tptr == TopPTR || _ptr == TopPTR ||
5527 metadata()->equals(tp->metadata())) {
5528 return make(ptr, md, offset);
5529 }
5530 // metadata is different
5531 if( ptr == Constant ) { // Cannot be equal constants, so...
5532 if( tptr == Constant && _ptr != Constant) return t;
5533 if( _ptr == Constant && tptr != Constant) return this;
5534 ptr = NotNull; // Fall down in lattice
5535 }
5536 return make(ptr, nullptr, offset);
5537 break;
5538 }
5539 } // End of switch
5540 return this; // Return the double constant
5541 }
5542
5543
5544 //------------------------------xdual------------------------------------------
5545 // Dual of a pure metadata pointer.
5546 const Type *TypeMetadataPtr::xdual() const {
5547 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5548 }
5549
5550 //------------------------------dump2------------------------------------------
5551 #ifndef PRODUCT
5552 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5553 st->print("metadataptr:%s", ptr_msg[_ptr]);
5554 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5555 switch( _offset ) {
5556 case OffsetTop: st->print("+top"); break;
5557 case OffsetBot: st->print("+any"); break;
5558 case 0: break;
5559 default: st->print("+%d",_offset); break;
5560 }
5561 }
5562 #endif
5563
5564
5565 //=============================================================================
5566 // Convenience common pre-built type.
5567 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5568
5569 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5570 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5571 }
5572
5573 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5574 return make(Constant, m, 0);
5575 }
5576 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5577 return make(Constant, m, 0);
5578 }
5579
5580 //------------------------------make-------------------------------------------
5581 // Create a meta data constant
5582 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5583 assert(m == nullptr || !m->is_klass(), "wrong type");
5584 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5585 }
5586
5587
5588 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5589 const Type* elem = _ary->_elem;
5590 bool xk = klass_is_exact();
5591 if (elem->make_oopptr() != nullptr) {
5592 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5593 if (elem->is_klassptr()->klass_is_exact()) {
5594 xk = true;
5595 }
5596 }
5597 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5598 }
5599
5600 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5601 if (klass->is_instance_klass()) {
5602 return TypeInstKlassPtr::make(klass, interface_handling);
5603 }
5604 return TypeAryKlassPtr::make(klass, interface_handling);
5605 }
5606
5607 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5608 if (klass->is_instance_klass()) {
5609 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5610 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5611 }
5612 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5613 }
5614
5615
5616 //------------------------------TypeKlassPtr-----------------------------------
5617 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5618 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5619 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5620 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5621 }
5622
5623 // Is there a single ciKlass* that can represent that type?
5624 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5625 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5626 if (_interfaces->empty()) {
5627 return _klass;
5628 }
5629 if (_klass != ciEnv::current()->Object_klass()) {
5630 if (_interfaces->eq(_klass->as_instance_klass())) {
5631 return _klass;
5632 }
5633 return nullptr;
5634 }
5635 return _interfaces->exact_klass();
5636 }
5637
5638 //------------------------------eq---------------------------------------------
5639 // Structural equality check for Type representations
5640 bool TypeKlassPtr::eq(const Type *t) const {
5641 const TypeKlassPtr *p = t->is_klassptr();
5642 return
5643 _interfaces->eq(p->_interfaces) &&
5644 TypePtr::eq(p);
5645 }
5646
5647 //------------------------------hash-------------------------------------------
5648 // Type-specific hashing function.
5649 uint TypeKlassPtr::hash(void) const {
5650 return TypePtr::hash() + _interfaces->hash();
5651 }
5652
5653 //------------------------------singleton--------------------------------------
5654 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5655 // constants
5656 bool TypeKlassPtr::singleton(void) const {
5657 // detune optimizer to not generate constant klass + constant offset as a constant!
5658 // TopPTR, Null, AnyNull, Constant are all singletons
5659 return (_offset == 0) && !below_centerline(_ptr);
5660 }
5661
5662 // Do not allow interface-vs.-noninterface joins to collapse to top.
5663 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5664 // logic here mirrors the one from TypeOopPtr::filter. See comments
5665 // there.
5666 const Type* ft = join_helper(kills, include_speculative);
5667 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5668 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5669
5670 if (ft->empty()) {
5671 return Type::TOP; // Canonical empty value
5672 }
5673
5674 return ft;
5675 }
5676
5677 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5678 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5679 return _interfaces->union_with(other->_interfaces);
5680 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5681 return other->_interfaces;
5682 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5683 return _interfaces;
5684 }
5685 return _interfaces->intersection_with(other->_interfaces);
5686 }
5687
5688 //------------------------------get_con----------------------------------------
5689 intptr_t TypeKlassPtr::get_con() const {
5690 assert( _ptr == Null || _ptr == Constant, "" );
5691 assert( _offset >= 0, "" );
5692
5693 if (_offset != 0) {
5694 // After being ported to the compiler interface, the compiler no longer
5695 // directly manipulates the addresses of oops. Rather, it only has a pointer
5696 // to a handle at compile time. This handle is embedded in the generated
5697 // code and dereferenced at the time the nmethod is made. Until that time,
5698 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5699 // have access to the addresses!). This does not seem to currently happen,
5700 // but this assertion here is to help prevent its occurrence.
5701 tty->print_cr("Found oop constant with non-zero offset");
5702 ShouldNotReachHere();
5703 }
5704
5705 ciKlass* k = exact_klass();
5706
5707 return (intptr_t)k->constant_encoding();
5708 }
5709
5710 //------------------------------dump2------------------------------------------
5711 // Dump Klass Type
5712 #ifndef PRODUCT
5713 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5717 case NotNull:
5718 {
5719 const char *name = klass()->name()->as_utf8();
5720 if (name) {
5721 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5722 } else {
5723 ShouldNotReachHere();
5724 }
5725 _interfaces->dump(st);
5726 }
5727 case BotPTR:
5728 if (!WizardMode && !Verbose && _ptr != Constant) break;
5729 case TopPTR:
5730 case AnyNull:
5731 st->print(":%s", ptr_msg[_ptr]);
5732 if (_ptr == Constant) st->print(":exact");
5733 break;
5734 default:
5735 break;
5736 }
5737
5738 if (_offset) { // Dump offset, if any
5739 if (_offset == OffsetBot) { st->print("+any"); }
5740 else if (_offset == OffsetTop) { st->print("+unknown"); }
5741 else { st->print("+%d", _offset); }
5742 }
5743
5744 st->print(" *");
5745 }
5746 #endif
5747
5748 //=============================================================================
5749 // Convenience common pre-built types.
5750
5751 // Not-null object klass or below
5752 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5753 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5754
5755 bool TypeInstKlassPtr::eq(const Type *t) const {
5756 const TypeKlassPtr *p = t->is_klassptr();
5757 return
5758 klass()->equals(p->klass()) &&
5759 TypeKlassPtr::eq(p);
5760 }
5761
5762 uint TypeInstKlassPtr::hash(void) const {
5763 return klass()->hash() + TypeKlassPtr::hash();
5764 }
5765
5766 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5767 TypeInstKlassPtr *r =
5768 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5769
5770 return r;
5771 }
5772
5773 //------------------------------add_offset-------------------------------------
5774 // Access internals of klass object
5775 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5776 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5777 }
5778
5779 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5780 return make(_ptr, klass(), _interfaces, offset);
5781 }
5782
5783 //------------------------------cast_to_ptr_type-------------------------------
5784 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5785 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5786 if( ptr == _ptr ) return this;
5787 return make(ptr, _klass, _interfaces, _offset);
5788 }
5789
5790
5791 bool TypeInstKlassPtr::must_be_exact() const {
5792 if (!_klass->is_loaded()) return false;
5793 ciInstanceKlass* ik = _klass->as_instance_klass();
5794 if (ik->is_final()) return true; // cannot clear xk
5795 return false;
5796 }
5797
5798 //-----------------------------cast_to_exactness-------------------------------
5799 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5800 if (klass_is_exact == (_ptr == Constant)) return this;
5801 if (must_be_exact()) return this;
5802 ciKlass* k = klass();
5803 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5804 }
5805
5806
5807 //-----------------------------as_instance_type--------------------------------
5808 // Corresponding type for an instance of the given class.
5809 // It will be NotNull, and exact if and only if the klass type is exact.
5810 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5811 ciKlass* k = klass();
5812 bool xk = klass_is_exact();
5813 Compile* C = Compile::current();
5814 Dependencies* deps = C->dependencies();
5815 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5816 // Element is an instance
5817 bool klass_is_exact = false;
5818 const TypeInterfaces* interfaces = _interfaces;
5819 if (k->is_loaded()) {
5820 // Try to set klass_is_exact.
5821 ciInstanceKlass* ik = k->as_instance_klass();
5822 klass_is_exact = ik->is_final();
5823 if (!klass_is_exact && klass_change
5824 && deps != nullptr && UseUniqueSubclasses) {
5825 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5826 if (sub != nullptr) {
5827 if (_interfaces->eq(sub)) {
5828 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5829 k = ik = sub;
5830 xk = sub->is_final();
5831 }
5832 }
5833 }
5834 }
5835 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5836 }
5837
5838 //------------------------------xmeet------------------------------------------
5839 // Compute the MEET of two types, return a new Type object.
5840 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5841 // Perform a fast test for common case; meeting the same types together.
5842 if( this == t ) return this; // Meeting same type-rep?
5843
5844 // Current "this->_base" is Pointer
5845 switch (t->base()) { // switch on original type
5846
5847 case Int: // Mixing ints & oops happens when javac
5848 case Long: // reuses local variables
5849 case FloatTop:
5850 case FloatCon:
5851 case FloatBot:
5852 case DoubleTop:
5853 case DoubleCon:
5854 case DoubleBot:
5855 case NarrowOop:
5856 case NarrowKlass:
5857 case Bottom: // Ye Olde Default
5858 return Type::BOTTOM;
5859 case Top:
5860 return this;
5861
5862 default: // All else is a mistake
5863 typerr(t);
5864
5865 case AnyPtr: { // Meeting to AnyPtrs
5866 // Found an AnyPtr type vs self-KlassPtr type
5867 const TypePtr *tp = t->is_ptr();
5868 int offset = meet_offset(tp->offset());
5869 PTR ptr = meet_ptr(tp->ptr());
5870 switch (tp->ptr()) {
5871 case TopPTR:
5872 return this;
5873 case Null:
5874 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5875 case AnyNull:
5876 return make( ptr, klass(), _interfaces, offset );
5877 case BotPTR:
5878 case NotNull:
5879 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5880 default: typerr(t);
5881 }
5882 }
5883
5884 case RawPtr:
5885 case MetadataPtr:
5886 case OopPtr:
5887 case AryPtr: // Meet with AryPtr
5888 case InstPtr: // Meet with InstPtr
5889 return TypePtr::BOTTOM;
5890
5891 //
5892 // A-top }
5893 // / | \ } Tops
5894 // B-top A-any C-top }
5895 // | / | \ | } Any-nulls
5896 // B-any | C-any }
5897 // | | |
5898 // B-con A-con C-con } constants; not comparable across classes
5899 // | | |
5900 // B-not | C-not }
5901 // | \ | / | } not-nulls
5902 // B-bot A-not C-bot }
5903 // \ | / } Bottoms
5904 // A-bot }
5905 //
5906
5907 case InstKlassPtr: { // Meet two KlassPtr types
5908 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5909 int off = meet_offset(tkls->offset());
5910 PTR ptr = meet_ptr(tkls->ptr());
5911 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5912
5913 ciKlass* res_klass = nullptr;
5914 bool res_xk = false;
5915 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5916 case UNLOADED:
5917 ShouldNotReachHere();
5918 case SUBTYPE:
5919 case NOT_SUBTYPE:
5920 case LCA:
5921 case QUICK: {
5922 assert(res_xk == (ptr == Constant), "");
5923 const Type* res = make(ptr, res_klass, interfaces, off);
5924 return res;
5925 }
5926 default:
5927 ShouldNotReachHere();
5928 }
5929 } // End of case KlassPtr
5930 case AryKlassPtr: { // All arrays inherit from Object class
5931 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5932 int offset = meet_offset(tp->offset());
5933 PTR ptr = meet_ptr(tp->ptr());
5934 const TypeInterfaces* interfaces = meet_interfaces(tp);
5935 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5936 const TypeInterfaces* this_interfaces = _interfaces;
5937
5938 switch (ptr) {
5939 case TopPTR:
5940 case AnyNull: // Fall 'down' to dual of object klass
5941 // For instances when a subclass meets a superclass we fall
5942 // below the centerline when the superclass is exact. We need to
5943 // do the same here.
5944 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5945 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5946 } else {
5947 // cannot subclass, so the meet has to fall badly below the centerline
5948 ptr = NotNull;
5949 interfaces = _interfaces->intersection_with(tp->_interfaces);
5950 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5951 }
5952 case Constant:
5953 case NotNull:
5954 case BotPTR: // Fall down to object klass
5955 // LCA is object_klass, but if we subclass from the top we can do better
5956 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5957 // If 'this' (InstPtr) is above the centerline and it is Object class
5958 // then we can subclass in the Java class hierarchy.
5959 // For instances when a subclass meets a superclass we fall
5960 // below the centerline when the superclass is exact. We need
5961 // to do the same here.
5962 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5963 // that is, tp's array type is a subtype of my klass
5964 return TypeAryKlassPtr::make(ptr,
5965 tp->elem(), tp->klass(), offset);
5966 }
5967 }
5968 // The other case cannot happen, since I cannot be a subtype of an array.
5969 // The meet falls down to Object class below centerline.
5970 if( ptr == Constant )
5971 ptr = NotNull;
5972 interfaces = this_interfaces->intersection_with(tp_interfaces);
5973 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5974 default: typerr(t);
5975 }
5976 }
5977
5978 } // End of switch
5979 return this; // Return the double constant
5980 }
5981
5982 //------------------------------xdual------------------------------------------
5983 // Dual: compute field-by-field dual
5984 const Type *TypeInstKlassPtr::xdual() const {
5985 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5986 }
5987
5988 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
5989 static_assert(std::is_base_of<T2, T1>::value, "");
5990 if (!this_one->is_loaded() || !other->is_loaded()) {
5991 return false;
5992 }
5993 if (!this_one->is_instance_type(other)) {
5994 return false;
5995 }
5996
5997 if (!other_exact) {
5998 return false;
5999 }
6000
6001 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6002 return true;
6003 }
6004
6005 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6066 const TypeInterfaces* interfaces = _interfaces;
6067 if (k->is_loaded()) {
6068 ciInstanceKlass* ik = k->as_instance_klass();
6069 bool klass_is_exact = ik->is_final();
6070 if (!klass_is_exact &&
6071 deps != nullptr) {
6072 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6073 if (sub != nullptr) {
6074 if (_interfaces->eq(sub)) {
6075 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6076 k = ik = sub;
6077 klass_is_exact = sub->is_final();
6078 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6079 }
6080 }
6081 }
6082 }
6083 return this;
6084 }
6085
6086
6087 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6088 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6089 }
6090
6091 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6092 if (k->is_obj_array_klass()) {
6093 // Element is an object array. Recursively call ourself.
6094 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6095 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6096 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6097 } else if (k->is_type_array_klass()) {
6098 // Element is an typeArray
6099 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6100 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6101 } else {
6102 ShouldNotReachHere();
6103 return nullptr;
6104 }
6105 }
6106
6107 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6108 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6109 }
6110
6111 //------------------------------eq---------------------------------------------
6112 // Structural equality check for Type representations
6113 bool TypeAryKlassPtr::eq(const Type *t) const {
6114 const TypeAryKlassPtr *p = t->is_aryklassptr();
6115 return
6116 _elem == p->_elem && // Check array
6117 TypeKlassPtr::eq(p); // Check sub-parts
6118 }
6119
6120 //------------------------------hash-------------------------------------------
6121 // Type-specific hashing function.
6122 uint TypeAryKlassPtr::hash(void) const {
6123 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6124 }
6125
6126 //----------------------compute_klass------------------------------------------
6127 // Compute the defining klass for this class
6128 ciKlass* TypeAryPtr::compute_klass() const {
6129 // Compute _klass based on element type.
6130 ciKlass* k_ary = nullptr;
6131 const TypeInstPtr *tinst;
6132 const TypeAryPtr *tary;
6133 const Type* el = elem();
6134 if (el->isa_narrowoop()) {
6135 el = el->make_ptr();
6136 }
6137
6138 // Get element klass
6139 if ((tinst = el->isa_instptr()) != nullptr) {
6140 // Leave k_ary at null.
6141 } else if ((tary = el->isa_aryptr()) != nullptr) {
6142 // Leave k_ary at null.
6143 } else if ((el->base() == Type::Top) ||
6144 (el->base() == Type::Bottom)) {
6145 // element type of Bottom occurs from meet of basic type
6146 // and object; Top occurs when doing join on Bottom.
6147 // Leave k_ary at null.
6148 } else {
6149 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6150 // Compute array klass directly from basic type
6151 k_ary = ciTypeArrayKlass::make(el->basic_type());
6152 }
6153 return k_ary;
6154 }
6155
6156 //------------------------------klass------------------------------------------
6157 // Return the defining klass for this class
6158 ciKlass* TypeAryPtr::klass() const {
6159 if( _klass ) return _klass; // Return cached value, if possible
6160
6161 // Oops, need to compute _klass and cache it
6162 ciKlass* k_ary = compute_klass();
6170 // type TypeAryPtr::OOPS. This Type is shared between all
6171 // active compilations. However, the ciKlass which represents
6172 // this Type is *not* shared between compilations, so caching
6173 // this value would result in fetching a dangling pointer.
6174 //
6175 // Recomputing the underlying ciKlass for each request is
6176 // a bit less efficient than caching, but calls to
6177 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6178 ((TypeAryPtr*)this)->_klass = k_ary;
6179 }
6180 return k_ary;
6181 }
6182
6183 // Is there a single ciKlass* that can represent that type?
6184 ciKlass* TypeAryPtr::exact_klass_helper() const {
6185 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6186 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6187 if (k == nullptr) {
6188 return nullptr;
6189 }
6190 k = ciObjArrayKlass::make(k);
6191 return k;
6192 }
6193
6194 return klass();
6195 }
6196
6197 const Type* TypeAryPtr::base_element_type(int& dims) const {
6198 const Type* elem = this->elem();
6199 dims = 1;
6200 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6201 elem = elem->make_ptr()->is_aryptr()->elem();
6202 dims++;
6203 }
6204 return elem;
6205 }
6206
6207 //------------------------------add_offset-------------------------------------
6208 // Access internals of klass object
6209 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6210 return make(_ptr, elem(), klass(), xadd_offset(offset));
6211 }
6212
6213 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6214 return make(_ptr, elem(), klass(), offset);
6215 }
6216
6217 //------------------------------cast_to_ptr_type-------------------------------
6218 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6219 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6220 if (ptr == _ptr) return this;
6221 return make(ptr, elem(), _klass, _offset);
6222 }
6223
6224 bool TypeAryKlassPtr::must_be_exact() const {
6225 if (_elem == Type::BOTTOM) return false;
6226 if (_elem == Type::TOP ) return false;
6227 const TypeKlassPtr* tk = _elem->isa_klassptr();
6228 if (!tk) return true; // a primitive type, like int
6229 return tk->must_be_exact();
6230 }
6231
6232
6233 //-----------------------------cast_to_exactness-------------------------------
6234 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6235 if (must_be_exact()) return this; // cannot clear xk
6236 ciKlass* k = _klass;
6237 const Type* elem = this->elem();
6238 if (elem->isa_klassptr() && !klass_is_exact) {
6239 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6240 }
6241 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6242 }
6243
6244
6245 //-----------------------------as_instance_type--------------------------------
6246 // Corresponding type for an instance of the given class.
6247 // It will be NotNull, and exact if and only if the klass type is exact.
6248 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6249 ciKlass* k = klass();
6250 bool xk = klass_is_exact();
6251 const Type* el = nullptr;
6252 if (elem()->isa_klassptr()) {
6253 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6254 k = nullptr;
6255 } else {
6256 el = elem();
6257 }
6258 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6259 }
6260
6261
6262 //------------------------------xmeet------------------------------------------
6263 // Compute the MEET of two types, return a new Type object.
6264 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6265 // Perform a fast test for common case; meeting the same types together.
6266 if( this == t ) return this; // Meeting same type-rep?
6267
6268 // Current "this->_base" is Pointer
6269 switch (t->base()) { // switch on original type
6270
6271 case Int: // Mixing ints & oops happens when javac
6272 case Long: // reuses local variables
6273 case FloatTop:
6274 case FloatCon:
6275 case FloatBot:
6276 case DoubleTop:
6277 case DoubleCon:
6278 case DoubleBot:
6279 case NarrowOop:
6280 case NarrowKlass:
6281 case Bottom: // Ye Olde Default
6282 return Type::BOTTOM;
6283 case Top:
6284 return this;
6285
6286 default: // All else is a mistake
6287 typerr(t);
6288
6289 case AnyPtr: { // Meeting to AnyPtrs
6290 // Found an AnyPtr type vs self-KlassPtr type
6291 const TypePtr *tp = t->is_ptr();
6292 int offset = meet_offset(tp->offset());
6293 PTR ptr = meet_ptr(tp->ptr());
6294 switch (tp->ptr()) {
6295 case TopPTR:
6296 return this;
6297 case Null:
6298 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6299 case AnyNull:
6300 return make( ptr, _elem, klass(), offset );
6301 case BotPTR:
6302 case NotNull:
6303 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6304 default: typerr(t);
6305 }
6306 }
6307
6308 case RawPtr:
6309 case MetadataPtr:
6310 case OopPtr:
6311 case AryPtr: // Meet with AryPtr
6312 case InstPtr: // Meet with InstPtr
6313 return TypePtr::BOTTOM;
6314
6315 //
6316 // A-top }
6317 // / | \ } Tops
6318 // B-top A-any C-top }
6319 // | / | \ | } Any-nulls
6320 // B-any | C-any }
6321 // | | |
6322 // B-con A-con C-con } constants; not comparable across classes
6323 // | | |
6324 // B-not | C-not }
6325 // | \ | / | } not-nulls
6326 // B-bot A-not C-bot }
6327 // \ | / } Bottoms
6328 // A-bot }
6329 //
6330
6331 case AryKlassPtr: { // Meet two KlassPtr types
6332 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6333 int off = meet_offset(tap->offset());
6334 const Type* elem = _elem->meet(tap->_elem);
6335
6336 PTR ptr = meet_ptr(tap->ptr());
6337 ciKlass* res_klass = nullptr;
6338 bool res_xk = false;
6339 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6340 assert(res_xk == (ptr == Constant), "");
6341 return make(ptr, elem, res_klass, off);
6342 } // End of case KlassPtr
6343 case InstKlassPtr: {
6344 const TypeInstKlassPtr *tp = t->is_instklassptr();
6345 int offset = meet_offset(tp->offset());
6346 PTR ptr = meet_ptr(tp->ptr());
6347 const TypeInterfaces* interfaces = meet_interfaces(tp);
6348 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6349 const TypeInterfaces* this_interfaces = _interfaces;
6350
6351 switch (ptr) {
6352 case TopPTR:
6353 case AnyNull: // Fall 'down' to dual of object klass
6354 // For instances when a subclass meets a superclass we fall
6355 // below the centerline when the superclass is exact. We need to
6356 // do the same here.
6357 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6358 !tp->klass_is_exact()) {
6359 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6360 } else {
6361 // cannot subclass, so the meet has to fall badly below the centerline
6362 ptr = NotNull;
6363 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6364 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6365 }
6366 case Constant:
6367 case NotNull:
6368 case BotPTR: // Fall down to object klass
6369 // LCA is object_klass, but if we subclass from the top we can do better
6370 if (above_centerline(tp->ptr())) {
6371 // If 'tp' is above the centerline and it is Object class
6372 // then we can subclass in the Java class hierarchy.
6373 // For instances when a subclass meets a superclass we fall
6374 // below the centerline when the superclass is exact. We need
6375 // to do the same here.
6376 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6377 !tp->klass_is_exact()) {
6378 // that is, my array type is a subtype of 'tp' klass
6379 return make(ptr, _elem, _klass, offset);
6380 }
6381 }
6382 // The other case cannot happen, since t cannot be a subtype of an array.
6383 // The meet falls down to Object class below centerline.
6384 if (ptr == Constant)
6385 ptr = NotNull;
6386 interfaces = this_interfaces->intersection_with(tp_interfaces);
6387 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6388 default: typerr(t);
6389 }
6390 }
6391
6392 } // End of switch
6393 return this; // Return the double constant
6394 }
6395
6396 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6397 static_assert(std::is_base_of<T2, T1>::value, "");
6398
6399 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6400 return true;
6401 }
6402
6403 int dummy;
6404 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6405
6406 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6407 return false;
6408 }
6409
6410 if (this_one->is_instance_type(other)) {
6411 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6412 other_exact;
6413 }
6414
6415 assert(this_one->is_array_type(other), "");
6416 const T1* other_ary = this_one->is_array_type(other);
6417 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6418 if (other_top_or_bottom) {
6419 return false;
6420 }
6421
6422 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6423 const TypePtr* this_elem = this_one->elem()->make_ptr();
6424 if (this_elem != nullptr && other_elem != nullptr) {
6425 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6426 }
6427 if (this_elem == nullptr && other_elem == nullptr) {
6428 return this_one->klass()->is_subtype_of(other->klass());
6429 }
6430 return false;
6431 }
6432
6433 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6434 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6435 }
6436
6437 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6438 static_assert(std::is_base_of<T2, T1>::value, "");
6439
6440 int dummy;
6441 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6442
6443 if (!this_one->is_array_type(other) ||
6444 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6497 }
6498
6499 const TypePtr* this_elem = this_one->elem()->make_ptr();
6500 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6501 if (other_elem != nullptr && this_elem != nullptr) {
6502 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6503 }
6504 if (other_elem == nullptr && this_elem == nullptr) {
6505 return this_one->klass()->is_subtype_of(other->klass());
6506 }
6507 return false;
6508 }
6509
6510 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6511 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6512 }
6513
6514 //------------------------------xdual------------------------------------------
6515 // Dual: compute field-by-field dual
6516 const Type *TypeAryKlassPtr::xdual() const {
6517 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6518 }
6519
6520 // Is there a single ciKlass* that can represent that type?
6521 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6522 if (elem()->isa_klassptr()) {
6523 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6524 if (k == nullptr) {
6525 return nullptr;
6526 }
6527 k = ciObjArrayKlass::make(k);
6528 return k;
6529 }
6530
6531 return klass();
6532 }
6533
6534 ciKlass* TypeAryKlassPtr::klass() const {
6535 if (_klass != nullptr) {
6536 return _klass;
6537 }
6538 ciKlass* k = nullptr;
6539 if (elem()->isa_klassptr()) {
6540 // leave null
6541 } else if ((elem()->base() == Type::Top) ||
6542 (elem()->base() == Type::Bottom)) {
6543 } else {
6544 k = ciTypeArrayKlass::make(elem()->basic_type());
6545 ((TypeAryKlassPtr*)this)->_klass = k;
6546 }
6547 return k;
6554 switch( _ptr ) {
6555 case Constant:
6556 st->print("precise ");
6557 case NotNull:
6558 {
6559 st->print("[");
6560 _elem->dump2(d, depth, st);
6561 _interfaces->dump(st);
6562 st->print(": ");
6563 }
6564 case BotPTR:
6565 if( !WizardMode && !Verbose && _ptr != Constant ) break;
6566 case TopPTR:
6567 case AnyNull:
6568 st->print(":%s", ptr_msg[_ptr]);
6569 if( _ptr == Constant ) st->print(":exact");
6570 break;
6571 default:
6572 break;
6573 }
6574
6575 if( _offset ) { // Dump offset, if any
6576 if( _offset == OffsetBot ) { st->print("+any"); }
6577 else if( _offset == OffsetTop ) { st->print("+unknown"); }
6578 else { st->print("+%d", _offset); }
6579 }
6580
6581 st->print(" *");
6582 }
6583 #endif
6584
6585 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6586 const Type* elem = this->elem();
6587 dims = 1;
6588 while (elem->isa_aryklassptr()) {
6589 elem = elem->is_aryklassptr()->elem();
6590 dims++;
6591 }
6592 return elem;
6593 }
6594
6595 //=============================================================================
6596 // Convenience common pre-built types.
6597
6598 //------------------------------make-------------------------------------------
6599 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6600 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6601 }
6602
6603 //------------------------------make-------------------------------------------
6604 const TypeFunc *TypeFunc::make(ciMethod* method) {
6605 Compile* C = Compile::current();
6606 const TypeFunc* tf = C->last_tf(method); // check cache
6607 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6608 const TypeTuple *domain;
6609 if (method->is_static()) {
6610 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6611 } else {
6612 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6613 }
6614 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6615 tf = TypeFunc::make(domain, range);
6616 C->set_last_tf(method, tf); // fill cache
6617 return tf;
6618 }
6619
6620 //------------------------------meet-------------------------------------------
6621 // Compute the MEET of two types. It returns a new Type object.
6622 const Type *TypeFunc::xmeet( const Type *t ) const {
6623 // Perform a fast test for common case; meeting the same types together.
6624 if( this == t ) return this; // Meeting same type-rep?
6625
6626 // Current "this->_base" is Func
6627 switch (t->base()) { // switch on original type
6628
6629 case Bottom: // Ye Olde Default
6630 return t;
6631
6632 default: // All else is a mistake
6633 typerr(t);
6634
6635 case Top:
6636 break;
6637 }
6638 return this; // Return the double constant
6639 }
6640
6641 //------------------------------xdual------------------------------------------
6642 // Dual: compute field-by-field dual
6643 const Type *TypeFunc::xdual() const {
6644 return this;
6645 }
6646
6647 //------------------------------eq---------------------------------------------
6648 // Structural equality check for Type representations
6649 bool TypeFunc::eq( const Type *t ) const {
6650 const TypeFunc *a = (const TypeFunc*)t;
6651 return _domain == a->_domain &&
6652 _range == a->_range;
6653 }
6654
6655 //------------------------------hash-------------------------------------------
6656 // Type-specific hashing function.
6657 uint TypeFunc::hash(void) const {
6658 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6659 }
6660
6661 //------------------------------dump2------------------------------------------
6662 // Dump Function Type
6663 #ifndef PRODUCT
6664 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6665 if( _range->cnt() <= Parms )
6666 st->print("void");
6667 else {
6668 uint i;
6669 for (i = Parms; i < _range->cnt()-1; i++) {
6670 _range->field_at(i)->dump2(d,depth,st);
6671 st->print("/");
6672 }
6673 _range->field_at(i)->dump2(d,depth,st);
6674 }
6675 st->print(" ");
6676 st->print("( ");
6677 if( !depth || d[this] ) { // Check for recursive dump
6678 st->print("...)");
6679 return;
6680 }
6681 d.Insert((void*)this,(void*)this); // Stop recursion
6682 if (Parms < _domain->cnt())
6683 _domain->field_at(Parms)->dump2(d,depth-1,st);
6684 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6685 st->print(", ");
6686 _domain->field_at(i)->dump2(d,depth-1,st);
6687 }
6688 st->print(" )");
6689 }
6690 #endif
6691
6692 //------------------------------singleton--------------------------------------
6693 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6694 // constants (Ldi nodes). Singletons are integer, float or double constants
6695 // or a single symbol.
6696 bool TypeFunc::singleton(void) const {
6697 return false; // Never a singleton
6698 }
6699
6700 bool TypeFunc::empty(void) const {
6701 return false; // Never empty
6702 }
6703
6704
6705 BasicType TypeFunc::return_type() const{
6706 if (range()->cnt() == TypeFunc::Parms) {
6707 return T_VOID;
6708 }
6709 return range()->field_at(TypeFunc::Parms)->basic_type();
6710 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciFlatArrayKlass.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciMethodData.hpp"
30 #include "ci/ciTypeFlow.hpp"
31 #include "classfile/javaClasses.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "libadt/dict.hpp"
35 #include "memory/oopFactory.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/instanceMirrorKlass.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/typeArrayKlass.hpp"
41 #include "opto/matcher.hpp"
42 #include "opto/node.hpp"
43 #include "opto/opcodes.hpp"
44 #include "opto/type.hpp"
45 #include "utilities/checkedCast.hpp"
46 #include "utilities/powerOfTwo.hpp"
47 #include "utilities/stringUtils.hpp"
48
49 // Portions of code courtesy of Clifford Click
50
51 // Optimization - Graph Style
52
53 // Dictionary of types shared among compilations.
54 Dict* Type::_shared_type_dict = nullptr;
55 const Type::Offset Type::Offset::top(Type::OffsetTop);
56 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
57
58 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
59 // Either is 'TOP' offset? Return the other offset!
60 if (_offset == OffsetTop) return other;
61 if (other._offset == OffsetTop) return *this;
62 // If either is different, return 'BOTTOM' offset
63 if (_offset != other._offset) return bottom;
64 return Offset(_offset);
65 }
66
67 const Type::Offset Type::Offset::dual() const {
68 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
69 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
70 return Offset(_offset); // Map everything else into self
71 }
72
73 const Type::Offset Type::Offset::add(intptr_t offset) const {
74 // Adding to 'TOP' offset? Return 'TOP'!
75 if (_offset == OffsetTop || offset == OffsetTop) return top;
76 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
77 if (_offset == OffsetBot || offset == OffsetBot) return bottom;
78 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
79 offset += (intptr_t)_offset;
80 if (offset != (int)offset || offset == OffsetTop) return bottom;
81
82 // assert( _offset >= 0 && _offset+offset >= 0, "" );
83 // It is possible to construct a negative offset during PhaseCCP
84
85 return Offset((int)offset); // Sum valid offsets
86 }
87
88 void Type::Offset::dump2(outputStream *st) const {
89 if (_offset == 0) {
90 return;
91 } else if (_offset == OffsetTop) {
92 st->print("+top");
93 }
94 else if (_offset == OffsetBot) {
95 st->print("+bot");
96 } else if (_offset) {
97 st->print("+%d", _offset);
98 }
99 }
100
101 // Array which maps compiler types to Basic Types
102 const Type::TypeInfo Type::_type_info[Type::lastype] = {
103 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
104 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
105 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
106 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
107 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
108 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
109 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
110 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
111 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
112 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
113 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
114
115 #if defined(PPC64)
116 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
117 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
118 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
119 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
254 case ciTypeFlow::StateVector::T_NULL:
255 assert(type == ciTypeFlow::StateVector::null_type(), "");
256 return TypePtr::NULL_PTR;
257
258 case ciTypeFlow::StateVector::T_LONG2:
259 // The ciTypeFlow pass pushes a long, then the half.
260 // We do the same.
261 assert(type == ciTypeFlow::StateVector::long2_type(), "");
262 return TypeInt::TOP;
263
264 case ciTypeFlow::StateVector::T_DOUBLE2:
265 // The ciTypeFlow pass pushes double, then the half.
266 // Our convention is the same.
267 assert(type == ciTypeFlow::StateVector::double2_type(), "");
268 return Type::TOP;
269
270 case T_ADDRESS:
271 assert(type->is_return_address(), "");
272 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
273
274 case T_OBJECT:
275 return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
276
277 default:
278 // make sure we did not mix up the cases:
279 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
280 assert(type != ciTypeFlow::StateVector::top_type(), "");
281 assert(type != ciTypeFlow::StateVector::null_type(), "");
282 assert(type != ciTypeFlow::StateVector::long2_type(), "");
283 assert(type != ciTypeFlow::StateVector::double2_type(), "");
284 assert(!type->is_return_address(), "");
285
286 return Type::get_const_type(type);
287 }
288 }
289
290
291 //-----------------------make_from_constant------------------------------------
292 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
293 int stable_dimension, bool is_narrow_oop,
294 bool is_autobox_cache) {
295 switch (constant.basic_type()) {
296 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
569 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
570 ffalse[0] = Type::CONTROL;
571 ffalse[1] = Type::TOP;
572 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
573
574 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
575 fneither[0] = Type::TOP;
576 fneither[1] = Type::TOP;
577 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
578
579 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
580 ftrue[0] = Type::TOP;
581 ftrue[1] = Type::CONTROL;
582 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
583
584 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
585 floop[0] = Type::CONTROL;
586 floop[1] = TypeInt::INT;
587 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
588
589 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
590 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
591 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
592
593 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
594 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
595
596 const Type **fmembar = TypeTuple::fields(0);
597 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
598
599 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
600 fsc[0] = TypeInt::CC;
601 fsc[1] = Type::MEMORY;
602 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
603
604 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
605 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
606 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
607 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
608 false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
609 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
610 false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
611 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
612
613 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
614
615 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
616 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
617
618 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
619
620 mreg2type[Op_Node] = Type::BOTTOM;
621 mreg2type[Op_Set ] = nullptr;
622 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
623 mreg2type[Op_RegI] = TypeInt::INT;
624 mreg2type[Op_RegP] = TypePtr::BOTTOM;
625 mreg2type[Op_RegF] = Type::FLOAT;
626 mreg2type[Op_RegD] = Type::DOUBLE;
627 mreg2type[Op_RegL] = TypeLong::LONG;
628 mreg2type[Op_RegFlags] = TypeInt::CC;
629
630 GrowableArray<ciInstanceKlass*> array_interfaces;
631 array_interfaces.push(current->env()->Cloneable_klass());
632 array_interfaces.push(current->env()->Serializable_klass());
633 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
634 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
635
636 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
637
638 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
639
640 #ifdef _LP64
641 if (UseCompressedOops) {
642 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
643 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
644 } else
645 #endif
646 {
647 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
648 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
649 }
650 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom);
651 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom);
652 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom);
653 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Offset::bottom);
654 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom);
655 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom);
656 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom);
657 TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true), nullptr, false, Offset::bottom);
658
659 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
660 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
661 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
662 TypeAryPtr::_array_body_type[T_PRIMITIVE_OBJECT] = TypeAryPtr::OOPS;
663 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
664 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
665 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
666 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
667 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
668 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
669 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
670 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
671 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
672
673 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
674 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
675
676 const Type **fi2c = TypeTuple::fields(2);
677 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
678 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
679 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
680
681 const Type **intpair = TypeTuple::fields(2);
682 intpair[0] = TypeInt::INT;
683 intpair[1] = TypeInt::INT;
684 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
685
686 const Type **longpair = TypeTuple::fields(2);
687 longpair[0] = TypeLong::LONG;
688 longpair[1] = TypeLong::LONG;
689 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
690
691 const Type **intccpair = TypeTuple::fields(2);
692 intccpair[0] = TypeInt::INT;
693 intccpair[1] = TypeInt::CC;
694 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
695
696 const Type **longccpair = TypeTuple::fields(2);
697 longccpair[0] = TypeLong::LONG;
698 longccpair[1] = TypeInt::CC;
699 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
700
701 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
702 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
703 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
704 _const_basic_type[T_CHAR] = TypeInt::CHAR;
705 _const_basic_type[T_BYTE] = TypeInt::BYTE;
706 _const_basic_type[T_SHORT] = TypeInt::SHORT;
707 _const_basic_type[T_INT] = TypeInt::INT;
708 _const_basic_type[T_LONG] = TypeLong::LONG;
709 _const_basic_type[T_FLOAT] = Type::FLOAT;
710 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
711 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
712 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
713 _const_basic_type[T_PRIMITIVE_OBJECT] = TypeInstPtr::BOTTOM;
714 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
715 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
716 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
717
718 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
719 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
720 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
721 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
722 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
723 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
724 _zero_type[T_INT] = TypeInt::ZERO;
725 _zero_type[T_LONG] = TypeLong::ZERO;
726 _zero_type[T_FLOAT] = TypeF::ZERO;
727 _zero_type[T_DOUBLE] = TypeD::ZERO;
728 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
729 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
730 _zero_type[T_PRIMITIVE_OBJECT] = TypePtr::NULL_PTR;
731 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
732 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
733
734 // get_zero_type() should not happen for T_CONFLICT
735 _zero_type[T_CONFLICT]= nullptr;
736
737 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
738 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
739
740 if (Matcher::supports_scalable_vector()) {
741 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
742 }
743
744 // Vector predefined types, it needs initialized _const_basic_type[].
745 if (Matcher::vector_size_supported(T_BYTE,4)) {
746 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
747 }
748 if (Matcher::vector_size_supported(T_FLOAT,2)) {
749 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
750 }
981 ~VerifyMeet() {
982 assert(_C->_type_verify->_depth != 0, "");
983 _C->_type_verify->_depth--;
984 if (_C->_type_verify->_depth == 0) {
985 _C->_type_verify->_cache.trunc_to(0);
986 }
987 }
988
989 const Type* meet(const Type* t1, const Type* t2) const {
990 return _C->_type_verify->meet(t1, t2);
991 }
992
993 void add(const Type* t1, const Type* t2, const Type* res) const {
994 _C->_type_verify->add(t1, t2, res);
995 }
996 };
997
998 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
999 Compile* C = Compile::current();
1000 const Type* mt2 = verify.meet(t, this);
1001
1002 // Verify that:
1003 // this meet t == t meet this
1004 if (mt != mt2) {
1005 tty->print_cr("=== Meet Not Commutative ===");
1006 tty->print("t = "); t->dump(); tty->cr();
1007 tty->print("this = "); dump(); tty->cr();
1008 tty->print("t meet this = "); mt2->dump(); tty->cr();
1009 tty->print("this meet t = "); mt->dump(); tty->cr();
1010 fatal("meet not commutative");
1011 }
1012 const Type* dual_join = mt->_dual;
1013 const Type* t2t = verify.meet(dual_join,t->_dual);
1014 const Type* t2this = verify.meet(dual_join,this->_dual);
1015
1016 // Interface meet Oop is Not Symmetric:
1017 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1018 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1019
1020 // Verify that:
1021 // !(t meet this) meet !t ==
1022 // (!t join !this) meet !t == !t
1023 // and
1024 // !(t meet this) meet !this ==
1025 // (!t join !this) meet !this == !this
1026 if (t2t != t->_dual || t2this != this->_dual) {
1027 tty->print_cr("=== Meet Not Symmetric ===");
1028 tty->print("t = "); t->dump(); tty->cr();
1029 tty->print("this= "); dump(); tty->cr();
1030 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
1031
1032 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
1033 tty->print("this_dual= "); _dual->dump(); tty->cr();
1034 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
1035
1036 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1037 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1038
1039 fatal("meet not symmetric");
1040 }
1041 }
1042 #endif
1043
1044 //------------------------------meet-------------------------------------------
1045 // Compute the MEET of two types. NOT virtual. It enforces that meet is
2176
2177 bool TypeLong::empty(void) const {
2178 return _lo > _hi;
2179 }
2180
2181 //=============================================================================
2182 // Convenience common pre-built types.
2183 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2184 const TypeTuple *TypeTuple::IFFALSE;
2185 const TypeTuple *TypeTuple::IFTRUE;
2186 const TypeTuple *TypeTuple::IFNEITHER;
2187 const TypeTuple *TypeTuple::LOOPBODY;
2188 const TypeTuple *TypeTuple::MEMBAR;
2189 const TypeTuple *TypeTuple::STORECONDITIONAL;
2190 const TypeTuple *TypeTuple::START_I2C;
2191 const TypeTuple *TypeTuple::INT_PAIR;
2192 const TypeTuple *TypeTuple::LONG_PAIR;
2193 const TypeTuple *TypeTuple::INT_CC_PAIR;
2194 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2195
2196 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2197 for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2198 ciField* field = vk->nonstatic_field_at(j);
2199 BasicType bt = field->type()->basic_type();
2200 const Type* ft = Type::get_const_type(field->type());
2201 field_array[pos++] = ft;
2202 if (type2size[bt] == 2) {
2203 field_array[pos++] = Type::HALF;
2204 }
2205 }
2206 }
2207
2208 //------------------------------make-------------------------------------------
2209 // Make a TypeTuple from the range of a method signature
2210 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2211 ciType* return_type = sig->return_type();
2212 uint arg_cnt = return_type->size();
2213 if (ret_vt_fields) {
2214 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2215 // InlineTypeNode::IsInit field used for null checking
2216 arg_cnt++;
2217 }
2218 const Type **field_array = fields(arg_cnt);
2219 switch (return_type->basic_type()) {
2220 case T_LONG:
2221 field_array[TypeFunc::Parms] = TypeLong::LONG;
2222 field_array[TypeFunc::Parms+1] = Type::HALF;
2223 break;
2224 case T_DOUBLE:
2225 field_array[TypeFunc::Parms] = Type::DOUBLE;
2226 field_array[TypeFunc::Parms+1] = Type::HALF;
2227 break;
2228 case T_OBJECT:
2229 if (return_type->is_inlinetype() && ret_vt_fields) {
2230 uint pos = TypeFunc::Parms;
2231 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2232 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2233 // InlineTypeNode::IsInit field used for null checking
2234 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2235 break;
2236 } else {
2237 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2238 }
2239 break;
2240 case T_ARRAY:
2241 case T_BOOLEAN:
2242 case T_CHAR:
2243 case T_FLOAT:
2244 case T_BYTE:
2245 case T_SHORT:
2246 case T_INT:
2247 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2248 break;
2249 case T_VOID:
2250 break;
2251 default:
2252 ShouldNotReachHere();
2253 }
2254 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2255 }
2256
2257 // Make a TypeTuple from the domain of a method signature
2258 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2259 ciSignature* sig = method->signature();
2260 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2261 if (vt_fields_as_args) {
2262 arg_cnt = 0;
2263 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2264 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2265 arg_cnt += type2size[(*sig_cc)._bt];
2266 }
2267 }
2268
2269 uint pos = TypeFunc::Parms;
2270 const Type** field_array = fields(arg_cnt);
2271 if (!method->is_static()) {
2272 ciInstanceKlass* recv = method->holder();
2273 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2274 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2275 } else {
2276 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2277 }
2278 }
2279
2280 int i = 0;
2281 while (pos < TypeFunc::Parms + arg_cnt) {
2282 ciType* type = sig->type_at(i);
2283 BasicType bt = type->basic_type();
2284
2285 switch (bt) {
2286 case T_LONG:
2287 field_array[pos++] = TypeLong::LONG;
2288 field_array[pos++] = Type::HALF;
2289 break;
2290 case T_DOUBLE:
2291 field_array[pos++] = Type::DOUBLE;
2292 field_array[pos++] = Type::HALF;
2293 break;
2294 case T_OBJECT:
2295 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2296 // InlineTypeNode::IsInit field used for null checking
2297 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2298 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2299 } else {
2300 field_array[pos++] = get_const_type(type, interface_handling);
2301 }
2302 break;
2303 case T_ARRAY:
2304 case T_FLOAT:
2305 case T_INT:
2306 field_array[pos++] = get_const_type(type, interface_handling);
2307 break;
2308 case T_BOOLEAN:
2309 case T_CHAR:
2310 case T_BYTE:
2311 case T_SHORT:
2312 field_array[pos++] = TypeInt::INT;
2313 break;
2314 default:
2315 ShouldNotReachHere();
2316 }
2317 i++;
2318 }
2319 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2320
2321 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2322 }
2323
2324 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2325 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2326 }
2327
2328 //------------------------------fields-----------------------------------------
2329 // Subroutine call type with space allocated for argument types
2330 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2331 const Type **TypeTuple::fields( uint arg_cnt ) {
2332 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2333 flds[TypeFunc::Control ] = Type::CONTROL;
2334 flds[TypeFunc::I_O ] = Type::ABIO;
2335 flds[TypeFunc::Memory ] = Type::MEMORY;
2336 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2337 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2338
2339 return flds;
2434 if (_fields[i]->empty()) return true;
2435 }
2436 return false;
2437 }
2438
2439 //=============================================================================
2440 // Convenience common pre-built types.
2441
2442 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2443 // Certain normalizations keep us sane when comparing types.
2444 // We do not want arrayOop variables to differ only by the wideness
2445 // of their index types. Pick minimum wideness, since that is the
2446 // forced wideness of small ranges anyway.
2447 if (size->_widen != Type::WidenMin)
2448 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2449 else
2450 return size;
2451 }
2452
2453 //------------------------------make-------------------------------------------
2454 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2455 bool flat, bool not_flat, bool not_null_free) {
2456 if (UseCompressedOops && elem->isa_oopptr()) {
2457 elem = elem->make_narrowoop();
2458 }
2459 size = normalize_array_size(size);
2460 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2461 }
2462
2463 //------------------------------meet-------------------------------------------
2464 // Compute the MEET of two types. It returns a new Type object.
2465 const Type *TypeAry::xmeet( const Type *t ) const {
2466 // Perform a fast test for common case; meeting the same types together.
2467 if( this == t ) return this; // Meeting same type-rep?
2468
2469 // Current "this->_base" is Ary
2470 switch (t->base()) { // switch on original type
2471
2472 case Bottom: // Ye Olde Default
2473 return t;
2474
2475 default: // All else is a mistake
2476 typerr(t);
2477
2478 case Array: { // Meeting 2 arrays?
2479 const TypeAry *a = t->is_ary();
2480 return TypeAry::make(_elem->meet_speculative(a->_elem),
2481 _size->xmeet(a->_size)->is_int(),
2482 _stable && a->_stable,
2483 _flat && a->_flat,
2484 _not_flat && a->_not_flat,
2485 _not_null_free && a->_not_null_free);
2486 }
2487 case Top:
2488 break;
2489 }
2490 return this; // Return the double constant
2491 }
2492
2493 //------------------------------xdual------------------------------------------
2494 // Dual: compute field-by-field dual
2495 const Type *TypeAry::xdual() const {
2496 const TypeInt* size_dual = _size->dual()->is_int();
2497 size_dual = normalize_array_size(size_dual);
2498 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2499 }
2500
2501 //------------------------------eq---------------------------------------------
2502 // Structural equality check for Type representations
2503 bool TypeAry::eq( const Type *t ) const {
2504 const TypeAry *a = (const TypeAry*)t;
2505 return _elem == a->_elem &&
2506 _stable == a->_stable &&
2507 _size == a->_size &&
2508 _flat == a->_flat &&
2509 _not_flat == a->_not_flat &&
2510 _not_null_free == a->_not_null_free;
2511
2512 }
2513
2514 //------------------------------hash-------------------------------------------
2515 // Type-specific hashing function.
2516 uint TypeAry::hash(void) const {
2517 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2518 (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0);
2519 }
2520
2521 /**
2522 * Return same type without a speculative part in the element
2523 */
2524 const TypeAry* TypeAry::remove_speculative() const {
2525 return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2526 }
2527
2528 /**
2529 * Return same type with cleaned up speculative part of element
2530 */
2531 const Type* TypeAry::cleanup_speculative() const {
2532 return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2533 }
2534
2535 /**
2536 * Return same type but with a different inline depth (used for speculation)
2537 *
2538 * @param depth depth to meet with
2539 */
2540 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2541 if (!UseInlineDepthForSpeculativeTypes) {
2542 return this;
2543 }
2544 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2545 }
2546
2547 //------------------------------dump2------------------------------------------
2548 #ifndef PRODUCT
2549 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2550 if (_stable) st->print("stable:");
2551 if (_flat) st->print("flat:");
2552 if (Verbose) {
2553 if (_not_flat) st->print("not flat:");
2554 if (_not_null_free) st->print("not null free:");
2555 }
2556 _elem->dump2(d, depth, st);
2557 st->print("[");
2558 _size->dump2(d, depth, st);
2559 st->print("]");
2560 }
2561 #endif
2562
2563 //------------------------------singleton--------------------------------------
2564 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2565 // constants (Ldi nodes). Singletons are integer, float or double constants
2566 // or a single symbol.
2567 bool TypeAry::singleton(void) const {
2568 return false; // Never a singleton
2569 }
2570
2571 bool TypeAry::empty(void) const {
2572 return _elem->empty() || _size->empty();
2573 }
2574
2575 //--------------------------ary_must_be_exact----------------------------------
2576 bool TypeAry::ary_must_be_exact() const {
2577 // This logic looks at the element type of an array, and returns true
2578 // if the element type is either a primitive or a final instance class.
2579 // In such cases, an array built on this ary must have no subclasses.
2580 if (_elem == BOTTOM) return false; // general array not exact
2581 if (_elem == TOP ) return false; // inverted general array not exact
2582 const TypeOopPtr* toop = nullptr;
2583 if (UseCompressedOops && _elem->isa_narrowoop()) {
2584 toop = _elem->make_ptr()->isa_oopptr();
2585 } else {
2586 toop = _elem->isa_oopptr();
2587 }
2588 if (!toop) return true; // a primitive type, like int
2589 if (!toop->is_loaded()) return false; // unloaded class
2590 const TypeInstPtr* tinst;
2591 if (_elem->isa_narrowoop())
2592 tinst = _elem->make_ptr()->isa_instptr();
2593 else
2594 tinst = _elem->isa_instptr();
2595 if (tinst) {
2596 if (tinst->instance_klass()->is_final()) {
2597 // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
2598 if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2599 return false;
2600 }
2601 return true;
2602 }
2603 return false;
2604 }
2605 const TypeAryPtr* tap;
2606 if (_elem->isa_narrowoop())
2607 tap = _elem->make_ptr()->isa_aryptr();
2608 else
2609 tap = _elem->isa_aryptr();
2610 if (tap)
2611 return tap->ary()->ary_must_be_exact();
2612 return false;
2613 }
2614
2615 //==============================TypeVect=======================================
2616 // Convenience common pre-built types.
2617 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2618 const TypeVect *TypeVect::VECTS = nullptr; // 32-bit vectors
2619 const TypeVect *TypeVect::VECTD = nullptr; // 64-bit vectors
2620 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2621 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2622 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2623 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2624
2780
2781 //=============================================================================
2782 // Convenience common pre-built types.
2783 const TypePtr *TypePtr::NULL_PTR;
2784 const TypePtr *TypePtr::NOTNULL;
2785 const TypePtr *TypePtr::BOTTOM;
2786
2787 //------------------------------meet-------------------------------------------
2788 // Meet over the PTR enum
2789 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2790 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2791 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2792 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2793 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2794 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2795 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2796 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2797 };
2798
2799 //------------------------------make-------------------------------------------
2800 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2801 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2802 }
2803
2804 //------------------------------cast_to_ptr_type-------------------------------
2805 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2806 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2807 if( ptr == _ptr ) return this;
2808 return make(_base, ptr, _offset, _speculative, _inline_depth);
2809 }
2810
2811 //------------------------------get_con----------------------------------------
2812 intptr_t TypePtr::get_con() const {
2813 assert( _ptr == Null, "" );
2814 return offset();
2815 }
2816
2817 //------------------------------meet-------------------------------------------
2818 // Compute the MEET of two types. It returns a new Type object.
2819 const Type *TypePtr::xmeet(const Type *t) const {
2820 const Type* res = xmeet_helper(t);
2821 if (res->isa_ptr() == nullptr) {
2822 return res;
2823 }
2824
2825 const TypePtr* res_ptr = res->is_ptr();
2826 if (res_ptr->speculative() != nullptr) {
2827 // type->speculative() is null means that speculation is no better
2828 // than type, i.e. type->speculative() == type. So there are 2
2829 // ways to represent the fact that we have no useful speculative
2830 // data and we should use a single one to be able to test for
2831 // equality between types. Check whether type->speculative() ==
2832 // type and set speculative to null if it is the case.
2833 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2834 return res_ptr->remove_speculative();
2865 int depth = meet_inline_depth(tp->inline_depth());
2866 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2867 }
2868 case RawPtr: // For these, flip the call around to cut down
2869 case OopPtr:
2870 case InstPtr: // on the cases I have to handle.
2871 case AryPtr:
2872 case MetadataPtr:
2873 case KlassPtr:
2874 case InstKlassPtr:
2875 case AryKlassPtr:
2876 return t->xmeet(this); // Call in reverse direction
2877 default: // All else is a mistake
2878 typerr(t);
2879
2880 }
2881 return this;
2882 }
2883
2884 //------------------------------meet_offset------------------------------------
2885 Type::Offset TypePtr::meet_offset(int offset) const {
2886 return _offset.meet(Offset(offset));
2887 }
2888
2889 //------------------------------dual_offset------------------------------------
2890 Type::Offset TypePtr::dual_offset() const {
2891 return _offset.dual();
2892 }
2893
2894 //------------------------------xdual------------------------------------------
2895 // Dual: compute field-by-field dual
2896 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2897 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2898 };
2899 const Type *TypePtr::xdual() const {
2900 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2901 }
2902
2903 //------------------------------xadd_offset------------------------------------
2904 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2905 return _offset.add(offset);
2906 }
2907
2908 //------------------------------add_offset-------------------------------------
2909 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2910 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2911 }
2912
2913 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2914 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2915 }
2916
2917 //------------------------------eq---------------------------------------------
2918 // Structural equality check for Type representations
2919 bool TypePtr::eq( const Type *t ) const {
2920 const TypePtr *a = (const TypePtr*)t;
2921 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2922 }
2923
2924 //------------------------------hash-------------------------------------------
2925 // Type-specific hashing function.
2926 uint TypePtr::hash(void) const {
2927 return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2928 }
2929
2930 /**
2931 * Return same type without a speculative part
2932 */
2933 const TypePtr* TypePtr::remove_speculative() const {
2934 if (_speculative == nullptr) {
2935 return this;
2936 }
2937 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2938 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2939 }
2940
2941 /**
2942 * Return same type but drop speculative part if we know we won't use
2943 * it
2944 */
2945 const Type* TypePtr::cleanup_speculative() const {
2946 if (speculative() == nullptr) {
2947 return this;
3173 }
3174 // We already know the speculative type is always null
3175 if (speculative_always_null()) {
3176 return false;
3177 }
3178 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3179 return false;
3180 }
3181 return true;
3182 }
3183
3184 //------------------------------dump2------------------------------------------
3185 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3186 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3187 };
3188
3189 #ifndef PRODUCT
3190 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3191 if( _ptr == Null ) st->print("null");
3192 else st->print("%s *", ptr_msg[_ptr]);
3193 _offset.dump2(st);
3194 dump_inline_depth(st);
3195 dump_speculative(st);
3196 }
3197
3198 /**
3199 *dump the speculative part of the type
3200 */
3201 void TypePtr::dump_speculative(outputStream *st) const {
3202 if (_speculative != nullptr) {
3203 st->print(" (speculative=");
3204 _speculative->dump_on(st);
3205 st->print(")");
3206 }
3207 }
3208
3209 /**
3210 *dump the inline depth of the type
3211 */
3212 void TypePtr::dump_inline_depth(outputStream *st) const {
3213 if (_inline_depth != InlineDepthBottom) {
3214 if (_inline_depth == InlineDepthTop) {
3215 st->print(" (inline_depth=InlineDepthTop)");
3216 } else {
3217 st->print(" (inline_depth=%d)", _inline_depth);
3218 }
3219 }
3220 }
3221 #endif
3222
3223 //------------------------------singleton--------------------------------------
3224 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3225 // constants
3226 bool TypePtr::singleton(void) const {
3227 // TopPTR, Null, AnyNull, Constant are all singletons
3228 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3229 }
3230
3231 bool TypePtr::empty(void) const {
3232 return (_offset == Offset::top) || above_centerline(_ptr);
3233 }
3234
3235 //=============================================================================
3236 // Convenience common pre-built types.
3237 const TypeRawPtr *TypeRawPtr::BOTTOM;
3238 const TypeRawPtr *TypeRawPtr::NOTNULL;
3239
3240 //------------------------------make-------------------------------------------
3241 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3242 assert( ptr != Constant, "what is the constant?" );
3243 assert( ptr != Null, "Use TypePtr for null" );
3244 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3245 }
3246
3247 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3248 assert( bits, "Use TypePtr for null" );
3249 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3250 }
3251
3252 //------------------------------cast_to_ptr_type-------------------------------
3604 void TypeInterfaces::verify_is_loaded() const {
3605 for (int i = 0; i < _list.length(); i++) {
3606 ciKlass* interface = _list.at(i);
3607 assert(interface->is_loaded(), "Interface not loaded");
3608 }
3609 }
3610 #endif
3611
3612 // Can't be implemented because there's no way to know if the type is above or below the center line.
3613 const Type* TypeInterfaces::xmeet(const Type* t) const {
3614 ShouldNotReachHere();
3615 return Type::xmeet(t);
3616 }
3617
3618 bool TypeInterfaces::singleton(void) const {
3619 ShouldNotReachHere();
3620 return Type::singleton();
3621 }
3622
3623 //------------------------------TypeOopPtr-------------------------------------
3624 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3625 int instance_id, const TypePtr* speculative, int inline_depth)
3626 : TypePtr(t, ptr, offset, speculative, inline_depth),
3627 _const_oop(o), _klass(k),
3628 _interfaces(interfaces),
3629 _klass_is_exact(xk),
3630 _is_ptr_to_narrowoop(false),
3631 _is_ptr_to_narrowklass(false),
3632 _is_ptr_to_boxed_value(false),
3633 _instance_id(instance_id) {
3634 #ifdef ASSERT
3635 if (klass() != nullptr && klass()->is_loaded()) {
3636 interfaces->verify_is_loaded();
3637 }
3638 #endif
3639 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3640 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3641 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3642 }
3643 #ifdef _LP64
3644 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3645 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3646 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3647 } else if (klass() == nullptr) {
3648 // Array with unknown body type
3649 assert(this->isa_aryptr(), "only arrays without klass");
3650 _is_ptr_to_narrowoop = UseCompressedOops;
3651 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3652 if (klass()->is_obj_array_klass()) {
3653 _is_ptr_to_narrowoop = true;
3654 } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3655 // Check if the field of the inline type array element contains oops
3656 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3657 int foffset = field_offset.get() + vk->first_field_offset();
3658 ciField* field = vk->get_field_by_offset(foffset, false);
3659 assert(field != nullptr, "missing field");
3660 BasicType bt = field->layout_type();
3661 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3662 }
3663 } else if (klass()->is_instance_klass()) {
3664 if (this->isa_klassptr()) {
3665 // Perm objects don't use compressed references
3666 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3667 // unsafe access
3668 _is_ptr_to_narrowoop = UseCompressedOops;
3669 } else {
3670 assert(this->isa_instptr(), "must be an instance ptr.");
3671 if (klass() == ciEnv::current()->Class_klass() &&
3672 (this->offset() == java_lang_Class::klass_offset() ||
3673 this->offset() == java_lang_Class::array_klass_offset())) {
3674 // Special hidden fields from the Class.
3675 assert(this->isa_instptr(), "must be an instance ptr.");
3676 _is_ptr_to_narrowoop = false;
3677 } else if (klass() == ciEnv::current()->Class_klass() &&
3678 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3679 // Static fields
3680 ciField* field = nullptr;
3681 if (const_oop() != nullptr) {
3682 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3683 field = k->get_field_by_offset(this->offset(), true);
3684 }
3685 if (field != nullptr) {
3686 BasicType basic_elem_type = field->layout_type();
3687 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3688 } else {
3689 // unsafe access
3690 _is_ptr_to_narrowoop = UseCompressedOops;
3691 }
3692 } else {
3693 // Instance fields which contains a compressed oop references.
3694 ciInstanceKlass* ik = klass()->as_instance_klass();
3695 ciField* field = ik->get_field_by_offset(this->offset(), false);
3696 if (field != nullptr) {
3697 BasicType basic_elem_type = field->layout_type();
3698 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3699 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3700 // Compile::find_alias_type() cast exactness on all types to verify
3701 // that it does not affect alias type.
3702 _is_ptr_to_narrowoop = UseCompressedOops;
3703 } else {
3704 // Type for the copy start in LibraryCallKit::inline_native_clone().
3705 _is_ptr_to_narrowoop = UseCompressedOops;
3706 }
3707 }
3708 }
3709 }
3710 }
3711 #endif
3712 }
3713
3714 //------------------------------make-------------------------------------------
3715 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3716 const TypePtr* speculative, int inline_depth) {
3717 assert(ptr != Constant, "no constant generic pointers");
3718 ciKlass* k = Compile::current()->env()->Object_klass();
3719 bool xk = false;
3720 ciObject* o = nullptr;
3721 const TypeInterfaces* interfaces = TypeInterfaces::make();
3722 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3723 }
3724
3725
3726 //------------------------------cast_to_ptr_type-------------------------------
3727 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3728 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3729 if( ptr == _ptr ) return this;
3730 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3731 }
3732
3733 //-----------------------------cast_to_instance_id----------------------------
3734 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3735 // There are no instances of a general oop.
3736 // Return self unchanged.
3737 return this;
3738 }
3739
3740 //-----------------------------cast_to_exactness-------------------------------
3741 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3742 // There is no such thing as an exact general oop.
3743 // Return self unchanged.
3744 return this;
3745 }
3746
3747 //------------------------------as_klass_type----------------------------------
3748 // Return the klass type corresponding to this instance or array type.
3749 // It is the type that is loaded from an object of this type.
3750 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3751 ShouldNotReachHere();
3752 return nullptr;
3753 }
3754
3755 //------------------------------meet-------------------------------------------
3756 // Compute the MEET of two types. It returns a new Type object.
3757 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3758 // Perform a fast test for common case; meeting the same types together.
3759 if( this == t ) return this; // Meeting same type-rep?
3760
3761 // Current "this->_base" is OopPtr
3762 switch (t->base()) { // switch on original type
3763
3764 case Int: // Mixing ints & oops happens when javac
3765 case Long: // reuses local variables
3766 case FloatTop:
3772 case NarrowOop:
3773 case NarrowKlass:
3774 case Bottom: // Ye Olde Default
3775 return Type::BOTTOM;
3776 case Top:
3777 return this;
3778
3779 default: // All else is a mistake
3780 typerr(t);
3781
3782 case RawPtr:
3783 case MetadataPtr:
3784 case KlassPtr:
3785 case InstKlassPtr:
3786 case AryKlassPtr:
3787 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3788
3789 case AnyPtr: {
3790 // Found an AnyPtr type vs self-OopPtr type
3791 const TypePtr *tp = t->is_ptr();
3792 Offset offset = meet_offset(tp->offset());
3793 PTR ptr = meet_ptr(tp->ptr());
3794 const TypePtr* speculative = xmeet_speculative(tp);
3795 int depth = meet_inline_depth(tp->inline_depth());
3796 switch (tp->ptr()) {
3797 case Null:
3798 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3799 // else fall through:
3800 case TopPTR:
3801 case AnyNull: {
3802 int instance_id = meet_instance_id(InstanceTop);
3803 return make(ptr, offset, instance_id, speculative, depth);
3804 }
3805 case BotPTR:
3806 case NotNull:
3807 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3808 default: typerr(t);
3809 }
3810 }
3811
3812 case OopPtr: { // Meeting to other OopPtrs
3814 int instance_id = meet_instance_id(tp->instance_id());
3815 const TypePtr* speculative = xmeet_speculative(tp);
3816 int depth = meet_inline_depth(tp->inline_depth());
3817 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3818 }
3819
3820 case InstPtr: // For these, flip the call around to cut down
3821 case AryPtr:
3822 return t->xmeet(this); // Call in reverse direction
3823
3824 } // End of switch
3825 return this; // Return the double constant
3826 }
3827
3828
3829 //------------------------------xdual------------------------------------------
3830 // Dual of a pure heap pointer. No relevant klass or oop information.
3831 const Type *TypeOopPtr::xdual() const {
3832 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3833 assert(const_oop() == nullptr, "no constants here");
3834 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3835 }
3836
3837 //--------------------------make_from_klass_common-----------------------------
3838 // Computes the element-type given a klass.
3839 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3840 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3841 Compile* C = Compile::current();
3842 Dependencies* deps = C->dependencies();
3843 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3844 // Element is an instance
3845 bool klass_is_exact = false;
3846 if (klass->is_loaded()) {
3847 // Try to set klass_is_exact.
3848 ciInstanceKlass* ik = klass->as_instance_klass();
3849 klass_is_exact = ik->is_final();
3850 if (!klass_is_exact && klass_change
3851 && deps != nullptr && UseUniqueSubclasses) {
3852 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3853 if (sub != nullptr) {
3854 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3855 klass = ik = sub;
3856 klass_is_exact = sub->is_final();
3857 }
3858 }
3859 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3860 !ik->is_interface() && !ik->has_subklass()) {
3861 // Add a dependence; if concrete subclass added we need to recompile
3862 deps->assert_leaf_type(ik);
3863 klass_is_exact = true;
3864 }
3865 }
3866 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3867 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3868 } else if (klass->is_obj_array_klass()) {
3869 // Element is an object or inline type array. Recursively call ourself.
3870 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3871 // Determine null-free/flat properties
3872 const TypeOopPtr* exact_etype = etype;
3873 if (etype->can_be_inline_type()) {
3874 // Use exact type if element can be an inline type
3875 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3876 }
3877 bool not_null_free = !exact_etype->can_be_inline_type();
3878 bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
3879 // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
3880 bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
3881 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
3882 // We used to pass NotNull in here, asserting that the sub-arrays
3883 // are all not-null. This is not true in generally, as code can
3884 // slam nullptrs down in the subarrays.
3885 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3886 return arr;
3887 } else if (klass->is_type_array_klass()) {
3888 // Element is an typeArray
3889 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3890 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3891 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3892 // We used to pass NotNull in here, asserting that the array pointer
3893 // is not-null. That was not true in general.
3894 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3895 return arr;
3896 } else if (klass->is_flat_array_klass()) {
3897 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3898 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3899 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
3900 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3901 return arr;
3902 } else {
3903 ShouldNotReachHere();
3904 return nullptr;
3905 }
3906 }
3907
3908 //------------------------------make_from_constant-----------------------------
3909 // Make a java pointer from an oop constant
3910 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3911 assert(!o->is_null_object(), "null object not yet handled here.");
3912
3913 const bool make_constant = require_constant || o->should_be_constant();
3914
3915 ciKlass* klass = o->klass();
3916 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3917 // Element is an instance or inline type
3918 if (make_constant) {
3919 return TypeInstPtr::make(o);
3920 } else {
3921 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3922 }
3923 } else if (klass->is_obj_array_klass()) {
3924 // Element is an object array. Recursively call ourself.
3925 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3926 bool is_flat = o->as_obj_array()->is_flat();
3927 bool is_null_free = o->as_obj_array()->is_null_free();
3928 if (is_null_free) {
3929 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3930 }
3931 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3932 /* stable= */ false, /* flat= */ false, /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free);
3933 // We used to pass NotNull in here, asserting that the sub-arrays
3934 // are all not-null. This is not true in generally, as code can
3935 // slam nulls down in the subarrays.
3936 if (make_constant) {
3937 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3938 } else {
3939 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3940 }
3941 } else if (klass->is_type_array_klass()) {
3942 // Element is an typeArray
3943 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3944 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3945 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3946 // We used to pass NotNull in here, asserting that the array pointer
3947 // is not-null. That was not true in general.
3948 if (make_constant) {
3949 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3950 } else {
3951 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3952 }
3953 } else if (klass->is_flat_array_klass()) {
3954 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3955 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3956 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
3957 // We used to pass NotNull in here, asserting that the sub-arrays
3958 // are all not-null. This is not true in generally, as code can
3959 // slam nullptrs down in the subarrays.
3960 if (make_constant) {
3961 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3962 } else {
3963 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3964 }
3965 }
3966
3967 fatal("unhandled object type");
3968 return nullptr;
3969 }
3970
3971 //------------------------------get_con----------------------------------------
3972 intptr_t TypeOopPtr::get_con() const {
3973 assert( _ptr == Null || _ptr == Constant, "" );
3974 assert(offset() >= 0, "");
3975
3976 if (offset() != 0) {
3977 // After being ported to the compiler interface, the compiler no longer
3978 // directly manipulates the addresses of oops. Rather, it only has a pointer
3979 // to a handle at compile time. This handle is embedded in the generated
3980 // code and dereferenced at the time the nmethod is made. Until that time,
3981 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3982 // have access to the addresses!). This does not seem to currently happen,
3983 // but this assertion here is to help prevent its occurrence.
3984 tty->print_cr("Found oop constant with non-zero offset");
3985 ShouldNotReachHere();
3986 }
3987
3988 return (intptr_t)const_oop()->constant_encoding();
3989 }
3990
3991
3992 //-----------------------------filter------------------------------------------
3993 // Do not allow interface-vs.-noninterface joins to collapse to top.
3994 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3995
3996 const Type* ft = join_helper(kills, include_speculative);
4017 } else {
4018 return one->equals(two) && TypePtr::eq(t);
4019 }
4020 }
4021
4022 //------------------------------hash-------------------------------------------
4023 // Type-specific hashing function.
4024 uint TypeOopPtr::hash(void) const {
4025 return
4026 (uint)(const_oop() ? const_oop()->hash() : 0) +
4027 (uint)_klass_is_exact +
4028 (uint)_instance_id + TypePtr::hash();
4029 }
4030
4031 //------------------------------dump2------------------------------------------
4032 #ifndef PRODUCT
4033 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4034 st->print("oopptr:%s", ptr_msg[_ptr]);
4035 if( _klass_is_exact ) st->print(":exact");
4036 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4037 _offset.dump2(st);
4038 if (_instance_id == InstanceTop)
4039 st->print(",iid=top");
4040 else if (_instance_id != InstanceBot)
4041 st->print(",iid=%d",_instance_id);
4042
4043 dump_inline_depth(st);
4044 dump_speculative(st);
4045 }
4046 #endif
4047
4048 //------------------------------singleton--------------------------------------
4049 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4050 // constants
4051 bool TypeOopPtr::singleton(void) const {
4052 // detune optimizer to not generate constant oop + constant offset as a constant!
4053 // TopPTR, Null, AnyNull, Constant are all singletons
4054 return (offset() == 0) && !below_centerline(_ptr);
4055 }
4056
4057 //------------------------------add_offset-------------------------------------
4058 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4059 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4060 }
4061
4062 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4063 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4064 }
4065
4066 /**
4067 * Return same type without a speculative part
4068 */
4069 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4070 if (_speculative == nullptr) {
4071 return this;
4072 }
4073 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4074 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4075 }
4076
4077 /**
4078 * Return same type but drop speculative part if we know we won't use
4079 * it
4080 */
4081 const Type* TypeOopPtr::cleanup_speculative() const {
4082 // If the klass is exact and the ptr is not null then there's
4083 // nothing that the speculative type can help us with
4156 const TypeInstPtr *TypeInstPtr::BOTTOM;
4157 const TypeInstPtr *TypeInstPtr::MIRROR;
4158 const TypeInstPtr *TypeInstPtr::MARK;
4159 const TypeInstPtr *TypeInstPtr::KLASS;
4160
4161 // Is there a single ciKlass* that can represent that type?
4162 ciKlass* TypeInstPtr::exact_klass_helper() const {
4163 if (_interfaces->empty()) {
4164 return _klass;
4165 }
4166 if (_klass != ciEnv::current()->Object_klass()) {
4167 if (_interfaces->eq(_klass->as_instance_klass())) {
4168 return _klass;
4169 }
4170 return nullptr;
4171 }
4172 return _interfaces->exact_klass();
4173 }
4174
4175 //------------------------------TypeInstPtr-------------------------------------
4176 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4177 bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4178 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4179 _flat_in_array(flat_in_array) {
4180 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4181 assert(k != nullptr &&
4182 (k->is_loaded() || o == nullptr),
4183 "cannot have constants with non-loaded klass");
4184 assert(!klass()->flat_in_array() || flat_in_array, "Should be flat in array");
4185 assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4186 };
4187
4188 //------------------------------make-------------------------------------------
4189 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4190 ciKlass* k,
4191 const TypeInterfaces* interfaces,
4192 bool xk,
4193 ciObject* o,
4194 Offset offset,
4195 bool flat_in_array,
4196 int instance_id,
4197 const TypePtr* speculative,
4198 int inline_depth) {
4199 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4200 // Either const_oop() is null or else ptr is Constant
4201 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4202 "constant pointers must have a value supplied" );
4203 // Ptr is never Null
4204 assert( ptr != Null, "null pointers are not typed" );
4205
4206 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4207 if (ptr == Constant) {
4208 // Note: This case includes meta-object constants, such as methods.
4209 xk = true;
4210 } else if (k->is_loaded()) {
4211 ciInstanceKlass* ik = k->as_instance_klass();
4212 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4213 assert(!ik->is_interface(), "no interface here");
4214 if (xk && ik->is_interface()) xk = false; // no exact interface
4215 }
4216
4217 // Check if this type is known to be flat in arrays
4218 flat_in_array = flat_in_array || k->flat_in_array();
4219
4220 // Now hash this baby
4221 TypeInstPtr *result =
4222 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4223
4224 return result;
4225 }
4226
4227 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4228 if (k->is_instance_klass()) {
4229 if (k->is_loaded()) {
4230 if (k->is_interface() && interface_handling == ignore_interfaces) {
4231 assert(interface, "no interface expected");
4232 k = ciEnv::current()->Object_klass();
4233 const TypeInterfaces* interfaces = TypeInterfaces::make();
4234 return interfaces;
4235 }
4236 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4237 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4238 if (k->is_interface()) {
4239 assert(interface, "no interface expected");
4240 k = ciEnv::current()->Object_klass();
4241 } else {
4242 assert(klass, "no instance klass expected");
4268 switch (bt) {
4269 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4270 case T_INT: return TypeInt::make(constant.as_int());
4271 case T_CHAR: return TypeInt::make(constant.as_char());
4272 case T_BYTE: return TypeInt::make(constant.as_byte());
4273 case T_SHORT: return TypeInt::make(constant.as_short());
4274 case T_FLOAT: return TypeF::make(constant.as_float());
4275 case T_DOUBLE: return TypeD::make(constant.as_double());
4276 case T_LONG: return TypeLong::make(constant.as_long());
4277 default: break;
4278 }
4279 fatal("Invalid boxed value type '%s'", type2name(bt));
4280 return nullptr;
4281 }
4282
4283 //------------------------------cast_to_ptr_type-------------------------------
4284 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4285 if( ptr == _ptr ) return this;
4286 // Reconstruct _sig info here since not a problem with later lazy
4287 // construction, _sig will show up on demand.
4288 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4289 }
4290
4291
4292 //-----------------------------cast_to_exactness-------------------------------
4293 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4294 if( klass_is_exact == _klass_is_exact ) return this;
4295 if (!_klass->is_loaded()) return this;
4296 ciInstanceKlass* ik = _klass->as_instance_klass();
4297 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4298 assert(!ik->is_interface(), "no interface here");
4299 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4300 }
4301
4302 //-----------------------------cast_to_instance_id----------------------------
4303 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4304 if( instance_id == _instance_id ) return this;
4305 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4306 }
4307
4308 //------------------------------xmeet_unloaded---------------------------------
4309 // Compute the MEET of two InstPtrs when at least one is unloaded.
4310 // Assume classes are different since called after check for same name/class-loader
4311 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4312 Offset off = meet_offset(tinst->offset());
4313 PTR ptr = meet_ptr(tinst->ptr());
4314 int instance_id = meet_instance_id(tinst->instance_id());
4315 const TypePtr* speculative = xmeet_speculative(tinst);
4316 int depth = meet_inline_depth(tinst->inline_depth());
4317
4318 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4319 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4320 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4321 //
4322 // Meet unloaded class with java/lang/Object
4323 //
4324 // Meet
4325 // | Unloaded Class
4326 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4327 // ===================================================================
4328 // TOP | ..........................Unloaded......................|
4329 // AnyNull | U-AN |................Unloaded......................|
4330 // Constant | ... O-NN .................................. | O-BOT |
4331 // NotNull | ... O-NN .................................. | O-BOT |
4332 // BOTTOM | ........................Object-BOTTOM ..................|
4333 //
4334 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4335 //
4336 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4337 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4338 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4339 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4340 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4341 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4342 }
4343 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4344
4345 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4346 }
4347
4348 // Both are unloaded, not the same class, not Object
4349 // Or meet unloaded with a different loaded class, not java/lang/Object
4350 if (ptr != TypePtr::BotPTR) {
4351 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4352 }
4353 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4354 }
4355
4356
4357 //------------------------------meet-------------------------------------------
4378 case Top:
4379 return this;
4380
4381 default: // All else is a mistake
4382 typerr(t);
4383
4384 case MetadataPtr:
4385 case KlassPtr:
4386 case InstKlassPtr:
4387 case AryKlassPtr:
4388 case RawPtr: return TypePtr::BOTTOM;
4389
4390 case AryPtr: { // All arrays inherit from Object class
4391 // Call in reverse direction to avoid duplication
4392 return t->is_aryptr()->xmeet_helper(this);
4393 }
4394
4395 case OopPtr: { // Meeting to OopPtrs
4396 // Found a OopPtr type vs self-InstPtr type
4397 const TypeOopPtr *tp = t->is_oopptr();
4398 Offset offset = meet_offset(tp->offset());
4399 PTR ptr = meet_ptr(tp->ptr());
4400 switch (tp->ptr()) {
4401 case TopPTR:
4402 case AnyNull: {
4403 int instance_id = meet_instance_id(InstanceTop);
4404 const TypePtr* speculative = xmeet_speculative(tp);
4405 int depth = meet_inline_depth(tp->inline_depth());
4406 return make(ptr, klass(), _interfaces, klass_is_exact(),
4407 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4408 }
4409 case NotNull:
4410 case BotPTR: {
4411 int instance_id = meet_instance_id(tp->instance_id());
4412 const TypePtr* speculative = xmeet_speculative(tp);
4413 int depth = meet_inline_depth(tp->inline_depth());
4414 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4415 }
4416 default: typerr(t);
4417 }
4418 }
4419
4420 case AnyPtr: { // Meeting to AnyPtrs
4421 // Found an AnyPtr type vs self-InstPtr type
4422 const TypePtr *tp = t->is_ptr();
4423 Offset offset = meet_offset(tp->offset());
4424 PTR ptr = meet_ptr(tp->ptr());
4425 int instance_id = meet_instance_id(InstanceTop);
4426 const TypePtr* speculative = xmeet_speculative(tp);
4427 int depth = meet_inline_depth(tp->inline_depth());
4428 switch (tp->ptr()) {
4429 case Null:
4430 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4431 // else fall through to AnyNull
4432 case TopPTR:
4433 case AnyNull: {
4434 return make(ptr, klass(), _interfaces, klass_is_exact(),
4435 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4436 }
4437 case NotNull:
4438 case BotPTR:
4439 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4440 default: typerr(t);
4441 }
4442 }
4443
4444 /*
4445 A-top }
4446 / | \ } Tops
4447 B-top A-any C-top }
4448 | / | \ | } Any-nulls
4449 B-any | C-any }
4450 | | |
4451 B-con A-con C-con } constants; not comparable across classes
4452 | | |
4453 B-not | C-not }
4454 | \ | / | } not-nulls
4455 B-bot A-not C-bot }
4456 \ | / } Bottoms
4457 A-bot }
4458 */
4459
4460 case InstPtr: { // Meeting 2 Oops?
4461 // Found an InstPtr sub-type vs self-InstPtr type
4462 const TypeInstPtr *tinst = t->is_instptr();
4463 Offset off = meet_offset(tinst->offset());
4464 PTR ptr = meet_ptr(tinst->ptr());
4465 int instance_id = meet_instance_id(tinst->instance_id());
4466 const TypePtr* speculative = xmeet_speculative(tinst);
4467 int depth = meet_inline_depth(tinst->inline_depth());
4468 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4469
4470 ciKlass* tinst_klass = tinst->klass();
4471 ciKlass* this_klass = klass();
4472
4473 ciKlass* res_klass = nullptr;
4474 bool res_xk = false;
4475 bool res_flat_in_array = false;
4476 const Type* res;
4477 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4478
4479 if (kind == UNLOADED) {
4480 // One of these classes has not been loaded
4481 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4482 #ifndef PRODUCT
4483 if (PrintOpto && Verbose) {
4484 tty->print("meet of unloaded classes resulted in: ");
4485 unloaded_meet->dump();
4486 tty->cr();
4487 tty->print(" this == ");
4488 dump();
4489 tty->cr();
4490 tty->print(" tinst == ");
4491 tinst->dump();
4492 tty->cr();
4493 }
4494 #endif
4495 res = unloaded_meet;
4496 } else {
4497 if (kind == NOT_SUBTYPE && instance_id > 0) {
4498 instance_id = InstanceBot;
4499 } else if (kind == LCA) {
4500 instance_id = InstanceBot;
4501 }
4502 ciObject* o = nullptr; // Assume not constant when done
4503 ciObject* this_oop = const_oop();
4504 ciObject* tinst_oop = tinst->const_oop();
4505 if (ptr == Constant) {
4506 if (this_oop != nullptr && tinst_oop != nullptr &&
4507 this_oop->equals(tinst_oop))
4508 o = this_oop;
4509 else if (above_centerline(_ptr)) {
4510 assert(!tinst_klass->is_interface(), "");
4511 o = tinst_oop;
4512 } else if (above_centerline(tinst->_ptr)) {
4513 assert(!this_klass->is_interface(), "");
4514 o = this_oop;
4515 } else
4516 ptr = NotNull;
4517 }
4518 res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4519 }
4520
4521 return res;
4522
4523 } // End of case InstPtr
4524
4525 } // End of switch
4526 return this; // Return the double constant
4527 }
4528
4529 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4530 ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4531 ciKlass* this_klass = this_type->klass();
4532 ciKlass* other_klass = other_type->klass();
4533 const bool this_flat_in_array = this_type->flat_in_array();
4534 const bool other_flat_in_array = other_type->flat_in_array();
4535 const bool this_not_flat_in_array = this_type->not_flat_in_array();
4536 const bool other_not_flat_in_array = other_type->not_flat_in_array();
4537
4538 bool this_xk = this_type->klass_is_exact();
4539 bool other_xk = other_type->klass_is_exact();
4540 PTR this_ptr = this_type->ptr();
4541 PTR other_ptr = other_type->ptr();
4542 const TypeInterfaces* this_interfaces = this_type->interfaces();
4543 const TypeInterfaces* other_interfaces = other_type->interfaces();
4544 // Check for easy case; klasses are equal (and perhaps not loaded!)
4545 // If we have constants, then we created oops so classes are loaded
4546 // and we can handle the constants further down. This case handles
4547 // both-not-loaded or both-loaded classes
4548 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4549 res_klass = this_klass;
4550 res_xk = this_xk;
4551 res_flat_in_array = this_flat_in_array;
4552 return QUICK;
4553 }
4554
4555 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4556 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4557 return UNLOADED;
4558 }
4559
4560 // !!! Here's how the symmetry requirement breaks down into invariants:
4561 // If we split one up & one down AND they subtype, take the down man.
4562 // If we split one up & one down AND they do NOT subtype, "fall hard".
4563 // If both are up and they subtype, take the subtype class.
4564 // If both are up and they do NOT subtype, "fall hard".
4565 // If both are down and they subtype, take the supertype class.
4566 // If both are down and they do NOT subtype, "fall hard".
4567 // Constants treated as down.
4568
4569 // Now, reorder the above list; observe that both-down+subtype is also
4570 // "fall hard"; "fall hard" becomes the default case:
4571 // If we split one up & one down AND they subtype, take the down man.
4572 // If both are up and they subtype, take the subtype class.
4573
4574 // If both are down and they subtype, "fall hard".
4575 // If both are down and they do NOT subtype, "fall hard".
4576 // If both are up and they do NOT subtype, "fall hard".
4577 // If we split one up & one down AND they do NOT subtype, "fall hard".
4578
4579 // If a proper subtype is exact, and we return it, we return it exactly.
4580 // If a proper supertype is exact, there can be no subtyping relationship!
4581 // If both types are equal to the subtype, exactness is and-ed below the
4582 // centerline and or-ed above it. (N.B. Constants are always exact.)
4583
4584 // Check for subtyping:
4585 // Flat in array matrix, yes = y, no = n, maybe = m, top/empty = T:
4586 // yes maybe no -> Super Klass
4587 // yes y y y
4588 // maybe y m m
4589 // no T n n
4590 // |
4591 // v
4592 // Sub Klass
4593
4594 const T* subtype = nullptr;
4595 bool subtype_exact = false;
4596 bool flat_in_array = false;
4597 if (this_type->is_same_java_type_as(other_type)) {
4598 subtype = this_type;
4599 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4600 flat_in_array = below_centerline(ptr) ? (this_flat_in_array && other_flat_in_array) : (this_flat_in_array || other_flat_in_array);
4601 } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4602 subtype = this_type; // Pick subtyping class
4603 subtype_exact = this_xk;
4604 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4605 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4606 } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4607 subtype = other_type; // Pick subtyping class
4608 subtype_exact = other_xk;
4609 bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4610 flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4611 }
4612
4613 if (subtype) {
4614 if (above_centerline(ptr)) {
4615 // Both types are empty.
4616 this_type = other_type = subtype;
4617 this_xk = other_xk = subtype_exact;
4618 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4619 // this_type is empty while other_type is not. Take other_type.
4620 this_type = other_type;
4621 this_xk = other_xk;
4622 flat_in_array = other_flat_in_array;
4623 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4624 // other_type is empty while this_type is not. Take this_type.
4625 other_type = this_type; // this is down; keep down man
4626 flat_in_array = this_flat_in_array;
4627 } else {
4628 // this_type and other_type are both non-empty.
4629 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4630 }
4631 }
4632
4633 // Check for classes now being equal
4634 if (this_type->is_same_java_type_as(other_type)) {
4635 // If the klasses are equal, the constants may still differ. Fall to
4636 // NotNull if they do (neither constant is null; that is a special case
4637 // handled elsewhere).
4638 res_klass = this_type->klass();
4639 res_xk = this_xk;
4640 res_flat_in_array = subtype ? flat_in_array : this_flat_in_array;
4641 return SUBTYPE;
4642 } // Else classes are not equal
4643
4644 // Since klasses are different, we require a LCA in the Java
4645 // class hierarchy - which means we have to fall to at least NotNull.
4646 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4647 ptr = NotNull;
4648 }
4649
4650 interfaces = this_interfaces->intersection_with(other_interfaces);
4651
4652 // Now we find the LCA of Java classes
4653 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4654
4655 res_klass = k;
4656 res_xk = false;
4657 res_flat_in_array = this_flat_in_array && other_flat_in_array;
4658
4659 return LCA;
4660 }
4661
4662 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4663 return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4664 }
4665
4666 //------------------------java_mirror_type--------------------------------------
4667 ciType* TypeInstPtr::java_mirror_type(bool* is_null_free_array) const {
4668 // must be a singleton type
4669 if( const_oop() == nullptr ) return nullptr;
4670
4671 // must be of type java.lang.Class
4672 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4673 return const_oop()->as_instance()->java_mirror_type(is_null_free_array);
4674 }
4675
4676
4677 //------------------------------xdual------------------------------------------
4678 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4679 // inheritance mechanism.
4680 const Type *TypeInstPtr::xdual() const {
4681 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4682 }
4683
4684 //------------------------------eq---------------------------------------------
4685 // Structural equality check for Type representations
4686 bool TypeInstPtr::eq( const Type *t ) const {
4687 const TypeInstPtr *p = t->is_instptr();
4688 return
4689 klass()->equals(p->klass()) &&
4690 flat_in_array() == p->flat_in_array() &&
4691 _interfaces->eq(p->_interfaces) &&
4692 TypeOopPtr::eq(p); // Check sub-type stuff
4693 }
4694
4695 //------------------------------hash-------------------------------------------
4696 // Type-specific hashing function.
4697 uint TypeInstPtr::hash(void) const {
4698 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4699 }
4700
4701 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4702 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4703 }
4704
4705
4706 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4707 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4708 }
4709
4710 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4711 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4712 }
4713
4714
4715 //------------------------------dump2------------------------------------------
4716 // Dump oop Type
4717 #ifndef PRODUCT
4718 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4732 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4733 char* buf = ss.as_string(/* c_heap= */false);
4734 StringUtils::replace_no_expand(buf, "\n", "");
4735 st->print_raw(buf);
4736 }
4737 case BotPTR:
4738 if (!WizardMode && !Verbose) {
4739 if( _klass_is_exact ) st->print(":exact");
4740 break;
4741 }
4742 case TopPTR:
4743 case AnyNull:
4744 case NotNull:
4745 st->print(":%s", ptr_msg[_ptr]);
4746 if( _klass_is_exact ) st->print(":exact");
4747 break;
4748 default:
4749 break;
4750 }
4751
4752 _offset.dump2(st);
4753
4754 st->print(" *");
4755
4756 if (flat_in_array() && !klass()->is_inlinetype()) {
4757 st->print(" (flat in array)");
4758 }
4759
4760 if (_instance_id == InstanceTop)
4761 st->print(",iid=top");
4762 else if (_instance_id != InstanceBot)
4763 st->print(",iid=%d",_instance_id);
4764
4765 dump_inline_depth(st);
4766 dump_speculative(st);
4767 }
4768 #endif
4769
4770 //------------------------------add_offset-------------------------------------
4771 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4772 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4773 _instance_id, add_offset_speculative(offset), _inline_depth);
4774 }
4775
4776 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4777 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4778 _instance_id, with_offset_speculative(offset), _inline_depth);
4779 }
4780
4781 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4782 if (_speculative == nullptr) {
4783 return this;
4784 }
4785 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4786 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4787 _instance_id, nullptr, _inline_depth);
4788 }
4789
4790 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4791 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
4792 }
4793
4794 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4795 if (!UseInlineDepthForSpeculativeTypes) {
4796 return this;
4797 }
4798 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4799 }
4800
4801 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4802 assert(is_known_instance(), "should be known");
4803 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4804 }
4805
4806 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4807 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4808 }
4809
4810 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4811 bool xk = klass_is_exact();
4812 ciInstanceKlass* ik = klass()->as_instance_klass();
4813 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4814 if (_interfaces->eq(ik)) {
4815 Compile* C = Compile::current();
4816 Dependencies* deps = C->dependencies();
4817 deps->assert_leaf_type(ik);
4818 xk = true;
4819 }
4820 }
4821 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4822 }
4823
4824 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4825 static_assert(std::is_base_of<T2, T1>::value, "");
4826
4827 if (!this_one->is_instance_type(other)) {
4828 return false;
4829 }
4830
4831 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4832 return true;
4833 }
4834
4835 return this_one->klass()->is_subtype_of(other->klass()) &&
4836 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4837 }
4838
4839
4840 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4841 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4846 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4847 return true;
4848 }
4849
4850 if (this_one->is_instance_type(other)) {
4851 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4852 }
4853
4854 int dummy;
4855 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4856 if (this_top_or_bottom) {
4857 return false;
4858 }
4859
4860 const T1* other_ary = this_one->is_array_type(other);
4861 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4862 const TypePtr* this_elem = this_one->elem()->make_ptr();
4863 if (other_elem != nullptr && this_elem != nullptr) {
4864 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4865 }
4866 if (other_elem == nullptr && this_elem == nullptr) {
4867 return this_one->klass()->is_subtype_of(other->klass());
4868 }
4869
4870 return false;
4871 }
4872
4873 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4874 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4875 }
4876
4877 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4878 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4879 }
4880
4881 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4882 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4883 }
4884
4885 //=============================================================================
4886 // Convenience common pre-built types.
4887 const TypeAryPtr *TypeAryPtr::RANGE;
4888 const TypeAryPtr *TypeAryPtr::OOPS;
4889 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4890 const TypeAryPtr *TypeAryPtr::BYTES;
4891 const TypeAryPtr *TypeAryPtr::SHORTS;
4892 const TypeAryPtr *TypeAryPtr::CHARS;
4893 const TypeAryPtr *TypeAryPtr::INTS;
4894 const TypeAryPtr *TypeAryPtr::LONGS;
4895 const TypeAryPtr *TypeAryPtr::FLOATS;
4896 const TypeAryPtr *TypeAryPtr::DOUBLES;
4897 const TypeAryPtr *TypeAryPtr::INLINES;
4898
4899 //------------------------------make-------------------------------------------
4900 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4901 int instance_id, const TypePtr* speculative, int inline_depth) {
4902 assert(!(k == nullptr && ary->_elem->isa_int()),
4903 "integral arrays must be pre-equipped with a class");
4904 if (!xk) xk = ary->ary_must_be_exact();
4905 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4906 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4907 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4908 k = nullptr;
4909 }
4910 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4911 k = nullptr;
4912 }
4913 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4914 }
4915
4916 //------------------------------make-------------------------------------------
4917 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4918 int instance_id, const TypePtr* speculative, int inline_depth,
4919 bool is_autobox_cache) {
4920 assert(!(k == nullptr && ary->_elem->isa_int()),
4921 "integral arrays must be pre-equipped with a class");
4922 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4923 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4924 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4925 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4926 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4927 k = nullptr;
4928 }
4929 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4930 k = nullptr;
4931 }
4932 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4933 }
4934
4935 //------------------------------cast_to_ptr_type-------------------------------
4936 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4937 if( ptr == _ptr ) return this;
4938 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4939 }
4940
4941
4942 //-----------------------------cast_to_exactness-------------------------------
4943 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4944 if( klass_is_exact == _klass_is_exact ) return this;
4945 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4946 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4947 }
4948
4949 //-----------------------------cast_to_instance_id----------------------------
4950 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4951 if( instance_id == _instance_id ) return this;
4952 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4953 }
4954
4955
4956 //-----------------------------max_array_length-------------------------------
4957 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4958 jint TypeAryPtr::max_array_length(BasicType etype) {
4959 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4960 if (etype == T_NARROWOOP) {
4961 etype = T_OBJECT;
4962 } else if (etype == T_ILLEGAL) { // bottom[]
4963 etype = T_BYTE; // will produce conservatively high value
4964 } else {
4965 fatal("not an element type: %s", type2name(etype));
4966 }
4967 }
4968 return arrayOopDesc::max_array_length(etype);
4969 }
4970
4971 //-----------------------------narrow_size_type-------------------------------
4972 // Narrow the given size type to the index range for the given array base type.
4988 if (hi > max_hi) {
4989 hi = max_hi;
4990 if (size->is_con()) {
4991 lo = hi;
4992 }
4993 chg = true;
4994 }
4995 // Negative length arrays will produce weird intermediate dead fast-path code
4996 if (lo > hi)
4997 return TypeInt::ZERO;
4998 if (!chg)
4999 return size;
5000 return TypeInt::make(lo, hi, Type::WidenMin);
5001 }
5002
5003 //-------------------------------cast_to_size----------------------------------
5004 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5005 assert(new_size != nullptr, "");
5006 new_size = narrow_size_type(new_size);
5007 if (new_size == size()) return this;
5008 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5009 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5010 }
5011
5012 //-------------------------------cast_to_not_flat------------------------------
5013 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5014 if (not_flat == is_not_flat()) {
5015 return this;
5016 }
5017 assert(!not_flat || !is_flat(), "inconsistency");
5018 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
5019 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5020 // We keep the speculative part if it contains information about flat-/nullability.
5021 // Make sure it's removed if it's not better than the non-speculative type anymore.
5022 if (res->speculative() == res->remove_speculative()) {
5023 return res->remove_speculative();
5024 }
5025 return res;
5026 }
5027
5028 //-------------------------------cast_to_not_null_free-------------------------
5029 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5030 if (not_null_free == is_not_null_free()) {
5031 return this;
5032 }
5033 assert(!not_null_free || !is_flat(), "inconsistency");
5034 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
5035 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5036 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5037 // We keep the speculative part if it contains information about flat-/nullability.
5038 // Make sure it's removed if it's not better than the non-speculative type anymore.
5039 if (res->speculative() == res->remove_speculative()) {
5040 return res->remove_speculative();
5041 }
5042 return res;
5043 }
5044
5045 //---------------------------------update_properties---------------------------
5046 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5047 if ((from->is_flat() && is_not_flat()) ||
5048 (from->is_not_flat() && is_flat()) ||
5049 (from->is_null_free() && is_not_null_free()) ||
5050 (from->is_not_null_free() && is_null_free())) {
5051 return nullptr; // Inconsistent properties
5052 } else if (from->is_not_null_free()) {
5053 return cast_to_not_null_free(); // Implies not flat
5054 } else if (from->is_not_flat()) {
5055 return cast_to_not_flat();
5056 }
5057 return this;
5058 }
5059
5060 jint TypeAryPtr::flat_layout_helper() const {
5061 return klass()->as_flat_array_klass()->layout_helper();
5062 }
5063
5064 int TypeAryPtr::flat_elem_size() const {
5065 return klass()->as_flat_array_klass()->element_byte_size();
5066 }
5067
5068 int TypeAryPtr::flat_log_elem_size() const {
5069 return klass()->as_flat_array_klass()->log2_element_size();
5070 }
5071
5072 //------------------------------cast_to_stable---------------------------------
5073 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5074 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5075 return this;
5076
5077 const Type* elem = this->elem();
5078 const TypePtr* elem_ptr = elem->make_ptr();
5079
5080 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5081 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5082 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5083 }
5084
5085 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5086
5087 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5088 }
5089
5090 //-----------------------------stable_dimension--------------------------------
5091 int TypeAryPtr::stable_dimension() const {
5092 if (!is_stable()) return 0;
5093 int dim = 1;
5094 const TypePtr* elem_ptr = elem()->make_ptr();
5095 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5096 dim += elem_ptr->is_aryptr()->stable_dimension();
5097 return dim;
5098 }
5099
5100 //----------------------cast_to_autobox_cache-----------------------------------
5101 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5102 if (is_autobox_cache()) return this;
5103 const TypeOopPtr* etype = elem()->make_oopptr();
5104 if (etype == nullptr) return this;
5105 // The pointers in the autobox arrays are always non-null.
5106 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5107 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5108 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5109 }
5110
5111 //------------------------------eq---------------------------------------------
5112 // Structural equality check for Type representations
5113 bool TypeAryPtr::eq( const Type *t ) const {
5114 const TypeAryPtr *p = t->is_aryptr();
5115 return
5116 _ary == p->_ary && // Check array
5117 TypeOopPtr::eq(p) &&// Check sub-parts
5118 _field_offset == p->_field_offset;
5119 }
5120
5121 //------------------------------hash-------------------------------------------
5122 // Type-specific hashing function.
5123 uint TypeAryPtr::hash(void) const {
5124 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5125 }
5126
5127 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5128 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5129 }
5130
5131 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5132 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5133 }
5134
5135 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5136 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5137 }
5138 //------------------------------meet-------------------------------------------
5139 // Compute the MEET of two types. It returns a new Type object.
5140 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5141 // Perform a fast test for common case; meeting the same types together.
5142 if( this == t ) return this; // Meeting same type-rep?
5143 // Current "this->_base" is Pointer
5144 switch (t->base()) { // switch on original type
5148 case Long:
5149 case FloatTop:
5150 case FloatCon:
5151 case FloatBot:
5152 case DoubleTop:
5153 case DoubleCon:
5154 case DoubleBot:
5155 case NarrowOop:
5156 case NarrowKlass:
5157 case Bottom: // Ye Olde Default
5158 return Type::BOTTOM;
5159 case Top:
5160 return this;
5161
5162 default: // All else is a mistake
5163 typerr(t);
5164
5165 case OopPtr: { // Meeting to OopPtrs
5166 // Found a OopPtr type vs self-AryPtr type
5167 const TypeOopPtr *tp = t->is_oopptr();
5168 Offset offset = meet_offset(tp->offset());
5169 PTR ptr = meet_ptr(tp->ptr());
5170 int depth = meet_inline_depth(tp->inline_depth());
5171 const TypePtr* speculative = xmeet_speculative(tp);
5172 switch (tp->ptr()) {
5173 case TopPTR:
5174 case AnyNull: {
5175 int instance_id = meet_instance_id(InstanceTop);
5176 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5177 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5178 }
5179 case BotPTR:
5180 case NotNull: {
5181 int instance_id = meet_instance_id(tp->instance_id());
5182 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5183 }
5184 default: ShouldNotReachHere();
5185 }
5186 }
5187
5188 case AnyPtr: { // Meeting two AnyPtrs
5189 // Found an AnyPtr type vs self-AryPtr type
5190 const TypePtr *tp = t->is_ptr();
5191 Offset offset = meet_offset(tp->offset());
5192 PTR ptr = meet_ptr(tp->ptr());
5193 const TypePtr* speculative = xmeet_speculative(tp);
5194 int depth = meet_inline_depth(tp->inline_depth());
5195 switch (tp->ptr()) {
5196 case TopPTR:
5197 return this;
5198 case BotPTR:
5199 case NotNull:
5200 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5201 case Null:
5202 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5203 // else fall through to AnyNull
5204 case AnyNull: {
5205 int instance_id = meet_instance_id(InstanceTop);
5206 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5207 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5208 }
5209 default: ShouldNotReachHere();
5210 }
5211 }
5212
5213 case MetadataPtr:
5214 case KlassPtr:
5215 case InstKlassPtr:
5216 case AryKlassPtr:
5217 case RawPtr: return TypePtr::BOTTOM;
5218
5219 case AryPtr: { // Meeting 2 references?
5220 const TypeAryPtr *tap = t->is_aryptr();
5221 Offset off = meet_offset(tap->offset());
5222 Offset field_off = meet_field_offset(tap->field_offset());
5223 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5224 PTR ptr = meet_ptr(tap->ptr());
5225 int instance_id = meet_instance_id(tap->instance_id());
5226 const TypePtr* speculative = xmeet_speculative(tap);
5227 int depth = meet_inline_depth(tap->inline_depth());
5228
5229 ciKlass* res_klass = nullptr;
5230 bool res_xk = false;
5231 bool res_flat = false;
5232 bool res_not_flat = false;
5233 bool res_not_null_free = false;
5234 const Type* elem = tary->_elem;
5235 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5236 instance_id = InstanceBot;
5237 } else if (this->is_flat() != tap->is_flat()) {
5238 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5239 if (tary->_flat) {
5240 // Result is in a flat representation
5241 off = Offset(is_flat() ? offset() : tap->offset());
5242 field_off = is_flat() ? field_offset() : tap->field_offset();
5243 } else if (below_centerline(ptr)) {
5244 // Result is in a non-flat representation
5245 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5246 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5247 } else if (flat_offset() == tap->flat_offset()) {
5248 off = Offset(!is_flat() ? offset() : tap->offset());
5249 field_off = !is_flat() ? field_offset() : tap->field_offset();
5250 }
5251 }
5252
5253 ciObject* o = nullptr; // Assume not constant when done
5254 ciObject* this_oop = const_oop();
5255 ciObject* tap_oop = tap->const_oop();
5256 if (ptr == Constant) {
5257 if (this_oop != nullptr && tap_oop != nullptr &&
5258 this_oop->equals(tap_oop)) {
5259 o = tap_oop;
5260 } else if (above_centerline(_ptr)) {
5261 o = tap_oop;
5262 } else if (above_centerline(tap->_ptr)) {
5263 o = this_oop;
5264 } else {
5265 ptr = NotNull;
5266 }
5267 }
5268 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5269 }
5270
5271 // All arrays inherit from Object class
5272 case InstPtr: {
5273 const TypeInstPtr *tp = t->is_instptr();
5274 Offset offset = meet_offset(tp->offset());
5275 PTR ptr = meet_ptr(tp->ptr());
5276 int instance_id = meet_instance_id(tp->instance_id());
5277 const TypePtr* speculative = xmeet_speculative(tp);
5278 int depth = meet_inline_depth(tp->inline_depth());
5279 const TypeInterfaces* interfaces = meet_interfaces(tp);
5280 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5281 const TypeInterfaces* this_interfaces = _interfaces;
5282
5283 switch (ptr) {
5284 case TopPTR:
5285 case AnyNull: // Fall 'down' to dual of object klass
5286 // For instances when a subclass meets a superclass we fall
5287 // below the centerline when the superclass is exact. We need to
5288 // do the same here.
5289 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5290 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5291 } else {
5292 // cannot subclass, so the meet has to fall badly below the centerline
5293 ptr = NotNull;
5294 instance_id = InstanceBot;
5295 interfaces = this_interfaces->intersection_with(tp_interfaces);
5296 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5297 }
5298 case Constant:
5299 case NotNull:
5300 case BotPTR: // Fall down to object klass
5301 // LCA is object_klass, but if we subclass from the top we can do better
5302 if (above_centerline(tp->ptr())) {
5303 // If 'tp' is above the centerline and it is Object class
5304 // then we can subclass in the Java class hierarchy.
5305 // For instances when a subclass meets a superclass we fall
5306 // below the centerline when the superclass is exact. We need
5307 // to do the same here.
5308 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5309 // that is, my array type is a subtype of 'tp' klass
5310 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5311 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5312 }
5313 }
5314 // The other case cannot happen, since t cannot be a subtype of an array.
5315 // The meet falls down to Object class below centerline.
5316 if (ptr == Constant) {
5317 ptr = NotNull;
5318 }
5319 if (instance_id > 0) {
5320 instance_id = InstanceBot;
5321 }
5322 interfaces = this_interfaces->intersection_with(tp_interfaces);
5323 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5324 default: typerr(t);
5325 }
5326 }
5327 }
5328 return this; // Lint noise
5329 }
5330
5331
5332 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5333 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5334 int dummy;
5335 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5336 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5337 ciKlass* this_klass = this_ary->klass();
5338 ciKlass* other_klass = other_ary->klass();
5339 bool this_xk = this_ary->klass_is_exact();
5340 bool other_xk = other_ary->klass_is_exact();
5341 PTR this_ptr = this_ary->ptr();
5342 PTR other_ptr = other_ary->ptr();
5343 bool this_flat = this_ary->is_flat();
5344 bool this_not_flat = this_ary->is_not_flat();
5345 bool other_flat = other_ary->is_flat();
5346 bool other_not_flat = other_ary->is_not_flat();
5347 bool this_not_null_free = this_ary->is_not_null_free();
5348 bool other_not_null_free = other_ary->is_not_null_free();
5349 res_klass = nullptr;
5350 MeetResult result = SUBTYPE;
5351 res_flat = this_flat && other_flat;
5352 res_not_flat = this_not_flat && other_not_flat;
5353 res_not_null_free = this_not_null_free && other_not_null_free;
5354
5355 if (elem->isa_int()) {
5356 // Integral array element types have irrelevant lattice relations.
5357 // It is the klass that determines array layout, not the element type.
5358 if (this_top_or_bottom) {
5359 res_klass = other_klass;
5360 } else if (other_top_or_bottom || other_klass == this_klass) {
5361 res_klass = this_klass;
5362 } else {
5363 // Something like byte[int+] meets char[int+].
5364 // This must fall to bottom, not (int[-128..65535])[int+].
5365 // instance_id = InstanceBot;
5366 elem = Type::BOTTOM;
5367 result = NOT_SUBTYPE;
5368 if (above_centerline(ptr) || ptr == Constant) {
5369 ptr = NotNull;
5370 res_xk = false;
5371 return NOT_SUBTYPE;
5372 }
5373 }
5374 } else {// Non integral arrays.
5375 // Must fall to bottom if exact klasses in upper lattice
5376 // are not equal or super klass is exact.
5377 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5378 // meet with top[] and bottom[] are processed further down:
5379 !this_top_or_bottom && !other_top_or_bottom &&
5380 // both are exact and not equal:
5382 // 'tap' is exact and super or unrelated:
5383 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5384 // 'this' is exact and super or unrelated:
5385 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5386 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5387 elem = Type::BOTTOM;
5388 }
5389 ptr = NotNull;
5390 res_xk = false;
5391 return NOT_SUBTYPE;
5392 }
5393 }
5394
5395 res_xk = false;
5396 switch (other_ptr) {
5397 case AnyNull:
5398 case TopPTR:
5399 // Compute new klass on demand, do not use tap->_klass
5400 if (below_centerline(this_ptr)) {
5401 res_xk = this_xk;
5402 if (this_ary->is_flat()) {
5403 elem = this_ary->elem();
5404 }
5405 } else {
5406 res_xk = (other_xk || this_xk);
5407 }
5408 break;
5409 case Constant: {
5410 if (this_ptr == Constant) {
5411 res_xk = true;
5412 } else if (above_centerline(this_ptr)) {
5413 res_xk = true;
5414 } else {
5415 // Only precise for identical arrays
5416 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5417 // Even though MyValue is final, [LMyValue is only exact if the array
5418 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5419 if (res_xk && !res_not_null_free) {
5420 res_xk = false;
5421 }
5422 }
5423 break;
5424 }
5425 case NotNull:
5426 case BotPTR:
5427 // Compute new klass on demand, do not use tap->_klass
5428 if (above_centerline(this_ptr)) {
5429 res_xk = other_xk;
5430 if (other_ary->is_flat()) {
5431 elem = other_ary->elem();
5432 }
5433 } else {
5434 res_xk = (other_xk && this_xk) &&
5435 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5436 // Even though MyValue is final, [LMyValue is only exact if the array
5437 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5438 if (res_xk && !res_not_null_free) {
5439 res_xk = false;
5440 }
5441 }
5442 break;
5443 default: {
5444 ShouldNotReachHere();
5445 return result;
5446 }
5447 }
5448 return result;
5449 }
5450
5451
5452 //------------------------------xdual------------------------------------------
5453 // Dual: compute field-by-field dual
5454 const Type *TypeAryPtr::xdual() const {
5455 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());
5456 }
5457
5458 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5459 return _field_offset.meet(offset);
5460 }
5461
5462 //------------------------------dual_offset------------------------------------
5463 Type::Offset TypeAryPtr::dual_field_offset() const {
5464 return _field_offset.dual();
5465 }
5466
5467 //------------------------------dump2------------------------------------------
5468 #ifndef PRODUCT
5469 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5470 _ary->dump2(d,depth,st);
5471 _interfaces->dump(st);
5472
5473 switch( _ptr ) {
5474 case Constant:
5475 const_oop()->print(st);
5476 break;
5477 case BotPTR:
5478 if (!WizardMode && !Verbose) {
5479 if( _klass_is_exact ) st->print(":exact");
5480 break;
5481 }
5482 case TopPTR:
5483 case AnyNull:
5484 case NotNull:
5485 st->print(":%s", ptr_msg[_ptr]);
5486 if( _klass_is_exact ) st->print(":exact");
5487 break;
5488 default:
5489 break;
5490 }
5491
5492 if (is_flat()) {
5493 st->print(":flat");
5494 st->print("(");
5495 _field_offset.dump2(st);
5496 st->print(")");
5497 }
5498 if (is_null_free()) {
5499 st->print(":null_free");
5500 }
5501 if (offset() != 0) {
5502 BasicType basic_elem_type = elem()->basic_type();
5503 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5504 if( _offset == Offset::top ) st->print("+undefined");
5505 else if( _offset == Offset::bottom ) st->print("+any");
5506 else if( offset() < header_size ) st->print("+%d", offset());
5507 else {
5508 if (basic_elem_type == T_ILLEGAL) {
5509 st->print("+any");
5510 } else {
5511 int elem_size = type2aelembytes(basic_elem_type);
5512 st->print("[%d]", (offset() - header_size)/elem_size);
5513 }
5514 }
5515 }
5516 st->print(" *");
5517 if (_instance_id == InstanceTop)
5518 st->print(",iid=top");
5519 else if (_instance_id != InstanceBot)
5520 st->print(",iid=%d",_instance_id);
5521
5522 dump_inline_depth(st);
5523 dump_speculative(st);
5524 }
5525 #endif
5526
5527 bool TypeAryPtr::empty(void) const {
5528 if (_ary->empty()) return true;
5529 // FIXME: Does this belong here? Or in the meet code itself?
5530 if (is_flat() && is_not_flat()) {
5531 return true;
5532 }
5533 return TypeOopPtr::empty();
5534 }
5535
5536 //------------------------------add_offset-------------------------------------
5537 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5538 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);
5539 }
5540
5541 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5542 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, Offset(offset), _field_offset, _instance_id, with_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5543 }
5544
5545 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5546 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5547 }
5548
5549 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5550 if (_speculative == nullptr) {
5551 return this;
5552 }
5553 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5554 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, nullptr, _inline_depth, _is_autobox_cache);
5555 }
5556
5557 const Type* TypeAryPtr::cleanup_speculative() const {
5558 if (speculative() == nullptr) {
5559 return this;
5560 }
5561 // Keep speculative part if it contains information about flat-/nullability
5562 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5563 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5564 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5565 return this;
5566 }
5567 return TypeOopPtr::cleanup_speculative();
5568 }
5569
5570 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5571 if (!UseInlineDepthForSpeculativeTypes) {
5572 return this;
5573 }
5574 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5575 }
5576
5577 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5578 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);
5579 }
5580
5581 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5582 int adj = 0;
5583 if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5584 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5585 adj = _offset.get();
5586 offset += _offset.get();
5587 }
5588 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5589 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5590 offset += _field_offset.get();
5591 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5592 offset += header;
5593 }
5594 }
5595 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5596 // Try to get the field of the inline type array element we are pointing to
5597 ciInlineKlass* vk = elem()->inline_klass();
5598 int shift = flat_log_elem_size();
5599 int mask = (1 << shift) - 1;
5600 intptr_t field_offset = ((offset - header) & mask);
5601 ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5602 if (field != nullptr) {
5603 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5604 }
5605 }
5606 }
5607 return add_offset(offset - adj);
5608 }
5609
5610 // Return offset incremented by field_offset for flat inline type arrays
5611 int TypeAryPtr::flat_offset() const {
5612 int offset = _offset.get();
5613 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5614 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5615 offset += _field_offset.get();
5616 }
5617 return offset;
5618 }
5619
5620 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5621 assert(is_known_instance(), "should be known");
5622 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5623 }
5624
5625 //=============================================================================
5626
5627
5628 //------------------------------hash-------------------------------------------
5629 // Type-specific hashing function.
5630 uint TypeNarrowPtr::hash(void) const {
5631 return _ptrtype->hash() + 7;
5632 }
5633
5634 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5635 return _ptrtype->singleton();
5636 }
5637
5638 bool TypeNarrowPtr::empty(void) const {
5639 return _ptrtype->empty();
5640 }
5641
5642 intptr_t TypeNarrowPtr::get_con() const {
5643 return _ptrtype->get_con();
5644 }
5645
5646 bool TypeNarrowPtr::eq( const Type *t ) const {
5647 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5698
5699 case Int: // Mixing ints & oops happens when javac
5700 case Long: // reuses local variables
5701 case FloatTop:
5702 case FloatCon:
5703 case FloatBot:
5704 case DoubleTop:
5705 case DoubleCon:
5706 case DoubleBot:
5707 case AnyPtr:
5708 case RawPtr:
5709 case OopPtr:
5710 case InstPtr:
5711 case AryPtr:
5712 case MetadataPtr:
5713 case KlassPtr:
5714 case InstKlassPtr:
5715 case AryKlassPtr:
5716 case NarrowOop:
5717 case NarrowKlass:
5718 case Bottom: // Ye Olde Default
5719 return Type::BOTTOM;
5720 case Top:
5721 return this;
5722
5723 default: // All else is a mistake
5724 typerr(t);
5725
5726 } // End of switch
5727
5728 return this;
5729 }
5730
5731 #ifndef PRODUCT
5732 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5733 _ptrtype->dump2(d, depth, st);
5734 }
5735 #endif
5736
5737 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5781 return (one == two) && TypePtr::eq(t);
5782 } else {
5783 return one->equals(two) && TypePtr::eq(t);
5784 }
5785 }
5786
5787 //------------------------------hash-------------------------------------------
5788 // Type-specific hashing function.
5789 uint TypeMetadataPtr::hash(void) const {
5790 return
5791 (metadata() ? metadata()->hash() : 0) +
5792 TypePtr::hash();
5793 }
5794
5795 //------------------------------singleton--------------------------------------
5796 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5797 // constants
5798 bool TypeMetadataPtr::singleton(void) const {
5799 // detune optimizer to not generate constant metadata + constant offset as a constant!
5800 // TopPTR, Null, AnyNull, Constant are all singletons
5801 return (offset() == 0) && !below_centerline(_ptr);
5802 }
5803
5804 //------------------------------add_offset-------------------------------------
5805 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5806 return make( _ptr, _metadata, xadd_offset(offset));
5807 }
5808
5809 //-----------------------------filter------------------------------------------
5810 // Do not allow interface-vs.-noninterface joins to collapse to top.
5811 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5812 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5813 if (ft == nullptr || ft->empty())
5814 return Type::TOP; // Canonical empty value
5815 return ft;
5816 }
5817
5818 //------------------------------get_con----------------------------------------
5819 intptr_t TypeMetadataPtr::get_con() const {
5820 assert( _ptr == Null || _ptr == Constant, "" );
5821 assert(offset() >= 0, "");
5822
5823 if (offset() != 0) {
5824 // After being ported to the compiler interface, the compiler no longer
5825 // directly manipulates the addresses of oops. Rather, it only has a pointer
5826 // to a handle at compile time. This handle is embedded in the generated
5827 // code and dereferenced at the time the nmethod is made. Until that time,
5828 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5829 // have access to the addresses!). This does not seem to currently happen,
5830 // but this assertion here is to help prevent its occurrence.
5831 tty->print_cr("Found oop constant with non-zero offset");
5832 ShouldNotReachHere();
5833 }
5834
5835 return (intptr_t)metadata()->constant_encoding();
5836 }
5837
5838 //------------------------------cast_to_ptr_type-------------------------------
5839 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5840 if( ptr == _ptr ) return this;
5841 return make(ptr, metadata(), _offset);
5842 }
5843
5854 case Long: // reuses local variables
5855 case FloatTop:
5856 case FloatCon:
5857 case FloatBot:
5858 case DoubleTop:
5859 case DoubleCon:
5860 case DoubleBot:
5861 case NarrowOop:
5862 case NarrowKlass:
5863 case Bottom: // Ye Olde Default
5864 return Type::BOTTOM;
5865 case Top:
5866 return this;
5867
5868 default: // All else is a mistake
5869 typerr(t);
5870
5871 case AnyPtr: {
5872 // Found an AnyPtr type vs self-OopPtr type
5873 const TypePtr *tp = t->is_ptr();
5874 Offset offset = meet_offset(tp->offset());
5875 PTR ptr = meet_ptr(tp->ptr());
5876 switch (tp->ptr()) {
5877 case Null:
5878 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5879 // else fall through:
5880 case TopPTR:
5881 case AnyNull: {
5882 return make(ptr, _metadata, offset);
5883 }
5884 case BotPTR:
5885 case NotNull:
5886 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5887 default: typerr(t);
5888 }
5889 }
5890
5891 case RawPtr:
5892 case KlassPtr:
5893 case InstKlassPtr:
5894 case AryKlassPtr:
5895 case OopPtr:
5896 case InstPtr:
5897 case AryPtr:
5898 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5899
5900 case MetadataPtr: {
5901 const TypeMetadataPtr *tp = t->is_metadataptr();
5902 Offset offset = meet_offset(tp->offset());
5903 PTR tptr = tp->ptr();
5904 PTR ptr = meet_ptr(tptr);
5905 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5906 if (tptr == TopPTR || _ptr == TopPTR ||
5907 metadata()->equals(tp->metadata())) {
5908 return make(ptr, md, offset);
5909 }
5910 // metadata is different
5911 if( ptr == Constant ) { // Cannot be equal constants, so...
5912 if( tptr == Constant && _ptr != Constant) return t;
5913 if( _ptr == Constant && tptr != Constant) return this;
5914 ptr = NotNull; // Fall down in lattice
5915 }
5916 return make(ptr, nullptr, offset);
5917 break;
5918 }
5919 } // End of switch
5920 return this; // Return the double constant
5921 }
5922
5923
5924 //------------------------------xdual------------------------------------------
5925 // Dual of a pure metadata pointer.
5926 const Type *TypeMetadataPtr::xdual() const {
5927 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5928 }
5929
5930 //------------------------------dump2------------------------------------------
5931 #ifndef PRODUCT
5932 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5933 st->print("metadataptr:%s", ptr_msg[_ptr]);
5934 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5935 switch (offset()) {
5936 case OffsetTop: st->print("+top"); break;
5937 case OffsetBot: st->print("+any"); break;
5938 case 0: break;
5939 default: st->print("+%d",offset()); break;
5940 }
5941 }
5942 #endif
5943
5944
5945 //=============================================================================
5946 // Convenience common pre-built type.
5947 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5948
5949 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5950 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5951 }
5952
5953 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5954 return make(Constant, m, Offset(0));
5955 }
5956 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5957 return make(Constant, m, Offset(0));
5958 }
5959
5960 //------------------------------make-------------------------------------------
5961 // Create a meta data constant
5962 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5963 assert(m == nullptr || !m->is_klass(), "wrong type");
5964 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5965 }
5966
5967
5968 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5969 const Type* elem = _ary->_elem;
5970 bool xk = klass_is_exact();
5971 if (elem->make_oopptr() != nullptr) {
5972 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5973 if (elem->is_klassptr()->klass_is_exact() &&
5974 // Even though MyValue is final, [LMyValue is only exact if the array
5975 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5976 (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5977 xk = true;
5978 }
5979 }
5980 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5981 }
5982
5983 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5984 if (klass->is_instance_klass()) {
5985 return TypeInstKlassPtr::make(klass, interface_handling);
5986 }
5987 return TypeAryKlassPtr::make(klass, interface_handling);
5988 }
5989
5990 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
5991 if (klass->is_instance_klass()) {
5992 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5993 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5994 }
5995 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5996 }
5997
5998 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
5999 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6000 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6001 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6002 }
6003
6004 // Is there a single ciKlass* that can represent that type?
6005 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6006 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6007 if (_interfaces->empty()) {
6008 return _klass;
6009 }
6010 if (_klass != ciEnv::current()->Object_klass()) {
6011 if (_interfaces->eq(_klass->as_instance_klass())) {
6012 return _klass;
6013 }
6014 return nullptr;
6015 }
6016 return _interfaces->exact_klass();
6017 }
6018
6019 //------------------------------eq---------------------------------------------
6020 // Structural equality check for Type representations
6021 bool TypeKlassPtr::eq(const Type *t) const {
6022 const TypeKlassPtr *p = t->is_klassptr();
6023 return
6024 _interfaces->eq(p->_interfaces) &&
6025 TypePtr::eq(p);
6026 }
6027
6028 //------------------------------hash-------------------------------------------
6029 // Type-specific hashing function.
6030 uint TypeKlassPtr::hash(void) const {
6031 return TypePtr::hash() + _interfaces->hash();
6032 }
6033
6034 //------------------------------singleton--------------------------------------
6035 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6036 // constants
6037 bool TypeKlassPtr::singleton(void) const {
6038 // detune optimizer to not generate constant klass + constant offset as a constant!
6039 // TopPTR, Null, AnyNull, Constant are all singletons
6040 return (offset() == 0) && !below_centerline(_ptr);
6041 }
6042
6043 // Do not allow interface-vs.-noninterface joins to collapse to top.
6044 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6045 // logic here mirrors the one from TypeOopPtr::filter. See comments
6046 // there.
6047 const Type* ft = join_helper(kills, include_speculative);
6048 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
6049 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
6050
6051 if (ft->empty()) {
6052 return Type::TOP; // Canonical empty value
6053 }
6054
6055 return ft;
6056 }
6057
6058 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6059 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6060 return _interfaces->union_with(other->_interfaces);
6061 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6062 return other->_interfaces;
6063 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6064 return _interfaces;
6065 }
6066 return _interfaces->intersection_with(other->_interfaces);
6067 }
6068
6069 //------------------------------get_con----------------------------------------
6070 intptr_t TypeKlassPtr::get_con() const {
6071 assert( _ptr == Null || _ptr == Constant, "" );
6072 assert( offset() >= 0, "" );
6073
6074 if (offset() != 0) {
6075 // After being ported to the compiler interface, the compiler no longer
6076 // directly manipulates the addresses of oops. Rather, it only has a pointer
6077 // to a handle at compile time. This handle is embedded in the generated
6078 // code and dereferenced at the time the nmethod is made. Until that time,
6079 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6080 // have access to the addresses!). This does not seem to currently happen,
6081 // but this assertion here is to help prevent its occurrence.
6082 tty->print_cr("Found oop constant with non-zero offset");
6083 ShouldNotReachHere();
6084 }
6085
6086 ciKlass* k = exact_klass();
6087
6088 return (intptr_t)k->constant_encoding();
6089 }
6090
6091 //------------------------------dump2------------------------------------------
6092 // Dump Klass Type
6093 #ifndef PRODUCT
6094 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6098 case NotNull:
6099 {
6100 const char *name = klass()->name()->as_utf8();
6101 if (name) {
6102 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6103 } else {
6104 ShouldNotReachHere();
6105 }
6106 _interfaces->dump(st);
6107 }
6108 case BotPTR:
6109 if (!WizardMode && !Verbose && _ptr != Constant) break;
6110 case TopPTR:
6111 case AnyNull:
6112 st->print(":%s", ptr_msg[_ptr]);
6113 if (_ptr == Constant) st->print(":exact");
6114 break;
6115 default:
6116 break;
6117 }
6118 if (Verbose) {
6119 if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");
6120 }
6121 _offset.dump2(st);
6122 st->print(" *");
6123 }
6124 #endif
6125
6126 //=============================================================================
6127 // Convenience common pre-built types.
6128
6129 // Not-null object klass or below
6130 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6131 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6132
6133 bool TypeInstKlassPtr::eq(const Type *t) const {
6134 const TypeKlassPtr *p = t->is_klassptr();
6135 return
6136 klass()->equals(p->klass()) &&
6137 flat_in_array() == p->flat_in_array() &&
6138 TypeKlassPtr::eq(p);
6139 }
6140
6141 uint TypeInstKlassPtr::hash(void) const {
6142 return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6143 }
6144
6145 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6146 flat_in_array = flat_in_array || k->flat_in_array();
6147
6148 TypeInstKlassPtr *r =
6149 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6150
6151 return r;
6152 }
6153
6154 //------------------------------add_offset-------------------------------------
6155 // Access internals of klass object
6156 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6157 return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6158 }
6159
6160 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6161 return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6162 }
6163
6164 //------------------------------cast_to_ptr_type-------------------------------
6165 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6166 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6167 if( ptr == _ptr ) return this;
6168 return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6169 }
6170
6171
6172 bool TypeInstKlassPtr::must_be_exact() const {
6173 if (!_klass->is_loaded()) return false;
6174 ciInstanceKlass* ik = _klass->as_instance_klass();
6175 if (ik->is_final()) return true; // cannot clear xk
6176 return false;
6177 }
6178
6179 //-----------------------------cast_to_exactness-------------------------------
6180 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6181 if (klass_is_exact == (_ptr == Constant)) return this;
6182 if (must_be_exact()) return this;
6183 ciKlass* k = klass();
6184 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6185 }
6186
6187
6188 //-----------------------------as_instance_type--------------------------------
6189 // Corresponding type for an instance of the given class.
6190 // It will be NotNull, and exact if and only if the klass type is exact.
6191 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6192 ciKlass* k = klass();
6193 bool xk = klass_is_exact();
6194 Compile* C = Compile::current();
6195 Dependencies* deps = C->dependencies();
6196 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6197 // Element is an instance
6198 bool klass_is_exact = false;
6199 const TypeInterfaces* interfaces = _interfaces;
6200 if (k->is_loaded()) {
6201 // Try to set klass_is_exact.
6202 ciInstanceKlass* ik = k->as_instance_klass();
6203 klass_is_exact = ik->is_final();
6204 if (!klass_is_exact && klass_change
6205 && deps != nullptr && UseUniqueSubclasses) {
6206 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6207 if (sub != nullptr) {
6208 if (_interfaces->eq(sub)) {
6209 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6210 k = ik = sub;
6211 xk = sub->is_final();
6212 }
6213 }
6214 }
6215 }
6216 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6217 }
6218
6219 //------------------------------xmeet------------------------------------------
6220 // Compute the MEET of two types, return a new Type object.
6221 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6222 // Perform a fast test for common case; meeting the same types together.
6223 if( this == t ) return this; // Meeting same type-rep?
6224
6225 // Current "this->_base" is Pointer
6226 switch (t->base()) { // switch on original type
6227
6228 case Int: // Mixing ints & oops happens when javac
6229 case Long: // reuses local variables
6230 case FloatTop:
6231 case FloatCon:
6232 case FloatBot:
6233 case DoubleTop:
6234 case DoubleCon:
6235 case DoubleBot:
6236 case NarrowOop:
6237 case NarrowKlass:
6238 case Bottom: // Ye Olde Default
6239 return Type::BOTTOM;
6240 case Top:
6241 return this;
6242
6243 default: // All else is a mistake
6244 typerr(t);
6245
6246 case AnyPtr: { // Meeting to AnyPtrs
6247 // Found an AnyPtr type vs self-KlassPtr type
6248 const TypePtr *tp = t->is_ptr();
6249 Offset offset = meet_offset(tp->offset());
6250 PTR ptr = meet_ptr(tp->ptr());
6251 switch (tp->ptr()) {
6252 case TopPTR:
6253 return this;
6254 case Null:
6255 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6256 case AnyNull:
6257 return make(ptr, klass(), _interfaces, offset, flat_in_array());
6258 case BotPTR:
6259 case NotNull:
6260 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6261 default: typerr(t);
6262 }
6263 }
6264
6265 case RawPtr:
6266 case MetadataPtr:
6267 case OopPtr:
6268 case AryPtr: // Meet with AryPtr
6269 case InstPtr: // Meet with InstPtr
6270 return TypePtr::BOTTOM;
6271
6272 //
6273 // A-top }
6274 // / | \ } Tops
6275 // B-top A-any C-top }
6276 // | / | \ | } Any-nulls
6277 // B-any | C-any }
6278 // | | |
6279 // B-con A-con C-con } constants; not comparable across classes
6280 // | | |
6281 // B-not | C-not }
6282 // | \ | / | } not-nulls
6283 // B-bot A-not C-bot }
6284 // \ | / } Bottoms
6285 // A-bot }
6286 //
6287
6288 case InstKlassPtr: { // Meet two KlassPtr types
6289 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6290 Offset off = meet_offset(tkls->offset());
6291 PTR ptr = meet_ptr(tkls->ptr());
6292 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6293
6294 ciKlass* res_klass = nullptr;
6295 bool res_xk = false;
6296 bool res_flat_in_array = false;
6297 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6298 case UNLOADED:
6299 ShouldNotReachHere();
6300 case SUBTYPE:
6301 case NOT_SUBTYPE:
6302 case LCA:
6303 case QUICK: {
6304 assert(res_xk == (ptr == Constant), "");
6305 const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6306 return res;
6307 }
6308 default:
6309 ShouldNotReachHere();
6310 }
6311 } // End of case KlassPtr
6312 case AryKlassPtr: { // All arrays inherit from Object class
6313 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6314 Offset offset = meet_offset(tp->offset());
6315 PTR ptr = meet_ptr(tp->ptr());
6316 const TypeInterfaces* interfaces = meet_interfaces(tp);
6317 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6318 const TypeInterfaces* this_interfaces = _interfaces;
6319
6320 switch (ptr) {
6321 case TopPTR:
6322 case AnyNull: // Fall 'down' to dual of object klass
6323 // For instances when a subclass meets a superclass we fall
6324 // below the centerline when the superclass is exact. We need to
6325 // do the same here.
6326 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6327 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6328 } else {
6329 // cannot subclass, so the meet has to fall badly below the centerline
6330 ptr = NotNull;
6331 interfaces = _interfaces->intersection_with(tp->_interfaces);
6332 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6333 }
6334 case Constant:
6335 case NotNull:
6336 case BotPTR: // Fall down to object klass
6337 // LCA is object_klass, but if we subclass from the top we can do better
6338 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6339 // If 'this' (InstPtr) is above the centerline and it is Object class
6340 // then we can subclass in the Java class hierarchy.
6341 // For instances when a subclass meets a superclass we fall
6342 // below the centerline when the superclass is exact. We need
6343 // to do the same here.
6344 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6345 // that is, tp's array type is a subtype of my klass
6346 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6347 }
6348 }
6349 // The other case cannot happen, since I cannot be a subtype of an array.
6350 // The meet falls down to Object class below centerline.
6351 if( ptr == Constant )
6352 ptr = NotNull;
6353 interfaces = this_interfaces->intersection_with(tp_interfaces);
6354 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6355 default: typerr(t);
6356 }
6357 }
6358
6359 } // End of switch
6360 return this; // Return the double constant
6361 }
6362
6363 //------------------------------xdual------------------------------------------
6364 // Dual: compute field-by-field dual
6365 const Type *TypeInstKlassPtr::xdual() const {
6366 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6367 }
6368
6369 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6370 static_assert(std::is_base_of<T2, T1>::value, "");
6371 if (!this_one->is_loaded() || !other->is_loaded()) {
6372 return false;
6373 }
6374 if (!this_one->is_instance_type(other)) {
6375 return false;
6376 }
6377
6378 if (!other_exact) {
6379 return false;
6380 }
6381
6382 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6383 return true;
6384 }
6385
6386 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6447 const TypeInterfaces* interfaces = _interfaces;
6448 if (k->is_loaded()) {
6449 ciInstanceKlass* ik = k->as_instance_klass();
6450 bool klass_is_exact = ik->is_final();
6451 if (!klass_is_exact &&
6452 deps != nullptr) {
6453 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6454 if (sub != nullptr) {
6455 if (_interfaces->eq(sub)) {
6456 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6457 k = ik = sub;
6458 klass_is_exact = sub->is_final();
6459 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6460 }
6461 }
6462 }
6463 }
6464 return this;
6465 }
6466
6467 bool TypeInstKlassPtr::can_be_inline_array() const {
6468 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6469 }
6470
6471 bool TypeAryKlassPtr::can_be_inline_array() const {
6472 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6473 }
6474
6475 bool TypeInstPtr::can_be_inline_array() const {
6476 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6477 }
6478
6479 bool TypeAryPtr::can_be_inline_array() const {
6480 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6481 }
6482
6483 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6484 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6485 }
6486
6487 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6488 if (k->is_obj_array_klass()) {
6489 // Element is an object array. Recursively call ourself.
6490 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6491 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6492 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, null_free);
6493 } else if (k->is_type_array_klass()) {
6494 // Element is an typeArray
6495 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6496 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6497 } else if (k->is_flat_array_klass()) {
6498 ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6499 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6500 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6501 } else {
6502 ShouldNotReachHere();
6503 return nullptr;
6504 }
6505 }
6506
6507 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6508 bool null_free = k->as_array_klass()->is_elem_null_free();
6509 bool not_null_free = (ptr == Constant) ? !null_free : !k->is_flat_array_klass() && (k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false));
6510
6511 bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != nullptr &&
6512 k->as_array_klass()->element_klass()->is_inlinetype() &&
6513 !k->as_array_klass()->element_klass()->flat_in_array());
6514
6515 return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6516 }
6517
6518 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6519 return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6520 }
6521
6522 //------------------------------eq---------------------------------------------
6523 // Structural equality check for Type representations
6524 bool TypeAryKlassPtr::eq(const Type *t) const {
6525 const TypeAryKlassPtr *p = t->is_aryklassptr();
6526 return
6527 _elem == p->_elem && // Check array
6528 _not_flat == p->_not_flat &&
6529 _not_null_free == p->_not_null_free &&
6530 _null_free == p->_null_free &&
6531 TypeKlassPtr::eq(p); // Check sub-parts
6532 }
6533
6534 //------------------------------hash-------------------------------------------
6535 // Type-specific hashing function.
6536 uint TypeAryKlassPtr::hash(void) const {
6537 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6538 (uint)(_not_null_free ? 44 : 0) + (uint)(_null_free ? 45 : 0);
6539 }
6540
6541 //----------------------compute_klass------------------------------------------
6542 // Compute the defining klass for this class
6543 ciKlass* TypeAryPtr::compute_klass() const {
6544 // Compute _klass based on element type.
6545 ciKlass* k_ary = nullptr;
6546 const TypeInstPtr *tinst;
6547 const TypeAryPtr *tary;
6548 const Type* el = elem();
6549 if (el->isa_narrowoop()) {
6550 el = el->make_ptr();
6551 }
6552
6553 // Get element klass
6554 if (is_flat() && el->is_inlinetypeptr()) {
6555 // Klass is required by TypeAryPtr::flat_layout_helper() and others
6556 if (el->inline_klass() != nullptr) {
6557 k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6558 }
6559 } else if ((tinst = el->isa_instptr()) != nullptr) {
6560 // Leave k_ary at nullptr.
6561 } else if ((tary = el->isa_aryptr()) != nullptr) {
6562 // Leave k_ary at nullptr.
6563 } else if ((el->base() == Type::Top) ||
6564 (el->base() == Type::Bottom)) {
6565 // element type of Bottom occurs from meet of basic type
6566 // and object; Top occurs when doing join on Bottom.
6567 // Leave k_ary at null.
6568 } else {
6569 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6570 // Compute array klass directly from basic type
6571 k_ary = ciTypeArrayKlass::make(el->basic_type());
6572 }
6573 return k_ary;
6574 }
6575
6576 //------------------------------klass------------------------------------------
6577 // Return the defining klass for this class
6578 ciKlass* TypeAryPtr::klass() const {
6579 if( _klass ) return _klass; // Return cached value, if possible
6580
6581 // Oops, need to compute _klass and cache it
6582 ciKlass* k_ary = compute_klass();
6590 // type TypeAryPtr::OOPS. This Type is shared between all
6591 // active compilations. However, the ciKlass which represents
6592 // this Type is *not* shared between compilations, so caching
6593 // this value would result in fetching a dangling pointer.
6594 //
6595 // Recomputing the underlying ciKlass for each request is
6596 // a bit less efficient than caching, but calls to
6597 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6598 ((TypeAryPtr*)this)->_klass = k_ary;
6599 }
6600 return k_ary;
6601 }
6602
6603 // Is there a single ciKlass* that can represent that type?
6604 ciKlass* TypeAryPtr::exact_klass_helper() const {
6605 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6606 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6607 if (k == nullptr) {
6608 return nullptr;
6609 }
6610 k = ciArrayKlass::make(k, is_null_free());
6611 return k;
6612 }
6613
6614 return klass();
6615 }
6616
6617 const Type* TypeAryPtr::base_element_type(int& dims) const {
6618 const Type* elem = this->elem();
6619 dims = 1;
6620 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6621 elem = elem->make_ptr()->is_aryptr()->elem();
6622 dims++;
6623 }
6624 return elem;
6625 }
6626
6627 //------------------------------add_offset-------------------------------------
6628 // Access internals of klass object
6629 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6630 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6631 }
6632
6633 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6634 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6635 }
6636
6637 //------------------------------cast_to_ptr_type-------------------------------
6638 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6639 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6640 if (ptr == _ptr) return this;
6641 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6642 }
6643
6644 bool TypeAryKlassPtr::must_be_exact() const {
6645 if (_elem == Type::BOTTOM) return false;
6646 if (_elem == Type::TOP ) return false;
6647 const TypeKlassPtr* tk = _elem->isa_klassptr();
6648 if (!tk) return true; // a primitive type, like int
6649 // Even though MyValue is final, [LMyValue is only exact if the array
6650 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
6651 if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6652 return false;
6653 }
6654 return tk->must_be_exact();
6655 }
6656
6657
6658 //-----------------------------cast_to_exactness-------------------------------
6659 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6660 if (must_be_exact() && !klass_is_exact) return this; // cannot clear xk
6661 if (klass_is_exact == this->klass_is_exact()) {
6662 return this;
6663 }
6664 ciKlass* k = _klass;
6665 const Type* elem = this->elem();
6666 if (elem->isa_klassptr() && !klass_is_exact) {
6667 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6668 }
6669 bool not_flat = is_not_flat();
6670 bool not_null_free = is_not_null_free();
6671 if (_elem->isa_klassptr()) {
6672 if (klass_is_exact || _elem->isa_aryklassptr()) {
6673 assert(!is_null_free() && !is_flat(), "null-free (or flat) inline type arrays should always be exact");
6674 // An array can't be null-free (or flat) if the klass is exact
6675 not_null_free = true;
6676 not_flat = true;
6677 } else {
6678 // Klass is not exact (anymore), re-compute null-free/flat properties
6679 const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6680 not_null_free = !exact_etype->can_be_inline_type();
6681 not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
6682 }
6683 }
6684 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6685 }
6686
6687 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_null_free() const {
6688 return make(_ptr, elem(), klass(), _offset, is_not_flat(), false, true);
6689 }
6690
6691 //-----------------------------as_instance_type--------------------------------
6692 // Corresponding type for an instance of the given class.
6693 // It will be NotNull, and exact if and only if the klass type is exact.
6694 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6695 ciKlass* k = klass();
6696 bool xk = klass_is_exact();
6697 const Type* el = nullptr;
6698 if (elem()->isa_klassptr()) {
6699 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6700 k = nullptr;
6701 } else {
6702 el = elem();
6703 }
6704 bool null_free = _null_free;
6705 if (null_free && el->isa_ptr()) {
6706 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6707 }
6708 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6709 }
6710
6711
6712 //------------------------------xmeet------------------------------------------
6713 // Compute the MEET of two types, return a new Type object.
6714 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6715 // Perform a fast test for common case; meeting the same types together.
6716 if( this == t ) return this; // Meeting same type-rep?
6717
6718 // Current "this->_base" is Pointer
6719 switch (t->base()) { // switch on original type
6720
6721 case Int: // Mixing ints & oops happens when javac
6722 case Long: // reuses local variables
6723 case FloatTop:
6724 case FloatCon:
6725 case FloatBot:
6726 case DoubleTop:
6727 case DoubleCon:
6728 case DoubleBot:
6729 case NarrowOop:
6730 case NarrowKlass:
6731 case Bottom: // Ye Olde Default
6732 return Type::BOTTOM;
6733 case Top:
6734 return this;
6735
6736 default: // All else is a mistake
6737 typerr(t);
6738
6739 case AnyPtr: { // Meeting to AnyPtrs
6740 // Found an AnyPtr type vs self-KlassPtr type
6741 const TypePtr *tp = t->is_ptr();
6742 Offset offset = meet_offset(tp->offset());
6743 PTR ptr = meet_ptr(tp->ptr());
6744 switch (tp->ptr()) {
6745 case TopPTR:
6746 return this;
6747 case Null:
6748 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6749 case AnyNull:
6750 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
6751 case BotPTR:
6752 case NotNull:
6753 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6754 default: typerr(t);
6755 }
6756 }
6757
6758 case RawPtr:
6759 case MetadataPtr:
6760 case OopPtr:
6761 case AryPtr: // Meet with AryPtr
6762 case InstPtr: // Meet with InstPtr
6763 return TypePtr::BOTTOM;
6764
6765 //
6766 // A-top }
6767 // / | \ } Tops
6768 // B-top A-any C-top }
6769 // | / | \ | } Any-nulls
6770 // B-any | C-any }
6771 // | | |
6772 // B-con A-con C-con } constants; not comparable across classes
6773 // | | |
6774 // B-not | C-not }
6775 // | \ | / | } not-nulls
6776 // B-bot A-not C-bot }
6777 // \ | / } Bottoms
6778 // A-bot }
6779 //
6780
6781 case AryKlassPtr: { // Meet two KlassPtr types
6782 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6783 Offset off = meet_offset(tap->offset());
6784 const Type* elem = _elem->meet(tap->_elem);
6785 PTR ptr = meet_ptr(tap->ptr());
6786 ciKlass* res_klass = nullptr;
6787 bool res_xk = false;
6788 bool res_flat = false;
6789 bool res_not_flat = false;
6790 bool res_not_null_free = false;
6791 MeetResult res = meet_aryptr(ptr, elem, this, tap,
6792 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
6793 assert(res_xk == (ptr == Constant), "");
6794 bool null_free = meet_null_free(tap->_null_free);
6795 if (res == NOT_SUBTYPE) {
6796 null_free = false;
6797 } else if (res == SUBTYPE) {
6798 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6799 null_free = _null_free;
6800 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6801 null_free = tap->_null_free;
6802 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6803 null_free = _null_free || tap->_null_free;
6804 }
6805 }
6806 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6807 } // End of case KlassPtr
6808 case InstKlassPtr: {
6809 const TypeInstKlassPtr *tp = t->is_instklassptr();
6810 Offset offset = meet_offset(tp->offset());
6811 PTR ptr = meet_ptr(tp->ptr());
6812 const TypeInterfaces* interfaces = meet_interfaces(tp);
6813 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6814 const TypeInterfaces* this_interfaces = _interfaces;
6815
6816 switch (ptr) {
6817 case TopPTR:
6818 case AnyNull: // Fall 'down' to dual of object klass
6819 // For instances when a subclass meets a superclass we fall
6820 // below the centerline when the superclass is exact. We need to
6821 // do the same here.
6822 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6823 !tp->klass_is_exact()) {
6824 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6825 } else {
6826 // cannot subclass, so the meet has to fall badly below the centerline
6827 ptr = NotNull;
6828 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6829 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6830 }
6831 case Constant:
6832 case NotNull:
6833 case BotPTR: // Fall down to object klass
6834 // LCA is object_klass, but if we subclass from the top we can do better
6835 if (above_centerline(tp->ptr())) {
6836 // If 'tp' is above the centerline and it is Object class
6837 // then we can subclass in the Java class hierarchy.
6838 // For instances when a subclass meets a superclass we fall
6839 // below the centerline when the superclass is exact. We need
6840 // to do the same here.
6841 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6842 !tp->klass_is_exact()) {
6843 // that is, my array type is a subtype of 'tp' klass
6844 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6845 }
6846 }
6847 // The other case cannot happen, since t cannot be a subtype of an array.
6848 // The meet falls down to Object class below centerline.
6849 if (ptr == Constant)
6850 ptr = NotNull;
6851 interfaces = this_interfaces->intersection_with(tp_interfaces);
6852 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6853 default: typerr(t);
6854 }
6855 }
6856
6857 } // End of switch
6858 return this; // Return the double constant
6859 }
6860
6861 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6862 static_assert(std::is_base_of<T2, T1>::value, "");
6863
6864 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6865 return true;
6866 }
6867
6868 int dummy;
6869 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6870
6871 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6872 return false;
6873 }
6874
6875 if (this_one->is_instance_type(other)) {
6876 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6877 other_exact;
6878 }
6879
6880 assert(this_one->is_array_type(other), "");
6881 const T1* other_ary = this_one->is_array_type(other);
6882 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6883 if (other_top_or_bottom) {
6884 return false;
6885 }
6886
6887 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6888 const TypePtr* this_elem = this_one->elem()->make_ptr();
6889 if (this_elem != nullptr && other_elem != nullptr) {
6890 if (other->is_null_free() && !this_one->is_null_free()) {
6891 return false; // A nullable array can't be a subtype of a null-free array
6892 }
6893 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6894 }
6895 if (this_elem == nullptr && other_elem == nullptr) {
6896 return this_one->klass()->is_subtype_of(other->klass());
6897 }
6898 return false;
6899 }
6900
6901 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6902 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6903 }
6904
6905 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6906 static_assert(std::is_base_of<T2, T1>::value, "");
6907
6908 int dummy;
6909 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6910
6911 if (!this_one->is_array_type(other) ||
6912 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6965 }
6966
6967 const TypePtr* this_elem = this_one->elem()->make_ptr();
6968 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6969 if (other_elem != nullptr && this_elem != nullptr) {
6970 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6971 }
6972 if (other_elem == nullptr && this_elem == nullptr) {
6973 return this_one->klass()->is_subtype_of(other->klass());
6974 }
6975 return false;
6976 }
6977
6978 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6979 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6980 }
6981
6982 //------------------------------xdual------------------------------------------
6983 // Dual: compute field-by-field dual
6984 const Type *TypeAryKlassPtr::xdual() const {
6985 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6986 }
6987
6988 // Is there a single ciKlass* that can represent that type?
6989 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6990 if (elem()->isa_klassptr()) {
6991 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6992 if (k == nullptr) {
6993 return nullptr;
6994 }
6995 k = ciArrayKlass::make(k, _null_free);
6996 return k;
6997 }
6998
6999 return klass();
7000 }
7001
7002 ciKlass* TypeAryKlassPtr::klass() const {
7003 if (_klass != nullptr) {
7004 return _klass;
7005 }
7006 ciKlass* k = nullptr;
7007 if (elem()->isa_klassptr()) {
7008 // leave null
7009 } else if ((elem()->base() == Type::Top) ||
7010 (elem()->base() == Type::Bottom)) {
7011 } else {
7012 k = ciTypeArrayKlass::make(elem()->basic_type());
7013 ((TypeAryKlassPtr*)this)->_klass = k;
7014 }
7015 return k;
7022 switch( _ptr ) {
7023 case Constant:
7024 st->print("precise ");
7025 case NotNull:
7026 {
7027 st->print("[");
7028 _elem->dump2(d, depth, st);
7029 _interfaces->dump(st);
7030 st->print(": ");
7031 }
7032 case BotPTR:
7033 if( !WizardMode && !Verbose && _ptr != Constant ) break;
7034 case TopPTR:
7035 case AnyNull:
7036 st->print(":%s", ptr_msg[_ptr]);
7037 if( _ptr == Constant ) st->print(":exact");
7038 break;
7039 default:
7040 break;
7041 }
7042 if (is_flat()) st->print(":flat");
7043 if (_null_free) st->print(":null free");
7044 if (Verbose) {
7045 if (_not_flat) st->print(":not flat");
7046 if (_not_null_free) st->print(":not null free");
7047 }
7048
7049 _offset.dump2(st);
7050
7051 st->print(" *");
7052 }
7053 #endif
7054
7055 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7056 const Type* elem = this->elem();
7057 dims = 1;
7058 while (elem->isa_aryklassptr()) {
7059 elem = elem->is_aryklassptr()->elem();
7060 dims++;
7061 }
7062 return elem;
7063 }
7064
7065 //=============================================================================
7066 // Convenience common pre-built types.
7067
7068 //------------------------------make-------------------------------------------
7069 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7070 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7071 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7072 }
7073
7074 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7075 return make(domain, domain, range, range);
7076 }
7077
7078 //------------------------------osr_domain-----------------------------
7079 const TypeTuple* osr_domain() {
7080 const Type **fields = TypeTuple::fields(2);
7081 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7082 return TypeTuple::make(TypeFunc::Parms+1, fields);
7083 }
7084
7085 //------------------------------make-------------------------------------------
7086 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7087 Compile* C = Compile::current();
7088 const TypeFunc* tf = nullptr;
7089 if (!is_osr_compilation) {
7090 tf = C->last_tf(method); // check cache
7091 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7092 }
7093 // Inline types are not passed/returned by reference, instead each field of
7094 // the inline type is passed/returned as an argument. We maintain two views of
7095 // the argument/return list here: one based on the signature (with an inline
7096 // type argument/return as a single slot), one based on the actual calling
7097 // convention (with an inline type argument/return as a list of its fields).
7098 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7099 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7100 if (method != C->method() && method->get_Method()->mismatch()) {
7101 has_scalar_args = false;
7102 }
7103 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7104 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7105 ciSignature* sig = method->signature();
7106 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7107 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7108 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7109 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7110 if (!is_osr_compilation) {
7111 C->set_last_tf(method, tf); // fill cache
7112 }
7113 return tf;
7114 }
7115
7116 //------------------------------meet-------------------------------------------
7117 // Compute the MEET of two types. It returns a new Type object.
7118 const Type *TypeFunc::xmeet( const Type *t ) const {
7119 // Perform a fast test for common case; meeting the same types together.
7120 if( this == t ) return this; // Meeting same type-rep?
7121
7122 // Current "this->_base" is Func
7123 switch (t->base()) { // switch on original type
7124
7125 case Bottom: // Ye Olde Default
7126 return t;
7127
7128 default: // All else is a mistake
7129 typerr(t);
7130
7131 case Top:
7132 break;
7133 }
7134 return this; // Return the double constant
7135 }
7136
7137 //------------------------------xdual------------------------------------------
7138 // Dual: compute field-by-field dual
7139 const Type *TypeFunc::xdual() const {
7140 return this;
7141 }
7142
7143 //------------------------------eq---------------------------------------------
7144 // Structural equality check for Type representations
7145 bool TypeFunc::eq( const Type *t ) const {
7146 const TypeFunc *a = (const TypeFunc*)t;
7147 return _domain_sig == a->_domain_sig &&
7148 _domain_cc == a->_domain_cc &&
7149 _range_sig == a->_range_sig &&
7150 _range_cc == a->_range_cc;
7151 }
7152
7153 //------------------------------hash-------------------------------------------
7154 // Type-specific hashing function.
7155 uint TypeFunc::hash(void) const {
7156 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7157 }
7158
7159 //------------------------------dump2------------------------------------------
7160 // Dump Function Type
7161 #ifndef PRODUCT
7162 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7163 if( _range_sig->cnt() <= Parms )
7164 st->print("void");
7165 else {
7166 uint i;
7167 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7168 _range_sig->field_at(i)->dump2(d,depth,st);
7169 st->print("/");
7170 }
7171 _range_sig->field_at(i)->dump2(d,depth,st);
7172 }
7173 st->print(" ");
7174 st->print("( ");
7175 if( !depth || d[this] ) { // Check for recursive dump
7176 st->print("...)");
7177 return;
7178 }
7179 d.Insert((void*)this,(void*)this); // Stop recursion
7180 if (Parms < _domain_sig->cnt())
7181 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7182 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7183 st->print(", ");
7184 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7185 }
7186 st->print(" )");
7187 }
7188 #endif
7189
7190 //------------------------------singleton--------------------------------------
7191 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7192 // constants (Ldi nodes). Singletons are integer, float or double constants
7193 // or a single symbol.
7194 bool TypeFunc::singleton(void) const {
7195 return false; // Never a singleton
7196 }
7197
7198 bool TypeFunc::empty(void) const {
7199 return false; // Never empty
7200 }
7201
7202
7203 BasicType TypeFunc::return_type() const{
7204 if (range_sig()->cnt() == TypeFunc::Parms) {
7205 return T_VOID;
7206 }
7207 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7208 }
|