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