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