5 * This code is free software; you can redistribute it and/or modify it
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 "ci/ciMethodData.hpp"
26 #include "ci/ciTypeFlow.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/vmSymbols.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/callnode.hpp"
39 #include "opto/arraycopynode.hpp"
40 #include "opto/matcher.hpp"
41 #include "opto/node.hpp"
42 #include "opto/opcodes.hpp"
43 #include "opto/runtime.hpp"
44 #include "opto/type.hpp"
45 #include "utilities/checkedCast.hpp"
46 #include "utilities/powerOfTwo.hpp"
47 #include "utilities/stringUtils.hpp"
48 #include "runtime/stubRoutines.hpp"
49
50 // Portions of code courtesy of Clifford Click
51
52 // Optimization - Graph Style
53
54 // Dictionary of types shared among compilations.
55 Dict* Type::_shared_type_dict = nullptr;
56
57 // Array which maps compiler types to Basic Types
58 const Type::TypeInfo Type::_type_info[Type::lastype] = {
59 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
60 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
61 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
62 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
63 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
64 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
65 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
66 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
67 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
68 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
69 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
70
71 #if defined(PPC64)
72 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
73 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
74 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
75 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
214 case ciTypeFlow::StateVector::T_NULL:
215 assert(type == ciTypeFlow::StateVector::null_type(), "");
216 return TypePtr::NULL_PTR;
217
218 case ciTypeFlow::StateVector::T_LONG2:
219 // The ciTypeFlow pass pushes a long, then the half.
220 // We do the same.
221 assert(type == ciTypeFlow::StateVector::long2_type(), "");
222 return TypeInt::TOP;
223
224 case ciTypeFlow::StateVector::T_DOUBLE2:
225 // The ciTypeFlow pass pushes double, then the half.
226 // Our convention is the same.
227 assert(type == ciTypeFlow::StateVector::double2_type(), "");
228 return Type::TOP;
229
230 case T_ADDRESS:
231 assert(type->is_return_address(), "");
232 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
233
234 default:
235 // make sure we did not mix up the cases:
236 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
237 assert(type != ciTypeFlow::StateVector::top_type(), "");
238 assert(type != ciTypeFlow::StateVector::null_type(), "");
239 assert(type != ciTypeFlow::StateVector::long2_type(), "");
240 assert(type != ciTypeFlow::StateVector::double2_type(), "");
241 assert(!type->is_return_address(), "");
242
243 return Type::get_const_type(type);
244 }
245 }
246
247
248 //-----------------------make_from_constant------------------------------------
249 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
250 int stable_dimension, bool is_narrow_oop,
251 bool is_autobox_cache) {
252 switch (constant.basic_type()) {
253 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
534 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
535 ffalse[0] = Type::CONTROL;
536 ffalse[1] = Type::TOP;
537 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
538
539 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
540 fneither[0] = Type::TOP;
541 fneither[1] = Type::TOP;
542 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
543
544 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
545 ftrue[0] = Type::TOP;
546 ftrue[1] = Type::CONTROL;
547 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
548
549 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
550 floop[0] = Type::CONTROL;
551 floop[1] = TypeInt::INT;
552 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
553
554 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
555 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
556 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
557
558 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
559 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
560
561 const Type **fmembar = TypeTuple::fields(0);
562 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
563
564 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
565 fsc[0] = TypeInt::CC;
566 fsc[1] = Type::MEMORY;
567 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
568
569 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
570 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
571 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
572 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
573 false, nullptr, oopDesc::mark_offset_in_bytes());
574 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
575 false, nullptr, oopDesc::klass_offset_in_bytes());
576 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
577
578 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
579
580 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
581 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
582
583 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
584
585 mreg2type[Op_Node] = Type::BOTTOM;
586 mreg2type[Op_Set ] = nullptr;
587 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
588 mreg2type[Op_RegI] = TypeInt::INT;
589 mreg2type[Op_RegP] = TypePtr::BOTTOM;
590 mreg2type[Op_RegF] = Type::FLOAT;
591 mreg2type[Op_RegD] = Type::DOUBLE;
592 mreg2type[Op_RegL] = TypeLong::LONG;
593 mreg2type[Op_RegFlags] = TypeInt::CC;
594
595 GrowableArray<ciInstanceKlass*> array_interfaces;
596 array_interfaces.push(current->env()->Cloneable_klass());
597 array_interfaces.push(current->env()->Serializable_klass());
598 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
599 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
600
601 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS), nullptr, false, Type::OffsetBot);
602 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
603
604 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
605
606 #ifdef _LP64
607 if (UseCompressedOops) {
608 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
609 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
610 } else
611 #endif
612 {
613 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
614 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
615 }
616 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
617 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
618 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
619 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
620 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
621 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
622 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
623
624 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
625 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
626 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
627 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
628 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
629 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
630 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
631 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
632 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
633 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
634 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
635 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
636
637 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
638 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
639
640 const Type **fi2c = TypeTuple::fields(2);
641 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
642 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
643 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
644
645 const Type **intpair = TypeTuple::fields(2);
646 intpair[0] = TypeInt::INT;
647 intpair[1] = TypeInt::INT;
648 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
649
650 const Type **longpair = TypeTuple::fields(2);
651 longpair[0] = TypeLong::LONG;
652 longpair[1] = TypeLong::LONG;
653 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
654
655 const Type **intccpair = TypeTuple::fields(2);
656 intccpair[0] = TypeInt::INT;
657 intccpair[1] = TypeInt::CC;
658 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
659
660 const Type **longccpair = TypeTuple::fields(2);
661 longccpair[0] = TypeLong::LONG;
662 longccpair[1] = TypeInt::CC;
663 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
664
665 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
666 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
667 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
668 _const_basic_type[T_CHAR] = TypeInt::CHAR;
669 _const_basic_type[T_BYTE] = TypeInt::BYTE;
670 _const_basic_type[T_SHORT] = TypeInt::SHORT;
671 _const_basic_type[T_INT] = TypeInt::INT;
672 _const_basic_type[T_LONG] = TypeLong::LONG;
673 _const_basic_type[T_FLOAT] = Type::FLOAT;
674 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
675 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
676 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
677 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
678 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
679 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
680
681 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
682 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
683 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
684 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
685 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
686 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
687 _zero_type[T_INT] = TypeInt::ZERO;
688 _zero_type[T_LONG] = TypeLong::ZERO;
689 _zero_type[T_FLOAT] = TypeF::ZERO;
690 _zero_type[T_DOUBLE] = TypeD::ZERO;
691 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
692 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
693 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
694 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
695
696 // get_zero_type() should not happen for T_CONFLICT
697 _zero_type[T_CONFLICT]= nullptr;
698
699 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
700 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
701
702 if (Matcher::supports_scalable_vector()) {
703 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
704 }
705
706 // Vector predefined types, it needs initialized _const_basic_type[].
707 if (Matcher::vector_size_supported(T_BYTE, 4)) {
708 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
709 }
710 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
711 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
712 }
947 ~VerifyMeet() {
948 assert(_C->_type_verify->_depth != 0, "");
949 _C->_type_verify->_depth--;
950 if (_C->_type_verify->_depth == 0) {
951 _C->_type_verify->_cache.trunc_to(0);
952 }
953 }
954
955 const Type* meet(const Type* t1, const Type* t2) const {
956 return _C->_type_verify->meet(t1, t2);
957 }
958
959 void add(const Type* t1, const Type* t2, const Type* res) const {
960 _C->_type_verify->add(t1, t2, res);
961 }
962 };
963
964 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
965 Compile* C = Compile::current();
966 const Type* mt2 = verify.meet(t, this);
967 if (mt != mt2) {
968 tty->print_cr("=== Meet Not Commutative ===");
969 tty->print("t = "); t->dump(); tty->cr();
970 tty->print("this = "); dump(); tty->cr();
971 tty->print("t meet this = "); mt2->dump(); tty->cr();
972 tty->print("this meet t = "); mt->dump(); tty->cr();
973 fatal("meet not commutative");
974 }
975 const Type* dual_join = mt->_dual;
976 const Type* t2t = verify.meet(dual_join,t->_dual);
977 const Type* t2this = verify.meet(dual_join,this->_dual);
978
979 // Interface meet Oop is Not Symmetric:
980 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
981 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
982
983 if (t2t != t->_dual || t2this != this->_dual) {
984 tty->print_cr("=== Meet Not Symmetric ===");
985 tty->print("t = "); t->dump(); tty->cr();
986 tty->print("this= "); dump(); tty->cr();
987 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
988
989 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
990 tty->print("this_dual= "); _dual->dump(); tty->cr();
991 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
992
993 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
994 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
995
996 fatal("meet not symmetric");
997 }
998 }
999 #endif
1000
1001 //------------------------------meet-------------------------------------------
1002 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1003 // commutative and the lattice is symmetric.
1004 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1005 if (isa_narrowoop() && t->isa_narrowoop()) {
1006 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1007 return result->make_narrowoop();
1008 }
1009 if (isa_narrowklass() && t->isa_narrowklass()) {
1010 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1011 return result->make_narrowklass();
1012 }
1013
1014 #ifdef ASSERT
1015 Compile* C = Compile::current();
1016 VerifyMeet verify(C);
1017 #endif
1018
1019 const Type *this_t = maybe_remove_speculative(include_speculative);
1020 t = t->maybe_remove_speculative(include_speculative);
1021
1022 const Type *mt = this_t->xmeet(t);
1023 #ifdef ASSERT
1024 verify.add(this_t, t, mt);
1025 if (isa_narrowoop() || t->isa_narrowoop()) {
1026 return mt;
1027 }
1028 if (isa_narrowklass() || t->isa_narrowklass()) {
1029 return mt;
1030 }
1031 this_t->check_symmetrical(t, mt, verify);
1032 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1033 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1034 #endif
1035 return mt;
1036 }
1037
1038 //------------------------------xmeet------------------------------------------
1039 // Compute the MEET of two types. It returns a new Type object.
1040 const Type *Type::xmeet( const Type *t ) const {
1041 // Perform a fast test for common case; meeting the same types together.
1042 if( this == t ) return this; // Meeting same type-rep?
1043
1044 // Meeting TOP with anything?
1045 if( _base == Top ) return t;
1046
1047 // Meeting BOTTOM with anything?
1048 if( _base == Bottom ) return BOTTOM;
1049
1050 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2298
2299 bool TypeLong::empty(void) const {
2300 return _lo > _hi;
2301 }
2302
2303 //=============================================================================
2304 // Convenience common pre-built types.
2305 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2306 const TypeTuple *TypeTuple::IFFALSE;
2307 const TypeTuple *TypeTuple::IFTRUE;
2308 const TypeTuple *TypeTuple::IFNEITHER;
2309 const TypeTuple *TypeTuple::LOOPBODY;
2310 const TypeTuple *TypeTuple::MEMBAR;
2311 const TypeTuple *TypeTuple::STORECONDITIONAL;
2312 const TypeTuple *TypeTuple::START_I2C;
2313 const TypeTuple *TypeTuple::INT_PAIR;
2314 const TypeTuple *TypeTuple::LONG_PAIR;
2315 const TypeTuple *TypeTuple::INT_CC_PAIR;
2316 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2317
2318 //------------------------------make-------------------------------------------
2319 // Make a TypeTuple from the range of a method signature
2320 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2321 ciType* return_type = sig->return_type();
2322 uint arg_cnt = return_type->size();
2323 const Type **field_array = fields(arg_cnt);
2324 switch (return_type->basic_type()) {
2325 case T_LONG:
2326 field_array[TypeFunc::Parms] = TypeLong::LONG;
2327 field_array[TypeFunc::Parms+1] = Type::HALF;
2328 break;
2329 case T_DOUBLE:
2330 field_array[TypeFunc::Parms] = Type::DOUBLE;
2331 field_array[TypeFunc::Parms+1] = Type::HALF;
2332 break;
2333 case T_OBJECT:
2334 case T_ARRAY:
2335 case T_BOOLEAN:
2336 case T_CHAR:
2337 case T_FLOAT:
2338 case T_BYTE:
2339 case T_SHORT:
2340 case T_INT:
2341 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2342 break;
2343 case T_VOID:
2344 break;
2345 default:
2346 ShouldNotReachHere();
2347 }
2348 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2349 }
2350
2351 // Make a TypeTuple from the domain of a method signature
2352 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2353 uint arg_cnt = sig->size();
2354
2355 uint pos = TypeFunc::Parms;
2356 const Type **field_array;
2357 if (recv != nullptr) {
2358 arg_cnt++;
2359 field_array = fields(arg_cnt);
2360 // Use get_const_type here because it respects UseUniqueSubclasses:
2361 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2362 } else {
2363 field_array = fields(arg_cnt);
2364 }
2365
2366 int i = 0;
2367 while (pos < TypeFunc::Parms + arg_cnt) {
2368 ciType* type = sig->type_at(i);
2369
2370 switch (type->basic_type()) {
2371 case T_LONG:
2372 field_array[pos++] = TypeLong::LONG;
2373 field_array[pos++] = Type::HALF;
2374 break;
2375 case T_DOUBLE:
2376 field_array[pos++] = Type::DOUBLE;
2377 field_array[pos++] = Type::HALF;
2378 break;
2379 case T_OBJECT:
2380 case T_ARRAY:
2381 case T_FLOAT:
2382 case T_INT:
2383 field_array[pos++] = get_const_type(type, interface_handling);
2384 break;
2385 case T_BOOLEAN:
2386 case T_CHAR:
2387 case T_BYTE:
2388 case T_SHORT:
2389 field_array[pos++] = TypeInt::INT;
2390 break;
2391 default:
2392 ShouldNotReachHere();
2393 }
2394 i++;
2395 }
2396
2397 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2398 }
2399
2400 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2401 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2402 }
2403
2404 //------------------------------fields-----------------------------------------
2405 // Subroutine call type with space allocated for argument types
2406 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2407 const Type **TypeTuple::fields( uint arg_cnt ) {
2408 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2409 flds[TypeFunc::Control ] = Type::CONTROL;
2410 flds[TypeFunc::I_O ] = Type::ABIO;
2411 flds[TypeFunc::Memory ] = Type::MEMORY;
2412 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2413 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2414
2415 return flds;
2510 if (_fields[i]->empty()) return true;
2511 }
2512 return false;
2513 }
2514
2515 //=============================================================================
2516 // Convenience common pre-built types.
2517
2518 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2519 // Certain normalizations keep us sane when comparing types.
2520 // We do not want arrayOop variables to differ only by the wideness
2521 // of their index types. Pick minimum wideness, since that is the
2522 // forced wideness of small ranges anyway.
2523 if (size->_widen != Type::WidenMin)
2524 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2525 else
2526 return size;
2527 }
2528
2529 //------------------------------make-------------------------------------------
2530 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2531 if (UseCompressedOops && elem->isa_oopptr()) {
2532 elem = elem->make_narrowoop();
2533 }
2534 size = normalize_array_size(size);
2535 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2536 }
2537
2538 //------------------------------meet-------------------------------------------
2539 // Compute the MEET of two types. It returns a new Type object.
2540 const Type *TypeAry::xmeet( const Type *t ) const {
2541 // Perform a fast test for common case; meeting the same types together.
2542 if( this == t ) return this; // Meeting same type-rep?
2543
2544 // Current "this->_base" is Ary
2545 switch (t->base()) { // switch on original type
2546
2547 case Bottom: // Ye Olde Default
2548 return t;
2549
2550 default: // All else is a mistake
2551 typerr(t);
2552
2553 case Array: { // Meeting 2 arrays?
2554 const TypeAry *a = t->is_ary();
2555 return TypeAry::make(_elem->meet_speculative(a->_elem),
2556 _size->xmeet(a->_size)->is_int(),
2557 _stable && a->_stable);
2558 }
2559 case Top:
2560 break;
2561 }
2562 return this; // Return the double constant
2563 }
2564
2565 //------------------------------xdual------------------------------------------
2566 // Dual: compute field-by-field dual
2567 const Type *TypeAry::xdual() const {
2568 const TypeInt* size_dual = _size->dual()->is_int();
2569 size_dual = normalize_array_size(size_dual);
2570 return new TypeAry(_elem->dual(), size_dual, !_stable);
2571 }
2572
2573 //------------------------------eq---------------------------------------------
2574 // Structural equality check for Type representations
2575 bool TypeAry::eq( const Type *t ) const {
2576 const TypeAry *a = (const TypeAry*)t;
2577 return _elem == a->_elem &&
2578 _stable == a->_stable &&
2579 _size == a->_size;
2580 }
2581
2582 //------------------------------hash-------------------------------------------
2583 // Type-specific hashing function.
2584 uint TypeAry::hash(void) const {
2585 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2586 }
2587
2588 /**
2589 * Return same type without a speculative part in the element
2590 */
2591 const TypeAry* TypeAry::remove_speculative() const {
2592 return make(_elem->remove_speculative(), _size, _stable);
2593 }
2594
2595 /**
2596 * Return same type with cleaned up speculative part of element
2597 */
2598 const Type* TypeAry::cleanup_speculative() const {
2599 return make(_elem->cleanup_speculative(), _size, _stable);
2600 }
2601
2602 /**
2603 * Return same type but with a different inline depth (used for speculation)
2604 *
2605 * @param depth depth to meet with
2606 */
2607 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2608 if (!UseInlineDepthForSpeculativeTypes) {
2609 return this;
2610 }
2611 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2612 }
2613
2614 //------------------------------dump2------------------------------------------
2615 #ifndef PRODUCT
2616 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2617 if (_stable) st->print("stable:");
2618 _elem->dump2(d, depth, st);
2619 st->print("[");
2620 _size->dump2(d, depth, st);
2621 st->print("]");
2622 }
2623 #endif
2624
2625 //------------------------------singleton--------------------------------------
2626 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2627 // constants (Ldi nodes). Singletons are integer, float or double constants
2628 // or a single symbol.
2629 bool TypeAry::singleton(void) const {
2630 return false; // Never a singleton
2631 }
2632
2633 bool TypeAry::empty(void) const {
2634 return _elem->empty() || _size->empty();
2635 }
2636
2637 //--------------------------ary_must_be_exact----------------------------------
2638 bool TypeAry::ary_must_be_exact() const {
2639 // This logic looks at the element type of an array, and returns true
2640 // if the element type is either a primitive or a final instance class.
2641 // In such cases, an array built on this ary must have no subclasses.
2642 if (_elem == BOTTOM) return false; // general array not exact
2643 if (_elem == TOP ) return false; // inverted general array not exact
2644 const TypeOopPtr* toop = nullptr;
2645 if (UseCompressedOops && _elem->isa_narrowoop()) {
2646 toop = _elem->make_ptr()->isa_oopptr();
2647 } else {
2648 toop = _elem->isa_oopptr();
2649 }
2650 if (!toop) return true; // a primitive type, like int
2651 if (!toop->is_loaded()) return false; // unloaded class
2652 const TypeInstPtr* tinst;
2653 if (_elem->isa_narrowoop())
2654 tinst = _elem->make_ptr()->isa_instptr();
2655 else
2656 tinst = _elem->isa_instptr();
2657 if (tinst)
2658 return tinst->instance_klass()->is_final();
2659 const TypeAryPtr* tap;
2660 if (_elem->isa_narrowoop())
2661 tap = _elem->make_ptr()->isa_aryptr();
2662 else
2663 tap = _elem->isa_aryptr();
2664 if (tap)
2665 return tap->ary()->ary_must_be_exact();
2666 return false;
2667 }
2668
2669 //==============================TypeVect=======================================
2670 // Convenience common pre-built types.
2671 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2672 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2673 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2674 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2675 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2676 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2677 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2678
2813
2814 //=============================================================================
2815 // Convenience common pre-built types.
2816 const TypePtr *TypePtr::NULL_PTR;
2817 const TypePtr *TypePtr::NOTNULL;
2818 const TypePtr *TypePtr::BOTTOM;
2819
2820 //------------------------------meet-------------------------------------------
2821 // Meet over the PTR enum
2822 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2823 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2824 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2825 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2826 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2827 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2828 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2829 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2830 };
2831
2832 //------------------------------make-------------------------------------------
2833 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2834 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2835 }
2836
2837 //------------------------------cast_to_ptr_type-------------------------------
2838 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2839 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2840 if( ptr == _ptr ) return this;
2841 return make(_base, ptr, _offset, _speculative, _inline_depth);
2842 }
2843
2844 //------------------------------get_con----------------------------------------
2845 intptr_t TypePtr::get_con() const {
2846 assert( _ptr == Null, "" );
2847 return _offset;
2848 }
2849
2850 //------------------------------meet-------------------------------------------
2851 // Compute the MEET of two types. It returns a new Type object.
2852 const Type *TypePtr::xmeet(const Type *t) const {
2853 const Type* res = xmeet_helper(t);
2854 if (res->isa_ptr() == nullptr) {
2855 return res;
2856 }
2857
2858 const TypePtr* res_ptr = res->is_ptr();
2859 if (res_ptr->speculative() != nullptr) {
2860 // type->speculative() is null means that speculation is no better
2861 // than type, i.e. type->speculative() == type. So there are 2
2862 // ways to represent the fact that we have no useful speculative
2863 // data and we should use a single one to be able to test for
2864 // equality between types. Check whether type->speculative() ==
2865 // type and set speculative to null if it is the case.
2866 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2867 return res_ptr->remove_speculative();
2901 int depth = meet_inline_depth(tp->inline_depth());
2902 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2903 }
2904 case RawPtr: // For these, flip the call around to cut down
2905 case OopPtr:
2906 case InstPtr: // on the cases I have to handle.
2907 case AryPtr:
2908 case MetadataPtr:
2909 case KlassPtr:
2910 case InstKlassPtr:
2911 case AryKlassPtr:
2912 return t->xmeet(this); // Call in reverse direction
2913 default: // All else is a mistake
2914 typerr(t);
2915
2916 }
2917 return this;
2918 }
2919
2920 //------------------------------meet_offset------------------------------------
2921 int TypePtr::meet_offset( int offset ) const {
2922 // Either is 'TOP' offset? Return the other offset!
2923 if( _offset == OffsetTop ) return offset;
2924 if( offset == OffsetTop ) return _offset;
2925 // If either is different, return 'BOTTOM' offset
2926 if( _offset != offset ) return OffsetBot;
2927 return _offset;
2928 }
2929
2930 //------------------------------dual_offset------------------------------------
2931 int TypePtr::dual_offset( ) const {
2932 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2933 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2934 return _offset; // Map everything else into self
2935 }
2936
2937 //------------------------------xdual------------------------------------------
2938 // Dual: compute field-by-field dual
2939 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2940 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2941 };
2942 const Type *TypePtr::xdual() const {
2943 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2944 }
2945
2946 //------------------------------xadd_offset------------------------------------
2947 int TypePtr::xadd_offset( intptr_t offset ) const {
2948 // Adding to 'TOP' offset? Return 'TOP'!
2949 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2950 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2951 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2952 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2953 offset += (intptr_t)_offset;
2954 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2955
2956 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2957 // It is possible to construct a negative offset during PhaseCCP
2958
2959 return (int)offset; // Sum valid offsets
2960 }
2961
2962 //------------------------------add_offset-------------------------------------
2963 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2964 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2965 }
2966
2967 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2968 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2969 }
2970
2971 //------------------------------eq---------------------------------------------
2972 // Structural equality check for Type representations
2973 bool TypePtr::eq( const Type *t ) const {
2974 const TypePtr *a = (const TypePtr*)t;
2975 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2976 }
2977
2978 //------------------------------hash-------------------------------------------
2979 // Type-specific hashing function.
2980 uint TypePtr::hash(void) const {
2981 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2982 }
2983
2984 /**
2985 * Return same type without a speculative part
2986 */
2987 const TypePtr* TypePtr::remove_speculative() const {
2988 if (_speculative == nullptr) {
2989 return this;
2990 }
2991 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2992 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2993 }
2994
2995 /**
2996 * Return same type but drop speculative part if we know we won't use
2997 * it
2998 */
2999 const Type* TypePtr::cleanup_speculative() const {
3000 if (speculative() == nullptr) {
3001 return this;
3227 }
3228 // We already know the speculative type is always null
3229 if (speculative_always_null()) {
3230 return false;
3231 }
3232 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3233 return false;
3234 }
3235 return true;
3236 }
3237
3238 //------------------------------dump2------------------------------------------
3239 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3240 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3241 };
3242
3243 #ifndef PRODUCT
3244 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3245 if( _ptr == Null ) st->print("null");
3246 else st->print("%s *", ptr_msg[_ptr]);
3247 if( _offset == OffsetTop ) st->print("+top");
3248 else if( _offset == OffsetBot ) st->print("+bot");
3249 else if( _offset ) st->print("+%d", _offset);
3250 dump_inline_depth(st);
3251 dump_speculative(st);
3252 }
3253
3254 /**
3255 *dump the speculative part of the type
3256 */
3257 void TypePtr::dump_speculative(outputStream *st) const {
3258 if (_speculative != nullptr) {
3259 st->print(" (speculative=");
3260 _speculative->dump_on(st);
3261 st->print(")");
3262 }
3263 }
3264
3265 /**
3266 *dump the inline depth of the type
3267 */
3268 void TypePtr::dump_inline_depth(outputStream *st) const {
3269 if (_inline_depth != InlineDepthBottom) {
3270 if (_inline_depth == InlineDepthTop) {
3271 st->print(" (inline_depth=InlineDepthTop)");
3272 } else {
3273 st->print(" (inline_depth=%d)", _inline_depth);
3274 }
3275 }
3276 }
3277 #endif
3278
3279 //------------------------------singleton--------------------------------------
3280 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3281 // constants
3282 bool TypePtr::singleton(void) const {
3283 // TopPTR, Null, AnyNull, Constant are all singletons
3284 return (_offset != OffsetBot) && !below_centerline(_ptr);
3285 }
3286
3287 bool TypePtr::empty(void) const {
3288 return (_offset == OffsetTop) || above_centerline(_ptr);
3289 }
3290
3291 //=============================================================================
3292 // Convenience common pre-built types.
3293 const TypeRawPtr *TypeRawPtr::BOTTOM;
3294 const TypeRawPtr *TypeRawPtr::NOTNULL;
3295
3296 //------------------------------make-------------------------------------------
3297 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3298 assert( ptr != Constant, "what is the constant?" );
3299 assert( ptr != Null, "Use TypePtr for null" );
3300 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3301 }
3302
3303 const TypeRawPtr *TypeRawPtr::make(address bits) {
3304 assert(bits != nullptr, "Use TypePtr for null");
3305 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3306 }
3307
3308 //------------------------------cast_to_ptr_type-------------------------------
3675 #endif
3676
3677 // Can't be implemented because there's no way to know if the type is above or below the center line.
3678 const Type* TypeInterfaces::xmeet(const Type* t) const {
3679 ShouldNotReachHere();
3680 return Type::xmeet(t);
3681 }
3682
3683 bool TypeInterfaces::singleton(void) const {
3684 ShouldNotReachHere();
3685 return Type::singleton();
3686 }
3687
3688 bool TypeInterfaces::has_non_array_interface() const {
3689 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3690
3691 return !TypeAryPtr::_array_interfaces->contains(this);
3692 }
3693
3694 //------------------------------TypeOopPtr-------------------------------------
3695 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3696 int instance_id, const TypePtr* speculative, int inline_depth)
3697 : TypePtr(t, ptr, offset, speculative, inline_depth),
3698 _const_oop(o), _klass(k),
3699 _interfaces(interfaces),
3700 _klass_is_exact(xk),
3701 _is_ptr_to_narrowoop(false),
3702 _is_ptr_to_narrowklass(false),
3703 _is_ptr_to_boxed_value(false),
3704 _instance_id(instance_id) {
3705 #ifdef ASSERT
3706 if (klass() != nullptr && klass()->is_loaded()) {
3707 interfaces->verify_is_loaded();
3708 }
3709 #endif
3710 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3711 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3712 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3713 }
3714 #ifdef _LP64
3715 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3716 if (_offset == oopDesc::klass_offset_in_bytes()) {
3717 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3718 } else if (klass() == nullptr) {
3719 // Array with unknown body type
3720 assert(this->isa_aryptr(), "only arrays without klass");
3721 _is_ptr_to_narrowoop = UseCompressedOops;
3722 } else if (this->isa_aryptr()) {
3723 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3724 _offset != arrayOopDesc::length_offset_in_bytes());
3725 } else if (klass()->is_instance_klass()) {
3726 ciInstanceKlass* ik = klass()->as_instance_klass();
3727 if (this->isa_klassptr()) {
3728 // Perm objects don't use compressed references
3729 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3730 // unsafe access
3731 _is_ptr_to_narrowoop = UseCompressedOops;
3732 } else {
3733 assert(this->isa_instptr(), "must be an instance ptr.");
3734
3735 if (klass() == ciEnv::current()->Class_klass() &&
3736 (_offset == java_lang_Class::klass_offset() ||
3737 _offset == java_lang_Class::array_klass_offset())) {
3738 // Special hidden fields from the Class.
3739 assert(this->isa_instptr(), "must be an instance ptr.");
3740 _is_ptr_to_narrowoop = false;
3741 } else if (klass() == ciEnv::current()->Class_klass() &&
3742 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3743 // Static fields
3744 ciField* field = nullptr;
3745 if (const_oop() != nullptr) {
3746 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3747 field = k->get_field_by_offset(_offset, true);
3748 }
3749 if (field != nullptr) {
3750 BasicType basic_elem_type = field->layout_type();
3751 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3752 } else {
3753 // unsafe access
3754 _is_ptr_to_narrowoop = UseCompressedOops;
3755 }
3756 } else {
3757 // Instance fields which contains a compressed oop references.
3758 ciField* field = ik->get_field_by_offset(_offset, false);
3759 if (field != nullptr) {
3760 BasicType basic_elem_type = field->layout_type();
3761 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3762 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3763 // Compile::find_alias_type() cast exactness on all types to verify
3764 // that it does not affect alias type.
3765 _is_ptr_to_narrowoop = UseCompressedOops;
3766 } else {
3767 // Type for the copy start in LibraryCallKit::inline_native_clone().
3768 _is_ptr_to_narrowoop = UseCompressedOops;
3769 }
3770 }
3771 }
3772 }
3773 }
3774 #endif
3775 }
3776
3777 //------------------------------make-------------------------------------------
3778 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3779 const TypePtr* speculative, int inline_depth) {
3780 assert(ptr != Constant, "no constant generic pointers");
3781 ciKlass* k = Compile::current()->env()->Object_klass();
3782 bool xk = false;
3783 ciObject* o = nullptr;
3784 const TypeInterfaces* interfaces = TypeInterfaces::make();
3785 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3786 }
3787
3788
3789 //------------------------------cast_to_ptr_type-------------------------------
3790 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3791 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3792 if( ptr == _ptr ) return this;
3793 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3794 }
3795
3796 //-----------------------------cast_to_instance_id----------------------------
3797 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3798 // There are no instances of a general oop.
3799 // Return self unchanged.
3800 return this;
3801 }
3802
3803 //-----------------------------cast_to_exactness-------------------------------
3804 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3805 // There is no such thing as an exact general oop.
3806 // Return self unchanged.
3807 return this;
3808 }
3809
3810
3811 //------------------------------as_klass_type----------------------------------
3812 // Return the klass type corresponding to this instance or array type.
3813 // It is the type that is loaded from an object of this type.
3814 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3815 ShouldNotReachHere();
3816 return nullptr;
3817 }
3818
3819 //------------------------------meet-------------------------------------------
3820 // Compute the MEET of two types. It returns a new Type object.
3821 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3822 // Perform a fast test for common case; meeting the same types together.
3823 if( this == t ) return this; // Meeting same type-rep?
3824
3825 // Current "this->_base" is OopPtr
3826 switch (t->base()) { // switch on original type
3827
3828 case Int: // Mixing ints & oops happens when javac
3829 case Long: // reuses local variables
3830 case HalfFloatTop:
3839 case NarrowOop:
3840 case NarrowKlass:
3841 case Bottom: // Ye Olde Default
3842 return Type::BOTTOM;
3843 case Top:
3844 return this;
3845
3846 default: // All else is a mistake
3847 typerr(t);
3848
3849 case RawPtr:
3850 case MetadataPtr:
3851 case KlassPtr:
3852 case InstKlassPtr:
3853 case AryKlassPtr:
3854 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3855
3856 case AnyPtr: {
3857 // Found an AnyPtr type vs self-OopPtr type
3858 const TypePtr *tp = t->is_ptr();
3859 int offset = meet_offset(tp->offset());
3860 PTR ptr = meet_ptr(tp->ptr());
3861 const TypePtr* speculative = xmeet_speculative(tp);
3862 int depth = meet_inline_depth(tp->inline_depth());
3863 switch (tp->ptr()) {
3864 case Null:
3865 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3866 // else fall through:
3867 case TopPTR:
3868 case AnyNull: {
3869 int instance_id = meet_instance_id(InstanceTop);
3870 return make(ptr, offset, instance_id, speculative, depth);
3871 }
3872 case BotPTR:
3873 case NotNull:
3874 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3875 default: typerr(t);
3876 }
3877 }
3878
3879 case OopPtr: { // Meeting to other OopPtrs
3881 int instance_id = meet_instance_id(tp->instance_id());
3882 const TypePtr* speculative = xmeet_speculative(tp);
3883 int depth = meet_inline_depth(tp->inline_depth());
3884 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3885 }
3886
3887 case InstPtr: // For these, flip the call around to cut down
3888 case AryPtr:
3889 return t->xmeet(this); // Call in reverse direction
3890
3891 } // End of switch
3892 return this; // Return the double constant
3893 }
3894
3895
3896 //------------------------------xdual------------------------------------------
3897 // Dual of a pure heap pointer. No relevant klass or oop information.
3898 const Type *TypeOopPtr::xdual() const {
3899 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3900 assert(const_oop() == nullptr, "no constants here");
3901 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3902 }
3903
3904 //--------------------------make_from_klass_common-----------------------------
3905 // Computes the element-type given a klass.
3906 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3907 if (klass->is_instance_klass()) {
3908 Compile* C = Compile::current();
3909 Dependencies* deps = C->dependencies();
3910 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3911 // Element is an instance
3912 bool klass_is_exact = false;
3913 if (klass->is_loaded()) {
3914 // Try to set klass_is_exact.
3915 ciInstanceKlass* ik = klass->as_instance_klass();
3916 klass_is_exact = ik->is_final();
3917 if (!klass_is_exact && klass_change
3918 && deps != nullptr && UseUniqueSubclasses) {
3919 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3920 if (sub != nullptr) {
3921 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3922 klass = ik = sub;
3923 klass_is_exact = sub->is_final();
3924 }
3925 }
3926 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3927 !ik->is_interface() && !ik->has_subklass()) {
3928 // Add a dependence; if concrete subclass added we need to recompile
3929 deps->assert_leaf_type(ik);
3930 klass_is_exact = true;
3931 }
3932 }
3933 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3934 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3935 } else if (klass->is_obj_array_klass()) {
3936 // Element is an object array. Recursively call ourself.
3937 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3938 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3939 bool xk = etype->klass_is_exact();
3940 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3941 // We used to pass NotNull in here, asserting that the sub-arrays
3942 // are all not-null. This is not true in generally, as code can
3943 // slam nulls down in the subarrays.
3944 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3945 return arr;
3946 } else if (klass->is_type_array_klass()) {
3947 // Element is an typeArray
3948 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3949 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3950 // We used to pass NotNull in here, asserting that the array pointer
3951 // is not-null. That was not true in general.
3952 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3953 return arr;
3954 } else {
3955 ShouldNotReachHere();
3956 return nullptr;
3957 }
3958 }
3959
3960 //------------------------------make_from_constant-----------------------------
3961 // Make a java pointer from an oop constant
3962 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3963 assert(!o->is_null_object(), "null object not yet handled here.");
3964
3965 const bool make_constant = require_constant || o->should_be_constant();
3966
3967 ciKlass* klass = o->klass();
3968 if (klass->is_instance_klass()) {
3969 // Element is an instance
3970 if (make_constant) {
3971 return TypeInstPtr::make(o);
3972 } else {
3973 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3974 }
3975 } else if (klass->is_obj_array_klass()) {
3976 // Element is an object array. Recursively call ourself.
3977 const TypeOopPtr *etype =
3978 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3979 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3980 // We used to pass NotNull in here, asserting that the sub-arrays
3981 // are all not-null. This is not true in generally, as code can
3982 // slam nulls down in the subarrays.
3983 if (make_constant) {
3984 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3985 } else {
3986 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3987 }
3988 } else if (klass->is_type_array_klass()) {
3989 // Element is an typeArray
3990 const Type* etype =
3991 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3992 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3993 // We used to pass NotNull in here, asserting that the array pointer
3994 // is not-null. That was not true in general.
3995 if (make_constant) {
3996 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3997 } else {
3998 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3999 }
4000 }
4001
4002 fatal("unhandled object type");
4003 return nullptr;
4004 }
4005
4006 //------------------------------get_con----------------------------------------
4007 intptr_t TypeOopPtr::get_con() const {
4008 assert( _ptr == Null || _ptr == Constant, "" );
4009 assert( _offset >= 0, "" );
4010
4011 if (_offset != 0) {
4012 // After being ported to the compiler interface, the compiler no longer
4013 // directly manipulates the addresses of oops. Rather, it only has a pointer
4014 // to a handle at compile time. This handle is embedded in the generated
4015 // code and dereferenced at the time the nmethod is made. Until that time,
4016 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4017 // have access to the addresses!). This does not seem to currently happen,
4018 // but this assertion here is to help prevent its occurrence.
4019 tty->print_cr("Found oop constant with non-zero offset");
4020 ShouldNotReachHere();
4021 }
4022
4023 return (intptr_t)const_oop()->constant_encoding();
4024 }
4025
4026
4027 //-----------------------------filter------------------------------------------
4028 // Do not allow interface-vs.-noninterface joins to collapse to top.
4029 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4030
4031 const Type* ft = join_helper(kills, include_speculative);
4050 } else {
4051 return one->equals(two) && TypePtr::eq(t);
4052 }
4053 }
4054
4055 //------------------------------hash-------------------------------------------
4056 // Type-specific hashing function.
4057 uint TypeOopPtr::hash(void) const {
4058 return
4059 (uint)(const_oop() ? const_oop()->hash() : 0) +
4060 (uint)_klass_is_exact +
4061 (uint)_instance_id + TypePtr::hash();
4062 }
4063
4064 //------------------------------dump2------------------------------------------
4065 #ifndef PRODUCT
4066 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4067 st->print("oopptr:%s", ptr_msg[_ptr]);
4068 if( _klass_is_exact ) st->print(":exact");
4069 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4070 switch( _offset ) {
4071 case OffsetTop: st->print("+top"); break;
4072 case OffsetBot: st->print("+any"); break;
4073 case 0: break;
4074 default: st->print("+%d",_offset); break;
4075 }
4076 if (_instance_id == InstanceTop)
4077 st->print(",iid=top");
4078 else if (_instance_id != InstanceBot)
4079 st->print(",iid=%d",_instance_id);
4080
4081 dump_inline_depth(st);
4082 dump_speculative(st);
4083 }
4084 #endif
4085
4086 //------------------------------singleton--------------------------------------
4087 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4088 // constants
4089 bool TypeOopPtr::singleton(void) const {
4090 // detune optimizer to not generate constant oop + constant offset as a constant!
4091 // TopPTR, Null, AnyNull, Constant are all singletons
4092 return (_offset == 0) && !below_centerline(_ptr);
4093 }
4094
4095 //------------------------------add_offset-------------------------------------
4096 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4097 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4098 }
4099
4100 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4101 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
4102 }
4103
4104 /**
4105 * Return same type without a speculative part
4106 */
4107 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4108 if (_speculative == nullptr) {
4109 return this;
4110 }
4111 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4112 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4113 }
4114
4115 /**
4116 * Return same type but drop speculative part if we know we won't use
4117 * it
4118 */
4119 const Type* TypeOopPtr::cleanup_speculative() const {
4120 // If the klass is exact and the ptr is not null then there's
4121 // nothing that the speculative type can help us with
4194 const TypeInstPtr *TypeInstPtr::BOTTOM;
4195 const TypeInstPtr *TypeInstPtr::MIRROR;
4196 const TypeInstPtr *TypeInstPtr::MARK;
4197 const TypeInstPtr *TypeInstPtr::KLASS;
4198
4199 // Is there a single ciKlass* that can represent that type?
4200 ciKlass* TypeInstPtr::exact_klass_helper() const {
4201 if (_interfaces->empty()) {
4202 return _klass;
4203 }
4204 if (_klass != ciEnv::current()->Object_klass()) {
4205 if (_interfaces->eq(_klass->as_instance_klass())) {
4206 return _klass;
4207 }
4208 return nullptr;
4209 }
4210 return _interfaces->exact_klass();
4211 }
4212
4213 //------------------------------TypeInstPtr-------------------------------------
4214 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4215 int instance_id, const TypePtr* speculative, int inline_depth)
4216 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4217 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4218 assert(k != nullptr &&
4219 (k->is_loaded() || o == nullptr),
4220 "cannot have constants with non-loaded klass");
4221 };
4222
4223 //------------------------------make-------------------------------------------
4224 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4225 ciKlass* k,
4226 const TypeInterfaces* interfaces,
4227 bool xk,
4228 ciObject* o,
4229 int offset,
4230 int instance_id,
4231 const TypePtr* speculative,
4232 int inline_depth) {
4233 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4234 // Either const_oop() is null or else ptr is Constant
4235 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4236 "constant pointers must have a value supplied" );
4237 // Ptr is never Null
4238 assert( ptr != Null, "null pointers are not typed" );
4239
4240 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4241 if (ptr == Constant) {
4242 // Note: This case includes meta-object constants, such as methods.
4243 xk = true;
4244 } else if (k->is_loaded()) {
4245 ciInstanceKlass* ik = k->as_instance_klass();
4246 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4247 assert(!ik->is_interface(), "no interface here");
4248 if (xk && ik->is_interface()) xk = false; // no exact interface
4249 }
4250
4251 // Now hash this baby
4252 TypeInstPtr *result =
4253 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4254
4255 return result;
4256 }
4257
4258 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4259 if (k->is_instance_klass()) {
4260 if (k->is_loaded()) {
4261 if (k->is_interface() && interface_handling == ignore_interfaces) {
4262 assert(interface, "no interface expected");
4263 k = ciEnv::current()->Object_klass();
4264 const TypeInterfaces* interfaces = TypeInterfaces::make();
4265 return interfaces;
4266 }
4267 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4268 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4269 if (k->is_interface()) {
4270 assert(interface, "no interface expected");
4271 k = ciEnv::current()->Object_klass();
4272 } else {
4273 assert(klass, "no instance klass expected");
4299 switch (bt) {
4300 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4301 case T_INT: return TypeInt::make(constant.as_int());
4302 case T_CHAR: return TypeInt::make(constant.as_char());
4303 case T_BYTE: return TypeInt::make(constant.as_byte());
4304 case T_SHORT: return TypeInt::make(constant.as_short());
4305 case T_FLOAT: return TypeF::make(constant.as_float());
4306 case T_DOUBLE: return TypeD::make(constant.as_double());
4307 case T_LONG: return TypeLong::make(constant.as_long());
4308 default: break;
4309 }
4310 fatal("Invalid boxed value type '%s'", type2name(bt));
4311 return nullptr;
4312 }
4313
4314 //------------------------------cast_to_ptr_type-------------------------------
4315 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4316 if( ptr == _ptr ) return this;
4317 // Reconstruct _sig info here since not a problem with later lazy
4318 // construction, _sig will show up on demand.
4319 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4320 }
4321
4322
4323 //-----------------------------cast_to_exactness-------------------------------
4324 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4325 if( klass_is_exact == _klass_is_exact ) return this;
4326 if (!_klass->is_loaded()) return this;
4327 ciInstanceKlass* ik = _klass->as_instance_klass();
4328 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4329 assert(!ik->is_interface(), "no interface here");
4330 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4331 }
4332
4333 //-----------------------------cast_to_instance_id----------------------------
4334 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4335 if( instance_id == _instance_id ) return this;
4336 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4337 }
4338
4339 //------------------------------xmeet_unloaded---------------------------------
4340 // Compute the MEET of two InstPtrs when at least one is unloaded.
4341 // Assume classes are different since called after check for same name/class-loader
4342 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4343 int off = meet_offset(tinst->offset());
4344 PTR ptr = meet_ptr(tinst->ptr());
4345 int instance_id = meet_instance_id(tinst->instance_id());
4346 const TypePtr* speculative = xmeet_speculative(tinst);
4347 int depth = meet_inline_depth(tinst->inline_depth());
4348
4349 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4350 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4351 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4352 //
4353 // Meet unloaded class with java/lang/Object
4354 //
4355 // Meet
4356 // | Unloaded Class
4357 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4358 // ===================================================================
4359 // TOP | ..........................Unloaded......................|
4360 // AnyNull | U-AN |................Unloaded......................|
4361 // Constant | ... O-NN .................................. | O-BOT |
4362 // NotNull | ... O-NN .................................. | O-BOT |
4363 // BOTTOM | ........................Object-BOTTOM ..................|
4364 //
4365 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4366 //
4367 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4368 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4369 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4370 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4371 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4372 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4373 }
4374 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4375
4376 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4377 }
4378
4379 // Both are unloaded, not the same class, not Object
4380 // Or meet unloaded with a different loaded class, not java/lang/Object
4381 if (ptr != TypePtr::BotPTR) {
4382 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4383 }
4384 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4385 }
4386
4387
4388 //------------------------------meet-------------------------------------------
4412 case Top:
4413 return this;
4414
4415 default: // All else is a mistake
4416 typerr(t);
4417
4418 case MetadataPtr:
4419 case KlassPtr:
4420 case InstKlassPtr:
4421 case AryKlassPtr:
4422 case RawPtr: return TypePtr::BOTTOM;
4423
4424 case AryPtr: { // All arrays inherit from Object class
4425 // Call in reverse direction to avoid duplication
4426 return t->is_aryptr()->xmeet_helper(this);
4427 }
4428
4429 case OopPtr: { // Meeting to OopPtrs
4430 // Found a OopPtr type vs self-InstPtr type
4431 const TypeOopPtr *tp = t->is_oopptr();
4432 int offset = meet_offset(tp->offset());
4433 PTR ptr = meet_ptr(tp->ptr());
4434 switch (tp->ptr()) {
4435 case TopPTR:
4436 case AnyNull: {
4437 int instance_id = meet_instance_id(InstanceTop);
4438 const TypePtr* speculative = xmeet_speculative(tp);
4439 int depth = meet_inline_depth(tp->inline_depth());
4440 return make(ptr, klass(), _interfaces, klass_is_exact(),
4441 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4442 }
4443 case NotNull:
4444 case BotPTR: {
4445 int instance_id = meet_instance_id(tp->instance_id());
4446 const TypePtr* speculative = xmeet_speculative(tp);
4447 int depth = meet_inline_depth(tp->inline_depth());
4448 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4449 }
4450 default: typerr(t);
4451 }
4452 }
4453
4454 case AnyPtr: { // Meeting to AnyPtrs
4455 // Found an AnyPtr type vs self-InstPtr type
4456 const TypePtr *tp = t->is_ptr();
4457 int offset = meet_offset(tp->offset());
4458 PTR ptr = meet_ptr(tp->ptr());
4459 int instance_id = meet_instance_id(InstanceTop);
4460 const TypePtr* speculative = xmeet_speculative(tp);
4461 int depth = meet_inline_depth(tp->inline_depth());
4462 switch (tp->ptr()) {
4463 case Null:
4464 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4465 // else fall through to AnyNull
4466 case TopPTR:
4467 case AnyNull: {
4468 return make(ptr, klass(), _interfaces, klass_is_exact(),
4469 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4470 }
4471 case NotNull:
4472 case BotPTR:
4473 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4474 default: typerr(t);
4475 }
4476 }
4477
4478 /*
4479 A-top }
4480 / | \ } Tops
4481 B-top A-any C-top }
4482 | / | \ | } Any-nulls
4483 B-any | C-any }
4484 | | |
4485 B-con A-con C-con } constants; not comparable across classes
4486 | | |
4487 B-not | C-not }
4488 | \ | / | } not-nulls
4489 B-bot A-not C-bot }
4490 \ | / } Bottoms
4491 A-bot }
4492 */
4493
4494 case InstPtr: { // Meeting 2 Oops?
4495 // Found an InstPtr sub-type vs self-InstPtr type
4496 const TypeInstPtr *tinst = t->is_instptr();
4497 int off = meet_offset(tinst->offset());
4498 PTR ptr = meet_ptr(tinst->ptr());
4499 int instance_id = meet_instance_id(tinst->instance_id());
4500 const TypePtr* speculative = xmeet_speculative(tinst);
4501 int depth = meet_inline_depth(tinst->inline_depth());
4502 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4503
4504 ciKlass* tinst_klass = tinst->klass();
4505 ciKlass* this_klass = klass();
4506
4507 ciKlass* res_klass = nullptr;
4508 bool res_xk = false;
4509 const Type* res;
4510 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4511
4512 if (kind == UNLOADED) {
4513 // One of these classes has not been loaded
4514 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4515 #ifndef PRODUCT
4516 if (PrintOpto && Verbose) {
4517 tty->print("meet of unloaded classes resulted in: ");
4518 unloaded_meet->dump();
4519 tty->cr();
4520 tty->print(" this == ");
4521 dump();
4522 tty->cr();
4523 tty->print(" tinst == ");
4524 tinst->dump();
4525 tty->cr();
4526 }
4527 #endif
4528 res = unloaded_meet;
4529 } else {
4530 if (kind == NOT_SUBTYPE && instance_id > 0) {
4531 instance_id = InstanceBot;
4532 } else if (kind == LCA) {
4533 instance_id = InstanceBot;
4534 }
4535 ciObject* o = nullptr; // Assume not constant when done
4536 ciObject* this_oop = const_oop();
4537 ciObject* tinst_oop = tinst->const_oop();
4538 if (ptr == Constant) {
4539 if (this_oop != nullptr && tinst_oop != nullptr &&
4540 this_oop->equals(tinst_oop))
4541 o = this_oop;
4542 else if (above_centerline(_ptr)) {
4543 assert(!tinst_klass->is_interface(), "");
4544 o = tinst_oop;
4545 } else if (above_centerline(tinst->_ptr)) {
4546 assert(!this_klass->is_interface(), "");
4547 o = this_oop;
4548 } else
4549 ptr = NotNull;
4550 }
4551 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4552 }
4553
4554 return res;
4555
4556 } // End of case InstPtr
4557
4558 } // End of switch
4559 return this; // Return the double constant
4560 }
4561
4562 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4563 ciKlass*& res_klass, bool& res_xk) {
4564 ciKlass* this_klass = this_type->klass();
4565 ciKlass* other_klass = other_type->klass();
4566 bool this_xk = this_type->klass_is_exact();
4567 bool other_xk = other_type->klass_is_exact();
4568 PTR this_ptr = this_type->ptr();
4569 PTR other_ptr = other_type->ptr();
4570 const TypeInterfaces* this_interfaces = this_type->interfaces();
4571 const TypeInterfaces* other_interfaces = other_type->interfaces();
4572 // Check for easy case; klasses are equal (and perhaps not loaded!)
4573 // If we have constants, then we created oops so classes are loaded
4574 // and we can handle the constants further down. This case handles
4575 // both-not-loaded or both-loaded classes
4576 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4577 res_klass = this_klass;
4578 res_xk = this_xk;
4579 return QUICK;
4580 }
4581
4582 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4583 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4584 return UNLOADED;
4585 }
4586
4587 // !!! Here's how the symmetry requirement breaks down into invariants:
4588 // If we split one up & one down AND they subtype, take the down man.
4589 // If we split one up & one down AND they do NOT subtype, "fall hard".
4590 // If both are up and they subtype, take the subtype class.
4591 // If both are up and they do NOT subtype, "fall hard".
4592 // If both are down and they subtype, take the supertype class.
4593 // If both are down and they do NOT subtype, "fall hard".
4594 // Constants treated as down.
4595
4596 // Now, reorder the above list; observe that both-down+subtype is also
4597 // "fall hard"; "fall hard" becomes the default case:
4598 // If we split one up & one down AND they subtype, take the down man.
4599 // If both are up and they subtype, take the subtype class.
4600
4601 // If both are down and they subtype, "fall hard".
4602 // If both are down and they do NOT subtype, "fall hard".
4603 // If both are up and they do NOT subtype, "fall hard".
4604 // If we split one up & one down AND they do NOT subtype, "fall hard".
4605
4606 // If a proper subtype is exact, and we return it, we return it exactly.
4607 // If a proper supertype is exact, there can be no subtyping relationship!
4608 // If both types are equal to the subtype, exactness is and-ed below the
4609 // centerline and or-ed above it. (N.B. Constants are always exact.)
4610
4611 // Check for subtyping:
4612 const T* subtype = nullptr;
4613 bool subtype_exact = false;
4614 if (this_type->is_same_java_type_as(other_type)) {
4615 subtype = this_type;
4616 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4617 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4618 subtype = this_type; // Pick subtyping class
4619 subtype_exact = this_xk;
4620 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4621 subtype = other_type; // Pick subtyping class
4622 subtype_exact = other_xk;
4623 }
4624
4625 if (subtype) {
4626 if (above_centerline(ptr)) { // both are up?
4627 this_type = other_type = subtype;
4628 this_xk = other_xk = subtype_exact;
4629 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4630 this_type = other_type; // tinst is down; keep down man
4631 this_xk = other_xk;
4632 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4633 other_type = this_type; // this is down; keep down man
4634 other_xk = this_xk;
4635 } else {
4636 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4637 }
4638 }
4639
4640 // Check for classes now being equal
4641 if (this_type->is_same_java_type_as(other_type)) {
4642 // If the klasses are equal, the constants may still differ. Fall to
4643 // NotNull if they do (neither constant is null; that is a special case
4644 // handled elsewhere).
4645 res_klass = this_type->klass();
4646 res_xk = this_xk;
4647 return SUBTYPE;
4648 } // Else classes are not equal
4649
4650 // Since klasses are different, we require a LCA in the Java
4651 // class hierarchy - which means we have to fall to at least NotNull.
4652 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4653 ptr = NotNull;
4654 }
4655
4656 interfaces = this_interfaces->intersection_with(other_interfaces);
4657
4658 // Now we find the LCA of Java classes
4659 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4660
4661 res_klass = k;
4662 res_xk = false;
4663
4664 return LCA;
4665 }
4666
4667 //------------------------java_mirror_type--------------------------------------
4668 ciType* TypeInstPtr::java_mirror_type() const {
4669 // must be a singleton type
4670 if( const_oop() == nullptr ) return nullptr;
4671
4672 // must be of type java.lang.Class
4673 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4674
4675 return const_oop()->as_instance()->java_mirror_type();
4676 }
4677
4678
4679 //------------------------------xdual------------------------------------------
4680 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4681 // inheritance mechanism.
4682 const Type *TypeInstPtr::xdual() const {
4683 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4684 }
4685
4686 //------------------------------eq---------------------------------------------
4687 // Structural equality check for Type representations
4688 bool TypeInstPtr::eq( const Type *t ) const {
4689 const TypeInstPtr *p = t->is_instptr();
4690 return
4691 klass()->equals(p->klass()) &&
4692 _interfaces->eq(p->_interfaces) &&
4693 TypeOopPtr::eq(p); // Check sub-type stuff
4694 }
4695
4696 //------------------------------hash-------------------------------------------
4697 // Type-specific hashing function.
4698 uint TypeInstPtr::hash(void) const {
4699 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4700 }
4701
4702 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4703 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4704 }
4705
4706
4707 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4708 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4709 }
4710
4711 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4712 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4713 }
4714
4715
4716 //------------------------------dump2------------------------------------------
4717 // Dump oop Type
4718 #ifndef PRODUCT
4719 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4733 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4734 char* buf = ss.as_string(/* c_heap= */false);
4735 StringUtils::replace_no_expand(buf, "\n", "");
4736 st->print_raw(buf);
4737 }
4738 case BotPTR:
4739 if (!WizardMode && !Verbose) {
4740 if( _klass_is_exact ) st->print(":exact");
4741 break;
4742 }
4743 case TopPTR:
4744 case AnyNull:
4745 case NotNull:
4746 st->print(":%s", ptr_msg[_ptr]);
4747 if( _klass_is_exact ) st->print(":exact");
4748 break;
4749 default:
4750 break;
4751 }
4752
4753 if( _offset ) { // Dump offset, if any
4754 if( _offset == OffsetBot ) st->print("+any");
4755 else if( _offset == OffsetTop ) st->print("+unknown");
4756 else st->print("+%d", _offset);
4757 }
4758
4759 st->print(" *");
4760 if (_instance_id == InstanceTop)
4761 st->print(",iid=top");
4762 else if (_instance_id != InstanceBot)
4763 st->print(",iid=%d",_instance_id);
4764
4765 dump_inline_depth(st);
4766 dump_speculative(st);
4767 }
4768 #endif
4769
4770 //------------------------------add_offset-------------------------------------
4771 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4772 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4773 _instance_id, add_offset_speculative(offset), _inline_depth);
4774 }
4775
4776 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4777 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4778 _instance_id, with_offset_speculative(offset), _inline_depth);
4779 }
4780
4781 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4782 if (_speculative == nullptr) {
4783 return this;
4784 }
4785 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4786 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4787 _instance_id, nullptr, _inline_depth);
4788 }
4789
4790 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4791 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4792 }
4793
4794 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4795 if (!UseInlineDepthForSpeculativeTypes) {
4796 return this;
4797 }
4798 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4799 }
4800
4801 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4802 assert(is_known_instance(), "should be known");
4803 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4804 }
4805
4806 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4807 bool xk = klass_is_exact();
4808 ciInstanceKlass* ik = klass()->as_instance_klass();
4809 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4810 if (_interfaces->eq(ik)) {
4811 Compile* C = Compile::current();
4812 Dependencies* deps = C->dependencies();
4813 deps->assert_leaf_type(ik);
4814 xk = true;
4815 }
4816 }
4817 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4818 }
4819
4820 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) {
4821 static_assert(std::is_base_of<T2, T1>::value, "");
4822
4823 if (!this_one->is_instance_type(other)) {
4824 return false;
4825 }
4826
4827 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4828 return true;
4829 }
4830
4831 return this_one->klass()->is_subtype_of(other->klass()) &&
4832 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4833 }
4834
4835
4836 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4837 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4842 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4843 return true;
4844 }
4845
4846 if (this_one->is_instance_type(other)) {
4847 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4848 }
4849
4850 int dummy;
4851 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4852 if (this_top_or_bottom) {
4853 return false;
4854 }
4855
4856 const T1* other_ary = this_one->is_array_type(other);
4857 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4858 const TypePtr* this_elem = this_one->elem()->make_ptr();
4859 if (other_elem != nullptr && this_elem != nullptr) {
4860 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4861 }
4862
4863 if (other_elem == nullptr && this_elem == nullptr) {
4864 return this_one->klass()->is_subtype_of(other->klass());
4865 }
4866
4867 return false;
4868 }
4869
4870 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4871 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4872 }
4873
4874 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4875 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4876 }
4877
4878 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4879 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4880 }
4881
4882 //=============================================================================
4883 // Convenience common pre-built types.
4884 const TypeAryPtr* TypeAryPtr::BOTTOM;
4885 const TypeAryPtr* TypeAryPtr::RANGE;
4886 const TypeAryPtr* TypeAryPtr::OOPS;
4887 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4888 const TypeAryPtr* TypeAryPtr::BYTES;
4889 const TypeAryPtr* TypeAryPtr::SHORTS;
4890 const TypeAryPtr* TypeAryPtr::CHARS;
4891 const TypeAryPtr* TypeAryPtr::INTS;
4892 const TypeAryPtr* TypeAryPtr::LONGS;
4893 const TypeAryPtr* TypeAryPtr::FLOATS;
4894 const TypeAryPtr* TypeAryPtr::DOUBLES;
4895
4896 //------------------------------make-------------------------------------------
4897 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4898 int instance_id, const TypePtr* speculative, int inline_depth) {
4899 assert(!(k == nullptr && ary->_elem->isa_int()),
4900 "integral arrays must be pre-equipped with a class");
4901 if (!xk) xk = ary->ary_must_be_exact();
4902 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4903 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4904 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4905 k = nullptr;
4906 }
4907 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4908 }
4909
4910 //------------------------------make-------------------------------------------
4911 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4912 int instance_id, const TypePtr* speculative, int inline_depth,
4913 bool is_autobox_cache) {
4914 assert(!(k == nullptr && ary->_elem->isa_int()),
4915 "integral arrays must be pre-equipped with a class");
4916 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4917 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4918 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4919 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4920 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4921 k = nullptr;
4922 }
4923 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4924 }
4925
4926 //------------------------------cast_to_ptr_type-------------------------------
4927 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4928 if( ptr == _ptr ) return this;
4929 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4930 }
4931
4932
4933 //-----------------------------cast_to_exactness-------------------------------
4934 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4935 if( klass_is_exact == _klass_is_exact ) return this;
4936 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4937 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4938 }
4939
4940 //-----------------------------cast_to_instance_id----------------------------
4941 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4942 if( instance_id == _instance_id ) return this;
4943 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4944 }
4945
4946
4947 //-----------------------------max_array_length-------------------------------
4948 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4949 jint TypeAryPtr::max_array_length(BasicType etype) {
4950 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4951 if (etype == T_NARROWOOP) {
4952 etype = T_OBJECT;
4953 } else if (etype == T_ILLEGAL) { // bottom[]
4954 etype = T_BYTE; // will produce conservatively high value
4955 } else {
4956 fatal("not an element type: %s", type2name(etype));
4957 }
4958 }
4959 return arrayOopDesc::max_array_length(etype);
4960 }
4961
4962 //-----------------------------narrow_size_type-------------------------------
4963 // Narrow the given size type to the index range for the given array base type.
4979 if (hi > max_hi) {
4980 hi = max_hi;
4981 if (size->is_con()) {
4982 lo = hi;
4983 }
4984 chg = true;
4985 }
4986 // Negative length arrays will produce weird intermediate dead fast-path code
4987 if (lo > hi)
4988 return TypeInt::ZERO;
4989 if (!chg)
4990 return size;
4991 return TypeInt::make(lo, hi, Type::WidenMin);
4992 }
4993
4994 //-------------------------------cast_to_size----------------------------------
4995 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4996 assert(new_size != nullptr, "");
4997 new_size = narrow_size_type(new_size);
4998 if (new_size == size()) return this;
4999 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
5000 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
5001 }
5002
5003 //------------------------------cast_to_stable---------------------------------
5004 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5005 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5006 return this;
5007
5008 const Type* elem = this->elem();
5009 const TypePtr* elem_ptr = elem->make_ptr();
5010
5011 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5012 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5013 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5014 }
5015
5016 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
5017
5018 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
5019 }
5020
5021 //-----------------------------stable_dimension--------------------------------
5022 int TypeAryPtr::stable_dimension() const {
5023 if (!is_stable()) return 0;
5024 int dim = 1;
5025 const TypePtr* elem_ptr = elem()->make_ptr();
5026 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5027 dim += elem_ptr->is_aryptr()->stable_dimension();
5028 return dim;
5029 }
5030
5031 //----------------------cast_to_autobox_cache-----------------------------------
5032 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5033 if (is_autobox_cache()) return this;
5034 const TypeOopPtr* etype = elem()->make_oopptr();
5035 if (etype == nullptr) return this;
5036 // The pointers in the autobox arrays are always non-null.
5037 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5038 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
5039 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5040 }
5041
5042 //------------------------------eq---------------------------------------------
5043 // Structural equality check for Type representations
5044 bool TypeAryPtr::eq( const Type *t ) const {
5045 const TypeAryPtr *p = t->is_aryptr();
5046 return
5047 _ary == p->_ary && // Check array
5048 TypeOopPtr::eq(p); // Check sub-parts
5049 }
5050
5051 //------------------------------hash-------------------------------------------
5052 // Type-specific hashing function.
5053 uint TypeAryPtr::hash(void) const {
5054 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
5055 }
5056
5057 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5058 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5059 }
5060
5061 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5062 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5063 }
5064
5065 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5066 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5067 }
5068 //------------------------------meet-------------------------------------------
5069 // Compute the MEET of two types. It returns a new Type object.
5070 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5071 // Perform a fast test for common case; meeting the same types together.
5072 if( this == t ) return this; // Meeting same type-rep?
5073 // Current "this->_base" is Pointer
5074 switch (t->base()) { // switch on original type
5081 case HalfFloatBot:
5082 case FloatTop:
5083 case FloatCon:
5084 case FloatBot:
5085 case DoubleTop:
5086 case DoubleCon:
5087 case DoubleBot:
5088 case NarrowOop:
5089 case NarrowKlass:
5090 case Bottom: // Ye Olde Default
5091 return Type::BOTTOM;
5092 case Top:
5093 return this;
5094
5095 default: // All else is a mistake
5096 typerr(t);
5097
5098 case OopPtr: { // Meeting to OopPtrs
5099 // Found a OopPtr type vs self-AryPtr type
5100 const TypeOopPtr *tp = t->is_oopptr();
5101 int offset = meet_offset(tp->offset());
5102 PTR ptr = meet_ptr(tp->ptr());
5103 int depth = meet_inline_depth(tp->inline_depth());
5104 const TypePtr* speculative = xmeet_speculative(tp);
5105 switch (tp->ptr()) {
5106 case TopPTR:
5107 case AnyNull: {
5108 int instance_id = meet_instance_id(InstanceTop);
5109 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5110 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5111 }
5112 case BotPTR:
5113 case NotNull: {
5114 int instance_id = meet_instance_id(tp->instance_id());
5115 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5116 }
5117 default: ShouldNotReachHere();
5118 }
5119 }
5120
5121 case AnyPtr: { // Meeting two AnyPtrs
5122 // Found an AnyPtr type vs self-AryPtr type
5123 const TypePtr *tp = t->is_ptr();
5124 int offset = meet_offset(tp->offset());
5125 PTR ptr = meet_ptr(tp->ptr());
5126 const TypePtr* speculative = xmeet_speculative(tp);
5127 int depth = meet_inline_depth(tp->inline_depth());
5128 switch (tp->ptr()) {
5129 case TopPTR:
5130 return this;
5131 case BotPTR:
5132 case NotNull:
5133 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5134 case Null:
5135 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5136 // else fall through to AnyNull
5137 case AnyNull: {
5138 int instance_id = meet_instance_id(InstanceTop);
5139 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5140 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5141 }
5142 default: ShouldNotReachHere();
5143 }
5144 }
5145
5146 case MetadataPtr:
5147 case KlassPtr:
5148 case InstKlassPtr:
5149 case AryKlassPtr:
5150 case RawPtr: return TypePtr::BOTTOM;
5151
5152 case AryPtr: { // Meeting 2 references?
5153 const TypeAryPtr *tap = t->is_aryptr();
5154 int off = meet_offset(tap->offset());
5155 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5156 PTR ptr = meet_ptr(tap->ptr());
5157 int instance_id = meet_instance_id(tap->instance_id());
5158 const TypePtr* speculative = xmeet_speculative(tap);
5159 int depth = meet_inline_depth(tap->inline_depth());
5160
5161 ciKlass* res_klass = nullptr;
5162 bool res_xk = false;
5163 const Type* elem = tary->_elem;
5164 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
5165 instance_id = InstanceBot;
5166 }
5167
5168 ciObject* o = nullptr; // Assume not constant when done
5169 ciObject* this_oop = const_oop();
5170 ciObject* tap_oop = tap->const_oop();
5171 if (ptr == Constant) {
5172 if (this_oop != nullptr && tap_oop != nullptr &&
5173 this_oop->equals(tap_oop)) {
5174 o = tap_oop;
5175 } else if (above_centerline(_ptr)) {
5176 o = tap_oop;
5177 } else if (above_centerline(tap->_ptr)) {
5178 o = this_oop;
5179 } else {
5180 ptr = NotNull;
5181 }
5182 }
5183 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
5184 }
5185
5186 // All arrays inherit from Object class
5187 case InstPtr: {
5188 const TypeInstPtr *tp = t->is_instptr();
5189 int offset = meet_offset(tp->offset());
5190 PTR ptr = meet_ptr(tp->ptr());
5191 int instance_id = meet_instance_id(tp->instance_id());
5192 const TypePtr* speculative = xmeet_speculative(tp);
5193 int depth = meet_inline_depth(tp->inline_depth());
5194 const TypeInterfaces* interfaces = meet_interfaces(tp);
5195 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5196 const TypeInterfaces* this_interfaces = _interfaces;
5197
5198 switch (ptr) {
5199 case TopPTR:
5200 case AnyNull: // Fall 'down' to dual of object klass
5201 // For instances when a subclass meets a superclass we fall
5202 // below the centerline when the superclass is exact. We need to
5203 // do the same here.
5204 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5205 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5206 } else {
5207 // cannot subclass, so the meet has to fall badly below the centerline
5208 ptr = NotNull;
5209 instance_id = InstanceBot;
5210 interfaces = this_interfaces->intersection_with(tp_interfaces);
5211 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5212 }
5213 case Constant:
5214 case NotNull:
5215 case BotPTR: // Fall down to object klass
5216 // LCA is object_klass, but if we subclass from the top we can do better
5217 if (above_centerline(tp->ptr())) {
5218 // If 'tp' is above the centerline and it is Object class
5219 // then we can subclass in the Java class hierarchy.
5220 // For instances when a subclass meets a superclass we fall
5221 // below the centerline when the superclass is exact. We need
5222 // to do the same here.
5223 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5224 // that is, my array type is a subtype of 'tp' klass
5225 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5226 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5227 }
5228 }
5229 // The other case cannot happen, since t cannot be a subtype of an array.
5230 // The meet falls down to Object class below centerline.
5231 if (ptr == Constant) {
5232 ptr = NotNull;
5233 }
5234 if (instance_id > 0) {
5235 instance_id = InstanceBot;
5236 }
5237 interfaces = this_interfaces->intersection_with(tp_interfaces);
5238 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5239 default: typerr(t);
5240 }
5241 }
5242 }
5243 return this; // Lint noise
5244 }
5245
5246
5247 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5248 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5249 int dummy;
5250 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5251 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5252 ciKlass* this_klass = this_ary->klass();
5253 ciKlass* other_klass = other_ary->klass();
5254 bool this_xk = this_ary->klass_is_exact();
5255 bool other_xk = other_ary->klass_is_exact();
5256 PTR this_ptr = this_ary->ptr();
5257 PTR other_ptr = other_ary->ptr();
5258 res_klass = nullptr;
5259 MeetResult result = SUBTYPE;
5260 if (elem->isa_int()) {
5261 // Integral array element types have irrelevant lattice relations.
5262 // It is the klass that determines array layout, not the element type.
5263 if (this_top_or_bottom)
5264 res_klass = other_klass;
5265 else if (other_top_or_bottom || other_klass == this_klass) {
5266 res_klass = this_klass;
5267 } else {
5268 // Something like byte[int+] meets char[int+].
5269 // This must fall to bottom, not (int[-128..65535])[int+].
5270 // instance_id = InstanceBot;
5271 elem = Type::BOTTOM;
5272 result = NOT_SUBTYPE;
5273 if (above_centerline(ptr) || ptr == Constant) {
5274 ptr = NotNull;
5275 res_xk = false;
5276 return NOT_SUBTYPE;
5277 }
5278 }
5279 } else {// Non integral arrays.
5280 // Must fall to bottom if exact klasses in upper lattice
5281 // are not equal or super klass is exact.
5282 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5283 // meet with top[] and bottom[] are processed further down:
5284 !this_top_or_bottom && !other_top_or_bottom &&
5285 // both are exact and not equal:
5287 // 'tap' is exact and super or unrelated:
5288 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5289 // 'this' is exact and super or unrelated:
5290 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5291 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5292 elem = Type::BOTTOM;
5293 }
5294 ptr = NotNull;
5295 res_xk = false;
5296 return NOT_SUBTYPE;
5297 }
5298 }
5299
5300 res_xk = false;
5301 switch (other_ptr) {
5302 case AnyNull:
5303 case TopPTR:
5304 // Compute new klass on demand, do not use tap->_klass
5305 if (below_centerline(this_ptr)) {
5306 res_xk = this_xk;
5307 } else {
5308 res_xk = (other_xk || this_xk);
5309 }
5310 return result;
5311 case Constant: {
5312 if (this_ptr == Constant) {
5313 res_xk = true;
5314 } else if(above_centerline(this_ptr)) {
5315 res_xk = true;
5316 } else {
5317 // Only precise for identical arrays
5318 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5319 }
5320 return result;
5321 }
5322 case NotNull:
5323 case BotPTR:
5324 // Compute new klass on demand, do not use tap->_klass
5325 if (above_centerline(this_ptr)) {
5326 res_xk = other_xk;
5327 } else {
5328 res_xk = (other_xk && this_xk) &&
5329 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5330 }
5331 return result;
5332 default: {
5333 ShouldNotReachHere();
5334 return result;
5335 }
5336 }
5337 return result;
5338 }
5339
5340
5341 //------------------------------xdual------------------------------------------
5342 // Dual: compute field-by-field dual
5343 const Type *TypeAryPtr::xdual() const {
5344 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());
5345 }
5346
5347 //------------------------------dump2------------------------------------------
5348 #ifndef PRODUCT
5349 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5350 _ary->dump2(d,depth,st);
5351 _interfaces->dump(st);
5352
5353 switch( _ptr ) {
5354 case Constant:
5355 const_oop()->print(st);
5356 break;
5357 case BotPTR:
5358 if (!WizardMode && !Verbose) {
5359 if( _klass_is_exact ) st->print(":exact");
5360 break;
5361 }
5362 case TopPTR:
5363 case AnyNull:
5364 case NotNull:
5365 st->print(":%s", ptr_msg[_ptr]);
5366 if( _klass_is_exact ) st->print(":exact");
5367 break;
5368 default:
5369 break;
5370 }
5371
5372 if( _offset != 0 ) {
5373 BasicType basic_elem_type = elem()->basic_type();
5374 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5375 if( _offset == OffsetTop ) st->print("+undefined");
5376 else if( _offset == OffsetBot ) st->print("+any");
5377 else if( _offset < header_size ) st->print("+%d", _offset);
5378 else {
5379 if (basic_elem_type == T_ILLEGAL) {
5380 st->print("+any");
5381 } else {
5382 int elem_size = type2aelembytes(basic_elem_type);
5383 st->print("[%d]", (_offset - header_size)/elem_size);
5384 }
5385 }
5386 }
5387 st->print(" *");
5388 if (_instance_id == InstanceTop)
5389 st->print(",iid=top");
5390 else if (_instance_id != InstanceBot)
5391 st->print(",iid=%d",_instance_id);
5392
5393 dump_inline_depth(st);
5394 dump_speculative(st);
5395 }
5396 #endif
5397
5398 bool TypeAryPtr::empty(void) const {
5399 if (_ary->empty()) return true;
5400 return TypeOopPtr::empty();
5401 }
5402
5403 //------------------------------add_offset-------------------------------------
5404 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5405 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5406 }
5407
5408 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5409 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5410 }
5411
5412 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5413 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5414 }
5415
5416 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5417 if (_speculative == nullptr) {
5418 return this;
5419 }
5420 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5421 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5422 }
5423
5424 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5425 if (!UseInlineDepthForSpeculativeTypes) {
5426 return this;
5427 }
5428 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5429 }
5430
5431 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5432 assert(is_known_instance(), "should be known");
5433 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5434 }
5435
5436 //=============================================================================
5437
5438 //------------------------------hash-------------------------------------------
5439 // Type-specific hashing function.
5440 uint TypeNarrowPtr::hash(void) const {
5441 return _ptrtype->hash() + 7;
5442 }
5443
5444 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5445 return _ptrtype->singleton();
5446 }
5447
5448 bool TypeNarrowPtr::empty(void) const {
5449 return _ptrtype->empty();
5450 }
5451
5452 intptr_t TypeNarrowPtr::get_con() const {
5453 return _ptrtype->get_con();
5454 }
5455
5456 bool TypeNarrowPtr::eq( const Type *t ) const {
5457 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5511 case HalfFloatTop:
5512 case HalfFloatCon:
5513 case HalfFloatBot:
5514 case FloatTop:
5515 case FloatCon:
5516 case FloatBot:
5517 case DoubleTop:
5518 case DoubleCon:
5519 case DoubleBot:
5520 case AnyPtr:
5521 case RawPtr:
5522 case OopPtr:
5523 case InstPtr:
5524 case AryPtr:
5525 case MetadataPtr:
5526 case KlassPtr:
5527 case InstKlassPtr:
5528 case AryKlassPtr:
5529 case NarrowOop:
5530 case NarrowKlass:
5531
5532 case Bottom: // Ye Olde Default
5533 return Type::BOTTOM;
5534 case Top:
5535 return this;
5536
5537 default: // All else is a mistake
5538 typerr(t);
5539
5540 } // End of switch
5541
5542 return this;
5543 }
5544
5545 #ifndef PRODUCT
5546 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5547 _ptrtype->dump2(d, depth, st);
5548 }
5549 #endif
5550
5551 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5595 return (one == two) && TypePtr::eq(t);
5596 } else {
5597 return one->equals(two) && TypePtr::eq(t);
5598 }
5599 }
5600
5601 //------------------------------hash-------------------------------------------
5602 // Type-specific hashing function.
5603 uint TypeMetadataPtr::hash(void) const {
5604 return
5605 (metadata() ? metadata()->hash() : 0) +
5606 TypePtr::hash();
5607 }
5608
5609 //------------------------------singleton--------------------------------------
5610 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5611 // constants
5612 bool TypeMetadataPtr::singleton(void) const {
5613 // detune optimizer to not generate constant metadata + constant offset as a constant!
5614 // TopPTR, Null, AnyNull, Constant are all singletons
5615 return (_offset == 0) && !below_centerline(_ptr);
5616 }
5617
5618 //------------------------------add_offset-------------------------------------
5619 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5620 return make( _ptr, _metadata, xadd_offset(offset));
5621 }
5622
5623 //-----------------------------filter------------------------------------------
5624 // Do not allow interface-vs.-noninterface joins to collapse to top.
5625 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5626 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5627 if (ft == nullptr || ft->empty())
5628 return Type::TOP; // Canonical empty value
5629 return ft;
5630 }
5631
5632 //------------------------------get_con----------------------------------------
5633 intptr_t TypeMetadataPtr::get_con() const {
5634 assert( _ptr == Null || _ptr == Constant, "" );
5635 assert( _offset >= 0, "" );
5636
5637 if (_offset != 0) {
5638 // After being ported to the compiler interface, the compiler no longer
5639 // directly manipulates the addresses of oops. Rather, it only has a pointer
5640 // to a handle at compile time. This handle is embedded in the generated
5641 // code and dereferenced at the time the nmethod is made. Until that time,
5642 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5643 // have access to the addresses!). This does not seem to currently happen,
5644 // but this assertion here is to help prevent its occurrence.
5645 tty->print_cr("Found oop constant with non-zero offset");
5646 ShouldNotReachHere();
5647 }
5648
5649 return (intptr_t)metadata()->constant_encoding();
5650 }
5651
5652 //------------------------------cast_to_ptr_type-------------------------------
5653 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5654 if( ptr == _ptr ) return this;
5655 return make(ptr, metadata(), _offset);
5656 }
5657
5671 case HalfFloatBot:
5672 case FloatTop:
5673 case FloatCon:
5674 case FloatBot:
5675 case DoubleTop:
5676 case DoubleCon:
5677 case DoubleBot:
5678 case NarrowOop:
5679 case NarrowKlass:
5680 case Bottom: // Ye Olde Default
5681 return Type::BOTTOM;
5682 case Top:
5683 return this;
5684
5685 default: // All else is a mistake
5686 typerr(t);
5687
5688 case AnyPtr: {
5689 // Found an AnyPtr type vs self-OopPtr type
5690 const TypePtr *tp = t->is_ptr();
5691 int offset = meet_offset(tp->offset());
5692 PTR ptr = meet_ptr(tp->ptr());
5693 switch (tp->ptr()) {
5694 case Null:
5695 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5696 // else fall through:
5697 case TopPTR:
5698 case AnyNull: {
5699 return make(ptr, _metadata, offset);
5700 }
5701 case BotPTR:
5702 case NotNull:
5703 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5704 default: typerr(t);
5705 }
5706 }
5707
5708 case RawPtr:
5709 case KlassPtr:
5710 case InstKlassPtr:
5711 case AryKlassPtr:
5712 case OopPtr:
5713 case InstPtr:
5714 case AryPtr:
5715 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5716
5717 case MetadataPtr: {
5718 const TypeMetadataPtr *tp = t->is_metadataptr();
5719 int offset = meet_offset(tp->offset());
5720 PTR tptr = tp->ptr();
5721 PTR ptr = meet_ptr(tptr);
5722 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5723 if (tptr == TopPTR || _ptr == TopPTR ||
5724 metadata()->equals(tp->metadata())) {
5725 return make(ptr, md, offset);
5726 }
5727 // metadata is different
5728 if( ptr == Constant ) { // Cannot be equal constants, so...
5729 if( tptr == Constant && _ptr != Constant) return t;
5730 if( _ptr == Constant && tptr != Constant) return this;
5731 ptr = NotNull; // Fall down in lattice
5732 }
5733 return make(ptr, nullptr, offset);
5734 break;
5735 }
5736 } // End of switch
5737 return this; // Return the double constant
5738 }
5739
5740
5741 //------------------------------xdual------------------------------------------
5742 // Dual of a pure metadata pointer.
5743 const Type *TypeMetadataPtr::xdual() const {
5744 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5745 }
5746
5747 //------------------------------dump2------------------------------------------
5748 #ifndef PRODUCT
5749 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5750 st->print("metadataptr:%s", ptr_msg[_ptr]);
5751 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5752 switch( _offset ) {
5753 case OffsetTop: st->print("+top"); break;
5754 case OffsetBot: st->print("+any"); break;
5755 case 0: break;
5756 default: st->print("+%d",_offset); break;
5757 }
5758 }
5759 #endif
5760
5761
5762 //=============================================================================
5763 // Convenience common pre-built type.
5764 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5765
5766 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5767 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5768 }
5769
5770 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5771 return make(Constant, m, 0);
5772 }
5773 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5774 return make(Constant, m, 0);
5775 }
5776
5777 //------------------------------make-------------------------------------------
5778 // Create a meta data constant
5779 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5780 assert(m == nullptr || !m->is_klass(), "wrong type");
5781 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5782 }
5783
5784
5785 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5786 const Type* elem = _ary->_elem;
5787 bool xk = klass_is_exact();
5788 if (elem->make_oopptr() != nullptr) {
5789 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5790 if (elem->is_klassptr()->klass_is_exact()) {
5791 xk = true;
5792 }
5793 }
5794 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5795 }
5796
5797 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5798 if (klass->is_instance_klass()) {
5799 return TypeInstKlassPtr::make(klass, interface_handling);
5800 }
5801 return TypeAryKlassPtr::make(klass, interface_handling);
5802 }
5803
5804 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5805 if (klass->is_instance_klass()) {
5806 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5807 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5808 }
5809 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5810 }
5811
5812
5813 //------------------------------TypeKlassPtr-----------------------------------
5814 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5815 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5816 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5817 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5818 }
5819
5820 // Is there a single ciKlass* that can represent that type?
5821 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5822 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5823 if (_interfaces->empty()) {
5824 return _klass;
5825 }
5826 if (_klass != ciEnv::current()->Object_klass()) {
5827 if (_interfaces->eq(_klass->as_instance_klass())) {
5828 return _klass;
5829 }
5830 return nullptr;
5831 }
5832 return _interfaces->exact_klass();
5833 }
5834
5835 //------------------------------eq---------------------------------------------
5836 // Structural equality check for Type representations
5837 bool TypeKlassPtr::eq(const Type *t) const {
5838 const TypeKlassPtr *p = t->is_klassptr();
5839 return
5840 _interfaces->eq(p->_interfaces) &&
5841 TypePtr::eq(p);
5842 }
5843
5844 //------------------------------hash-------------------------------------------
5845 // Type-specific hashing function.
5846 uint TypeKlassPtr::hash(void) const {
5847 return TypePtr::hash() + _interfaces->hash();
5848 }
5849
5850 //------------------------------singleton--------------------------------------
5851 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5852 // constants
5853 bool TypeKlassPtr::singleton(void) const {
5854 // detune optimizer to not generate constant klass + constant offset as a constant!
5855 // TopPTR, Null, AnyNull, Constant are all singletons
5856 return (_offset == 0) && !below_centerline(_ptr);
5857 }
5858
5859 // Do not allow interface-vs.-noninterface joins to collapse to top.
5860 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5861 // logic here mirrors the one from TypeOopPtr::filter. See comments
5862 // there.
5863 const Type* ft = join_helper(kills, include_speculative);
5864
5865 if (ft->empty()) {
5866 return Type::TOP; // Canonical empty value
5867 }
5868
5869 return ft;
5870 }
5871
5872 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5873 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5874 return _interfaces->union_with(other->_interfaces);
5875 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5876 return other->_interfaces;
5877 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5878 return _interfaces;
5879 }
5880 return _interfaces->intersection_with(other->_interfaces);
5881 }
5882
5883 //------------------------------get_con----------------------------------------
5884 intptr_t TypeKlassPtr::get_con() const {
5885 assert( _ptr == Null || _ptr == Constant, "" );
5886 assert( _offset >= 0, "" );
5887
5888 if (_offset != 0) {
5889 // After being ported to the compiler interface, the compiler no longer
5890 // directly manipulates the addresses of oops. Rather, it only has a pointer
5891 // to a handle at compile time. This handle is embedded in the generated
5892 // code and dereferenced at the time the nmethod is made. Until that time,
5893 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5894 // have access to the addresses!). This does not seem to currently happen,
5895 // but this assertion here is to help prevent its occurrence.
5896 tty->print_cr("Found oop constant with non-zero offset");
5897 ShouldNotReachHere();
5898 }
5899
5900 ciKlass* k = exact_klass();
5901
5902 return (intptr_t)k->constant_encoding();
5903 }
5904
5905 //------------------------------dump2------------------------------------------
5906 // Dump Klass Type
5907 #ifndef PRODUCT
5908 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5912 case NotNull:
5913 {
5914 const char *name = klass()->name()->as_utf8();
5915 if (name) {
5916 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5917 } else {
5918 ShouldNotReachHere();
5919 }
5920 _interfaces->dump(st);
5921 }
5922 case BotPTR:
5923 if (!WizardMode && !Verbose && _ptr != Constant) break;
5924 case TopPTR:
5925 case AnyNull:
5926 st->print(":%s", ptr_msg[_ptr]);
5927 if (_ptr == Constant) st->print(":exact");
5928 break;
5929 default:
5930 break;
5931 }
5932
5933 if (_offset) { // Dump offset, if any
5934 if (_offset == OffsetBot) { st->print("+any"); }
5935 else if (_offset == OffsetTop) { st->print("+unknown"); }
5936 else { st->print("+%d", _offset); }
5937 }
5938
5939 st->print(" *");
5940 }
5941 #endif
5942
5943 //=============================================================================
5944 // Convenience common pre-built types.
5945
5946 // Not-null object klass or below
5947 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5948 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5949
5950 bool TypeInstKlassPtr::eq(const Type *t) const {
5951 const TypeKlassPtr *p = t->is_klassptr();
5952 return
5953 klass()->equals(p->klass()) &&
5954 TypeKlassPtr::eq(p);
5955 }
5956
5957 uint TypeInstKlassPtr::hash(void) const {
5958 return klass()->hash() + TypeKlassPtr::hash();
5959 }
5960
5961 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5962 TypeInstKlassPtr *r =
5963 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5964
5965 return r;
5966 }
5967
5968 //------------------------------add_offset-------------------------------------
5969 // Access internals of klass object
5970 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5971 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5972 }
5973
5974 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5975 return make(_ptr, klass(), _interfaces, offset);
5976 }
5977
5978 //------------------------------cast_to_ptr_type-------------------------------
5979 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5980 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5981 if( ptr == _ptr ) return this;
5982 return make(ptr, _klass, _interfaces, _offset);
5983 }
5984
5985
5986 bool TypeInstKlassPtr::must_be_exact() const {
5987 if (!_klass->is_loaded()) return false;
5988 ciInstanceKlass* ik = _klass->as_instance_klass();
5989 if (ik->is_final()) return true; // cannot clear xk
5990 return false;
5991 }
5992
5993 //-----------------------------cast_to_exactness-------------------------------
5994 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5995 if (klass_is_exact == (_ptr == Constant)) return this;
5996 if (must_be_exact()) return this;
5997 ciKlass* k = klass();
5998 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5999 }
6000
6001
6002 //-----------------------------as_instance_type--------------------------------
6003 // Corresponding type for an instance of the given class.
6004 // It will be NotNull, and exact if and only if the klass type is exact.
6005 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6006 ciKlass* k = klass();
6007 bool xk = klass_is_exact();
6008 Compile* C = Compile::current();
6009 Dependencies* deps = C->dependencies();
6010 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6011 // Element is an instance
6012 bool klass_is_exact = false;
6013 const TypeInterfaces* interfaces = _interfaces;
6014 if (k->is_loaded()) {
6015 // Try to set klass_is_exact.
6016 ciInstanceKlass* ik = k->as_instance_klass();
6017 klass_is_exact = ik->is_final();
6018 if (!klass_is_exact && klass_change
6019 && deps != nullptr && UseUniqueSubclasses) {
6020 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6021 if (sub != nullptr) {
6022 if (_interfaces->eq(sub)) {
6023 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6024 k = ik = sub;
6025 xk = sub->is_final();
6026 }
6027 }
6028 }
6029 }
6030 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
6031 }
6032
6033 //------------------------------xmeet------------------------------------------
6034 // Compute the MEET of two types, return a new Type object.
6035 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6036 // Perform a fast test for common case; meeting the same types together.
6037 if( this == t ) return this; // Meeting same type-rep?
6038
6039 // Current "this->_base" is Pointer
6040 switch (t->base()) { // switch on original type
6041
6042 case Int: // Mixing ints & oops happens when javac
6043 case Long: // reuses local variables
6044 case HalfFloatTop:
6045 case HalfFloatCon:
6046 case HalfFloatBot:
6047 case FloatTop:
6048 case FloatCon:
6049 case FloatBot:
6050 case DoubleTop:
6051 case DoubleCon:
6052 case DoubleBot:
6053 case NarrowOop:
6054 case NarrowKlass:
6055 case Bottom: // Ye Olde Default
6056 return Type::BOTTOM;
6057 case Top:
6058 return this;
6059
6060 default: // All else is a mistake
6061 typerr(t);
6062
6063 case AnyPtr: { // Meeting to AnyPtrs
6064 // Found an AnyPtr type vs self-KlassPtr type
6065 const TypePtr *tp = t->is_ptr();
6066 int offset = meet_offset(tp->offset());
6067 PTR ptr = meet_ptr(tp->ptr());
6068 switch (tp->ptr()) {
6069 case TopPTR:
6070 return this;
6071 case Null:
6072 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6073 case AnyNull:
6074 return make( ptr, klass(), _interfaces, offset );
6075 case BotPTR:
6076 case NotNull:
6077 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6078 default: typerr(t);
6079 }
6080 }
6081
6082 case RawPtr:
6083 case MetadataPtr:
6084 case OopPtr:
6085 case AryPtr: // Meet with AryPtr
6086 case InstPtr: // Meet with InstPtr
6087 return TypePtr::BOTTOM;
6088
6089 //
6090 // A-top }
6091 // / | \ } Tops
6092 // B-top A-any C-top }
6093 // | / | \ | } Any-nulls
6094 // B-any | C-any }
6095 // | | |
6096 // B-con A-con C-con } constants; not comparable across classes
6097 // | | |
6098 // B-not | C-not }
6099 // | \ | / | } not-nulls
6100 // B-bot A-not C-bot }
6101 // \ | / } Bottoms
6102 // A-bot }
6103 //
6104
6105 case InstKlassPtr: { // Meet two KlassPtr types
6106 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6107 int off = meet_offset(tkls->offset());
6108 PTR ptr = meet_ptr(tkls->ptr());
6109 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6110
6111 ciKlass* res_klass = nullptr;
6112 bool res_xk = false;
6113 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6114 case UNLOADED:
6115 ShouldNotReachHere();
6116 case SUBTYPE:
6117 case NOT_SUBTYPE:
6118 case LCA:
6119 case QUICK: {
6120 assert(res_xk == (ptr == Constant), "");
6121 const Type* res = make(ptr, res_klass, interfaces, off);
6122 return res;
6123 }
6124 default:
6125 ShouldNotReachHere();
6126 }
6127 } // End of case KlassPtr
6128 case AryKlassPtr: { // All arrays inherit from Object class
6129 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6130 int offset = meet_offset(tp->offset());
6131 PTR ptr = meet_ptr(tp->ptr());
6132 const TypeInterfaces* interfaces = meet_interfaces(tp);
6133 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6134 const TypeInterfaces* this_interfaces = _interfaces;
6135
6136 switch (ptr) {
6137 case TopPTR:
6138 case AnyNull: // Fall 'down' to dual of object klass
6139 // For instances when a subclass meets a superclass we fall
6140 // below the centerline when the superclass is exact. We need to
6141 // do the same here.
6142 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6143 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
6144 } else {
6145 // cannot subclass, so the meet has to fall badly below the centerline
6146 ptr = NotNull;
6147 interfaces = _interfaces->intersection_with(tp->_interfaces);
6148 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6149 }
6150 case Constant:
6151 case NotNull:
6152 case BotPTR: // Fall down to object klass
6153 // LCA is object_klass, but if we subclass from the top we can do better
6154 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6155 // If 'this' (InstPtr) is above the centerline and it is Object class
6156 // then we can subclass in the Java class hierarchy.
6157 // For instances when a subclass meets a superclass we fall
6158 // below the centerline when the superclass is exact. We need
6159 // to do the same here.
6160 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6161 // that is, tp's array type is a subtype of my klass
6162 return TypeAryKlassPtr::make(ptr,
6163 tp->elem(), tp->klass(), offset);
6164 }
6165 }
6166 // The other case cannot happen, since I cannot be a subtype of an array.
6167 // The meet falls down to Object class below centerline.
6168 if( ptr == Constant )
6169 ptr = NotNull;
6170 interfaces = this_interfaces->intersection_with(tp_interfaces);
6171 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6172 default: typerr(t);
6173 }
6174 }
6175
6176 } // End of switch
6177 return this; // Return the double constant
6178 }
6179
6180 //------------------------------xdual------------------------------------------
6181 // Dual: compute field-by-field dual
6182 const Type *TypeInstKlassPtr::xdual() const {
6183 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
6184 }
6185
6186 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) {
6187 static_assert(std::is_base_of<T2, T1>::value, "");
6188 if (!this_one->is_loaded() || !other->is_loaded()) {
6189 return false;
6190 }
6191 if (!this_one->is_instance_type(other)) {
6192 return false;
6193 }
6194
6195 if (!other_exact) {
6196 return false;
6197 }
6198
6199 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6200 return true;
6201 }
6202
6203 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6277 const TypeInterfaces* interfaces = _interfaces;
6278 if (k->is_loaded()) {
6279 ciInstanceKlass* ik = k->as_instance_klass();
6280 bool klass_is_exact = ik->is_final();
6281 if (!klass_is_exact &&
6282 deps != nullptr) {
6283 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6284 if (sub != nullptr) {
6285 if (_interfaces->eq(sub)) {
6286 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6287 k = ik = sub;
6288 klass_is_exact = sub->is_final();
6289 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6290 }
6291 }
6292 }
6293 }
6294 return this;
6295 }
6296
6297
6298 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6299 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6300 }
6301
6302 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6303 if (k->is_obj_array_klass()) {
6304 // Element is an object array. Recursively call ourself.
6305 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6306 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6307 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6308 } else if (k->is_type_array_klass()) {
6309 // Element is an typeArray
6310 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6311 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6312 } else {
6313 ShouldNotReachHere();
6314 return nullptr;
6315 }
6316 }
6317
6318 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6319 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6320 }
6321
6322 //------------------------------eq---------------------------------------------
6323 // Structural equality check for Type representations
6324 bool TypeAryKlassPtr::eq(const Type *t) const {
6325 const TypeAryKlassPtr *p = t->is_aryklassptr();
6326 return
6327 _elem == p->_elem && // Check array
6328 TypeKlassPtr::eq(p); // Check sub-parts
6329 }
6330
6331 //------------------------------hash-------------------------------------------
6332 // Type-specific hashing function.
6333 uint TypeAryKlassPtr::hash(void) const {
6334 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6335 }
6336
6337 //----------------------compute_klass------------------------------------------
6338 // Compute the defining klass for this class
6339 ciKlass* TypeAryPtr::compute_klass() const {
6340 // Compute _klass based on element type.
6341 ciKlass* k_ary = nullptr;
6342 const TypeInstPtr *tinst;
6343 const TypeAryPtr *tary;
6344 const Type* el = elem();
6345 if (el->isa_narrowoop()) {
6346 el = el->make_ptr();
6347 }
6348
6349 // Get element klass
6350 if ((tinst = el->isa_instptr()) != nullptr) {
6351 // Leave k_ary at null.
6352 } else if ((tary = el->isa_aryptr()) != nullptr) {
6353 // Leave k_ary at null.
6354 } else if ((el->base() == Type::Top) ||
6355 (el->base() == Type::Bottom)) {
6356 // element type of Bottom occurs from meet of basic type
6357 // and object; Top occurs when doing join on Bottom.
6358 // Leave k_ary at null.
6359 } else {
6360 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6361 // Compute array klass directly from basic type
6362 k_ary = ciTypeArrayKlass::make(el->basic_type());
6363 }
6364 return k_ary;
6365 }
6366
6367 //------------------------------klass------------------------------------------
6368 // Return the defining klass for this class
6369 ciKlass* TypeAryPtr::klass() const {
6370 if( _klass ) return _klass; // Return cached value, if possible
6371
6372 // Oops, need to compute _klass and cache it
6373 ciKlass* k_ary = compute_klass();
6381 // type TypeAryPtr::OOPS. This Type is shared between all
6382 // active compilations. However, the ciKlass which represents
6383 // this Type is *not* shared between compilations, so caching
6384 // this value would result in fetching a dangling pointer.
6385 //
6386 // Recomputing the underlying ciKlass for each request is
6387 // a bit less efficient than caching, but calls to
6388 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6389 ((TypeAryPtr*)this)->_klass = k_ary;
6390 }
6391 return k_ary;
6392 }
6393
6394 // Is there a single ciKlass* that can represent that type?
6395 ciKlass* TypeAryPtr::exact_klass_helper() const {
6396 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6397 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6398 if (k == nullptr) {
6399 return nullptr;
6400 }
6401 k = ciObjArrayKlass::make(k);
6402 return k;
6403 }
6404
6405 return klass();
6406 }
6407
6408 const Type* TypeAryPtr::base_element_type(int& dims) const {
6409 const Type* elem = this->elem();
6410 dims = 1;
6411 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6412 elem = elem->make_ptr()->is_aryptr()->elem();
6413 dims++;
6414 }
6415 return elem;
6416 }
6417
6418 //------------------------------add_offset-------------------------------------
6419 // Access internals of klass object
6420 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6421 return make(_ptr, elem(), klass(), xadd_offset(offset));
6422 }
6423
6424 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6425 return make(_ptr, elem(), klass(), offset);
6426 }
6427
6428 //------------------------------cast_to_ptr_type-------------------------------
6429 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6430 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6431 if (ptr == _ptr) return this;
6432 return make(ptr, elem(), _klass, _offset);
6433 }
6434
6435 bool TypeAryKlassPtr::must_be_exact() const {
6436 if (_elem == Type::BOTTOM) return false;
6437 if (_elem == Type::TOP ) return false;
6438 const TypeKlassPtr* tk = _elem->isa_klassptr();
6439 if (!tk) return true; // a primitive type, like int
6440 return tk->must_be_exact();
6441 }
6442
6443
6444 //-----------------------------cast_to_exactness-------------------------------
6445 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6446 if (must_be_exact()) return this; // cannot clear xk
6447 ciKlass* k = _klass;
6448 const Type* elem = this->elem();
6449 if (elem->isa_klassptr() && !klass_is_exact) {
6450 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6451 }
6452 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6453 }
6454
6455
6456 //-----------------------------as_instance_type--------------------------------
6457 // Corresponding type for an instance of the given class.
6458 // It will be NotNull, and exact if and only if the klass type is exact.
6459 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6460 ciKlass* k = klass();
6461 bool xk = klass_is_exact();
6462 const Type* el = nullptr;
6463 if (elem()->isa_klassptr()) {
6464 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6465 k = nullptr;
6466 } else {
6467 el = elem();
6468 }
6469 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6470 }
6471
6472
6473 //------------------------------xmeet------------------------------------------
6474 // Compute the MEET of two types, return a new Type object.
6475 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6476 // Perform a fast test for common case; meeting the same types together.
6477 if( this == t ) return this; // Meeting same type-rep?
6478
6479 // Current "this->_base" is Pointer
6480 switch (t->base()) { // switch on original type
6481
6482 case Int: // Mixing ints & oops happens when javac
6483 case Long: // reuses local variables
6484 case HalfFloatTop:
6485 case HalfFloatCon:
6486 case HalfFloatBot:
6487 case FloatTop:
6488 case FloatCon:
6489 case FloatBot:
6490 case DoubleTop:
6491 case DoubleCon:
6492 case DoubleBot:
6493 case NarrowOop:
6494 case NarrowKlass:
6495 case Bottom: // Ye Olde Default
6496 return Type::BOTTOM;
6497 case Top:
6498 return this;
6499
6500 default: // All else is a mistake
6501 typerr(t);
6502
6503 case AnyPtr: { // Meeting to AnyPtrs
6504 // Found an AnyPtr type vs self-KlassPtr type
6505 const TypePtr *tp = t->is_ptr();
6506 int offset = meet_offset(tp->offset());
6507 PTR ptr = meet_ptr(tp->ptr());
6508 switch (tp->ptr()) {
6509 case TopPTR:
6510 return this;
6511 case Null:
6512 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6513 case AnyNull:
6514 return make( ptr, _elem, klass(), offset );
6515 case BotPTR:
6516 case NotNull:
6517 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6518 default: typerr(t);
6519 }
6520 }
6521
6522 case RawPtr:
6523 case MetadataPtr:
6524 case OopPtr:
6525 case AryPtr: // Meet with AryPtr
6526 case InstPtr: // Meet with InstPtr
6527 return TypePtr::BOTTOM;
6528
6529 //
6530 // A-top }
6531 // / | \ } Tops
6532 // B-top A-any C-top }
6533 // | / | \ | } Any-nulls
6534 // B-any | C-any }
6535 // | | |
6536 // B-con A-con C-con } constants; not comparable across classes
6537 // | | |
6538 // B-not | C-not }
6539 // | \ | / | } not-nulls
6540 // B-bot A-not C-bot }
6541 // \ | / } Bottoms
6542 // A-bot }
6543 //
6544
6545 case AryKlassPtr: { // Meet two KlassPtr types
6546 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6547 int off = meet_offset(tap->offset());
6548 const Type* elem = _elem->meet(tap->_elem);
6549
6550 PTR ptr = meet_ptr(tap->ptr());
6551 ciKlass* res_klass = nullptr;
6552 bool res_xk = false;
6553 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6554 assert(res_xk == (ptr == Constant), "");
6555 return make(ptr, elem, res_klass, off);
6556 } // End of case KlassPtr
6557 case InstKlassPtr: {
6558 const TypeInstKlassPtr *tp = t->is_instklassptr();
6559 int offset = meet_offset(tp->offset());
6560 PTR ptr = meet_ptr(tp->ptr());
6561 const TypeInterfaces* interfaces = meet_interfaces(tp);
6562 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6563 const TypeInterfaces* this_interfaces = _interfaces;
6564
6565 switch (ptr) {
6566 case TopPTR:
6567 case AnyNull: // Fall 'down' to dual of object klass
6568 // For instances when a subclass meets a superclass we fall
6569 // below the centerline when the superclass is exact. We need to
6570 // do the same here.
6571 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6572 !tp->klass_is_exact()) {
6573 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6574 } else {
6575 // cannot subclass, so the meet has to fall badly below the centerline
6576 ptr = NotNull;
6577 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6578 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6579 }
6580 case Constant:
6581 case NotNull:
6582 case BotPTR: // Fall down to object klass
6583 // LCA is object_klass, but if we subclass from the top we can do better
6584 if (above_centerline(tp->ptr())) {
6585 // If 'tp' is above the centerline and it is Object class
6586 // then we can subclass in the Java class hierarchy.
6587 // For instances when a subclass meets a superclass we fall
6588 // below the centerline when the superclass is exact. We need
6589 // to do the same here.
6590 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6591 !tp->klass_is_exact()) {
6592 // that is, my array type is a subtype of 'tp' klass
6593 return make(ptr, _elem, _klass, offset);
6594 }
6595 }
6596 // The other case cannot happen, since t cannot be a subtype of an array.
6597 // The meet falls down to Object class below centerline.
6598 if (ptr == Constant)
6599 ptr = NotNull;
6600 interfaces = this_interfaces->intersection_with(tp_interfaces);
6601 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6602 default: typerr(t);
6603 }
6604 }
6605
6606 } // End of switch
6607 return this; // Return the double constant
6608 }
6609
6610 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) {
6611 static_assert(std::is_base_of<T2, T1>::value, "");
6612
6613 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6614 return true;
6615 }
6616
6617 int dummy;
6618 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6619
6620 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6621 return false;
6622 }
6623
6624 if (this_one->is_instance_type(other)) {
6625 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6626 other_exact;
6627 }
6628
6629 assert(this_one->is_array_type(other), "");
6630 const T1* other_ary = this_one->is_array_type(other);
6631 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6632 if (other_top_or_bottom) {
6633 return false;
6634 }
6635
6636 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6637 const TypePtr* this_elem = this_one->elem()->make_ptr();
6638 if (this_elem != nullptr && other_elem != nullptr) {
6639 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6640 }
6641 if (this_elem == nullptr && other_elem == nullptr) {
6642 return this_one->klass()->is_subtype_of(other->klass());
6643 }
6644 return false;
6645 }
6646
6647 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6648 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6649 }
6650
6651 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6652 static_assert(std::is_base_of<T2, T1>::value, "");
6653
6654 int dummy;
6655 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6656
6657 if (!this_one->is_array_type(other) ||
6658 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6711 }
6712
6713 const TypePtr* this_elem = this_one->elem()->make_ptr();
6714 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6715 if (other_elem != nullptr && this_elem != nullptr) {
6716 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6717 }
6718 if (other_elem == nullptr && this_elem == nullptr) {
6719 return this_one->klass()->is_subtype_of(other->klass());
6720 }
6721 return false;
6722 }
6723
6724 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6725 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6726 }
6727
6728 //------------------------------xdual------------------------------------------
6729 // Dual: compute field-by-field dual
6730 const Type *TypeAryKlassPtr::xdual() const {
6731 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6732 }
6733
6734 // Is there a single ciKlass* that can represent that type?
6735 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6736 if (elem()->isa_klassptr()) {
6737 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6738 if (k == nullptr) {
6739 return nullptr;
6740 }
6741 k = ciObjArrayKlass::make(k);
6742 return k;
6743 }
6744
6745 return klass();
6746 }
6747
6748 ciKlass* TypeAryKlassPtr::klass() const {
6749 if (_klass != nullptr) {
6750 return _klass;
6751 }
6752 ciKlass* k = nullptr;
6753 if (elem()->isa_klassptr()) {
6754 // leave null
6755 } else if ((elem()->base() == Type::Top) ||
6756 (elem()->base() == Type::Bottom)) {
6757 } else {
6758 k = ciTypeArrayKlass::make(elem()->basic_type());
6759 ((TypeAryKlassPtr*)this)->_klass = k;
6760 }
6761 return k;
6768 switch( _ptr ) {
6769 case Constant:
6770 st->print("precise ");
6771 case NotNull:
6772 {
6773 st->print("[");
6774 _elem->dump2(d, depth, st);
6775 _interfaces->dump(st);
6776 st->print(": ");
6777 }
6778 case BotPTR:
6779 if( !WizardMode && !Verbose && _ptr != Constant ) break;
6780 case TopPTR:
6781 case AnyNull:
6782 st->print(":%s", ptr_msg[_ptr]);
6783 if( _ptr == Constant ) st->print(":exact");
6784 break;
6785 default:
6786 break;
6787 }
6788
6789 if( _offset ) { // Dump offset, if any
6790 if( _offset == OffsetBot ) { st->print("+any"); }
6791 else if( _offset == OffsetTop ) { st->print("+unknown"); }
6792 else { st->print("+%d", _offset); }
6793 }
6794
6795 st->print(" *");
6796 }
6797 #endif
6798
6799 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6800 const Type* elem = this->elem();
6801 dims = 1;
6802 while (elem->isa_aryklassptr()) {
6803 elem = elem->is_aryklassptr()->elem();
6804 dims++;
6805 }
6806 return elem;
6807 }
6808
6809 //=============================================================================
6810 // Convenience common pre-built types.
6811
6812 //------------------------------make-------------------------------------------
6813 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6814 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6815 }
6816
6817 //------------------------------make-------------------------------------------
6818 const TypeFunc *TypeFunc::make(ciMethod* method) {
6819 Compile* C = Compile::current();
6820 const TypeFunc* tf = C->last_tf(method); // check cache
6821 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6822 const TypeTuple *domain;
6823 if (method->is_static()) {
6824 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6825 } else {
6826 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6827 }
6828 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6829 tf = TypeFunc::make(domain, range);
6830 C->set_last_tf(method, tf); // fill cache
6831 return tf;
6832 }
6833
6834 //------------------------------meet-------------------------------------------
6835 // Compute the MEET of two types. It returns a new Type object.
6836 const Type *TypeFunc::xmeet( const Type *t ) const {
6837 // Perform a fast test for common case; meeting the same types together.
6838 if( this == t ) return this; // Meeting same type-rep?
6839
6840 // Current "this->_base" is Func
6841 switch (t->base()) { // switch on original type
6842
6843 case Bottom: // Ye Olde Default
6844 return t;
6845
6846 default: // All else is a mistake
6847 typerr(t);
6848
6849 case Top:
6850 break;
6851 }
6852 return this; // Return the double constant
6853 }
6854
6855 //------------------------------xdual------------------------------------------
6856 // Dual: compute field-by-field dual
6857 const Type *TypeFunc::xdual() const {
6858 return this;
6859 }
6860
6861 //------------------------------eq---------------------------------------------
6862 // Structural equality check for Type representations
6863 bool TypeFunc::eq( const Type *t ) const {
6864 const TypeFunc *a = (const TypeFunc*)t;
6865 return _domain == a->_domain &&
6866 _range == a->_range;
6867 }
6868
6869 //------------------------------hash-------------------------------------------
6870 // Type-specific hashing function.
6871 uint TypeFunc::hash(void) const {
6872 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6873 }
6874
6875 //------------------------------dump2------------------------------------------
6876 // Dump Function Type
6877 #ifndef PRODUCT
6878 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6879 if( _range->cnt() <= Parms )
6880 st->print("void");
6881 else {
6882 uint i;
6883 for (i = Parms; i < _range->cnt()-1; i++) {
6884 _range->field_at(i)->dump2(d,depth,st);
6885 st->print("/");
6886 }
6887 _range->field_at(i)->dump2(d,depth,st);
6888 }
6889 st->print(" ");
6890 st->print("( ");
6891 if( !depth || d[this] ) { // Check for recursive dump
6892 st->print("...)");
6893 return;
6894 }
6895 d.Insert((void*)this,(void*)this); // Stop recursion
6896 if (Parms < _domain->cnt())
6897 _domain->field_at(Parms)->dump2(d,depth-1,st);
6898 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6899 st->print(", ");
6900 _domain->field_at(i)->dump2(d,depth-1,st);
6901 }
6902 st->print(" )");
6903 }
6904 #endif
6905
6906 //------------------------------singleton--------------------------------------
6907 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6908 // constants (Ldi nodes). Singletons are integer, float or double constants
6909 // or a single symbol.
6910 bool TypeFunc::singleton(void) const {
6911 return false; // Never a singleton
6912 }
6913
6914 bool TypeFunc::empty(void) const {
6915 return false; // Never empty
6916 }
6917
6918
6919 BasicType TypeFunc::return_type() const{
6920 if (range()->cnt() == TypeFunc::Parms) {
6921 return T_VOID;
6922 }
6923 return range()->field_at(TypeFunc::Parms)->basic_type();
6924 }
|
5 * This code is free software; you can redistribute it and/or modify it
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 "ci/ciFlatArrayKlass.hpp"
26 #include "ci/ciField.hpp"
27 #include "ci/ciInlineKlass.hpp"
28 #include "ci/ciMethodData.hpp"
29 #include "ci/ciTypeFlow.hpp"
30 #include "classfile/javaClasses.hpp"
31 #include "classfile/symbolTable.hpp"
32 #include "classfile/vmSymbols.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/callnode.hpp"
42 #include "opto/arraycopynode.hpp"
43 #include "opto/matcher.hpp"
44 #include "opto/node.hpp"
45 #include "opto/opcodes.hpp"
46 #include "opto/runtime.hpp"
47 #include "opto/type.hpp"
48 #include "utilities/checkedCast.hpp"
49 #include "utilities/globalDefinitions.hpp"
50 #include "utilities/powerOfTwo.hpp"
51 #include "utilities/stringUtils.hpp"
52 #include "runtime/stubRoutines.hpp"
53
54 // Portions of code courtesy of Clifford Click
55
56 // Optimization - Graph Style
57
58 // Dictionary of types shared among compilations.
59 Dict* Type::_shared_type_dict = nullptr;
60 const Type::Offset Type::Offset::top(Type::OffsetTop);
61 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
62
63 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
64 // Either is 'TOP' offset? Return the other offset!
65 if (_offset == OffsetTop) return other;
66 if (other._offset == OffsetTop) return *this;
67 // If either is different, return 'BOTTOM' offset
68 if (_offset != other._offset) return bottom;
69 return Offset(_offset);
70 }
71
72 const Type::Offset Type::Offset::dual() const {
73 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
74 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
75 return Offset(_offset); // Map everything else into self
76 }
77
78 const Type::Offset Type::Offset::add(intptr_t offset) const {
79 // Adding to 'TOP' offset? Return 'TOP'!
80 if (_offset == OffsetTop || offset == OffsetTop) return top;
81 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
82 if (_offset == OffsetBot || offset == OffsetBot) return bottom;
83 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
84 offset += (intptr_t)_offset;
85 if (offset != (int)offset || offset == OffsetTop) return bottom;
86
87 // assert( _offset >= 0 && _offset+offset >= 0, "" );
88 // It is possible to construct a negative offset during PhaseCCP
89
90 return Offset((int)offset); // Sum valid offsets
91 }
92
93 void Type::Offset::dump2(outputStream *st) const {
94 if (_offset == 0) {
95 return;
96 } else if (_offset == OffsetTop) {
97 st->print("+top");
98 }
99 else if (_offset == OffsetBot) {
100 st->print("+bot");
101 } else if (_offset) {
102 st->print("+%d", _offset);
103 }
104 }
105
106 // Array which maps compiler types to Basic Types
107 const Type::TypeInfo Type::_type_info[Type::lastype] = {
108 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
109 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
110 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
111 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
112 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
113 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
114 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
115 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
116 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
117 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
118 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
119
120 #if defined(PPC64)
121 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
122 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
123 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
124 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
263 case ciTypeFlow::StateVector::T_NULL:
264 assert(type == ciTypeFlow::StateVector::null_type(), "");
265 return TypePtr::NULL_PTR;
266
267 case ciTypeFlow::StateVector::T_LONG2:
268 // The ciTypeFlow pass pushes a long, then the half.
269 // We do the same.
270 assert(type == ciTypeFlow::StateVector::long2_type(), "");
271 return TypeInt::TOP;
272
273 case ciTypeFlow::StateVector::T_DOUBLE2:
274 // The ciTypeFlow pass pushes double, then the half.
275 // Our convention is the same.
276 assert(type == ciTypeFlow::StateVector::double2_type(), "");
277 return Type::TOP;
278
279 case T_ADDRESS:
280 assert(type->is_return_address(), "");
281 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
282
283 case T_OBJECT:
284 return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
285
286 default:
287 // make sure we did not mix up the cases:
288 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
289 assert(type != ciTypeFlow::StateVector::top_type(), "");
290 assert(type != ciTypeFlow::StateVector::null_type(), "");
291 assert(type != ciTypeFlow::StateVector::long2_type(), "");
292 assert(type != ciTypeFlow::StateVector::double2_type(), "");
293 assert(!type->is_return_address(), "");
294
295 return Type::get_const_type(type);
296 }
297 }
298
299
300 //-----------------------make_from_constant------------------------------------
301 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
302 int stable_dimension, bool is_narrow_oop,
303 bool is_autobox_cache) {
304 switch (constant.basic_type()) {
305 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
586 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
587 ffalse[0] = Type::CONTROL;
588 ffalse[1] = Type::TOP;
589 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
590
591 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
592 fneither[0] = Type::TOP;
593 fneither[1] = Type::TOP;
594 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
595
596 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
597 ftrue[0] = Type::TOP;
598 ftrue[1] = Type::CONTROL;
599 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
600
601 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
602 floop[0] = Type::CONTROL;
603 floop[1] = TypeInt::INT;
604 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
605
606 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
607 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
608 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
609
610 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
611 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
612
613 const Type **fmembar = TypeTuple::fields(0);
614 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
615
616 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
617 fsc[0] = TypeInt::CC;
618 fsc[1] = Type::MEMORY;
619 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
620
621 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
622 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
623 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
624 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
625 false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
626 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
627 false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
628 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
629
630 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
631
632 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
633 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
634
635 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
636
637 mreg2type[Op_Node] = Type::BOTTOM;
638 mreg2type[Op_Set ] = nullptr;
639 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
640 mreg2type[Op_RegI] = TypeInt::INT;
641 mreg2type[Op_RegP] = TypePtr::BOTTOM;
642 mreg2type[Op_RegF] = Type::FLOAT;
643 mreg2type[Op_RegD] = Type::DOUBLE;
644 mreg2type[Op_RegL] = TypeLong::LONG;
645 mreg2type[Op_RegFlags] = TypeInt::CC;
646
647 GrowableArray<ciInstanceKlass*> array_interfaces;
648 array_interfaces.push(current->env()->Cloneable_klass());
649 array_interfaces.push(current->env()->Serializable_klass());
650 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
651 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
652
653 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS), nullptr, false, Offset::bottom);
654 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
655
656 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
657
658 #ifdef _LP64
659 if (UseCompressedOops) {
660 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
661 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
662 } else
663 #endif
664 {
665 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
666 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
667 }
668 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom);
669 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom);
670 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom);
671 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Offset::bottom);
672 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom);
673 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom);
674 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom);
675 TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true), nullptr, false, Offset::bottom);
676
677 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
678 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
679 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
680 TypeAryPtr::_array_body_type[T_FLAT_ELEMENT] = TypeAryPtr::OOPS;
681 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
682 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
683 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
684 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
685 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
686 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
687 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
688 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
689 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
690
691 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
692 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
693
694 const Type **fi2c = TypeTuple::fields(2);
695 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
696 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
697 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
698
699 const Type **intpair = TypeTuple::fields(2);
700 intpair[0] = TypeInt::INT;
701 intpair[1] = TypeInt::INT;
702 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
703
704 const Type **longpair = TypeTuple::fields(2);
705 longpair[0] = TypeLong::LONG;
706 longpair[1] = TypeLong::LONG;
707 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
708
709 const Type **intccpair = TypeTuple::fields(2);
710 intccpair[0] = TypeInt::INT;
711 intccpair[1] = TypeInt::CC;
712 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
713
714 const Type **longccpair = TypeTuple::fields(2);
715 longccpair[0] = TypeLong::LONG;
716 longccpair[1] = TypeInt::CC;
717 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
718
719 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
720 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
721 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
722 _const_basic_type[T_CHAR] = TypeInt::CHAR;
723 _const_basic_type[T_BYTE] = TypeInt::BYTE;
724 _const_basic_type[T_SHORT] = TypeInt::SHORT;
725 _const_basic_type[T_INT] = TypeInt::INT;
726 _const_basic_type[T_LONG] = TypeLong::LONG;
727 _const_basic_type[T_FLOAT] = Type::FLOAT;
728 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
729 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
730 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
731 _const_basic_type[T_FLAT_ELEMENT] = TypeInstPtr::BOTTOM;
732 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
733 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
734 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
735
736 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
737 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
738 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
739 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
740 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
741 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
742 _zero_type[T_INT] = TypeInt::ZERO;
743 _zero_type[T_LONG] = TypeLong::ZERO;
744 _zero_type[T_FLOAT] = TypeF::ZERO;
745 _zero_type[T_DOUBLE] = TypeD::ZERO;
746 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
747 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
748 _zero_type[T_FLAT_ELEMENT] = TypePtr::NULL_PTR;
749 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
750 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
751
752 // get_zero_type() should not happen for T_CONFLICT
753 _zero_type[T_CONFLICT]= nullptr;
754
755 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
756 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
757
758 if (Matcher::supports_scalable_vector()) {
759 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
760 }
761
762 // Vector predefined types, it needs initialized _const_basic_type[].
763 if (Matcher::vector_size_supported(T_BYTE, 4)) {
764 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
765 }
766 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
767 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
768 }
1003 ~VerifyMeet() {
1004 assert(_C->_type_verify->_depth != 0, "");
1005 _C->_type_verify->_depth--;
1006 if (_C->_type_verify->_depth == 0) {
1007 _C->_type_verify->_cache.trunc_to(0);
1008 }
1009 }
1010
1011 const Type* meet(const Type* t1, const Type* t2) const {
1012 return _C->_type_verify->meet(t1, t2);
1013 }
1014
1015 void add(const Type* t1, const Type* t2, const Type* res) const {
1016 _C->_type_verify->add(t1, t2, res);
1017 }
1018 };
1019
1020 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1021 Compile* C = Compile::current();
1022 const Type* mt2 = verify.meet(t, this);
1023
1024 // Verify that:
1025 // this meet t == t meet this
1026 if (mt != mt2) {
1027 tty->print_cr("=== Meet Not Commutative ===");
1028 tty->print("t = "); t->dump(); tty->cr();
1029 tty->print("this = "); dump(); tty->cr();
1030 tty->print("t meet this = "); mt2->dump(); tty->cr();
1031 tty->print("this meet t = "); mt->dump(); tty->cr();
1032 fatal("meet not commutative");
1033 }
1034 const Type* dual_join = mt->_dual;
1035 const Type* t2t = verify.meet(dual_join,t->_dual);
1036 const Type* t2this = verify.meet(dual_join,this->_dual);
1037
1038 // Interface meet Oop is Not Symmetric:
1039 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1040 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1041
1042 // Verify that:
1043 // 1) mt_dual meet t_dual == t_dual
1044 // which corresponds to
1045 // !(t meet this) meet !t ==
1046 // (!t join !this) meet !t == !t
1047 // 2) mt_dual meet this_dual == this_dual
1048 // which corresponds to
1049 // !(t meet this) meet !this ==
1050 // (!t join !this) meet !this == !this
1051 if (t2t != t->_dual || t2this != this->_dual) {
1052 tty->print_cr("=== Meet Not Symmetric ===");
1053 tty->print("t = "); t->dump(); tty->cr();
1054 tty->print("this= "); dump(); tty->cr();
1055 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
1056
1057 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
1058 tty->print("this_dual= "); _dual->dump(); tty->cr();
1059 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
1060
1061 // 1)
1062 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1063 // 2)
1064 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1065
1066 fatal("meet not symmetric");
1067 }
1068 }
1069 #endif
1070
1071 //------------------------------meet-------------------------------------------
1072 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1073 // commutative and the lattice is symmetric.
1074 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1075 if (isa_narrowoop() && t->isa_narrowoop()) {
1076 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1077 return result->make_narrowoop();
1078 }
1079 if (isa_narrowklass() && t->isa_narrowklass()) {
1080 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1081 return result->make_narrowklass();
1082 }
1083
1084 #ifdef ASSERT
1085 Compile* C = Compile::current();
1086 VerifyMeet verify(C);
1087 #endif
1088
1089 const Type *this_t = maybe_remove_speculative(include_speculative);
1090 t = t->maybe_remove_speculative(include_speculative);
1091
1092 const Type *mt = this_t->xmeet(t);
1093 #ifdef ASSERT
1094 verify.add(this_t, t, mt);
1095 if (isa_narrowoop() || t->isa_narrowoop()) {
1096 return mt;
1097 }
1098 if (isa_narrowklass() || t->isa_narrowklass()) {
1099 return mt;
1100 }
1101 // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1102 if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1103 (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1104 this_t->check_symmetrical(t, mt, verify);
1105 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1106 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1107 #endif
1108 return mt;
1109 }
1110
1111 //------------------------------xmeet------------------------------------------
1112 // Compute the MEET of two types. It returns a new Type object.
1113 const Type *Type::xmeet( const Type *t ) const {
1114 // Perform a fast test for common case; meeting the same types together.
1115 if( this == t ) return this; // Meeting same type-rep?
1116
1117 // Meeting TOP with anything?
1118 if( _base == Top ) return t;
1119
1120 // Meeting BOTTOM with anything?
1121 if( _base == Bottom ) return BOTTOM;
1122
1123 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2371
2372 bool TypeLong::empty(void) const {
2373 return _lo > _hi;
2374 }
2375
2376 //=============================================================================
2377 // Convenience common pre-built types.
2378 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2379 const TypeTuple *TypeTuple::IFFALSE;
2380 const TypeTuple *TypeTuple::IFTRUE;
2381 const TypeTuple *TypeTuple::IFNEITHER;
2382 const TypeTuple *TypeTuple::LOOPBODY;
2383 const TypeTuple *TypeTuple::MEMBAR;
2384 const TypeTuple *TypeTuple::STORECONDITIONAL;
2385 const TypeTuple *TypeTuple::START_I2C;
2386 const TypeTuple *TypeTuple::INT_PAIR;
2387 const TypeTuple *TypeTuple::LONG_PAIR;
2388 const TypeTuple *TypeTuple::INT_CC_PAIR;
2389 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2390
2391 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2392 for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2393 ciField* field = vk->declared_nonstatic_field_at(i);
2394 if (field->is_flat()) {
2395 collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2396 if (!field->is_null_free()) {
2397 // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2398 // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2399 field_array[pos++] = Type::get_const_basic_type(T_INT);
2400 }
2401 } else {
2402 BasicType bt = field->type()->basic_type();
2403 const Type* ft = Type::get_const_type(field->type());
2404 field_array[pos++] = ft;
2405 if (type2size[bt] == 2) {
2406 field_array[pos++] = Type::HALF;
2407 }
2408 }
2409 }
2410 }
2411
2412 //------------------------------make-------------------------------------------
2413 // Make a TypeTuple from the range of a method signature
2414 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2415 ciType* return_type = sig->return_type();
2416 uint arg_cnt = return_type->size();
2417 if (ret_vt_fields) {
2418 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2419 // InlineTypeNode::IsInit field used for null checking
2420 arg_cnt++;
2421 }
2422 const Type **field_array = fields(arg_cnt);
2423 switch (return_type->basic_type()) {
2424 case T_LONG:
2425 field_array[TypeFunc::Parms] = TypeLong::LONG;
2426 field_array[TypeFunc::Parms+1] = Type::HALF;
2427 break;
2428 case T_DOUBLE:
2429 field_array[TypeFunc::Parms] = Type::DOUBLE;
2430 field_array[TypeFunc::Parms+1] = Type::HALF;
2431 break;
2432 case T_OBJECT:
2433 if (return_type->is_inlinetype() && ret_vt_fields) {
2434 uint pos = TypeFunc::Parms;
2435 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2436 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2437 // InlineTypeNode::IsInit field used for null checking
2438 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2439 assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2440 break;
2441 } else {
2442 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2443 }
2444 break;
2445 case T_ARRAY:
2446 case T_BOOLEAN:
2447 case T_CHAR:
2448 case T_FLOAT:
2449 case T_BYTE:
2450 case T_SHORT:
2451 case T_INT:
2452 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2453 break;
2454 case T_VOID:
2455 break;
2456 default:
2457 ShouldNotReachHere();
2458 }
2459 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2460 }
2461
2462 // Make a TypeTuple from the domain of a method signature
2463 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2464 ciSignature* sig = method->signature();
2465 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2466 if (vt_fields_as_args) {
2467 arg_cnt = 0;
2468 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2469 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2470 arg_cnt += type2size[(*sig_cc)._bt];
2471 }
2472 }
2473
2474 uint pos = TypeFunc::Parms;
2475 const Type** field_array = fields(arg_cnt);
2476 if (!method->is_static()) {
2477 ciInstanceKlass* recv = method->holder();
2478 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2479 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2480 } else {
2481 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2482 }
2483 }
2484
2485 int i = 0;
2486 while (pos < TypeFunc::Parms + arg_cnt) {
2487 ciType* type = sig->type_at(i);
2488 BasicType bt = type->basic_type();
2489
2490 switch (bt) {
2491 case T_LONG:
2492 field_array[pos++] = TypeLong::LONG;
2493 field_array[pos++] = Type::HALF;
2494 break;
2495 case T_DOUBLE:
2496 field_array[pos++] = Type::DOUBLE;
2497 field_array[pos++] = Type::HALF;
2498 break;
2499 case T_OBJECT:
2500 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2501 // InlineTypeNode::IsInit field used for null checking
2502 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2503 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2504 } else {
2505 field_array[pos++] = get_const_type(type, interface_handling);
2506 }
2507 break;
2508 case T_ARRAY:
2509 case T_FLOAT:
2510 case T_INT:
2511 field_array[pos++] = get_const_type(type, interface_handling);
2512 break;
2513 case T_BOOLEAN:
2514 case T_CHAR:
2515 case T_BYTE:
2516 case T_SHORT:
2517 field_array[pos++] = TypeInt::INT;
2518 break;
2519 default:
2520 ShouldNotReachHere();
2521 }
2522 i++;
2523 }
2524 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2525
2526 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2527 }
2528
2529 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2530 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2531 }
2532
2533 //------------------------------fields-----------------------------------------
2534 // Subroutine call type with space allocated for argument types
2535 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2536 const Type **TypeTuple::fields( uint arg_cnt ) {
2537 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2538 flds[TypeFunc::Control ] = Type::CONTROL;
2539 flds[TypeFunc::I_O ] = Type::ABIO;
2540 flds[TypeFunc::Memory ] = Type::MEMORY;
2541 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2542 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2543
2544 return flds;
2639 if (_fields[i]->empty()) return true;
2640 }
2641 return false;
2642 }
2643
2644 //=============================================================================
2645 // Convenience common pre-built types.
2646
2647 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2648 // Certain normalizations keep us sane when comparing types.
2649 // We do not want arrayOop variables to differ only by the wideness
2650 // of their index types. Pick minimum wideness, since that is the
2651 // forced wideness of small ranges anyway.
2652 if (size->_widen != Type::WidenMin)
2653 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2654 else
2655 return size;
2656 }
2657
2658 //------------------------------make-------------------------------------------
2659 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2660 bool flat, bool not_flat, bool not_null_free) {
2661 if (UseCompressedOops && elem->isa_oopptr()) {
2662 elem = elem->make_narrowoop();
2663 }
2664 size = normalize_array_size(size);
2665 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2666 }
2667
2668 //------------------------------meet-------------------------------------------
2669 // Compute the MEET of two types. It returns a new Type object.
2670 const Type *TypeAry::xmeet( const Type *t ) const {
2671 // Perform a fast test for common case; meeting the same types together.
2672 if( this == t ) return this; // Meeting same type-rep?
2673
2674 // Current "this->_base" is Ary
2675 switch (t->base()) { // switch on original type
2676
2677 case Bottom: // Ye Olde Default
2678 return t;
2679
2680 default: // All else is a mistake
2681 typerr(t);
2682
2683 case Array: { // Meeting 2 arrays?
2684 const TypeAry *a = t->is_ary();
2685 return TypeAry::make(_elem->meet_speculative(a->_elem),
2686 _size->xmeet(a->_size)->is_int(),
2687 _stable && a->_stable,
2688 _flat && a->_flat,
2689 _not_flat && a->_not_flat,
2690 _not_null_free && a->_not_null_free);
2691 }
2692 case Top:
2693 break;
2694 }
2695 return this; // Return the double constant
2696 }
2697
2698 //------------------------------xdual------------------------------------------
2699 // Dual: compute field-by-field dual
2700 const Type *TypeAry::xdual() const {
2701 const TypeInt* size_dual = _size->dual()->is_int();
2702 size_dual = normalize_array_size(size_dual);
2703 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2704 }
2705
2706 //------------------------------eq---------------------------------------------
2707 // Structural equality check for Type representations
2708 bool TypeAry::eq( const Type *t ) const {
2709 const TypeAry *a = (const TypeAry*)t;
2710 return _elem == a->_elem &&
2711 _stable == a->_stable &&
2712 _size == a->_size &&
2713 _flat == a->_flat &&
2714 _not_flat == a->_not_flat &&
2715 _not_null_free == a->_not_null_free;
2716
2717 }
2718
2719 //------------------------------hash-------------------------------------------
2720 // Type-specific hashing function.
2721 uint TypeAry::hash(void) const {
2722 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2723 (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0);
2724 }
2725
2726 /**
2727 * Return same type without a speculative part in the element
2728 */
2729 const TypeAry* TypeAry::remove_speculative() const {
2730 return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2731 }
2732
2733 /**
2734 * Return same type with cleaned up speculative part of element
2735 */
2736 const Type* TypeAry::cleanup_speculative() const {
2737 return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2738 }
2739
2740 /**
2741 * Return same type but with a different inline depth (used for speculation)
2742 *
2743 * @param depth depth to meet with
2744 */
2745 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2746 if (!UseInlineDepthForSpeculativeTypes) {
2747 return this;
2748 }
2749 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2750 }
2751
2752 //------------------------------dump2------------------------------------------
2753 #ifndef PRODUCT
2754 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2755 if (_stable) st->print("stable:");
2756 if (_flat) st->print("flat:");
2757 if (Verbose) {
2758 if (_not_flat) st->print("not flat:");
2759 if (_not_null_free) st->print("not null free:");
2760 }
2761 _elem->dump2(d, depth, st);
2762 st->print("[");
2763 _size->dump2(d, depth, st);
2764 st->print("]");
2765 }
2766 #endif
2767
2768 //------------------------------singleton--------------------------------------
2769 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2770 // constants (Ldi nodes). Singletons are integer, float or double constants
2771 // or a single symbol.
2772 bool TypeAry::singleton(void) const {
2773 return false; // Never a singleton
2774 }
2775
2776 bool TypeAry::empty(void) const {
2777 return _elem->empty() || _size->empty();
2778 }
2779
2780 //--------------------------ary_must_be_exact----------------------------------
2781 bool TypeAry::ary_must_be_exact() const {
2782 // This logic looks at the element type of an array, and returns true
2783 // if the element type is either a primitive or a final instance class.
2784 // In such cases, an array built on this ary must have no subclasses.
2785 if (_elem == BOTTOM) return false; // general array not exact
2786 if (_elem == TOP ) return false; // inverted general array not exact
2787 const TypeOopPtr* toop = nullptr;
2788 if (UseCompressedOops && _elem->isa_narrowoop()) {
2789 toop = _elem->make_ptr()->isa_oopptr();
2790 } else {
2791 toop = _elem->isa_oopptr();
2792 }
2793 if (!toop) return true; // a primitive type, like int
2794 if (!toop->is_loaded()) return false; // unloaded class
2795 const TypeInstPtr* tinst;
2796 if (_elem->isa_narrowoop())
2797 tinst = _elem->make_ptr()->isa_instptr();
2798 else
2799 tinst = _elem->isa_instptr();
2800 if (tinst) {
2801 if (tinst->instance_klass()->is_final()) {
2802 // Even though MyValue is final, [LMyValue is only exact if the array
2803 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2804 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2805 // If so, we should add '&& !_not_null_free'
2806 if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2807 return false;
2808 }
2809 return true;
2810 }
2811 return false;
2812 }
2813 const TypeAryPtr* tap;
2814 if (_elem->isa_narrowoop())
2815 tap = _elem->make_ptr()->isa_aryptr();
2816 else
2817 tap = _elem->isa_aryptr();
2818 if (tap)
2819 return tap->ary()->ary_must_be_exact();
2820 return false;
2821 }
2822
2823 //==============================TypeVect=======================================
2824 // Convenience common pre-built types.
2825 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2826 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2827 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2828 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2829 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2830 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2831 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2832
2967
2968 //=============================================================================
2969 // Convenience common pre-built types.
2970 const TypePtr *TypePtr::NULL_PTR;
2971 const TypePtr *TypePtr::NOTNULL;
2972 const TypePtr *TypePtr::BOTTOM;
2973
2974 //------------------------------meet-------------------------------------------
2975 // Meet over the PTR enum
2976 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2977 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2978 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2979 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2980 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2981 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2982 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2983 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2984 };
2985
2986 //------------------------------make-------------------------------------------
2987 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2988 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2989 }
2990
2991 //------------------------------cast_to_ptr_type-------------------------------
2992 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2993 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2994 if( ptr == _ptr ) return this;
2995 return make(_base, ptr, _offset, _speculative, _inline_depth);
2996 }
2997
2998 //------------------------------get_con----------------------------------------
2999 intptr_t TypePtr::get_con() const {
3000 assert( _ptr == Null, "" );
3001 return offset();
3002 }
3003
3004 //------------------------------meet-------------------------------------------
3005 // Compute the MEET of two types. It returns a new Type object.
3006 const Type *TypePtr::xmeet(const Type *t) const {
3007 const Type* res = xmeet_helper(t);
3008 if (res->isa_ptr() == nullptr) {
3009 return res;
3010 }
3011
3012 const TypePtr* res_ptr = res->is_ptr();
3013 if (res_ptr->speculative() != nullptr) {
3014 // type->speculative() is null means that speculation is no better
3015 // than type, i.e. type->speculative() == type. So there are 2
3016 // ways to represent the fact that we have no useful speculative
3017 // data and we should use a single one to be able to test for
3018 // equality between types. Check whether type->speculative() ==
3019 // type and set speculative to null if it is the case.
3020 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
3021 return res_ptr->remove_speculative();
3055 int depth = meet_inline_depth(tp->inline_depth());
3056 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
3057 }
3058 case RawPtr: // For these, flip the call around to cut down
3059 case OopPtr:
3060 case InstPtr: // on the cases I have to handle.
3061 case AryPtr:
3062 case MetadataPtr:
3063 case KlassPtr:
3064 case InstKlassPtr:
3065 case AryKlassPtr:
3066 return t->xmeet(this); // Call in reverse direction
3067 default: // All else is a mistake
3068 typerr(t);
3069
3070 }
3071 return this;
3072 }
3073
3074 //------------------------------meet_offset------------------------------------
3075 Type::Offset TypePtr::meet_offset(int offset) const {
3076 return _offset.meet(Offset(offset));
3077 }
3078
3079 //------------------------------dual_offset------------------------------------
3080 Type::Offset TypePtr::dual_offset() const {
3081 return _offset.dual();
3082 }
3083
3084 //------------------------------xdual------------------------------------------
3085 // Dual: compute field-by-field dual
3086 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
3087 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
3088 };
3089 const Type *TypePtr::xdual() const {
3090 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
3091 }
3092
3093 //------------------------------xadd_offset------------------------------------
3094 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
3095 return _offset.add(offset);
3096 }
3097
3098 //------------------------------add_offset-------------------------------------
3099 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
3100 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
3101 }
3102
3103 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
3104 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
3105 }
3106
3107 //------------------------------eq---------------------------------------------
3108 // Structural equality check for Type representations
3109 bool TypePtr::eq( const Type *t ) const {
3110 const TypePtr *a = (const TypePtr*)t;
3111 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
3112 }
3113
3114 //------------------------------hash-------------------------------------------
3115 // Type-specific hashing function.
3116 uint TypePtr::hash(void) const {
3117 return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
3118 }
3119
3120 /**
3121 * Return same type without a speculative part
3122 */
3123 const TypePtr* TypePtr::remove_speculative() const {
3124 if (_speculative == nullptr) {
3125 return this;
3126 }
3127 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3128 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
3129 }
3130
3131 /**
3132 * Return same type but drop speculative part if we know we won't use
3133 * it
3134 */
3135 const Type* TypePtr::cleanup_speculative() const {
3136 if (speculative() == nullptr) {
3137 return this;
3363 }
3364 // We already know the speculative type is always null
3365 if (speculative_always_null()) {
3366 return false;
3367 }
3368 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3369 return false;
3370 }
3371 return true;
3372 }
3373
3374 //------------------------------dump2------------------------------------------
3375 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3376 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3377 };
3378
3379 #ifndef PRODUCT
3380 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3381 if( _ptr == Null ) st->print("null");
3382 else st->print("%s *", ptr_msg[_ptr]);
3383 _offset.dump2(st);
3384 dump_inline_depth(st);
3385 dump_speculative(st);
3386 }
3387
3388 /**
3389 *dump the speculative part of the type
3390 */
3391 void TypePtr::dump_speculative(outputStream *st) const {
3392 if (_speculative != nullptr) {
3393 st->print(" (speculative=");
3394 _speculative->dump_on(st);
3395 st->print(")");
3396 }
3397 }
3398
3399 /**
3400 *dump the inline depth of the type
3401 */
3402 void TypePtr::dump_inline_depth(outputStream *st) const {
3403 if (_inline_depth != InlineDepthBottom) {
3404 if (_inline_depth == InlineDepthTop) {
3405 st->print(" (inline_depth=InlineDepthTop)");
3406 } else {
3407 st->print(" (inline_depth=%d)", _inline_depth);
3408 }
3409 }
3410 }
3411 #endif
3412
3413 //------------------------------singleton--------------------------------------
3414 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3415 // constants
3416 bool TypePtr::singleton(void) const {
3417 // TopPTR, Null, AnyNull, Constant are all singletons
3418 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3419 }
3420
3421 bool TypePtr::empty(void) const {
3422 return (_offset == Offset::top) || above_centerline(_ptr);
3423 }
3424
3425 //=============================================================================
3426 // Convenience common pre-built types.
3427 const TypeRawPtr *TypeRawPtr::BOTTOM;
3428 const TypeRawPtr *TypeRawPtr::NOTNULL;
3429
3430 //------------------------------make-------------------------------------------
3431 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3432 assert( ptr != Constant, "what is the constant?" );
3433 assert( ptr != Null, "Use TypePtr for null" );
3434 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3435 }
3436
3437 const TypeRawPtr *TypeRawPtr::make(address bits) {
3438 assert(bits != nullptr, "Use TypePtr for null");
3439 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3440 }
3441
3442 //------------------------------cast_to_ptr_type-------------------------------
3809 #endif
3810
3811 // Can't be implemented because there's no way to know if the type is above or below the center line.
3812 const Type* TypeInterfaces::xmeet(const Type* t) const {
3813 ShouldNotReachHere();
3814 return Type::xmeet(t);
3815 }
3816
3817 bool TypeInterfaces::singleton(void) const {
3818 ShouldNotReachHere();
3819 return Type::singleton();
3820 }
3821
3822 bool TypeInterfaces::has_non_array_interface() const {
3823 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3824
3825 return !TypeAryPtr::_array_interfaces->contains(this);
3826 }
3827
3828 //------------------------------TypeOopPtr-------------------------------------
3829 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3830 int instance_id, const TypePtr* speculative, int inline_depth)
3831 : TypePtr(t, ptr, offset, speculative, inline_depth),
3832 _const_oop(o), _klass(k),
3833 _interfaces(interfaces),
3834 _klass_is_exact(xk),
3835 _is_ptr_to_narrowoop(false),
3836 _is_ptr_to_narrowklass(false),
3837 _is_ptr_to_boxed_value(false),
3838 _instance_id(instance_id) {
3839 #ifdef ASSERT
3840 if (klass() != nullptr && klass()->is_loaded()) {
3841 interfaces->verify_is_loaded();
3842 }
3843 #endif
3844 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3845 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3846 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3847 }
3848 #ifdef _LP64
3849 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3850 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3851 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3852 } else if (klass() == nullptr) {
3853 // Array with unknown body type
3854 assert(this->isa_aryptr(), "only arrays without klass");
3855 _is_ptr_to_narrowoop = UseCompressedOops;
3856 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3857 if (klass()->is_obj_array_klass()) {
3858 _is_ptr_to_narrowoop = true;
3859 } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3860 // Check if the field of the inline type array element contains oops
3861 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3862 int foffset = field_offset.get() + vk->payload_offset();
3863 BasicType field_bt;
3864 ciField* field = vk->get_field_by_offset(foffset, false);
3865 if (field != nullptr) {
3866 field_bt = field->layout_type();
3867 } else {
3868 assert(field_offset.get() == vk->null_marker_offset_in_payload(), "no field or null marker of %s at offset %d", vk->name()->as_utf8(), foffset);
3869 field_bt = T_BOOLEAN;
3870 }
3871 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(field_bt);
3872 }
3873 } else if (klass()->is_instance_klass()) {
3874 if (this->isa_klassptr()) {
3875 // Perm objects don't use compressed references
3876 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3877 // unsafe access
3878 _is_ptr_to_narrowoop = UseCompressedOops;
3879 } else {
3880 assert(this->isa_instptr(), "must be an instance ptr.");
3881 if (klass() == ciEnv::current()->Class_klass() &&
3882 (this->offset() == java_lang_Class::klass_offset() ||
3883 this->offset() == java_lang_Class::array_klass_offset())) {
3884 // Special hidden fields from the Class.
3885 assert(this->isa_instptr(), "must be an instance ptr.");
3886 _is_ptr_to_narrowoop = false;
3887 } else if (klass() == ciEnv::current()->Class_klass() &&
3888 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3889 // Static fields
3890 ciField* field = nullptr;
3891 if (const_oop() != nullptr) {
3892 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3893 field = k->get_field_by_offset(this->offset(), true);
3894 }
3895 if (field != nullptr) {
3896 BasicType basic_elem_type = field->layout_type();
3897 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3898 } else {
3899 // unsafe access
3900 _is_ptr_to_narrowoop = UseCompressedOops;
3901 }
3902 } else {
3903 // Instance fields which contains a compressed oop references.
3904 ciInstanceKlass* ik = klass()->as_instance_klass();
3905 ciField* field = ik->get_field_by_offset(this->offset(), false);
3906 if (field != nullptr) {
3907 BasicType basic_elem_type = field->layout_type();
3908 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3909 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3910 // Compile::find_alias_type() cast exactness on all types to verify
3911 // that it does not affect alias type.
3912 _is_ptr_to_narrowoop = UseCompressedOops;
3913 } else {
3914 // Type for the copy start in LibraryCallKit::inline_native_clone().
3915 _is_ptr_to_narrowoop = UseCompressedOops;
3916 }
3917 }
3918 }
3919 }
3920 }
3921 #endif
3922 }
3923
3924 //------------------------------make-------------------------------------------
3925 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3926 const TypePtr* speculative, int inline_depth) {
3927 assert(ptr != Constant, "no constant generic pointers");
3928 ciKlass* k = Compile::current()->env()->Object_klass();
3929 bool xk = false;
3930 ciObject* o = nullptr;
3931 const TypeInterfaces* interfaces = TypeInterfaces::make();
3932 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3933 }
3934
3935
3936 //------------------------------cast_to_ptr_type-------------------------------
3937 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3938 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3939 if( ptr == _ptr ) return this;
3940 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3941 }
3942
3943 //-----------------------------cast_to_instance_id----------------------------
3944 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3945 // There are no instances of a general oop.
3946 // Return self unchanged.
3947 return this;
3948 }
3949
3950 //-----------------------------cast_to_exactness-------------------------------
3951 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3952 // There is no such thing as an exact general oop.
3953 // Return self unchanged.
3954 return this;
3955 }
3956
3957 //------------------------------as_klass_type----------------------------------
3958 // Return the klass type corresponding to this instance or array type.
3959 // It is the type that is loaded from an object of this type.
3960 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3961 ShouldNotReachHere();
3962 return nullptr;
3963 }
3964
3965 //------------------------------meet-------------------------------------------
3966 // Compute the MEET of two types. It returns a new Type object.
3967 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3968 // Perform a fast test for common case; meeting the same types together.
3969 if( this == t ) return this; // Meeting same type-rep?
3970
3971 // Current "this->_base" is OopPtr
3972 switch (t->base()) { // switch on original type
3973
3974 case Int: // Mixing ints & oops happens when javac
3975 case Long: // reuses local variables
3976 case HalfFloatTop:
3985 case NarrowOop:
3986 case NarrowKlass:
3987 case Bottom: // Ye Olde Default
3988 return Type::BOTTOM;
3989 case Top:
3990 return this;
3991
3992 default: // All else is a mistake
3993 typerr(t);
3994
3995 case RawPtr:
3996 case MetadataPtr:
3997 case KlassPtr:
3998 case InstKlassPtr:
3999 case AryKlassPtr:
4000 return TypePtr::BOTTOM; // Oop meet raw is not well defined
4001
4002 case AnyPtr: {
4003 // Found an AnyPtr type vs self-OopPtr type
4004 const TypePtr *tp = t->is_ptr();
4005 Offset offset = meet_offset(tp->offset());
4006 PTR ptr = meet_ptr(tp->ptr());
4007 const TypePtr* speculative = xmeet_speculative(tp);
4008 int depth = meet_inline_depth(tp->inline_depth());
4009 switch (tp->ptr()) {
4010 case Null:
4011 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4012 // else fall through:
4013 case TopPTR:
4014 case AnyNull: {
4015 int instance_id = meet_instance_id(InstanceTop);
4016 return make(ptr, offset, instance_id, speculative, depth);
4017 }
4018 case BotPTR:
4019 case NotNull:
4020 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4021 default: typerr(t);
4022 }
4023 }
4024
4025 case OopPtr: { // Meeting to other OopPtrs
4027 int instance_id = meet_instance_id(tp->instance_id());
4028 const TypePtr* speculative = xmeet_speculative(tp);
4029 int depth = meet_inline_depth(tp->inline_depth());
4030 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
4031 }
4032
4033 case InstPtr: // For these, flip the call around to cut down
4034 case AryPtr:
4035 return t->xmeet(this); // Call in reverse direction
4036
4037 } // End of switch
4038 return this; // Return the double constant
4039 }
4040
4041
4042 //------------------------------xdual------------------------------------------
4043 // Dual of a pure heap pointer. No relevant klass or oop information.
4044 const Type *TypeOopPtr::xdual() const {
4045 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
4046 assert(const_oop() == nullptr, "no constants here");
4047 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());
4048 }
4049
4050 //--------------------------make_from_klass_common-----------------------------
4051 // Computes the element-type given a klass.
4052 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
4053 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4054 Compile* C = Compile::current();
4055 Dependencies* deps = C->dependencies();
4056 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
4057 // Element is an instance
4058 bool klass_is_exact = false;
4059 if (klass->is_loaded()) {
4060 // Try to set klass_is_exact.
4061 ciInstanceKlass* ik = klass->as_instance_klass();
4062 klass_is_exact = ik->is_final();
4063 if (!klass_is_exact && klass_change
4064 && deps != nullptr && UseUniqueSubclasses) {
4065 ciInstanceKlass* sub = ik->unique_concrete_subklass();
4066 if (sub != nullptr) {
4067 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
4068 klass = ik = sub;
4069 klass_is_exact = sub->is_final();
4070 }
4071 }
4072 if (!klass_is_exact && try_for_exact && deps != nullptr &&
4073 !ik->is_interface() && !ik->has_subklass()) {
4074 // Add a dependence; if concrete subclass added we need to recompile
4075 deps->assert_leaf_type(ik);
4076 klass_is_exact = true;
4077 }
4078 }
4079 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
4080 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
4081 } else if (klass->is_obj_array_klass()) {
4082 // Element is an object or inline type array. Recursively call ourself.
4083 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
4084 // Determine null-free/flat properties
4085 const TypeOopPtr* exact_etype = etype;
4086 if (etype->can_be_inline_type()) {
4087 // Use exact type if element can be an inline type
4088 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
4089 }
4090 bool not_inline = !exact_etype->can_be_inline_type();
4091 bool not_null_free = not_inline;
4092 bool not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4093 // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
4094 bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
4095 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
4096 // We used to pass NotNull in here, asserting that the sub-arrays
4097 // are all not-null. This is not true in generally, as code can
4098 // slam nullptrs down in the subarrays.
4099 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4100 return arr;
4101 } else if (klass->is_type_array_klass()) {
4102 // Element is an typeArray
4103 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4104 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4105 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
4106 // We used to pass NotNull in here, asserting that the array pointer
4107 // is not-null. That was not true in general.
4108 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4109 return arr;
4110 } else if (klass->is_flat_array_klass()) {
4111 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4112 const bool is_null_free = klass->as_array_klass()->is_elem_null_free();
4113 if (is_null_free) {
4114 etype = etype->join_speculative(NOTNULL)->is_oopptr();
4115 }
4116 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
4117 const bool exact = is_null_free; // Only exact if null-free because "null-free [LMyValue <: null-able [LMyValue".
4118 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, exact, Offset(0));
4119 return arr;
4120 } else {
4121 ShouldNotReachHere();
4122 return nullptr;
4123 }
4124 }
4125
4126 //------------------------------make_from_constant-----------------------------
4127 // Make a java pointer from an oop constant
4128 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4129 assert(!o->is_null_object(), "null object not yet handled here.");
4130
4131 const bool make_constant = require_constant || o->should_be_constant();
4132
4133 ciKlass* klass = o->klass();
4134 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4135 // Element is an instance or inline type
4136 if (make_constant) {
4137 return TypeInstPtr::make(o);
4138 } else {
4139 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4140 }
4141 } else if (klass->is_obj_array_klass()) {
4142 // Element is an object array. Recursively call ourself.
4143 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4144 bool is_flat = o->as_obj_array()->is_flat();
4145 bool is_null_free = o->as_obj_array()->is_null_free();
4146 if (is_null_free) {
4147 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4148 }
4149 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
4150 /* stable= */ false, /* flat= */ false, /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free);
4151 // We used to pass NotNull in here, asserting that the sub-arrays
4152 // are all not-null. This is not true in generally, as code can
4153 // slam nulls down in the subarrays.
4154 if (make_constant) {
4155 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4156 } else {
4157 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4158 }
4159 } else if (klass->is_type_array_klass()) {
4160 // Element is an typeArray
4161 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4162 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
4163 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
4164 // We used to pass NotNull in here, asserting that the array pointer
4165 // is not-null. That was not true in general.
4166 if (make_constant) {
4167 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4168 } else {
4169 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4170 }
4171 } else if (klass->is_flat_array_klass()) {
4172 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4173 bool is_null_free = o->as_array()->is_null_free();
4174 if (is_null_free) {
4175 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4176 }
4177 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true,
4178 /* not_flat= */ false, /* not_null_free= */ !is_null_free);
4179 // We used to pass NotNull in here, asserting that the sub-arrays
4180 // are all not-null. This is not true in generally, as code can
4181 // slam nullptrs down in the subarrays.
4182 if (make_constant) {
4183 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4184 } else {
4185 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4186 }
4187 }
4188
4189 fatal("unhandled object type");
4190 return nullptr;
4191 }
4192
4193 //------------------------------get_con----------------------------------------
4194 intptr_t TypeOopPtr::get_con() const {
4195 assert( _ptr == Null || _ptr == Constant, "" );
4196 assert(offset() >= 0, "");
4197
4198 if (offset() != 0) {
4199 // After being ported to the compiler interface, the compiler no longer
4200 // directly manipulates the addresses of oops. Rather, it only has a pointer
4201 // to a handle at compile time. This handle is embedded in the generated
4202 // code and dereferenced at the time the nmethod is made. Until that time,
4203 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4204 // have access to the addresses!). This does not seem to currently happen,
4205 // but this assertion here is to help prevent its occurrence.
4206 tty->print_cr("Found oop constant with non-zero offset");
4207 ShouldNotReachHere();
4208 }
4209
4210 return (intptr_t)const_oop()->constant_encoding();
4211 }
4212
4213
4214 //-----------------------------filter------------------------------------------
4215 // Do not allow interface-vs.-noninterface joins to collapse to top.
4216 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4217
4218 const Type* ft = join_helper(kills, include_speculative);
4237 } else {
4238 return one->equals(two) && TypePtr::eq(t);
4239 }
4240 }
4241
4242 //------------------------------hash-------------------------------------------
4243 // Type-specific hashing function.
4244 uint TypeOopPtr::hash(void) const {
4245 return
4246 (uint)(const_oop() ? const_oop()->hash() : 0) +
4247 (uint)_klass_is_exact +
4248 (uint)_instance_id + TypePtr::hash();
4249 }
4250
4251 //------------------------------dump2------------------------------------------
4252 #ifndef PRODUCT
4253 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4254 st->print("oopptr:%s", ptr_msg[_ptr]);
4255 if( _klass_is_exact ) st->print(":exact");
4256 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4257 _offset.dump2(st);
4258 if (_instance_id == InstanceTop)
4259 st->print(",iid=top");
4260 else if (_instance_id != InstanceBot)
4261 st->print(",iid=%d",_instance_id);
4262
4263 dump_inline_depth(st);
4264 dump_speculative(st);
4265 }
4266 #endif
4267
4268 //------------------------------singleton--------------------------------------
4269 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4270 // constants
4271 bool TypeOopPtr::singleton(void) const {
4272 // detune optimizer to not generate constant oop + constant offset as a constant!
4273 // TopPTR, Null, AnyNull, Constant are all singletons
4274 return (offset() == 0) && !below_centerline(_ptr);
4275 }
4276
4277 //------------------------------add_offset-------------------------------------
4278 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4279 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4280 }
4281
4282 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4283 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4284 }
4285
4286 /**
4287 * Return same type without a speculative part
4288 */
4289 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4290 if (_speculative == nullptr) {
4291 return this;
4292 }
4293 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4294 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4295 }
4296
4297 /**
4298 * Return same type but drop speculative part if we know we won't use
4299 * it
4300 */
4301 const Type* TypeOopPtr::cleanup_speculative() const {
4302 // If the klass is exact and the ptr is not null then there's
4303 // nothing that the speculative type can help us with
4376 const TypeInstPtr *TypeInstPtr::BOTTOM;
4377 const TypeInstPtr *TypeInstPtr::MIRROR;
4378 const TypeInstPtr *TypeInstPtr::MARK;
4379 const TypeInstPtr *TypeInstPtr::KLASS;
4380
4381 // Is there a single ciKlass* that can represent that type?
4382 ciKlass* TypeInstPtr::exact_klass_helper() const {
4383 if (_interfaces->empty()) {
4384 return _klass;
4385 }
4386 if (_klass != ciEnv::current()->Object_klass()) {
4387 if (_interfaces->eq(_klass->as_instance_klass())) {
4388 return _klass;
4389 }
4390 return nullptr;
4391 }
4392 return _interfaces->exact_klass();
4393 }
4394
4395 //------------------------------TypeInstPtr-------------------------------------
4396 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4397 bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4398 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4399 _flat_in_array(flat_in_array) {
4400 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4401 assert(k != nullptr &&
4402 (k->is_loaded() || o == nullptr),
4403 "cannot have constants with non-loaded klass");
4404 assert(!klass()->maybe_flat_in_array() || flat_in_array, "Should be flat in array");
4405 assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4406 };
4407
4408 //------------------------------make-------------------------------------------
4409 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4410 ciKlass* k,
4411 const TypeInterfaces* interfaces,
4412 bool xk,
4413 ciObject* o,
4414 Offset offset,
4415 bool flat_in_array,
4416 int instance_id,
4417 const TypePtr* speculative,
4418 int inline_depth) {
4419 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4420 // Either const_oop() is null or else ptr is Constant
4421 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4422 "constant pointers must have a value supplied" );
4423 // Ptr is never Null
4424 assert( ptr != Null, "null pointers are not typed" );
4425
4426 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4427 if (ptr == Constant) {
4428 // Note: This case includes meta-object constants, such as methods.
4429 xk = true;
4430 } else if (k->is_loaded()) {
4431 ciInstanceKlass* ik = k->as_instance_klass();
4432 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4433 assert(!ik->is_interface(), "no interface here");
4434 if (xk && ik->is_interface()) xk = false; // no exact interface
4435 }
4436
4437 // Check if this type is known to be flat in arrays
4438 flat_in_array = flat_in_array || k->maybe_flat_in_array();
4439
4440 // Now hash this baby
4441 TypeInstPtr *result =
4442 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4443
4444 return result;
4445 }
4446
4447 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4448 if (k->is_instance_klass()) {
4449 if (k->is_loaded()) {
4450 if (k->is_interface() && interface_handling == ignore_interfaces) {
4451 assert(interface, "no interface expected");
4452 k = ciEnv::current()->Object_klass();
4453 const TypeInterfaces* interfaces = TypeInterfaces::make();
4454 return interfaces;
4455 }
4456 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4457 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4458 if (k->is_interface()) {
4459 assert(interface, "no interface expected");
4460 k = ciEnv::current()->Object_klass();
4461 } else {
4462 assert(klass, "no instance klass expected");
4488 switch (bt) {
4489 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4490 case T_INT: return TypeInt::make(constant.as_int());
4491 case T_CHAR: return TypeInt::make(constant.as_char());
4492 case T_BYTE: return TypeInt::make(constant.as_byte());
4493 case T_SHORT: return TypeInt::make(constant.as_short());
4494 case T_FLOAT: return TypeF::make(constant.as_float());
4495 case T_DOUBLE: return TypeD::make(constant.as_double());
4496 case T_LONG: return TypeLong::make(constant.as_long());
4497 default: break;
4498 }
4499 fatal("Invalid boxed value type '%s'", type2name(bt));
4500 return nullptr;
4501 }
4502
4503 //------------------------------cast_to_ptr_type-------------------------------
4504 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4505 if( ptr == _ptr ) return this;
4506 // Reconstruct _sig info here since not a problem with later lazy
4507 // construction, _sig will show up on demand.
4508 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4509 }
4510
4511
4512 //-----------------------------cast_to_exactness-------------------------------
4513 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4514 if( klass_is_exact == _klass_is_exact ) return this;
4515 if (!_klass->is_loaded()) return this;
4516 ciInstanceKlass* ik = _klass->as_instance_klass();
4517 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4518 assert(!ik->is_interface(), "no interface here");
4519 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4520 }
4521
4522 //-----------------------------cast_to_instance_id----------------------------
4523 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4524 if( instance_id == _instance_id ) return this;
4525 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4526 }
4527
4528 //------------------------------xmeet_unloaded---------------------------------
4529 // Compute the MEET of two InstPtrs when at least one is unloaded.
4530 // Assume classes are different since called after check for same name/class-loader
4531 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4532 Offset off = meet_offset(tinst->offset());
4533 PTR ptr = meet_ptr(tinst->ptr());
4534 int instance_id = meet_instance_id(tinst->instance_id());
4535 const TypePtr* speculative = xmeet_speculative(tinst);
4536 int depth = meet_inline_depth(tinst->inline_depth());
4537
4538 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4539 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4540 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4541 //
4542 // Meet unloaded class with java/lang/Object
4543 //
4544 // Meet
4545 // | Unloaded Class
4546 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4547 // ===================================================================
4548 // TOP | ..........................Unloaded......................|
4549 // AnyNull | U-AN |................Unloaded......................|
4550 // Constant | ... O-NN .................................. | O-BOT |
4551 // NotNull | ... O-NN .................................. | O-BOT |
4552 // BOTTOM | ........................Object-BOTTOM ..................|
4553 //
4554 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4555 //
4556 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4557 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4558 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4559 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4560 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4561 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4562 }
4563 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4564
4565 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4566 }
4567
4568 // Both are unloaded, not the same class, not Object
4569 // Or meet unloaded with a different loaded class, not java/lang/Object
4570 if (ptr != TypePtr::BotPTR) {
4571 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4572 }
4573 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4574 }
4575
4576
4577 //------------------------------meet-------------------------------------------
4601 case Top:
4602 return this;
4603
4604 default: // All else is a mistake
4605 typerr(t);
4606
4607 case MetadataPtr:
4608 case KlassPtr:
4609 case InstKlassPtr:
4610 case AryKlassPtr:
4611 case RawPtr: return TypePtr::BOTTOM;
4612
4613 case AryPtr: { // All arrays inherit from Object class
4614 // Call in reverse direction to avoid duplication
4615 return t->is_aryptr()->xmeet_helper(this);
4616 }
4617
4618 case OopPtr: { // Meeting to OopPtrs
4619 // Found a OopPtr type vs self-InstPtr type
4620 const TypeOopPtr *tp = t->is_oopptr();
4621 Offset offset = meet_offset(tp->offset());
4622 PTR ptr = meet_ptr(tp->ptr());
4623 switch (tp->ptr()) {
4624 case TopPTR:
4625 case AnyNull: {
4626 int instance_id = meet_instance_id(InstanceTop);
4627 const TypePtr* speculative = xmeet_speculative(tp);
4628 int depth = meet_inline_depth(tp->inline_depth());
4629 return make(ptr, klass(), _interfaces, klass_is_exact(),
4630 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4631 }
4632 case NotNull:
4633 case BotPTR: {
4634 int instance_id = meet_instance_id(tp->instance_id());
4635 const TypePtr* speculative = xmeet_speculative(tp);
4636 int depth = meet_inline_depth(tp->inline_depth());
4637 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4638 }
4639 default: typerr(t);
4640 }
4641 }
4642
4643 case AnyPtr: { // Meeting to AnyPtrs
4644 // Found an AnyPtr type vs self-InstPtr type
4645 const TypePtr *tp = t->is_ptr();
4646 Offset offset = meet_offset(tp->offset());
4647 PTR ptr = meet_ptr(tp->ptr());
4648 int instance_id = meet_instance_id(InstanceTop);
4649 const TypePtr* speculative = xmeet_speculative(tp);
4650 int depth = meet_inline_depth(tp->inline_depth());
4651 switch (tp->ptr()) {
4652 case Null:
4653 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4654 // else fall through to AnyNull
4655 case TopPTR:
4656 case AnyNull: {
4657 return make(ptr, klass(), _interfaces, klass_is_exact(),
4658 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4659 }
4660 case NotNull:
4661 case BotPTR:
4662 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4663 default: typerr(t);
4664 }
4665 }
4666
4667 /*
4668 A-top }
4669 / | \ } Tops
4670 B-top A-any C-top }
4671 | / | \ | } Any-nulls
4672 B-any | C-any }
4673 | | |
4674 B-con A-con C-con } constants; not comparable across classes
4675 | | |
4676 B-not | C-not }
4677 | \ | / | } not-nulls
4678 B-bot A-not C-bot }
4679 \ | / } Bottoms
4680 A-bot }
4681 */
4682
4683 case InstPtr: { // Meeting 2 Oops?
4684 // Found an InstPtr sub-type vs self-InstPtr type
4685 const TypeInstPtr *tinst = t->is_instptr();
4686 Offset off = meet_offset(tinst->offset());
4687 PTR ptr = meet_ptr(tinst->ptr());
4688 int instance_id = meet_instance_id(tinst->instance_id());
4689 const TypePtr* speculative = xmeet_speculative(tinst);
4690 int depth = meet_inline_depth(tinst->inline_depth());
4691 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4692
4693 ciKlass* tinst_klass = tinst->klass();
4694 ciKlass* this_klass = klass();
4695
4696 ciKlass* res_klass = nullptr;
4697 bool res_xk = false;
4698 bool res_flat_in_array = false;
4699 const Type* res;
4700 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4701
4702 if (kind == UNLOADED) {
4703 // One of these classes has not been loaded
4704 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4705 #ifndef PRODUCT
4706 if (PrintOpto && Verbose) {
4707 tty->print("meet of unloaded classes resulted in: ");
4708 unloaded_meet->dump();
4709 tty->cr();
4710 tty->print(" this == ");
4711 dump();
4712 tty->cr();
4713 tty->print(" tinst == ");
4714 tinst->dump();
4715 tty->cr();
4716 }
4717 #endif
4718 res = unloaded_meet;
4719 } else {
4720 if (kind == NOT_SUBTYPE && instance_id > 0) {
4721 instance_id = InstanceBot;
4722 } else if (kind == LCA) {
4723 instance_id = InstanceBot;
4724 }
4725 ciObject* o = nullptr; // Assume not constant when done
4726 ciObject* this_oop = const_oop();
4727 ciObject* tinst_oop = tinst->const_oop();
4728 if (ptr == Constant) {
4729 if (this_oop != nullptr && tinst_oop != nullptr &&
4730 this_oop->equals(tinst_oop))
4731 o = this_oop;
4732 else if (above_centerline(_ptr)) {
4733 assert(!tinst_klass->is_interface(), "");
4734 o = tinst_oop;
4735 } else if (above_centerline(tinst->_ptr)) {
4736 assert(!this_klass->is_interface(), "");
4737 o = this_oop;
4738 } else
4739 ptr = NotNull;
4740 }
4741 res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4742 }
4743
4744 return res;
4745
4746 } // End of case InstPtr
4747
4748 } // End of switch
4749 return this; // Return the double constant
4750 }
4751
4752 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4753 ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4754 ciKlass* this_klass = this_type->klass();
4755 ciKlass* other_klass = other_type->klass();
4756 const bool this_flat_in_array = this_type->flat_in_array();
4757 const bool other_flat_in_array = other_type->flat_in_array();
4758 const bool this_not_flat_in_array = this_type->not_flat_in_array();
4759 const bool other_not_flat_in_array = other_type->not_flat_in_array();
4760
4761 bool this_xk = this_type->klass_is_exact();
4762 bool other_xk = other_type->klass_is_exact();
4763 PTR this_ptr = this_type->ptr();
4764 PTR other_ptr = other_type->ptr();
4765 const TypeInterfaces* this_interfaces = this_type->interfaces();
4766 const TypeInterfaces* other_interfaces = other_type->interfaces();
4767 // Check for easy case; klasses are equal (and perhaps not loaded!)
4768 // If we have constants, then we created oops so classes are loaded
4769 // and we can handle the constants further down. This case handles
4770 // both-not-loaded or both-loaded classes
4771 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4772 res_klass = this_klass;
4773 res_xk = this_xk;
4774 res_flat_in_array = this_flat_in_array;
4775 return QUICK;
4776 }
4777
4778 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4779 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4780 return UNLOADED;
4781 }
4782
4783 // !!! Here's how the symmetry requirement breaks down into invariants:
4784 // If we split one up & one down AND they subtype, take the down man.
4785 // If we split one up & one down AND they do NOT subtype, "fall hard".
4786 // If both are up and they subtype, take the subtype class.
4787 // If both are up and they do NOT subtype, "fall hard".
4788 // If both are down and they subtype, take the supertype class.
4789 // If both are down and they do NOT subtype, "fall hard".
4790 // Constants treated as down.
4791
4792 // Now, reorder the above list; observe that both-down+subtype is also
4793 // "fall hard"; "fall hard" becomes the default case:
4794 // If we split one up & one down AND they subtype, take the down man.
4795 // If both are up and they subtype, take the subtype class.
4796
4797 // If both are down and they subtype, "fall hard".
4798 // If both are down and they do NOT subtype, "fall hard".
4799 // If both are up and they do NOT subtype, "fall hard".
4800 // If we split one up & one down AND they do NOT subtype, "fall hard".
4801
4802 // If a proper subtype is exact, and we return it, we return it exactly.
4803 // If a proper supertype is exact, there can be no subtyping relationship!
4804 // If both types are equal to the subtype, exactness is and-ed below the
4805 // centerline and or-ed above it. (N.B. Constants are always exact.)
4806
4807 // Flat in Array property _flat_in_array.
4808 // For simplicity, _flat_in_array is a boolean but we actually have a tri state:
4809 // - Flat in array -> flat_in_array()
4810 // - Not flat in array -> not_flat_in_array()
4811 // - Maybe flat in array -> !not_flat_in_array()
4812 //
4813 // Maybe we should convert _flat_in_array to a proper lattice with four elements at some point:
4814 //
4815 // Top
4816 // Flat in Array Not Flat in Array
4817 // Maybe Flat in Array
4818 //
4819 // where
4820 // Top = dual(maybe Flat In Array) = "Flat in Array AND Not Flat in Array"
4821 //
4822 // But for now we stick with the current model with _flat_in_array as a boolean.
4823 //
4824 // When meeting two InstPtr types, we want to have the following behavior:
4825 //
4826 // (FiA-M) Meet(this, other):
4827 // 'this' and 'other' are either the same klass OR sub klasses:
4828 //
4829 // yes maybe no
4830 // yes y m m y = Flat in Array
4831 // maybe m m m n = Not Flat in Array
4832 // no m m n m = Maybe Flat in Array
4833 //
4834 // Join(this, other):
4835 // (FiA-J-Same) 'this' and 'other' are the SAME klass:
4836 //
4837 // yes maybe no E = Empty set
4838 // yes y y E y = Flat in Array
4839 // maybe y m m n = Not Flat in Array
4840 // no E m n m = Maybe Flat in Array
4841 //
4842 // (FiA-J-Sub) 'this' and 'other' are SUB klasses:
4843 //
4844 // yes maybe no -> Super Klass E = Empty set
4845 // yes y y y y = Flat in Array
4846 // maybe y m m n = Not Flat in Array
4847 // no E m n m = Maybe Flat in Array
4848 // |
4849 // v
4850 // Sub Klass
4851 //
4852 // Note the difference when joining a super klass that is not flat in array with a sub klass that is compared to
4853 // the same klass case. We will take over the flat in array property of the sub klass. This can be done because
4854 // the super klass could be Object (i.e. not an inline type and thus not flat in array) while the sub klass is a
4855 // value class which can be flat in array.
4856 //
4857 // The empty set is only a possible result when matching 'ptr' above the center line (i.e. joining). In this case,
4858 // we can "fall hard" by setting 'ptr' to NotNull such that when we take the dual of that meet above the center
4859 // line, we get an empty set again.
4860 //
4861 // Note: When changing to a separate lattice with _flat_in_array we may want to add TypeInst(Klass)Ptr::empty()
4862 // that returns true when the meet result is FlatInArray::Top (i.e. dual(maybe flat in array)).
4863
4864 const T* subtype = nullptr;
4865 bool subtype_exact = false;
4866 bool flat_in_array = false;
4867 bool is_empty = false;
4868 if (this_type->is_same_java_type_as(other_type)) {
4869 // Same klass
4870 subtype = this_type;
4871 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4872 if (above_centerline(ptr)) {
4873 // Case (FiA-J-Same)
4874 // One is flat in array and the other not? Result is empty/"fall hard".
4875 is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4876 }
4877 } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4878 subtype = this_type; // Pick subtyping class
4879 subtype_exact = this_xk;
4880 if (above_centerline(ptr)) {
4881 // Case (FiA-J-Sub)
4882 is_empty = this_not_flat_in_array && other_flat_in_array;
4883 if (!is_empty) {
4884 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4885 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4886 }
4887 }
4888 } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4889 subtype = other_type; // Pick subtyping class
4890 subtype_exact = other_xk;
4891 if (above_centerline(ptr)) {
4892 // Case (FiA-J-Sub)
4893 is_empty = this_flat_in_array && other_not_flat_in_array;
4894 if (!is_empty) {
4895 bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4896 flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4897 }
4898 }
4899 }
4900
4901
4902 if (subtype && !is_empty) {
4903 if (above_centerline(ptr)) {
4904 // Both types are empty.
4905 this_type = other_type = subtype;
4906 this_xk = other_xk = subtype_exact;
4907 // Case (FiA-J-Sub)
4908 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4909 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4910 // One is flat in array and the other not? Result is empty/"fall hard".
4911 is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4912 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4913 // this_type is empty while other_type is not. Take other_type.
4914 this_type = other_type;
4915 this_xk = other_xk;
4916 flat_in_array = other_flat_in_array;
4917 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4918 // other_type is empty while this_type is not. Take this_type.
4919 other_type = this_type; // this is down; keep down man
4920 flat_in_array = this_flat_in_array;
4921 } else {
4922 // this_type and other_type are both non-empty.
4923 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4924 // Case (FiA-M)
4925 // Meeting two types below the center line: Only flat in array if both are.
4926 flat_in_array = this_flat_in_array && other_flat_in_array;
4927 }
4928 }
4929
4930 // Check for classes now being equal
4931 if (this_type->is_same_java_type_as(other_type) && !is_empty) {
4932 // If the klasses are equal, the constants may still differ. Fall to
4933 // NotNull if they do (neither constant is null; that is a special case
4934 // handled elsewhere).
4935 res_klass = this_type->klass();
4936 res_xk = this_xk;
4937 res_flat_in_array = flat_in_array;
4938 return SUBTYPE;
4939 } // Else classes are not equal
4940
4941 // Since klasses are different, we require a LCA in the Java
4942 // class hierarchy - which means we have to fall to at least NotNull.
4943 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4944 ptr = NotNull;
4945 }
4946
4947 interfaces = this_interfaces->intersection_with(other_interfaces);
4948
4949 // Now we find the LCA of Java classes
4950 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4951
4952 res_klass = k;
4953 res_xk = false;
4954 res_flat_in_array = this_flat_in_array && other_flat_in_array;
4955
4956 return LCA;
4957 }
4958
4959 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4960 return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4961 }
4962
4963 //------------------------java_mirror_type--------------------------------------
4964 ciType* TypeInstPtr::java_mirror_type(bool* is_null_free_array) const {
4965 // must be a singleton type
4966 if( const_oop() == nullptr ) return nullptr;
4967
4968 // must be of type java.lang.Class
4969 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4970 return const_oop()->as_instance()->java_mirror_type(is_null_free_array);
4971 }
4972
4973
4974 //------------------------------xdual------------------------------------------
4975 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4976 // inheritance mechanism.
4977 const Type *TypeInstPtr::xdual() const {
4978 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());
4979 }
4980
4981 //------------------------------eq---------------------------------------------
4982 // Structural equality check for Type representations
4983 bool TypeInstPtr::eq( const Type *t ) const {
4984 const TypeInstPtr *p = t->is_instptr();
4985 return
4986 klass()->equals(p->klass()) &&
4987 flat_in_array() == p->flat_in_array() &&
4988 _interfaces->eq(p->_interfaces) &&
4989 TypeOopPtr::eq(p); // Check sub-type stuff
4990 }
4991
4992 //------------------------------hash-------------------------------------------
4993 // Type-specific hashing function.
4994 uint TypeInstPtr::hash(void) const {
4995 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4996 }
4997
4998 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4999 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5000 }
5001
5002
5003 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5004 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
5005 }
5006
5007 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5008 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5009 }
5010
5011
5012 //------------------------------dump2------------------------------------------
5013 // Dump oop Type
5014 #ifndef PRODUCT
5015 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
5029 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
5030 char* buf = ss.as_string(/* c_heap= */false);
5031 StringUtils::replace_no_expand(buf, "\n", "");
5032 st->print_raw(buf);
5033 }
5034 case BotPTR:
5035 if (!WizardMode && !Verbose) {
5036 if( _klass_is_exact ) st->print(":exact");
5037 break;
5038 }
5039 case TopPTR:
5040 case AnyNull:
5041 case NotNull:
5042 st->print(":%s", ptr_msg[_ptr]);
5043 if( _klass_is_exact ) st->print(":exact");
5044 break;
5045 default:
5046 break;
5047 }
5048
5049 _offset.dump2(st);
5050
5051 st->print(" *");
5052
5053 if (flat_in_array() && !klass()->is_inlinetype()) {
5054 st->print(" (flat in array)");
5055 }
5056
5057 if (_instance_id == InstanceTop)
5058 st->print(",iid=top");
5059 else if (_instance_id != InstanceBot)
5060 st->print(",iid=%d",_instance_id);
5061
5062 dump_inline_depth(st);
5063 dump_speculative(st);
5064 }
5065 #endif
5066
5067 //------------------------------add_offset-------------------------------------
5068 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
5069 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
5070 _instance_id, add_offset_speculative(offset), _inline_depth);
5071 }
5072
5073 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
5074 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
5075 _instance_id, with_offset_speculative(offset), _inline_depth);
5076 }
5077
5078 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
5079 if (_speculative == nullptr) {
5080 return this;
5081 }
5082 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5083 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
5084 _instance_id, nullptr, _inline_depth);
5085 }
5086
5087 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
5088 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
5089 }
5090
5091 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
5092 if (!UseInlineDepthForSpeculativeTypes) {
5093 return this;
5094 }
5095 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
5096 }
5097
5098 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
5099 assert(is_known_instance(), "should be known");
5100 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
5101 }
5102
5103 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
5104 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
5105 }
5106
5107 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
5108 bool xk = klass_is_exact();
5109 ciInstanceKlass* ik = klass()->as_instance_klass();
5110 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
5111 if (_interfaces->eq(ik)) {
5112 Compile* C = Compile::current();
5113 Dependencies* deps = C->dependencies();
5114 deps->assert_leaf_type(ik);
5115 xk = true;
5116 }
5117 }
5118 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
5119 }
5120
5121 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) {
5122 static_assert(std::is_base_of<T2, T1>::value, "");
5123
5124 if (!this_one->is_instance_type(other)) {
5125 return false;
5126 }
5127
5128 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
5129 return true;
5130 }
5131
5132 return this_one->klass()->is_subtype_of(other->klass()) &&
5133 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
5134 }
5135
5136
5137 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5138 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5143 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
5144 return true;
5145 }
5146
5147 if (this_one->is_instance_type(other)) {
5148 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
5149 }
5150
5151 int dummy;
5152 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
5153 if (this_top_or_bottom) {
5154 return false;
5155 }
5156
5157 const T1* other_ary = this_one->is_array_type(other);
5158 const TypePtr* other_elem = other_ary->elem()->make_ptr();
5159 const TypePtr* this_elem = this_one->elem()->make_ptr();
5160 if (other_elem != nullptr && this_elem != nullptr) {
5161 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
5162 }
5163 if (other_elem == nullptr && this_elem == nullptr) {
5164 return this_one->klass()->is_subtype_of(other->klass());
5165 }
5166
5167 return false;
5168 }
5169
5170 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5171 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5172 }
5173
5174 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5175 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5176 }
5177
5178 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5179 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5180 }
5181
5182 //=============================================================================
5183 // Convenience common pre-built types.
5184 const TypeAryPtr* TypeAryPtr::BOTTOM;
5185 const TypeAryPtr *TypeAryPtr::RANGE;
5186 const TypeAryPtr *TypeAryPtr::OOPS;
5187 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5188 const TypeAryPtr *TypeAryPtr::BYTES;
5189 const TypeAryPtr *TypeAryPtr::SHORTS;
5190 const TypeAryPtr *TypeAryPtr::CHARS;
5191 const TypeAryPtr *TypeAryPtr::INTS;
5192 const TypeAryPtr *TypeAryPtr::LONGS;
5193 const TypeAryPtr *TypeAryPtr::FLOATS;
5194 const TypeAryPtr *TypeAryPtr::DOUBLES;
5195 const TypeAryPtr *TypeAryPtr::INLINES;
5196
5197 //------------------------------make-------------------------------------------
5198 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5199 int instance_id, const TypePtr* speculative, int inline_depth) {
5200 assert(!(k == nullptr && ary->_elem->isa_int()),
5201 "integral arrays must be pre-equipped with a class");
5202 if (!xk) xk = ary->ary_must_be_exact();
5203 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5204 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5205 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5206 k = nullptr;
5207 }
5208 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5209 }
5210
5211 //------------------------------make-------------------------------------------
5212 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5213 int instance_id, const TypePtr* speculative, int inline_depth,
5214 bool is_autobox_cache) {
5215 assert(!(k == nullptr && ary->_elem->isa_int()),
5216 "integral arrays must be pre-equipped with a class");
5217 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5218 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
5219 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5220 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5221 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5222 k = nullptr;
5223 }
5224 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5225 }
5226
5227 //------------------------------cast_to_ptr_type-------------------------------
5228 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5229 if( ptr == _ptr ) return this;
5230 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5231 }
5232
5233
5234 //-----------------------------cast_to_exactness-------------------------------
5235 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5236 if( klass_is_exact == _klass_is_exact ) return this;
5237 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
5238 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5239 }
5240
5241 //-----------------------------cast_to_instance_id----------------------------
5242 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5243 if( instance_id == _instance_id ) return this;
5244 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5245 }
5246
5247
5248 //-----------------------------max_array_length-------------------------------
5249 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5250 jint TypeAryPtr::max_array_length(BasicType etype) {
5251 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5252 if (etype == T_NARROWOOP) {
5253 etype = T_OBJECT;
5254 } else if (etype == T_ILLEGAL) { // bottom[]
5255 etype = T_BYTE; // will produce conservatively high value
5256 } else {
5257 fatal("not an element type: %s", type2name(etype));
5258 }
5259 }
5260 return arrayOopDesc::max_array_length(etype);
5261 }
5262
5263 //-----------------------------narrow_size_type-------------------------------
5264 // Narrow the given size type to the index range for the given array base type.
5280 if (hi > max_hi) {
5281 hi = max_hi;
5282 if (size->is_con()) {
5283 lo = hi;
5284 }
5285 chg = true;
5286 }
5287 // Negative length arrays will produce weird intermediate dead fast-path code
5288 if (lo > hi)
5289 return TypeInt::ZERO;
5290 if (!chg)
5291 return size;
5292 return TypeInt::make(lo, hi, Type::WidenMin);
5293 }
5294
5295 //-------------------------------cast_to_size----------------------------------
5296 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5297 assert(new_size != nullptr, "");
5298 new_size = narrow_size_type(new_size);
5299 if (new_size == size()) return this;
5300 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5301 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5302 }
5303
5304 //-------------------------------cast_to_not_flat------------------------------
5305 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5306 if (not_flat == is_not_flat()) {
5307 return this;
5308 }
5309 assert(!not_flat || !is_flat(), "inconsistency");
5310 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
5311 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5312 // We keep the speculative part if it contains information about flat-/nullability.
5313 // Make sure it's removed if it's not better than the non-speculative type anymore.
5314 if (res->speculative() == res->remove_speculative()) {
5315 return res->remove_speculative();
5316 }
5317 return res;
5318 }
5319
5320 //-------------------------------cast_to_not_null_free-------------------------
5321 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5322 if (not_null_free == is_not_null_free()) {
5323 return this;
5324 }
5325 assert(!not_null_free || !is_null_free(), "inconsistency");
5326 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free);
5327 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5328 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5329 // We keep the speculative part if it contains information about flat-/nullability.
5330 // Make sure it's removed if it's not better than the non-speculative type anymore.
5331 if (res->speculative() == res->remove_speculative()) {
5332 return res->remove_speculative();
5333 }
5334 return res;
5335 }
5336
5337 //---------------------------------update_properties---------------------------
5338 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5339 if ((from->is_flat() && is_not_flat()) ||
5340 (from->is_not_flat() && is_flat()) ||
5341 (from->is_null_free() && is_not_null_free()) ||
5342 (from->is_not_null_free() && is_null_free())) {
5343 return nullptr; // Inconsistent properties
5344 }
5345 const TypeAryPtr* res = this;
5346 if (from->is_not_null_free()) {
5347 res = res->cast_to_not_null_free();
5348 }
5349 if (from->is_not_flat()) {
5350 res = res->cast_to_not_flat();
5351 }
5352 return res;
5353 }
5354
5355 jint TypeAryPtr::flat_layout_helper() const {
5356 return klass()->as_flat_array_klass()->layout_helper();
5357 }
5358
5359 int TypeAryPtr::flat_elem_size() const {
5360 return klass()->as_flat_array_klass()->element_byte_size();
5361 }
5362
5363 int TypeAryPtr::flat_log_elem_size() const {
5364 return klass()->as_flat_array_klass()->log2_element_size();
5365 }
5366
5367 //------------------------------cast_to_stable---------------------------------
5368 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5369 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5370 return this;
5371
5372 const Type* elem = this->elem();
5373 const TypePtr* elem_ptr = elem->make_ptr();
5374
5375 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5376 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5377 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5378 }
5379
5380 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5381
5382 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5383 }
5384
5385 //-----------------------------stable_dimension--------------------------------
5386 int TypeAryPtr::stable_dimension() const {
5387 if (!is_stable()) return 0;
5388 int dim = 1;
5389 const TypePtr* elem_ptr = elem()->make_ptr();
5390 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5391 dim += elem_ptr->is_aryptr()->stable_dimension();
5392 return dim;
5393 }
5394
5395 //----------------------cast_to_autobox_cache-----------------------------------
5396 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5397 if (is_autobox_cache()) return this;
5398 const TypeOopPtr* etype = elem()->make_oopptr();
5399 if (etype == nullptr) return this;
5400 // The pointers in the autobox arrays are always non-null.
5401 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5402 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5403 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5404 }
5405
5406 //------------------------------eq---------------------------------------------
5407 // Structural equality check for Type representations
5408 bool TypeAryPtr::eq( const Type *t ) const {
5409 const TypeAryPtr *p = t->is_aryptr();
5410 return
5411 _ary == p->_ary && // Check array
5412 TypeOopPtr::eq(p) &&// Check sub-parts
5413 _field_offset == p->_field_offset;
5414 }
5415
5416 //------------------------------hash-------------------------------------------
5417 // Type-specific hashing function.
5418 uint TypeAryPtr::hash(void) const {
5419 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5420 }
5421
5422 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5423 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5424 }
5425
5426 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5427 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5428 }
5429
5430 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5431 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5432 }
5433 //------------------------------meet-------------------------------------------
5434 // Compute the MEET of two types. It returns a new Type object.
5435 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5436 // Perform a fast test for common case; meeting the same types together.
5437 if( this == t ) return this; // Meeting same type-rep?
5438 // Current "this->_base" is Pointer
5439 switch (t->base()) { // switch on original type
5446 case HalfFloatBot:
5447 case FloatTop:
5448 case FloatCon:
5449 case FloatBot:
5450 case DoubleTop:
5451 case DoubleCon:
5452 case DoubleBot:
5453 case NarrowOop:
5454 case NarrowKlass:
5455 case Bottom: // Ye Olde Default
5456 return Type::BOTTOM;
5457 case Top:
5458 return this;
5459
5460 default: // All else is a mistake
5461 typerr(t);
5462
5463 case OopPtr: { // Meeting to OopPtrs
5464 // Found a OopPtr type vs self-AryPtr type
5465 const TypeOopPtr *tp = t->is_oopptr();
5466 Offset offset = meet_offset(tp->offset());
5467 PTR ptr = meet_ptr(tp->ptr());
5468 int depth = meet_inline_depth(tp->inline_depth());
5469 const TypePtr* speculative = xmeet_speculative(tp);
5470 switch (tp->ptr()) {
5471 case TopPTR:
5472 case AnyNull: {
5473 int instance_id = meet_instance_id(InstanceTop);
5474 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5475 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5476 }
5477 case BotPTR:
5478 case NotNull: {
5479 int instance_id = meet_instance_id(tp->instance_id());
5480 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5481 }
5482 default: ShouldNotReachHere();
5483 }
5484 }
5485
5486 case AnyPtr: { // Meeting two AnyPtrs
5487 // Found an AnyPtr type vs self-AryPtr type
5488 const TypePtr *tp = t->is_ptr();
5489 Offset offset = meet_offset(tp->offset());
5490 PTR ptr = meet_ptr(tp->ptr());
5491 const TypePtr* speculative = xmeet_speculative(tp);
5492 int depth = meet_inline_depth(tp->inline_depth());
5493 switch (tp->ptr()) {
5494 case TopPTR:
5495 return this;
5496 case BotPTR:
5497 case NotNull:
5498 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5499 case Null:
5500 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5501 // else fall through to AnyNull
5502 case AnyNull: {
5503 int instance_id = meet_instance_id(InstanceTop);
5504 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5505 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5506 }
5507 default: ShouldNotReachHere();
5508 }
5509 }
5510
5511 case MetadataPtr:
5512 case KlassPtr:
5513 case InstKlassPtr:
5514 case AryKlassPtr:
5515 case RawPtr: return TypePtr::BOTTOM;
5516
5517 case AryPtr: { // Meeting 2 references?
5518 const TypeAryPtr *tap = t->is_aryptr();
5519 Offset off = meet_offset(tap->offset());
5520 Offset field_off = meet_field_offset(tap->field_offset());
5521 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5522 PTR ptr = meet_ptr(tap->ptr());
5523 int instance_id = meet_instance_id(tap->instance_id());
5524 const TypePtr* speculative = xmeet_speculative(tap);
5525 int depth = meet_inline_depth(tap->inline_depth());
5526
5527 ciKlass* res_klass = nullptr;
5528 bool res_xk = false;
5529 bool res_flat = false;
5530 bool res_not_flat = false;
5531 bool res_not_null_free = false;
5532 const Type* elem = tary->_elem;
5533 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5534 instance_id = InstanceBot;
5535 } else if (this->is_flat() != tap->is_flat()) {
5536 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5537 if (tary->_flat) {
5538 // Result is in a flat representation
5539 off = Offset(is_flat() ? offset() : tap->offset());
5540 field_off = is_flat() ? field_offset() : tap->field_offset();
5541 } else if (below_centerline(ptr)) {
5542 // Result is in a non-flat representation
5543 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5544 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5545 } else if (flat_offset() == tap->flat_offset()) {
5546 off = Offset(!is_flat() ? offset() : tap->offset());
5547 field_off = !is_flat() ? field_offset() : tap->field_offset();
5548 }
5549 }
5550
5551 ciObject* o = nullptr; // Assume not constant when done
5552 ciObject* this_oop = const_oop();
5553 ciObject* tap_oop = tap->const_oop();
5554 if (ptr == Constant) {
5555 if (this_oop != nullptr && tap_oop != nullptr &&
5556 this_oop->equals(tap_oop)) {
5557 o = tap_oop;
5558 } else if (above_centerline(_ptr)) {
5559 o = tap_oop;
5560 } else if (above_centerline(tap->_ptr)) {
5561 o = this_oop;
5562 } else {
5563 ptr = NotNull;
5564 }
5565 }
5566 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);
5567 }
5568
5569 // All arrays inherit from Object class
5570 case InstPtr: {
5571 const TypeInstPtr *tp = t->is_instptr();
5572 Offset offset = meet_offset(tp->offset());
5573 PTR ptr = meet_ptr(tp->ptr());
5574 int instance_id = meet_instance_id(tp->instance_id());
5575 const TypePtr* speculative = xmeet_speculative(tp);
5576 int depth = meet_inline_depth(tp->inline_depth());
5577 const TypeInterfaces* interfaces = meet_interfaces(tp);
5578 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5579 const TypeInterfaces* this_interfaces = _interfaces;
5580
5581 switch (ptr) {
5582 case TopPTR:
5583 case AnyNull: // Fall 'down' to dual of object klass
5584 // For instances when a subclass meets a superclass we fall
5585 // below the centerline when the superclass is exact. We need to
5586 // do the same here.
5587 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5588 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5589 } else {
5590 // cannot subclass, so the meet has to fall badly below the centerline
5591 ptr = NotNull;
5592 instance_id = InstanceBot;
5593 interfaces = this_interfaces->intersection_with(tp_interfaces);
5594 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5595 }
5596 case Constant:
5597 case NotNull:
5598 case BotPTR: // Fall down to object klass
5599 // LCA is object_klass, but if we subclass from the top we can do better
5600 if (above_centerline(tp->ptr())) {
5601 // If 'tp' is above the centerline and it is Object class
5602 // then we can subclass in the Java class hierarchy.
5603 // For instances when a subclass meets a superclass we fall
5604 // below the centerline when the superclass is exact. We need
5605 // to do the same here.
5606 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5607 // that is, my array type is a subtype of 'tp' klass
5608 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5609 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5610 }
5611 }
5612 // The other case cannot happen, since t cannot be a subtype of an array.
5613 // The meet falls down to Object class below centerline.
5614 if (ptr == Constant) {
5615 ptr = NotNull;
5616 }
5617 if (instance_id > 0) {
5618 instance_id = InstanceBot;
5619 }
5620 interfaces = this_interfaces->intersection_with(tp_interfaces);
5621 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5622 default: typerr(t);
5623 }
5624 }
5625 }
5626 return this; // Lint noise
5627 }
5628
5629
5630 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5631 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5632 int dummy;
5633 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5634 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5635 ciKlass* this_klass = this_ary->klass();
5636 ciKlass* other_klass = other_ary->klass();
5637 bool this_xk = this_ary->klass_is_exact();
5638 bool other_xk = other_ary->klass_is_exact();
5639 PTR this_ptr = this_ary->ptr();
5640 PTR other_ptr = other_ary->ptr();
5641 bool this_flat = this_ary->is_flat();
5642 bool this_not_flat = this_ary->is_not_flat();
5643 bool other_flat = other_ary->is_flat();
5644 bool other_not_flat = other_ary->is_not_flat();
5645 bool this_not_null_free = this_ary->is_not_null_free();
5646 bool other_not_null_free = other_ary->is_not_null_free();
5647 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5648 res_klass = nullptr;
5649 MeetResult result = SUBTYPE;
5650 res_flat = this_flat && other_flat;
5651 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5652 res_not_flat = this_not_flat && other_not_flat;
5653 res_not_null_free = this_not_null_free && other_not_null_free;
5654
5655 if (elem->isa_int()) {
5656 // Integral array element types have irrelevant lattice relations.
5657 // It is the klass that determines array layout, not the element type.
5658 if (this_top_or_bottom) {
5659 res_klass = other_klass;
5660 } else if (other_top_or_bottom || other_klass == this_klass) {
5661 res_klass = this_klass;
5662 } else {
5663 // Something like byte[int+] meets char[int+].
5664 // This must fall to bottom, not (int[-128..65535])[int+].
5665 // instance_id = InstanceBot;
5666 elem = Type::BOTTOM;
5667 result = NOT_SUBTYPE;
5668 if (above_centerline(ptr) || ptr == Constant) {
5669 ptr = NotNull;
5670 res_xk = false;
5671 return NOT_SUBTYPE;
5672 }
5673 }
5674 } else {// Non integral arrays.
5675 // Must fall to bottom if exact klasses in upper lattice
5676 // are not equal or super klass is exact.
5677 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5678 // meet with top[] and bottom[] are processed further down:
5679 !this_top_or_bottom && !other_top_or_bottom &&
5680 // both are exact and not equal:
5682 // 'tap' is exact and super or unrelated:
5683 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5684 // 'this' is exact and super or unrelated:
5685 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5686 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5687 elem = Type::BOTTOM;
5688 }
5689 ptr = NotNull;
5690 res_xk = false;
5691 return NOT_SUBTYPE;
5692 }
5693 }
5694
5695 res_xk = false;
5696 switch (other_ptr) {
5697 case AnyNull:
5698 case TopPTR:
5699 // Compute new klass on demand, do not use tap->_klass
5700 if (below_centerline(this_ptr)) {
5701 res_xk = this_xk;
5702 if (this_ary->is_flat()) {
5703 elem = this_ary->elem();
5704 }
5705 } else {
5706 res_xk = (other_xk || this_xk);
5707 }
5708 break;
5709 case Constant: {
5710 if (this_ptr == Constant && same_nullness) {
5711 // Only exact if same nullness since:
5712 // null-free [LMyValue <: nullable [LMyValue.
5713 res_xk = true;
5714 } else if (above_centerline(this_ptr)) {
5715 res_xk = true;
5716 } else {
5717 // Only precise for identical arrays
5718 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5719 // Even though MyValue is final, [LMyValue is only exact if the array
5720 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5721 if (res_xk && !res_null_free && !res_not_null_free) {
5722 res_xk = false;
5723 }
5724 }
5725 break;
5726 }
5727 case NotNull:
5728 case BotPTR:
5729 // Compute new klass on demand, do not use tap->_klass
5730 if (above_centerline(this_ptr)) {
5731 res_xk = other_xk;
5732 if (other_ary->is_flat()) {
5733 elem = other_ary->elem();
5734 }
5735 } else {
5736 res_xk = (other_xk && this_xk) &&
5737 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5738 // Even though MyValue is final, [LMyValue is only exact if the array
5739 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5740 if (res_xk && !res_null_free && !res_not_null_free) {
5741 res_xk = false;
5742 }
5743 }
5744 break;
5745 default: {
5746 ShouldNotReachHere();
5747 return result;
5748 }
5749 }
5750 return result;
5751 }
5752
5753
5754 //------------------------------xdual------------------------------------------
5755 // Dual: compute field-by-field dual
5756 const Type *TypeAryPtr::xdual() const {
5757 bool xk = _klass_is_exact;
5758 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, xk, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5759 }
5760
5761 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5762 return _field_offset.meet(offset);
5763 }
5764
5765 //------------------------------dual_offset------------------------------------
5766 Type::Offset TypeAryPtr::dual_field_offset() const {
5767 return _field_offset.dual();
5768 }
5769
5770 //------------------------------dump2------------------------------------------
5771 #ifndef PRODUCT
5772 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5773 _ary->dump2(d,depth,st);
5774 _interfaces->dump(st);
5775
5776 switch( _ptr ) {
5777 case Constant:
5778 const_oop()->print(st);
5779 break;
5780 case BotPTR:
5781 if (!WizardMode && !Verbose) {
5782 if( _klass_is_exact ) st->print(":exact");
5783 break;
5784 }
5785 case TopPTR:
5786 case AnyNull:
5787 case NotNull:
5788 st->print(":%s", ptr_msg[_ptr]);
5789 if( _klass_is_exact ) st->print(":exact");
5790 break;
5791 default:
5792 break;
5793 }
5794
5795 if (is_flat()) {
5796 st->print(":flat");
5797 st->print("(");
5798 _field_offset.dump2(st);
5799 st->print(")");
5800 } else if (is_not_flat()) {
5801 st->print(":not_flat");
5802 }
5803 if (is_null_free()) {
5804 st->print(":null_free");
5805 } else if (is_not_null_free()) {
5806 st->print(":nullable");
5807 }
5808 if (offset() != 0) {
5809 BasicType basic_elem_type = elem()->basic_type();
5810 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5811 if( _offset == Offset::top ) st->print("+undefined");
5812 else if( _offset == Offset::bottom ) st->print("+any");
5813 else if( offset() < header_size ) st->print("+%d", offset());
5814 else {
5815 if (basic_elem_type == T_ILLEGAL) {
5816 st->print("+any");
5817 } else {
5818 int elem_size = type2aelembytes(basic_elem_type);
5819 st->print("[%d]", (offset() - header_size)/elem_size);
5820 }
5821 }
5822 }
5823 st->print(" *");
5824 if (_instance_id == InstanceTop)
5825 st->print(",iid=top");
5826 else if (_instance_id != InstanceBot)
5827 st->print(",iid=%d",_instance_id);
5828
5829 dump_inline_depth(st);
5830 dump_speculative(st);
5831 }
5832 #endif
5833
5834 bool TypeAryPtr::empty(void) const {
5835 if (_ary->empty()) return true;
5836 // FIXME: Does this belong here? Or in the meet code itself?
5837 if (is_flat() && is_not_flat()) {
5838 return true;
5839 }
5840 return TypeOopPtr::empty();
5841 }
5842
5843 //------------------------------add_offset-------------------------------------
5844 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5845 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);
5846 }
5847
5848 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5849 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);
5850 }
5851
5852 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5853 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5854 }
5855
5856 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5857 if (_speculative == nullptr) {
5858 return this;
5859 }
5860 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5861 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);
5862 }
5863
5864 const Type* TypeAryPtr::cleanup_speculative() const {
5865 if (speculative() == nullptr) {
5866 return this;
5867 }
5868 // Keep speculative part if it contains information about flat-/nullability
5869 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5870 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5871 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5872 return this;
5873 }
5874 return TypeOopPtr::cleanup_speculative();
5875 }
5876
5877 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5878 if (!UseInlineDepthForSpeculativeTypes) {
5879 return this;
5880 }
5881 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5882 }
5883
5884 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5885 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);
5886 }
5887
5888 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5889 int adj = 0;
5890 if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5891 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5892 adj = _offset.get();
5893 offset += _offset.get();
5894 }
5895 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5896 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5897 offset += _field_offset.get();
5898 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5899 offset += header;
5900 }
5901 }
5902 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5903 // Try to get the field of the inline type array element we are pointing to
5904 ciInlineKlass* vk = elem()->inline_klass();
5905 int shift = flat_log_elem_size();
5906 int mask = (1 << shift) - 1;
5907 intptr_t field_offset = ((offset - header) & mask);
5908 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5909 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5910 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5911 }
5912 }
5913 }
5914 return add_offset(offset - adj);
5915 }
5916
5917 // Return offset incremented by field_offset for flat inline type arrays
5918 int TypeAryPtr::flat_offset() const {
5919 int offset = _offset.get();
5920 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5921 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5922 offset += _field_offset.get();
5923 }
5924 return offset;
5925 }
5926
5927 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5928 assert(is_known_instance(), "should be known");
5929 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5930 }
5931
5932 //=============================================================================
5933
5934
5935 //------------------------------hash-------------------------------------------
5936 // Type-specific hashing function.
5937 uint TypeNarrowPtr::hash(void) const {
5938 return _ptrtype->hash() + 7;
5939 }
5940
5941 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5942 return _ptrtype->singleton();
5943 }
5944
5945 bool TypeNarrowPtr::empty(void) const {
5946 return _ptrtype->empty();
5947 }
5948
5949 intptr_t TypeNarrowPtr::get_con() const {
5950 return _ptrtype->get_con();
5951 }
5952
5953 bool TypeNarrowPtr::eq( const Type *t ) const {
5954 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
6008 case HalfFloatTop:
6009 case HalfFloatCon:
6010 case HalfFloatBot:
6011 case FloatTop:
6012 case FloatCon:
6013 case FloatBot:
6014 case DoubleTop:
6015 case DoubleCon:
6016 case DoubleBot:
6017 case AnyPtr:
6018 case RawPtr:
6019 case OopPtr:
6020 case InstPtr:
6021 case AryPtr:
6022 case MetadataPtr:
6023 case KlassPtr:
6024 case InstKlassPtr:
6025 case AryKlassPtr:
6026 case NarrowOop:
6027 case NarrowKlass:
6028 case Bottom: // Ye Olde Default
6029 return Type::BOTTOM;
6030 case Top:
6031 return this;
6032
6033 default: // All else is a mistake
6034 typerr(t);
6035
6036 } // End of switch
6037
6038 return this;
6039 }
6040
6041 #ifndef PRODUCT
6042 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6043 _ptrtype->dump2(d, depth, st);
6044 }
6045 #endif
6046
6047 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
6091 return (one == two) && TypePtr::eq(t);
6092 } else {
6093 return one->equals(two) && TypePtr::eq(t);
6094 }
6095 }
6096
6097 //------------------------------hash-------------------------------------------
6098 // Type-specific hashing function.
6099 uint TypeMetadataPtr::hash(void) const {
6100 return
6101 (metadata() ? metadata()->hash() : 0) +
6102 TypePtr::hash();
6103 }
6104
6105 //------------------------------singleton--------------------------------------
6106 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6107 // constants
6108 bool TypeMetadataPtr::singleton(void) const {
6109 // detune optimizer to not generate constant metadata + constant offset as a constant!
6110 // TopPTR, Null, AnyNull, Constant are all singletons
6111 return (offset() == 0) && !below_centerline(_ptr);
6112 }
6113
6114 //------------------------------add_offset-------------------------------------
6115 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6116 return make( _ptr, _metadata, xadd_offset(offset));
6117 }
6118
6119 //-----------------------------filter------------------------------------------
6120 // Do not allow interface-vs.-noninterface joins to collapse to top.
6121 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6122 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6123 if (ft == nullptr || ft->empty())
6124 return Type::TOP; // Canonical empty value
6125 return ft;
6126 }
6127
6128 //------------------------------get_con----------------------------------------
6129 intptr_t TypeMetadataPtr::get_con() const {
6130 assert( _ptr == Null || _ptr == Constant, "" );
6131 assert(offset() >= 0, "");
6132
6133 if (offset() != 0) {
6134 // After being ported to the compiler interface, the compiler no longer
6135 // directly manipulates the addresses of oops. Rather, it only has a pointer
6136 // to a handle at compile time. This handle is embedded in the generated
6137 // code and dereferenced at the time the nmethod is made. Until that time,
6138 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6139 // have access to the addresses!). This does not seem to currently happen,
6140 // but this assertion here is to help prevent its occurrence.
6141 tty->print_cr("Found oop constant with non-zero offset");
6142 ShouldNotReachHere();
6143 }
6144
6145 return (intptr_t)metadata()->constant_encoding();
6146 }
6147
6148 //------------------------------cast_to_ptr_type-------------------------------
6149 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6150 if( ptr == _ptr ) return this;
6151 return make(ptr, metadata(), _offset);
6152 }
6153
6167 case HalfFloatBot:
6168 case FloatTop:
6169 case FloatCon:
6170 case FloatBot:
6171 case DoubleTop:
6172 case DoubleCon:
6173 case DoubleBot:
6174 case NarrowOop:
6175 case NarrowKlass:
6176 case Bottom: // Ye Olde Default
6177 return Type::BOTTOM;
6178 case Top:
6179 return this;
6180
6181 default: // All else is a mistake
6182 typerr(t);
6183
6184 case AnyPtr: {
6185 // Found an AnyPtr type vs self-OopPtr type
6186 const TypePtr *tp = t->is_ptr();
6187 Offset offset = meet_offset(tp->offset());
6188 PTR ptr = meet_ptr(tp->ptr());
6189 switch (tp->ptr()) {
6190 case Null:
6191 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6192 // else fall through:
6193 case TopPTR:
6194 case AnyNull: {
6195 return make(ptr, _metadata, offset);
6196 }
6197 case BotPTR:
6198 case NotNull:
6199 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6200 default: typerr(t);
6201 }
6202 }
6203
6204 case RawPtr:
6205 case KlassPtr:
6206 case InstKlassPtr:
6207 case AryKlassPtr:
6208 case OopPtr:
6209 case InstPtr:
6210 case AryPtr:
6211 return TypePtr::BOTTOM; // Oop meet raw is not well defined
6212
6213 case MetadataPtr: {
6214 const TypeMetadataPtr *tp = t->is_metadataptr();
6215 Offset offset = meet_offset(tp->offset());
6216 PTR tptr = tp->ptr();
6217 PTR ptr = meet_ptr(tptr);
6218 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6219 if (tptr == TopPTR || _ptr == TopPTR ||
6220 metadata()->equals(tp->metadata())) {
6221 return make(ptr, md, offset);
6222 }
6223 // metadata is different
6224 if( ptr == Constant ) { // Cannot be equal constants, so...
6225 if( tptr == Constant && _ptr != Constant) return t;
6226 if( _ptr == Constant && tptr != Constant) return this;
6227 ptr = NotNull; // Fall down in lattice
6228 }
6229 return make(ptr, nullptr, offset);
6230 break;
6231 }
6232 } // End of switch
6233 return this; // Return the double constant
6234 }
6235
6236
6237 //------------------------------xdual------------------------------------------
6238 // Dual of a pure metadata pointer.
6239 const Type *TypeMetadataPtr::xdual() const {
6240 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6241 }
6242
6243 //------------------------------dump2------------------------------------------
6244 #ifndef PRODUCT
6245 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6246 st->print("metadataptr:%s", ptr_msg[_ptr]);
6247 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
6248 switch (offset()) {
6249 case OffsetTop: st->print("+top"); break;
6250 case OffsetBot: st->print("+any"); break;
6251 case 0: break;
6252 default: st->print("+%d",offset()); break;
6253 }
6254 }
6255 #endif
6256
6257
6258 //=============================================================================
6259 // Convenience common pre-built type.
6260 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6261
6262 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6263 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6264 }
6265
6266 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6267 return make(Constant, m, Offset(0));
6268 }
6269 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6270 return make(Constant, m, Offset(0));
6271 }
6272
6273 //------------------------------make-------------------------------------------
6274 // Create a meta data constant
6275 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6276 assert(m == nullptr || !m->is_klass(), "wrong type");
6277 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6278 }
6279
6280
6281 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6282 const Type* elem = _ary->_elem;
6283 bool xk = klass_is_exact();
6284 if (elem->make_oopptr() != nullptr) {
6285 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6286 if (elem->is_klassptr()->klass_is_exact() &&
6287 // Even though MyValue is final, [LMyValue is only exact if the array
6288 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6289 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6290 // If so, we should add '|| is_not_null_free()'
6291 (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
6292 xk = true;
6293 }
6294 }
6295 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
6296 }
6297
6298 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6299 if (klass->is_instance_klass()) {
6300 return TypeInstKlassPtr::make(klass, interface_handling);
6301 }
6302 return TypeAryKlassPtr::make(klass, interface_handling);
6303 }
6304
6305 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
6306 if (klass->is_instance_klass()) {
6307 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
6308 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
6309 }
6310 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
6311 }
6312
6313 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6314 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6315 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6316 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6317 }
6318
6319 // Is there a single ciKlass* that can represent that type?
6320 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6321 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6322 if (_interfaces->empty()) {
6323 return _klass;
6324 }
6325 if (_klass != ciEnv::current()->Object_klass()) {
6326 if (_interfaces->eq(_klass->as_instance_klass())) {
6327 return _klass;
6328 }
6329 return nullptr;
6330 }
6331 return _interfaces->exact_klass();
6332 }
6333
6334 //------------------------------eq---------------------------------------------
6335 // Structural equality check for Type representations
6336 bool TypeKlassPtr::eq(const Type *t) const {
6337 const TypeKlassPtr *p = t->is_klassptr();
6338 return
6339 _interfaces->eq(p->_interfaces) &&
6340 TypePtr::eq(p);
6341 }
6342
6343 //------------------------------hash-------------------------------------------
6344 // Type-specific hashing function.
6345 uint TypeKlassPtr::hash(void) const {
6346 return TypePtr::hash() + _interfaces->hash();
6347 }
6348
6349 //------------------------------singleton--------------------------------------
6350 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6351 // constants
6352 bool TypeKlassPtr::singleton(void) const {
6353 // detune optimizer to not generate constant klass + constant offset as a constant!
6354 // TopPTR, Null, AnyNull, Constant are all singletons
6355 return (offset() == 0) && !below_centerline(_ptr);
6356 }
6357
6358 // Do not allow interface-vs.-noninterface joins to collapse to top.
6359 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6360 // logic here mirrors the one from TypeOopPtr::filter. See comments
6361 // there.
6362 const Type* ft = join_helper(kills, include_speculative);
6363
6364 if (ft->empty()) {
6365 return Type::TOP; // Canonical empty value
6366 }
6367
6368 return ft;
6369 }
6370
6371 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6372 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6373 return _interfaces->union_with(other->_interfaces);
6374 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6375 return other->_interfaces;
6376 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6377 return _interfaces;
6378 }
6379 return _interfaces->intersection_with(other->_interfaces);
6380 }
6381
6382 //------------------------------get_con----------------------------------------
6383 intptr_t TypeKlassPtr::get_con() const {
6384 assert( _ptr == Null || _ptr == Constant, "" );
6385 assert( offset() >= 0, "" );
6386
6387 if (offset() != 0) {
6388 // After being ported to the compiler interface, the compiler no longer
6389 // directly manipulates the addresses of oops. Rather, it only has a pointer
6390 // to a handle at compile time. This handle is embedded in the generated
6391 // code and dereferenced at the time the nmethod is made. Until that time,
6392 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6393 // have access to the addresses!). This does not seem to currently happen,
6394 // but this assertion here is to help prevent its occurrence.
6395 tty->print_cr("Found oop constant with non-zero offset");
6396 ShouldNotReachHere();
6397 }
6398
6399 ciKlass* k = exact_klass();
6400
6401 return (intptr_t)k->constant_encoding();
6402 }
6403
6404 //------------------------------dump2------------------------------------------
6405 // Dump Klass Type
6406 #ifndef PRODUCT
6407 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6411 case NotNull:
6412 {
6413 const char *name = klass()->name()->as_utf8();
6414 if (name) {
6415 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6416 } else {
6417 ShouldNotReachHere();
6418 }
6419 _interfaces->dump(st);
6420 }
6421 case BotPTR:
6422 if (!WizardMode && !Verbose && _ptr != Constant) break;
6423 case TopPTR:
6424 case AnyNull:
6425 st->print(":%s", ptr_msg[_ptr]);
6426 if (_ptr == Constant) st->print(":exact");
6427 break;
6428 default:
6429 break;
6430 }
6431 if (Verbose) {
6432 if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");
6433 }
6434 _offset.dump2(st);
6435 st->print(" *");
6436
6437 if (flat_in_array() && !klass()->is_inlinetype()) {
6438 st->print(" (flat in array)");
6439 }
6440 }
6441 #endif
6442
6443 //=============================================================================
6444 // Convenience common pre-built types.
6445
6446 // Not-null object klass or below
6447 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6448 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6449
6450 bool TypeInstKlassPtr::eq(const Type *t) const {
6451 const TypeKlassPtr *p = t->is_klassptr();
6452 return
6453 klass()->equals(p->klass()) &&
6454 flat_in_array() == p->flat_in_array() &&
6455 TypeKlassPtr::eq(p);
6456 }
6457
6458 uint TypeInstKlassPtr::hash(void) const {
6459 return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6460 }
6461
6462 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6463 flat_in_array = flat_in_array || k->maybe_flat_in_array();
6464
6465 TypeInstKlassPtr *r =
6466 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6467
6468 return r;
6469 }
6470
6471 //------------------------------add_offset-------------------------------------
6472 // Access internals of klass object
6473 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6474 return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6475 }
6476
6477 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6478 return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6479 }
6480
6481 //------------------------------cast_to_ptr_type-------------------------------
6482 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6483 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6484 if( ptr == _ptr ) return this;
6485 return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6486 }
6487
6488
6489 bool TypeInstKlassPtr::must_be_exact() const {
6490 if (!_klass->is_loaded()) return false;
6491 ciInstanceKlass* ik = _klass->as_instance_klass();
6492 if (ik->is_final()) return true; // cannot clear xk
6493 return false;
6494 }
6495
6496 //-----------------------------cast_to_exactness-------------------------------
6497 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6498 if (klass_is_exact == (_ptr == Constant)) return this;
6499 if (must_be_exact()) return this;
6500 ciKlass* k = klass();
6501 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6502 }
6503
6504
6505 //-----------------------------as_instance_type--------------------------------
6506 // Corresponding type for an instance of the given class.
6507 // It will be NotNull, and exact if and only if the klass type is exact.
6508 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6509 ciKlass* k = klass();
6510 bool xk = klass_is_exact();
6511 Compile* C = Compile::current();
6512 Dependencies* deps = C->dependencies();
6513 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6514 // Element is an instance
6515 bool klass_is_exact = false;
6516 const TypeInterfaces* interfaces = _interfaces;
6517 if (k->is_loaded()) {
6518 // Try to set klass_is_exact.
6519 ciInstanceKlass* ik = k->as_instance_klass();
6520 klass_is_exact = ik->is_final();
6521 if (!klass_is_exact && klass_change
6522 && deps != nullptr && UseUniqueSubclasses) {
6523 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6524 if (sub != nullptr) {
6525 if (_interfaces->eq(sub)) {
6526 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6527 k = ik = sub;
6528 xk = sub->is_final();
6529 }
6530 }
6531 }
6532 }
6533 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6534 }
6535
6536 //------------------------------xmeet------------------------------------------
6537 // Compute the MEET of two types, return a new Type object.
6538 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6539 // Perform a fast test for common case; meeting the same types together.
6540 if( this == t ) return this; // Meeting same type-rep?
6541
6542 // Current "this->_base" is Pointer
6543 switch (t->base()) { // switch on original type
6544
6545 case Int: // Mixing ints & oops happens when javac
6546 case Long: // reuses local variables
6547 case HalfFloatTop:
6548 case HalfFloatCon:
6549 case HalfFloatBot:
6550 case FloatTop:
6551 case FloatCon:
6552 case FloatBot:
6553 case DoubleTop:
6554 case DoubleCon:
6555 case DoubleBot:
6556 case NarrowOop:
6557 case NarrowKlass:
6558 case Bottom: // Ye Olde Default
6559 return Type::BOTTOM;
6560 case Top:
6561 return this;
6562
6563 default: // All else is a mistake
6564 typerr(t);
6565
6566 case AnyPtr: { // Meeting to AnyPtrs
6567 // Found an AnyPtr type vs self-KlassPtr type
6568 const TypePtr *tp = t->is_ptr();
6569 Offset offset = meet_offset(tp->offset());
6570 PTR ptr = meet_ptr(tp->ptr());
6571 switch (tp->ptr()) {
6572 case TopPTR:
6573 return this;
6574 case Null:
6575 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6576 case AnyNull:
6577 return make(ptr, klass(), _interfaces, offset, flat_in_array());
6578 case BotPTR:
6579 case NotNull:
6580 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6581 default: typerr(t);
6582 }
6583 }
6584
6585 case RawPtr:
6586 case MetadataPtr:
6587 case OopPtr:
6588 case AryPtr: // Meet with AryPtr
6589 case InstPtr: // Meet with InstPtr
6590 return TypePtr::BOTTOM;
6591
6592 //
6593 // A-top }
6594 // / | \ } Tops
6595 // B-top A-any C-top }
6596 // | / | \ | } Any-nulls
6597 // B-any | C-any }
6598 // | | |
6599 // B-con A-con C-con } constants; not comparable across classes
6600 // | | |
6601 // B-not | C-not }
6602 // | \ | / | } not-nulls
6603 // B-bot A-not C-bot }
6604 // \ | / } Bottoms
6605 // A-bot }
6606 //
6607
6608 case InstKlassPtr: { // Meet two KlassPtr types
6609 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6610 Offset off = meet_offset(tkls->offset());
6611 PTR ptr = meet_ptr(tkls->ptr());
6612 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6613
6614 ciKlass* res_klass = nullptr;
6615 bool res_xk = false;
6616 bool res_flat_in_array = false;
6617 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6618 case UNLOADED:
6619 ShouldNotReachHere();
6620 case SUBTYPE:
6621 case NOT_SUBTYPE:
6622 case LCA:
6623 case QUICK: {
6624 assert(res_xk == (ptr == Constant), "");
6625 const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6626 return res;
6627 }
6628 default:
6629 ShouldNotReachHere();
6630 }
6631 } // End of case KlassPtr
6632 case AryKlassPtr: { // All arrays inherit from Object class
6633 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6634 Offset offset = meet_offset(tp->offset());
6635 PTR ptr = meet_ptr(tp->ptr());
6636 const TypeInterfaces* interfaces = meet_interfaces(tp);
6637 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6638 const TypeInterfaces* this_interfaces = _interfaces;
6639
6640 switch (ptr) {
6641 case TopPTR:
6642 case AnyNull: // Fall 'down' to dual of object klass
6643 // For instances when a subclass meets a superclass we fall
6644 // below the centerline when the superclass is exact. We need to
6645 // do the same here.
6646 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6647 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free());
6648 } else {
6649 // cannot subclass, so the meet has to fall badly below the centerline
6650 ptr = NotNull;
6651 interfaces = _interfaces->intersection_with(tp->_interfaces);
6652 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6653 }
6654 case Constant:
6655 case NotNull:
6656 case BotPTR: // Fall down to object klass
6657 // LCA is object_klass, but if we subclass from the top we can do better
6658 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6659 // If 'this' (InstPtr) is above the centerline and it is Object class
6660 // then we can subclass in the Java class hierarchy.
6661 // For instances when a subclass meets a superclass we fall
6662 // below the centerline when the superclass is exact. We need
6663 // to do the same here.
6664 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6665 // that is, tp's array type is a subtype of my klass
6666 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free());
6667 }
6668 }
6669 // The other case cannot happen, since I cannot be a subtype of an array.
6670 // The meet falls down to Object class below centerline.
6671 if( ptr == Constant )
6672 ptr = NotNull;
6673 interfaces = this_interfaces->intersection_with(tp_interfaces);
6674 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6675 default: typerr(t);
6676 }
6677 }
6678
6679 } // End of switch
6680 return this; // Return the double constant
6681 }
6682
6683 //------------------------------xdual------------------------------------------
6684 // Dual: compute field-by-field dual
6685 const Type *TypeInstKlassPtr::xdual() const {
6686 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6687 }
6688
6689 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) {
6690 static_assert(std::is_base_of<T2, T1>::value, "");
6691 if (!this_one->is_loaded() || !other->is_loaded()) {
6692 return false;
6693 }
6694 if (!this_one->is_instance_type(other)) {
6695 return false;
6696 }
6697
6698 if (!other_exact) {
6699 return false;
6700 }
6701
6702 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6703 return true;
6704 }
6705
6706 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6780 const TypeInterfaces* interfaces = _interfaces;
6781 if (k->is_loaded()) {
6782 ciInstanceKlass* ik = k->as_instance_klass();
6783 bool klass_is_exact = ik->is_final();
6784 if (!klass_is_exact &&
6785 deps != nullptr) {
6786 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6787 if (sub != nullptr) {
6788 if (_interfaces->eq(sub)) {
6789 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6790 k = ik = sub;
6791 klass_is_exact = sub->is_final();
6792 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6793 }
6794 }
6795 }
6796 }
6797 return this;
6798 }
6799
6800 bool TypeInstKlassPtr::can_be_inline_array() const {
6801 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6802 }
6803
6804 bool TypeAryKlassPtr::can_be_inline_array() const {
6805 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6806 }
6807
6808 bool TypeInstPtr::can_be_inline_array() const {
6809 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6810 }
6811
6812 bool TypeAryPtr::can_be_inline_array() const {
6813 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6814 }
6815
6816 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free) {
6817 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free))->hashcons();
6818 }
6819
6820 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free) {
6821 if (k->is_obj_array_klass()) {
6822 // Element is an object array. Recursively call ourself.
6823 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6824 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6825 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, flat, null_free);
6826 } else if (k->is_type_array_klass()) {
6827 // Element is an typeArray
6828 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6829 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free);
6830 } else if (k->is_flat_array_klass()) {
6831 ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6832 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6833 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free);
6834 } else {
6835 ShouldNotReachHere();
6836 return nullptr;
6837 }
6838 }
6839
6840 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6841 bool null_free = k->as_array_klass()->is_elem_null_free();
6842 bool flat = k->is_flat_array_klass();
6843
6844 bool not_inline = k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false);
6845 bool not_null_free = (ptr == Constant) ? !null_free : not_inline;
6846 bool not_flat = (ptr == Constant) ? !flat : (!UseArrayFlattening || not_inline ||
6847 (k->as_array_klass()->element_klass() != nullptr &&
6848 k->as_array_klass()->element_klass()->is_inlinetype() &&
6849 !k->as_array_klass()->element_klass()->maybe_flat_in_array()));
6850
6851 return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, flat, null_free);
6852 }
6853
6854 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6855 return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6856 }
6857
6858 //------------------------------eq---------------------------------------------
6859 // Structural equality check for Type representations
6860 bool TypeAryKlassPtr::eq(const Type *t) const {
6861 const TypeAryKlassPtr *p = t->is_aryklassptr();
6862 return
6863 _elem == p->_elem && // Check array
6864 _not_flat == p->_not_flat &&
6865 _not_null_free == p->_not_null_free &&
6866 _null_free == p->_null_free &&
6867 _flat == p->_flat &&
6868 TypeKlassPtr::eq(p); // Check sub-parts
6869 }
6870
6871 //------------------------------hash-------------------------------------------
6872 // Type-specific hashing function.
6873 uint TypeAryKlassPtr::hash(void) const {
6874 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6875 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0);
6876 }
6877
6878 //----------------------compute_klass------------------------------------------
6879 // Compute the defining klass for this class
6880 ciKlass* TypeAryPtr::compute_klass() const {
6881 // Compute _klass based on element type.
6882 ciKlass* k_ary = nullptr;
6883 const TypeInstPtr *tinst;
6884 const TypeAryPtr *tary;
6885 const Type* el = elem();
6886 if (el->isa_narrowoop()) {
6887 el = el->make_ptr();
6888 }
6889
6890 // Get element klass
6891 if (is_flat() && el->is_inlinetypeptr()) {
6892 // Klass is required by TypeAryPtr::flat_layout_helper() and others
6893 if (el->inline_klass() != nullptr) {
6894 // TODO 8350865 We assume atomic if the atomic layout is available
6895 bool atomic = is_null_free() ? el->inline_klass()->has_atomic_layout() : el->inline_klass()->has_nullable_atomic_layout();
6896 k_ary = ciArrayKlass::make(el->inline_klass(), /* flat */ true, is_null_free(), atomic);
6897 }
6898 } else if ((tinst = el->isa_instptr()) != nullptr) {
6899 // Leave k_ary at nullptr.
6900 } else if ((tary = el->isa_aryptr()) != nullptr) {
6901 // Leave k_ary at nullptr.
6902 } else if ((el->base() == Type::Top) ||
6903 (el->base() == Type::Bottom)) {
6904 // element type of Bottom occurs from meet of basic type
6905 // and object; Top occurs when doing join on Bottom.
6906 // Leave k_ary at null.
6907 } else {
6908 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6909 // Compute array klass directly from basic type
6910 k_ary = ciTypeArrayKlass::make(el->basic_type());
6911 }
6912 return k_ary;
6913 }
6914
6915 //------------------------------klass------------------------------------------
6916 // Return the defining klass for this class
6917 ciKlass* TypeAryPtr::klass() const {
6918 if( _klass ) return _klass; // Return cached value, if possible
6919
6920 // Oops, need to compute _klass and cache it
6921 ciKlass* k_ary = compute_klass();
6929 // type TypeAryPtr::OOPS. This Type is shared between all
6930 // active compilations. However, the ciKlass which represents
6931 // this Type is *not* shared between compilations, so caching
6932 // this value would result in fetching a dangling pointer.
6933 //
6934 // Recomputing the underlying ciKlass for each request is
6935 // a bit less efficient than caching, but calls to
6936 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6937 ((TypeAryPtr*)this)->_klass = k_ary;
6938 }
6939 return k_ary;
6940 }
6941
6942 // Is there a single ciKlass* that can represent that type?
6943 ciKlass* TypeAryPtr::exact_klass_helper() const {
6944 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6945 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6946 if (k == nullptr) {
6947 return nullptr;
6948 }
6949 k = ciArrayKlass::make(k, is_flat(), is_null_free());
6950 return k;
6951 }
6952
6953 return klass();
6954 }
6955
6956 const Type* TypeAryPtr::base_element_type(int& dims) const {
6957 const Type* elem = this->elem();
6958 dims = 1;
6959 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6960 elem = elem->make_ptr()->is_aryptr()->elem();
6961 dims++;
6962 }
6963 return elem;
6964 }
6965
6966 //------------------------------add_offset-------------------------------------
6967 // Access internals of klass object
6968 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6969 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free);
6970 }
6971
6972 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6973 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free);
6974 }
6975
6976 //------------------------------cast_to_ptr_type-------------------------------
6977 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6978 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6979 if (ptr == _ptr) return this;
6980 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free);
6981 }
6982
6983 bool TypeAryKlassPtr::must_be_exact() const {
6984 if (_elem == Type::BOTTOM) return false;
6985 if (_elem == Type::TOP ) return false;
6986 const TypeKlassPtr* tk = _elem->isa_klassptr();
6987 if (!tk) return true; // a primitive type, like int
6988 // Even though MyValue is final, [LMyValue is only exact if the array
6989 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6990 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6991 // If so, we should add '&& !is_not_null_free()'
6992 if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6993 return false;
6994 }
6995 return tk->must_be_exact();
6996 }
6997
6998
6999 //-----------------------------cast_to_exactness-------------------------------
7000 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
7001 if (must_be_exact() && !klass_is_exact) return this; // cannot clear xk
7002 if (klass_is_exact == this->klass_is_exact()) {
7003 return this;
7004 }
7005 ciKlass* k = _klass;
7006 const Type* elem = this->elem();
7007 if (elem->isa_klassptr() && !klass_is_exact) {
7008 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
7009 }
7010 bool not_flat = is_not_flat();
7011 bool not_null_free = is_not_null_free();
7012 if (_elem->isa_klassptr()) {
7013 if (klass_is_exact || _elem->isa_aryklassptr()) {
7014 assert((!is_null_free() && !is_flat()) ||
7015 _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
7016 "null-free (or flat) concrete inline type arrays should always be exact");
7017 // An array can't be null-free (or flat) if the klass is exact
7018 not_null_free = true;
7019 not_flat = true;
7020 } else {
7021 // Klass is not exact (anymore), re-compute null-free/flat properties
7022 const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
7023 bool not_inline = !exact_etype->can_be_inline_type();
7024 not_null_free = not_inline;
7025 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
7026 }
7027 }
7028 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _flat, _null_free);
7029 }
7030
7031 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_null_free() const {
7032 return make(_ptr, elem(), klass(), _offset, is_not_flat(), false, is_flat(), true);
7033 }
7034
7035 //-----------------------------as_instance_type--------------------------------
7036 // Corresponding type for an instance of the given class.
7037 // It will be NotNull, and exact if and only if the klass type is exact.
7038 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
7039 ciKlass* k = klass();
7040 bool xk = klass_is_exact();
7041 const Type* el = nullptr;
7042 if (elem()->isa_klassptr()) {
7043 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
7044 k = nullptr;
7045 } else {
7046 el = elem();
7047 }
7048 bool null_free = _null_free;
7049 if (null_free && el->isa_ptr()) {
7050 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
7051 }
7052 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
7053 }
7054
7055
7056 //------------------------------xmeet------------------------------------------
7057 // Compute the MEET of two types, return a new Type object.
7058 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
7059 // Perform a fast test for common case; meeting the same types together.
7060 if( this == t ) return this; // Meeting same type-rep?
7061
7062 // Current "this->_base" is Pointer
7063 switch (t->base()) { // switch on original type
7064
7065 case Int: // Mixing ints & oops happens when javac
7066 case Long: // reuses local variables
7067 case HalfFloatTop:
7068 case HalfFloatCon:
7069 case HalfFloatBot:
7070 case FloatTop:
7071 case FloatCon:
7072 case FloatBot:
7073 case DoubleTop:
7074 case DoubleCon:
7075 case DoubleBot:
7076 case NarrowOop:
7077 case NarrowKlass:
7078 case Bottom: // Ye Olde Default
7079 return Type::BOTTOM;
7080 case Top:
7081 return this;
7082
7083 default: // All else is a mistake
7084 typerr(t);
7085
7086 case AnyPtr: { // Meeting to AnyPtrs
7087 // Found an AnyPtr type vs self-KlassPtr type
7088 const TypePtr *tp = t->is_ptr();
7089 Offset offset = meet_offset(tp->offset());
7090 PTR ptr = meet_ptr(tp->ptr());
7091 switch (tp->ptr()) {
7092 case TopPTR:
7093 return this;
7094 case Null:
7095 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7096 case AnyNull:
7097 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
7098 case BotPTR:
7099 case NotNull:
7100 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7101 default: typerr(t);
7102 }
7103 }
7104
7105 case RawPtr:
7106 case MetadataPtr:
7107 case OopPtr:
7108 case AryPtr: // Meet with AryPtr
7109 case InstPtr: // Meet with InstPtr
7110 return TypePtr::BOTTOM;
7111
7112 //
7113 // A-top }
7114 // / | \ } Tops
7115 // B-top A-any C-top }
7116 // | / | \ | } Any-nulls
7117 // B-any | C-any }
7118 // | | |
7119 // B-con A-con C-con } constants; not comparable across classes
7120 // | | |
7121 // B-not | C-not }
7122 // | \ | / | } not-nulls
7123 // B-bot A-not C-bot }
7124 // \ | / } Bottoms
7125 // A-bot }
7126 //
7127
7128 case AryKlassPtr: { // Meet two KlassPtr types
7129 const TypeAryKlassPtr *tap = t->is_aryklassptr();
7130 Offset off = meet_offset(tap->offset());
7131 const Type* elem = _elem->meet(tap->_elem);
7132 PTR ptr = meet_ptr(tap->ptr());
7133 ciKlass* res_klass = nullptr;
7134 bool res_xk = false;
7135 bool res_flat = false;
7136 bool res_not_flat = false;
7137 bool res_not_null_free = false;
7138 MeetResult res = meet_aryptr(ptr, elem, this, tap,
7139 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
7140 assert(res_xk == (ptr == Constant), "");
7141 bool flat = meet_flat(tap->_flat);
7142 bool null_free = meet_null_free(tap->_null_free);
7143 if (res == NOT_SUBTYPE) {
7144 flat = false;
7145 null_free = false;
7146 } else if (res == SUBTYPE) {
7147 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7148 flat = _flat;
7149 null_free = _null_free;
7150 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7151 flat = tap->_flat;
7152 null_free = tap->_null_free;
7153 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7154 null_free = _null_free || tap->_null_free;
7155 flat = _flat || tap->_flat;
7156 }
7157 }
7158 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free);
7159 } // End of case KlassPtr
7160 case InstKlassPtr: {
7161 const TypeInstKlassPtr *tp = t->is_instklassptr();
7162 Offset offset = meet_offset(tp->offset());
7163 PTR ptr = meet_ptr(tp->ptr());
7164 const TypeInterfaces* interfaces = meet_interfaces(tp);
7165 const TypeInterfaces* tp_interfaces = tp->_interfaces;
7166 const TypeInterfaces* this_interfaces = _interfaces;
7167
7168 switch (ptr) {
7169 case TopPTR:
7170 case AnyNull: // Fall 'down' to dual of object klass
7171 // For instances when a subclass meets a superclass we fall
7172 // below the centerline when the superclass is exact. We need to
7173 // do the same here.
7174 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7175 !tp->klass_is_exact()) {
7176 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
7177 } else {
7178 // cannot subclass, so the meet has to fall badly below the centerline
7179 ptr = NotNull;
7180 interfaces = this_interfaces->intersection_with(tp->_interfaces);
7181 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7182 }
7183 case Constant:
7184 case NotNull:
7185 case BotPTR: // Fall down to object klass
7186 // LCA is object_klass, but if we subclass from the top we can do better
7187 if (above_centerline(tp->ptr())) {
7188 // If 'tp' is above the centerline and it is Object class
7189 // then we can subclass in the Java class hierarchy.
7190 // For instances when a subclass meets a superclass we fall
7191 // below the centerline when the superclass is exact. We need
7192 // to do the same here.
7193 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7194 !tp->klass_is_exact()) {
7195 // that is, my array type is a subtype of 'tp' klass
7196 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
7197 }
7198 }
7199 // The other case cannot happen, since t cannot be a subtype of an array.
7200 // The meet falls down to Object class below centerline.
7201 if (ptr == Constant)
7202 ptr = NotNull;
7203 interfaces = this_interfaces->intersection_with(tp_interfaces);
7204 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7205 default: typerr(t);
7206 }
7207 }
7208
7209 } // End of switch
7210 return this; // Return the double constant
7211 }
7212
7213 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) {
7214 static_assert(std::is_base_of<T2, T1>::value, "");
7215
7216 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7217 return true;
7218 }
7219
7220 int dummy;
7221 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7222
7223 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7224 return false;
7225 }
7226
7227 if (this_one->is_instance_type(other)) {
7228 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7229 other_exact;
7230 }
7231
7232 assert(this_one->is_array_type(other), "");
7233 const T1* other_ary = this_one->is_array_type(other);
7234 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7235 if (other_top_or_bottom) {
7236 return false;
7237 }
7238
7239 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7240 const TypePtr* this_elem = this_one->elem()->make_ptr();
7241 if (this_elem != nullptr && other_elem != nullptr) {
7242 if (other->is_null_free() && !this_one->is_null_free()) {
7243 return false; // A nullable array can't be a subtype of a null-free array
7244 }
7245 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7246 }
7247 if (this_elem == nullptr && other_elem == nullptr) {
7248 return this_one->klass()->is_subtype_of(other->klass());
7249 }
7250 return false;
7251 }
7252
7253 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7254 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7255 }
7256
7257 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7258 static_assert(std::is_base_of<T2, T1>::value, "");
7259
7260 int dummy;
7261 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7262
7263 if (!this_one->is_array_type(other) ||
7264 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7317 }
7318
7319 const TypePtr* this_elem = this_one->elem()->make_ptr();
7320 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7321 if (other_elem != nullptr && this_elem != nullptr) {
7322 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7323 }
7324 if (other_elem == nullptr && this_elem == nullptr) {
7325 return this_one->klass()->is_subtype_of(other->klass());
7326 }
7327 return false;
7328 }
7329
7330 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7331 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7332 }
7333
7334 //------------------------------xdual------------------------------------------
7335 // Dual: compute field-by-field dual
7336 const Type *TypeAryKlassPtr::xdual() const {
7337 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free());
7338 }
7339
7340 // Is there a single ciKlass* that can represent that type?
7341 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7342 if (elem()->isa_klassptr()) {
7343 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7344 if (k == nullptr) {
7345 return nullptr;
7346 }
7347 // TODO 8350865 LibraryCallKit::inline_newArray passes a constant TypeAryKlassPtr to GraphKit::new_array
7348 // As long as atomicity is not tracked by TypeAryKlassPtr, don't re-compute it here to avoid loosing atomicity information
7349 if (k->is_inlinetype() && _klass != nullptr) {
7350 return _klass;
7351 }
7352 k = ciArrayKlass::make(k, is_flat(), is_null_free());
7353 return k;
7354 }
7355
7356 return klass();
7357 }
7358
7359 ciKlass* TypeAryKlassPtr::klass() const {
7360 if (_klass != nullptr) {
7361 return _klass;
7362 }
7363 ciKlass* k = nullptr;
7364 if (elem()->isa_klassptr()) {
7365 // leave null
7366 } else if ((elem()->base() == Type::Top) ||
7367 (elem()->base() == Type::Bottom)) {
7368 } else {
7369 k = ciTypeArrayKlass::make(elem()->basic_type());
7370 ((TypeAryKlassPtr*)this)->_klass = k;
7371 }
7372 return k;
7379 switch( _ptr ) {
7380 case Constant:
7381 st->print("precise ");
7382 case NotNull:
7383 {
7384 st->print("[");
7385 _elem->dump2(d, depth, st);
7386 _interfaces->dump(st);
7387 st->print(": ");
7388 }
7389 case BotPTR:
7390 if( !WizardMode && !Verbose && _ptr != Constant ) break;
7391 case TopPTR:
7392 case AnyNull:
7393 st->print(":%s", ptr_msg[_ptr]);
7394 if( _ptr == Constant ) st->print(":exact");
7395 break;
7396 default:
7397 break;
7398 }
7399 if (_flat) st->print(":flat");
7400 if (_null_free) st->print(":null free");
7401 if (Verbose) {
7402 if (_not_flat) st->print(":not flat");
7403 if (_not_null_free) st->print(":not null free");
7404 }
7405
7406 _offset.dump2(st);
7407
7408 st->print(" *");
7409 }
7410 #endif
7411
7412 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7413 const Type* elem = this->elem();
7414 dims = 1;
7415 while (elem->isa_aryklassptr()) {
7416 elem = elem->is_aryklassptr()->elem();
7417 dims++;
7418 }
7419 return elem;
7420 }
7421
7422 //=============================================================================
7423 // Convenience common pre-built types.
7424
7425 //------------------------------make-------------------------------------------
7426 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7427 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7428 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7429 }
7430
7431 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7432 return make(domain, domain, range, range);
7433 }
7434
7435 //------------------------------osr_domain-----------------------------
7436 const TypeTuple* osr_domain() {
7437 const Type **fields = TypeTuple::fields(2);
7438 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7439 return TypeTuple::make(TypeFunc::Parms+1, fields);
7440 }
7441
7442 //------------------------------make-------------------------------------------
7443 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7444 Compile* C = Compile::current();
7445 const TypeFunc* tf = nullptr;
7446 if (!is_osr_compilation) {
7447 tf = C->last_tf(method); // check cache
7448 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7449 }
7450 // Inline types are not passed/returned by reference, instead each field of
7451 // the inline type is passed/returned as an argument. We maintain two views of
7452 // the argument/return list here: one based on the signature (with an inline
7453 // type argument/return as a single slot), one based on the actual calling
7454 // convention (with an inline type argument/return as a list of its fields).
7455 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7456 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7457 if (method != C->method() && method->get_Method()->mismatch()) {
7458 has_scalar_args = false;
7459 }
7460 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7461 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7462 ciSignature* sig = method->signature();
7463 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7464 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7465 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7466 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7467 if (!is_osr_compilation) {
7468 C->set_last_tf(method, tf); // fill cache
7469 }
7470 return tf;
7471 }
7472
7473 //------------------------------meet-------------------------------------------
7474 // Compute the MEET of two types. It returns a new Type object.
7475 const Type *TypeFunc::xmeet( const Type *t ) const {
7476 // Perform a fast test for common case; meeting the same types together.
7477 if( this == t ) return this; // Meeting same type-rep?
7478
7479 // Current "this->_base" is Func
7480 switch (t->base()) { // switch on original type
7481
7482 case Bottom: // Ye Olde Default
7483 return t;
7484
7485 default: // All else is a mistake
7486 typerr(t);
7487
7488 case Top:
7489 break;
7490 }
7491 return this; // Return the double constant
7492 }
7493
7494 //------------------------------xdual------------------------------------------
7495 // Dual: compute field-by-field dual
7496 const Type *TypeFunc::xdual() const {
7497 return this;
7498 }
7499
7500 //------------------------------eq---------------------------------------------
7501 // Structural equality check for Type representations
7502 bool TypeFunc::eq( const Type *t ) const {
7503 const TypeFunc *a = (const TypeFunc*)t;
7504 return _domain_sig == a->_domain_sig &&
7505 _domain_cc == a->_domain_cc &&
7506 _range_sig == a->_range_sig &&
7507 _range_cc == a->_range_cc;
7508 }
7509
7510 //------------------------------hash-------------------------------------------
7511 // Type-specific hashing function.
7512 uint TypeFunc::hash(void) const {
7513 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7514 }
7515
7516 //------------------------------dump2------------------------------------------
7517 // Dump Function Type
7518 #ifndef PRODUCT
7519 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7520 if( _range_sig->cnt() <= Parms )
7521 st->print("void");
7522 else {
7523 uint i;
7524 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7525 _range_sig->field_at(i)->dump2(d,depth,st);
7526 st->print("/");
7527 }
7528 _range_sig->field_at(i)->dump2(d,depth,st);
7529 }
7530 st->print(" ");
7531 st->print("( ");
7532 if( !depth || d[this] ) { // Check for recursive dump
7533 st->print("...)");
7534 return;
7535 }
7536 d.Insert((void*)this,(void*)this); // Stop recursion
7537 if (Parms < _domain_sig->cnt())
7538 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7539 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7540 st->print(", ");
7541 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7542 }
7543 st->print(" )");
7544 }
7545 #endif
7546
7547 //------------------------------singleton--------------------------------------
7548 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7549 // constants (Ldi nodes). Singletons are integer, float or double constants
7550 // or a single symbol.
7551 bool TypeFunc::singleton(void) const {
7552 return false; // Never a singleton
7553 }
7554
7555 bool TypeFunc::empty(void) const {
7556 return false; // Never empty
7557 }
7558
7559
7560 BasicType TypeFunc::return_type() const{
7561 if (range_sig()->cnt() == TypeFunc::Parms) {
7562 return T_VOID;
7563 }
7564 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7565 }
|