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