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 _instance_id(instance_id) {
3579 #ifdef ASSERT
3580 if (klass() != nullptr && klass()->is_loaded()) {
3581 interfaces->verify_is_loaded();
3582 }
3583 #endif
3584 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3585 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3586 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3587 }
3588 #ifdef _LP64
3589 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3590 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3591 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3592 } else if (klass() == nullptr) {
3593 // Array with unknown body type
3594 assert(this->isa_aryptr(), "only arrays without klass");
3595 _is_ptr_to_narrowoop = UseCompressedOops;
3596 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3597 if (klass()->is_obj_array_klass()) {
3598 _is_ptr_to_narrowoop = true;
3599 } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3600 // Check if the field of the inline type array element contains oops
3601 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3602 int foffset = field_offset.get() + vk->payload_offset();
3603 BasicType field_bt;
3604 ciField* field = vk->get_field_by_offset(foffset, false);
3605 if (field != nullptr) {
3606 field_bt = field->layout_type();
3607 } else {
3608 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);
3609 field_bt = T_BOOLEAN;
3610 }
3611 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(field_bt);
3612 }
3613 } else if (klass()->is_instance_klass()) {
3614 if (this->isa_klassptr()) {
3615 // Perm objects don't use compressed references
3616 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3617 // unsafe access
3618 _is_ptr_to_narrowoop = UseCompressedOops;
3619 } else {
3620 assert(this->isa_instptr(), "must be an instance ptr.");
3621 if (klass() == ciEnv::current()->Class_klass() &&
3622 (this->offset() == java_lang_Class::klass_offset() ||
3623 this->offset() == java_lang_Class::array_klass_offset())) {
3624 // Special hidden fields from the Class.
3625 assert(this->isa_instptr(), "must be an instance ptr.");
3626 _is_ptr_to_narrowoop = false;
3627 } else if (klass() == ciEnv::current()->Class_klass() &&
3628 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3629 // Static fields
3630 ciField* field = nullptr;
3631 if (const_oop() != nullptr) {
3632 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3633 field = k->get_field_by_offset(this->offset(), true);
3634 }
3635 if (field != nullptr) {
3636 BasicType basic_elem_type = field->layout_type();
3637 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3638 } else {
3639 // unsafe access
3640 _is_ptr_to_narrowoop = UseCompressedOops;
3641 }
3642 } else {
3643 // Instance fields which contains a compressed oop references.
3644 ciInstanceKlass* ik = klass()->as_instance_klass();
3645 ciField* field = ik->get_field_by_offset(this->offset(), false);
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 if (klass()->equals(ciEnv::current()->Object_klass())) {
3650 // Compile::find_alias_type() cast exactness on all types to verify
3651 // that it does not affect alias type.
3652 _is_ptr_to_narrowoop = UseCompressedOops;
3653 } else {
3654 // Type for the copy start in LibraryCallKit::inline_native_clone().
3655 _is_ptr_to_narrowoop = UseCompressedOops;
3656 }
3657 }
3658 }
3659 }
3660 }
3661 #endif
3662 }
3663
3664 //------------------------------make-------------------------------------------
3665 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3666 const TypePtr* speculative, int inline_depth) {
3667 assert(ptr != Constant, "no constant generic pointers");
3668 ciKlass* k = Compile::current()->env()->Object_klass();
3669 bool xk = false;
3670 ciObject* o = nullptr;
3671 const TypeInterfaces* interfaces = TypeInterfaces::make();
3672 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3673 }
3674
3675
3676 //------------------------------cast_to_ptr_type-------------------------------
3677 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3678 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3679 if( ptr == _ptr ) return this;
3680 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3681 }
3682
3683 //-----------------------------cast_to_instance_id----------------------------
3684 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3685 // There are no instances of a general oop.
3686 // Return self unchanged.
3687 return this;
3688 }
3689
3690 //-----------------------------cast_to_exactness-------------------------------
3691 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3692 // There is no such thing as an exact general oop.
3693 // Return self unchanged.
3694 return this;
3695 }
3696
3697 //------------------------------as_klass_type----------------------------------
3698 // Return the klass type corresponding to this instance or array type.
3699 // It is the type that is loaded from an object of this type.
3700 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3701 ShouldNotReachHere();
3702 return nullptr;
3703 }
3704
3705 //------------------------------meet-------------------------------------------
3706 // Compute the MEET of two types. It returns a new Type object.
3707 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3708 // Perform a fast test for common case; meeting the same types together.
3709 if( this == t ) return this; // Meeting same type-rep?
3710
3711 // Current "this->_base" is OopPtr
3712 switch (t->base()) { // switch on original type
3713
3714 case Int: // Mixing ints & oops happens when javac
3715 case Long: // reuses local variables
3716 case HalfFloatTop:
3725 case NarrowOop:
3726 case NarrowKlass:
3727 case Bottom: // Ye Olde Default
3728 return Type::BOTTOM;
3729 case Top:
3730 return this;
3731
3732 default: // All else is a mistake
3733 typerr(t);
3734
3735 case RawPtr:
3736 case MetadataPtr:
3737 case KlassPtr:
3738 case InstKlassPtr:
3739 case AryKlassPtr:
3740 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3741
3742 case AnyPtr: {
3743 // Found an AnyPtr type vs self-OopPtr type
3744 const TypePtr *tp = t->is_ptr();
3745 Offset offset = meet_offset(tp->offset());
3746 PTR ptr = meet_ptr(tp->ptr());
3747 const TypePtr* speculative = xmeet_speculative(tp);
3748 int depth = meet_inline_depth(tp->inline_depth());
3749 switch (tp->ptr()) {
3750 case Null:
3751 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3752 // else fall through:
3753 case TopPTR:
3754 case AnyNull: {
3755 int instance_id = meet_instance_id(InstanceTop);
3756 return make(ptr, offset, instance_id, speculative, depth);
3757 }
3758 case BotPTR:
3759 case NotNull:
3760 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3761 default: typerr(t);
3762 }
3763 }
3764
3765 case OopPtr: { // Meeting to other OopPtrs
3767 int instance_id = meet_instance_id(tp->instance_id());
3768 const TypePtr* speculative = xmeet_speculative(tp);
3769 int depth = meet_inline_depth(tp->inline_depth());
3770 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3771 }
3772
3773 case InstPtr: // For these, flip the call around to cut down
3774 case AryPtr:
3775 return t->xmeet(this); // Call in reverse direction
3776
3777 } // End of switch
3778 return this; // Return the double constant
3779 }
3780
3781
3782 //------------------------------xdual------------------------------------------
3783 // Dual of a pure heap pointer. No relevant klass or oop information.
3784 const Type *TypeOopPtr::xdual() const {
3785 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3786 assert(const_oop() == nullptr, "no constants here");
3787 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());
3788 }
3789
3790 //--------------------------make_from_klass_common-----------------------------
3791 // Computes the element-type given a klass.
3792 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3793 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3794 Compile* C = Compile::current();
3795 Dependencies* deps = C->dependencies();
3796 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3797 // Element is an instance
3798 bool klass_is_exact = false;
3799 if (klass->is_loaded()) {
3800 // Try to set klass_is_exact.
3801 ciInstanceKlass* ik = klass->as_instance_klass();
3802 klass_is_exact = ik->is_final();
3803 if (!klass_is_exact && klass_change
3804 && deps != nullptr && UseUniqueSubclasses) {
3805 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3806 if (sub != nullptr) {
3807 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3808 klass = ik = sub;
3809 klass_is_exact = sub->is_final();
3810 }
3811 }
3812 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3813 !ik->is_interface() && !ik->has_subklass()) {
3814 // Add a dependence; if concrete subclass added we need to recompile
3815 deps->assert_leaf_type(ik);
3816 klass_is_exact = true;
3817 }
3818 }
3819 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3820 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3821 } else if (klass->is_obj_array_klass()) {
3822 // Element is an object or inline type array. Recursively call ourself.
3823 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3824 // Determine null-free/flat properties
3825 const bool is_null_free = klass->as_array_klass()->is_elem_null_free();
3826 if (is_null_free) {
3827 etype = etype->join_speculative(NOTNULL)->is_oopptr();
3828 }
3829 const TypeOopPtr* exact_etype = etype;
3830 if (etype->can_be_inline_type()) {
3831 // Use exact type if element can be an inline type
3832 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3833 }
3834 bool not_inline = !exact_etype->can_be_inline_type();
3835 bool not_null_free = not_inline;
3836 bool not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
3837 bool atomic = klass->as_array_klass()->is_elem_atomic();
3838 // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
3839 bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
3840 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free, atomic);
3841 // We used to pass NotNull in here, asserting that the sub-arrays
3842 // are all not-null. This is not true in generally, as code can
3843 // slam nullptrs down in the subarrays.
3844 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3845 return arr;
3846 } else if (klass->is_type_array_klass()) {
3847 // Element is an typeArray
3848 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3849 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3850 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3851 // We used to pass NotNull in here, asserting that the array pointer
3852 // is not-null. That was not true in general.
3853 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3854 return arr;
3855 } else if (klass->is_flat_array_klass()) {
3856 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3857 const bool is_null_free = klass->as_array_klass()->is_elem_null_free();
3858 if (is_null_free) {
3859 etype = etype->join_speculative(NOTNULL)->is_oopptr();
3860 }
3861 bool atomic = klass->as_array_klass()->is_elem_atomic();
3862 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true, /* not_flat= */ false, /* not_null_free= */ false, atomic);
3863 const bool exact = is_null_free; // Only exact if null-free because "null-free [LMyValue <: null-able [LMyValue".
3864 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, exact, Offset(0));
3865 return arr;
3866 } else {
3867 ShouldNotReachHere();
3868 return nullptr;
3869 }
3870 }
3871
3872 //------------------------------make_from_constant-----------------------------
3873 // Make a java pointer from an oop constant
3874 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3875 assert(!o->is_null_object(), "null object not yet handled here.");
3876
3877 const bool make_constant = require_constant || o->should_be_constant();
3878
3879 ciKlass* klass = o->klass();
3880 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3881 // Element is an instance or inline type
3882 if (make_constant) {
3883 return TypeInstPtr::make(o);
3884 } else {
3885 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3886 }
3887 } else if (klass->is_obj_array_klass()) {
3888 // Element is an object array. Recursively call ourself.
3889 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3890 bool is_flat = o->as_array()->is_flat();
3891 bool is_null_free = o->as_array()->is_null_free();
3892 if (is_null_free) {
3893 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3894 }
3895 bool is_atomic = o->as_array()->is_atomic();
3896 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
3897 /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
3898 // We used to pass NotNull in here, asserting that the sub-arrays
3899 // are all not-null. This is not true in generally, as code can
3900 // slam nulls down in the subarrays.
3901 if (make_constant) {
3902 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3903 } else {
3904 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3905 }
3906 } else if (klass->is_type_array_klass()) {
3907 // Element is an typeArray
3908 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3909 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
3910 /* not_flat= */ true, /* not_null_free= */ true);
3911 // We used to pass NotNull in here, asserting that the array pointer
3912 // is not-null. That was not true in general.
3913 if (make_constant) {
3914 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3915 } else {
3916 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3917 }
3918 } else if (klass->is_flat_array_klass()) {
3919 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3920 bool is_null_free = o->as_array()->is_null_free();
3921 if (is_null_free) {
3922 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3923 }
3924 bool is_atomic = o->as_array()->is_atomic();
3925 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true,
3926 /* not_flat= */ false, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
3927 // We used to pass NotNull in here, asserting that the sub-arrays
3928 // are all not-null. This is not true in generally, as code can
3929 // slam nullptrs down in the subarrays.
3930 if (make_constant) {
3931 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3932 } else {
3933 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3934 }
3935 }
3936
3937 fatal("unhandled object type");
3938 return nullptr;
3939 }
3940
3941 //------------------------------get_con----------------------------------------
3942 intptr_t TypeOopPtr::get_con() const {
3943 assert( _ptr == Null || _ptr == Constant, "" );
3944 assert(offset() >= 0, "");
3945
3946 if (offset() != 0) {
3947 // After being ported to the compiler interface, the compiler no longer
3948 // directly manipulates the addresses of oops. Rather, it only has a pointer
3949 // to a handle at compile time. This handle is embedded in the generated
3950 // code and dereferenced at the time the nmethod is made. Until that time,
3951 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3952 // have access to the addresses!). This does not seem to currently happen,
3953 // but this assertion here is to help prevent its occurrence.
3954 tty->print_cr("Found oop constant with non-zero offset");
3955 ShouldNotReachHere();
3956 }
3957
3958 return (intptr_t)const_oop()->constant_encoding();
3959 }
3960
3961
3962 //-----------------------------filter------------------------------------------
3963 // Do not allow interface-vs.-noninterface joins to collapse to top.
3964 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3965
3966 const Type* ft = join_helper(kills, include_speculative);
3985 } else {
3986 return one->equals(two) && TypePtr::eq(t);
3987 }
3988 }
3989
3990 //------------------------------hash-------------------------------------------
3991 // Type-specific hashing function.
3992 uint TypeOopPtr::hash(void) const {
3993 return
3994 (uint)(const_oop() ? const_oop()->hash() : 0) +
3995 (uint)_klass_is_exact +
3996 (uint)_instance_id + TypePtr::hash();
3997 }
3998
3999 //------------------------------dump2------------------------------------------
4000 #ifndef PRODUCT
4001 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4002 st->print("oopptr:%s", ptr_msg[_ptr]);
4003 if( _klass_is_exact ) st->print(":exact");
4004 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4005 _offset.dump2(st);
4006 if (_instance_id == InstanceTop)
4007 st->print(",iid=top");
4008 else if (_instance_id != InstanceBot)
4009 st->print(",iid=%d",_instance_id);
4010
4011 dump_inline_depth(st);
4012 dump_speculative(st);
4013 }
4014 #endif
4015
4016 //------------------------------singleton--------------------------------------
4017 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4018 // constants
4019 bool TypeOopPtr::singleton(void) const {
4020 // detune optimizer to not generate constant oop + constant offset as a constant!
4021 // TopPTR, Null, AnyNull, Constant are all singletons
4022 return (offset() == 0) && !below_centerline(_ptr);
4023 }
4024
4025 //------------------------------add_offset-------------------------------------
4026 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4027 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4028 }
4029
4030 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4031 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4032 }
4033
4034 /**
4035 * Return same type without a speculative part
4036 */
4037 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4038 if (_speculative == nullptr) {
4039 return this;
4040 }
4041 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4042 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4043 }
4044
4045 /**
4046 * Return same type but drop speculative part if we know we won't use
4047 * it
4048 */
4049 const Type* TypeOopPtr::cleanup_speculative() const {
4050 // If the klass is exact and the ptr is not null then there's
4051 // nothing that the speculative type can help us with
4124 const TypeInstPtr *TypeInstPtr::BOTTOM;
4125 const TypeInstPtr *TypeInstPtr::MIRROR;
4126 const TypeInstPtr *TypeInstPtr::MARK;
4127 const TypeInstPtr *TypeInstPtr::KLASS;
4128
4129 // Is there a single ciKlass* that can represent that type?
4130 ciKlass* TypeInstPtr::exact_klass_helper() const {
4131 if (_interfaces->empty()) {
4132 return _klass;
4133 }
4134 if (_klass != ciEnv::current()->Object_klass()) {
4135 if (_interfaces->eq(_klass->as_instance_klass())) {
4136 return _klass;
4137 }
4138 return nullptr;
4139 }
4140 return _interfaces->exact_klass();
4141 }
4142
4143 //------------------------------TypeInstPtr-------------------------------------
4144 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4145 bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4146 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4147 _flat_in_array(flat_in_array) {
4148 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4149 assert(k != nullptr &&
4150 (k->is_loaded() || o == nullptr),
4151 "cannot have constants with non-loaded klass");
4152 assert(!klass()->maybe_flat_in_array() || flat_in_array, "Should be flat in array");
4153 assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4154 };
4155
4156 //------------------------------make-------------------------------------------
4157 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4158 ciKlass* k,
4159 const TypeInterfaces* interfaces,
4160 bool xk,
4161 ciObject* o,
4162 Offset offset,
4163 bool flat_in_array,
4164 int instance_id,
4165 const TypePtr* speculative,
4166 int inline_depth) {
4167 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4168 // Either const_oop() is null or else ptr is Constant
4169 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4170 "constant pointers must have a value supplied" );
4171 // Ptr is never Null
4172 assert( ptr != Null, "null pointers are not typed" );
4173
4174 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4175 if (ptr == Constant) {
4176 // Note: This case includes meta-object constants, such as methods.
4177 xk = true;
4178 } else if (k->is_loaded()) {
4179 ciInstanceKlass* ik = k->as_instance_klass();
4180 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4181 assert(!ik->is_interface(), "no interface here");
4182 if (xk && ik->is_interface()) xk = false; // no exact interface
4183 }
4184
4185 // Check if this type is known to be flat in arrays
4186 flat_in_array = flat_in_array || k->maybe_flat_in_array();
4187
4188 // Now hash this baby
4189 TypeInstPtr *result =
4190 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4191
4192 return result;
4193 }
4194
4195 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4196 if (k->is_instance_klass()) {
4197 if (k->is_loaded()) {
4198 if (k->is_interface() && interface_handling == ignore_interfaces) {
4199 assert(interface, "no interface expected");
4200 k = ciEnv::current()->Object_klass();
4201 const TypeInterfaces* interfaces = TypeInterfaces::make();
4202 return interfaces;
4203 }
4204 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4205 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4206 if (k->is_interface()) {
4207 assert(interface, "no interface expected");
4208 k = ciEnv::current()->Object_klass();
4209 } else {
4210 assert(klass, "no instance klass expected");
4236 switch (bt) {
4237 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4238 case T_INT: return TypeInt::make(constant.as_int());
4239 case T_CHAR: return TypeInt::make(constant.as_char());
4240 case T_BYTE: return TypeInt::make(constant.as_byte());
4241 case T_SHORT: return TypeInt::make(constant.as_short());
4242 case T_FLOAT: return TypeF::make(constant.as_float());
4243 case T_DOUBLE: return TypeD::make(constant.as_double());
4244 case T_LONG: return TypeLong::make(constant.as_long());
4245 default: break;
4246 }
4247 fatal("Invalid boxed value type '%s'", type2name(bt));
4248 return nullptr;
4249 }
4250
4251 //------------------------------cast_to_ptr_type-------------------------------
4252 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4253 if( ptr == _ptr ) return this;
4254 // Reconstruct _sig info here since not a problem with later lazy
4255 // construction, _sig will show up on demand.
4256 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4257 }
4258
4259
4260 //-----------------------------cast_to_exactness-------------------------------
4261 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4262 if( klass_is_exact == _klass_is_exact ) return this;
4263 if (!_klass->is_loaded()) return this;
4264 ciInstanceKlass* ik = _klass->as_instance_klass();
4265 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4266 assert(!ik->is_interface(), "no interface here");
4267 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4268 }
4269
4270 //-----------------------------cast_to_instance_id----------------------------
4271 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4272 if( instance_id == _instance_id ) return this;
4273 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4274 }
4275
4276 //------------------------------xmeet_unloaded---------------------------------
4277 // Compute the MEET of two InstPtrs when at least one is unloaded.
4278 // Assume classes are different since called after check for same name/class-loader
4279 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4280 Offset off = meet_offset(tinst->offset());
4281 PTR ptr = meet_ptr(tinst->ptr());
4282 int instance_id = meet_instance_id(tinst->instance_id());
4283 const TypePtr* speculative = xmeet_speculative(tinst);
4284 int depth = meet_inline_depth(tinst->inline_depth());
4285
4286 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4287 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4288 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4289 //
4290 // Meet unloaded class with java/lang/Object
4291 //
4292 // Meet
4293 // | Unloaded Class
4294 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4295 // ===================================================================
4296 // TOP | ..........................Unloaded......................|
4297 // AnyNull | U-AN |................Unloaded......................|
4298 // Constant | ... O-NN .................................. | O-BOT |
4299 // NotNull | ... O-NN .................................. | O-BOT |
4300 // BOTTOM | ........................Object-BOTTOM ..................|
4301 //
4302 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4303 //
4304 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4305 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4306 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4307 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4308 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4309 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4310 }
4311 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4312
4313 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4314 }
4315
4316 // Both are unloaded, not the same class, not Object
4317 // Or meet unloaded with a different loaded class, not java/lang/Object
4318 if (ptr != TypePtr::BotPTR) {
4319 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4320 }
4321 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4322 }
4323
4324
4325 //------------------------------meet-------------------------------------------
4349 case Top:
4350 return this;
4351
4352 default: // All else is a mistake
4353 typerr(t);
4354
4355 case MetadataPtr:
4356 case KlassPtr:
4357 case InstKlassPtr:
4358 case AryKlassPtr:
4359 case RawPtr: return TypePtr::BOTTOM;
4360
4361 case AryPtr: { // All arrays inherit from Object class
4362 // Call in reverse direction to avoid duplication
4363 return t->is_aryptr()->xmeet_helper(this);
4364 }
4365
4366 case OopPtr: { // Meeting to OopPtrs
4367 // Found a OopPtr type vs self-InstPtr type
4368 const TypeOopPtr *tp = t->is_oopptr();
4369 Offset offset = meet_offset(tp->offset());
4370 PTR ptr = meet_ptr(tp->ptr());
4371 switch (tp->ptr()) {
4372 case TopPTR:
4373 case AnyNull: {
4374 int instance_id = meet_instance_id(InstanceTop);
4375 const TypePtr* speculative = xmeet_speculative(tp);
4376 int depth = meet_inline_depth(tp->inline_depth());
4377 return make(ptr, klass(), _interfaces, klass_is_exact(),
4378 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4379 }
4380 case NotNull:
4381 case BotPTR: {
4382 int instance_id = meet_instance_id(tp->instance_id());
4383 const TypePtr* speculative = xmeet_speculative(tp);
4384 int depth = meet_inline_depth(tp->inline_depth());
4385 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4386 }
4387 default: typerr(t);
4388 }
4389 }
4390
4391 case AnyPtr: { // Meeting to AnyPtrs
4392 // Found an AnyPtr type vs self-InstPtr type
4393 const TypePtr *tp = t->is_ptr();
4394 Offset offset = meet_offset(tp->offset());
4395 PTR ptr = meet_ptr(tp->ptr());
4396 int instance_id = meet_instance_id(InstanceTop);
4397 const TypePtr* speculative = xmeet_speculative(tp);
4398 int depth = meet_inline_depth(tp->inline_depth());
4399 switch (tp->ptr()) {
4400 case Null:
4401 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4402 // else fall through to AnyNull
4403 case TopPTR:
4404 case AnyNull: {
4405 return make(ptr, klass(), _interfaces, klass_is_exact(),
4406 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4407 }
4408 case NotNull:
4409 case BotPTR:
4410 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4411 default: typerr(t);
4412 }
4413 }
4414
4415 /*
4416 A-top }
4417 / | \ } Tops
4418 B-top A-any C-top }
4419 | / | \ | } Any-nulls
4420 B-any | C-any }
4421 | | |
4422 B-con A-con C-con } constants; not comparable across classes
4423 | | |
4424 B-not | C-not }
4425 | \ | / | } not-nulls
4426 B-bot A-not C-bot }
4427 \ | / } Bottoms
4428 A-bot }
4429 */
4430
4431 case InstPtr: { // Meeting 2 Oops?
4432 // Found an InstPtr sub-type vs self-InstPtr type
4433 const TypeInstPtr *tinst = t->is_instptr();
4434 Offset off = meet_offset(tinst->offset());
4435 PTR ptr = meet_ptr(tinst->ptr());
4436 int instance_id = meet_instance_id(tinst->instance_id());
4437 const TypePtr* speculative = xmeet_speculative(tinst);
4438 int depth = meet_inline_depth(tinst->inline_depth());
4439 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4440
4441 ciKlass* tinst_klass = tinst->klass();
4442 ciKlass* this_klass = klass();
4443
4444 ciKlass* res_klass = nullptr;
4445 bool res_xk = false;
4446 bool res_flat_in_array = false;
4447 const Type* res;
4448 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4449
4450 if (kind == UNLOADED) {
4451 // One of these classes has not been loaded
4452 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4453 #ifndef PRODUCT
4454 if (PrintOpto && Verbose) {
4455 tty->print("meet of unloaded classes resulted in: ");
4456 unloaded_meet->dump();
4457 tty->cr();
4458 tty->print(" this == ");
4459 dump();
4460 tty->cr();
4461 tty->print(" tinst == ");
4462 tinst->dump();
4463 tty->cr();
4464 }
4465 #endif
4466 res = unloaded_meet;
4467 } else {
4468 if (kind == NOT_SUBTYPE && instance_id > 0) {
4469 instance_id = InstanceBot;
4470 } else if (kind == LCA) {
4471 instance_id = InstanceBot;
4472 }
4473 ciObject* o = nullptr; // Assume not constant when done
4474 ciObject* this_oop = const_oop();
4475 ciObject* tinst_oop = tinst->const_oop();
4476 if (ptr == Constant) {
4477 if (this_oop != nullptr && tinst_oop != nullptr &&
4478 this_oop->equals(tinst_oop))
4479 o = this_oop;
4480 else if (above_centerline(_ptr)) {
4481 assert(!tinst_klass->is_interface(), "");
4482 o = tinst_oop;
4483 } else if (above_centerline(tinst->_ptr)) {
4484 assert(!this_klass->is_interface(), "");
4485 o = this_oop;
4486 } else
4487 ptr = NotNull;
4488 }
4489 res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4490 }
4491
4492 return res;
4493
4494 } // End of case InstPtr
4495
4496 } // End of switch
4497 return this; // Return the double constant
4498 }
4499
4500 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4501 ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4502 ciKlass* this_klass = this_type->klass();
4503 ciKlass* other_klass = other_type->klass();
4504 const bool this_flat_in_array = this_type->flat_in_array();
4505 const bool other_flat_in_array = other_type->flat_in_array();
4506 const bool this_not_flat_in_array = this_type->not_flat_in_array();
4507 const bool other_not_flat_in_array = other_type->not_flat_in_array();
4508
4509 bool this_xk = this_type->klass_is_exact();
4510 bool other_xk = other_type->klass_is_exact();
4511 PTR this_ptr = this_type->ptr();
4512 PTR other_ptr = other_type->ptr();
4513 const TypeInterfaces* this_interfaces = this_type->interfaces();
4514 const TypeInterfaces* other_interfaces = other_type->interfaces();
4515 // Check for easy case; klasses are equal (and perhaps not loaded!)
4516 // If we have constants, then we created oops so classes are loaded
4517 // and we can handle the constants further down. This case handles
4518 // both-not-loaded or both-loaded classes
4519 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4520 res_klass = this_klass;
4521 res_xk = this_xk;
4522 res_flat_in_array = this_flat_in_array;
4523 return QUICK;
4524 }
4525
4526 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4527 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4528 return UNLOADED;
4529 }
4530
4531 // !!! Here's how the symmetry requirement breaks down into invariants:
4532 // If we split one up & one down AND they subtype, take the down man.
4533 // If we split one up & one down AND they do NOT subtype, "fall hard".
4534 // If both are up and they subtype, take the subtype class.
4535 // If both are up and they do NOT subtype, "fall hard".
4536 // If both are down and they subtype, take the supertype class.
4537 // If both are down and they do NOT subtype, "fall hard".
4538 // Constants treated as down.
4539
4540 // Now, reorder the above list; observe that both-down+subtype is also
4541 // "fall hard"; "fall hard" becomes the default case:
4542 // If we split one up & one down AND they subtype, take the down man.
4543 // If both are up and they subtype, take the subtype class.
4544
4545 // If both are down and they subtype, "fall hard".
4546 // If both are down and they do NOT subtype, "fall hard".
4547 // If both are up and they do NOT subtype, "fall hard".
4548 // If we split one up & one down AND they do NOT subtype, "fall hard".
4549
4550 // If a proper subtype is exact, and we return it, we return it exactly.
4551 // If a proper supertype is exact, there can be no subtyping relationship!
4552 // If both types are equal to the subtype, exactness is and-ed below the
4553 // centerline and or-ed above it. (N.B. Constants are always exact.)
4554
4555 // Flat in Array property _flat_in_array.
4556 // For simplicity, _flat_in_array is a boolean but we actually have a tri state:
4557 // - Flat in array -> flat_in_array()
4558 // - Not flat in array -> not_flat_in_array()
4559 // - Maybe flat in array -> !not_flat_in_array()
4560 //
4561 // Maybe we should convert _flat_in_array to a proper lattice with four elements at some point:
4562 //
4563 // Top
4564 // Flat in Array Not Flat in Array
4565 // Maybe Flat in Array
4566 //
4567 // where
4568 // Top = dual(maybe Flat In Array) = "Flat in Array AND Not Flat in Array"
4569 //
4570 // But for now we stick with the current model with _flat_in_array as a boolean.
4571 //
4572 // When meeting two InstPtr types, we want to have the following behavior:
4573 //
4574 // (FiA-M) Meet(this, other):
4575 // 'this' and 'other' are either the same klass OR sub klasses:
4576 //
4577 // yes maybe no
4578 // yes y m m y = Flat in Array
4579 // maybe m m m n = Not Flat in Array
4580 // no m m n m = Maybe Flat in Array
4581 //
4582 // Join(this, other):
4583 // (FiA-J-Same) 'this' and 'other' are the SAME klass:
4584 //
4585 // yes maybe no E = Empty set
4586 // yes y y E y = Flat in Array
4587 // maybe y m m n = Not Flat in Array
4588 // no E m n m = Maybe Flat in Array
4589 //
4590 // (FiA-J-Sub) 'this' and 'other' are SUB klasses:
4591 //
4592 // yes maybe no -> Super Klass E = Empty set
4593 // yes y y y y = Flat in Array
4594 // maybe y m m n = Not Flat in Array
4595 // no E m n m = Maybe Flat in Array
4596 // |
4597 // v
4598 // Sub Klass
4599 //
4600 // Note the difference when joining a super klass that is not flat in array with a sub klass that is compared to
4601 // the same klass case. We will take over the flat in array property of the sub klass. This can be done because
4602 // the super klass could be Object (i.e. not an inline type and thus not flat in array) while the sub klass is a
4603 // value class which can be flat in array.
4604 //
4605 // The empty set is only a possible result when matching 'ptr' above the center line (i.e. joining). In this case,
4606 // we can "fall hard" by setting 'ptr' to NotNull such that when we take the dual of that meet above the center
4607 // line, we get an empty set again.
4608 //
4609 // Note: When changing to a separate lattice with _flat_in_array we may want to add TypeInst(Klass)Ptr::empty()
4610 // that returns true when the meet result is FlatInArray::Top (i.e. dual(maybe flat in array)).
4611
4612 const T* subtype = nullptr;
4613 bool subtype_exact = false;
4614 bool flat_in_array = false;
4615 bool is_empty = false;
4616 if (this_type->is_same_java_type_as(other_type)) {
4617 // Same klass
4618 subtype = this_type;
4619 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4620 if (above_centerline(ptr)) {
4621 // Case (FiA-J-Same)
4622 // One is flat in array and the other not? Result is empty/"fall hard".
4623 is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4624 }
4625 } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4626 subtype = this_type; // Pick subtyping class
4627 subtype_exact = this_xk;
4628 if (above_centerline(ptr)) {
4629 // Case (FiA-J-Sub)
4630 is_empty = this_not_flat_in_array && other_flat_in_array;
4631 if (!is_empty) {
4632 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4633 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4634 }
4635 }
4636 } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4637 subtype = other_type; // Pick subtyping class
4638 subtype_exact = other_xk;
4639 if (above_centerline(ptr)) {
4640 // Case (FiA-J-Sub)
4641 is_empty = this_flat_in_array && other_not_flat_in_array;
4642 if (!is_empty) {
4643 bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4644 flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4645 }
4646 }
4647 }
4648
4649
4650 if (subtype && !is_empty) {
4651 if (above_centerline(ptr)) {
4652 // Both types are empty.
4653 this_type = other_type = subtype;
4654 this_xk = other_xk = subtype_exact;
4655 // Case (FiA-J-Sub)
4656 bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4657 flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4658 // One is flat in array and the other not? Result is empty/"fall hard".
4659 is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4660 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4661 // this_type is empty while other_type is not. Take other_type.
4662 this_type = other_type;
4663 this_xk = other_xk;
4664 flat_in_array = other_flat_in_array;
4665 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4666 // other_type is empty while this_type is not. Take this_type.
4667 other_type = this_type; // this is down; keep down man
4668 flat_in_array = this_flat_in_array;
4669 } else {
4670 // this_type and other_type are both non-empty.
4671 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4672 // Case (FiA-M)
4673 // Meeting two types below the center line: Only flat in array if both are.
4674 flat_in_array = this_flat_in_array && other_flat_in_array;
4675 }
4676 }
4677
4678 // Check for classes now being equal
4679 if (this_type->is_same_java_type_as(other_type) && !is_empty) {
4680 // If the klasses are equal, the constants may still differ. Fall to
4681 // NotNull if they do (neither constant is null; that is a special case
4682 // handled elsewhere).
4683 res_klass = this_type->klass();
4684 res_xk = this_xk;
4685 res_flat_in_array = flat_in_array;
4686 return SUBTYPE;
4687 } // Else classes are not equal
4688
4689 // Since klasses are different, we require a LCA in the Java
4690 // class hierarchy - which means we have to fall to at least NotNull.
4691 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4692 ptr = NotNull;
4693 }
4694
4695 interfaces = this_interfaces->intersection_with(other_interfaces);
4696
4697 // Now we find the LCA of Java classes
4698 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4699
4700 res_klass = k;
4701 res_xk = false;
4702 res_flat_in_array = this_flat_in_array && other_flat_in_array;
4703
4704 return LCA;
4705 }
4706
4707 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4708 return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4709 }
4710
4711 //------------------------java_mirror_type--------------------------------------
4712 ciType* TypeInstPtr::java_mirror_type() const {
4713 // must be a singleton type
4714 if( const_oop() == nullptr ) return nullptr;
4715
4716 // must be of type java.lang.Class
4717 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4718 return const_oop()->as_instance()->java_mirror_type();
4719 }
4720
4721
4722 //------------------------------xdual------------------------------------------
4723 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4724 // inheritance mechanism.
4725 const Type *TypeInstPtr::xdual() const {
4726 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());
4727 }
4728
4729 //------------------------------eq---------------------------------------------
4730 // Structural equality check for Type representations
4731 bool TypeInstPtr::eq( const Type *t ) const {
4732 const TypeInstPtr *p = t->is_instptr();
4733 return
4734 klass()->equals(p->klass()) &&
4735 flat_in_array() == p->flat_in_array() &&
4736 _interfaces->eq(p->_interfaces) &&
4737 TypeOopPtr::eq(p); // Check sub-type stuff
4738 }
4739
4740 //------------------------------hash-------------------------------------------
4741 // Type-specific hashing function.
4742 uint TypeInstPtr::hash(void) const {
4743 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4744 }
4745
4746 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4747 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4748 }
4749
4750
4751 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4752 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4753 }
4754
4755 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4756 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4757 }
4758
4759
4760 //------------------------------dump2------------------------------------------
4761 // Dump oop Type
4762 #ifndef PRODUCT
4763 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4777 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4778 char* buf = ss.as_string(/* c_heap= */false);
4779 StringUtils::replace_no_expand(buf, "\n", "");
4780 st->print_raw(buf);
4781 }
4782 case BotPTR:
4783 if (!WizardMode && !Verbose) {
4784 if( _klass_is_exact ) st->print(":exact");
4785 break;
4786 }
4787 case TopPTR:
4788 case AnyNull:
4789 case NotNull:
4790 st->print(":%s", ptr_msg[_ptr]);
4791 if( _klass_is_exact ) st->print(":exact");
4792 break;
4793 default:
4794 break;
4795 }
4796
4797 _offset.dump2(st);
4798
4799 st->print(" *");
4800
4801 if (flat_in_array() && !klass()->is_inlinetype()) {
4802 st->print(" (flat in array)");
4803 }
4804
4805 if (_instance_id == InstanceTop)
4806 st->print(",iid=top");
4807 else if (_instance_id != InstanceBot)
4808 st->print(",iid=%d",_instance_id);
4809
4810 dump_inline_depth(st);
4811 dump_speculative(st);
4812 }
4813 #endif
4814
4815 //------------------------------add_offset-------------------------------------
4816 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4817 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4818 _instance_id, add_offset_speculative(offset), _inline_depth);
4819 }
4820
4821 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4822 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4823 _instance_id, with_offset_speculative(offset), _inline_depth);
4824 }
4825
4826 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4827 if (_speculative == nullptr) {
4828 return this;
4829 }
4830 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4831 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4832 _instance_id, nullptr, _inline_depth);
4833 }
4834
4835 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4836 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
4837 }
4838
4839 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4840 if (!UseInlineDepthForSpeculativeTypes) {
4841 return this;
4842 }
4843 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4844 }
4845
4846 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4847 assert(is_known_instance(), "should be known");
4848 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4849 }
4850
4851 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4852 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4853 }
4854
4855 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4856 bool xk = klass_is_exact();
4857 ciInstanceKlass* ik = klass()->as_instance_klass();
4858 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4859 if (_interfaces->eq(ik)) {
4860 Compile* C = Compile::current();
4861 Dependencies* deps = C->dependencies();
4862 deps->assert_leaf_type(ik);
4863 xk = true;
4864 }
4865 }
4866 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4867 }
4868
4869 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) {
4870 static_assert(std::is_base_of<T2, T1>::value, "");
4871
4872 if (!this_one->is_instance_type(other)) {
4873 return false;
4874 }
4875
4876 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4877 return true;
4878 }
4879
4880 return this_one->klass()->is_subtype_of(other->klass()) &&
4881 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4882 }
4883
4884
4885 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4886 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4891 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4892 return true;
4893 }
4894
4895 if (this_one->is_instance_type(other)) {
4896 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4897 }
4898
4899 int dummy;
4900 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4901 if (this_top_or_bottom) {
4902 return false;
4903 }
4904
4905 const T1* other_ary = this_one->is_array_type(other);
4906 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4907 const TypePtr* this_elem = this_one->elem()->make_ptr();
4908 if (other_elem != nullptr && this_elem != nullptr) {
4909 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4910 }
4911 if (other_elem == nullptr && this_elem == nullptr) {
4912 return this_one->klass()->is_subtype_of(other->klass());
4913 }
4914
4915 return false;
4916 }
4917
4918 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4919 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4920 }
4921
4922 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4923 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4924 }
4925
4926 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4927 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4928 }
4929
4930 //=============================================================================
4931 // Convenience common pre-built types.
4932 const TypeAryPtr* TypeAryPtr::BOTTOM;
4933 const TypeAryPtr *TypeAryPtr::RANGE;
4934 const TypeAryPtr *TypeAryPtr::OOPS;
4935 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4936 const TypeAryPtr *TypeAryPtr::BYTES;
4937 const TypeAryPtr *TypeAryPtr::SHORTS;
4938 const TypeAryPtr *TypeAryPtr::CHARS;
4939 const TypeAryPtr *TypeAryPtr::INTS;
4940 const TypeAryPtr *TypeAryPtr::LONGS;
4941 const TypeAryPtr *TypeAryPtr::FLOATS;
4942 const TypeAryPtr *TypeAryPtr::DOUBLES;
4943 const TypeAryPtr *TypeAryPtr::INLINES;
4944
4945 //------------------------------make-------------------------------------------
4946 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4947 int instance_id, const TypePtr* speculative, int inline_depth) {
4948 assert(!(k == nullptr && ary->_elem->isa_int()),
4949 "integral arrays must be pre-equipped with a class");
4950 if (!xk) xk = ary->ary_must_be_exact();
4951 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4952 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4953 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4954 k = nullptr;
4955 }
4956 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4957 }
4958
4959 //------------------------------make-------------------------------------------
4960 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4961 int instance_id, const TypePtr* speculative, int inline_depth,
4962 bool is_autobox_cache) {
4963 assert(!(k == nullptr && ary->_elem->isa_int()),
4964 "integral arrays must be pre-equipped with a class");
4965 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4966 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4967 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4968 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4969 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4970 k = nullptr;
4971 }
4972 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4973 }
4974
4975 //------------------------------cast_to_ptr_type-------------------------------
4976 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4977 if( ptr == _ptr ) return this;
4978 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4979 }
4980
4981
4982 //-----------------------------cast_to_exactness-------------------------------
4983 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4984 if( klass_is_exact == _klass_is_exact ) return this;
4985 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4986 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4987 }
4988
4989 //-----------------------------cast_to_instance_id----------------------------
4990 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4991 if( instance_id == _instance_id ) return this;
4992 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4993 }
4994
4995
4996 //-----------------------------max_array_length-------------------------------
4997 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4998 jint TypeAryPtr::max_array_length(BasicType etype) {
4999 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5000 if (etype == T_NARROWOOP) {
5001 etype = T_OBJECT;
5002 } else if (etype == T_ILLEGAL) { // bottom[]
5003 etype = T_BYTE; // will produce conservatively high value
5004 } else {
5005 fatal("not an element type: %s", type2name(etype));
5006 }
5007 }
5008 return arrayOopDesc::max_array_length(etype);
5009 }
5010
5011 //-----------------------------narrow_size_type-------------------------------
5012 // Narrow the given size type to the index range for the given array base type.
5030 if (size->is_con()) {
5031 lo = hi;
5032 }
5033 chg = true;
5034 }
5035 // Negative length arrays will produce weird intermediate dead fast-path code
5036 if (lo > hi) {
5037 return TypeInt::ZERO;
5038 }
5039 if (!chg) {
5040 return size;
5041 }
5042 return TypeInt::make(lo, hi, Type::WidenMin);
5043 }
5044
5045 //-------------------------------cast_to_size----------------------------------
5046 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5047 assert(new_size != nullptr, "");
5048 new_size = narrow_size_type(new_size);
5049 if (new_size == size()) return this;
5050 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5051 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5052 }
5053
5054 //-------------------------------cast_to_not_flat------------------------------
5055 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5056 if (not_flat == is_not_flat()) {
5057 return this;
5058 }
5059 assert(!not_flat || !is_flat(), "inconsistency");
5060 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5061 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5062 // We keep the speculative part if it contains information about flat-/nullability.
5063 // Make sure it's removed if it's not better than the non-speculative type anymore.
5064 if (res->speculative() == res->remove_speculative()) {
5065 return res->remove_speculative();
5066 }
5067 return res;
5068 }
5069
5070 //-------------------------------cast_to_not_null_free-------------------------
5071 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5072 if (not_null_free == is_not_null_free()) {
5073 return this;
5074 }
5075 assert(!not_null_free || !is_null_free(), "inconsistency");
5076 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5077 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5078 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5079 // We keep the speculative part if it contains information about flat-/nullability.
5080 // Make sure it's removed if it's not better than the non-speculative type anymore.
5081 if (res->speculative() == res->remove_speculative()) {
5082 return res->remove_speculative();
5083 }
5084 return res;
5085 }
5086
5087 //---------------------------------update_properties---------------------------
5088 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5089 if ((from->is_flat() && is_not_flat()) ||
5090 (from->is_not_flat() && is_flat()) ||
5091 (from->is_null_free() && is_not_null_free()) ||
5092 (from->is_not_null_free() && is_null_free())) {
5093 return nullptr; // Inconsistent properties
5094 }
5095 const TypeAryPtr* res = this;
5096 if (from->is_not_null_free()) {
5097 res = res->cast_to_not_null_free();
5098 }
5099 if (from->is_not_flat()) {
5100 res = res->cast_to_not_flat();
5101 }
5102 return res;
5103 }
5104
5105 jint TypeAryPtr::flat_layout_helper() const {
5106 return klass()->as_flat_array_klass()->layout_helper();
5107 }
5108
5109 int TypeAryPtr::flat_elem_size() const {
5110 return klass()->as_flat_array_klass()->element_byte_size();
5111 }
5112
5113 int TypeAryPtr::flat_log_elem_size() const {
5114 return klass()->as_flat_array_klass()->log2_element_size();
5115 }
5116
5117 //------------------------------cast_to_stable---------------------------------
5118 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5119 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5120 return this;
5121
5122 const Type* elem = this->elem();
5123 const TypePtr* elem_ptr = elem->make_ptr();
5124
5125 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5126 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5127 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5128 }
5129
5130 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5131
5132 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5133 }
5134
5135 //-----------------------------stable_dimension--------------------------------
5136 int TypeAryPtr::stable_dimension() const {
5137 if (!is_stable()) return 0;
5138 int dim = 1;
5139 const TypePtr* elem_ptr = elem()->make_ptr();
5140 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5141 dim += elem_ptr->is_aryptr()->stable_dimension();
5142 return dim;
5143 }
5144
5145 //----------------------cast_to_autobox_cache-----------------------------------
5146 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5147 if (is_autobox_cache()) return this;
5148 const TypeOopPtr* etype = elem()->make_oopptr();
5149 if (etype == nullptr) return this;
5150 // The pointers in the autobox arrays are always non-null.
5151 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5152 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5153 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5154 }
5155
5156 //------------------------------eq---------------------------------------------
5157 // Structural equality check for Type representations
5158 bool TypeAryPtr::eq( const Type *t ) const {
5159 const TypeAryPtr *p = t->is_aryptr();
5160 return
5161 _ary == p->_ary && // Check array
5162 TypeOopPtr::eq(p) &&// Check sub-parts
5163 _field_offset == p->_field_offset;
5164 }
5165
5166 //------------------------------hash-------------------------------------------
5167 // Type-specific hashing function.
5168 uint TypeAryPtr::hash(void) const {
5169 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5170 }
5171
5172 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5173 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5174 }
5175
5176 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5177 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5178 }
5179
5180 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5181 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5182 }
5183 //------------------------------meet-------------------------------------------
5184 // Compute the MEET of two types. It returns a new Type object.
5185 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5186 // Perform a fast test for common case; meeting the same types together.
5187 if( this == t ) return this; // Meeting same type-rep?
5188 // Current "this->_base" is Pointer
5189 switch (t->base()) { // switch on original type
5196 case HalfFloatBot:
5197 case FloatTop:
5198 case FloatCon:
5199 case FloatBot:
5200 case DoubleTop:
5201 case DoubleCon:
5202 case DoubleBot:
5203 case NarrowOop:
5204 case NarrowKlass:
5205 case Bottom: // Ye Olde Default
5206 return Type::BOTTOM;
5207 case Top:
5208 return this;
5209
5210 default: // All else is a mistake
5211 typerr(t);
5212
5213 case OopPtr: { // Meeting to OopPtrs
5214 // Found a OopPtr type vs self-AryPtr type
5215 const TypeOopPtr *tp = t->is_oopptr();
5216 Offset offset = meet_offset(tp->offset());
5217 PTR ptr = meet_ptr(tp->ptr());
5218 int depth = meet_inline_depth(tp->inline_depth());
5219 const TypePtr* speculative = xmeet_speculative(tp);
5220 switch (tp->ptr()) {
5221 case TopPTR:
5222 case AnyNull: {
5223 int instance_id = meet_instance_id(InstanceTop);
5224 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5225 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5226 }
5227 case BotPTR:
5228 case NotNull: {
5229 int instance_id = meet_instance_id(tp->instance_id());
5230 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5231 }
5232 default: ShouldNotReachHere();
5233 }
5234 }
5235
5236 case AnyPtr: { // Meeting two AnyPtrs
5237 // Found an AnyPtr type vs self-AryPtr type
5238 const TypePtr *tp = t->is_ptr();
5239 Offset offset = meet_offset(tp->offset());
5240 PTR ptr = meet_ptr(tp->ptr());
5241 const TypePtr* speculative = xmeet_speculative(tp);
5242 int depth = meet_inline_depth(tp->inline_depth());
5243 switch (tp->ptr()) {
5244 case TopPTR:
5245 return this;
5246 case BotPTR:
5247 case NotNull:
5248 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5249 case Null:
5250 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5251 // else fall through to AnyNull
5252 case AnyNull: {
5253 int instance_id = meet_instance_id(InstanceTop);
5254 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5255 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5256 }
5257 default: ShouldNotReachHere();
5258 }
5259 }
5260
5261 case MetadataPtr:
5262 case KlassPtr:
5263 case InstKlassPtr:
5264 case AryKlassPtr:
5265 case RawPtr: return TypePtr::BOTTOM;
5266
5267 case AryPtr: { // Meeting 2 references?
5268 const TypeAryPtr *tap = t->is_aryptr();
5269 Offset off = meet_offset(tap->offset());
5270 Offset field_off = meet_field_offset(tap->field_offset());
5271 const Type* tm = _ary->meet_speculative(tap->_ary);
5272 const TypeAry* tary = tm->isa_ary();
5273 if (tary == nullptr) {
5274 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5275 return tm;
5276 }
5277 PTR ptr = meet_ptr(tap->ptr());
5278 int instance_id = meet_instance_id(tap->instance_id());
5279 const TypePtr* speculative = xmeet_speculative(tap);
5280 int depth = meet_inline_depth(tap->inline_depth());
5281
5282 ciKlass* res_klass = nullptr;
5283 bool res_xk = false;
5284 bool res_flat = false;
5285 bool res_not_flat = false;
5286 bool res_not_null_free = false;
5287 bool res_atomic = false;
5288 const Type* elem = tary->_elem;
5289 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5290 instance_id = InstanceBot;
5291 } else if (this->is_flat() != tap->is_flat()) {
5292 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5293 if (tary->_flat) {
5294 // Result is in a flat representation
5295 off = Offset(is_flat() ? offset() : tap->offset());
5296 field_off = is_flat() ? field_offset() : tap->field_offset();
5297 } else if (below_centerline(ptr)) {
5298 // Result is in a non-flat representation
5299 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5300 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5301 } else if (flat_offset() == tap->flat_offset()) {
5302 off = Offset(!is_flat() ? offset() : tap->offset());
5303 field_off = !is_flat() ? field_offset() : tap->field_offset();
5304 }
5305 }
5306
5307 ciObject* o = nullptr; // Assume not constant when done
5308 ciObject* this_oop = const_oop();
5309 ciObject* tap_oop = tap->const_oop();
5310 if (ptr == Constant) {
5311 if (this_oop != nullptr && tap_oop != nullptr &&
5312 this_oop->equals(tap_oop)) {
5313 o = tap_oop;
5314 } else if (above_centerline(_ptr)) {
5315 o = tap_oop;
5316 } else if (above_centerline(tap->_ptr)) {
5317 o = this_oop;
5318 } else {
5319 ptr = NotNull;
5320 }
5321 }
5322 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);
5323 }
5324
5325 // All arrays inherit from Object class
5326 case InstPtr: {
5327 const TypeInstPtr *tp = t->is_instptr();
5328 Offset offset = meet_offset(tp->offset());
5329 PTR ptr = meet_ptr(tp->ptr());
5330 int instance_id = meet_instance_id(tp->instance_id());
5331 const TypePtr* speculative = xmeet_speculative(tp);
5332 int depth = meet_inline_depth(tp->inline_depth());
5333 const TypeInterfaces* interfaces = meet_interfaces(tp);
5334 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5335 const TypeInterfaces* this_interfaces = _interfaces;
5336
5337 switch (ptr) {
5338 case TopPTR:
5339 case AnyNull: // Fall 'down' to dual of object klass
5340 // For instances when a subclass meets a superclass we fall
5341 // below the centerline when the superclass is exact. We need to
5342 // do the same here.
5343 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5344 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5345 } else {
5346 // cannot subclass, so the meet has to fall badly below the centerline
5347 ptr = NotNull;
5348 instance_id = InstanceBot;
5349 interfaces = this_interfaces->intersection_with(tp_interfaces);
5350 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5351 }
5352 case Constant:
5353 case NotNull:
5354 case BotPTR: // Fall down to object klass
5355 // LCA is object_klass, but if we subclass from the top we can do better
5356 if (above_centerline(tp->ptr())) {
5357 // If 'tp' is above the centerline and it is Object class
5358 // then we can subclass in the Java class hierarchy.
5359 // For instances when a subclass meets a superclass we fall
5360 // below the centerline when the superclass is exact. We need
5361 // to do the same here.
5362 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5363 // that is, my array type is a subtype of 'tp' klass
5364 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5365 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5366 }
5367 }
5368 // The other case cannot happen, since t cannot be a subtype of an array.
5369 // The meet falls down to Object class below centerline.
5370 if (ptr == Constant) {
5371 ptr = NotNull;
5372 }
5373 if (instance_id > 0) {
5374 instance_id = InstanceBot;
5375 }
5376 interfaces = this_interfaces->intersection_with(tp_interfaces);
5377 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5378 default: typerr(t);
5379 }
5380 }
5381 }
5382 return this; // Lint noise
5383 }
5384
5385
5386 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5387 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5388 int dummy;
5389 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5390 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5391 ciKlass* this_klass = this_ary->klass();
5392 ciKlass* other_klass = other_ary->klass();
5393 bool this_xk = this_ary->klass_is_exact();
5394 bool other_xk = other_ary->klass_is_exact();
5395 PTR this_ptr = this_ary->ptr();
5396 PTR other_ptr = other_ary->ptr();
5397 bool this_flat = this_ary->is_flat();
5398 bool this_not_flat = this_ary->is_not_flat();
5399 bool other_flat = other_ary->is_flat();
5400 bool other_not_flat = other_ary->is_not_flat();
5401 bool this_not_null_free = this_ary->is_not_null_free();
5402 bool other_not_null_free = other_ary->is_not_null_free();
5403 bool this_atomic = this_ary->is_atomic();
5404 bool other_atomic = other_ary->is_atomic();
5405 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5406 res_klass = nullptr;
5407 MeetResult result = SUBTYPE;
5408 res_flat = this_flat && other_flat;
5409 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5410 res_not_flat = this_not_flat && other_not_flat;
5411 res_not_null_free = this_not_null_free && other_not_null_free;
5412 res_atomic = this_atomic && other_atomic;
5413
5414 if (elem->isa_int()) {
5415 // Integral array element types have irrelevant lattice relations.
5416 // It is the klass that determines array layout, not the element type.
5417 if (this_top_or_bottom) {
5418 res_klass = other_klass;
5419 } else if (other_top_or_bottom || other_klass == this_klass) {
5420 res_klass = this_klass;
5421 } else {
5422 // Something like byte[int+] meets char[int+].
5423 // This must fall to bottom, not (int[-128..65535])[int+].
5424 // instance_id = InstanceBot;
5425 elem = Type::BOTTOM;
5426 result = NOT_SUBTYPE;
5427 if (above_centerline(ptr) || ptr == Constant) {
5428 ptr = NotNull;
5429 res_xk = false;
5430 return NOT_SUBTYPE;
5431 }
5432 }
5433 } else {// Non integral arrays.
5434 // Must fall to bottom if exact klasses in upper lattice
5435 // are not equal or super klass is exact.
5436 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5437 // meet with top[] and bottom[] are processed further down:
5438 !this_top_or_bottom && !other_top_or_bottom &&
5439 // both are exact and not equal:
5441 // 'tap' is exact and super or unrelated:
5442 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5443 // 'this' is exact and super or unrelated:
5444 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5445 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5446 elem = Type::BOTTOM;
5447 }
5448 ptr = NotNull;
5449 res_xk = false;
5450 return NOT_SUBTYPE;
5451 }
5452 }
5453
5454 res_xk = false;
5455 switch (other_ptr) {
5456 case AnyNull:
5457 case TopPTR:
5458 // Compute new klass on demand, do not use tap->_klass
5459 if (below_centerline(this_ptr)) {
5460 res_xk = this_xk;
5461 if (this_ary->is_flat()) {
5462 elem = this_ary->elem();
5463 }
5464 } else {
5465 res_xk = (other_xk || this_xk);
5466 }
5467 break;
5468 case Constant: {
5469 if (this_ptr == Constant && same_nullness) {
5470 // Only exact if same nullness since:
5471 // null-free [LMyValue <: nullable [LMyValue.
5472 res_xk = true;
5473 } else if (above_centerline(this_ptr)) {
5474 res_xk = true;
5475 } else {
5476 // Only precise for identical arrays
5477 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5478 // Even though MyValue is final, [LMyValue is only exact if the array
5479 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5480 if (res_xk && !res_null_free && !res_not_null_free) {
5481 res_xk = false;
5482 }
5483 }
5484 break;
5485 }
5486 case NotNull:
5487 case BotPTR:
5488 // Compute new klass on demand, do not use tap->_klass
5489 if (above_centerline(this_ptr)) {
5490 res_xk = other_xk;
5491 if (other_ary->is_flat()) {
5492 elem = other_ary->elem();
5493 }
5494 } else {
5495 res_xk = (other_xk && this_xk) &&
5496 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5497 // Even though MyValue is final, [LMyValue is only exact if the array
5498 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5499 if (res_xk && !res_null_free && !res_not_null_free) {
5500 res_xk = false;
5501 }
5502 }
5503 break;
5504 default: {
5505 ShouldNotReachHere();
5506 return result;
5507 }
5508 }
5509 return result;
5510 }
5511
5512
5513 //------------------------------xdual------------------------------------------
5514 // Dual: compute field-by-field dual
5515 const Type *TypeAryPtr::xdual() const {
5516 bool xk = _klass_is_exact;
5517 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());
5518 }
5519
5520 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5521 return _field_offset.meet(offset);
5522 }
5523
5524 //------------------------------dual_offset------------------------------------
5525 Type::Offset TypeAryPtr::dual_field_offset() const {
5526 return _field_offset.dual();
5527 }
5528
5529 //------------------------------dump2------------------------------------------
5530 #ifndef PRODUCT
5531 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5532 _ary->dump2(d,depth,st);
5533 _interfaces->dump(st);
5534
5535 switch( _ptr ) {
5536 case Constant:
5537 const_oop()->print(st);
5538 break;
5539 case BotPTR:
5540 if (!WizardMode && !Verbose) {
5541 if( _klass_is_exact ) st->print(":exact");
5542 break;
5543 }
5544 case TopPTR:
5545 case AnyNull:
5546 case NotNull:
5547 st->print(":%s", ptr_msg[_ptr]);
5548 if( _klass_is_exact ) st->print(":exact");
5549 break;
5550 default:
5551 break;
5552 }
5553
5554 if (is_flat()) {
5555 st->print(":flat");
5556 st->print("(");
5557 _field_offset.dump2(st);
5558 st->print(")");
5559 } else if (is_not_flat()) {
5560 st->print(":not_flat");
5561 }
5562 if (is_null_free()) {
5563 st->print(":null free");
5564 }
5565 if (is_atomic()) {
5566 st->print(":atomic");
5567 }
5568 if (Verbose) {
5569 if (is_not_flat()) {
5570 st->print(":not flat");
5571 }
5572 if (is_not_null_free()) {
5573 st->print(":nullable");
5574 }
5575 }
5576 if (offset() != 0) {
5577 BasicType basic_elem_type = elem()->basic_type();
5578 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5579 if( _offset == Offset::top ) st->print("+undefined");
5580 else if( _offset == Offset::bottom ) st->print("+any");
5581 else if( offset() < header_size ) st->print("+%d", offset());
5582 else {
5583 if (basic_elem_type == T_ILLEGAL) {
5584 st->print("+any");
5585 } else {
5586 int elem_size = type2aelembytes(basic_elem_type);
5587 st->print("[%d]", (offset() - header_size)/elem_size);
5588 }
5589 }
5590 }
5591 st->print(" *");
5592 if (_instance_id == InstanceTop)
5593 st->print(",iid=top");
5594 else if (_instance_id != InstanceBot)
5595 st->print(",iid=%d",_instance_id);
5596
5597 dump_inline_depth(st);
5598 dump_speculative(st);
5599 }
5600 #endif
5601
5602 bool TypeAryPtr::empty(void) const {
5603 if (_ary->empty()) return true;
5604 // FIXME: Does this belong here? Or in the meet code itself?
5605 if (is_flat() && is_not_flat()) {
5606 return true;
5607 }
5608 return TypeOopPtr::empty();
5609 }
5610
5611 //------------------------------add_offset-------------------------------------
5612 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5613 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);
5614 }
5615
5616 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5617 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);
5618 }
5619
5620 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5621 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5622 }
5623
5624 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5625 if (_speculative == nullptr) {
5626 return this;
5627 }
5628 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5629 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);
5630 }
5631
5632 const Type* TypeAryPtr::cleanup_speculative() const {
5633 if (speculative() == nullptr) {
5634 return this;
5635 }
5636 // Keep speculative part if it contains information about flat-/nullability
5637 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5638 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5639 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5640 return this;
5641 }
5642 return TypeOopPtr::cleanup_speculative();
5643 }
5644
5645 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5646 if (!UseInlineDepthForSpeculativeTypes) {
5647 return this;
5648 }
5649 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5650 }
5651
5652 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5653 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);
5654 }
5655
5656 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5657 int adj = 0;
5658 if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5659 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5660 adj = _offset.get();
5661 offset += _offset.get();
5662 }
5663 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5664 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5665 offset += _field_offset.get();
5666 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5667 offset += header;
5668 }
5669 }
5670 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5671 // Try to get the field of the inline type array element we are pointing to
5672 ciInlineKlass* vk = elem()->inline_klass();
5673 int shift = flat_log_elem_size();
5674 int mask = (1 << shift) - 1;
5675 intptr_t field_offset = ((offset - header) & mask);
5676 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5677 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5678 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5679 }
5680 }
5681 }
5682 return add_offset(offset - adj);
5683 }
5684
5685 // Return offset incremented by field_offset for flat inline type arrays
5686 int TypeAryPtr::flat_offset() const {
5687 int offset = _offset.get();
5688 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5689 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5690 offset += _field_offset.get();
5691 }
5692 return offset;
5693 }
5694
5695 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5696 assert(is_known_instance(), "should be known");
5697 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5698 }
5699
5700 //=============================================================================
5701
5702
5703 //------------------------------hash-------------------------------------------
5704 // Type-specific hashing function.
5705 uint TypeNarrowPtr::hash(void) const {
5706 return _ptrtype->hash() + 7;
5707 }
5708
5709 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5710 return _ptrtype->singleton();
5711 }
5712
5713 bool TypeNarrowPtr::empty(void) const {
5714 return _ptrtype->empty();
5715 }
5716
5717 intptr_t TypeNarrowPtr::get_con() const {
5718 return _ptrtype->get_con();
5719 }
5720
5721 bool TypeNarrowPtr::eq( const Type *t ) const {
5722 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5776 case HalfFloatTop:
5777 case HalfFloatCon:
5778 case HalfFloatBot:
5779 case FloatTop:
5780 case FloatCon:
5781 case FloatBot:
5782 case DoubleTop:
5783 case DoubleCon:
5784 case DoubleBot:
5785 case AnyPtr:
5786 case RawPtr:
5787 case OopPtr:
5788 case InstPtr:
5789 case AryPtr:
5790 case MetadataPtr:
5791 case KlassPtr:
5792 case InstKlassPtr:
5793 case AryKlassPtr:
5794 case NarrowOop:
5795 case NarrowKlass:
5796 case Bottom: // Ye Olde Default
5797 return Type::BOTTOM;
5798 case Top:
5799 return this;
5800
5801 default: // All else is a mistake
5802 typerr(t);
5803
5804 } // End of switch
5805
5806 return this;
5807 }
5808
5809 #ifndef PRODUCT
5810 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5811 _ptrtype->dump2(d, depth, st);
5812 }
5813 #endif
5814
5815 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5859 return (one == two) && TypePtr::eq(t);
5860 } else {
5861 return one->equals(two) && TypePtr::eq(t);
5862 }
5863 }
5864
5865 //------------------------------hash-------------------------------------------
5866 // Type-specific hashing function.
5867 uint TypeMetadataPtr::hash(void) const {
5868 return
5869 (metadata() ? metadata()->hash() : 0) +
5870 TypePtr::hash();
5871 }
5872
5873 //------------------------------singleton--------------------------------------
5874 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5875 // constants
5876 bool TypeMetadataPtr::singleton(void) const {
5877 // detune optimizer to not generate constant metadata + constant offset as a constant!
5878 // TopPTR, Null, AnyNull, Constant are all singletons
5879 return (offset() == 0) && !below_centerline(_ptr);
5880 }
5881
5882 //------------------------------add_offset-------------------------------------
5883 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5884 return make( _ptr, _metadata, xadd_offset(offset));
5885 }
5886
5887 //-----------------------------filter------------------------------------------
5888 // Do not allow interface-vs.-noninterface joins to collapse to top.
5889 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5890 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5891 if (ft == nullptr || ft->empty())
5892 return Type::TOP; // Canonical empty value
5893 return ft;
5894 }
5895
5896 //------------------------------get_con----------------------------------------
5897 intptr_t TypeMetadataPtr::get_con() const {
5898 assert( _ptr == Null || _ptr == Constant, "" );
5899 assert(offset() >= 0, "");
5900
5901 if (offset() != 0) {
5902 // After being ported to the compiler interface, the compiler no longer
5903 // directly manipulates the addresses of oops. Rather, it only has a pointer
5904 // to a handle at compile time. This handle is embedded in the generated
5905 // code and dereferenced at the time the nmethod is made. Until that time,
5906 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5907 // have access to the addresses!). This does not seem to currently happen,
5908 // but this assertion here is to help prevent its occurrence.
5909 tty->print_cr("Found oop constant with non-zero offset");
5910 ShouldNotReachHere();
5911 }
5912
5913 return (intptr_t)metadata()->constant_encoding();
5914 }
5915
5916 //------------------------------cast_to_ptr_type-------------------------------
5917 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5918 if( ptr == _ptr ) return this;
5919 return make(ptr, metadata(), _offset);
5920 }
5921
5935 case HalfFloatBot:
5936 case FloatTop:
5937 case FloatCon:
5938 case FloatBot:
5939 case DoubleTop:
5940 case DoubleCon:
5941 case DoubleBot:
5942 case NarrowOop:
5943 case NarrowKlass:
5944 case Bottom: // Ye Olde Default
5945 return Type::BOTTOM;
5946 case Top:
5947 return this;
5948
5949 default: // All else is a mistake
5950 typerr(t);
5951
5952 case AnyPtr: {
5953 // Found an AnyPtr type vs self-OopPtr type
5954 const TypePtr *tp = t->is_ptr();
5955 Offset offset = meet_offset(tp->offset());
5956 PTR ptr = meet_ptr(tp->ptr());
5957 switch (tp->ptr()) {
5958 case Null:
5959 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5960 // else fall through:
5961 case TopPTR:
5962 case AnyNull: {
5963 return make(ptr, _metadata, offset);
5964 }
5965 case BotPTR:
5966 case NotNull:
5967 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5968 default: typerr(t);
5969 }
5970 }
5971
5972 case RawPtr:
5973 case KlassPtr:
5974 case InstKlassPtr:
5975 case AryKlassPtr:
5976 case OopPtr:
5977 case InstPtr:
5978 case AryPtr:
5979 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5980
5981 case MetadataPtr: {
5982 const TypeMetadataPtr *tp = t->is_metadataptr();
5983 Offset offset = meet_offset(tp->offset());
5984 PTR tptr = tp->ptr();
5985 PTR ptr = meet_ptr(tptr);
5986 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5987 if (tptr == TopPTR || _ptr == TopPTR ||
5988 metadata()->equals(tp->metadata())) {
5989 return make(ptr, md, offset);
5990 }
5991 // metadata is different
5992 if( ptr == Constant ) { // Cannot be equal constants, so...
5993 if( tptr == Constant && _ptr != Constant) return t;
5994 if( _ptr == Constant && tptr != Constant) return this;
5995 ptr = NotNull; // Fall down in lattice
5996 }
5997 return make(ptr, nullptr, offset);
5998 break;
5999 }
6000 } // End of switch
6001 return this; // Return the double constant
6002 }
6003
6004
6005 //------------------------------xdual------------------------------------------
6006 // Dual of a pure metadata pointer.
6007 const Type *TypeMetadataPtr::xdual() const {
6008 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6009 }
6010
6011 //------------------------------dump2------------------------------------------
6012 #ifndef PRODUCT
6013 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6014 st->print("metadataptr:%s", ptr_msg[_ptr]);
6015 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
6016 switch (offset()) {
6017 case OffsetTop: st->print("+top"); break;
6018 case OffsetBot: st->print("+any"); break;
6019 case 0: break;
6020 default: st->print("+%d",offset()); break;
6021 }
6022 }
6023 #endif
6024
6025
6026 //=============================================================================
6027 // Convenience common pre-built type.
6028 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6029
6030 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6031 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6032 }
6033
6034 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6035 return make(Constant, m, Offset(0));
6036 }
6037 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6038 return make(Constant, m, Offset(0));
6039 }
6040
6041 //------------------------------make-------------------------------------------
6042 // Create a meta data constant
6043 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6044 assert(m == nullptr || !m->is_klass(), "wrong type");
6045 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6046 }
6047
6048
6049 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6050 const Type* elem = _ary->_elem;
6051 bool xk = klass_is_exact();
6052 if (elem->make_oopptr() != nullptr) {
6053 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6054 if (elem->is_klassptr()->klass_is_exact() &&
6055 // Even though MyValue is final, [LMyValue is only exact if the array
6056 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6057 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6058 // If so, we should add '|| is_not_null_free()'
6059 (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
6060 xk = true;
6061 }
6062 }
6063 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());
6064 }
6065
6066 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6067 if (klass->is_instance_klass()) {
6068 return TypeInstKlassPtr::make(klass, interface_handling);
6069 }
6070 return TypeAryKlassPtr::make(klass, interface_handling);
6071 }
6072
6073 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
6074 if (klass->is_instance_klass()) {
6075 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
6076 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
6077 }
6078 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
6079 }
6080
6081 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6082 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6083 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6084 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6085 }
6086
6087 // Is there a single ciKlass* that can represent that type?
6088 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6089 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6090 if (_interfaces->empty()) {
6091 return _klass;
6092 }
6093 if (_klass != ciEnv::current()->Object_klass()) {
6094 if (_interfaces->eq(_klass->as_instance_klass())) {
6095 return _klass;
6096 }
6097 return nullptr;
6098 }
6099 return _interfaces->exact_klass();
6100 }
6101
6102 //------------------------------eq---------------------------------------------
6103 // Structural equality check for Type representations
6104 bool TypeKlassPtr::eq(const Type *t) const {
6105 const TypeKlassPtr *p = t->is_klassptr();
6106 return
6107 _interfaces->eq(p->_interfaces) &&
6108 TypePtr::eq(p);
6109 }
6110
6111 //------------------------------hash-------------------------------------------
6112 // Type-specific hashing function.
6113 uint TypeKlassPtr::hash(void) const {
6114 return TypePtr::hash() + _interfaces->hash();
6115 }
6116
6117 //------------------------------singleton--------------------------------------
6118 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6119 // constants
6120 bool TypeKlassPtr::singleton(void) const {
6121 // detune optimizer to not generate constant klass + constant offset as a constant!
6122 // TopPTR, Null, AnyNull, Constant are all singletons
6123 return (offset() == 0) && !below_centerline(_ptr);
6124 }
6125
6126 // Do not allow interface-vs.-noninterface joins to collapse to top.
6127 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6128 // logic here mirrors the one from TypeOopPtr::filter. See comments
6129 // there.
6130 const Type* ft = join_helper(kills, include_speculative);
6131
6132 if (ft->empty()) {
6133 return Type::TOP; // Canonical empty value
6134 }
6135
6136 return ft;
6137 }
6138
6139 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6140 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6141 return _interfaces->union_with(other->_interfaces);
6142 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6143 return other->_interfaces;
6144 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6145 return _interfaces;
6146 }
6147 return _interfaces->intersection_with(other->_interfaces);
6148 }
6149
6150 //------------------------------get_con----------------------------------------
6151 intptr_t TypeKlassPtr::get_con() const {
6152 assert( _ptr == Null || _ptr == Constant, "" );
6153 assert( offset() >= 0, "" );
6154
6155 if (offset() != 0) {
6156 // After being ported to the compiler interface, the compiler no longer
6157 // directly manipulates the addresses of oops. Rather, it only has a pointer
6158 // to a handle at compile time. This handle is embedded in the generated
6159 // code and dereferenced at the time the nmethod is made. Until that time,
6160 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6161 // have access to the addresses!). This does not seem to currently happen,
6162 // but this assertion here is to help prevent its occurrence.
6163 tty->print_cr("Found oop constant with non-zero offset");
6164 ShouldNotReachHere();
6165 }
6166
6167 ciKlass* k = exact_klass();
6168
6169 return (intptr_t)k->constant_encoding();
6170 }
6171
6172 //------------------------------dump2------------------------------------------
6173 // Dump Klass Type
6174 #ifndef PRODUCT
6175 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6179 case NotNull:
6180 {
6181 const char *name = klass()->name()->as_utf8();
6182 if (name) {
6183 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6184 } else {
6185 ShouldNotReachHere();
6186 }
6187 _interfaces->dump(st);
6188 }
6189 case BotPTR:
6190 if (!WizardMode && !Verbose && _ptr != Constant) break;
6191 case TopPTR:
6192 case AnyNull:
6193 st->print(":%s", ptr_msg[_ptr]);
6194 if (_ptr == Constant) st->print(":exact");
6195 break;
6196 default:
6197 break;
6198 }
6199 if (Verbose) {
6200 if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");
6201 }
6202 _offset.dump2(st);
6203 st->print(" *");
6204
6205 if (flat_in_array() && !klass()->is_inlinetype()) {
6206 st->print(" (flat in array)");
6207 }
6208 }
6209 #endif
6210
6211 //=============================================================================
6212 // Convenience common pre-built types.
6213
6214 // Not-null object klass or below
6215 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6216 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6217
6218 bool TypeInstKlassPtr::eq(const Type *t) const {
6219 const TypeKlassPtr *p = t->is_klassptr();
6220 return
6221 klass()->equals(p->klass()) &&
6222 flat_in_array() == p->flat_in_array() &&
6223 TypeKlassPtr::eq(p);
6224 }
6225
6226 uint TypeInstKlassPtr::hash(void) const {
6227 return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6228 }
6229
6230 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6231 flat_in_array = flat_in_array || k->maybe_flat_in_array();
6232
6233 TypeInstKlassPtr *r =
6234 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6235
6236 return r;
6237 }
6238
6239 //------------------------------add_offset-------------------------------------
6240 // Access internals of klass object
6241 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6242 return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6243 }
6244
6245 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6246 return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6247 }
6248
6249 //------------------------------cast_to_ptr_type-------------------------------
6250 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6251 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6252 if( ptr == _ptr ) return this;
6253 return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6254 }
6255
6256
6257 bool TypeInstKlassPtr::must_be_exact() const {
6258 if (!_klass->is_loaded()) return false;
6259 ciInstanceKlass* ik = _klass->as_instance_klass();
6260 if (ik->is_final()) return true; // cannot clear xk
6261 return false;
6262 }
6263
6264 //-----------------------------cast_to_exactness-------------------------------
6265 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6266 if (klass_is_exact == (_ptr == Constant)) return this;
6267 if (must_be_exact()) return this;
6268 ciKlass* k = klass();
6269 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6270 }
6271
6272
6273 //-----------------------------as_instance_type--------------------------------
6274 // Corresponding type for an instance of the given class.
6275 // It will be NotNull, and exact if and only if the klass type is exact.
6276 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6277 ciKlass* k = klass();
6278 bool xk = klass_is_exact();
6279 Compile* C = Compile::current();
6280 Dependencies* deps = C->dependencies();
6281 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6282 // Element is an instance
6283 bool klass_is_exact = false;
6284 const TypeInterfaces* interfaces = _interfaces;
6285 if (k->is_loaded()) {
6286 // Try to set klass_is_exact.
6287 ciInstanceKlass* ik = k->as_instance_klass();
6288 klass_is_exact = ik->is_final();
6289 if (!klass_is_exact && klass_change
6290 && deps != nullptr && UseUniqueSubclasses) {
6291 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6292 if (sub != nullptr) {
6293 if (_interfaces->eq(sub)) {
6294 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6295 k = ik = sub;
6296 xk = sub->is_final();
6297 }
6298 }
6299 }
6300 }
6301 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6302 }
6303
6304 //------------------------------xmeet------------------------------------------
6305 // Compute the MEET of two types, return a new Type object.
6306 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6307 // Perform a fast test for common case; meeting the same types together.
6308 if( this == t ) return this; // Meeting same type-rep?
6309
6310 // Current "this->_base" is Pointer
6311 switch (t->base()) { // switch on original type
6312
6313 case Int: // Mixing ints & oops happens when javac
6314 case Long: // reuses local variables
6315 case HalfFloatTop:
6316 case HalfFloatCon:
6317 case HalfFloatBot:
6318 case FloatTop:
6319 case FloatCon:
6320 case FloatBot:
6321 case DoubleTop:
6322 case DoubleCon:
6323 case DoubleBot:
6324 case NarrowOop:
6325 case NarrowKlass:
6326 case Bottom: // Ye Olde Default
6327 return Type::BOTTOM;
6328 case Top:
6329 return this;
6330
6331 default: // All else is a mistake
6332 typerr(t);
6333
6334 case AnyPtr: { // Meeting to AnyPtrs
6335 // Found an AnyPtr type vs self-KlassPtr type
6336 const TypePtr *tp = t->is_ptr();
6337 Offset offset = meet_offset(tp->offset());
6338 PTR ptr = meet_ptr(tp->ptr());
6339 switch (tp->ptr()) {
6340 case TopPTR:
6341 return this;
6342 case Null:
6343 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6344 case AnyNull:
6345 return make(ptr, klass(), _interfaces, offset, flat_in_array());
6346 case BotPTR:
6347 case NotNull:
6348 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6349 default: typerr(t);
6350 }
6351 }
6352
6353 case RawPtr:
6354 case MetadataPtr:
6355 case OopPtr:
6356 case AryPtr: // Meet with AryPtr
6357 case InstPtr: // Meet with InstPtr
6358 return TypePtr::BOTTOM;
6359
6360 //
6361 // A-top }
6362 // / | \ } Tops
6363 // B-top A-any C-top }
6364 // | / | \ | } Any-nulls
6365 // B-any | C-any }
6366 // | | |
6367 // B-con A-con C-con } constants; not comparable across classes
6368 // | | |
6369 // B-not | C-not }
6370 // | \ | / | } not-nulls
6371 // B-bot A-not C-bot }
6372 // \ | / } Bottoms
6373 // A-bot }
6374 //
6375
6376 case InstKlassPtr: { // Meet two KlassPtr types
6377 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6378 Offset off = meet_offset(tkls->offset());
6379 PTR ptr = meet_ptr(tkls->ptr());
6380 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6381
6382 ciKlass* res_klass = nullptr;
6383 bool res_xk = false;
6384 bool res_flat_in_array = false;
6385 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6386 case UNLOADED:
6387 ShouldNotReachHere();
6388 case SUBTYPE:
6389 case NOT_SUBTYPE:
6390 case LCA:
6391 case QUICK: {
6392 assert(res_xk == (ptr == Constant), "");
6393 const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6394 return res;
6395 }
6396 default:
6397 ShouldNotReachHere();
6398 }
6399 } // End of case KlassPtr
6400 case AryKlassPtr: { // All arrays inherit from Object class
6401 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6402 Offset offset = meet_offset(tp->offset());
6403 PTR ptr = meet_ptr(tp->ptr());
6404 const TypeInterfaces* interfaces = meet_interfaces(tp);
6405 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6406 const TypeInterfaces* this_interfaces = _interfaces;
6407
6408 switch (ptr) {
6409 case TopPTR:
6410 case AnyNull: // Fall 'down' to dual of object klass
6411 // For instances when a subclass meets a superclass we fall
6412 // below the centerline when the superclass is exact. We need to
6413 // do the same here.
6414 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6415 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_vm_type());
6416 } else {
6417 // cannot subclass, so the meet has to fall badly below the centerline
6418 ptr = NotNull;
6419 interfaces = _interfaces->intersection_with(tp->_interfaces);
6420 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6421 }
6422 case Constant:
6423 case NotNull:
6424 case BotPTR: // Fall down to object klass
6425 // LCA is object_klass, but if we subclass from the top we can do better
6426 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6427 // If 'this' (InstPtr) is above the centerline and it is Object class
6428 // then we can subclass in the Java class hierarchy.
6429 // For instances when a subclass meets a superclass we fall
6430 // below the centerline when the superclass is exact. We need
6431 // to do the same here.
6432 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6433 // that is, tp's array type is a subtype of my klass
6434 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_vm_type());
6435 }
6436 }
6437 // The other case cannot happen, since I cannot be a subtype of an array.
6438 // The meet falls down to Object class below centerline.
6439 if( ptr == Constant )
6440 ptr = NotNull;
6441 interfaces = this_interfaces->intersection_with(tp_interfaces);
6442 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6443 default: typerr(t);
6444 }
6445 }
6446
6447 } // End of switch
6448 return this; // Return the double constant
6449 }
6450
6451 //------------------------------xdual------------------------------------------
6452 // Dual: compute field-by-field dual
6453 const Type *TypeInstKlassPtr::xdual() const {
6454 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6455 }
6456
6457 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) {
6458 static_assert(std::is_base_of<T2, T1>::value, "");
6459 if (!this_one->is_loaded() || !other->is_loaded()) {
6460 return false;
6461 }
6462 if (!this_one->is_instance_type(other)) {
6463 return false;
6464 }
6465
6466 if (!other_exact) {
6467 return false;
6468 }
6469
6470 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6471 return true;
6472 }
6473
6474 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6548 const TypeInterfaces* interfaces = _interfaces;
6549 if (k->is_loaded()) {
6550 ciInstanceKlass* ik = k->as_instance_klass();
6551 bool klass_is_exact = ik->is_final();
6552 if (!klass_is_exact &&
6553 deps != nullptr) {
6554 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6555 if (sub != nullptr) {
6556 if (_interfaces->eq(sub)) {
6557 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6558 k = ik = sub;
6559 klass_is_exact = sub->is_final();
6560 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6561 }
6562 }
6563 }
6564 }
6565 return this;
6566 }
6567
6568 bool TypeInstKlassPtr::can_be_inline_array() const {
6569 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6570 }
6571
6572 bool TypeAryKlassPtr::can_be_inline_array() const {
6573 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6574 }
6575
6576 bool TypeInstPtr::can_be_inline_array() const {
6577 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6578 }
6579
6580 bool TypeAryPtr::can_be_inline_array() const {
6581 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6582 }
6583
6584 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 vm_type) {
6585 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, vm_type))->hashcons();
6586 }
6587
6588 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 vm_type) {
6589 if (k->is_obj_array_klass()) {
6590 // Element is an object array. Recursively call ourself.
6591 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6592 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6593 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, flat, null_free, atomic, vm_type);
6594 } else if (k->is_type_array_klass()) {
6595 // Element is an typeArray
6596 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6597 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic);
6598 } else if (k->is_flat_array_klass()) {
6599 ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6600 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6601 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, vm_type);
6602 } else {
6603 ShouldNotReachHere();
6604 return nullptr;
6605 }
6606 }
6607
6608 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool vm_type) {
6609 bool flat = k->is_flat_array_klass();
6610 bool null_free = k->as_array_klass()->is_elem_null_free();
6611 bool atomic = k->as_array_klass()->is_elem_atomic();
6612
6613 bool not_inline = k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false);
6614 bool not_null_free = (ptr == Constant) ? !null_free : not_inline;
6615 bool not_flat = (ptr == Constant) ? !flat : (!UseArrayFlattening || not_inline ||
6616 (k->as_array_klass()->element_klass() != nullptr &&
6617 k->as_array_klass()->element_klass()->is_inlinetype() &&
6618 !k->as_array_klass()->element_klass()->maybe_flat_in_array()));
6619
6620 return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, flat, null_free, atomic, vm_type);
6621 }
6622
6623 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling, bool vm_type) {
6624 return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling, vm_type);
6625 }
6626
6627 const TypeAryKlassPtr* TypeAryKlassPtr::get_vm_type(bool vm_type) const {
6628 ciKlass* eklass = elem()->is_klassptr()->exact_klass_helper();
6629 if (elem()->isa_aryklassptr()) {
6630 eklass = exact_klass()->as_obj_array_klass()->element_klass();
6631 }
6632 ciKlass* array_klass = ciArrayKlass::make(eklass, is_null_free(), is_atomic(), true);
6633 return make(_ptr, array_klass, Offset(0), trust_interfaces, vm_type);
6634 }
6635
6636 //------------------------------eq---------------------------------------------
6637 // Structural equality check for Type representations
6638 bool TypeAryKlassPtr::eq(const Type *t) const {
6639 const TypeAryKlassPtr *p = t->is_aryklassptr();
6640 return
6641 _elem == p->_elem && // Check array
6642 _flat == p->_flat &&
6643 _not_flat == p->_not_flat &&
6644 _null_free == p->_null_free &&
6645 _not_null_free == p->_not_null_free &&
6646 _atomic == p->_atomic &&
6647 _vm_type == p->_vm_type &&
6648 TypeKlassPtr::eq(p); // Check sub-parts
6649 }
6650
6651 //------------------------------hash-------------------------------------------
6652 // Type-specific hashing function.
6653 uint TypeAryKlassPtr::hash(void) const {
6654 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6655 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0) + (uint)(_vm_type ? 48 : 0);
6656 }
6657
6658 //----------------------compute_klass------------------------------------------
6659 // Compute the defining klass for this class
6660 ciKlass* TypeAryPtr::compute_klass() const {
6661 // Compute _klass based on element type.
6662 ciKlass* k_ary = nullptr;
6663 const TypeInstPtr *tinst;
6664 const TypeAryPtr *tary;
6665 const Type* el = elem();
6666 if (el->isa_narrowoop()) {
6667 el = el->make_ptr();
6668 }
6669
6670 // Get element klass
6671 if (is_flat() && el->is_inlinetypeptr()) {
6672 // Klass is required by TypeAryPtr::flat_layout_helper() and others
6673 if (el->inline_klass() != nullptr) {
6674 // TODO 8350865 We assume atomic if the atomic layout is available, use is_atomic() here
6675 bool atomic = is_null_free() ? el->inline_klass()->has_atomic_layout() : el->inline_klass()->has_nullable_atomic_layout();
6676 k_ary = ciArrayKlass::make(el->inline_klass(), is_null_free(), atomic, true);
6677 }
6678 } else if ((tinst = el->isa_instptr()) != nullptr) {
6679 // Leave k_ary at nullptr.
6680 } else if ((tary = el->isa_aryptr()) != nullptr) {
6681 // Leave k_ary at nullptr.
6682 } else if ((el->base() == Type::Top) ||
6683 (el->base() == Type::Bottom)) {
6684 // element type of Bottom occurs from meet of basic type
6685 // and object; Top occurs when doing join on Bottom.
6686 // Leave k_ary at null.
6687 } else {
6688 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6689 // Compute array klass directly from basic type
6690 k_ary = ciTypeArrayKlass::make(el->basic_type());
6691 }
6692 return k_ary;
6693 }
6694
6695 //------------------------------klass------------------------------------------
6696 // Return the defining klass for this class
6697 ciKlass* TypeAryPtr::klass() const {
6698 if( _klass ) return _klass; // Return cached value, if possible
6699
6700 // Oops, need to compute _klass and cache it
6701 ciKlass* k_ary = compute_klass();
6709 // type TypeAryPtr::OOPS. This Type is shared between all
6710 // active compilations. However, the ciKlass which represents
6711 // this Type is *not* shared between compilations, so caching
6712 // this value would result in fetching a dangling pointer.
6713 //
6714 // Recomputing the underlying ciKlass for each request is
6715 // a bit less efficient than caching, but calls to
6716 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6717 ((TypeAryPtr*)this)->_klass = k_ary;
6718 }
6719 return k_ary;
6720 }
6721
6722 // Is there a single ciKlass* that can represent that type?
6723 ciKlass* TypeAryPtr::exact_klass_helper() const {
6724 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6725 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6726 if (k == nullptr) {
6727 return nullptr;
6728 }
6729 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), is_flat() || is_null_free());
6730 return k;
6731 }
6732
6733 return klass();
6734 }
6735
6736 const Type* TypeAryPtr::base_element_type(int& dims) const {
6737 const Type* elem = this->elem();
6738 dims = 1;
6739 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6740 elem = elem->make_ptr()->is_aryptr()->elem();
6741 dims++;
6742 }
6743 return elem;
6744 }
6745
6746 //------------------------------add_offset-------------------------------------
6747 // Access internals of klass object
6748 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6749 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _vm_type);
6750 }
6751
6752 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6753 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _vm_type);
6754 }
6755
6756 //------------------------------cast_to_ptr_type-------------------------------
6757 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6758 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6759 if (ptr == _ptr) return this;
6760 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _vm_type);
6761 }
6762
6763 bool TypeAryKlassPtr::must_be_exact() const {
6764 if (_elem == Type::BOTTOM) return false;
6765 if (_elem == Type::TOP ) return false;
6766 const TypeKlassPtr* tk = _elem->isa_klassptr();
6767 if (!tk) return true; // a primitive type, like int
6768 // Even though MyValue is final, [LMyValue is only exact if the array
6769 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6770 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6771 // If so, we should add '&& !is_not_null_free()'
6772 if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6773 return false;
6774 }
6775 return tk->must_be_exact();
6776 }
6777
6778
6779 //-----------------------------cast_to_exactness-------------------------------
6780 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6781 if (must_be_exact() && !klass_is_exact) return this; // cannot clear xk
6782 if (klass_is_exact == this->klass_is_exact()) {
6783 return this;
6784 }
6785 ciKlass* k = _klass;
6786 const Type* elem = this->elem();
6787 if (elem->isa_klassptr() && !klass_is_exact) {
6788 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6789 }
6790 bool not_flat = is_not_flat();
6791 bool not_null_free = is_not_null_free();
6792 if (_elem->isa_klassptr()) {
6793 if (klass_is_exact || _elem->isa_aryklassptr()) {
6794 assert((!is_null_free() && !is_flat()) ||
6795 _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
6796 "null-free (or flat) concrete inline type arrays should always be exact");
6797 // An array can't be null-free (or flat) if the klass is exact
6798 not_null_free = true;
6799 not_flat = true;
6800 } else {
6801 // Klass is not exact (anymore), re-compute null-free/flat properties
6802 const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6803 bool not_inline = !exact_etype->can_be_inline_type();
6804 not_null_free = not_inline;
6805 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
6806 }
6807 }
6808 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _flat, _null_free, _atomic, _vm_type);
6809 }
6810
6811 //-----------------------------as_instance_type--------------------------------
6812 // Corresponding type for an instance of the given class.
6813 // It will be NotNull, and exact if and only if the klass type is exact.
6814 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6815 ciKlass* k = klass();
6816 bool xk = klass_is_exact();
6817 const Type* el = nullptr;
6818 if (elem()->isa_klassptr()) {
6819 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6820 k = nullptr;
6821 } else {
6822 el = elem();
6823 }
6824 bool null_free = _null_free;
6825 if (null_free && el->isa_ptr()) {
6826 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6827 }
6828 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));
6829 }
6830
6831
6832 //------------------------------xmeet------------------------------------------
6833 // Compute the MEET of two types, return a new Type object.
6834 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6835 // Perform a fast test for common case; meeting the same types together.
6836 if( this == t ) return this; // Meeting same type-rep?
6837
6838 // Current "this->_base" is Pointer
6839 switch (t->base()) { // switch on original type
6840
6841 case Int: // Mixing ints & oops happens when javac
6842 case Long: // reuses local variables
6843 case HalfFloatTop:
6844 case HalfFloatCon:
6845 case HalfFloatBot:
6846 case FloatTop:
6847 case FloatCon:
6848 case FloatBot:
6849 case DoubleTop:
6850 case DoubleCon:
6851 case DoubleBot:
6852 case NarrowOop:
6853 case NarrowKlass:
6854 case Bottom: // Ye Olde Default
6855 return Type::BOTTOM;
6856 case Top:
6857 return this;
6858
6859 default: // All else is a mistake
6860 typerr(t);
6861
6862 case AnyPtr: { // Meeting to AnyPtrs
6863 // Found an AnyPtr type vs self-KlassPtr type
6864 const TypePtr *tp = t->is_ptr();
6865 Offset offset = meet_offset(tp->offset());
6866 PTR ptr = meet_ptr(tp->ptr());
6867 switch (tp->ptr()) {
6868 case TopPTR:
6869 return this;
6870 case Null:
6871 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6872 case AnyNull:
6873 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_vm_type());
6874 case BotPTR:
6875 case NotNull:
6876 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6877 default: typerr(t);
6878 }
6879 }
6880
6881 case RawPtr:
6882 case MetadataPtr:
6883 case OopPtr:
6884 case AryPtr: // Meet with AryPtr
6885 case InstPtr: // Meet with InstPtr
6886 return TypePtr::BOTTOM;
6887
6888 //
6889 // A-top }
6890 // / | \ } Tops
6891 // B-top A-any C-top }
6892 // | / | \ | } Any-nulls
6893 // B-any | C-any }
6894 // | | |
6895 // B-con A-con C-con } constants; not comparable across classes
6896 // | | |
6897 // B-not | C-not }
6898 // | \ | / | } not-nulls
6899 // B-bot A-not C-bot }
6900 // \ | / } Bottoms
6901 // A-bot }
6902 //
6903
6904 case AryKlassPtr: { // Meet two KlassPtr types
6905 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6906 Offset off = meet_offset(tap->offset());
6907 const Type* elem = _elem->meet(tap->_elem);
6908 PTR ptr = meet_ptr(tap->ptr());
6909 ciKlass* res_klass = nullptr;
6910 bool res_xk = false;
6911 bool res_flat = false;
6912 bool res_not_flat = false;
6913 bool res_not_null_free = false;
6914 bool res_atomic = false;
6915 MeetResult res = meet_aryptr(ptr, elem, this, tap,
6916 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
6917 assert(res_xk == (ptr == Constant), "");
6918 bool flat = meet_flat(tap->_flat);
6919 bool null_free = meet_null_free(tap->_null_free);
6920 bool atomic = meet_atomic(tap->_atomic);
6921 bool vm_type = _vm_type && tap->_vm_type;
6922 if (res == NOT_SUBTYPE) {
6923 flat = false;
6924 null_free = false;
6925 atomic = false;
6926 vm_type = false;
6927 } else if (res == SUBTYPE) {
6928 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6929 flat = _flat;
6930 null_free = _null_free;
6931 atomic = _atomic;
6932 vm_type = _vm_type;
6933 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6934 flat = tap->_flat;
6935 null_free = tap->_null_free;
6936 atomic = tap->_atomic;
6937 vm_type = tap->_vm_type;
6938 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6939 flat = _flat || tap->_flat;
6940 null_free = _null_free || tap->_null_free;
6941 atomic = _atomic || tap->_atomic;
6942 vm_type = _vm_type || tap->_vm_type;
6943 }
6944 }
6945 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, vm_type);
6946 } // End of case KlassPtr
6947 case InstKlassPtr: {
6948 const TypeInstKlassPtr *tp = t->is_instklassptr();
6949 Offset offset = meet_offset(tp->offset());
6950 PTR ptr = meet_ptr(tp->ptr());
6951 const TypeInterfaces* interfaces = meet_interfaces(tp);
6952 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6953 const TypeInterfaces* this_interfaces = _interfaces;
6954
6955 switch (ptr) {
6956 case TopPTR:
6957 case AnyNull: // Fall 'down' to dual of object klass
6958 // For instances when a subclass meets a superclass we fall
6959 // below the centerline when the superclass is exact. We need to
6960 // do the same here.
6961 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6962 !tp->klass_is_exact()) {
6963 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_vm_type());
6964 } else {
6965 // cannot subclass, so the meet has to fall badly below the centerline
6966 ptr = NotNull;
6967 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6968 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6969 }
6970 case Constant:
6971 case NotNull:
6972 case BotPTR: // Fall down to object klass
6973 // LCA is object_klass, but if we subclass from the top we can do better
6974 if (above_centerline(tp->ptr())) {
6975 // If 'tp' is above the centerline and it is Object class
6976 // then we can subclass in the Java class hierarchy.
6977 // For instances when a subclass meets a superclass we fall
6978 // below the centerline when the superclass is exact. We need
6979 // to do the same here.
6980 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6981 !tp->klass_is_exact()) {
6982 // that is, my array type is a subtype of 'tp' klass
6983 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_vm_type());
6984 }
6985 }
6986 // The other case cannot happen, since t cannot be a subtype of an array.
6987 // The meet falls down to Object class below centerline.
6988 if (ptr == Constant)
6989 ptr = NotNull;
6990 interfaces = this_interfaces->intersection_with(tp_interfaces);
6991 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6992 default: typerr(t);
6993 }
6994 }
6995
6996 } // End of switch
6997 return this; // Return the double constant
6998 }
6999
7000 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) {
7001 static_assert(std::is_base_of<T2, T1>::value, "");
7002
7003 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7004 return true;
7005 }
7006
7007 int dummy;
7008 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7009
7010 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7011 return false;
7012 }
7013
7014 if (this_one->is_instance_type(other)) {
7015 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7016 other_exact;
7017 }
7018
7019 assert(this_one->is_array_type(other), "");
7020 const T1* other_ary = this_one->is_array_type(other);
7021 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7022 if (other_top_or_bottom) {
7023 return false;
7024 }
7025
7026 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7027 const TypePtr* this_elem = this_one->elem()->make_ptr();
7028 if (this_elem != nullptr && other_elem != nullptr) {
7029 if (other->is_null_free() && !this_one->is_null_free()) {
7030 return false; // A nullable array can't be a subtype of a null-free array
7031 }
7032 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7033 }
7034 if (this_elem == nullptr && other_elem == nullptr) {
7035 return this_one->klass()->is_subtype_of(other->klass());
7036 }
7037 return false;
7038 }
7039
7040 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7041 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7042 }
7043
7044 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7045 static_assert(std::is_base_of<T2, T1>::value, "");
7046
7047 int dummy;
7048 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7049
7050 if (!this_one->is_array_type(other) ||
7051 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7104 }
7105
7106 const TypePtr* this_elem = this_one->elem()->make_ptr();
7107 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7108 if (other_elem != nullptr && this_elem != nullptr) {
7109 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7110 }
7111 if (other_elem == nullptr && this_elem == nullptr) {
7112 return this_one->klass()->is_subtype_of(other->klass());
7113 }
7114 return false;
7115 }
7116
7117 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7118 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7119 }
7120
7121 //------------------------------xdual------------------------------------------
7122 // Dual: compute field-by-field dual
7123 const Type *TypeAryKlassPtr::xdual() const {
7124 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _vm_type);
7125 }
7126
7127 // Is there a single ciKlass* that can represent that type?
7128 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7129 if (elem()->isa_klassptr()) {
7130 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7131 if (k == nullptr) {
7132 return nullptr;
7133 }
7134 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _vm_type);
7135 return k;
7136 }
7137
7138 return klass();
7139 }
7140
7141 ciKlass* TypeAryKlassPtr::klass() const {
7142 if (_klass != nullptr) {
7143 return _klass;
7144 }
7145 ciKlass* k = nullptr;
7146 if (elem()->isa_klassptr()) {
7147 // leave null
7148 } else if ((elem()->base() == Type::Top) ||
7149 (elem()->base() == Type::Bottom)) {
7150 } else {
7151 k = ciTypeArrayKlass::make(elem()->basic_type());
7152 ((TypeAryKlassPtr*)this)->_klass = k;
7153 }
7154 return k;
7161 switch( _ptr ) {
7162 case Constant:
7163 st->print("precise ");
7164 case NotNull:
7165 {
7166 st->print("[");
7167 _elem->dump2(d, depth, st);
7168 _interfaces->dump(st);
7169 st->print(": ");
7170 }
7171 case BotPTR:
7172 if( !WizardMode && !Verbose && _ptr != Constant ) break;
7173 case TopPTR:
7174 case AnyNull:
7175 st->print(":%s", ptr_msg[_ptr]);
7176 if( _ptr == Constant ) st->print(":exact");
7177 break;
7178 default:
7179 break;
7180 }
7181 if (_flat) st->print(":flat");
7182 if (_null_free) st->print(":null free");
7183 if (_atomic) st->print(":atomic");
7184 if (_vm_type) st->print(":vm_type");
7185 if (Verbose) {
7186 if (_not_flat) st->print(":not flat");
7187 if (_not_null_free) st->print(":nullable");
7188 }
7189
7190 _offset.dump2(st);
7191
7192 st->print(" *");
7193 }
7194 #endif
7195
7196 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7197 const Type* elem = this->elem();
7198 dims = 1;
7199 while (elem->isa_aryklassptr()) {
7200 elem = elem->is_aryklassptr()->elem();
7201 dims++;
7202 }
7203 return elem;
7204 }
7205
7206 //=============================================================================
7207 // Convenience common pre-built types.
7208
7209 //------------------------------make-------------------------------------------
7210 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7211 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7212 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7213 }
7214
7215 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7216 return make(domain, domain, range, range);
7217 }
7218
7219 //------------------------------osr_domain-----------------------------
7220 const TypeTuple* osr_domain() {
7221 const Type **fields = TypeTuple::fields(2);
7222 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7223 return TypeTuple::make(TypeFunc::Parms+1, fields);
7224 }
7225
7226 //------------------------------make-------------------------------------------
7227 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7228 Compile* C = Compile::current();
7229 const TypeFunc* tf = nullptr;
7230 if (!is_osr_compilation) {
7231 tf = C->last_tf(method); // check cache
7232 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7233 }
7234 // Inline types are not passed/returned by reference, instead each field of
7235 // the inline type is passed/returned as an argument. We maintain two views of
7236 // the argument/return list here: one based on the signature (with an inline
7237 // type argument/return as a single slot), one based on the actual calling
7238 // convention (with an inline type argument/return as a list of its fields).
7239 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7240 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7241 if (method != C->method() && method->get_Method()->mismatch()) {
7242 has_scalar_args = false;
7243 }
7244 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7245 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7246 ciSignature* sig = method->signature();
7247 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7248 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7249 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7250 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7251 if (!is_osr_compilation) {
7252 C->set_last_tf(method, tf); // fill cache
7253 }
7254 return tf;
7255 }
7256
7257 //------------------------------meet-------------------------------------------
7258 // Compute the MEET of two types. It returns a new Type object.
7259 const Type *TypeFunc::xmeet( const Type *t ) const {
7260 // Perform a fast test for common case; meeting the same types together.
7261 if( this == t ) return this; // Meeting same type-rep?
7262
7263 // Current "this->_base" is Func
7264 switch (t->base()) { // switch on original type
7265
7266 case Bottom: // Ye Olde Default
7267 return t;
7268
7269 default: // All else is a mistake
7270 typerr(t);
7271
7272 case Top:
7273 break;
7274 }
7275 return this; // Return the double constant
7276 }
7277
7278 //------------------------------xdual------------------------------------------
7279 // Dual: compute field-by-field dual
7280 const Type *TypeFunc::xdual() const {
7281 return this;
7282 }
7283
7284 //------------------------------eq---------------------------------------------
7285 // Structural equality check for Type representations
7286 bool TypeFunc::eq( const Type *t ) const {
7287 const TypeFunc *a = (const TypeFunc*)t;
7288 return _domain_sig == a->_domain_sig &&
7289 _domain_cc == a->_domain_cc &&
7290 _range_sig == a->_range_sig &&
7291 _range_cc == a->_range_cc;
7292 }
7293
7294 //------------------------------hash-------------------------------------------
7295 // Type-specific hashing function.
7296 uint TypeFunc::hash(void) const {
7297 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7298 }
7299
7300 //------------------------------dump2------------------------------------------
7301 // Dump Function Type
7302 #ifndef PRODUCT
7303 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7304 if( _range_sig->cnt() <= Parms )
7305 st->print("void");
7306 else {
7307 uint i;
7308 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7309 _range_sig->field_at(i)->dump2(d,depth,st);
7310 st->print("/");
7311 }
7312 _range_sig->field_at(i)->dump2(d,depth,st);
7313 }
7314 st->print(" ");
7315 st->print("( ");
7316 if( !depth || d[this] ) { // Check for recursive dump
7317 st->print("...)");
7318 return;
7319 }
7320 d.Insert((void*)this,(void*)this); // Stop recursion
7321 if (Parms < _domain_sig->cnt())
7322 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7323 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7324 st->print(", ");
7325 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7326 }
7327 st->print(" )");
7328 }
7329 #endif
7330
7331 //------------------------------singleton--------------------------------------
7332 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7333 // constants (Ldi nodes). Singletons are integer, float or double constants
7334 // or a single symbol.
7335 bool TypeFunc::singleton(void) const {
7336 return false; // Never a singleton
7337 }
7338
7339 bool TypeFunc::empty(void) const {
7340 return false; // Never empty
7341 }
7342
7343
7344 BasicType TypeFunc::return_type() const{
7345 if (range_sig()->cnt() == TypeFunc::Parms) {
7346 return T_VOID;
7347 }
7348 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7349 }
|