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(T_BOOLEAN, 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
2627
2628 //=============================================================================
2629 // Convenience common pre-built types.
2630 const TypePtr *TypePtr::NULL_PTR;
2631 const TypePtr *TypePtr::NOTNULL;
2632 const TypePtr *TypePtr::BOTTOM;
2633
2634 //------------------------------meet-------------------------------------------
2635 // Meet over the PTR enum
2636 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2637 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2638 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2639 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2640 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2641 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2642 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2643 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2644 };
2645
2646 //------------------------------make-------------------------------------------
2647 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2648 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2649 }
2650
2651 //------------------------------cast_to_ptr_type-------------------------------
2652 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2653 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2654 if( ptr == _ptr ) return this;
2655 return make(_base, ptr, _offset, _speculative, _inline_depth);
2656 }
2657
2658 //------------------------------get_con----------------------------------------
2659 intptr_t TypePtr::get_con() const {
2660 assert( _ptr == Null, "" );
2661 return _offset;
2662 }
2663
2664 //------------------------------meet-------------------------------------------
2665 // Compute the MEET of two types. It returns a new Type object.
2666 const Type *TypePtr::xmeet(const Type *t) const {
2667 const Type* res = xmeet_helper(t);
2668 if (res->isa_ptr() == nullptr) {
2669 return res;
2670 }
2671
2672 const TypePtr* res_ptr = res->is_ptr();
2673 if (res_ptr->speculative() != nullptr) {
2674 // type->speculative() is null means that speculation is no better
2675 // than type, i.e. type->speculative() == type. So there are 2
2676 // ways to represent the fact that we have no useful speculative
2677 // data and we should use a single one to be able to test for
2678 // equality between types. Check whether type->speculative() ==
2679 // type and set speculative to null if it is the case.
2680 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2681 return res_ptr->remove_speculative();
2712 int depth = meet_inline_depth(tp->inline_depth());
2713 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2714 }
2715 case RawPtr: // For these, flip the call around to cut down
2716 case OopPtr:
2717 case InstPtr: // on the cases I have to handle.
2718 case AryPtr:
2719 case MetadataPtr:
2720 case KlassPtr:
2721 case InstKlassPtr:
2722 case AryKlassPtr:
2723 return t->xmeet(this); // Call in reverse direction
2724 default: // All else is a mistake
2725 typerr(t);
2726
2727 }
2728 return this;
2729 }
2730
2731 //------------------------------meet_offset------------------------------------
2732 int TypePtr::meet_offset( int offset ) const {
2733 // Either is 'TOP' offset? Return the other offset!
2734 if( _offset == OffsetTop ) return offset;
2735 if( offset == OffsetTop ) return _offset;
2736 // If either is different, return 'BOTTOM' offset
2737 if( _offset != offset ) return OffsetBot;
2738 return _offset;
2739 }
2740
2741 //------------------------------dual_offset------------------------------------
2742 int TypePtr::dual_offset( ) const {
2743 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2744 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2745 return _offset; // Map everything else into self
2746 }
2747
2748 //------------------------------xdual------------------------------------------
2749 // Dual: compute field-by-field dual
2750 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2751 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2752 };
2753 const Type *TypePtr::xdual() const {
2754 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2755 }
2756
2757 //------------------------------xadd_offset------------------------------------
2758 int TypePtr::xadd_offset( intptr_t offset ) const {
2759 // Adding to 'TOP' offset? Return 'TOP'!
2760 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2761 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2762 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2763 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2764 offset += (intptr_t)_offset;
2765 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2766
2767 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2768 // It is possible to construct a negative offset during PhaseCCP
2769
2770 return (int)offset; // Sum valid offsets
2771 }
2772
2773 //------------------------------add_offset-------------------------------------
2774 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2775 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2776 }
2777
2778 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2779 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2780 }
2781
2782 //------------------------------eq---------------------------------------------
2783 // Structural equality check for Type representations
2784 bool TypePtr::eq( const Type *t ) const {
2785 const TypePtr *a = (const TypePtr*)t;
2786 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2787 }
2788
2789 //------------------------------hash-------------------------------------------
2790 // Type-specific hashing function.
2791 uint TypePtr::hash(void) const {
2792 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2793 }
2794
2795 /**
2796 * Return same type without a speculative part
2797 */
2798 const TypePtr* TypePtr::remove_speculative() const {
2799 if (_speculative == nullptr) {
2800 return this;
2801 }
2802 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2803 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2804 }
2805
2806 /**
2807 * Return same type but drop speculative part if we know we won't use
2808 * it
2809 */
2810 const Type* TypePtr::cleanup_speculative() const {
2811 if (speculative() == nullptr) {
2812 return this;
3038 }
3039 // We already know the speculative type is always null
3040 if (speculative_always_null()) {
3041 return false;
3042 }
3043 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3044 return false;
3045 }
3046 return true;
3047 }
3048
3049 //------------------------------dump2------------------------------------------
3050 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3051 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3052 };
3053
3054 #ifndef PRODUCT
3055 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3056 if( _ptr == Null ) st->print("null");
3057 else st->print("%s *", ptr_msg[_ptr]);
3058 if( _offset == OffsetTop ) st->print("+top");
3059 else if( _offset == OffsetBot ) st->print("+bot");
3060 else if( _offset ) st->print("+%d", _offset);
3061 dump_inline_depth(st);
3062 dump_speculative(st);
3063 }
3064
3065 /**
3066 *dump the speculative part of the type
3067 */
3068 void TypePtr::dump_speculative(outputStream *st) const {
3069 if (_speculative != nullptr) {
3070 st->print(" (speculative=");
3071 _speculative->dump_on(st);
3072 st->print(")");
3073 }
3074 }
3075
3076 /**
3077 *dump the inline depth of the type
3078 */
3079 void TypePtr::dump_inline_depth(outputStream *st) const {
3080 if (_inline_depth != InlineDepthBottom) {
3081 if (_inline_depth == InlineDepthTop) {
3082 st->print(" (inline_depth=InlineDepthTop)");
3083 } else {
3084 st->print(" (inline_depth=%d)", _inline_depth);
3085 }
3086 }
3087 }
3088 #endif
3089
3090 //------------------------------singleton--------------------------------------
3091 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3092 // constants
3093 bool TypePtr::singleton(void) const {
3094 // TopPTR, Null, AnyNull, Constant are all singletons
3095 return (_offset != OffsetBot) && !below_centerline(_ptr);
3096 }
3097
3098 bool TypePtr::empty(void) const {
3099 return (_offset == OffsetTop) || above_centerline(_ptr);
3100 }
3101
3102 //=============================================================================
3103 // Convenience common pre-built types.
3104 const TypeRawPtr *TypeRawPtr::BOTTOM;
3105 const TypeRawPtr *TypeRawPtr::NOTNULL;
3106
3107 //------------------------------make-------------------------------------------
3108 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3109 assert( ptr != Constant, "what is the constant?" );
3110 assert( ptr != Null, "Use TypePtr for null" );
3111 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3112 }
3113
3114 const TypeRawPtr *TypeRawPtr::make(address bits) {
3115 assert(bits != nullptr, "Use TypePtr for null");
3116 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3117 }
3118
3119 //------------------------------cast_to_ptr_type-------------------------------
3480 void TypeInterfaces::verify_is_loaded() const {
3481 for (int i = 0; i < _interfaces.length(); i++) {
3482 ciKlass* interface = _interfaces.at(i);
3483 assert(interface->is_loaded(), "Interface not loaded");
3484 }
3485 }
3486 #endif
3487
3488 // Can't be implemented because there's no way to know if the type is above or below the center line.
3489 const Type* TypeInterfaces::xmeet(const Type* t) const {
3490 ShouldNotReachHere();
3491 return Type::xmeet(t);
3492 }
3493
3494 bool TypeInterfaces::singleton(void) const {
3495 ShouldNotReachHere();
3496 return Type::singleton();
3497 }
3498
3499 //------------------------------TypeOopPtr-------------------------------------
3500 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3501 int instance_id, const TypePtr* speculative, int inline_depth)
3502 : TypePtr(t, ptr, offset, speculative, inline_depth),
3503 _const_oop(o), _klass(k),
3504 _interfaces(interfaces),
3505 _klass_is_exact(xk),
3506 _is_ptr_to_narrowoop(false),
3507 _is_ptr_to_narrowklass(false),
3508 _is_ptr_to_boxed_value(false),
3509 _instance_id(instance_id) {
3510 #ifdef ASSERT
3511 if (klass() != nullptr && klass()->is_loaded()) {
3512 interfaces->verify_is_loaded();
3513 }
3514 #endif
3515 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3516 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3517 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3518 }
3519 #ifdef _LP64
3520 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3521 if (_offset == oopDesc::klass_offset_in_bytes()) {
3522 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3523 } else if (klass() == nullptr) {
3524 // Array with unknown body type
3525 assert(this->isa_aryptr(), "only arrays without klass");
3526 _is_ptr_to_narrowoop = UseCompressedOops;
3527 } else if (this->isa_aryptr()) {
3528 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3529 _offset != arrayOopDesc::length_offset_in_bytes());
3530 } else if (klass()->is_instance_klass()) {
3531 ciInstanceKlass* ik = klass()->as_instance_klass();
3532 if (this->isa_klassptr()) {
3533 // Perm objects don't use compressed references
3534 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3535 // unsafe access
3536 _is_ptr_to_narrowoop = UseCompressedOops;
3537 } else {
3538 assert(this->isa_instptr(), "must be an instance ptr.");
3539
3540 if (klass() == ciEnv::current()->Class_klass() &&
3541 (_offset == java_lang_Class::klass_offset() ||
3542 _offset == java_lang_Class::array_klass_offset())) {
3543 // Special hidden fields from the Class.
3544 assert(this->isa_instptr(), "must be an instance ptr.");
3545 _is_ptr_to_narrowoop = false;
3546 } else if (klass() == ciEnv::current()->Class_klass() &&
3547 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3548 // Static fields
3549 ciField* field = nullptr;
3550 if (const_oop() != nullptr) {
3551 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3552 field = k->get_field_by_offset(_offset, true);
3553 }
3554 if (field != nullptr) {
3555 BasicType basic_elem_type = field->layout_type();
3556 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3557 } else {
3558 // unsafe access
3559 _is_ptr_to_narrowoop = UseCompressedOops;
3560 }
3561 } else {
3562 // Instance fields which contains a compressed oop references.
3563 ciField* field = ik->get_field_by_offset(_offset, false);
3564 if (field != nullptr) {
3565 BasicType basic_elem_type = field->layout_type();
3566 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3567 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3568 // Compile::find_alias_type() cast exactness on all types to verify
3569 // that it does not affect alias type.
3570 _is_ptr_to_narrowoop = UseCompressedOops;
3571 } else {
3572 // Type for the copy start in LibraryCallKit::inline_native_clone().
3573 _is_ptr_to_narrowoop = UseCompressedOops;
3574 }
3575 }
3576 }
3577 }
3578 }
3579 #endif
3580 }
3581
3582 //------------------------------make-------------------------------------------
3583 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3584 const TypePtr* speculative, int inline_depth) {
3585 assert(ptr != Constant, "no constant generic pointers");
3586 ciKlass* k = Compile::current()->env()->Object_klass();
3587 bool xk = false;
3588 ciObject* o = nullptr;
3589 const TypeInterfaces* interfaces = TypeInterfaces::make();
3590 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3591 }
3592
3593
3594 //------------------------------cast_to_ptr_type-------------------------------
3595 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3596 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3597 if( ptr == _ptr ) return this;
3598 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3599 }
3600
3601 //-----------------------------cast_to_instance_id----------------------------
3602 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3603 // There are no instances of a general oop.
3604 // Return self unchanged.
3605 return this;
3606 }
3607
3608 //-----------------------------cast_to_exactness-------------------------------
3609 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3610 // There is no such thing as an exact general oop.
3611 // Return self unchanged.
3612 return this;
3613 }
3614
3615
3616 //------------------------------as_klass_type----------------------------------
3617 // Return the klass type corresponding to this instance or array type.
3618 // It is the type that is loaded from an object of this type.
3619 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3620 ShouldNotReachHere();
3621 return nullptr;
3622 }
3623
3624 //------------------------------meet-------------------------------------------
3625 // Compute the MEET of two types. It returns a new Type object.
3626 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3627 // Perform a fast test for common case; meeting the same types together.
3628 if( this == t ) return this; // Meeting same type-rep?
3629
3630 // Current "this->_base" is OopPtr
3631 switch (t->base()) { // switch on original type
3632
3633 case Int: // Mixing ints & oops happens when javac
3634 case Long: // reuses local variables
3635 case FloatTop:
3641 case NarrowOop:
3642 case NarrowKlass:
3643 case Bottom: // Ye Olde Default
3644 return Type::BOTTOM;
3645 case Top:
3646 return this;
3647
3648 default: // All else is a mistake
3649 typerr(t);
3650
3651 case RawPtr:
3652 case MetadataPtr:
3653 case KlassPtr:
3654 case InstKlassPtr:
3655 case AryKlassPtr:
3656 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3657
3658 case AnyPtr: {
3659 // Found an AnyPtr type vs self-OopPtr type
3660 const TypePtr *tp = t->is_ptr();
3661 int offset = meet_offset(tp->offset());
3662 PTR ptr = meet_ptr(tp->ptr());
3663 const TypePtr* speculative = xmeet_speculative(tp);
3664 int depth = meet_inline_depth(tp->inline_depth());
3665 switch (tp->ptr()) {
3666 case Null:
3667 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3668 // else fall through:
3669 case TopPTR:
3670 case AnyNull: {
3671 int instance_id = meet_instance_id(InstanceTop);
3672 return make(ptr, offset, instance_id, speculative, depth);
3673 }
3674 case BotPTR:
3675 case NotNull:
3676 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3677 default: typerr(t);
3678 }
3679 }
3680
3681 case OopPtr: { // Meeting to other OopPtrs
3683 int instance_id = meet_instance_id(tp->instance_id());
3684 const TypePtr* speculative = xmeet_speculative(tp);
3685 int depth = meet_inline_depth(tp->inline_depth());
3686 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3687 }
3688
3689 case InstPtr: // For these, flip the call around to cut down
3690 case AryPtr:
3691 return t->xmeet(this); // Call in reverse direction
3692
3693 } // End of switch
3694 return this; // Return the double constant
3695 }
3696
3697
3698 //------------------------------xdual------------------------------------------
3699 // Dual of a pure heap pointer. No relevant klass or oop information.
3700 const Type *TypeOopPtr::xdual() const {
3701 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3702 assert(const_oop() == nullptr, "no constants here");
3703 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3704 }
3705
3706 //--------------------------make_from_klass_common-----------------------------
3707 // Computes the element-type given a klass.
3708 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3709 if (klass->is_instance_klass()) {
3710 Compile* C = Compile::current();
3711 Dependencies* deps = C->dependencies();
3712 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3713 // Element is an instance
3714 bool klass_is_exact = false;
3715 if (klass->is_loaded()) {
3716 // Try to set klass_is_exact.
3717 ciInstanceKlass* ik = klass->as_instance_klass();
3718 klass_is_exact = ik->is_final();
3719 if (!klass_is_exact && klass_change
3720 && deps != nullptr && UseUniqueSubclasses) {
3721 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3722 if (sub != nullptr) {
3723 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3724 klass = ik = sub;
3725 klass_is_exact = sub->is_final();
3726 }
3727 }
3728 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3729 !ik->is_interface() && !ik->has_subklass()) {
3730 // Add a dependence; if concrete subclass added we need to recompile
3731 deps->assert_leaf_type(ik);
3732 klass_is_exact = true;
3733 }
3734 }
3735 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3736 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3737 } else if (klass->is_obj_array_klass()) {
3738 // Element is an object array. Recursively call ourself.
3739 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3740 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3741 bool xk = etype->klass_is_exact();
3742 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3743 // We used to pass NotNull in here, asserting that the sub-arrays
3744 // are all not-null. This is not true in generally, as code can
3745 // slam nulls down in the subarrays.
3746 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3747 return arr;
3748 } else if (klass->is_type_array_klass()) {
3749 // Element is an typeArray
3750 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3751 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3752 // We used to pass NotNull in here, asserting that the array pointer
3753 // is not-null. That was not true in general.
3754 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3755 return arr;
3756 } else {
3757 ShouldNotReachHere();
3758 return nullptr;
3759 }
3760 }
3761
3762 //------------------------------make_from_constant-----------------------------
3763 // Make a java pointer from an oop constant
3764 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3765 assert(!o->is_null_object(), "null object not yet handled here.");
3766
3767 const bool make_constant = require_constant || o->should_be_constant();
3768
3769 ciKlass* klass = o->klass();
3770 if (klass->is_instance_klass()) {
3771 // Element is an instance
3772 if (make_constant) {
3773 return TypeInstPtr::make(o);
3774 } else {
3775 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3776 }
3777 } else if (klass->is_obj_array_klass()) {
3778 // Element is an object array. Recursively call ourself.
3779 const TypeOopPtr *etype =
3780 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3781 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3782 // We used to pass NotNull in here, asserting that the sub-arrays
3783 // are all not-null. This is not true in generally, as code can
3784 // slam nulls down in the subarrays.
3785 if (make_constant) {
3786 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3787 } else {
3788 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3789 }
3790 } else if (klass->is_type_array_klass()) {
3791 // Element is an typeArray
3792 const Type* etype =
3793 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3794 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3795 // We used to pass NotNull in here, asserting that the array pointer
3796 // is not-null. That was not true in general.
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 }
3803
3804 fatal("unhandled object type");
3805 return nullptr;
3806 }
3807
3808 //------------------------------get_con----------------------------------------
3809 intptr_t TypeOopPtr::get_con() const {
3810 assert( _ptr == Null || _ptr == Constant, "" );
3811 assert( _offset >= 0, "" );
3812
3813 if (_offset != 0) {
3814 // After being ported to the compiler interface, the compiler no longer
3815 // directly manipulates the addresses of oops. Rather, it only has a pointer
3816 // to a handle at compile time. This handle is embedded in the generated
3817 // code and dereferenced at the time the nmethod is made. Until that time,
3818 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3819 // have access to the addresses!). This does not seem to currently happen,
3820 // but this assertion here is to help prevent its occurrence.
3821 tty->print_cr("Found oop constant with non-zero offset");
3822 ShouldNotReachHere();
3823 }
3824
3825 return (intptr_t)const_oop()->constant_encoding();
3826 }
3827
3828
3829 //-----------------------------filter------------------------------------------
3830 // Do not allow interface-vs.-noninterface joins to collapse to top.
3831 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3832
3833 const Type* ft = join_helper(kills, include_speculative);
3854 } else {
3855 return one->equals(two) && TypePtr::eq(t);
3856 }
3857 }
3858
3859 //------------------------------hash-------------------------------------------
3860 // Type-specific hashing function.
3861 uint TypeOopPtr::hash(void) const {
3862 return
3863 (uint)(const_oop() ? const_oop()->hash() : 0) +
3864 (uint)_klass_is_exact +
3865 (uint)_instance_id + TypePtr::hash();
3866 }
3867
3868 //------------------------------dump2------------------------------------------
3869 #ifndef PRODUCT
3870 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3871 st->print("oopptr:%s", ptr_msg[_ptr]);
3872 if( _klass_is_exact ) st->print(":exact");
3873 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3874 switch( _offset ) {
3875 case OffsetTop: st->print("+top"); break;
3876 case OffsetBot: st->print("+any"); break;
3877 case 0: break;
3878 default: st->print("+%d",_offset); break;
3879 }
3880 if (_instance_id == InstanceTop)
3881 st->print(",iid=top");
3882 else if (_instance_id != InstanceBot)
3883 st->print(",iid=%d",_instance_id);
3884
3885 dump_inline_depth(st);
3886 dump_speculative(st);
3887 }
3888 #endif
3889
3890 //------------------------------singleton--------------------------------------
3891 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3892 // constants
3893 bool TypeOopPtr::singleton(void) const {
3894 // detune optimizer to not generate constant oop + constant offset as a constant!
3895 // TopPTR, Null, AnyNull, Constant are all singletons
3896 return (_offset == 0) && !below_centerline(_ptr);
3897 }
3898
3899 //------------------------------add_offset-------------------------------------
3900 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3901 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3902 }
3903
3904 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3905 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3906 }
3907
3908 /**
3909 * Return same type without a speculative part
3910 */
3911 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3912 if (_speculative == nullptr) {
3913 return this;
3914 }
3915 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3916 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3917 }
3918
3919 /**
3920 * Return same type but drop speculative part if we know we won't use
3921 * it
3922 */
3923 const Type* TypeOopPtr::cleanup_speculative() const {
3924 // If the klass is exact and the ptr is not null then there's
3925 // nothing that the speculative type can help us with
3998 const TypeInstPtr *TypeInstPtr::BOTTOM;
3999 const TypeInstPtr *TypeInstPtr::MIRROR;
4000 const TypeInstPtr *TypeInstPtr::MARK;
4001 const TypeInstPtr *TypeInstPtr::KLASS;
4002
4003 // Is there a single ciKlass* that can represent that type?
4004 ciKlass* TypeInstPtr::exact_klass_helper() const {
4005 if (_interfaces->empty()) {
4006 return _klass;
4007 }
4008 if (_klass != ciEnv::current()->Object_klass()) {
4009 if (_interfaces->eq(_klass->as_instance_klass())) {
4010 return _klass;
4011 }
4012 return nullptr;
4013 }
4014 return _interfaces->exact_klass();
4015 }
4016
4017 //------------------------------TypeInstPtr-------------------------------------
4018 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4019 int instance_id, const TypePtr* speculative, int inline_depth)
4020 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4021 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4022 assert(k != nullptr &&
4023 (k->is_loaded() || o == nullptr),
4024 "cannot have constants with non-loaded klass");
4025 };
4026
4027 //------------------------------make-------------------------------------------
4028 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4029 ciKlass* k,
4030 const TypeInterfaces* interfaces,
4031 bool xk,
4032 ciObject* o,
4033 int offset,
4034 int instance_id,
4035 const TypePtr* speculative,
4036 int inline_depth) {
4037 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4038 // Either const_oop() is null or else ptr is Constant
4039 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4040 "constant pointers must have a value supplied" );
4041 // Ptr is never Null
4042 assert( ptr != Null, "null pointers are not typed" );
4043
4044 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4045 if (ptr == Constant) {
4046 // Note: This case includes meta-object constants, such as methods.
4047 xk = true;
4048 } else if (k->is_loaded()) {
4049 ciInstanceKlass* ik = k->as_instance_klass();
4050 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4051 assert(!ik->is_interface(), "no interface here");
4052 if (xk && ik->is_interface()) xk = false; // no exact interface
4053 }
4054
4055 // Now hash this baby
4056 TypeInstPtr *result =
4057 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4058
4059 return result;
4060 }
4061
4062 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4063 if (k->is_instance_klass()) {
4064 if (k->is_loaded()) {
4065 if (k->is_interface() && interface_handling == ignore_interfaces) {
4066 assert(interface, "no interface expected");
4067 k = ciEnv::current()->Object_klass();
4068 const TypeInterfaces* interfaces = TypeInterfaces::make();
4069 return interfaces;
4070 }
4071 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4072 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4073 if (k->is_interface()) {
4074 assert(interface, "no interface expected");
4075 k = ciEnv::current()->Object_klass();
4076 } else {
4077 assert(klass, "no instance klass expected");
4103 switch (bt) {
4104 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4105 case T_INT: return TypeInt::make(constant.as_int());
4106 case T_CHAR: return TypeInt::make(constant.as_char());
4107 case T_BYTE: return TypeInt::make(constant.as_byte());
4108 case T_SHORT: return TypeInt::make(constant.as_short());
4109 case T_FLOAT: return TypeF::make(constant.as_float());
4110 case T_DOUBLE: return TypeD::make(constant.as_double());
4111 case T_LONG: return TypeLong::make(constant.as_long());
4112 default: break;
4113 }
4114 fatal("Invalid boxed value type '%s'", type2name(bt));
4115 return nullptr;
4116 }
4117
4118 //------------------------------cast_to_ptr_type-------------------------------
4119 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4120 if( ptr == _ptr ) return this;
4121 // Reconstruct _sig info here since not a problem with later lazy
4122 // construction, _sig will show up on demand.
4123 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4124 }
4125
4126
4127 //-----------------------------cast_to_exactness-------------------------------
4128 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4129 if( klass_is_exact == _klass_is_exact ) return this;
4130 if (!_klass->is_loaded()) return this;
4131 ciInstanceKlass* ik = _klass->as_instance_klass();
4132 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4133 assert(!ik->is_interface(), "no interface here");
4134 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4135 }
4136
4137 //-----------------------------cast_to_instance_id----------------------------
4138 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4139 if( instance_id == _instance_id ) return this;
4140 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4141 }
4142
4143 //------------------------------xmeet_unloaded---------------------------------
4144 // Compute the MEET of two InstPtrs when at least one is unloaded.
4145 // Assume classes are different since called after check for same name/class-loader
4146 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4147 int off = meet_offset(tinst->offset());
4148 PTR ptr = meet_ptr(tinst->ptr());
4149 int instance_id = meet_instance_id(tinst->instance_id());
4150 const TypePtr* speculative = xmeet_speculative(tinst);
4151 int depth = meet_inline_depth(tinst->inline_depth());
4152
4153 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4154 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4155 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4156 //
4157 // Meet unloaded class with java/lang/Object
4158 //
4159 // Meet
4160 // | Unloaded Class
4161 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4162 // ===================================================================
4163 // TOP | ..........................Unloaded......................|
4164 // AnyNull | U-AN |................Unloaded......................|
4165 // Constant | ... O-NN .................................. | O-BOT |
4166 // NotNull | ... O-NN .................................. | O-BOT |
4167 // BOTTOM | ........................Object-BOTTOM ..................|
4168 //
4169 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4170 //
4171 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4172 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4173 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4174 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4175 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4176 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4177 }
4178 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4179
4180 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4181 }
4182
4183 // Both are unloaded, not the same class, not Object
4184 // Or meet unloaded with a different loaded class, not java/lang/Object
4185 if (ptr != TypePtr::BotPTR) {
4186 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4187 }
4188 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4189 }
4190
4191
4192 //------------------------------meet-------------------------------------------
4213 case Top:
4214 return this;
4215
4216 default: // All else is a mistake
4217 typerr(t);
4218
4219 case MetadataPtr:
4220 case KlassPtr:
4221 case InstKlassPtr:
4222 case AryKlassPtr:
4223 case RawPtr: return TypePtr::BOTTOM;
4224
4225 case AryPtr: { // All arrays inherit from Object class
4226 // Call in reverse direction to avoid duplication
4227 return t->is_aryptr()->xmeet_helper(this);
4228 }
4229
4230 case OopPtr: { // Meeting to OopPtrs
4231 // Found a OopPtr type vs self-InstPtr type
4232 const TypeOopPtr *tp = t->is_oopptr();
4233 int offset = meet_offset(tp->offset());
4234 PTR ptr = meet_ptr(tp->ptr());
4235 switch (tp->ptr()) {
4236 case TopPTR:
4237 case AnyNull: {
4238 int instance_id = meet_instance_id(InstanceTop);
4239 const TypePtr* speculative = xmeet_speculative(tp);
4240 int depth = meet_inline_depth(tp->inline_depth());
4241 return make(ptr, klass(), _interfaces, klass_is_exact(),
4242 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4243 }
4244 case NotNull:
4245 case BotPTR: {
4246 int instance_id = meet_instance_id(tp->instance_id());
4247 const TypePtr* speculative = xmeet_speculative(tp);
4248 int depth = meet_inline_depth(tp->inline_depth());
4249 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4250 }
4251 default: typerr(t);
4252 }
4253 }
4254
4255 case AnyPtr: { // Meeting to AnyPtrs
4256 // Found an AnyPtr type vs self-InstPtr type
4257 const TypePtr *tp = t->is_ptr();
4258 int offset = meet_offset(tp->offset());
4259 PTR ptr = meet_ptr(tp->ptr());
4260 int instance_id = meet_instance_id(InstanceTop);
4261 const TypePtr* speculative = xmeet_speculative(tp);
4262 int depth = meet_inline_depth(tp->inline_depth());
4263 switch (tp->ptr()) {
4264 case Null:
4265 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4266 // else fall through to AnyNull
4267 case TopPTR:
4268 case AnyNull: {
4269 return make(ptr, klass(), _interfaces, klass_is_exact(),
4270 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4271 }
4272 case NotNull:
4273 case BotPTR:
4274 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4275 default: typerr(t);
4276 }
4277 }
4278
4279 /*
4280 A-top }
4281 / | \ } Tops
4282 B-top A-any C-top }
4283 | / | \ | } Any-nulls
4284 B-any | C-any }
4285 | | |
4286 B-con A-con C-con } constants; not comparable across classes
4287 | | |
4288 B-not | C-not }
4289 | \ | / | } not-nulls
4290 B-bot A-not C-bot }
4291 \ | / } Bottoms
4292 A-bot }
4293 */
4294
4295 case InstPtr: { // Meeting 2 Oops?
4296 // Found an InstPtr sub-type vs self-InstPtr type
4297 const TypeInstPtr *tinst = t->is_instptr();
4298 int off = meet_offset(tinst->offset());
4299 PTR ptr = meet_ptr(tinst->ptr());
4300 int instance_id = meet_instance_id(tinst->instance_id());
4301 const TypePtr* speculative = xmeet_speculative(tinst);
4302 int depth = meet_inline_depth(tinst->inline_depth());
4303 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4304
4305 ciKlass* tinst_klass = tinst->klass();
4306 ciKlass* this_klass = klass();
4307
4308 ciKlass* res_klass = nullptr;
4309 bool res_xk = false;
4310 const Type* res;
4311 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4312
4313 if (kind == UNLOADED) {
4314 // One of these classes has not been loaded
4315 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4316 #ifndef PRODUCT
4317 if (PrintOpto && Verbose) {
4318 tty->print("meet of unloaded classes resulted in: ");
4319 unloaded_meet->dump();
4320 tty->cr();
4321 tty->print(" this == ");
4322 dump();
4323 tty->cr();
4324 tty->print(" tinst == ");
4325 tinst->dump();
4326 tty->cr();
4327 }
4328 #endif
4329 res = unloaded_meet;
4330 } else {
4331 if (kind == NOT_SUBTYPE && instance_id > 0) {
4332 instance_id = InstanceBot;
4333 } else if (kind == LCA) {
4334 instance_id = InstanceBot;
4335 }
4336 ciObject* o = nullptr; // Assume not constant when done
4337 ciObject* this_oop = const_oop();
4338 ciObject* tinst_oop = tinst->const_oop();
4339 if (ptr == Constant) {
4340 if (this_oop != nullptr && tinst_oop != nullptr &&
4341 this_oop->equals(tinst_oop))
4342 o = this_oop;
4343 else if (above_centerline(_ptr)) {
4344 assert(!tinst_klass->is_interface(), "");
4345 o = tinst_oop;
4346 } else if (above_centerline(tinst->_ptr)) {
4347 assert(!this_klass->is_interface(), "");
4348 o = this_oop;
4349 } else
4350 ptr = NotNull;
4351 }
4352 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4353 }
4354
4355 return res;
4356
4357 } // End of case InstPtr
4358
4359 } // End of switch
4360 return this; // Return the double constant
4361 }
4362
4363 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4364 ciKlass*& res_klass, bool& res_xk) {
4365 ciKlass* this_klass = this_type->klass();
4366 ciKlass* other_klass = other_type->klass();
4367 bool this_xk = this_type->klass_is_exact();
4368 bool other_xk = other_type->klass_is_exact();
4369 PTR this_ptr = this_type->ptr();
4370 PTR other_ptr = other_type->ptr();
4371 const TypeInterfaces* this_interfaces = this_type->interfaces();
4372 const TypeInterfaces* other_interfaces = other_type->interfaces();
4373 // Check for easy case; klasses are equal (and perhaps not loaded!)
4374 // If we have constants, then we created oops so classes are loaded
4375 // and we can handle the constants further down. This case handles
4376 // both-not-loaded or both-loaded classes
4377 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4378 res_klass = this_klass;
4379 res_xk = this_xk;
4380 return QUICK;
4381 }
4382
4383 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4384 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4385 return UNLOADED;
4386 }
4387
4388 // !!! Here's how the symmetry requirement breaks down into invariants:
4389 // If we split one up & one down AND they subtype, take the down man.
4390 // If we split one up & one down AND they do NOT subtype, "fall hard".
4391 // If both are up and they subtype, take the subtype class.
4392 // If both are up and they do NOT subtype, "fall hard".
4393 // If both are down and they subtype, take the supertype class.
4394 // If both are down and they do NOT subtype, "fall hard".
4395 // Constants treated as down.
4396
4397 // Now, reorder the above list; observe that both-down+subtype is also
4398 // "fall hard"; "fall hard" becomes the default case:
4399 // If we split one up & one down AND they subtype, take the down man.
4400 // If both are up and they subtype, take the subtype class.
4401
4402 // If both are down and they subtype, "fall hard".
4403 // If both are down and they do NOT subtype, "fall hard".
4404 // If both are up and they do NOT subtype, "fall hard".
4405 // If we split one up & one down AND they do NOT subtype, "fall hard".
4406
4407 // If a proper subtype is exact, and we return it, we return it exactly.
4408 // If a proper supertype is exact, there can be no subtyping relationship!
4409 // If both types are equal to the subtype, exactness is and-ed below the
4410 // centerline and or-ed above it. (N.B. Constants are always exact.)
4411
4412 // Check for subtyping:
4413 const T* subtype = nullptr;
4414 bool subtype_exact = false;
4415 if (this_type->is_same_java_type_as(other_type)) {
4416 subtype = this_type;
4417 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4418 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4419 subtype = this_type; // Pick subtyping class
4420 subtype_exact = this_xk;
4421 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4422 subtype = other_type; // Pick subtyping class
4423 subtype_exact = other_xk;
4424 }
4425
4426 if (subtype) {
4427 if (above_centerline(ptr)) { // both are up?
4428 this_type = other_type = subtype;
4429 this_xk = other_xk = subtype_exact;
4430 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4431 this_type = other_type; // tinst is down; keep down man
4432 this_xk = other_xk;
4433 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4434 other_type = this_type; // this is down; keep down man
4435 other_xk = this_xk;
4436 } else {
4437 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4438 }
4439 }
4440
4441 // Check for classes now being equal
4442 if (this_type->is_same_java_type_as(other_type)) {
4443 // If the klasses are equal, the constants may still differ. Fall to
4444 // NotNull if they do (neither constant is null; that is a special case
4445 // handled elsewhere).
4446 res_klass = this_type->klass();
4447 res_xk = this_xk;
4448 return SUBTYPE;
4449 } // Else classes are not equal
4450
4451 // Since klasses are different, we require a LCA in the Java
4452 // class hierarchy - which means we have to fall to at least NotNull.
4453 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4454 ptr = NotNull;
4455 }
4456
4457 interfaces = this_interfaces->intersection_with(other_interfaces);
4458
4459 // Now we find the LCA of Java classes
4460 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4461
4462 res_klass = k;
4463 res_xk = false;
4464
4465 return LCA;
4466 }
4467
4468 //------------------------java_mirror_type--------------------------------------
4469 ciType* TypeInstPtr::java_mirror_type() const {
4470 // must be a singleton type
4471 if( const_oop() == nullptr ) return nullptr;
4472
4473 // must be of type java.lang.Class
4474 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4475
4476 return const_oop()->as_instance()->java_mirror_type();
4477 }
4478
4479
4480 //------------------------------xdual------------------------------------------
4481 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4482 // inheritance mechanism.
4483 const Type *TypeInstPtr::xdual() const {
4484 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4485 }
4486
4487 //------------------------------eq---------------------------------------------
4488 // Structural equality check for Type representations
4489 bool TypeInstPtr::eq( const Type *t ) const {
4490 const TypeInstPtr *p = t->is_instptr();
4491 return
4492 klass()->equals(p->klass()) &&
4493 _interfaces->eq(p->_interfaces) &&
4494 TypeOopPtr::eq(p); // Check sub-type stuff
4495 }
4496
4497 //------------------------------hash-------------------------------------------
4498 // Type-specific hashing function.
4499 uint TypeInstPtr::hash(void) const {
4500 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4501 }
4502
4503 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4504 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4505 }
4506
4507
4508 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4509 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4510 }
4511
4512 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4513 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4514 }
4515
4516
4517 //------------------------------dump2------------------------------------------
4518 // Dump oop Type
4519 #ifndef PRODUCT
4520 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4534 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4535 char* buf = ss.as_string(/* c_heap= */false);
4536 StringUtils::replace_no_expand(buf, "\n", "");
4537 st->print_raw(buf);
4538 }
4539 case BotPTR:
4540 if (!WizardMode && !Verbose) {
4541 if( _klass_is_exact ) st->print(":exact");
4542 break;
4543 }
4544 case TopPTR:
4545 case AnyNull:
4546 case NotNull:
4547 st->print(":%s", ptr_msg[_ptr]);
4548 if( _klass_is_exact ) st->print(":exact");
4549 break;
4550 default:
4551 break;
4552 }
4553
4554 if( _offset ) { // Dump offset, if any
4555 if( _offset == OffsetBot ) st->print("+any");
4556 else if( _offset == OffsetTop ) st->print("+unknown");
4557 else st->print("+%d", _offset);
4558 }
4559
4560 st->print(" *");
4561 if (_instance_id == InstanceTop)
4562 st->print(",iid=top");
4563 else if (_instance_id != InstanceBot)
4564 st->print(",iid=%d",_instance_id);
4565
4566 dump_inline_depth(st);
4567 dump_speculative(st);
4568 }
4569 #endif
4570
4571 //------------------------------add_offset-------------------------------------
4572 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4573 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4574 _instance_id, add_offset_speculative(offset), _inline_depth);
4575 }
4576
4577 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4578 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4579 _instance_id, with_offset_speculative(offset), _inline_depth);
4580 }
4581
4582 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4583 if (_speculative == nullptr) {
4584 return this;
4585 }
4586 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4587 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4588 _instance_id, nullptr, _inline_depth);
4589 }
4590
4591 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4592 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4593 }
4594
4595 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4596 if (!UseInlineDepthForSpeculativeTypes) {
4597 return this;
4598 }
4599 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4600 }
4601
4602 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4603 assert(is_known_instance(), "should be known");
4604 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4605 }
4606
4607 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4608 bool xk = klass_is_exact();
4609 ciInstanceKlass* ik = klass()->as_instance_klass();
4610 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4611 if (_interfaces->eq(ik)) {
4612 Compile* C = Compile::current();
4613 Dependencies* deps = C->dependencies();
4614 deps->assert_leaf_type(ik);
4615 xk = true;
4616 }
4617 }
4618 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4619 }
4620
4621 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) {
4622 static_assert(std::is_base_of<T2, T1>::value, "");
4623
4624 if (!this_one->is_instance_type(other)) {
4625 return false;
4626 }
4627
4628 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4629 return true;
4630 }
4631
4632 return this_one->klass()->is_subtype_of(other->klass()) &&
4633 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4634 }
4635
4636
4637 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4638 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4643 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4644 return true;
4645 }
4646
4647 if (this_one->is_instance_type(other)) {
4648 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4649 }
4650
4651 int dummy;
4652 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4653 if (this_top_or_bottom) {
4654 return false;
4655 }
4656
4657 const T1* other_ary = this_one->is_array_type(other);
4658 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4659 const TypePtr* this_elem = this_one->elem()->make_ptr();
4660 if (other_elem != nullptr && this_elem != nullptr) {
4661 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4662 }
4663
4664 if (other_elem == nullptr && this_elem == nullptr) {
4665 return this_one->klass()->is_subtype_of(other->klass());
4666 }
4667
4668 return false;
4669 }
4670
4671 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4672 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4673 }
4674
4675 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4676 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4677 }
4678
4679 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4680 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4681 }
4682
4683 //=============================================================================
4684 // Convenience common pre-built types.
4685 const TypeAryPtr *TypeAryPtr::RANGE;
4686 const TypeAryPtr *TypeAryPtr::OOPS;
4687 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4688 const TypeAryPtr *TypeAryPtr::BYTES;
4689 const TypeAryPtr *TypeAryPtr::SHORTS;
4690 const TypeAryPtr *TypeAryPtr::CHARS;
4691 const TypeAryPtr *TypeAryPtr::INTS;
4692 const TypeAryPtr *TypeAryPtr::LONGS;
4693 const TypeAryPtr *TypeAryPtr::FLOATS;
4694 const TypeAryPtr *TypeAryPtr::DOUBLES;
4695
4696 //------------------------------make-------------------------------------------
4697 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4698 int instance_id, const TypePtr* speculative, int inline_depth) {
4699 assert(!(k == nullptr && ary->_elem->isa_int()),
4700 "integral arrays must be pre-equipped with a class");
4701 if (!xk) xk = ary->ary_must_be_exact();
4702 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4703 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4704 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4705 k = nullptr;
4706 }
4707 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4708 }
4709
4710 //------------------------------make-------------------------------------------
4711 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4712 int instance_id, const TypePtr* speculative, int inline_depth,
4713 bool is_autobox_cache) {
4714 assert(!(k == nullptr && ary->_elem->isa_int()),
4715 "integral arrays must be pre-equipped with a class");
4716 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4717 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4718 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4719 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4720 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4721 k = nullptr;
4722 }
4723 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4724 }
4725
4726 //------------------------------cast_to_ptr_type-------------------------------
4727 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4728 if( ptr == _ptr ) return this;
4729 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4730 }
4731
4732
4733 //-----------------------------cast_to_exactness-------------------------------
4734 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4735 if( klass_is_exact == _klass_is_exact ) return this;
4736 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4737 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4738 }
4739
4740 //-----------------------------cast_to_instance_id----------------------------
4741 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4742 if( instance_id == _instance_id ) return this;
4743 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4744 }
4745
4746
4747 //-----------------------------max_array_length-------------------------------
4748 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4749 jint TypeAryPtr::max_array_length(BasicType etype) {
4750 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4751 if (etype == T_NARROWOOP) {
4752 etype = T_OBJECT;
4753 } else if (etype == T_ILLEGAL) { // bottom[]
4754 etype = T_BYTE; // will produce conservatively high value
4755 } else {
4756 fatal("not an element type: %s", type2name(etype));
4757 }
4758 }
4759 return arrayOopDesc::max_array_length(etype);
4760 }
4761
4762 //-----------------------------narrow_size_type-------------------------------
4763 // Narrow the given size type to the index range for the given array base type.
4779 if (hi > max_hi) {
4780 hi = max_hi;
4781 if (size->is_con()) {
4782 lo = hi;
4783 }
4784 chg = true;
4785 }
4786 // Negative length arrays will produce weird intermediate dead fast-path code
4787 if (lo > hi)
4788 return TypeInt::ZERO;
4789 if (!chg)
4790 return size;
4791 return TypeInt::make(lo, hi, Type::WidenMin);
4792 }
4793
4794 //-------------------------------cast_to_size----------------------------------
4795 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4796 assert(new_size != nullptr, "");
4797 new_size = narrow_size_type(new_size);
4798 if (new_size == size()) return this;
4799 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4800 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4801 }
4802
4803 //------------------------------cast_to_stable---------------------------------
4804 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4805 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4806 return this;
4807
4808 const Type* elem = this->elem();
4809 const TypePtr* elem_ptr = elem->make_ptr();
4810
4811 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4812 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4813 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4814 }
4815
4816 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4817
4818 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4819 }
4820
4821 //-----------------------------stable_dimension--------------------------------
4822 int TypeAryPtr::stable_dimension() const {
4823 if (!is_stable()) return 0;
4824 int dim = 1;
4825 const TypePtr* elem_ptr = elem()->make_ptr();
4826 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4827 dim += elem_ptr->is_aryptr()->stable_dimension();
4828 return dim;
4829 }
4830
4831 //----------------------cast_to_autobox_cache-----------------------------------
4832 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4833 if (is_autobox_cache()) return this;
4834 const TypeOopPtr* etype = elem()->make_oopptr();
4835 if (etype == nullptr) return this;
4836 // The pointers in the autobox arrays are always non-null.
4837 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4838 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4839 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4840 }
4841
4842 //------------------------------eq---------------------------------------------
4843 // Structural equality check for Type representations
4844 bool TypeAryPtr::eq( const Type *t ) const {
4845 const TypeAryPtr *p = t->is_aryptr();
4846 return
4847 _ary == p->_ary && // Check array
4848 TypeOopPtr::eq(p); // Check sub-parts
4849 }
4850
4851 //------------------------------hash-------------------------------------------
4852 // Type-specific hashing function.
4853 uint TypeAryPtr::hash(void) const {
4854 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4855 }
4856
4857 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4858 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4859 }
4860
4861 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4862 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4863 }
4864
4865 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4866 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4867 }
4868 //------------------------------meet-------------------------------------------
4869 // Compute the MEET of two types. It returns a new Type object.
4870 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4871 // Perform a fast test for common case; meeting the same types together.
4872 if( this == t ) return this; // Meeting same type-rep?
4873 // Current "this->_base" is Pointer
4874 switch (t->base()) { // switch on original type
4878 case Long:
4879 case FloatTop:
4880 case FloatCon:
4881 case FloatBot:
4882 case DoubleTop:
4883 case DoubleCon:
4884 case DoubleBot:
4885 case NarrowOop:
4886 case NarrowKlass:
4887 case Bottom: // Ye Olde Default
4888 return Type::BOTTOM;
4889 case Top:
4890 return this;
4891
4892 default: // All else is a mistake
4893 typerr(t);
4894
4895 case OopPtr: { // Meeting to OopPtrs
4896 // Found a OopPtr type vs self-AryPtr type
4897 const TypeOopPtr *tp = t->is_oopptr();
4898 int offset = meet_offset(tp->offset());
4899 PTR ptr = meet_ptr(tp->ptr());
4900 int depth = meet_inline_depth(tp->inline_depth());
4901 const TypePtr* speculative = xmeet_speculative(tp);
4902 switch (tp->ptr()) {
4903 case TopPTR:
4904 case AnyNull: {
4905 int instance_id = meet_instance_id(InstanceTop);
4906 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4907 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4908 }
4909 case BotPTR:
4910 case NotNull: {
4911 int instance_id = meet_instance_id(tp->instance_id());
4912 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4913 }
4914 default: ShouldNotReachHere();
4915 }
4916 }
4917
4918 case AnyPtr: { // Meeting two AnyPtrs
4919 // Found an AnyPtr type vs self-AryPtr type
4920 const TypePtr *tp = t->is_ptr();
4921 int offset = meet_offset(tp->offset());
4922 PTR ptr = meet_ptr(tp->ptr());
4923 const TypePtr* speculative = xmeet_speculative(tp);
4924 int depth = meet_inline_depth(tp->inline_depth());
4925 switch (tp->ptr()) {
4926 case TopPTR:
4927 return this;
4928 case BotPTR:
4929 case NotNull:
4930 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4931 case Null:
4932 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4933 // else fall through to AnyNull
4934 case AnyNull: {
4935 int instance_id = meet_instance_id(InstanceTop);
4936 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4937 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4938 }
4939 default: ShouldNotReachHere();
4940 }
4941 }
4942
4943 case MetadataPtr:
4944 case KlassPtr:
4945 case InstKlassPtr:
4946 case AryKlassPtr:
4947 case RawPtr: return TypePtr::BOTTOM;
4948
4949 case AryPtr: { // Meeting 2 references?
4950 const TypeAryPtr *tap = t->is_aryptr();
4951 int off = meet_offset(tap->offset());
4952 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4953 PTR ptr = meet_ptr(tap->ptr());
4954 int instance_id = meet_instance_id(tap->instance_id());
4955 const TypePtr* speculative = xmeet_speculative(tap);
4956 int depth = meet_inline_depth(tap->inline_depth());
4957
4958 ciKlass* res_klass = nullptr;
4959 bool res_xk = false;
4960 const Type* elem = tary->_elem;
4961 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4962 instance_id = InstanceBot;
4963 }
4964
4965 ciObject* o = nullptr; // Assume not constant when done
4966 ciObject* this_oop = const_oop();
4967 ciObject* tap_oop = tap->const_oop();
4968 if (ptr == Constant) {
4969 if (this_oop != nullptr && tap_oop != nullptr &&
4970 this_oop->equals(tap_oop)) {
4971 o = tap_oop;
4972 } else if (above_centerline(_ptr)) {
4973 o = tap_oop;
4974 } else if (above_centerline(tap->_ptr)) {
4975 o = this_oop;
4976 } else {
4977 ptr = NotNull;
4978 }
4979 }
4980 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4981 }
4982
4983 // All arrays inherit from Object class
4984 case InstPtr: {
4985 const TypeInstPtr *tp = t->is_instptr();
4986 int offset = meet_offset(tp->offset());
4987 PTR ptr = meet_ptr(tp->ptr());
4988 int instance_id = meet_instance_id(tp->instance_id());
4989 const TypePtr* speculative = xmeet_speculative(tp);
4990 int depth = meet_inline_depth(tp->inline_depth());
4991 const TypeInterfaces* interfaces = meet_interfaces(tp);
4992 const TypeInterfaces* tp_interfaces = tp->_interfaces;
4993 const TypeInterfaces* this_interfaces = _interfaces;
4994
4995 switch (ptr) {
4996 case TopPTR:
4997 case AnyNull: // Fall 'down' to dual of object klass
4998 // For instances when a subclass meets a superclass we fall
4999 // below the centerline when the superclass is exact. We need to
5000 // do the same here.
5001 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5002 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5003 } else {
5004 // cannot subclass, so the meet has to fall badly below the centerline
5005 ptr = NotNull;
5006 instance_id = InstanceBot;
5007 interfaces = this_interfaces->intersection_with(tp_interfaces);
5008 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5009 }
5010 case Constant:
5011 case NotNull:
5012 case BotPTR: // Fall down to object klass
5013 // LCA is object_klass, but if we subclass from the top we can do better
5014 if (above_centerline(tp->ptr())) {
5015 // If 'tp' is above the centerline and it is Object class
5016 // then we can subclass in the Java class hierarchy.
5017 // For instances when a subclass meets a superclass we fall
5018 // below the centerline when the superclass is exact. We need
5019 // to do the same here.
5020 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5021 // that is, my array type is a subtype of 'tp' klass
5022 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5023 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5024 }
5025 }
5026 // The other case cannot happen, since t cannot be a subtype of an array.
5027 // The meet falls down to Object class below centerline.
5028 if (ptr == Constant) {
5029 ptr = NotNull;
5030 }
5031 if (instance_id > 0) {
5032 instance_id = InstanceBot;
5033 }
5034 interfaces = this_interfaces->intersection_with(tp_interfaces);
5035 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5036 default: typerr(t);
5037 }
5038 }
5039 }
5040 return this; // Lint noise
5041 }
5042
5043
5044 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5045 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5046 int dummy;
5047 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5048 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5049 ciKlass* this_klass = this_ary->klass();
5050 ciKlass* other_klass = other_ary->klass();
5051 bool this_xk = this_ary->klass_is_exact();
5052 bool other_xk = other_ary->klass_is_exact();
5053 PTR this_ptr = this_ary->ptr();
5054 PTR other_ptr = other_ary->ptr();
5055 res_klass = nullptr;
5056 MeetResult result = SUBTYPE;
5057 if (elem->isa_int()) {
5058 // Integral array element types have irrelevant lattice relations.
5059 // It is the klass that determines array layout, not the element type.
5060 if (this_top_or_bottom)
5061 res_klass = other_klass;
5062 else if (other_top_or_bottom || other_klass == this_klass) {
5063 res_klass = this_klass;
5064 } else {
5065 // Something like byte[int+] meets char[int+].
5066 // This must fall to bottom, not (int[-128..65535])[int+].
5067 // instance_id = InstanceBot;
5068 elem = Type::BOTTOM;
5069 result = NOT_SUBTYPE;
5070 if (above_centerline(ptr) || ptr == Constant) {
5071 ptr = NotNull;
5072 res_xk = false;
5073 return NOT_SUBTYPE;
5074 }
5075 }
5076 } else {// Non integral arrays.
5077 // Must fall to bottom if exact klasses in upper lattice
5078 // are not equal or super klass is exact.
5079 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5080 // meet with top[] and bottom[] are processed further down:
5081 !this_top_or_bottom && !other_top_or_bottom &&
5082 // both are exact and not equal:
5084 // 'tap' is exact and super or unrelated:
5085 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5086 // 'this' is exact and super or unrelated:
5087 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5088 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5089 elem = Type::BOTTOM;
5090 }
5091 ptr = NotNull;
5092 res_xk = false;
5093 return NOT_SUBTYPE;
5094 }
5095 }
5096
5097 res_xk = false;
5098 switch (other_ptr) {
5099 case AnyNull:
5100 case TopPTR:
5101 // Compute new klass on demand, do not use tap->_klass
5102 if (below_centerline(this_ptr)) {
5103 res_xk = this_xk;
5104 } else {
5105 res_xk = (other_xk || this_xk);
5106 }
5107 return result;
5108 case Constant: {
5109 if (this_ptr == Constant) {
5110 res_xk = true;
5111 } else if(above_centerline(this_ptr)) {
5112 res_xk = true;
5113 } else {
5114 // Only precise for identical arrays
5115 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5116 }
5117 return result;
5118 }
5119 case NotNull:
5120 case BotPTR:
5121 // Compute new klass on demand, do not use tap->_klass
5122 if (above_centerline(this_ptr)) {
5123 res_xk = other_xk;
5124 } else {
5125 res_xk = (other_xk && this_xk) &&
5126 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5127 }
5128 return result;
5129 default: {
5130 ShouldNotReachHere();
5131 return result;
5132 }
5133 }
5134 return result;
5135 }
5136
5137
5138 //------------------------------xdual------------------------------------------
5139 // Dual: compute field-by-field dual
5140 const Type *TypeAryPtr::xdual() const {
5141 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());
5142 }
5143
5144 //------------------------------dump2------------------------------------------
5145 #ifndef PRODUCT
5146 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5147 _ary->dump2(d,depth,st);
5148 _interfaces->dump(st);
5149
5150 switch( _ptr ) {
5151 case Constant:
5152 const_oop()->print(st);
5153 break;
5154 case BotPTR:
5155 if (!WizardMode && !Verbose) {
5156 if( _klass_is_exact ) st->print(":exact");
5157 break;
5158 }
5159 case TopPTR:
5160 case AnyNull:
5161 case NotNull:
5162 st->print(":%s", ptr_msg[_ptr]);
5163 if( _klass_is_exact ) st->print(":exact");
5164 break;
5165 default:
5166 break;
5167 }
5168
5169 if( _offset != 0 ) {
5170 BasicType basic_elem_type = elem()->basic_type();
5171 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5172 if( _offset == OffsetTop ) st->print("+undefined");
5173 else if( _offset == OffsetBot ) st->print("+any");
5174 else if( _offset < header_size ) st->print("+%d", _offset);
5175 else {
5176 if (basic_elem_type == T_ILLEGAL) {
5177 st->print("+any");
5178 } else {
5179 int elem_size = type2aelembytes(basic_elem_type);
5180 st->print("[%d]", (_offset - header_size)/elem_size);
5181 }
5182 }
5183 }
5184 st->print(" *");
5185 if (_instance_id == InstanceTop)
5186 st->print(",iid=top");
5187 else if (_instance_id != InstanceBot)
5188 st->print(",iid=%d",_instance_id);
5189
5190 dump_inline_depth(st);
5191 dump_speculative(st);
5192 }
5193 #endif
5194
5195 bool TypeAryPtr::empty(void) const {
5196 if (_ary->empty()) return true;
5197 return TypeOopPtr::empty();
5198 }
5199
5200 //------------------------------add_offset-------------------------------------
5201 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5202 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5203 }
5204
5205 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5206 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5207 }
5208
5209 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5210 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5211 }
5212
5213 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5214 if (_speculative == nullptr) {
5215 return this;
5216 }
5217 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5218 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5219 }
5220
5221 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5222 if (!UseInlineDepthForSpeculativeTypes) {
5223 return this;
5224 }
5225 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5226 }
5227
5228 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5229 assert(is_known_instance(), "should be known");
5230 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5231 }
5232
5233 //=============================================================================
5234
5235 //------------------------------hash-------------------------------------------
5236 // Type-specific hashing function.
5237 uint TypeNarrowPtr::hash(void) const {
5238 return _ptrtype->hash() + 7;
5239 }
5240
5241 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5242 return _ptrtype->singleton();
5243 }
5244
5245 bool TypeNarrowPtr::empty(void) const {
5246 return _ptrtype->empty();
5247 }
5248
5249 intptr_t TypeNarrowPtr::get_con() const {
5250 return _ptrtype->get_con();
5251 }
5252
5253 bool TypeNarrowPtr::eq( const Type *t ) const {
5254 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5305
5306 case Int: // Mixing ints & oops happens when javac
5307 case Long: // reuses local variables
5308 case FloatTop:
5309 case FloatCon:
5310 case FloatBot:
5311 case DoubleTop:
5312 case DoubleCon:
5313 case DoubleBot:
5314 case AnyPtr:
5315 case RawPtr:
5316 case OopPtr:
5317 case InstPtr:
5318 case AryPtr:
5319 case MetadataPtr:
5320 case KlassPtr:
5321 case InstKlassPtr:
5322 case AryKlassPtr:
5323 case NarrowOop:
5324 case NarrowKlass:
5325
5326 case Bottom: // Ye Olde Default
5327 return Type::BOTTOM;
5328 case Top:
5329 return this;
5330
5331 default: // All else is a mistake
5332 typerr(t);
5333
5334 } // End of switch
5335
5336 return this;
5337 }
5338
5339 #ifndef PRODUCT
5340 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5341 _ptrtype->dump2(d, depth, st);
5342 }
5343 #endif
5344
5345 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5389 return (one == two) && TypePtr::eq(t);
5390 } else {
5391 return one->equals(two) && TypePtr::eq(t);
5392 }
5393 }
5394
5395 //------------------------------hash-------------------------------------------
5396 // Type-specific hashing function.
5397 uint TypeMetadataPtr::hash(void) const {
5398 return
5399 (metadata() ? metadata()->hash() : 0) +
5400 TypePtr::hash();
5401 }
5402
5403 //------------------------------singleton--------------------------------------
5404 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5405 // constants
5406 bool TypeMetadataPtr::singleton(void) const {
5407 // detune optimizer to not generate constant metadata + constant offset as a constant!
5408 // TopPTR, Null, AnyNull, Constant are all singletons
5409 return (_offset == 0) && !below_centerline(_ptr);
5410 }
5411
5412 //------------------------------add_offset-------------------------------------
5413 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5414 return make( _ptr, _metadata, xadd_offset(offset));
5415 }
5416
5417 //-----------------------------filter------------------------------------------
5418 // Do not allow interface-vs.-noninterface joins to collapse to top.
5419 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5420 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5421 if (ft == nullptr || ft->empty())
5422 return Type::TOP; // Canonical empty value
5423 return ft;
5424 }
5425
5426 //------------------------------get_con----------------------------------------
5427 intptr_t TypeMetadataPtr::get_con() const {
5428 assert( _ptr == Null || _ptr == Constant, "" );
5429 assert( _offset >= 0, "" );
5430
5431 if (_offset != 0) {
5432 // After being ported to the compiler interface, the compiler no longer
5433 // directly manipulates the addresses of oops. Rather, it only has a pointer
5434 // to a handle at compile time. This handle is embedded in the generated
5435 // code and dereferenced at the time the nmethod is made. Until that time,
5436 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5437 // have access to the addresses!). This does not seem to currently happen,
5438 // but this assertion here is to help prevent its occurrence.
5439 tty->print_cr("Found oop constant with non-zero offset");
5440 ShouldNotReachHere();
5441 }
5442
5443 return (intptr_t)metadata()->constant_encoding();
5444 }
5445
5446 //------------------------------cast_to_ptr_type-------------------------------
5447 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5448 if( ptr == _ptr ) return this;
5449 return make(ptr, metadata(), _offset);
5450 }
5451
5462 case Long: // reuses local variables
5463 case FloatTop:
5464 case FloatCon:
5465 case FloatBot:
5466 case DoubleTop:
5467 case DoubleCon:
5468 case DoubleBot:
5469 case NarrowOop:
5470 case NarrowKlass:
5471 case Bottom: // Ye Olde Default
5472 return Type::BOTTOM;
5473 case Top:
5474 return this;
5475
5476 default: // All else is a mistake
5477 typerr(t);
5478
5479 case AnyPtr: {
5480 // Found an AnyPtr type vs self-OopPtr type
5481 const TypePtr *tp = t->is_ptr();
5482 int offset = meet_offset(tp->offset());
5483 PTR ptr = meet_ptr(tp->ptr());
5484 switch (tp->ptr()) {
5485 case Null:
5486 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5487 // else fall through:
5488 case TopPTR:
5489 case AnyNull: {
5490 return make(ptr, _metadata, offset);
5491 }
5492 case BotPTR:
5493 case NotNull:
5494 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5495 default: typerr(t);
5496 }
5497 }
5498
5499 case RawPtr:
5500 case KlassPtr:
5501 case InstKlassPtr:
5502 case AryKlassPtr:
5503 case OopPtr:
5504 case InstPtr:
5505 case AryPtr:
5506 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5507
5508 case MetadataPtr: {
5509 const TypeMetadataPtr *tp = t->is_metadataptr();
5510 int offset = meet_offset(tp->offset());
5511 PTR tptr = tp->ptr();
5512 PTR ptr = meet_ptr(tptr);
5513 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5514 if (tptr == TopPTR || _ptr == TopPTR ||
5515 metadata()->equals(tp->metadata())) {
5516 return make(ptr, md, offset);
5517 }
5518 // metadata is different
5519 if( ptr == Constant ) { // Cannot be equal constants, so...
5520 if( tptr == Constant && _ptr != Constant) return t;
5521 if( _ptr == Constant && tptr != Constant) return this;
5522 ptr = NotNull; // Fall down in lattice
5523 }
5524 return make(ptr, nullptr, offset);
5525 break;
5526 }
5527 } // End of switch
5528 return this; // Return the double constant
5529 }
5530
5531
5532 //------------------------------xdual------------------------------------------
5533 // Dual of a pure metadata pointer.
5534 const Type *TypeMetadataPtr::xdual() const {
5535 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5536 }
5537
5538 //------------------------------dump2------------------------------------------
5539 #ifndef PRODUCT
5540 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5541 st->print("metadataptr:%s", ptr_msg[_ptr]);
5542 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5543 switch( _offset ) {
5544 case OffsetTop: st->print("+top"); break;
5545 case OffsetBot: st->print("+any"); break;
5546 case 0: break;
5547 default: st->print("+%d",_offset); break;
5548 }
5549 }
5550 #endif
5551
5552
5553 //=============================================================================
5554 // Convenience common pre-built type.
5555 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5556
5557 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5558 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5559 }
5560
5561 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5562 return make(Constant, m, 0);
5563 }
5564 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5565 return make(Constant, m, 0);
5566 }
5567
5568 //------------------------------make-------------------------------------------
5569 // Create a meta data constant
5570 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5571 assert(m == nullptr || !m->is_klass(), "wrong type");
5572 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5573 }
5574
5575
5576 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5577 const Type* elem = _ary->_elem;
5578 bool xk = klass_is_exact();
5579 if (elem->make_oopptr() != nullptr) {
5580 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5581 if (elem->is_klassptr()->klass_is_exact()) {
5582 xk = true;
5583 }
5584 }
5585 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5586 }
5587
5588 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5589 if (klass->is_instance_klass()) {
5590 return TypeInstKlassPtr::make(klass, interface_handling);
5591 }
5592 return TypeAryKlassPtr::make(klass, interface_handling);
5593 }
5594
5595 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5596 if (klass->is_instance_klass()) {
5597 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5598 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5599 }
5600 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5601 }
5602
5603
5604 //------------------------------TypeKlassPtr-----------------------------------
5605 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5606 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5607 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5608 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5609 }
5610
5611 // Is there a single ciKlass* that can represent that type?
5612 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5613 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5614 if (_interfaces->empty()) {
5615 return _klass;
5616 }
5617 if (_klass != ciEnv::current()->Object_klass()) {
5618 if (_interfaces->eq(_klass->as_instance_klass())) {
5619 return _klass;
5620 }
5621 return nullptr;
5622 }
5623 return _interfaces->exact_klass();
5624 }
5625
5626 //------------------------------eq---------------------------------------------
5627 // Structural equality check for Type representations
5628 bool TypeKlassPtr::eq(const Type *t) const {
5629 const TypeKlassPtr *p = t->is_klassptr();
5630 return
5631 _interfaces->eq(p->_interfaces) &&
5632 TypePtr::eq(p);
5633 }
5634
5635 //------------------------------hash-------------------------------------------
5636 // Type-specific hashing function.
5637 uint TypeKlassPtr::hash(void) const {
5638 return TypePtr::hash() + _interfaces->hash();
5639 }
5640
5641 //------------------------------singleton--------------------------------------
5642 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5643 // constants
5644 bool TypeKlassPtr::singleton(void) const {
5645 // detune optimizer to not generate constant klass + constant offset as a constant!
5646 // TopPTR, Null, AnyNull, Constant are all singletons
5647 return (_offset == 0) && !below_centerline(_ptr);
5648 }
5649
5650 // Do not allow interface-vs.-noninterface joins to collapse to top.
5651 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5652 // logic here mirrors the one from TypeOopPtr::filter. See comments
5653 // there.
5654 const Type* ft = join_helper(kills, include_speculative);
5655 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5656 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5657
5658 if (ft->empty()) {
5659 return Type::TOP; // Canonical empty value
5660 }
5661
5662 return ft;
5663 }
5664
5665 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5666 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5667 return _interfaces->union_with(other->_interfaces);
5668 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5669 return other->_interfaces;
5670 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5671 return _interfaces;
5672 }
5673 return _interfaces->intersection_with(other->_interfaces);
5674 }
5675
5676 //------------------------------get_con----------------------------------------
5677 intptr_t TypeKlassPtr::get_con() const {
5678 assert( _ptr == Null || _ptr == Constant, "" );
5679 assert( _offset >= 0, "" );
5680
5681 if (_offset != 0) {
5682 // After being ported to the compiler interface, the compiler no longer
5683 // directly manipulates the addresses of oops. Rather, it only has a pointer
5684 // to a handle at compile time. This handle is embedded in the generated
5685 // code and dereferenced at the time the nmethod is made. Until that time,
5686 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5687 // have access to the addresses!). This does not seem to currently happen,
5688 // but this assertion here is to help prevent its occurrence.
5689 tty->print_cr("Found oop constant with non-zero offset");
5690 ShouldNotReachHere();
5691 }
5692
5693 ciKlass* k = exact_klass();
5694
5695 return (intptr_t)k->constant_encoding();
5696 }
5697
5698 //------------------------------dump2------------------------------------------
5699 // Dump Klass Type
5700 #ifndef PRODUCT
5701 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5705 case NotNull:
5706 {
5707 const char *name = klass()->name()->as_utf8();
5708 if (name) {
5709 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5710 } else {
5711 ShouldNotReachHere();
5712 }
5713 _interfaces->dump(st);
5714 }
5715 case BotPTR:
5716 if (!WizardMode && !Verbose && _ptr != Constant) break;
5717 case TopPTR:
5718 case AnyNull:
5719 st->print(":%s", ptr_msg[_ptr]);
5720 if (_ptr == Constant) st->print(":exact");
5721 break;
5722 default:
5723 break;
5724 }
5725
5726 if (_offset) { // Dump offset, if any
5727 if (_offset == OffsetBot) { st->print("+any"); }
5728 else if (_offset == OffsetTop) { st->print("+unknown"); }
5729 else { st->print("+%d", _offset); }
5730 }
5731
5732 st->print(" *");
5733 }
5734 #endif
5735
5736 //=============================================================================
5737 // Convenience common pre-built types.
5738
5739 // Not-null object klass or below
5740 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5741 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5742
5743 bool TypeInstKlassPtr::eq(const Type *t) const {
5744 const TypeKlassPtr *p = t->is_klassptr();
5745 return
5746 klass()->equals(p->klass()) &&
5747 TypeKlassPtr::eq(p);
5748 }
5749
5750 uint TypeInstKlassPtr::hash(void) const {
5751 return klass()->hash() + TypeKlassPtr::hash();
5752 }
5753
5754 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5755 TypeInstKlassPtr *r =
5756 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5757
5758 return r;
5759 }
5760
5761 //------------------------------add_offset-------------------------------------
5762 // Access internals of klass object
5763 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5764 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5765 }
5766
5767 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5768 return make(_ptr, klass(), _interfaces, offset);
5769 }
5770
5771 //------------------------------cast_to_ptr_type-------------------------------
5772 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5773 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5774 if( ptr == _ptr ) return this;
5775 return make(ptr, _klass, _interfaces, _offset);
5776 }
5777
5778
5779 bool TypeInstKlassPtr::must_be_exact() const {
5780 if (!_klass->is_loaded()) return false;
5781 ciInstanceKlass* ik = _klass->as_instance_klass();
5782 if (ik->is_final()) return true; // cannot clear xk
5783 return false;
5784 }
5785
5786 //-----------------------------cast_to_exactness-------------------------------
5787 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5788 if (klass_is_exact == (_ptr == Constant)) return this;
5789 if (must_be_exact()) return this;
5790 ciKlass* k = klass();
5791 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5792 }
5793
5794
5795 //-----------------------------as_instance_type--------------------------------
5796 // Corresponding type for an instance of the given class.
5797 // It will be NotNull, and exact if and only if the klass type is exact.
5798 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5799 ciKlass* k = klass();
5800 bool xk = klass_is_exact();
5801 Compile* C = Compile::current();
5802 Dependencies* deps = C->dependencies();
5803 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5804 // Element is an instance
5805 bool klass_is_exact = false;
5806 const TypeInterfaces* interfaces = _interfaces;
5807 if (k->is_loaded()) {
5808 // Try to set klass_is_exact.
5809 ciInstanceKlass* ik = k->as_instance_klass();
5810 klass_is_exact = ik->is_final();
5811 if (!klass_is_exact && klass_change
5812 && deps != nullptr && UseUniqueSubclasses) {
5813 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5814 if (sub != nullptr) {
5815 if (_interfaces->eq(sub)) {
5816 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5817 k = ik = sub;
5818 xk = sub->is_final();
5819 }
5820 }
5821 }
5822 }
5823 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5824 }
5825
5826 //------------------------------xmeet------------------------------------------
5827 // Compute the MEET of two types, return a new Type object.
5828 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5829 // Perform a fast test for common case; meeting the same types together.
5830 if( this == t ) return this; // Meeting same type-rep?
5831
5832 // Current "this->_base" is Pointer
5833 switch (t->base()) { // switch on original type
5834
5835 case Int: // Mixing ints & oops happens when javac
5836 case Long: // reuses local variables
5837 case FloatTop:
5838 case FloatCon:
5839 case FloatBot:
5840 case DoubleTop:
5841 case DoubleCon:
5842 case DoubleBot:
5843 case NarrowOop:
5844 case NarrowKlass:
5845 case Bottom: // Ye Olde Default
5846 return Type::BOTTOM;
5847 case Top:
5848 return this;
5849
5850 default: // All else is a mistake
5851 typerr(t);
5852
5853 case AnyPtr: { // Meeting to AnyPtrs
5854 // Found an AnyPtr type vs self-KlassPtr type
5855 const TypePtr *tp = t->is_ptr();
5856 int offset = meet_offset(tp->offset());
5857 PTR ptr = meet_ptr(tp->ptr());
5858 switch (tp->ptr()) {
5859 case TopPTR:
5860 return this;
5861 case Null:
5862 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5863 case AnyNull:
5864 return make( ptr, klass(), _interfaces, offset );
5865 case BotPTR:
5866 case NotNull:
5867 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5868 default: typerr(t);
5869 }
5870 }
5871
5872 case RawPtr:
5873 case MetadataPtr:
5874 case OopPtr:
5875 case AryPtr: // Meet with AryPtr
5876 case InstPtr: // Meet with InstPtr
5877 return TypePtr::BOTTOM;
5878
5879 //
5880 // A-top }
5881 // / | \ } Tops
5882 // B-top A-any C-top }
5883 // | / | \ | } Any-nulls
5884 // B-any | C-any }
5885 // | | |
5886 // B-con A-con C-con } constants; not comparable across classes
5887 // | | |
5888 // B-not | C-not }
5889 // | \ | / | } not-nulls
5890 // B-bot A-not C-bot }
5891 // \ | / } Bottoms
5892 // A-bot }
5893 //
5894
5895 case InstKlassPtr: { // Meet two KlassPtr types
5896 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5897 int off = meet_offset(tkls->offset());
5898 PTR ptr = meet_ptr(tkls->ptr());
5899 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5900
5901 ciKlass* res_klass = nullptr;
5902 bool res_xk = false;
5903 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5904 case UNLOADED:
5905 ShouldNotReachHere();
5906 case SUBTYPE:
5907 case NOT_SUBTYPE:
5908 case LCA:
5909 case QUICK: {
5910 assert(res_xk == (ptr == Constant), "");
5911 const Type* res = make(ptr, res_klass, interfaces, off);
5912 return res;
5913 }
5914 default:
5915 ShouldNotReachHere();
5916 }
5917 } // End of case KlassPtr
5918 case AryKlassPtr: { // All arrays inherit from Object class
5919 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5920 int offset = meet_offset(tp->offset());
5921 PTR ptr = meet_ptr(tp->ptr());
5922 const TypeInterfaces* interfaces = meet_interfaces(tp);
5923 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5924 const TypeInterfaces* this_interfaces = _interfaces;
5925
5926 switch (ptr) {
5927 case TopPTR:
5928 case AnyNull: // Fall 'down' to dual of object klass
5929 // For instances when a subclass meets a superclass we fall
5930 // below the centerline when the superclass is exact. We need to
5931 // do the same here.
5932 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5933 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5934 } else {
5935 // cannot subclass, so the meet has to fall badly below the centerline
5936 ptr = NotNull;
5937 interfaces = _interfaces->intersection_with(tp->_interfaces);
5938 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5939 }
5940 case Constant:
5941 case NotNull:
5942 case BotPTR: // Fall down to object klass
5943 // LCA is object_klass, but if we subclass from the top we can do better
5944 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5945 // If 'this' (InstPtr) is above the centerline and it is Object class
5946 // then we can subclass in the Java class hierarchy.
5947 // For instances when a subclass meets a superclass we fall
5948 // below the centerline when the superclass is exact. We need
5949 // to do the same here.
5950 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5951 // that is, tp's array type is a subtype of my klass
5952 return TypeAryKlassPtr::make(ptr,
5953 tp->elem(), tp->klass(), offset);
5954 }
5955 }
5956 // The other case cannot happen, since I cannot be a subtype of an array.
5957 // The meet falls down to Object class below centerline.
5958 if( ptr == Constant )
5959 ptr = NotNull;
5960 interfaces = this_interfaces->intersection_with(tp_interfaces);
5961 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5962 default: typerr(t);
5963 }
5964 }
5965
5966 } // End of switch
5967 return this; // Return the double constant
5968 }
5969
5970 //------------------------------xdual------------------------------------------
5971 // Dual: compute field-by-field dual
5972 const Type *TypeInstKlassPtr::xdual() const {
5973 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5974 }
5975
5976 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) {
5977 static_assert(std::is_base_of<T2, T1>::value, "");
5978 if (!this_one->is_loaded() || !other->is_loaded()) {
5979 return false;
5980 }
5981 if (!this_one->is_instance_type(other)) {
5982 return false;
5983 }
5984
5985 if (!other_exact) {
5986 return false;
5987 }
5988
5989 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5990 return true;
5991 }
5992
5993 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6054 const TypeInterfaces* interfaces = _interfaces;
6055 if (k->is_loaded()) {
6056 ciInstanceKlass* ik = k->as_instance_klass();
6057 bool klass_is_exact = ik->is_final();
6058 if (!klass_is_exact &&
6059 deps != nullptr) {
6060 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6061 if (sub != nullptr) {
6062 if (_interfaces->eq(sub)) {
6063 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6064 k = ik = sub;
6065 klass_is_exact = sub->is_final();
6066 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6067 }
6068 }
6069 }
6070 }
6071 return this;
6072 }
6073
6074
6075 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6076 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6077 }
6078
6079 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6080 if (k->is_obj_array_klass()) {
6081 // Element is an object array. Recursively call ourself.
6082 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6083 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6084 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6085 } else if (k->is_type_array_klass()) {
6086 // Element is an typeArray
6087 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6088 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6089 } else {
6090 ShouldNotReachHere();
6091 return nullptr;
6092 }
6093 }
6094
6095 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6096 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6097 }
6098
6099 //------------------------------eq---------------------------------------------
6100 // Structural equality check for Type representations
6101 bool TypeAryKlassPtr::eq(const Type *t) const {
6102 const TypeAryKlassPtr *p = t->is_aryklassptr();
6103 return
6104 _elem == p->_elem && // Check array
6105 TypeKlassPtr::eq(p); // Check sub-parts
6106 }
6107
6108 //------------------------------hash-------------------------------------------
6109 // Type-specific hashing function.
6110 uint TypeAryKlassPtr::hash(void) const {
6111 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6112 }
6113
6114 //----------------------compute_klass------------------------------------------
6115 // Compute the defining klass for this class
6116 ciKlass* TypeAryPtr::compute_klass() const {
6117 // Compute _klass based on element type.
6118 ciKlass* k_ary = nullptr;
6119 const TypeInstPtr *tinst;
6120 const TypeAryPtr *tary;
6121 const Type* el = elem();
6122 if (el->isa_narrowoop()) {
6123 el = el->make_ptr();
6124 }
6125
6126 // Get element klass
6127 if ((tinst = el->isa_instptr()) != nullptr) {
6128 // Leave k_ary at null.
6129 } else if ((tary = el->isa_aryptr()) != nullptr) {
6130 // Leave k_ary at null.
6131 } else if ((el->base() == Type::Top) ||
6132 (el->base() == Type::Bottom)) {
6133 // element type of Bottom occurs from meet of basic type
6134 // and object; Top occurs when doing join on Bottom.
6135 // Leave k_ary at null.
6136 } else {
6137 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6138 // Compute array klass directly from basic type
6139 k_ary = ciTypeArrayKlass::make(el->basic_type());
6140 }
6141 return k_ary;
6142 }
6143
6144 //------------------------------klass------------------------------------------
6145 // Return the defining klass for this class
6146 ciKlass* TypeAryPtr::klass() const {
6147 if( _klass ) return _klass; // Return cached value, if possible
6148
6149 // Oops, need to compute _klass and cache it
6150 ciKlass* k_ary = compute_klass();
6158 // type TypeAryPtr::OOPS. This Type is shared between all
6159 // active compilations. However, the ciKlass which represents
6160 // this Type is *not* shared between compilations, so caching
6161 // this value would result in fetching a dangling pointer.
6162 //
6163 // Recomputing the underlying ciKlass for each request is
6164 // a bit less efficient than caching, but calls to
6165 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6166 ((TypeAryPtr*)this)->_klass = k_ary;
6167 }
6168 return k_ary;
6169 }
6170
6171 // Is there a single ciKlass* that can represent that type?
6172 ciKlass* TypeAryPtr::exact_klass_helper() const {
6173 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6174 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6175 if (k == nullptr) {
6176 return nullptr;
6177 }
6178 k = ciObjArrayKlass::make(k);
6179 return k;
6180 }
6181
6182 return klass();
6183 }
6184
6185 const Type* TypeAryPtr::base_element_type(int& dims) const {
6186 const Type* elem = this->elem();
6187 dims = 1;
6188 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6189 elem = elem->make_ptr()->is_aryptr()->elem();
6190 dims++;
6191 }
6192 return elem;
6193 }
6194
6195 //------------------------------add_offset-------------------------------------
6196 // Access internals of klass object
6197 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6198 return make(_ptr, elem(), klass(), xadd_offset(offset));
6199 }
6200
6201 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6202 return make(_ptr, elem(), klass(), offset);
6203 }
6204
6205 //------------------------------cast_to_ptr_type-------------------------------
6206 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6207 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6208 if (ptr == _ptr) return this;
6209 return make(ptr, elem(), _klass, _offset);
6210 }
6211
6212 bool TypeAryKlassPtr::must_be_exact() const {
6213 if (_elem == Type::BOTTOM) return false;
6214 if (_elem == Type::TOP ) return false;
6215 const TypeKlassPtr* tk = _elem->isa_klassptr();
6216 if (!tk) return true; // a primitive type, like int
6217 return tk->must_be_exact();
6218 }
6219
6220
6221 //-----------------------------cast_to_exactness-------------------------------
6222 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6223 if (must_be_exact()) return this; // cannot clear xk
6224 ciKlass* k = _klass;
6225 const Type* elem = this->elem();
6226 if (elem->isa_klassptr() && !klass_is_exact) {
6227 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6228 }
6229 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6230 }
6231
6232
6233 //-----------------------------as_instance_type--------------------------------
6234 // Corresponding type for an instance of the given class.
6235 // It will be NotNull, and exact if and only if the klass type is exact.
6236 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6237 ciKlass* k = klass();
6238 bool xk = klass_is_exact();
6239 const Type* el = nullptr;
6240 if (elem()->isa_klassptr()) {
6241 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6242 k = nullptr;
6243 } else {
6244 el = elem();
6245 }
6246 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6247 }
6248
6249
6250 //------------------------------xmeet------------------------------------------
6251 // Compute the MEET of two types, return a new Type object.
6252 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6253 // Perform a fast test for common case; meeting the same types together.
6254 if( this == t ) return this; // Meeting same type-rep?
6255
6256 // Current "this->_base" is Pointer
6257 switch (t->base()) { // switch on original type
6258
6259 case Int: // Mixing ints & oops happens when javac
6260 case Long: // reuses local variables
6261 case FloatTop:
6262 case FloatCon:
6263 case FloatBot:
6264 case DoubleTop:
6265 case DoubleCon:
6266 case DoubleBot:
6267 case NarrowOop:
6268 case NarrowKlass:
6269 case Bottom: // Ye Olde Default
6270 return Type::BOTTOM;
6271 case Top:
6272 return this;
6273
6274 default: // All else is a mistake
6275 typerr(t);
6276
6277 case AnyPtr: { // Meeting to AnyPtrs
6278 // Found an AnyPtr type vs self-KlassPtr type
6279 const TypePtr *tp = t->is_ptr();
6280 int offset = meet_offset(tp->offset());
6281 PTR ptr = meet_ptr(tp->ptr());
6282 switch (tp->ptr()) {
6283 case TopPTR:
6284 return this;
6285 case Null:
6286 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6287 case AnyNull:
6288 return make( ptr, _elem, klass(), offset );
6289 case BotPTR:
6290 case NotNull:
6291 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6292 default: typerr(t);
6293 }
6294 }
6295
6296 case RawPtr:
6297 case MetadataPtr:
6298 case OopPtr:
6299 case AryPtr: // Meet with AryPtr
6300 case InstPtr: // Meet with InstPtr
6301 return TypePtr::BOTTOM;
6302
6303 //
6304 // A-top }
6305 // / | \ } Tops
6306 // B-top A-any C-top }
6307 // | / | \ | } Any-nulls
6308 // B-any | C-any }
6309 // | | |
6310 // B-con A-con C-con } constants; not comparable across classes
6311 // | | |
6312 // B-not | C-not }
6313 // | \ | / | } not-nulls
6314 // B-bot A-not C-bot }
6315 // \ | / } Bottoms
6316 // A-bot }
6317 //
6318
6319 case AryKlassPtr: { // Meet two KlassPtr types
6320 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6321 int off = meet_offset(tap->offset());
6322 const Type* elem = _elem->meet(tap->_elem);
6323
6324 PTR ptr = meet_ptr(tap->ptr());
6325 ciKlass* res_klass = nullptr;
6326 bool res_xk = false;
6327 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6328 assert(res_xk == (ptr == Constant), "");
6329 return make(ptr, elem, res_klass, off);
6330 } // End of case KlassPtr
6331 case InstKlassPtr: {
6332 const TypeInstKlassPtr *tp = t->is_instklassptr();
6333 int offset = meet_offset(tp->offset());
6334 PTR ptr = meet_ptr(tp->ptr());
6335 const TypeInterfaces* interfaces = meet_interfaces(tp);
6336 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6337 const TypeInterfaces* this_interfaces = _interfaces;
6338
6339 switch (ptr) {
6340 case TopPTR:
6341 case AnyNull: // Fall 'down' to dual of object klass
6342 // For instances when a subclass meets a superclass we fall
6343 // below the centerline when the superclass is exact. We need to
6344 // do the same here.
6345 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6346 !tp->klass_is_exact()) {
6347 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6348 } else {
6349 // cannot subclass, so the meet has to fall badly below the centerline
6350 ptr = NotNull;
6351 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6352 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6353 }
6354 case Constant:
6355 case NotNull:
6356 case BotPTR: // Fall down to object klass
6357 // LCA is object_klass, but if we subclass from the top we can do better
6358 if (above_centerline(tp->ptr())) {
6359 // If 'tp' is above the centerline and it is Object class
6360 // then we can subclass in the Java class hierarchy.
6361 // For instances when a subclass meets a superclass we fall
6362 // below the centerline when the superclass is exact. We need
6363 // to do the same here.
6364 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6365 !tp->klass_is_exact()) {
6366 // that is, my array type is a subtype of 'tp' klass
6367 return make(ptr, _elem, _klass, offset);
6368 }
6369 }
6370 // The other case cannot happen, since t cannot be a subtype of an array.
6371 // The meet falls down to Object class below centerline.
6372 if (ptr == Constant)
6373 ptr = NotNull;
6374 interfaces = this_interfaces->intersection_with(tp_interfaces);
6375 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6376 default: typerr(t);
6377 }
6378 }
6379
6380 } // End of switch
6381 return this; // Return the double constant
6382 }
6383
6384 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) {
6385 static_assert(std::is_base_of<T2, T1>::value, "");
6386
6387 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6388 return true;
6389 }
6390
6391 int dummy;
6392 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6393
6394 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6395 return false;
6396 }
6397
6398 if (this_one->is_instance_type(other)) {
6399 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6400 other_exact;
6401 }
6402
6403 assert(this_one->is_array_type(other), "");
6404 const T1* other_ary = this_one->is_array_type(other);
6405 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6406 if (other_top_or_bottom) {
6407 return false;
6408 }
6409
6410 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6411 const TypePtr* this_elem = this_one->elem()->make_ptr();
6412 if (this_elem != nullptr && other_elem != nullptr) {
6413 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6414 }
6415 if (this_elem == nullptr && other_elem == nullptr) {
6416 return this_one->klass()->is_subtype_of(other->klass());
6417 }
6418 return false;
6419 }
6420
6421 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6422 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6423 }
6424
6425 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6426 static_assert(std::is_base_of<T2, T1>::value, "");
6427
6428 int dummy;
6429 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6430
6431 if (!this_one->is_array_type(other) ||
6432 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6485 }
6486
6487 const TypePtr* this_elem = this_one->elem()->make_ptr();
6488 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6489 if (other_elem != nullptr && this_elem != nullptr) {
6490 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6491 }
6492 if (other_elem == nullptr && this_elem == nullptr) {
6493 return this_one->klass()->is_subtype_of(other->klass());
6494 }
6495 return false;
6496 }
6497
6498 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6499 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6500 }
6501
6502 //------------------------------xdual------------------------------------------
6503 // Dual: compute field-by-field dual
6504 const Type *TypeAryKlassPtr::xdual() const {
6505 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6506 }
6507
6508 // Is there a single ciKlass* that can represent that type?
6509 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6510 if (elem()->isa_klassptr()) {
6511 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6512 if (k == nullptr) {
6513 return nullptr;
6514 }
6515 k = ciObjArrayKlass::make(k);
6516 return k;
6517 }
6518
6519 return klass();
6520 }
6521
6522 ciKlass* TypeAryKlassPtr::klass() const {
6523 if (_klass != nullptr) {
6524 return _klass;
6525 }
6526 ciKlass* k = nullptr;
6527 if (elem()->isa_klassptr()) {
6528 // leave null
6529 } else if ((elem()->base() == Type::Top) ||
6530 (elem()->base() == Type::Bottom)) {
6531 } else {
6532 k = ciTypeArrayKlass::make(elem()->basic_type());
6533 ((TypeAryKlassPtr*)this)->_klass = k;
6534 }
6535 return k;
6542 switch( _ptr ) {
6543 case Constant:
6544 st->print("precise ");
6545 case NotNull:
6546 {
6547 st->print("[");
6548 _elem->dump2(d, depth, st);
6549 _interfaces->dump(st);
6550 st->print(": ");
6551 }
6552 case BotPTR:
6553 if( !WizardMode && !Verbose && _ptr != Constant ) break;
6554 case TopPTR:
6555 case AnyNull:
6556 st->print(":%s", ptr_msg[_ptr]);
6557 if( _ptr == Constant ) st->print(":exact");
6558 break;
6559 default:
6560 break;
6561 }
6562
6563 if( _offset ) { // Dump offset, if any
6564 if( _offset == OffsetBot ) { st->print("+any"); }
6565 else if( _offset == OffsetTop ) { st->print("+unknown"); }
6566 else { st->print("+%d", _offset); }
6567 }
6568
6569 st->print(" *");
6570 }
6571 #endif
6572
6573 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6574 const Type* elem = this->elem();
6575 dims = 1;
6576 while (elem->isa_aryklassptr()) {
6577 elem = elem->is_aryklassptr()->elem();
6578 dims++;
6579 }
6580 return elem;
6581 }
6582
6583 //=============================================================================
6584 // Convenience common pre-built types.
6585
6586 //------------------------------make-------------------------------------------
6587 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6588 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6589 }
6590
6591 //------------------------------make-------------------------------------------
6592 const TypeFunc *TypeFunc::make(ciMethod* method) {
6593 Compile* C = Compile::current();
6594 const TypeFunc* tf = C->last_tf(method); // check cache
6595 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6596 const TypeTuple *domain;
6597 if (method->is_static()) {
6598 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6599 } else {
6600 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6601 }
6602 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6603 tf = TypeFunc::make(domain, range);
6604 C->set_last_tf(method, tf); // fill cache
6605 return tf;
6606 }
6607
6608 //------------------------------meet-------------------------------------------
6609 // Compute the MEET of two types. It returns a new Type object.
6610 const Type *TypeFunc::xmeet( const Type *t ) const {
6611 // Perform a fast test for common case; meeting the same types together.
6612 if( this == t ) return this; // Meeting same type-rep?
6613
6614 // Current "this->_base" is Func
6615 switch (t->base()) { // switch on original type
6616
6617 case Bottom: // Ye Olde Default
6618 return t;
6619
6620 default: // All else is a mistake
6621 typerr(t);
6622
6623 case Top:
6624 break;
6625 }
6626 return this; // Return the double constant
6627 }
6628
6629 //------------------------------xdual------------------------------------------
6630 // Dual: compute field-by-field dual
6631 const Type *TypeFunc::xdual() const {
6632 return this;
6633 }
6634
6635 //------------------------------eq---------------------------------------------
6636 // Structural equality check for Type representations
6637 bool TypeFunc::eq( const Type *t ) const {
6638 const TypeFunc *a = (const TypeFunc*)t;
6639 return _domain == a->_domain &&
6640 _range == a->_range;
6641 }
6642
6643 //------------------------------hash-------------------------------------------
6644 // Type-specific hashing function.
6645 uint TypeFunc::hash(void) const {
6646 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6647 }
6648
6649 //------------------------------dump2------------------------------------------
6650 // Dump Function Type
6651 #ifndef PRODUCT
6652 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6653 if( _range->cnt() <= Parms )
6654 st->print("void");
6655 else {
6656 uint i;
6657 for (i = Parms; i < _range->cnt()-1; i++) {
6658 _range->field_at(i)->dump2(d,depth,st);
6659 st->print("/");
6660 }
6661 _range->field_at(i)->dump2(d,depth,st);
6662 }
6663 st->print(" ");
6664 st->print("( ");
6665 if( !depth || d[this] ) { // Check for recursive dump
6666 st->print("...)");
6667 return;
6668 }
6669 d.Insert((void*)this,(void*)this); // Stop recursion
6670 if (Parms < _domain->cnt())
6671 _domain->field_at(Parms)->dump2(d,depth-1,st);
6672 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6673 st->print(", ");
6674 _domain->field_at(i)->dump2(d,depth-1,st);
6675 }
6676 st->print(" )");
6677 }
6678 #endif
6679
6680 //------------------------------singleton--------------------------------------
6681 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6682 // constants (Ldi nodes). Singletons are integer, float or double constants
6683 // or a single symbol.
6684 bool TypeFunc::singleton(void) const {
6685 return false; // Never a singleton
6686 }
6687
6688 bool TypeFunc::empty(void) const {
6689 return false; // Never empty
6690 }
6691
6692
6693 BasicType TypeFunc::return_type() const{
6694 if (range()->cnt() == TypeFunc::Parms) {
6695 return T_VOID;
6696 }
6697 return range()->field_at(TypeFunc::Parms)->basic_type();
6698 }
|
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(T_BOOLEAN, 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
2759
2760 //=============================================================================
2761 // Convenience common pre-built types.
2762 const TypePtr *TypePtr::NULL_PTR;
2763 const TypePtr *TypePtr::NOTNULL;
2764 const TypePtr *TypePtr::BOTTOM;
2765
2766 //------------------------------meet-------------------------------------------
2767 // Meet over the PTR enum
2768 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2769 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2770 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2771 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2772 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2773 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2774 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2775 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2776 };
2777
2778 //------------------------------make-------------------------------------------
2779 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2780 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2781 }
2782
2783 //------------------------------cast_to_ptr_type-------------------------------
2784 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2785 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2786 if( ptr == _ptr ) return this;
2787 return make(_base, ptr, _offset, _speculative, _inline_depth);
2788 }
2789
2790 //------------------------------get_con----------------------------------------
2791 intptr_t TypePtr::get_con() const {
2792 assert( _ptr == Null, "" );
2793 return offset();
2794 }
2795
2796 //------------------------------meet-------------------------------------------
2797 // Compute the MEET of two types. It returns a new Type object.
2798 const Type *TypePtr::xmeet(const Type *t) const {
2799 const Type* res = xmeet_helper(t);
2800 if (res->isa_ptr() == nullptr) {
2801 return res;
2802 }
2803
2804 const TypePtr* res_ptr = res->is_ptr();
2805 if (res_ptr->speculative() != nullptr) {
2806 // type->speculative() is null means that speculation is no better
2807 // than type, i.e. type->speculative() == type. So there are 2
2808 // ways to represent the fact that we have no useful speculative
2809 // data and we should use a single one to be able to test for
2810 // equality between types. Check whether type->speculative() ==
2811 // type and set speculative to null if it is the case.
2812 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2813 return res_ptr->remove_speculative();
2844 int depth = meet_inline_depth(tp->inline_depth());
2845 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2846 }
2847 case RawPtr: // For these, flip the call around to cut down
2848 case OopPtr:
2849 case InstPtr: // on the cases I have to handle.
2850 case AryPtr:
2851 case MetadataPtr:
2852 case KlassPtr:
2853 case InstKlassPtr:
2854 case AryKlassPtr:
2855 return t->xmeet(this); // Call in reverse direction
2856 default: // All else is a mistake
2857 typerr(t);
2858
2859 }
2860 return this;
2861 }
2862
2863 //------------------------------meet_offset------------------------------------
2864 Type::Offset TypePtr::meet_offset(int offset) const {
2865 return _offset.meet(Offset(offset));
2866 }
2867
2868 //------------------------------dual_offset------------------------------------
2869 Type::Offset TypePtr::dual_offset() const {
2870 return _offset.dual();
2871 }
2872
2873 //------------------------------xdual------------------------------------------
2874 // Dual: compute field-by-field dual
2875 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2876 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2877 };
2878 const Type *TypePtr::xdual() const {
2879 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2880 }
2881
2882 //------------------------------xadd_offset------------------------------------
2883 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2884 return _offset.add(offset);
2885 }
2886
2887 //------------------------------add_offset-------------------------------------
2888 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2889 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2890 }
2891
2892 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2893 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2894 }
2895
2896 //------------------------------eq---------------------------------------------
2897 // Structural equality check for Type representations
2898 bool TypePtr::eq( const Type *t ) const {
2899 const TypePtr *a = (const TypePtr*)t;
2900 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2901 }
2902
2903 //------------------------------hash-------------------------------------------
2904 // Type-specific hashing function.
2905 uint TypePtr::hash(void) const {
2906 return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2907 }
2908
2909 /**
2910 * Return same type without a speculative part
2911 */
2912 const TypePtr* TypePtr::remove_speculative() const {
2913 if (_speculative == nullptr) {
2914 return this;
2915 }
2916 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2917 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2918 }
2919
2920 /**
2921 * Return same type but drop speculative part if we know we won't use
2922 * it
2923 */
2924 const Type* TypePtr::cleanup_speculative() const {
2925 if (speculative() == nullptr) {
2926 return this;
3152 }
3153 // We already know the speculative type is always null
3154 if (speculative_always_null()) {
3155 return false;
3156 }
3157 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3158 return false;
3159 }
3160 return true;
3161 }
3162
3163 //------------------------------dump2------------------------------------------
3164 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3165 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3166 };
3167
3168 #ifndef PRODUCT
3169 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3170 if( _ptr == Null ) st->print("null");
3171 else st->print("%s *", ptr_msg[_ptr]);
3172 _offset.dump2(st);
3173 dump_inline_depth(st);
3174 dump_speculative(st);
3175 }
3176
3177 /**
3178 *dump the speculative part of the type
3179 */
3180 void TypePtr::dump_speculative(outputStream *st) const {
3181 if (_speculative != nullptr) {
3182 st->print(" (speculative=");
3183 _speculative->dump_on(st);
3184 st->print(")");
3185 }
3186 }
3187
3188 /**
3189 *dump the inline depth of the type
3190 */
3191 void TypePtr::dump_inline_depth(outputStream *st) const {
3192 if (_inline_depth != InlineDepthBottom) {
3193 if (_inline_depth == InlineDepthTop) {
3194 st->print(" (inline_depth=InlineDepthTop)");
3195 } else {
3196 st->print(" (inline_depth=%d)", _inline_depth);
3197 }
3198 }
3199 }
3200 #endif
3201
3202 //------------------------------singleton--------------------------------------
3203 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3204 // constants
3205 bool TypePtr::singleton(void) const {
3206 // TopPTR, Null, AnyNull, Constant are all singletons
3207 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3208 }
3209
3210 bool TypePtr::empty(void) const {
3211 return (_offset == Offset::top) || above_centerline(_ptr);
3212 }
3213
3214 //=============================================================================
3215 // Convenience common pre-built types.
3216 const TypeRawPtr *TypeRawPtr::BOTTOM;
3217 const TypeRawPtr *TypeRawPtr::NOTNULL;
3218
3219 //------------------------------make-------------------------------------------
3220 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3221 assert( ptr != Constant, "what is the constant?" );
3222 assert( ptr != Null, "Use TypePtr for null" );
3223 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3224 }
3225
3226 const TypeRawPtr *TypeRawPtr::make(address bits) {
3227 assert(bits != nullptr, "Use TypePtr for null");
3228 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3229 }
3230
3231 //------------------------------cast_to_ptr_type-------------------------------
3592 void TypeInterfaces::verify_is_loaded() const {
3593 for (int i = 0; i < _interfaces.length(); i++) {
3594 ciKlass* interface = _interfaces.at(i);
3595 assert(interface->is_loaded(), "Interface not loaded");
3596 }
3597 }
3598 #endif
3599
3600 // Can't be implemented because there's no way to know if the type is above or below the center line.
3601 const Type* TypeInterfaces::xmeet(const Type* t) const {
3602 ShouldNotReachHere();
3603 return Type::xmeet(t);
3604 }
3605
3606 bool TypeInterfaces::singleton(void) const {
3607 ShouldNotReachHere();
3608 return Type::singleton();
3609 }
3610
3611 //------------------------------TypeOopPtr-------------------------------------
3612 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3613 int instance_id, const TypePtr* speculative, int inline_depth)
3614 : TypePtr(t, ptr, offset, speculative, inline_depth),
3615 _const_oop(o), _klass(k),
3616 _interfaces(interfaces),
3617 _klass_is_exact(xk),
3618 _is_ptr_to_narrowoop(false),
3619 _is_ptr_to_narrowklass(false),
3620 _is_ptr_to_boxed_value(false),
3621 _instance_id(instance_id) {
3622 #ifdef ASSERT
3623 if (klass() != nullptr && klass()->is_loaded()) {
3624 interfaces->verify_is_loaded();
3625 }
3626 #endif
3627 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3628 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3629 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3630 }
3631 #ifdef _LP64
3632 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3633 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3634 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3635 } else if (klass() == nullptr) {
3636 // Array with unknown body type
3637 assert(this->isa_aryptr(), "only arrays without klass");
3638 _is_ptr_to_narrowoop = UseCompressedOops;
3639 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3640 if (klass()->is_obj_array_klass()) {
3641 _is_ptr_to_narrowoop = true;
3642 } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3643 // Check if the field of the inline type array element contains oops
3644 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3645 int foffset = field_offset.get() + vk->first_field_offset();
3646 ciField* field = vk->get_field_by_offset(foffset, false);
3647 assert(field != nullptr, "missing field");
3648 BasicType bt = field->layout_type();
3649 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3650 }
3651 } else if (klass()->is_instance_klass()) {
3652 if (this->isa_klassptr()) {
3653 // Perm objects don't use compressed references
3654 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3655 // unsafe access
3656 _is_ptr_to_narrowoop = UseCompressedOops;
3657 } else {
3658 assert(this->isa_instptr(), "must be an instance ptr.");
3659 if (klass() == ciEnv::current()->Class_klass() &&
3660 (this->offset() == java_lang_Class::klass_offset() ||
3661 this->offset() == java_lang_Class::array_klass_offset())) {
3662 // Special hidden fields from the Class.
3663 assert(this->isa_instptr(), "must be an instance ptr.");
3664 _is_ptr_to_narrowoop = false;
3665 } else if (klass() == ciEnv::current()->Class_klass() &&
3666 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3667 // Static fields
3668 ciField* field = nullptr;
3669 if (const_oop() != nullptr) {
3670 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3671 field = k->get_field_by_offset(this->offset(), true);
3672 }
3673 if (field != nullptr) {
3674 BasicType basic_elem_type = field->layout_type();
3675 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3676 } else {
3677 // unsafe access
3678 _is_ptr_to_narrowoop = UseCompressedOops;
3679 }
3680 } else {
3681 // Instance fields which contains a compressed oop references.
3682 ciInstanceKlass* ik = klass()->as_instance_klass();
3683 ciField* field = ik->get_field_by_offset(this->offset(), false);
3684 if (field != nullptr) {
3685 BasicType basic_elem_type = field->layout_type();
3686 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3687 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3688 // Compile::find_alias_type() cast exactness on all types to verify
3689 // that it does not affect alias type.
3690 _is_ptr_to_narrowoop = UseCompressedOops;
3691 } else {
3692 // Type for the copy start in LibraryCallKit::inline_native_clone().
3693 _is_ptr_to_narrowoop = UseCompressedOops;
3694 }
3695 }
3696 }
3697 }
3698 }
3699 #endif
3700 }
3701
3702 //------------------------------make-------------------------------------------
3703 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3704 const TypePtr* speculative, int inline_depth) {
3705 assert(ptr != Constant, "no constant generic pointers");
3706 ciKlass* k = Compile::current()->env()->Object_klass();
3707 bool xk = false;
3708 ciObject* o = nullptr;
3709 const TypeInterfaces* interfaces = TypeInterfaces::make();
3710 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3711 }
3712
3713
3714 //------------------------------cast_to_ptr_type-------------------------------
3715 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3716 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3717 if( ptr == _ptr ) return this;
3718 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3719 }
3720
3721 //-----------------------------cast_to_instance_id----------------------------
3722 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3723 // There are no instances of a general oop.
3724 // Return self unchanged.
3725 return this;
3726 }
3727
3728 //-----------------------------cast_to_exactness-------------------------------
3729 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3730 // There is no such thing as an exact general oop.
3731 // Return self unchanged.
3732 return this;
3733 }
3734
3735 //------------------------------as_klass_type----------------------------------
3736 // Return the klass type corresponding to this instance or array type.
3737 // It is the type that is loaded from an object of this type.
3738 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3739 ShouldNotReachHere();
3740 return nullptr;
3741 }
3742
3743 //------------------------------meet-------------------------------------------
3744 // Compute the MEET of two types. It returns a new Type object.
3745 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3746 // Perform a fast test for common case; meeting the same types together.
3747 if( this == t ) return this; // Meeting same type-rep?
3748
3749 // Current "this->_base" is OopPtr
3750 switch (t->base()) { // switch on original type
3751
3752 case Int: // Mixing ints & oops happens when javac
3753 case Long: // reuses local variables
3754 case FloatTop:
3760 case NarrowOop:
3761 case NarrowKlass:
3762 case Bottom: // Ye Olde Default
3763 return Type::BOTTOM;
3764 case Top:
3765 return this;
3766
3767 default: // All else is a mistake
3768 typerr(t);
3769
3770 case RawPtr:
3771 case MetadataPtr:
3772 case KlassPtr:
3773 case InstKlassPtr:
3774 case AryKlassPtr:
3775 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3776
3777 case AnyPtr: {
3778 // Found an AnyPtr type vs self-OopPtr type
3779 const TypePtr *tp = t->is_ptr();
3780 Offset offset = meet_offset(tp->offset());
3781 PTR ptr = meet_ptr(tp->ptr());
3782 const TypePtr* speculative = xmeet_speculative(tp);
3783 int depth = meet_inline_depth(tp->inline_depth());
3784 switch (tp->ptr()) {
3785 case Null:
3786 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3787 // else fall through:
3788 case TopPTR:
3789 case AnyNull: {
3790 int instance_id = meet_instance_id(InstanceTop);
3791 return make(ptr, offset, instance_id, speculative, depth);
3792 }
3793 case BotPTR:
3794 case NotNull:
3795 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3796 default: typerr(t);
3797 }
3798 }
3799
3800 case OopPtr: { // Meeting to other OopPtrs
3802 int instance_id = meet_instance_id(tp->instance_id());
3803 const TypePtr* speculative = xmeet_speculative(tp);
3804 int depth = meet_inline_depth(tp->inline_depth());
3805 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3806 }
3807
3808 case InstPtr: // For these, flip the call around to cut down
3809 case AryPtr:
3810 return t->xmeet(this); // Call in reverse direction
3811
3812 } // End of switch
3813 return this; // Return the double constant
3814 }
3815
3816
3817 //------------------------------xdual------------------------------------------
3818 // Dual of a pure heap pointer. No relevant klass or oop information.
3819 const Type *TypeOopPtr::xdual() const {
3820 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3821 assert(const_oop() == nullptr, "no constants here");
3822 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());
3823 }
3824
3825 //--------------------------make_from_klass_common-----------------------------
3826 // Computes the element-type given a klass.
3827 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3828 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3829 Compile* C = Compile::current();
3830 Dependencies* deps = C->dependencies();
3831 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3832 // Element is an instance
3833 bool klass_is_exact = false;
3834 if (klass->is_loaded()) {
3835 // Try to set klass_is_exact.
3836 ciInstanceKlass* ik = klass->as_instance_klass();
3837 klass_is_exact = ik->is_final();
3838 if (!klass_is_exact && klass_change
3839 && deps != nullptr && UseUniqueSubclasses) {
3840 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3841 if (sub != nullptr) {
3842 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3843 klass = ik = sub;
3844 klass_is_exact = sub->is_final();
3845 }
3846 }
3847 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3848 !ik->is_interface() && !ik->has_subklass()) {
3849 // Add a dependence; if concrete subclass added we need to recompile
3850 deps->assert_leaf_type(ik);
3851 klass_is_exact = true;
3852 }
3853 }
3854 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3855 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3856 } else if (klass->is_obj_array_klass()) {
3857 // Element is an object or inline type array. Recursively call ourself.
3858 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3859 // Determine null-free/flat properties
3860 const TypeOopPtr* exact_etype = etype;
3861 if (etype->can_be_inline_type()) {
3862 // Use exact type if element can be an inline type
3863 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3864 }
3865 bool not_null_free = !exact_etype->can_be_inline_type();
3866 bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
3867 // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
3868 bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
3869 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
3870 // We used to pass NotNull in here, asserting that the sub-arrays
3871 // are all not-null. This is not true in generally, as code can
3872 // slam nullptrs down in the subarrays.
3873 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3874 return arr;
3875 } else if (klass->is_type_array_klass()) {
3876 // Element is an typeArray
3877 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3878 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3879 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3880 // We used to pass NotNull in here, asserting that the array pointer
3881 // is not-null. That was not true in general.
3882 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3883 return arr;
3884 } else if (klass->is_flat_array_klass()) {
3885 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3886 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3887 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
3888 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3889 return arr;
3890 } else {
3891 ShouldNotReachHere();
3892 return nullptr;
3893 }
3894 }
3895
3896 //------------------------------make_from_constant-----------------------------
3897 // Make a java pointer from an oop constant
3898 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3899 assert(!o->is_null_object(), "null object not yet handled here.");
3900
3901 const bool make_constant = require_constant || o->should_be_constant();
3902
3903 ciKlass* klass = o->klass();
3904 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3905 // Element is an instance or inline type
3906 if (make_constant) {
3907 return TypeInstPtr::make(o);
3908 } else {
3909 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3910 }
3911 } else if (klass->is_obj_array_klass()) {
3912 // Element is an object array. Recursively call ourself.
3913 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3914 bool is_flat = o->as_obj_array()->is_flat();
3915 bool is_null_free = o->as_obj_array()->is_null_free();
3916 if (is_null_free) {
3917 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3918 }
3919 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3920 /* stable= */ false, /* flat= */ false, /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free);
3921 // We used to pass NotNull in here, asserting that the sub-arrays
3922 // are all not-null. This is not true in generally, as code can
3923 // slam nulls down in the subarrays.
3924 if (make_constant) {
3925 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3926 } else {
3927 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3928 }
3929 } else if (klass->is_type_array_klass()) {
3930 // Element is an typeArray
3931 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3932 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3933 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3934 // We used to pass NotNull in here, asserting that the array pointer
3935 // is not-null. That was not true in general.
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_flat_array_klass()) {
3942 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3943 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3944 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
3945 // We used to pass NotNull in here, asserting that the sub-arrays
3946 // are all not-null. This is not true in generally, as code can
3947 // slam nullptrs down in the subarrays.
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 }
3954
3955 fatal("unhandled object type");
3956 return nullptr;
3957 }
3958
3959 //------------------------------get_con----------------------------------------
3960 intptr_t TypeOopPtr::get_con() const {
3961 assert( _ptr == Null || _ptr == Constant, "" );
3962 assert(offset() >= 0, "");
3963
3964 if (offset() != 0) {
3965 // After being ported to the compiler interface, the compiler no longer
3966 // directly manipulates the addresses of oops. Rather, it only has a pointer
3967 // to a handle at compile time. This handle is embedded in the generated
3968 // code and dereferenced at the time the nmethod is made. Until that time,
3969 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3970 // have access to the addresses!). This does not seem to currently happen,
3971 // but this assertion here is to help prevent its occurrence.
3972 tty->print_cr("Found oop constant with non-zero offset");
3973 ShouldNotReachHere();
3974 }
3975
3976 return (intptr_t)const_oop()->constant_encoding();
3977 }
3978
3979
3980 //-----------------------------filter------------------------------------------
3981 // Do not allow interface-vs.-noninterface joins to collapse to top.
3982 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3983
3984 const Type* ft = join_helper(kills, include_speculative);
4005 } else {
4006 return one->equals(two) && TypePtr::eq(t);
4007 }
4008 }
4009
4010 //------------------------------hash-------------------------------------------
4011 // Type-specific hashing function.
4012 uint TypeOopPtr::hash(void) const {
4013 return
4014 (uint)(const_oop() ? const_oop()->hash() : 0) +
4015 (uint)_klass_is_exact +
4016 (uint)_instance_id + TypePtr::hash();
4017 }
4018
4019 //------------------------------dump2------------------------------------------
4020 #ifndef PRODUCT
4021 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4022 st->print("oopptr:%s", ptr_msg[_ptr]);
4023 if( _klass_is_exact ) st->print(":exact");
4024 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4025 _offset.dump2(st);
4026 if (_instance_id == InstanceTop)
4027 st->print(",iid=top");
4028 else if (_instance_id != InstanceBot)
4029 st->print(",iid=%d",_instance_id);
4030
4031 dump_inline_depth(st);
4032 dump_speculative(st);
4033 }
4034 #endif
4035
4036 //------------------------------singleton--------------------------------------
4037 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4038 // constants
4039 bool TypeOopPtr::singleton(void) const {
4040 // detune optimizer to not generate constant oop + constant offset as a constant!
4041 // TopPTR, Null, AnyNull, Constant are all singletons
4042 return (offset() == 0) && !below_centerline(_ptr);
4043 }
4044
4045 //------------------------------add_offset-------------------------------------
4046 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4047 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4048 }
4049
4050 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4051 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4052 }
4053
4054 /**
4055 * Return same type without a speculative part
4056 */
4057 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4058 if (_speculative == nullptr) {
4059 return this;
4060 }
4061 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4062 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4063 }
4064
4065 /**
4066 * Return same type but drop speculative part if we know we won't use
4067 * it
4068 */
4069 const Type* TypeOopPtr::cleanup_speculative() const {
4070 // If the klass is exact and the ptr is not null then there's
4071 // nothing that the speculative type can help us with
4144 const TypeInstPtr *TypeInstPtr::BOTTOM;
4145 const TypeInstPtr *TypeInstPtr::MIRROR;
4146 const TypeInstPtr *TypeInstPtr::MARK;
4147 const TypeInstPtr *TypeInstPtr::KLASS;
4148
4149 // Is there a single ciKlass* that can represent that type?
4150 ciKlass* TypeInstPtr::exact_klass_helper() const {
4151 if (_interfaces->empty()) {
4152 return _klass;
4153 }
4154 if (_klass != ciEnv::current()->Object_klass()) {
4155 if (_interfaces->eq(_klass->as_instance_klass())) {
4156 return _klass;
4157 }
4158 return nullptr;
4159 }
4160 return _interfaces->exact_klass();
4161 }
4162
4163 //------------------------------TypeInstPtr-------------------------------------
4164 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4165 bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4166 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4167 _flat_in_array(flat_in_array) {
4168 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4169 assert(k != nullptr &&
4170 (k->is_loaded() || o == nullptr),
4171 "cannot have constants with non-loaded klass");
4172 assert(!klass()->flat_in_array() || flat_in_array, "Should be flat in array");
4173 assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4174 };
4175
4176 //------------------------------make-------------------------------------------
4177 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4178 ciKlass* k,
4179 const TypeInterfaces* interfaces,
4180 bool xk,
4181 ciObject* o,
4182 Offset offset,
4183 bool flat_in_array,
4184 int instance_id,
4185 const TypePtr* speculative,
4186 int inline_depth) {
4187 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4188 // Either const_oop() is null or else ptr is Constant
4189 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4190 "constant pointers must have a value supplied" );
4191 // Ptr is never Null
4192 assert( ptr != Null, "null pointers are not typed" );
4193
4194 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4195 if (ptr == Constant) {
4196 // Note: This case includes meta-object constants, such as methods.
4197 xk = true;
4198 } else if (k->is_loaded()) {
4199 ciInstanceKlass* ik = k->as_instance_klass();
4200 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4201 assert(!ik->is_interface(), "no interface here");
4202 if (xk && ik->is_interface()) xk = false; // no exact interface
4203 }
4204
4205 // Check if this type is known to be flat in arrays
4206 flat_in_array = flat_in_array || k->flat_in_array();
4207
4208 // Now hash this baby
4209 TypeInstPtr *result =
4210 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4211
4212 return result;
4213 }
4214
4215 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4216 if (k->is_instance_klass()) {
4217 if (k->is_loaded()) {
4218 if (k->is_interface() && interface_handling == ignore_interfaces) {
4219 assert(interface, "no interface expected");
4220 k = ciEnv::current()->Object_klass();
4221 const TypeInterfaces* interfaces = TypeInterfaces::make();
4222 return interfaces;
4223 }
4224 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4225 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4226 if (k->is_interface()) {
4227 assert(interface, "no interface expected");
4228 k = ciEnv::current()->Object_klass();
4229 } else {
4230 assert(klass, "no instance klass expected");
4256 switch (bt) {
4257 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4258 case T_INT: return TypeInt::make(constant.as_int());
4259 case T_CHAR: return TypeInt::make(constant.as_char());
4260 case T_BYTE: return TypeInt::make(constant.as_byte());
4261 case T_SHORT: return TypeInt::make(constant.as_short());
4262 case T_FLOAT: return TypeF::make(constant.as_float());
4263 case T_DOUBLE: return TypeD::make(constant.as_double());
4264 case T_LONG: return TypeLong::make(constant.as_long());
4265 default: break;
4266 }
4267 fatal("Invalid boxed value type '%s'", type2name(bt));
4268 return nullptr;
4269 }
4270
4271 //------------------------------cast_to_ptr_type-------------------------------
4272 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4273 if( ptr == _ptr ) return this;
4274 // Reconstruct _sig info here since not a problem with later lazy
4275 // construction, _sig will show up on demand.
4276 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4277 }
4278
4279
4280 //-----------------------------cast_to_exactness-------------------------------
4281 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4282 if( klass_is_exact == _klass_is_exact ) return this;
4283 if (!_klass->is_loaded()) return this;
4284 ciInstanceKlass* ik = _klass->as_instance_klass();
4285 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4286 assert(!ik->is_interface(), "no interface here");
4287 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4288 }
4289
4290 //-----------------------------cast_to_instance_id----------------------------
4291 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4292 if( instance_id == _instance_id ) return this;
4293 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4294 }
4295
4296 //------------------------------xmeet_unloaded---------------------------------
4297 // Compute the MEET of two InstPtrs when at least one is unloaded.
4298 // Assume classes are different since called after check for same name/class-loader
4299 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4300 Offset off = meet_offset(tinst->offset());
4301 PTR ptr = meet_ptr(tinst->ptr());
4302 int instance_id = meet_instance_id(tinst->instance_id());
4303 const TypePtr* speculative = xmeet_speculative(tinst);
4304 int depth = meet_inline_depth(tinst->inline_depth());
4305
4306 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4307 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4308 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4309 //
4310 // Meet unloaded class with java/lang/Object
4311 //
4312 // Meet
4313 // | Unloaded Class
4314 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4315 // ===================================================================
4316 // TOP | ..........................Unloaded......................|
4317 // AnyNull | U-AN |................Unloaded......................|
4318 // Constant | ... O-NN .................................. | O-BOT |
4319 // NotNull | ... O-NN .................................. | O-BOT |
4320 // BOTTOM | ........................Object-BOTTOM ..................|
4321 //
4322 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4323 //
4324 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4325 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4326 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4327 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4328 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4329 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4330 }
4331 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4332
4333 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4334 }
4335
4336 // Both are unloaded, not the same class, not Object
4337 // Or meet unloaded with a different loaded class, not java/lang/Object
4338 if (ptr != TypePtr::BotPTR) {
4339 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4340 }
4341 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4342 }
4343
4344
4345 //------------------------------meet-------------------------------------------
4366 case Top:
4367 return this;
4368
4369 default: // All else is a mistake
4370 typerr(t);
4371
4372 case MetadataPtr:
4373 case KlassPtr:
4374 case InstKlassPtr:
4375 case AryKlassPtr:
4376 case RawPtr: return TypePtr::BOTTOM;
4377
4378 case AryPtr: { // All arrays inherit from Object class
4379 // Call in reverse direction to avoid duplication
4380 return t->is_aryptr()->xmeet_helper(this);
4381 }
4382
4383 case OopPtr: { // Meeting to OopPtrs
4384 // Found a OopPtr type vs self-InstPtr type
4385 const TypeOopPtr *tp = t->is_oopptr();
4386 Offset offset = meet_offset(tp->offset());
4387 PTR ptr = meet_ptr(tp->ptr());
4388 switch (tp->ptr()) {
4389 case TopPTR:
4390 case AnyNull: {
4391 int instance_id = meet_instance_id(InstanceTop);
4392 const TypePtr* speculative = xmeet_speculative(tp);
4393 int depth = meet_inline_depth(tp->inline_depth());
4394 return make(ptr, klass(), _interfaces, klass_is_exact(),
4395 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4396 }
4397 case NotNull:
4398 case BotPTR: {
4399 int instance_id = meet_instance_id(tp->instance_id());
4400 const TypePtr* speculative = xmeet_speculative(tp);
4401 int depth = meet_inline_depth(tp->inline_depth());
4402 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4403 }
4404 default: typerr(t);
4405 }
4406 }
4407
4408 case AnyPtr: { // Meeting to AnyPtrs
4409 // Found an AnyPtr type vs self-InstPtr type
4410 const TypePtr *tp = t->is_ptr();
4411 Offset offset = meet_offset(tp->offset());
4412 PTR ptr = meet_ptr(tp->ptr());
4413 int instance_id = meet_instance_id(InstanceTop);
4414 const TypePtr* speculative = xmeet_speculative(tp);
4415 int depth = meet_inline_depth(tp->inline_depth());
4416 switch (tp->ptr()) {
4417 case Null:
4418 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4419 // else fall through to AnyNull
4420 case TopPTR:
4421 case AnyNull: {
4422 return make(ptr, klass(), _interfaces, klass_is_exact(),
4423 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4424 }
4425 case NotNull:
4426 case BotPTR:
4427 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4428 default: typerr(t);
4429 }
4430 }
4431
4432 /*
4433 A-top }
4434 / | \ } Tops
4435 B-top A-any C-top }
4436 | / | \ | } Any-nulls
4437 B-any | C-any }
4438 | | |
4439 B-con A-con C-con } constants; not comparable across classes
4440 | | |
4441 B-not | C-not }
4442 | \ | / | } not-nulls
4443 B-bot A-not C-bot }
4444 \ | / } Bottoms
4445 A-bot }
4446 */
4447
4448 case InstPtr: { // Meeting 2 Oops?
4449 // Found an InstPtr sub-type vs self-InstPtr type
4450 const TypeInstPtr *tinst = t->is_instptr();
4451 Offset off = meet_offset(tinst->offset());
4452 PTR ptr = meet_ptr(tinst->ptr());
4453 int instance_id = meet_instance_id(tinst->instance_id());
4454 const TypePtr* speculative = xmeet_speculative(tinst);
4455 int depth = meet_inline_depth(tinst->inline_depth());
4456 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4457
4458 ciKlass* tinst_klass = tinst->klass();
4459 ciKlass* this_klass = klass();
4460
4461 ciKlass* res_klass = nullptr;
4462 bool res_xk = false;
4463 bool res_flat_in_array = false;
4464 const Type* res;
4465 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4466
4467 if (kind == UNLOADED) {
4468 // One of these classes has not been loaded
4469 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4470 #ifndef PRODUCT
4471 if (PrintOpto && Verbose) {
4472 tty->print("meet of unloaded classes resulted in: ");
4473 unloaded_meet->dump();
4474 tty->cr();
4475 tty->print(" this == ");
4476 dump();
4477 tty->cr();
4478 tty->print(" tinst == ");
4479 tinst->dump();
4480 tty->cr();
4481 }
4482 #endif
4483 res = unloaded_meet;
4484 } else {
4485 if (kind == NOT_SUBTYPE && instance_id > 0) {
4486 instance_id = InstanceBot;
4487 } else if (kind == LCA) {
4488 instance_id = InstanceBot;
4489 }
4490 ciObject* o = nullptr; // Assume not constant when done
4491 ciObject* this_oop = const_oop();
4492 ciObject* tinst_oop = tinst->const_oop();
4493 if (ptr == Constant) {
4494 if (this_oop != nullptr && tinst_oop != nullptr &&
4495 this_oop->equals(tinst_oop))
4496 o = this_oop;
4497 else if (above_centerline(_ptr)) {
4498 assert(!tinst_klass->is_interface(), "");
4499 o = tinst_oop;
4500 } else if (above_centerline(tinst->_ptr)) {
4501 assert(!this_klass->is_interface(), "");
4502 o = this_oop;
4503 } else
4504 ptr = NotNull;
4505 }
4506 res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4507 }
4508
4509 return res;
4510
4511 } // End of case InstPtr
4512
4513 } // End of switch
4514 return this; // Return the double constant
4515 }
4516
4517 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4518 ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4519 ciKlass* this_klass = this_type->klass();
4520 ciKlass* other_klass = other_type->klass();
4521 const bool this_flat_in_array = this_type->flat_in_array();
4522 const bool other_flat_in_array = other_type->flat_in_array();
4523 const bool this_not_flat_in_array = this_type->not_flat_in_array();
4524 const bool other_not_flat_in_array = other_type->not_flat_in_array();
4525
4526 bool this_xk = this_type->klass_is_exact();
4527 bool other_xk = other_type->klass_is_exact();
4528 PTR this_ptr = this_type->ptr();
4529 PTR other_ptr = other_type->ptr();
4530 const TypeInterfaces* this_interfaces = this_type->interfaces();
4531 const TypeInterfaces* other_interfaces = other_type->interfaces();
4532 // Check for easy case; klasses are equal (and perhaps not loaded!)
4533 // If we have constants, then we created oops so classes are loaded
4534 // and we can handle the constants further down. This case handles
4535 // both-not-loaded or both-loaded classes
4536 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4537 res_klass = this_klass;
4538 res_xk = this_xk;
4539 res_flat_in_array = this_flat_in_array;
4540 return QUICK;
4541 }
4542
4543 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4544 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4545 return UNLOADED;
4546 }
4547
4548 // !!! Here's how the symmetry requirement breaks down into invariants:
4549 // If we split one up & one down AND they subtype, take the down man.
4550 // If we split one up & one down AND they do NOT subtype, "fall hard".
4551 // If both are up and they subtype, take the subtype class.
4552 // If both are up and they do NOT subtype, "fall hard".
4553 // If both are down and they subtype, take the supertype class.
4554 // If both are down and they do NOT subtype, "fall hard".
4555 // Constants treated as down.
4556
4557 // Now, reorder the above list; observe that both-down+subtype is also
4558 // "fall hard"; "fall hard" becomes the default case:
4559 // If we split one up & one down AND they subtype, take the down man.
4560 // If both are up and they subtype, take the subtype class.
4561
4562 // If both are down and they subtype, "fall hard".
4563 // If both are down and they do NOT subtype, "fall hard".
4564 // If both are up and they do NOT subtype, "fall hard".
4565 // If we split one up & one down AND they do NOT subtype, "fall hard".
4566
4567 // If a proper subtype is exact, and we return it, we return it exactly.
4568 // If a proper supertype is exact, there can be no subtyping relationship!
4569 // If both types are equal to the subtype, exactness is and-ed below the
4570 // centerline and or-ed above it. (N.B. Constants are always exact.)
4571
4572 // Check for subtyping:
4573 // Flat in array matrix, yes = y, no = n, maybe = m, top/empty = T:
4574 // yes maybe no -> Super Klass
4575 // yes y y y
4576 // maybe y m m
4577 // no T n n
4578 // |
4579 // v
4580 // Sub Klass
4581
4582 const T* subtype = nullptr;
4583 bool subtype_exact = false;
4584 bool flat_in_array = false;
4585 if (this_type->is_same_java_type_as(other_type)) {
4586 subtype = this_type;
4587 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4588 flat_in_array = below_centerline(ptr) ? (this_flat_in_array && other_flat_in_array) : (this_flat_in_array || other_flat_in_array);
4589 } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4590 subtype = this_type; // Pick subtyping class
4591 subtype_exact = this_xk;
4592 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4593 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4594 } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4595 subtype = other_type; // Pick subtyping class
4596 subtype_exact = other_xk;
4597 bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4598 flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4599 }
4600
4601 if (subtype) {
4602 if (above_centerline(ptr)) {
4603 // Both types are empty.
4604 this_type = other_type = subtype;
4605 this_xk = other_xk = subtype_exact;
4606 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4607 // this_type is empty while other_type is not. Take other_type.
4608 this_type = other_type;
4609 this_xk = other_xk;
4610 flat_in_array = other_flat_in_array;
4611 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4612 // other_type is empty while this_type is not. Take this_type.
4613 other_type = this_type; // this is down; keep down man
4614 flat_in_array = this_flat_in_array;
4615 } else {
4616 // this_type and other_type are both non-empty.
4617 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4618 }
4619 }
4620
4621 // Check for classes now being equal
4622 if (this_type->is_same_java_type_as(other_type)) {
4623 // If the klasses are equal, the constants may still differ. Fall to
4624 // NotNull if they do (neither constant is null; that is a special case
4625 // handled elsewhere).
4626 res_klass = this_type->klass();
4627 res_xk = this_xk;
4628 res_flat_in_array = subtype ? flat_in_array : this_flat_in_array;
4629 return SUBTYPE;
4630 } // Else classes are not equal
4631
4632 // Since klasses are different, we require a LCA in the Java
4633 // class hierarchy - which means we have to fall to at least NotNull.
4634 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4635 ptr = NotNull;
4636 }
4637
4638 interfaces = this_interfaces->intersection_with(other_interfaces);
4639
4640 // Now we find the LCA of Java classes
4641 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4642
4643 res_klass = k;
4644 res_xk = false;
4645 res_flat_in_array = this_flat_in_array && other_flat_in_array;
4646
4647 return LCA;
4648 }
4649
4650 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4651 return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4652 }
4653
4654 //------------------------java_mirror_type--------------------------------------
4655 ciType* TypeInstPtr::java_mirror_type(bool* is_null_free_array) const {
4656 // must be a singleton type
4657 if( const_oop() == nullptr ) return nullptr;
4658
4659 // must be of type java.lang.Class
4660 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4661 return const_oop()->as_instance()->java_mirror_type(is_null_free_array);
4662 }
4663
4664
4665 //------------------------------xdual------------------------------------------
4666 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4667 // inheritance mechanism.
4668 const Type *TypeInstPtr::xdual() const {
4669 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());
4670 }
4671
4672 //------------------------------eq---------------------------------------------
4673 // Structural equality check for Type representations
4674 bool TypeInstPtr::eq( const Type *t ) const {
4675 const TypeInstPtr *p = t->is_instptr();
4676 return
4677 klass()->equals(p->klass()) &&
4678 flat_in_array() == p->flat_in_array() &&
4679 _interfaces->eq(p->_interfaces) &&
4680 TypeOopPtr::eq(p); // Check sub-type stuff
4681 }
4682
4683 //------------------------------hash-------------------------------------------
4684 // Type-specific hashing function.
4685 uint TypeInstPtr::hash(void) const {
4686 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4687 }
4688
4689 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4690 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4691 }
4692
4693
4694 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4695 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4696 }
4697
4698 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4699 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4700 }
4701
4702
4703 //------------------------------dump2------------------------------------------
4704 // Dump oop Type
4705 #ifndef PRODUCT
4706 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4720 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4721 char* buf = ss.as_string(/* c_heap= */false);
4722 StringUtils::replace_no_expand(buf, "\n", "");
4723 st->print_raw(buf);
4724 }
4725 case BotPTR:
4726 if (!WizardMode && !Verbose) {
4727 if( _klass_is_exact ) st->print(":exact");
4728 break;
4729 }
4730 case TopPTR:
4731 case AnyNull:
4732 case NotNull:
4733 st->print(":%s", ptr_msg[_ptr]);
4734 if( _klass_is_exact ) st->print(":exact");
4735 break;
4736 default:
4737 break;
4738 }
4739
4740 _offset.dump2(st);
4741
4742 st->print(" *");
4743
4744 if (flat_in_array() && !klass()->is_inlinetype()) {
4745 st->print(" (flat in array)");
4746 }
4747
4748 if (_instance_id == InstanceTop)
4749 st->print(",iid=top");
4750 else if (_instance_id != InstanceBot)
4751 st->print(",iid=%d",_instance_id);
4752
4753 dump_inline_depth(st);
4754 dump_speculative(st);
4755 }
4756 #endif
4757
4758 //------------------------------add_offset-------------------------------------
4759 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4760 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4761 _instance_id, add_offset_speculative(offset), _inline_depth);
4762 }
4763
4764 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4765 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4766 _instance_id, with_offset_speculative(offset), _inline_depth);
4767 }
4768
4769 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4770 if (_speculative == nullptr) {
4771 return this;
4772 }
4773 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4774 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4775 _instance_id, nullptr, _inline_depth);
4776 }
4777
4778 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4779 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
4780 }
4781
4782 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4783 if (!UseInlineDepthForSpeculativeTypes) {
4784 return this;
4785 }
4786 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4787 }
4788
4789 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4790 assert(is_known_instance(), "should be known");
4791 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4792 }
4793
4794 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4795 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4796 }
4797
4798 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4799 bool xk = klass_is_exact();
4800 ciInstanceKlass* ik = klass()->as_instance_klass();
4801 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4802 if (_interfaces->eq(ik)) {
4803 Compile* C = Compile::current();
4804 Dependencies* deps = C->dependencies();
4805 deps->assert_leaf_type(ik);
4806 xk = true;
4807 }
4808 }
4809 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4810 }
4811
4812 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) {
4813 static_assert(std::is_base_of<T2, T1>::value, "");
4814
4815 if (!this_one->is_instance_type(other)) {
4816 return false;
4817 }
4818
4819 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4820 return true;
4821 }
4822
4823 return this_one->klass()->is_subtype_of(other->klass()) &&
4824 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4825 }
4826
4827
4828 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4829 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4834 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4835 return true;
4836 }
4837
4838 if (this_one->is_instance_type(other)) {
4839 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4840 }
4841
4842 int dummy;
4843 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4844 if (this_top_or_bottom) {
4845 return false;
4846 }
4847
4848 const T1* other_ary = this_one->is_array_type(other);
4849 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4850 const TypePtr* this_elem = this_one->elem()->make_ptr();
4851 if (other_elem != nullptr && this_elem != nullptr) {
4852 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4853 }
4854 if (other_elem == nullptr && this_elem == nullptr) {
4855 return this_one->klass()->is_subtype_of(other->klass());
4856 }
4857
4858 return false;
4859 }
4860
4861 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4862 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4863 }
4864
4865 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4866 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4867 }
4868
4869 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4870 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4871 }
4872
4873 //=============================================================================
4874 // Convenience common pre-built types.
4875 const TypeAryPtr *TypeAryPtr::RANGE;
4876 const TypeAryPtr *TypeAryPtr::OOPS;
4877 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4878 const TypeAryPtr *TypeAryPtr::BYTES;
4879 const TypeAryPtr *TypeAryPtr::SHORTS;
4880 const TypeAryPtr *TypeAryPtr::CHARS;
4881 const TypeAryPtr *TypeAryPtr::INTS;
4882 const TypeAryPtr *TypeAryPtr::LONGS;
4883 const TypeAryPtr *TypeAryPtr::FLOATS;
4884 const TypeAryPtr *TypeAryPtr::DOUBLES;
4885 const TypeAryPtr *TypeAryPtr::INLINES;
4886
4887 //------------------------------make-------------------------------------------
4888 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4889 int instance_id, const TypePtr* speculative, int inline_depth) {
4890 assert(!(k == nullptr && ary->_elem->isa_int()),
4891 "integral arrays must be pre-equipped with a class");
4892 if (!xk) xk = ary->ary_must_be_exact();
4893 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4894 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4895 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4896 k = nullptr;
4897 }
4898 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4899 k = nullptr;
4900 }
4901 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4902 }
4903
4904 //------------------------------make-------------------------------------------
4905 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4906 int instance_id, const TypePtr* speculative, int inline_depth,
4907 bool is_autobox_cache) {
4908 assert(!(k == nullptr && ary->_elem->isa_int()),
4909 "integral arrays must be pre-equipped with a class");
4910 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4911 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4912 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4913 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4914 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4915 k = nullptr;
4916 }
4917 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4918 k = nullptr;
4919 }
4920 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4921 }
4922
4923 //------------------------------cast_to_ptr_type-------------------------------
4924 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4925 if( ptr == _ptr ) return this;
4926 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4927 }
4928
4929
4930 //-----------------------------cast_to_exactness-------------------------------
4931 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4932 if( klass_is_exact == _klass_is_exact ) return this;
4933 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4934 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4935 }
4936
4937 //-----------------------------cast_to_instance_id----------------------------
4938 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4939 if( instance_id == _instance_id ) return this;
4940 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4941 }
4942
4943
4944 //-----------------------------max_array_length-------------------------------
4945 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4946 jint TypeAryPtr::max_array_length(BasicType etype) {
4947 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4948 if (etype == T_NARROWOOP) {
4949 etype = T_OBJECT;
4950 } else if (etype == T_ILLEGAL) { // bottom[]
4951 etype = T_BYTE; // will produce conservatively high value
4952 } else {
4953 fatal("not an element type: %s", type2name(etype));
4954 }
4955 }
4956 return arrayOopDesc::max_array_length(etype);
4957 }
4958
4959 //-----------------------------narrow_size_type-------------------------------
4960 // Narrow the given size type to the index range for the given array base type.
4976 if (hi > max_hi) {
4977 hi = max_hi;
4978 if (size->is_con()) {
4979 lo = hi;
4980 }
4981 chg = true;
4982 }
4983 // Negative length arrays will produce weird intermediate dead fast-path code
4984 if (lo > hi)
4985 return TypeInt::ZERO;
4986 if (!chg)
4987 return size;
4988 return TypeInt::make(lo, hi, Type::WidenMin);
4989 }
4990
4991 //-------------------------------cast_to_size----------------------------------
4992 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4993 assert(new_size != nullptr, "");
4994 new_size = narrow_size_type(new_size);
4995 if (new_size == size()) return this;
4996 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
4997 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4998 }
4999
5000 //-------------------------------cast_to_not_flat------------------------------
5001 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5002 if (not_flat == is_not_flat()) {
5003 return this;
5004 }
5005 assert(!not_flat || !is_flat(), "inconsistency");
5006 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
5007 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5008 // We keep the speculative part if it contains information about flat-/nullability.
5009 // Make sure it's removed if it's not better than the non-speculative type anymore.
5010 if (res->speculative() == res->remove_speculative()) {
5011 return res->remove_speculative();
5012 }
5013 return res;
5014 }
5015
5016 //-------------------------------cast_to_not_null_free-------------------------
5017 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5018 if (not_null_free == is_not_null_free()) {
5019 return this;
5020 }
5021 assert(!not_null_free || !is_flat(), "inconsistency");
5022 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
5023 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5024 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5025 // We keep the speculative part if it contains information about flat-/nullability.
5026 // Make sure it's removed if it's not better than the non-speculative type anymore.
5027 if (res->speculative() == res->remove_speculative()) {
5028 return res->remove_speculative();
5029 }
5030 return res;
5031 }
5032
5033 //---------------------------------update_properties---------------------------
5034 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5035 if ((from->is_flat() && is_not_flat()) ||
5036 (from->is_not_flat() && is_flat()) ||
5037 (from->is_null_free() && is_not_null_free()) ||
5038 (from->is_not_null_free() && is_null_free())) {
5039 return nullptr; // Inconsistent properties
5040 } else if (from->is_not_null_free()) {
5041 return cast_to_not_null_free(); // Implies not flat
5042 } else if (from->is_not_flat()) {
5043 return cast_to_not_flat();
5044 }
5045 return this;
5046 }
5047
5048 jint TypeAryPtr::flat_layout_helper() const {
5049 return klass()->as_flat_array_klass()->layout_helper();
5050 }
5051
5052 int TypeAryPtr::flat_elem_size() const {
5053 return klass()->as_flat_array_klass()->element_byte_size();
5054 }
5055
5056 int TypeAryPtr::flat_log_elem_size() const {
5057 return klass()->as_flat_array_klass()->log2_element_size();
5058 }
5059
5060 //------------------------------cast_to_stable---------------------------------
5061 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5062 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5063 return this;
5064
5065 const Type* elem = this->elem();
5066 const TypePtr* elem_ptr = elem->make_ptr();
5067
5068 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5069 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5070 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5071 }
5072
5073 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5074
5075 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5076 }
5077
5078 //-----------------------------stable_dimension--------------------------------
5079 int TypeAryPtr::stable_dimension() const {
5080 if (!is_stable()) return 0;
5081 int dim = 1;
5082 const TypePtr* elem_ptr = elem()->make_ptr();
5083 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5084 dim += elem_ptr->is_aryptr()->stable_dimension();
5085 return dim;
5086 }
5087
5088 //----------------------cast_to_autobox_cache-----------------------------------
5089 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5090 if (is_autobox_cache()) return this;
5091 const TypeOopPtr* etype = elem()->make_oopptr();
5092 if (etype == nullptr) return this;
5093 // The pointers in the autobox arrays are always non-null.
5094 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5095 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5096 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5097 }
5098
5099 //------------------------------eq---------------------------------------------
5100 // Structural equality check for Type representations
5101 bool TypeAryPtr::eq( const Type *t ) const {
5102 const TypeAryPtr *p = t->is_aryptr();
5103 return
5104 _ary == p->_ary && // Check array
5105 TypeOopPtr::eq(p) &&// Check sub-parts
5106 _field_offset == p->_field_offset;
5107 }
5108
5109 //------------------------------hash-------------------------------------------
5110 // Type-specific hashing function.
5111 uint TypeAryPtr::hash(void) const {
5112 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5113 }
5114
5115 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5116 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5117 }
5118
5119 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5120 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5121 }
5122
5123 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5124 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5125 }
5126 //------------------------------meet-------------------------------------------
5127 // Compute the MEET of two types. It returns a new Type object.
5128 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5129 // Perform a fast test for common case; meeting the same types together.
5130 if( this == t ) return this; // Meeting same type-rep?
5131 // Current "this->_base" is Pointer
5132 switch (t->base()) { // switch on original type
5136 case Long:
5137 case FloatTop:
5138 case FloatCon:
5139 case FloatBot:
5140 case DoubleTop:
5141 case DoubleCon:
5142 case DoubleBot:
5143 case NarrowOop:
5144 case NarrowKlass:
5145 case Bottom: // Ye Olde Default
5146 return Type::BOTTOM;
5147 case Top:
5148 return this;
5149
5150 default: // All else is a mistake
5151 typerr(t);
5152
5153 case OopPtr: { // Meeting to OopPtrs
5154 // Found a OopPtr type vs self-AryPtr type
5155 const TypeOopPtr *tp = t->is_oopptr();
5156 Offset offset = meet_offset(tp->offset());
5157 PTR ptr = meet_ptr(tp->ptr());
5158 int depth = meet_inline_depth(tp->inline_depth());
5159 const TypePtr* speculative = xmeet_speculative(tp);
5160 switch (tp->ptr()) {
5161 case TopPTR:
5162 case AnyNull: {
5163 int instance_id = meet_instance_id(InstanceTop);
5164 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5165 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5166 }
5167 case BotPTR:
5168 case NotNull: {
5169 int instance_id = meet_instance_id(tp->instance_id());
5170 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5171 }
5172 default: ShouldNotReachHere();
5173 }
5174 }
5175
5176 case AnyPtr: { // Meeting two AnyPtrs
5177 // Found an AnyPtr type vs self-AryPtr type
5178 const TypePtr *tp = t->is_ptr();
5179 Offset offset = meet_offset(tp->offset());
5180 PTR ptr = meet_ptr(tp->ptr());
5181 const TypePtr* speculative = xmeet_speculative(tp);
5182 int depth = meet_inline_depth(tp->inline_depth());
5183 switch (tp->ptr()) {
5184 case TopPTR:
5185 return this;
5186 case BotPTR:
5187 case NotNull:
5188 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5189 case Null:
5190 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5191 // else fall through to AnyNull
5192 case AnyNull: {
5193 int instance_id = meet_instance_id(InstanceTop);
5194 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5195 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5196 }
5197 default: ShouldNotReachHere();
5198 }
5199 }
5200
5201 case MetadataPtr:
5202 case KlassPtr:
5203 case InstKlassPtr:
5204 case AryKlassPtr:
5205 case RawPtr: return TypePtr::BOTTOM;
5206
5207 case AryPtr: { // Meeting 2 references?
5208 const TypeAryPtr *tap = t->is_aryptr();
5209 Offset off = meet_offset(tap->offset());
5210 Offset field_off = meet_field_offset(tap->field_offset());
5211 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5212 PTR ptr = meet_ptr(tap->ptr());
5213 int instance_id = meet_instance_id(tap->instance_id());
5214 const TypePtr* speculative = xmeet_speculative(tap);
5215 int depth = meet_inline_depth(tap->inline_depth());
5216
5217 ciKlass* res_klass = nullptr;
5218 bool res_xk = false;
5219 bool res_flat = false;
5220 bool res_not_flat = false;
5221 bool res_not_null_free = false;
5222 const Type* elem = tary->_elem;
5223 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5224 instance_id = InstanceBot;
5225 } else if (this->is_flat() != tap->is_flat()) {
5226 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5227 if (tary->_flat) {
5228 // Result is in a flat representation
5229 off = Offset(is_flat() ? offset() : tap->offset());
5230 field_off = is_flat() ? field_offset() : tap->field_offset();
5231 } else if (below_centerline(ptr)) {
5232 // Result is in a non-flat representation
5233 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5234 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5235 } else if (flat_offset() == tap->flat_offset()) {
5236 off = Offset(!is_flat() ? offset() : tap->offset());
5237 field_off = !is_flat() ? field_offset() : tap->field_offset();
5238 }
5239 }
5240
5241 ciObject* o = nullptr; // Assume not constant when done
5242 ciObject* this_oop = const_oop();
5243 ciObject* tap_oop = tap->const_oop();
5244 if (ptr == Constant) {
5245 if (this_oop != nullptr && tap_oop != nullptr &&
5246 this_oop->equals(tap_oop)) {
5247 o = tap_oop;
5248 } else if (above_centerline(_ptr)) {
5249 o = tap_oop;
5250 } else if (above_centerline(tap->_ptr)) {
5251 o = this_oop;
5252 } else {
5253 ptr = NotNull;
5254 }
5255 }
5256 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);
5257 }
5258
5259 // All arrays inherit from Object class
5260 case InstPtr: {
5261 const TypeInstPtr *tp = t->is_instptr();
5262 Offset offset = meet_offset(tp->offset());
5263 PTR ptr = meet_ptr(tp->ptr());
5264 int instance_id = meet_instance_id(tp->instance_id());
5265 const TypePtr* speculative = xmeet_speculative(tp);
5266 int depth = meet_inline_depth(tp->inline_depth());
5267 const TypeInterfaces* interfaces = meet_interfaces(tp);
5268 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5269 const TypeInterfaces* this_interfaces = _interfaces;
5270
5271 switch (ptr) {
5272 case TopPTR:
5273 case AnyNull: // Fall 'down' to dual of object klass
5274 // For instances when a subclass meets a superclass we fall
5275 // below the centerline when the superclass is exact. We need to
5276 // do the same here.
5277 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5278 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5279 } else {
5280 // cannot subclass, so the meet has to fall badly below the centerline
5281 ptr = NotNull;
5282 instance_id = InstanceBot;
5283 interfaces = this_interfaces->intersection_with(tp_interfaces);
5284 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5285 }
5286 case Constant:
5287 case NotNull:
5288 case BotPTR: // Fall down to object klass
5289 // LCA is object_klass, but if we subclass from the top we can do better
5290 if (above_centerline(tp->ptr())) {
5291 // If 'tp' is above the centerline and it is Object class
5292 // then we can subclass in the Java class hierarchy.
5293 // For instances when a subclass meets a superclass we fall
5294 // below the centerline when the superclass is exact. We need
5295 // to do the same here.
5296 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5297 // that is, my array type is a subtype of 'tp' klass
5298 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5299 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5300 }
5301 }
5302 // The other case cannot happen, since t cannot be a subtype of an array.
5303 // The meet falls down to Object class below centerline.
5304 if (ptr == Constant) {
5305 ptr = NotNull;
5306 }
5307 if (instance_id > 0) {
5308 instance_id = InstanceBot;
5309 }
5310 interfaces = this_interfaces->intersection_with(tp_interfaces);
5311 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5312 default: typerr(t);
5313 }
5314 }
5315 }
5316 return this; // Lint noise
5317 }
5318
5319
5320 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5321 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5322 int dummy;
5323 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5324 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5325 ciKlass* this_klass = this_ary->klass();
5326 ciKlass* other_klass = other_ary->klass();
5327 bool this_xk = this_ary->klass_is_exact();
5328 bool other_xk = other_ary->klass_is_exact();
5329 PTR this_ptr = this_ary->ptr();
5330 PTR other_ptr = other_ary->ptr();
5331 bool this_flat = this_ary->is_flat();
5332 bool this_not_flat = this_ary->is_not_flat();
5333 bool other_flat = other_ary->is_flat();
5334 bool other_not_flat = other_ary->is_not_flat();
5335 bool this_not_null_free = this_ary->is_not_null_free();
5336 bool other_not_null_free = other_ary->is_not_null_free();
5337 res_klass = nullptr;
5338 MeetResult result = SUBTYPE;
5339 res_flat = this_flat && other_flat;
5340 res_not_flat = this_not_flat && other_not_flat;
5341 res_not_null_free = this_not_null_free && other_not_null_free;
5342
5343 if (elem->isa_int()) {
5344 // Integral array element types have irrelevant lattice relations.
5345 // It is the klass that determines array layout, not the element type.
5346 if (this_top_or_bottom) {
5347 res_klass = other_klass;
5348 } else if (other_top_or_bottom || other_klass == this_klass) {
5349 res_klass = this_klass;
5350 } else {
5351 // Something like byte[int+] meets char[int+].
5352 // This must fall to bottom, not (int[-128..65535])[int+].
5353 // instance_id = InstanceBot;
5354 elem = Type::BOTTOM;
5355 result = NOT_SUBTYPE;
5356 if (above_centerline(ptr) || ptr == Constant) {
5357 ptr = NotNull;
5358 res_xk = false;
5359 return NOT_SUBTYPE;
5360 }
5361 }
5362 } else {// Non integral arrays.
5363 // Must fall to bottom if exact klasses in upper lattice
5364 // are not equal or super klass is exact.
5365 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5366 // meet with top[] and bottom[] are processed further down:
5367 !this_top_or_bottom && !other_top_or_bottom &&
5368 // both are exact and not equal:
5370 // 'tap' is exact and super or unrelated:
5371 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5372 // 'this' is exact and super or unrelated:
5373 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5374 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5375 elem = Type::BOTTOM;
5376 }
5377 ptr = NotNull;
5378 res_xk = false;
5379 return NOT_SUBTYPE;
5380 }
5381 }
5382
5383 res_xk = false;
5384 switch (other_ptr) {
5385 case AnyNull:
5386 case TopPTR:
5387 // Compute new klass on demand, do not use tap->_klass
5388 if (below_centerline(this_ptr)) {
5389 res_xk = this_xk;
5390 if (this_ary->is_flat()) {
5391 elem = this_ary->elem();
5392 }
5393 } else {
5394 res_xk = (other_xk || this_xk);
5395 }
5396 break;
5397 case Constant: {
5398 if (this_ptr == Constant) {
5399 res_xk = true;
5400 } else if (above_centerline(this_ptr)) {
5401 res_xk = true;
5402 } else {
5403 // Only precise for identical arrays
5404 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5405 // Even though MyValue is final, [LMyValue is only exact if the array
5406 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5407 if (res_xk && !res_not_null_free) {
5408 res_xk = false;
5409 }
5410 }
5411 break;
5412 }
5413 case NotNull:
5414 case BotPTR:
5415 // Compute new klass on demand, do not use tap->_klass
5416 if (above_centerline(this_ptr)) {
5417 res_xk = other_xk;
5418 if (other_ary->is_flat()) {
5419 elem = other_ary->elem();
5420 }
5421 } else {
5422 res_xk = (other_xk && this_xk) &&
5423 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5424 // Even though MyValue is final, [LMyValue is only exact if the array
5425 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5426 if (res_xk && !res_not_null_free) {
5427 res_xk = false;
5428 }
5429 }
5430 break;
5431 default: {
5432 ShouldNotReachHere();
5433 return result;
5434 }
5435 }
5436 return result;
5437 }
5438
5439
5440 //------------------------------xdual------------------------------------------
5441 // Dual: compute field-by-field dual
5442 const Type *TypeAryPtr::xdual() const {
5443 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());
5444 }
5445
5446 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5447 return _field_offset.meet(offset);
5448 }
5449
5450 //------------------------------dual_offset------------------------------------
5451 Type::Offset TypeAryPtr::dual_field_offset() const {
5452 return _field_offset.dual();
5453 }
5454
5455 //------------------------------dump2------------------------------------------
5456 #ifndef PRODUCT
5457 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5458 _ary->dump2(d,depth,st);
5459 _interfaces->dump(st);
5460
5461 switch( _ptr ) {
5462 case Constant:
5463 const_oop()->print(st);
5464 break;
5465 case BotPTR:
5466 if (!WizardMode && !Verbose) {
5467 if( _klass_is_exact ) st->print(":exact");
5468 break;
5469 }
5470 case TopPTR:
5471 case AnyNull:
5472 case NotNull:
5473 st->print(":%s", ptr_msg[_ptr]);
5474 if( _klass_is_exact ) st->print(":exact");
5475 break;
5476 default:
5477 break;
5478 }
5479
5480 if (is_flat()) {
5481 st->print(":flat");
5482 st->print("(");
5483 _field_offset.dump2(st);
5484 st->print(")");
5485 }
5486 if (is_null_free()) {
5487 st->print(":null_free");
5488 }
5489 if (offset() != 0) {
5490 BasicType basic_elem_type = elem()->basic_type();
5491 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5492 if( _offset == Offset::top ) st->print("+undefined");
5493 else if( _offset == Offset::bottom ) st->print("+any");
5494 else if( offset() < header_size ) st->print("+%d", offset());
5495 else {
5496 if (basic_elem_type == T_ILLEGAL) {
5497 st->print("+any");
5498 } else {
5499 int elem_size = type2aelembytes(basic_elem_type);
5500 st->print("[%d]", (offset() - header_size)/elem_size);
5501 }
5502 }
5503 }
5504 st->print(" *");
5505 if (_instance_id == InstanceTop)
5506 st->print(",iid=top");
5507 else if (_instance_id != InstanceBot)
5508 st->print(",iid=%d",_instance_id);
5509
5510 dump_inline_depth(st);
5511 dump_speculative(st);
5512 }
5513 #endif
5514
5515 bool TypeAryPtr::empty(void) const {
5516 if (_ary->empty()) return true;
5517 // FIXME: Does this belong here? Or in the meet code itself?
5518 if (is_flat() && is_not_flat()) {
5519 return true;
5520 }
5521 return TypeOopPtr::empty();
5522 }
5523
5524 //------------------------------add_offset-------------------------------------
5525 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5526 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);
5527 }
5528
5529 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5530 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);
5531 }
5532
5533 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5534 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5535 }
5536
5537 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5538 if (_speculative == nullptr) {
5539 return this;
5540 }
5541 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5542 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);
5543 }
5544
5545 const Type* TypeAryPtr::cleanup_speculative() const {
5546 if (speculative() == nullptr) {
5547 return this;
5548 }
5549 // Keep speculative part if it contains information about flat-/nullability
5550 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5551 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5552 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5553 return this;
5554 }
5555 return TypeOopPtr::cleanup_speculative();
5556 }
5557
5558 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5559 if (!UseInlineDepthForSpeculativeTypes) {
5560 return this;
5561 }
5562 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5563 }
5564
5565 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5566 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);
5567 }
5568
5569 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5570 int adj = 0;
5571 if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5572 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5573 adj = _offset.get();
5574 offset += _offset.get();
5575 }
5576 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5577 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5578 offset += _field_offset.get();
5579 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5580 offset += header;
5581 }
5582 }
5583 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5584 // Try to get the field of the inline type array element we are pointing to
5585 ciInlineKlass* vk = elem()->inline_klass();
5586 int shift = flat_log_elem_size();
5587 int mask = (1 << shift) - 1;
5588 intptr_t field_offset = ((offset - header) & mask);
5589 ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5590 if (field != nullptr) {
5591 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5592 }
5593 }
5594 }
5595 return add_offset(offset - adj);
5596 }
5597
5598 // Return offset incremented by field_offset for flat inline type arrays
5599 int TypeAryPtr::flat_offset() const {
5600 int offset = _offset.get();
5601 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5602 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5603 offset += _field_offset.get();
5604 }
5605 return offset;
5606 }
5607
5608 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5609 assert(is_known_instance(), "should be known");
5610 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5611 }
5612
5613 //=============================================================================
5614
5615
5616 //------------------------------hash-------------------------------------------
5617 // Type-specific hashing function.
5618 uint TypeNarrowPtr::hash(void) const {
5619 return _ptrtype->hash() + 7;
5620 }
5621
5622 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5623 return _ptrtype->singleton();
5624 }
5625
5626 bool TypeNarrowPtr::empty(void) const {
5627 return _ptrtype->empty();
5628 }
5629
5630 intptr_t TypeNarrowPtr::get_con() const {
5631 return _ptrtype->get_con();
5632 }
5633
5634 bool TypeNarrowPtr::eq( const Type *t ) const {
5635 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5686
5687 case Int: // Mixing ints & oops happens when javac
5688 case Long: // reuses local variables
5689 case FloatTop:
5690 case FloatCon:
5691 case FloatBot:
5692 case DoubleTop:
5693 case DoubleCon:
5694 case DoubleBot:
5695 case AnyPtr:
5696 case RawPtr:
5697 case OopPtr:
5698 case InstPtr:
5699 case AryPtr:
5700 case MetadataPtr:
5701 case KlassPtr:
5702 case InstKlassPtr:
5703 case AryKlassPtr:
5704 case NarrowOop:
5705 case NarrowKlass:
5706 case Bottom: // Ye Olde Default
5707 return Type::BOTTOM;
5708 case Top:
5709 return this;
5710
5711 default: // All else is a mistake
5712 typerr(t);
5713
5714 } // End of switch
5715
5716 return this;
5717 }
5718
5719 #ifndef PRODUCT
5720 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5721 _ptrtype->dump2(d, depth, st);
5722 }
5723 #endif
5724
5725 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5769 return (one == two) && TypePtr::eq(t);
5770 } else {
5771 return one->equals(two) && TypePtr::eq(t);
5772 }
5773 }
5774
5775 //------------------------------hash-------------------------------------------
5776 // Type-specific hashing function.
5777 uint TypeMetadataPtr::hash(void) const {
5778 return
5779 (metadata() ? metadata()->hash() : 0) +
5780 TypePtr::hash();
5781 }
5782
5783 //------------------------------singleton--------------------------------------
5784 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5785 // constants
5786 bool TypeMetadataPtr::singleton(void) const {
5787 // detune optimizer to not generate constant metadata + constant offset as a constant!
5788 // TopPTR, Null, AnyNull, Constant are all singletons
5789 return (offset() == 0) && !below_centerline(_ptr);
5790 }
5791
5792 //------------------------------add_offset-------------------------------------
5793 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5794 return make( _ptr, _metadata, xadd_offset(offset));
5795 }
5796
5797 //-----------------------------filter------------------------------------------
5798 // Do not allow interface-vs.-noninterface joins to collapse to top.
5799 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5800 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5801 if (ft == nullptr || ft->empty())
5802 return Type::TOP; // Canonical empty value
5803 return ft;
5804 }
5805
5806 //------------------------------get_con----------------------------------------
5807 intptr_t TypeMetadataPtr::get_con() const {
5808 assert( _ptr == Null || _ptr == Constant, "" );
5809 assert(offset() >= 0, "");
5810
5811 if (offset() != 0) {
5812 // After being ported to the compiler interface, the compiler no longer
5813 // directly manipulates the addresses of oops. Rather, it only has a pointer
5814 // to a handle at compile time. This handle is embedded in the generated
5815 // code and dereferenced at the time the nmethod is made. Until that time,
5816 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5817 // have access to the addresses!). This does not seem to currently happen,
5818 // but this assertion here is to help prevent its occurrence.
5819 tty->print_cr("Found oop constant with non-zero offset");
5820 ShouldNotReachHere();
5821 }
5822
5823 return (intptr_t)metadata()->constant_encoding();
5824 }
5825
5826 //------------------------------cast_to_ptr_type-------------------------------
5827 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5828 if( ptr == _ptr ) return this;
5829 return make(ptr, metadata(), _offset);
5830 }
5831
5842 case Long: // reuses local variables
5843 case FloatTop:
5844 case FloatCon:
5845 case FloatBot:
5846 case DoubleTop:
5847 case DoubleCon:
5848 case DoubleBot:
5849 case NarrowOop:
5850 case NarrowKlass:
5851 case Bottom: // Ye Olde Default
5852 return Type::BOTTOM;
5853 case Top:
5854 return this;
5855
5856 default: // All else is a mistake
5857 typerr(t);
5858
5859 case AnyPtr: {
5860 // Found an AnyPtr type vs self-OopPtr type
5861 const TypePtr *tp = t->is_ptr();
5862 Offset offset = meet_offset(tp->offset());
5863 PTR ptr = meet_ptr(tp->ptr());
5864 switch (tp->ptr()) {
5865 case Null:
5866 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5867 // else fall through:
5868 case TopPTR:
5869 case AnyNull: {
5870 return make(ptr, _metadata, offset);
5871 }
5872 case BotPTR:
5873 case NotNull:
5874 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5875 default: typerr(t);
5876 }
5877 }
5878
5879 case RawPtr:
5880 case KlassPtr:
5881 case InstKlassPtr:
5882 case AryKlassPtr:
5883 case OopPtr:
5884 case InstPtr:
5885 case AryPtr:
5886 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5887
5888 case MetadataPtr: {
5889 const TypeMetadataPtr *tp = t->is_metadataptr();
5890 Offset offset = meet_offset(tp->offset());
5891 PTR tptr = tp->ptr();
5892 PTR ptr = meet_ptr(tptr);
5893 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5894 if (tptr == TopPTR || _ptr == TopPTR ||
5895 metadata()->equals(tp->metadata())) {
5896 return make(ptr, md, offset);
5897 }
5898 // metadata is different
5899 if( ptr == Constant ) { // Cannot be equal constants, so...
5900 if( tptr == Constant && _ptr != Constant) return t;
5901 if( _ptr == Constant && tptr != Constant) return this;
5902 ptr = NotNull; // Fall down in lattice
5903 }
5904 return make(ptr, nullptr, offset);
5905 break;
5906 }
5907 } // End of switch
5908 return this; // Return the double constant
5909 }
5910
5911
5912 //------------------------------xdual------------------------------------------
5913 // Dual of a pure metadata pointer.
5914 const Type *TypeMetadataPtr::xdual() const {
5915 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5916 }
5917
5918 //------------------------------dump2------------------------------------------
5919 #ifndef PRODUCT
5920 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5921 st->print("metadataptr:%s", ptr_msg[_ptr]);
5922 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5923 switch (offset()) {
5924 case OffsetTop: st->print("+top"); break;
5925 case OffsetBot: st->print("+any"); break;
5926 case 0: break;
5927 default: st->print("+%d",offset()); break;
5928 }
5929 }
5930 #endif
5931
5932
5933 //=============================================================================
5934 // Convenience common pre-built type.
5935 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5936
5937 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5938 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5939 }
5940
5941 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5942 return make(Constant, m, Offset(0));
5943 }
5944 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5945 return make(Constant, m, Offset(0));
5946 }
5947
5948 //------------------------------make-------------------------------------------
5949 // Create a meta data constant
5950 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5951 assert(m == nullptr || !m->is_klass(), "wrong type");
5952 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5953 }
5954
5955
5956 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5957 const Type* elem = _ary->_elem;
5958 bool xk = klass_is_exact();
5959 if (elem->make_oopptr() != nullptr) {
5960 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5961 if (elem->is_klassptr()->klass_is_exact() &&
5962 // Even though MyValue is final, [LMyValue is only exact if the array
5963 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5964 (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5965 xk = true;
5966 }
5967 }
5968 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5969 }
5970
5971 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5972 if (klass->is_instance_klass()) {
5973 return TypeInstKlassPtr::make(klass, interface_handling);
5974 }
5975 return TypeAryKlassPtr::make(klass, interface_handling);
5976 }
5977
5978 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
5979 if (klass->is_instance_klass()) {
5980 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5981 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5982 }
5983 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5984 }
5985
5986 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
5987 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5988 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5989 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5990 }
5991
5992 // Is there a single ciKlass* that can represent that type?
5993 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5994 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5995 if (_interfaces->empty()) {
5996 return _klass;
5997 }
5998 if (_klass != ciEnv::current()->Object_klass()) {
5999 if (_interfaces->eq(_klass->as_instance_klass())) {
6000 return _klass;
6001 }
6002 return nullptr;
6003 }
6004 return _interfaces->exact_klass();
6005 }
6006
6007 //------------------------------eq---------------------------------------------
6008 // Structural equality check for Type representations
6009 bool TypeKlassPtr::eq(const Type *t) const {
6010 const TypeKlassPtr *p = t->is_klassptr();
6011 return
6012 _interfaces->eq(p->_interfaces) &&
6013 TypePtr::eq(p);
6014 }
6015
6016 //------------------------------hash-------------------------------------------
6017 // Type-specific hashing function.
6018 uint TypeKlassPtr::hash(void) const {
6019 return TypePtr::hash() + _interfaces->hash();
6020 }
6021
6022 //------------------------------singleton--------------------------------------
6023 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6024 // constants
6025 bool TypeKlassPtr::singleton(void) const {
6026 // detune optimizer to not generate constant klass + constant offset as a constant!
6027 // TopPTR, Null, AnyNull, Constant are all singletons
6028 return (offset() == 0) && !below_centerline(_ptr);
6029 }
6030
6031 // Do not allow interface-vs.-noninterface joins to collapse to top.
6032 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6033 // logic here mirrors the one from TypeOopPtr::filter. See comments
6034 // there.
6035 const Type* ft = join_helper(kills, include_speculative);
6036 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
6037 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
6038
6039 if (ft->empty()) {
6040 return Type::TOP; // Canonical empty value
6041 }
6042
6043 return ft;
6044 }
6045
6046 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6047 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6048 return _interfaces->union_with(other->_interfaces);
6049 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6050 return other->_interfaces;
6051 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6052 return _interfaces;
6053 }
6054 return _interfaces->intersection_with(other->_interfaces);
6055 }
6056
6057 //------------------------------get_con----------------------------------------
6058 intptr_t TypeKlassPtr::get_con() const {
6059 assert( _ptr == Null || _ptr == Constant, "" );
6060 assert( offset() >= 0, "" );
6061
6062 if (offset() != 0) {
6063 // After being ported to the compiler interface, the compiler no longer
6064 // directly manipulates the addresses of oops. Rather, it only has a pointer
6065 // to a handle at compile time. This handle is embedded in the generated
6066 // code and dereferenced at the time the nmethod is made. Until that time,
6067 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6068 // have access to the addresses!). This does not seem to currently happen,
6069 // but this assertion here is to help prevent its occurrence.
6070 tty->print_cr("Found oop constant with non-zero offset");
6071 ShouldNotReachHere();
6072 }
6073
6074 ciKlass* k = exact_klass();
6075
6076 return (intptr_t)k->constant_encoding();
6077 }
6078
6079 //------------------------------dump2------------------------------------------
6080 // Dump Klass Type
6081 #ifndef PRODUCT
6082 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6086 case NotNull:
6087 {
6088 const char *name = klass()->name()->as_utf8();
6089 if (name) {
6090 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6091 } else {
6092 ShouldNotReachHere();
6093 }
6094 _interfaces->dump(st);
6095 }
6096 case BotPTR:
6097 if (!WizardMode && !Verbose && _ptr != Constant) break;
6098 case TopPTR:
6099 case AnyNull:
6100 st->print(":%s", ptr_msg[_ptr]);
6101 if (_ptr == Constant) st->print(":exact");
6102 break;
6103 default:
6104 break;
6105 }
6106 if (Verbose) {
6107 if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");
6108 }
6109 _offset.dump2(st);
6110 st->print(" *");
6111 }
6112 #endif
6113
6114 //=============================================================================
6115 // Convenience common pre-built types.
6116
6117 // Not-null object klass or below
6118 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6119 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6120
6121 bool TypeInstKlassPtr::eq(const Type *t) const {
6122 const TypeKlassPtr *p = t->is_klassptr();
6123 return
6124 klass()->equals(p->klass()) &&
6125 flat_in_array() == p->flat_in_array() &&
6126 TypeKlassPtr::eq(p);
6127 }
6128
6129 uint TypeInstKlassPtr::hash(void) const {
6130 return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6131 }
6132
6133 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6134 flat_in_array = flat_in_array || k->flat_in_array();
6135
6136 TypeInstKlassPtr *r =
6137 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6138
6139 return r;
6140 }
6141
6142 //------------------------------add_offset-------------------------------------
6143 // Access internals of klass object
6144 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6145 return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6146 }
6147
6148 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6149 return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6150 }
6151
6152 //------------------------------cast_to_ptr_type-------------------------------
6153 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6154 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6155 if( ptr == _ptr ) return this;
6156 return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6157 }
6158
6159
6160 bool TypeInstKlassPtr::must_be_exact() const {
6161 if (!_klass->is_loaded()) return false;
6162 ciInstanceKlass* ik = _klass->as_instance_klass();
6163 if (ik->is_final()) return true; // cannot clear xk
6164 return false;
6165 }
6166
6167 //-----------------------------cast_to_exactness-------------------------------
6168 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6169 if (klass_is_exact == (_ptr == Constant)) return this;
6170 if (must_be_exact()) return this;
6171 ciKlass* k = klass();
6172 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6173 }
6174
6175
6176 //-----------------------------as_instance_type--------------------------------
6177 // Corresponding type for an instance of the given class.
6178 // It will be NotNull, and exact if and only if the klass type is exact.
6179 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6180 ciKlass* k = klass();
6181 bool xk = klass_is_exact();
6182 Compile* C = Compile::current();
6183 Dependencies* deps = C->dependencies();
6184 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6185 // Element is an instance
6186 bool klass_is_exact = false;
6187 const TypeInterfaces* interfaces = _interfaces;
6188 if (k->is_loaded()) {
6189 // Try to set klass_is_exact.
6190 ciInstanceKlass* ik = k->as_instance_klass();
6191 klass_is_exact = ik->is_final();
6192 if (!klass_is_exact && klass_change
6193 && deps != nullptr && UseUniqueSubclasses) {
6194 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6195 if (sub != nullptr) {
6196 if (_interfaces->eq(sub)) {
6197 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6198 k = ik = sub;
6199 xk = sub->is_final();
6200 }
6201 }
6202 }
6203 }
6204 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6205 }
6206
6207 //------------------------------xmeet------------------------------------------
6208 // Compute the MEET of two types, return a new Type object.
6209 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6210 // Perform a fast test for common case; meeting the same types together.
6211 if( this == t ) return this; // Meeting same type-rep?
6212
6213 // Current "this->_base" is Pointer
6214 switch (t->base()) { // switch on original type
6215
6216 case Int: // Mixing ints & oops happens when javac
6217 case Long: // reuses local variables
6218 case FloatTop:
6219 case FloatCon:
6220 case FloatBot:
6221 case DoubleTop:
6222 case DoubleCon:
6223 case DoubleBot:
6224 case NarrowOop:
6225 case NarrowKlass:
6226 case Bottom: // Ye Olde Default
6227 return Type::BOTTOM;
6228 case Top:
6229 return this;
6230
6231 default: // All else is a mistake
6232 typerr(t);
6233
6234 case AnyPtr: { // Meeting to AnyPtrs
6235 // Found an AnyPtr type vs self-KlassPtr type
6236 const TypePtr *tp = t->is_ptr();
6237 Offset offset = meet_offset(tp->offset());
6238 PTR ptr = meet_ptr(tp->ptr());
6239 switch (tp->ptr()) {
6240 case TopPTR:
6241 return this;
6242 case Null:
6243 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6244 case AnyNull:
6245 return make(ptr, klass(), _interfaces, offset, flat_in_array());
6246 case BotPTR:
6247 case NotNull:
6248 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6249 default: typerr(t);
6250 }
6251 }
6252
6253 case RawPtr:
6254 case MetadataPtr:
6255 case OopPtr:
6256 case AryPtr: // Meet with AryPtr
6257 case InstPtr: // Meet with InstPtr
6258 return TypePtr::BOTTOM;
6259
6260 //
6261 // A-top }
6262 // / | \ } Tops
6263 // B-top A-any C-top }
6264 // | / | \ | } Any-nulls
6265 // B-any | C-any }
6266 // | | |
6267 // B-con A-con C-con } constants; not comparable across classes
6268 // | | |
6269 // B-not | C-not }
6270 // | \ | / | } not-nulls
6271 // B-bot A-not C-bot }
6272 // \ | / } Bottoms
6273 // A-bot }
6274 //
6275
6276 case InstKlassPtr: { // Meet two KlassPtr types
6277 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6278 Offset off = meet_offset(tkls->offset());
6279 PTR ptr = meet_ptr(tkls->ptr());
6280 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6281
6282 ciKlass* res_klass = nullptr;
6283 bool res_xk = false;
6284 bool res_flat_in_array = false;
6285 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6286 case UNLOADED:
6287 ShouldNotReachHere();
6288 case SUBTYPE:
6289 case NOT_SUBTYPE:
6290 case LCA:
6291 case QUICK: {
6292 assert(res_xk == (ptr == Constant), "");
6293 const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6294 return res;
6295 }
6296 default:
6297 ShouldNotReachHere();
6298 }
6299 } // End of case KlassPtr
6300 case AryKlassPtr: { // All arrays inherit from Object class
6301 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6302 Offset offset = meet_offset(tp->offset());
6303 PTR ptr = meet_ptr(tp->ptr());
6304 const TypeInterfaces* interfaces = meet_interfaces(tp);
6305 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6306 const TypeInterfaces* this_interfaces = _interfaces;
6307
6308 switch (ptr) {
6309 case TopPTR:
6310 case AnyNull: // Fall 'down' to dual of object klass
6311 // For instances when a subclass meets a superclass we fall
6312 // below the centerline when the superclass is exact. We need to
6313 // do the same here.
6314 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6315 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6316 } else {
6317 // cannot subclass, so the meet has to fall badly below the centerline
6318 ptr = NotNull;
6319 interfaces = _interfaces->intersection_with(tp->_interfaces);
6320 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6321 }
6322 case Constant:
6323 case NotNull:
6324 case BotPTR: // Fall down to object klass
6325 // LCA is object_klass, but if we subclass from the top we can do better
6326 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6327 // If 'this' (InstPtr) is above the centerline and it is Object class
6328 // then we can subclass in the Java class hierarchy.
6329 // For instances when a subclass meets a superclass we fall
6330 // below the centerline when the superclass is exact. We need
6331 // to do the same here.
6332 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6333 // that is, tp's array type is a subtype of my klass
6334 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6335 }
6336 }
6337 // The other case cannot happen, since I cannot be a subtype of an array.
6338 // The meet falls down to Object class below centerline.
6339 if( ptr == Constant )
6340 ptr = NotNull;
6341 interfaces = this_interfaces->intersection_with(tp_interfaces);
6342 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6343 default: typerr(t);
6344 }
6345 }
6346
6347 } // End of switch
6348 return this; // Return the double constant
6349 }
6350
6351 //------------------------------xdual------------------------------------------
6352 // Dual: compute field-by-field dual
6353 const Type *TypeInstKlassPtr::xdual() const {
6354 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6355 }
6356
6357 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) {
6358 static_assert(std::is_base_of<T2, T1>::value, "");
6359 if (!this_one->is_loaded() || !other->is_loaded()) {
6360 return false;
6361 }
6362 if (!this_one->is_instance_type(other)) {
6363 return false;
6364 }
6365
6366 if (!other_exact) {
6367 return false;
6368 }
6369
6370 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6371 return true;
6372 }
6373
6374 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6435 const TypeInterfaces* interfaces = _interfaces;
6436 if (k->is_loaded()) {
6437 ciInstanceKlass* ik = k->as_instance_klass();
6438 bool klass_is_exact = ik->is_final();
6439 if (!klass_is_exact &&
6440 deps != nullptr) {
6441 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6442 if (sub != nullptr) {
6443 if (_interfaces->eq(sub)) {
6444 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6445 k = ik = sub;
6446 klass_is_exact = sub->is_final();
6447 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6448 }
6449 }
6450 }
6451 }
6452 return this;
6453 }
6454
6455 bool TypeInstKlassPtr::can_be_inline_array() const {
6456 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6457 }
6458
6459 bool TypeAryKlassPtr::can_be_inline_array() const {
6460 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6461 }
6462
6463 bool TypeInstPtr::can_be_inline_array() const {
6464 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6465 }
6466
6467 bool TypeAryPtr::can_be_inline_array() const {
6468 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6469 }
6470
6471 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6472 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6473 }
6474
6475 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6476 if (k->is_obj_array_klass()) {
6477 // Element is an object array. Recursively call ourself.
6478 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6479 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6480 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, null_free);
6481 } else if (k->is_type_array_klass()) {
6482 // Element is an typeArray
6483 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6484 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6485 } else if (k->is_flat_array_klass()) {
6486 ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6487 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6488 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6489 } else {
6490 ShouldNotReachHere();
6491 return nullptr;
6492 }
6493 }
6494
6495 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6496 bool null_free = k->as_array_klass()->is_elem_null_free();
6497 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));
6498
6499 bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != nullptr &&
6500 k->as_array_klass()->element_klass()->is_inlinetype() &&
6501 !k->as_array_klass()->element_klass()->flat_in_array());
6502
6503 return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6504 }
6505
6506 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6507 return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6508 }
6509
6510 //------------------------------eq---------------------------------------------
6511 // Structural equality check for Type representations
6512 bool TypeAryKlassPtr::eq(const Type *t) const {
6513 const TypeAryKlassPtr *p = t->is_aryklassptr();
6514 return
6515 _elem == p->_elem && // Check array
6516 _not_flat == p->_not_flat &&
6517 _not_null_free == p->_not_null_free &&
6518 _null_free == p->_null_free &&
6519 TypeKlassPtr::eq(p); // Check sub-parts
6520 }
6521
6522 //------------------------------hash-------------------------------------------
6523 // Type-specific hashing function.
6524 uint TypeAryKlassPtr::hash(void) const {
6525 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6526 (uint)(_not_null_free ? 44 : 0) + (uint)(_null_free ? 45 : 0);
6527 }
6528
6529 //----------------------compute_klass------------------------------------------
6530 // Compute the defining klass for this class
6531 ciKlass* TypeAryPtr::compute_klass() const {
6532 // Compute _klass based on element type.
6533 ciKlass* k_ary = nullptr;
6534 const TypeInstPtr *tinst;
6535 const TypeAryPtr *tary;
6536 const Type* el = elem();
6537 if (el->isa_narrowoop()) {
6538 el = el->make_ptr();
6539 }
6540
6541 // Get element klass
6542 if (is_flat() && el->is_inlinetypeptr()) {
6543 // Klass is required by TypeAryPtr::flat_layout_helper() and others
6544 if (el->inline_klass() != nullptr) {
6545 k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6546 }
6547 } else if ((tinst = el->isa_instptr()) != nullptr) {
6548 // Leave k_ary at nullptr.
6549 } else if ((tary = el->isa_aryptr()) != nullptr) {
6550 // Leave k_ary at nullptr.
6551 } else if ((el->base() == Type::Top) ||
6552 (el->base() == Type::Bottom)) {
6553 // element type of Bottom occurs from meet of basic type
6554 // and object; Top occurs when doing join on Bottom.
6555 // Leave k_ary at null.
6556 } else {
6557 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6558 // Compute array klass directly from basic type
6559 k_ary = ciTypeArrayKlass::make(el->basic_type());
6560 }
6561 return k_ary;
6562 }
6563
6564 //------------------------------klass------------------------------------------
6565 // Return the defining klass for this class
6566 ciKlass* TypeAryPtr::klass() const {
6567 if( _klass ) return _klass; // Return cached value, if possible
6568
6569 // Oops, need to compute _klass and cache it
6570 ciKlass* k_ary = compute_klass();
6578 // type TypeAryPtr::OOPS. This Type is shared between all
6579 // active compilations. However, the ciKlass which represents
6580 // this Type is *not* shared between compilations, so caching
6581 // this value would result in fetching a dangling pointer.
6582 //
6583 // Recomputing the underlying ciKlass for each request is
6584 // a bit less efficient than caching, but calls to
6585 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6586 ((TypeAryPtr*)this)->_klass = k_ary;
6587 }
6588 return k_ary;
6589 }
6590
6591 // Is there a single ciKlass* that can represent that type?
6592 ciKlass* TypeAryPtr::exact_klass_helper() const {
6593 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6594 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6595 if (k == nullptr) {
6596 return nullptr;
6597 }
6598 k = ciArrayKlass::make(k, is_null_free());
6599 return k;
6600 }
6601
6602 return klass();
6603 }
6604
6605 const Type* TypeAryPtr::base_element_type(int& dims) const {
6606 const Type* elem = this->elem();
6607 dims = 1;
6608 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6609 elem = elem->make_ptr()->is_aryptr()->elem();
6610 dims++;
6611 }
6612 return elem;
6613 }
6614
6615 //------------------------------add_offset-------------------------------------
6616 // Access internals of klass object
6617 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6618 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6619 }
6620
6621 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6622 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6623 }
6624
6625 //------------------------------cast_to_ptr_type-------------------------------
6626 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6627 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6628 if (ptr == _ptr) return this;
6629 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6630 }
6631
6632 bool TypeAryKlassPtr::must_be_exact() const {
6633 if (_elem == Type::BOTTOM) return false;
6634 if (_elem == Type::TOP ) return false;
6635 const TypeKlassPtr* tk = _elem->isa_klassptr();
6636 if (!tk) return true; // a primitive type, like int
6637 // Even though MyValue is final, [LMyValue is only exact if the array
6638 // is null-free due to null-free [LMyValue <: null-able [LMyValue.
6639 if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6640 return false;
6641 }
6642 return tk->must_be_exact();
6643 }
6644
6645
6646 //-----------------------------cast_to_exactness-------------------------------
6647 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6648 if (must_be_exact() && !klass_is_exact) return this; // cannot clear xk
6649 if (klass_is_exact == this->klass_is_exact()) {
6650 return this;
6651 }
6652 ciKlass* k = _klass;
6653 const Type* elem = this->elem();
6654 if (elem->isa_klassptr() && !klass_is_exact) {
6655 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6656 }
6657 bool not_flat = is_not_flat();
6658 bool not_null_free = is_not_null_free();
6659 if (_elem->isa_klassptr()) {
6660 if (klass_is_exact || _elem->isa_aryklassptr()) {
6661 assert((!is_null_free() && !is_flat()) ||
6662 _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
6663 "null-free (or flat) concrete inline type arrays should always be exact");
6664 // An array can't be null-free (or flat) if the klass is exact
6665 not_null_free = true;
6666 not_flat = true;
6667 } else {
6668 // Klass is not exact (anymore), re-compute null-free/flat properties
6669 const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6670 not_null_free = !exact_etype->can_be_inline_type();
6671 not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
6672 }
6673 }
6674 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6675 }
6676
6677 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_null_free() const {
6678 return make(_ptr, elem(), klass(), _offset, is_not_flat(), false, true);
6679 }
6680
6681 //-----------------------------as_instance_type--------------------------------
6682 // Corresponding type for an instance of the given class.
6683 // It will be NotNull, and exact if and only if the klass type is exact.
6684 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6685 ciKlass* k = klass();
6686 bool xk = klass_is_exact();
6687 const Type* el = nullptr;
6688 if (elem()->isa_klassptr()) {
6689 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6690 k = nullptr;
6691 } else {
6692 el = elem();
6693 }
6694 bool null_free = _null_free;
6695 if (null_free && el->isa_ptr()) {
6696 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6697 }
6698 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6699 }
6700
6701
6702 //------------------------------xmeet------------------------------------------
6703 // Compute the MEET of two types, return a new Type object.
6704 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6705 // Perform a fast test for common case; meeting the same types together.
6706 if( this == t ) return this; // Meeting same type-rep?
6707
6708 // Current "this->_base" is Pointer
6709 switch (t->base()) { // switch on original type
6710
6711 case Int: // Mixing ints & oops happens when javac
6712 case Long: // reuses local variables
6713 case FloatTop:
6714 case FloatCon:
6715 case FloatBot:
6716 case DoubleTop:
6717 case DoubleCon:
6718 case DoubleBot:
6719 case NarrowOop:
6720 case NarrowKlass:
6721 case Bottom: // Ye Olde Default
6722 return Type::BOTTOM;
6723 case Top:
6724 return this;
6725
6726 default: // All else is a mistake
6727 typerr(t);
6728
6729 case AnyPtr: { // Meeting to AnyPtrs
6730 // Found an AnyPtr type vs self-KlassPtr type
6731 const TypePtr *tp = t->is_ptr();
6732 Offset offset = meet_offset(tp->offset());
6733 PTR ptr = meet_ptr(tp->ptr());
6734 switch (tp->ptr()) {
6735 case TopPTR:
6736 return this;
6737 case Null:
6738 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6739 case AnyNull:
6740 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
6741 case BotPTR:
6742 case NotNull:
6743 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6744 default: typerr(t);
6745 }
6746 }
6747
6748 case RawPtr:
6749 case MetadataPtr:
6750 case OopPtr:
6751 case AryPtr: // Meet with AryPtr
6752 case InstPtr: // Meet with InstPtr
6753 return TypePtr::BOTTOM;
6754
6755 //
6756 // A-top }
6757 // / | \ } Tops
6758 // B-top A-any C-top }
6759 // | / | \ | } Any-nulls
6760 // B-any | C-any }
6761 // | | |
6762 // B-con A-con C-con } constants; not comparable across classes
6763 // | | |
6764 // B-not | C-not }
6765 // | \ | / | } not-nulls
6766 // B-bot A-not C-bot }
6767 // \ | / } Bottoms
6768 // A-bot }
6769 //
6770
6771 case AryKlassPtr: { // Meet two KlassPtr types
6772 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6773 Offset off = meet_offset(tap->offset());
6774 const Type* elem = _elem->meet(tap->_elem);
6775 PTR ptr = meet_ptr(tap->ptr());
6776 ciKlass* res_klass = nullptr;
6777 bool res_xk = false;
6778 bool res_flat = false;
6779 bool res_not_flat = false;
6780 bool res_not_null_free = false;
6781 MeetResult res = meet_aryptr(ptr, elem, this, tap,
6782 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
6783 assert(res_xk == (ptr == Constant), "");
6784 bool null_free = meet_null_free(tap->_null_free);
6785 if (res == NOT_SUBTYPE) {
6786 null_free = false;
6787 } else if (res == SUBTYPE) {
6788 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6789 null_free = _null_free;
6790 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6791 null_free = tap->_null_free;
6792 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6793 null_free = _null_free || tap->_null_free;
6794 }
6795 }
6796 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6797 } // End of case KlassPtr
6798 case InstKlassPtr: {
6799 const TypeInstKlassPtr *tp = t->is_instklassptr();
6800 Offset offset = meet_offset(tp->offset());
6801 PTR ptr = meet_ptr(tp->ptr());
6802 const TypeInterfaces* interfaces = meet_interfaces(tp);
6803 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6804 const TypeInterfaces* this_interfaces = _interfaces;
6805
6806 switch (ptr) {
6807 case TopPTR:
6808 case AnyNull: // Fall 'down' to dual of object klass
6809 // For instances when a subclass meets a superclass we fall
6810 // below the centerline when the superclass is exact. We need to
6811 // do the same here.
6812 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6813 !tp->klass_is_exact()) {
6814 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6815 } else {
6816 // cannot subclass, so the meet has to fall badly below the centerline
6817 ptr = NotNull;
6818 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6819 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6820 }
6821 case Constant:
6822 case NotNull:
6823 case BotPTR: // Fall down to object klass
6824 // LCA is object_klass, but if we subclass from the top we can do better
6825 if (above_centerline(tp->ptr())) {
6826 // If 'tp' is above the centerline and it is Object class
6827 // then we can subclass in the Java class hierarchy.
6828 // For instances when a subclass meets a superclass we fall
6829 // below the centerline when the superclass is exact. We need
6830 // to do the same here.
6831 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6832 !tp->klass_is_exact()) {
6833 // that is, my array type is a subtype of 'tp' klass
6834 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6835 }
6836 }
6837 // The other case cannot happen, since t cannot be a subtype of an array.
6838 // The meet falls down to Object class below centerline.
6839 if (ptr == Constant)
6840 ptr = NotNull;
6841 interfaces = this_interfaces->intersection_with(tp_interfaces);
6842 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6843 default: typerr(t);
6844 }
6845 }
6846
6847 } // End of switch
6848 return this; // Return the double constant
6849 }
6850
6851 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) {
6852 static_assert(std::is_base_of<T2, T1>::value, "");
6853
6854 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6855 return true;
6856 }
6857
6858 int dummy;
6859 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6860
6861 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6862 return false;
6863 }
6864
6865 if (this_one->is_instance_type(other)) {
6866 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6867 other_exact;
6868 }
6869
6870 assert(this_one->is_array_type(other), "");
6871 const T1* other_ary = this_one->is_array_type(other);
6872 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6873 if (other_top_or_bottom) {
6874 return false;
6875 }
6876
6877 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6878 const TypePtr* this_elem = this_one->elem()->make_ptr();
6879 if (this_elem != nullptr && other_elem != nullptr) {
6880 if (other->is_null_free() && !this_one->is_null_free()) {
6881 return false; // A nullable array can't be a subtype of a null-free array
6882 }
6883 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6884 }
6885 if (this_elem == nullptr && other_elem == nullptr) {
6886 return this_one->klass()->is_subtype_of(other->klass());
6887 }
6888 return false;
6889 }
6890
6891 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6892 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6893 }
6894
6895 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6896 static_assert(std::is_base_of<T2, T1>::value, "");
6897
6898 int dummy;
6899 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6900
6901 if (!this_one->is_array_type(other) ||
6902 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6955 }
6956
6957 const TypePtr* this_elem = this_one->elem()->make_ptr();
6958 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6959 if (other_elem != nullptr && this_elem != nullptr) {
6960 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6961 }
6962 if (other_elem == nullptr && this_elem == nullptr) {
6963 return this_one->klass()->is_subtype_of(other->klass());
6964 }
6965 return false;
6966 }
6967
6968 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6969 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6970 }
6971
6972 //------------------------------xdual------------------------------------------
6973 // Dual: compute field-by-field dual
6974 const Type *TypeAryKlassPtr::xdual() const {
6975 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6976 }
6977
6978 // Is there a single ciKlass* that can represent that type?
6979 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6980 if (elem()->isa_klassptr()) {
6981 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6982 if (k == nullptr) {
6983 return nullptr;
6984 }
6985 k = ciArrayKlass::make(k, _null_free);
6986 return k;
6987 }
6988
6989 return klass();
6990 }
6991
6992 ciKlass* TypeAryKlassPtr::klass() const {
6993 if (_klass != nullptr) {
6994 return _klass;
6995 }
6996 ciKlass* k = nullptr;
6997 if (elem()->isa_klassptr()) {
6998 // leave null
6999 } else if ((elem()->base() == Type::Top) ||
7000 (elem()->base() == Type::Bottom)) {
7001 } else {
7002 k = ciTypeArrayKlass::make(elem()->basic_type());
7003 ((TypeAryKlassPtr*)this)->_klass = k;
7004 }
7005 return k;
7012 switch( _ptr ) {
7013 case Constant:
7014 st->print("precise ");
7015 case NotNull:
7016 {
7017 st->print("[");
7018 _elem->dump2(d, depth, st);
7019 _interfaces->dump(st);
7020 st->print(": ");
7021 }
7022 case BotPTR:
7023 if( !WizardMode && !Verbose && _ptr != Constant ) break;
7024 case TopPTR:
7025 case AnyNull:
7026 st->print(":%s", ptr_msg[_ptr]);
7027 if( _ptr == Constant ) st->print(":exact");
7028 break;
7029 default:
7030 break;
7031 }
7032 if (is_flat()) st->print(":flat");
7033 if (_null_free) st->print(":null free");
7034 if (Verbose) {
7035 if (_not_flat) st->print(":not flat");
7036 if (_not_null_free) st->print(":not null free");
7037 }
7038
7039 _offset.dump2(st);
7040
7041 st->print(" *");
7042 }
7043 #endif
7044
7045 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7046 const Type* elem = this->elem();
7047 dims = 1;
7048 while (elem->isa_aryklassptr()) {
7049 elem = elem->is_aryklassptr()->elem();
7050 dims++;
7051 }
7052 return elem;
7053 }
7054
7055 //=============================================================================
7056 // Convenience common pre-built types.
7057
7058 //------------------------------make-------------------------------------------
7059 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7060 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7061 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7062 }
7063
7064 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7065 return make(domain, domain, range, range);
7066 }
7067
7068 //------------------------------osr_domain-----------------------------
7069 const TypeTuple* osr_domain() {
7070 const Type **fields = TypeTuple::fields(2);
7071 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7072 return TypeTuple::make(TypeFunc::Parms+1, fields);
7073 }
7074
7075 //------------------------------make-------------------------------------------
7076 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7077 Compile* C = Compile::current();
7078 const TypeFunc* tf = nullptr;
7079 if (!is_osr_compilation) {
7080 tf = C->last_tf(method); // check cache
7081 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7082 }
7083 // Inline types are not passed/returned by reference, instead each field of
7084 // the inline type is passed/returned as an argument. We maintain two views of
7085 // the argument/return list here: one based on the signature (with an inline
7086 // type argument/return as a single slot), one based on the actual calling
7087 // convention (with an inline type argument/return as a list of its fields).
7088 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7089 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7090 if (method != C->method() && method->get_Method()->mismatch()) {
7091 has_scalar_args = false;
7092 }
7093 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7094 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7095 ciSignature* sig = method->signature();
7096 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7097 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7098 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7099 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7100 if (!is_osr_compilation) {
7101 C->set_last_tf(method, tf); // fill cache
7102 }
7103 return tf;
7104 }
7105
7106 //------------------------------meet-------------------------------------------
7107 // Compute the MEET of two types. It returns a new Type object.
7108 const Type *TypeFunc::xmeet( const Type *t ) const {
7109 // Perform a fast test for common case; meeting the same types together.
7110 if( this == t ) return this; // Meeting same type-rep?
7111
7112 // Current "this->_base" is Func
7113 switch (t->base()) { // switch on original type
7114
7115 case Bottom: // Ye Olde Default
7116 return t;
7117
7118 default: // All else is a mistake
7119 typerr(t);
7120
7121 case Top:
7122 break;
7123 }
7124 return this; // Return the double constant
7125 }
7126
7127 //------------------------------xdual------------------------------------------
7128 // Dual: compute field-by-field dual
7129 const Type *TypeFunc::xdual() const {
7130 return this;
7131 }
7132
7133 //------------------------------eq---------------------------------------------
7134 // Structural equality check for Type representations
7135 bool TypeFunc::eq( const Type *t ) const {
7136 const TypeFunc *a = (const TypeFunc*)t;
7137 return _domain_sig == a->_domain_sig &&
7138 _domain_cc == a->_domain_cc &&
7139 _range_sig == a->_range_sig &&
7140 _range_cc == a->_range_cc;
7141 }
7142
7143 //------------------------------hash-------------------------------------------
7144 // Type-specific hashing function.
7145 uint TypeFunc::hash(void) const {
7146 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7147 }
7148
7149 //------------------------------dump2------------------------------------------
7150 // Dump Function Type
7151 #ifndef PRODUCT
7152 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7153 if( _range_sig->cnt() <= Parms )
7154 st->print("void");
7155 else {
7156 uint i;
7157 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7158 _range_sig->field_at(i)->dump2(d,depth,st);
7159 st->print("/");
7160 }
7161 _range_sig->field_at(i)->dump2(d,depth,st);
7162 }
7163 st->print(" ");
7164 st->print("( ");
7165 if( !depth || d[this] ) { // Check for recursive dump
7166 st->print("...)");
7167 return;
7168 }
7169 d.Insert((void*)this,(void*)this); // Stop recursion
7170 if (Parms < _domain_sig->cnt())
7171 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7172 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7173 st->print(", ");
7174 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7175 }
7176 st->print(" )");
7177 }
7178 #endif
7179
7180 //------------------------------singleton--------------------------------------
7181 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7182 // constants (Ldi nodes). Singletons are integer, float or double constants
7183 // or a single symbol.
7184 bool TypeFunc::singleton(void) const {
7185 return false; // Never a singleton
7186 }
7187
7188 bool TypeFunc::empty(void) const {
7189 return false; // Never empty
7190 }
7191
7192
7193 BasicType TypeFunc::return_type() const{
7194 if (range_sig()->cnt() == TypeFunc::Parms) {
7195 return T_VOID;
7196 }
7197 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7198 }
|