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/ciInstanceKlass.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "ci/ciTypeFlow.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/vmSymbols.hpp"
31 #include "compiler/compileLog.hpp"
32 #include "libadt/dict.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "oops/instanceKlass.hpp"
36 #include "oops/instanceMirrorKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/typeArrayKlass.hpp"
39 #include "opto/arraycopynode.hpp"
40 #include "opto/callnode.hpp"
41 #include "opto/matcher.hpp"
42 #include "opto/node.hpp"
43 #include "opto/opcodes.hpp"
44 #include "opto/rangeinference.hpp"
45 #include "opto/runtime.hpp"
46 #include "opto/type.hpp"
47 #include "runtime/stubRoutines.hpp"
48 #include "utilities/checkedCast.hpp"
49 #include "utilities/debug.hpp"
50 #include "utilities/ostream.hpp"
51 #include "utilities/powerOfTwo.hpp"
52 #include "utilities/stringUtils.hpp"
53
54 // Portions of code courtesy of Clifford Click
55
56 // Optimization - Graph Style
57
58 // Dictionary of types shared among compilations.
59 Dict* Type::_shared_type_dict = nullptr;
60
61 // Array which maps compiler types to Basic Types
62 const Type::TypeInfo Type::_type_info[Type::lastype] = {
63 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg}, // Bad
64 { Control, T_ILLEGAL, "control", false, 0 }, // Control
65 { Bottom, T_VOID, "top", false, 0 }, // Top
66 { Bad, T_INT, "int:", false, Op_RegI }, // Int
67 { Bad, T_LONG, "long:", false, Op_RegL }, // Long
68 { Half, T_VOID, "half", false, 0 }, // Half
69 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN }, // NarrowOop
70 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN }, // NarrowKlass
71 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg}, // Tuple
72 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg}, // Array
73 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg}, // Interfaces
74
75 #if defined(PPC64)
76 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask }, // VectorMask.
77 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA }, // VectorA.
78 { Bad, T_ILLEGAL, "vectors:", false, 0 }, // VectorS
79 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL }, // VectorD
218 case ciTypeFlow::StateVector::T_NULL:
219 assert(type == ciTypeFlow::StateVector::null_type(), "");
220 return TypePtr::NULL_PTR;
221
222 case ciTypeFlow::StateVector::T_LONG2:
223 // The ciTypeFlow pass pushes a long, then the half.
224 // We do the same.
225 assert(type == ciTypeFlow::StateVector::long2_type(), "");
226 return TypeInt::TOP;
227
228 case ciTypeFlow::StateVector::T_DOUBLE2:
229 // The ciTypeFlow pass pushes double, then the half.
230 // Our convention is the same.
231 assert(type == ciTypeFlow::StateVector::double2_type(), "");
232 return Type::TOP;
233
234 case T_ADDRESS:
235 assert(type->is_return_address(), "");
236 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci(), relocInfo::none);
237
238 default:
239 // make sure we did not mix up the cases:
240 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
241 assert(type != ciTypeFlow::StateVector::top_type(), "");
242 assert(type != ciTypeFlow::StateVector::null_type(), "");
243 assert(type != ciTypeFlow::StateVector::long2_type(), "");
244 assert(type != ciTypeFlow::StateVector::double2_type(), "");
245 assert(!type->is_return_address(), "");
246
247 return Type::get_const_type(type);
248 }
249 }
250
251
252 //-----------------------make_from_constant------------------------------------
253 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
254 int stable_dimension, bool is_narrow_oop,
255 bool is_autobox_cache) {
256 switch (constant.basic_type()) {
257 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
307 case T_NARROWOOP: loadbt = T_OBJECT; break;
308 case T_ARRAY: loadbt = T_OBJECT; break;
309 case T_ADDRESS: loadbt = T_OBJECT; break;
310 default: break;
311 }
312 if (conbt == loadbt) {
313 if (is_unsigned && conbt == T_BYTE) {
314 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
315 return ciConstant(T_INT, con.as_int() & 0xFF);
316 } else {
317 return con;
318 }
319 }
320 if (conbt == T_SHORT && loadbt == T_CHAR) {
321 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
322 return ciConstant(T_INT, con.as_int() & 0xFFFF);
323 }
324 return ciConstant(); // T_ILLEGAL
325 }
326
327 // Try to constant-fold a stable array element.
328 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
329 BasicType loadbt, bool is_unsigned_load) {
330 // Decode the results of GraphKit::array_element_address.
331 ciConstant element_value = array->element_value_by_offset(off);
332 if (element_value.basic_type() == T_ILLEGAL) {
333 return nullptr; // wrong offset
334 }
335 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
336
337 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
338 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
339
340 if (con.is_valid() && // not a mismatched access
341 !con.is_null_or_zero()) { // not a default value
342 bool is_narrow_oop = (loadbt == T_NARROWOOP);
343 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
344 }
345 return nullptr;
346 }
347
348 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
349 ciField* field;
350 ciType* type = holder->java_mirror_type();
351 if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
352 // Static field
353 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
354 } else {
355 // Instance field
356 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
357 }
358 if (field == nullptr) {
359 return nullptr; // Wrong offset
360 }
361 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
362 }
363
364 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
365 BasicType loadbt, bool is_unsigned_load) {
366 if (!field->is_constant()) {
367 return nullptr; // Non-constant field
540 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
541 ffalse[0] = Type::CONTROL;
542 ffalse[1] = Type::TOP;
543 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
544
545 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
546 fneither[0] = Type::TOP;
547 fneither[1] = Type::TOP;
548 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
549
550 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
551 ftrue[0] = Type::TOP;
552 ftrue[1] = Type::CONTROL;
553 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
554
555 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
556 floop[0] = Type::CONTROL;
557 floop[1] = TypeInt::INT;
558 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
559
560 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
561 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
562 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
563
564 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
565 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
566
567 const Type **fmembar = TypeTuple::fields(0);
568 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
569
570 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
571 fsc[0] = TypeInt::CC;
572 fsc[1] = Type::MEMORY;
573 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
574
575 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
576 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
577 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
578 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
579 false, nullptr, oopDesc::mark_offset_in_bytes());
580 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
581 false, nullptr, oopDesc::klass_offset_in_bytes());
582 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
583
584 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
585
586 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
587 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
588
589 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
590
591 mreg2type[Op_Node] = Type::BOTTOM;
592 mreg2type[Op_Set ] = nullptr;
593 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
594 mreg2type[Op_RegI] = TypeInt::INT;
595 mreg2type[Op_RegP] = TypePtr::BOTTOM;
596 mreg2type[Op_RegF] = Type::FLOAT;
597 mreg2type[Op_RegD] = Type::DOUBLE;
598 mreg2type[Op_RegL] = TypeLong::LONG;
599 mreg2type[Op_RegFlags] = TypeInt::CC;
600
601 GrowableArray<ciInstanceKlass*> array_interfaces;
602 array_interfaces.push(current->env()->Cloneable_klass());
603 array_interfaces.push(current->env()->Serializable_klass());
604 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
605 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
606
607 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS), nullptr, false, Type::OffsetBot);
608 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
609
610 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
611
612 #ifdef _LP64
613 if (UseCompressedOops) {
614 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
615 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
616 } else
617 #endif
618 {
619 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
620 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
621 }
622 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
623 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
624 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
625 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
626 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
627 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
628 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
629
630 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
631 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
632 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
633 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
634 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
635 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
636 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
637 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
638 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
639 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
640 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
641 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
642
643 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
644 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
645
646 const Type **fi2c = TypeTuple::fields(2);
647 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
648 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
649 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
650
651 const Type **intpair = TypeTuple::fields(2);
652 intpair[0] = TypeInt::INT;
653 intpair[1] = TypeInt::INT;
654 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
655
656 const Type **longpair = TypeTuple::fields(2);
657 longpair[0] = TypeLong::LONG;
658 longpair[1] = TypeLong::LONG;
659 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
660
661 const Type **intccpair = TypeTuple::fields(2);
662 intccpair[0] = TypeInt::INT;
663 intccpair[1] = TypeInt::CC;
664 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
665
666 const Type **longccpair = TypeTuple::fields(2);
667 longccpair[0] = TypeLong::LONG;
668 longccpair[1] = TypeInt::CC;
669 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
670
671 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
672 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
673 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
674 _const_basic_type[T_CHAR] = TypeInt::CHAR;
675 _const_basic_type[T_BYTE] = TypeInt::BYTE;
676 _const_basic_type[T_SHORT] = TypeInt::SHORT;
677 _const_basic_type[T_INT] = TypeInt::INT;
678 _const_basic_type[T_LONG] = TypeLong::LONG;
679 _const_basic_type[T_FLOAT] = Type::FLOAT;
680 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
681 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
682 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
683 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
684 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
685 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
686
687 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
688 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
689 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
690 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
691 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
692 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
693 _zero_type[T_INT] = TypeInt::ZERO;
694 _zero_type[T_LONG] = TypeLong::ZERO;
695 _zero_type[T_FLOAT] = TypeF::ZERO;
696 _zero_type[T_DOUBLE] = TypeD::ZERO;
697 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
698 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
699 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
700 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
701
702 // get_zero_type() should not happen for T_CONFLICT
703 _zero_type[T_CONFLICT]= nullptr;
704
705 TypeVect::VECTMASK = (TypeVect*)(new TypePVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
706 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
707
708 if (Matcher::supports_scalable_vector()) {
709 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
710 }
711
712 // Vector predefined types, it needs initialized _const_basic_type[].
713 if (Matcher::vector_size_supported(T_BYTE, 4)) {
714 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
715 }
716 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
717 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
718 }
954 ~VerifyMeet() {
955 assert(_C->_type_verify->_depth != 0, "");
956 _C->_type_verify->_depth--;
957 if (_C->_type_verify->_depth == 0) {
958 _C->_type_verify->_cache.trunc_to(0);
959 }
960 }
961
962 const Type* meet(const Type* t1, const Type* t2) const {
963 return _C->_type_verify->meet(t1, t2);
964 }
965
966 void add(const Type* t1, const Type* t2, const Type* res) const {
967 _C->_type_verify->add(t1, t2, res);
968 }
969 };
970
971 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
972 Compile* C = Compile::current();
973 const Type* mt2 = verify.meet(t, this);
974 if (mt != mt2) {
975 tty->print_cr("=== Meet Not Commutative ===");
976 tty->print("t = "); t->dump(); tty->cr();
977 tty->print("this = "); dump(); tty->cr();
978 tty->print("t meet this = "); mt2->dump(); tty->cr();
979 tty->print("this meet t = "); mt->dump(); tty->cr();
980 fatal("meet not commutative");
981 }
982 const Type* dual_join = mt->_dual;
983 const Type* t2t = verify.meet(dual_join,t->_dual);
984 const Type* t2this = verify.meet(dual_join,this->_dual);
985
986 // Interface meet Oop is Not Symmetric:
987 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
988 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
989
990 if (t2t != t->_dual || t2this != this->_dual) {
991 tty->print_cr("=== Meet Not Symmetric ===");
992 tty->print("t = "); t->dump(); tty->cr();
993 tty->print("this= "); dump(); tty->cr();
994 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
995
996 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
997 tty->print("this_dual= "); _dual->dump(); tty->cr();
998 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
999
1000 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1001 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1002
1003 fatal("meet not symmetric");
1004 }
1005 }
1006 #endif
1007
1008 //------------------------------meet-------------------------------------------
1009 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1010 // commutative and the lattice is symmetric.
1011 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1012 if (isa_narrowoop() && t->isa_narrowoop()) {
1013 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1014 return result->make_narrowoop();
1015 }
1016 if (isa_narrowklass() && t->isa_narrowklass()) {
1017 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1018 return result->make_narrowklass();
1019 }
1020
1021 #ifdef ASSERT
1022 Compile* C = Compile::current();
1023 VerifyMeet verify(C);
1024 #endif
1025
1026 const Type *this_t = maybe_remove_speculative(include_speculative);
1027 t = t->maybe_remove_speculative(include_speculative);
1028
1029 const Type *mt = this_t->xmeet(t);
1030 #ifdef ASSERT
1031 verify.add(this_t, t, mt);
1032 if (isa_narrowoop() || t->isa_narrowoop()) {
1033 return mt;
1034 }
1035 if (isa_narrowklass() || t->isa_narrowklass()) {
1036 return mt;
1037 }
1038 this_t->check_symmetrical(t, mt, verify);
1039 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1040 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1041 #endif
1042 return mt;
1043 }
1044
1045 //------------------------------xmeet------------------------------------------
1046 // Compute the MEET of two types. It returns a new Type object.
1047 const Type *Type::xmeet( const Type *t ) const {
1048 // Perform a fast test for common case; meeting the same types together.
1049 if( this == t ) return this; // Meeting same type-rep?
1050
1051 // Meeting TOP with anything?
1052 if( _base == Top ) return t;
1053
1054 // Meeting BOTTOM with anything?
1055 if( _base == Bottom ) return BOTTOM;
1056
1057 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2060 void TypeLong::dump_verbose() const {
2061 TypeIntHelper::int_type_dump(this, tty, true);
2062 }
2063 #endif
2064
2065 //=============================================================================
2066 // Convenience common pre-built types.
2067 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2068 const TypeTuple *TypeTuple::IFFALSE;
2069 const TypeTuple *TypeTuple::IFTRUE;
2070 const TypeTuple *TypeTuple::IFNEITHER;
2071 const TypeTuple *TypeTuple::LOOPBODY;
2072 const TypeTuple *TypeTuple::MEMBAR;
2073 const TypeTuple *TypeTuple::STORECONDITIONAL;
2074 const TypeTuple *TypeTuple::START_I2C;
2075 const TypeTuple *TypeTuple::INT_PAIR;
2076 const TypeTuple *TypeTuple::LONG_PAIR;
2077 const TypeTuple *TypeTuple::INT_CC_PAIR;
2078 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2079
2080 //------------------------------make-------------------------------------------
2081 // Make a TypeTuple from the range of a method signature
2082 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2083 ciType* return_type = sig->return_type();
2084 uint arg_cnt = return_type->size();
2085 const Type **field_array = fields(arg_cnt);
2086 switch (return_type->basic_type()) {
2087 case T_LONG:
2088 field_array[TypeFunc::Parms] = TypeLong::LONG;
2089 field_array[TypeFunc::Parms+1] = Type::HALF;
2090 break;
2091 case T_DOUBLE:
2092 field_array[TypeFunc::Parms] = Type::DOUBLE;
2093 field_array[TypeFunc::Parms+1] = Type::HALF;
2094 break;
2095 case T_OBJECT:
2096 case T_ARRAY:
2097 case T_BOOLEAN:
2098 case T_CHAR:
2099 case T_FLOAT:
2100 case T_BYTE:
2101 case T_SHORT:
2102 case T_INT:
2103 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2104 break;
2105 case T_VOID:
2106 break;
2107 default:
2108 ShouldNotReachHere();
2109 }
2110 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2111 }
2112
2113 // Make a TypeTuple from the domain of a method signature
2114 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2115 uint arg_cnt = sig->size();
2116
2117 uint pos = TypeFunc::Parms;
2118 const Type **field_array;
2119 if (recv != nullptr) {
2120 arg_cnt++;
2121 field_array = fields(arg_cnt);
2122 // Use get_const_type here because it respects UseUniqueSubclasses:
2123 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2124 } else {
2125 field_array = fields(arg_cnt);
2126 }
2127
2128 int i = 0;
2129 while (pos < TypeFunc::Parms + arg_cnt) {
2130 ciType* type = sig->type_at(i);
2131
2132 switch (type->basic_type()) {
2133 case T_LONG:
2134 field_array[pos++] = TypeLong::LONG;
2135 field_array[pos++] = Type::HALF;
2136 break;
2137 case T_DOUBLE:
2138 field_array[pos++] = Type::DOUBLE;
2139 field_array[pos++] = Type::HALF;
2140 break;
2141 case T_OBJECT:
2142 case T_ARRAY:
2143 case T_FLOAT:
2144 case T_INT:
2145 field_array[pos++] = get_const_type(type, interface_handling);
2146 break;
2147 case T_BOOLEAN:
2148 case T_CHAR:
2149 case T_BYTE:
2150 case T_SHORT:
2151 field_array[pos++] = TypeInt::INT;
2152 break;
2153 default:
2154 ShouldNotReachHere();
2155 }
2156 i++;
2157 }
2158
2159 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2160 }
2161
2162 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2163 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2164 }
2165
2166 //------------------------------fields-----------------------------------------
2167 // Subroutine call type with space allocated for argument types
2168 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2169 const Type **TypeTuple::fields( uint arg_cnt ) {
2170 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2171 flds[TypeFunc::Control ] = Type::CONTROL;
2172 flds[TypeFunc::I_O ] = Type::ABIO;
2173 flds[TypeFunc::Memory ] = Type::MEMORY;
2174 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2175 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2176
2177 return flds;
2272 if (_fields[i]->empty()) return true;
2273 }
2274 return false;
2275 }
2276
2277 //=============================================================================
2278 // Convenience common pre-built types.
2279
2280 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2281 // Certain normalizations keep us sane when comparing types.
2282 // We do not want arrayOop variables to differ only by the wideness
2283 // of their index types. Pick minimum wideness, since that is the
2284 // forced wideness of small ranges anyway.
2285 if (size->_widen != Type::WidenMin)
2286 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2287 else
2288 return size;
2289 }
2290
2291 //------------------------------make-------------------------------------------
2292 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2293 if (UseCompressedOops && elem->isa_oopptr()) {
2294 elem = elem->make_narrowoop();
2295 }
2296 size = normalize_array_size(size);
2297 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2298 }
2299
2300 //------------------------------meet-------------------------------------------
2301 // Compute the MEET of two types. It returns a new Type object.
2302 const Type *TypeAry::xmeet( const Type *t ) const {
2303 // Perform a fast test for common case; meeting the same types together.
2304 if( this == t ) return this; // Meeting same type-rep?
2305
2306 // Current "this->_base" is Ary
2307 switch (t->base()) { // switch on original type
2308
2309 case Bottom: // Ye Olde Default
2310 return t;
2311
2312 default: // All else is a mistake
2313 typerr(t);
2314
2315 case Array: { // Meeting 2 arrays?
2316 const TypeAry* a = t->is_ary();
2317 const Type* size = _size->xmeet(a->_size);
2318 const TypeInt* isize = size->isa_int();
2319 if (isize == nullptr) {
2320 assert(size == Type::TOP || size == Type::BOTTOM, "");
2321 return size;
2322 }
2323 return TypeAry::make(_elem->meet_speculative(a->_elem),
2324 isize, _stable && a->_stable);
2325 }
2326 case Top:
2327 break;
2328 }
2329 return this; // Return the double constant
2330 }
2331
2332 //------------------------------xdual------------------------------------------
2333 // Dual: compute field-by-field dual
2334 const Type *TypeAry::xdual() const {
2335 const TypeInt* size_dual = _size->dual()->is_int();
2336 size_dual = normalize_array_size(size_dual);
2337 return new TypeAry(_elem->dual(), size_dual, !_stable);
2338 }
2339
2340 //------------------------------eq---------------------------------------------
2341 // Structural equality check for Type representations
2342 bool TypeAry::eq( const Type *t ) const {
2343 const TypeAry *a = (const TypeAry*)t;
2344 return _elem == a->_elem &&
2345 _stable == a->_stable &&
2346 _size == a->_size;
2347 }
2348
2349 //------------------------------hash-------------------------------------------
2350 // Type-specific hashing function.
2351 uint TypeAry::hash(void) const {
2352 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2353 }
2354
2355 /**
2356 * Return same type without a speculative part in the element
2357 */
2358 const TypeAry* TypeAry::remove_speculative() const {
2359 return make(_elem->remove_speculative(), _size, _stable);
2360 }
2361
2362 /**
2363 * Return same type with cleaned up speculative part of element
2364 */
2365 const Type* TypeAry::cleanup_speculative() const {
2366 return make(_elem->cleanup_speculative(), _size, _stable);
2367 }
2368
2369 /**
2370 * Return same type but with a different inline depth (used for speculation)
2371 *
2372 * @param depth depth to meet with
2373 */
2374 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2375 if (!UseInlineDepthForSpeculativeTypes) {
2376 return this;
2377 }
2378 return make(AnyPtr, _ptr, _offset, _speculative, depth, _reloc);
2379 }
2380
2381 //------------------------------dump2------------------------------------------
2382 #ifndef PRODUCT
2383 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2384 if (_stable) st->print("stable:");
2385 _elem->dump2(d, depth, st);
2386 st->print("[");
2387 _size->dump2(d, depth, st);
2388 st->print("]");
2389 }
2390 #endif
2391
2392 //------------------------------singleton--------------------------------------
2393 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2394 // constants (Ldi nodes). Singletons are integer, float or double constants
2395 // or a single symbol.
2396 bool TypeAry::singleton(void) const {
2397 return false; // Never a singleton
2398 }
2399
2400 bool TypeAry::empty(void) const {
2401 return _elem->empty() || _size->empty();
2402 }
2403
2404 //--------------------------ary_must_be_exact----------------------------------
2405 bool TypeAry::ary_must_be_exact() const {
2406 // This logic looks at the element type of an array, and returns true
2407 // if the element type is either a primitive or a final instance class.
2408 // In such cases, an array built on this ary must have no subclasses.
2409 if (_elem == BOTTOM) return false; // general array not exact
2410 if (_elem == TOP ) return false; // inverted general array not exact
2411 const TypeOopPtr* toop = nullptr;
2412 if (UseCompressedOops && _elem->isa_narrowoop()) {
2413 toop = _elem->make_ptr()->isa_oopptr();
2414 } else {
2415 toop = _elem->isa_oopptr();
2416 }
2417 if (!toop) return true; // a primitive type, like int
2418 if (!toop->is_loaded()) return false; // unloaded class
2419 const TypeInstPtr* tinst;
2420 if (_elem->isa_narrowoop())
2421 tinst = _elem->make_ptr()->isa_instptr();
2422 else
2423 tinst = _elem->isa_instptr();
2424 if (tinst)
2425 return tinst->instance_klass()->is_final();
2426 const TypeAryPtr* tap;
2427 if (_elem->isa_narrowoop())
2428 tap = _elem->make_ptr()->isa_aryptr();
2429 else
2430 tap = _elem->isa_aryptr();
2431 if (tap)
2432 return tap->ary()->ary_must_be_exact();
2433 return false;
2434 }
2435
2436 //==============================TypeVect=======================================
2437 // Convenience common pre-built types.
2438 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2439 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2440 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2441 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2442 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2443 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2444 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2445
2586
2587 //=============================================================================
2588 // Convenience common pre-built types.
2589 const TypePtr *TypePtr::NULL_PTR;
2590 const TypePtr *TypePtr::NOTNULL;
2591 const TypePtr *TypePtr::BOTTOM;
2592
2593 //------------------------------meet-------------------------------------------
2594 // Meet over the PTR enum
2595 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2596 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2597 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2598 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2599 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2600 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2601 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2602 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2603 };
2604
2605 //------------------------------make-------------------------------------------
2606 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, int offset,
2607 const TypePtr* speculative, int inline_depth,
2608 relocInfo::relocType reloc) {
2609 return (TypePtr*)(new TypePtr(t, ptr, offset, reloc, speculative, inline_depth))->hashcons();
2610 }
2611
2612 //------------------------------cast_to_ptr_type-------------------------------
2613 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2614 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2615 if( ptr == _ptr ) return this;
2616 return make(_base, ptr, _offset, _speculative, _inline_depth, _reloc);
2617 }
2618
2619 //------------------------------get_con----------------------------------------
2620 intptr_t TypePtr::get_con() const {
2621 assert( _ptr == Null, "" );
2622 return _offset;
2623 }
2624
2625 //------------------------------meet-------------------------------------------
2626 // Compute the MEET of two types. It returns a new Type object.
2627 const Type *TypePtr::xmeet(const Type *t) const {
2628 const Type* res = xmeet_helper(t);
2629 if (res->isa_ptr() == nullptr) {
2630 return res;
2631 }
2632
2633 const TypePtr* res_ptr = res->is_ptr();
2634 if (res_ptr->speculative() != nullptr) {
2635 // type->speculative() is null means that speculation is no better
2636 // than type, i.e. type->speculative() == type. So there are 2
2637 // ways to represent the fact that we have no useful speculative
2638 // data and we should use a single one to be able to test for
2639 // equality between types. Check whether type->speculative() ==
2640 // type and set speculative to null if it is the case.
2641 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2642 return res_ptr->remove_speculative();
2676 int depth = meet_inline_depth(tp->inline_depth());
2677 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2678 }
2679 case RawPtr: // For these, flip the call around to cut down
2680 case OopPtr:
2681 case InstPtr: // on the cases I have to handle.
2682 case AryPtr:
2683 case MetadataPtr:
2684 case KlassPtr:
2685 case InstKlassPtr:
2686 case AryKlassPtr:
2687 return t->xmeet(this); // Call in reverse direction
2688 default: // All else is a mistake
2689 typerr(t);
2690
2691 }
2692 return this;
2693 }
2694
2695 //------------------------------meet_offset------------------------------------
2696 int TypePtr::meet_offset( int offset ) const {
2697 // Either is 'TOP' offset? Return the other offset!
2698 if( _offset == OffsetTop ) return offset;
2699 if( offset == OffsetTop ) return _offset;
2700 // If either is different, return 'BOTTOM' offset
2701 if( _offset != offset ) return OffsetBot;
2702 return _offset;
2703 }
2704
2705 //------------------------------dual_offset------------------------------------
2706 int TypePtr::dual_offset( ) const {
2707 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2708 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2709 return _offset; // Map everything else into self
2710 }
2711
2712 //------------------------------xdual------------------------------------------
2713 // Dual: compute field-by-field dual
2714 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2715 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2716 };
2717 const Type *TypePtr::xdual() const {
2718 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), relocInfo::none, dual_speculative(), dual_inline_depth());
2719 }
2720
2721 //------------------------------xadd_offset------------------------------------
2722 int TypePtr::xadd_offset( intptr_t offset ) const {
2723 // Adding to 'TOP' offset? Return 'TOP'!
2724 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2725 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2726 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2727 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2728 offset += (intptr_t)_offset;
2729 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2730
2731 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2732 // It is possible to construct a negative offset during PhaseCCP
2733
2734 return (int)offset; // Sum valid offsets
2735 }
2736
2737 //------------------------------add_offset-------------------------------------
2738 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2739 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth, _reloc);
2740 }
2741
2742 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2743 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth, _reloc);
2744 }
2745
2746 //------------------------------eq---------------------------------------------
2747 // Structural equality check for Type representations
2748 bool TypePtr::eq( const Type *t ) const {
2749 const TypePtr *a = (const TypePtr*)t;
2750 return _ptr == a->ptr() && _offset == a->offset() && _reloc == a->reloc() &&
2751 eq_speculative(a) && _inline_depth == a->_inline_depth;
2752 }
2753
2754 //------------------------------hash-------------------------------------------
2755 // Type-specific hashing function.
2756 uint TypePtr::hash(void) const {
2757 return (uint)_ptr + (uint)_offset + (uint)_reloc + (uint)hash_speculative() + (uint)_inline_depth;
2758 }
2759
2760 /**
2761 * Return same type without a speculative part
2762 */
2763 const TypePtr* TypePtr::remove_speculative() const {
2764 if (_speculative == nullptr) {
2765 return this;
2766 }
2767 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2768 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth, _reloc);
2769 }
2770
2771 /**
2772 * Return same type but drop speculative part if we know we won't use
2773 * it
2774 */
2775 const Type* TypePtr::cleanup_speculative() const {
2776 if (speculative() == nullptr) {
2777 return this;
2994 return false;
2995 }
2996 // We already know the speculative type cannot be null
2997 if (!speculative_maybe_null()) {
2998 return false;
2999 }
3000 // We already know this is always null
3001 if (this == TypePtr::NULL_PTR) {
3002 return false;
3003 }
3004 // We already know the speculative type is always null
3005 if (speculative_always_null()) {
3006 return false;
3007 }
3008 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3009 return false;
3010 }
3011 return true;
3012 }
3013
3014 //------------------------------dump2------------------------------------------
3015 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3016 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3017 };
3018
3019 #ifndef PRODUCT
3020 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3021 st->print("ptr:%s", ptr_msg[_ptr]);
3022 dump_offset(st);
3023 dump_inline_depth(st);
3024 dump_speculative(st);
3025 }
3026
3027 void TypePtr::dump_offset(outputStream* st) const {
3028 if (_offset == OffsetBot) {
3029 st->print("+bot");
3030 } else if (_offset == OffsetTop) {
3031 st->print("+top");
3032 } else {
3033 st->print("+%d", _offset);
3034 }
3035 }
3036
3037 /**
3038 *dump the speculative part of the type
3039 */
3040 void TypePtr::dump_speculative(outputStream *st) const {
3041 if (_speculative != nullptr) {
3042 st->print(" (speculative=");
3043 _speculative->dump_on(st);
3044 st->print(")");
3045 }
3046 }
3047
3048 /**
3049 *dump the inline depth of the type
3050 */
3051 void TypePtr::dump_inline_depth(outputStream *st) const {
3052 if (_inline_depth != InlineDepthBottom) {
3053 if (_inline_depth == InlineDepthTop) {
3054 st->print(" (inline_depth=InlineDepthTop)");
3055 } else {
3056 st->print(" (inline_depth=%d)", _inline_depth);
3057 }
3058 }
3059 }
3060 #endif
3061
3062 //------------------------------singleton--------------------------------------
3063 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3064 // constants
3065 bool TypePtr::singleton(void) const {
3066 // TopPTR, Null, AnyNull, Constant are all singletons
3067 return (_offset != OffsetBot) && !below_centerline(_ptr);
3068 }
3069
3070 bool TypePtr::empty(void) const {
3071 return (_offset == OffsetTop) || above_centerline(_ptr);
3072 }
3073
3074 //=============================================================================
3075 // Convenience common pre-built types.
3076 const TypeRawPtr *TypeRawPtr::BOTTOM;
3077 const TypeRawPtr *TypeRawPtr::NOTNULL;
3078
3079 //------------------------------make-------------------------------------------
3080 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3081 assert( ptr != Constant, "what is the constant?" );
3082 assert( ptr != Null, "Use TypePtr for null" );
3083 return (TypeRawPtr*)(new TypeRawPtr(ptr, nullptr, relocInfo::none))->hashcons();
3084 }
3085
3086 const TypeRawPtr* TypeRawPtr::make(address bits, relocInfo::relocType reloc) {
3087 assert(bits != nullptr, "Use TypePtr for null");
3088 return (TypeRawPtr*)(new TypeRawPtr(Constant, bits, reloc))->hashcons();
3089 }
3090
3091 //------------------------------cast_to_ptr_type-------------------------------
3470 #endif
3471
3472 // Can't be implemented because there's no way to know if the type is above or below the center line.
3473 const Type* TypeInterfaces::xmeet(const Type* t) const {
3474 ShouldNotReachHere();
3475 return Type::xmeet(t);
3476 }
3477
3478 bool TypeInterfaces::singleton(void) const {
3479 ShouldNotReachHere();
3480 return Type::singleton();
3481 }
3482
3483 bool TypeInterfaces::has_non_array_interface() const {
3484 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3485
3486 return !TypeAryPtr::_array_interfaces->contains(this);
3487 }
3488
3489 //------------------------------TypeOopPtr-------------------------------------
3490 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3491 int instance_id, const TypePtr* speculative, int inline_depth)
3492 : TypePtr(t, ptr, offset, relocInfo::oop_type, speculative, inline_depth),
3493 _const_oop(o), _klass(k),
3494 _interfaces(interfaces),
3495 _klass_is_exact(xk),
3496 _is_ptr_to_narrowoop(false),
3497 _is_ptr_to_narrowklass(false),
3498 _is_ptr_to_boxed_value(false),
3499 _instance_id(instance_id) {
3500 #ifdef ASSERT
3501 if (klass() != nullptr && klass()->is_loaded()) {
3502 interfaces->verify_is_loaded();
3503 }
3504 #endif
3505 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3506 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3507 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3508 }
3509 #ifdef _LP64
3510 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3511 if (_offset == oopDesc::klass_offset_in_bytes()) {
3512 _is_ptr_to_narrowklass = true;
3513 } else if (klass() == nullptr) {
3514 // Array with unknown body type
3515 assert(this->isa_aryptr(), "only arrays without klass");
3516 _is_ptr_to_narrowoop = UseCompressedOops;
3517 } else if (this->isa_aryptr()) {
3518 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3519 _offset != arrayOopDesc::length_offset_in_bytes());
3520 } else if (klass()->is_instance_klass()) {
3521 ciInstanceKlass* ik = klass()->as_instance_klass();
3522 if (this->isa_klassptr()) {
3523 // Perm objects don't use compressed references
3524 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3525 // unsafe access
3526 _is_ptr_to_narrowoop = UseCompressedOops;
3527 } else {
3528 assert(this->isa_instptr(), "must be an instance ptr.");
3529
3530 if (klass() == ciEnv::current()->Class_klass() &&
3531 (_offset == java_lang_Class::klass_offset() ||
3532 _offset == java_lang_Class::array_klass_offset())) {
3533 // Special hidden fields from the Class.
3534 assert(this->isa_instptr(), "must be an instance ptr.");
3535 _is_ptr_to_narrowoop = false;
3536 } else if (klass() == ciEnv::current()->Class_klass() &&
3537 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3538 // Static fields
3539 BasicType basic_elem_type = T_ILLEGAL;
3540 if (const_oop() != nullptr) {
3541 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3542 basic_elem_type = k->get_field_type_by_offset(_offset, true);
3543 }
3544 if (basic_elem_type != T_ILLEGAL) {
3545 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3546 } else {
3547 // unsafe access
3548 _is_ptr_to_narrowoop = UseCompressedOops;
3549 }
3550 } else {
3551 // Instance fields which contains a compressed oop references.
3552 BasicType basic_elem_type = ik->get_field_type_by_offset(_offset, false);
3553 if (basic_elem_type != T_ILLEGAL) {
3554 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3555 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3556 // Compile::find_alias_type() cast exactness on all types to verify
3557 // that it does not affect alias type.
3558 _is_ptr_to_narrowoop = UseCompressedOops;
3559 } else {
3560 // Type for the copy start in LibraryCallKit::inline_native_clone().
3561 _is_ptr_to_narrowoop = UseCompressedOops;
3562 }
3563 }
3564 }
3565 }
3566 }
3567 #endif
3568 }
3569
3570 //------------------------------make-------------------------------------------
3571 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3572 const TypePtr* speculative, int inline_depth) {
3573 assert(ptr != Constant, "no constant generic pointers");
3574 ciKlass* k = Compile::current()->env()->Object_klass();
3575 bool xk = false;
3576 ciObject* o = nullptr;
3577 const TypeInterfaces* interfaces = TypeInterfaces::make();
3578 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3579 }
3580
3581
3582 //------------------------------cast_to_ptr_type-------------------------------
3583 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3584 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3585 if( ptr == _ptr ) return this;
3586 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3587 }
3588
3589 //-----------------------------cast_to_instance_id----------------------------
3590 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3591 // There are no instances of a general oop.
3592 // Return self unchanged.
3593 return this;
3594 }
3595
3596 //-----------------------------cast_to_exactness-------------------------------
3597 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3598 // There is no such thing as an exact general oop.
3599 // Return self unchanged.
3600 return this;
3601 }
3602
3603
3604 //------------------------------as_klass_type----------------------------------
3605 // Return the klass type corresponding to this instance or array type.
3606 // It is the type that is loaded from an object of this type.
3607 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3608 ShouldNotReachHere();
3609 return nullptr;
3610 }
3611
3612 //------------------------------meet-------------------------------------------
3613 // Compute the MEET of two types. It returns a new Type object.
3614 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3615 // Perform a fast test for common case; meeting the same types together.
3616 if( this == t ) return this; // Meeting same type-rep?
3617
3618 // Current "this->_base" is OopPtr
3619 switch (t->base()) { // switch on original type
3620
3621 case Int: // Mixing ints & oops happens when javac
3622 case Long: // reuses local variables
3623 case HalfFloatTop:
3632 case NarrowOop:
3633 case NarrowKlass:
3634 case Bottom: // Ye Olde Default
3635 return Type::BOTTOM;
3636 case Top:
3637 return this;
3638
3639 default: // All else is a mistake
3640 typerr(t);
3641
3642 case RawPtr:
3643 case MetadataPtr:
3644 case KlassPtr:
3645 case InstKlassPtr:
3646 case AryKlassPtr:
3647 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3648
3649 case AnyPtr: {
3650 // Found an AnyPtr type vs self-OopPtr type
3651 const TypePtr *tp = t->is_ptr();
3652 int offset = meet_offset(tp->offset());
3653 PTR ptr = meet_ptr(tp->ptr());
3654 const TypePtr* speculative = xmeet_speculative(tp);
3655 int depth = meet_inline_depth(tp->inline_depth());
3656 switch (tp->ptr()) {
3657 case Null:
3658 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3659 // else fall through:
3660 case TopPTR:
3661 case AnyNull: {
3662 int instance_id = meet_instance_id(InstanceTop);
3663 return make(ptr, offset, instance_id, speculative, depth);
3664 }
3665 case BotPTR:
3666 case NotNull:
3667 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3668 default: typerr(t);
3669 }
3670 }
3671
3672 case OopPtr: { // Meeting to other OopPtrs
3674 int instance_id = meet_instance_id(tp->instance_id());
3675 const TypePtr* speculative = xmeet_speculative(tp);
3676 int depth = meet_inline_depth(tp->inline_depth());
3677 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3678 }
3679
3680 case InstPtr: // For these, flip the call around to cut down
3681 case AryPtr:
3682 return t->xmeet(this); // Call in reverse direction
3683
3684 } // End of switch
3685 return this; // Return the double constant
3686 }
3687
3688
3689 //------------------------------xdual------------------------------------------
3690 // Dual of a pure heap pointer. No relevant klass or oop information.
3691 const Type *TypeOopPtr::xdual() const {
3692 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3693 assert(const_oop() == nullptr, "no constants here");
3694 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3695 }
3696
3697 //--------------------------make_from_klass_common-----------------------------
3698 // Computes the element-type given a klass.
3699 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3700 if (klass->is_instance_klass()) {
3701 Compile* C = Compile::current();
3702 Dependencies* deps = C->dependencies();
3703 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3704 // Element is an instance
3705 bool klass_is_exact = false;
3706 if (klass->is_loaded()) {
3707 // Try to set klass_is_exact.
3708 ciInstanceKlass* ik = klass->as_instance_klass();
3709 klass_is_exact = ik->is_final();
3710 if (!klass_is_exact && klass_change
3711 && deps != nullptr && UseUniqueSubclasses) {
3712 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3713 if (sub != nullptr) {
3714 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3715 klass = ik = sub;
3716 klass_is_exact = sub->is_final();
3717 }
3718 }
3719 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3720 !ik->is_interface() && !ik->has_subklass()) {
3721 // Add a dependence; if concrete subclass added we need to recompile
3722 deps->assert_leaf_type(ik);
3723 klass_is_exact = true;
3724 }
3725 }
3726 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3727 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3728 } else if (klass->is_obj_array_klass()) {
3729 // Element is an object array. Recursively call ourself.
3730 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3731 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3732 bool xk = etype->klass_is_exact();
3733 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3734 // We used to pass NotNull in here, asserting that the sub-arrays
3735 // are all not-null. This is not true in generally, as code can
3736 // slam nulls down in the subarrays.
3737 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3738 return arr;
3739 } else if (klass->is_type_array_klass()) {
3740 // Element is an typeArray
3741 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3742 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3743 // We used to pass NotNull in here, asserting that the array pointer
3744 // is not-null. That was not true in general.
3745 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3746 return arr;
3747 } else {
3748 ShouldNotReachHere();
3749 return nullptr;
3750 }
3751 }
3752
3753 //------------------------------make_from_constant-----------------------------
3754 // Make a java pointer from an oop constant
3755 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3756 assert(!o->is_null_object(), "null object not yet handled here.");
3757
3758 const bool make_constant = require_constant || o->should_be_constant();
3759
3760 ciKlass* klass = o->klass();
3761 if (klass->is_instance_klass()) {
3762 // Element is an instance
3763 if (make_constant) {
3764 return TypeInstPtr::make(o);
3765 } else {
3766 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3767 }
3768 } else if (klass->is_obj_array_klass()) {
3769 // Element is an object array. Recursively call ourself.
3770 const TypeOopPtr *etype =
3771 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3772 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3773 // We used to pass NotNull in here, asserting that the sub-arrays
3774 // are all not-null. This is not true in generally, as code can
3775 // slam nulls down in the subarrays.
3776 if (make_constant) {
3777 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3778 } else {
3779 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3780 }
3781 } else if (klass->is_type_array_klass()) {
3782 // Element is an typeArray
3783 const Type* etype =
3784 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3785 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3786 // We used to pass NotNull in here, asserting that the array pointer
3787 // is not-null. That was not true in general.
3788 if (make_constant) {
3789 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3790 } else {
3791 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3792 }
3793 }
3794
3795 fatal("unhandled object type");
3796 return nullptr;
3797 }
3798
3799 //------------------------------get_con----------------------------------------
3800 intptr_t TypeOopPtr::get_con() const {
3801 assert( _ptr == Null || _ptr == Constant, "" );
3802 assert( _offset >= 0, "" );
3803
3804 if (_offset != 0) {
3805 // After being ported to the compiler interface, the compiler no longer
3806 // directly manipulates the addresses of oops. Rather, it only has a pointer
3807 // to a handle at compile time. This handle is embedded in the generated
3808 // code and dereferenced at the time the nmethod is made. Until that time,
3809 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3810 // have access to the addresses!). This does not seem to currently happen,
3811 // but this assertion here is to help prevent its occurrence.
3812 tty->print_cr("Found oop constant with non-zero offset");
3813 ShouldNotReachHere();
3814 }
3815
3816 return (intptr_t)const_oop()->constant_encoding();
3817 }
3818
3819
3820 //-----------------------------filter------------------------------------------
3821 // Do not allow interface-vs.-noninterface joins to collapse to top.
3822 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3823
3824 const Type* ft = join_helper(kills, include_speculative);
3870 dump_speculative(st);
3871 }
3872
3873 void TypeOopPtr::dump_instance_id(outputStream* st) const {
3874 if (_instance_id == InstanceTop) {
3875 st->print(",iid=top");
3876 } else if (_instance_id == InstanceBot) {
3877 st->print(",iid=bot");
3878 } else {
3879 st->print(",iid=%d", _instance_id);
3880 }
3881 }
3882 #endif
3883
3884 //------------------------------singleton--------------------------------------
3885 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3886 // constants
3887 bool TypeOopPtr::singleton(void) const {
3888 // detune optimizer to not generate constant oop + constant offset as a constant!
3889 // TopPTR, Null, AnyNull, Constant are all singletons
3890 return (_offset == 0) && !below_centerline(_ptr);
3891 }
3892
3893 //------------------------------add_offset-------------------------------------
3894 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3895 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3896 }
3897
3898 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3899 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3900 }
3901
3902 /**
3903 * Return same type without a speculative part
3904 */
3905 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3906 if (_speculative == nullptr) {
3907 return this;
3908 }
3909 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3910 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3911 }
3912
3913 /**
3914 * Return same type but drop speculative part if we know we won't use
3915 * it
3916 */
3917 const Type* TypeOopPtr::cleanup_speculative() const {
3918 // If the klass is exact and the ptr is not null then there's
3919 // nothing that the speculative type can help us with
3992 const TypeInstPtr *TypeInstPtr::BOTTOM;
3993 const TypeInstPtr *TypeInstPtr::MIRROR;
3994 const TypeInstPtr *TypeInstPtr::MARK;
3995 const TypeInstPtr *TypeInstPtr::KLASS;
3996
3997 // Is there a single ciKlass* that can represent that type?
3998 ciKlass* TypeInstPtr::exact_klass_helper() const {
3999 if (_interfaces->empty()) {
4000 return _klass;
4001 }
4002 if (_klass != ciEnv::current()->Object_klass()) {
4003 if (_interfaces->eq(_klass->as_instance_klass())) {
4004 return _klass;
4005 }
4006 return nullptr;
4007 }
4008 return _interfaces->exact_klass();
4009 }
4010
4011 //------------------------------TypeInstPtr-------------------------------------
4012 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4013 int instance_id, const TypePtr* speculative, int inline_depth)
4014 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4015 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4016 assert(k != nullptr &&
4017 (k->is_loaded() || o == nullptr),
4018 "cannot have constants with non-loaded klass");
4019 };
4020
4021 //------------------------------make-------------------------------------------
4022 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4023 ciKlass* k,
4024 const TypeInterfaces* interfaces,
4025 bool xk,
4026 ciObject* o,
4027 int offset,
4028 int instance_id,
4029 const TypePtr* speculative,
4030 int inline_depth) {
4031 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4032 // Either const_oop() is null or else ptr is Constant
4033 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4034 "constant pointers must have a value supplied" );
4035 // Ptr is never Null
4036 assert( ptr != Null, "null pointers are not typed" );
4037
4038 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4039 if (ptr == Constant) {
4040 // Note: This case includes meta-object constants, such as methods.
4041 xk = true;
4042 } else if (k->is_loaded()) {
4043 ciInstanceKlass* ik = k->as_instance_klass();
4044 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4045 assert(!ik->is_interface(), "no interface here");
4046 if (xk && ik->is_interface()) xk = false; // no exact interface
4047 }
4048
4049 // Now hash this baby
4050 TypeInstPtr *result =
4051 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4052
4053 return result;
4054 }
4055
4056 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4057 if (k->is_instance_klass()) {
4058 if (k->is_loaded()) {
4059 if (k->is_interface() && interface_handling == ignore_interfaces) {
4060 assert(interface, "no interface expected");
4061 k = ciEnv::current()->Object_klass();
4062 const TypeInterfaces* interfaces = TypeInterfaces::make();
4063 return interfaces;
4064 }
4065 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4066 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4067 if (k->is_interface()) {
4068 assert(interface, "no interface expected");
4069 k = ciEnv::current()->Object_klass();
4070 } else {
4071 assert(klass, "no instance klass expected");
4074 }
4075 const TypeInterfaces* interfaces = TypeInterfaces::make();
4076 return interfaces;
4077 }
4078 assert(array, "no array expected");
4079 assert(k->is_array_klass(), "Not an array?");
4080 ciType* e = k->as_array_klass()->base_element_type();
4081 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4082 if (interface_handling == ignore_interfaces) {
4083 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4084 }
4085 }
4086 return TypeAryPtr::_array_interfaces;
4087 }
4088
4089 //------------------------------cast_to_ptr_type-------------------------------
4090 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4091 if( ptr == _ptr ) return this;
4092 // Reconstruct _sig info here since not a problem with later lazy
4093 // construction, _sig will show up on demand.
4094 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4095 }
4096
4097
4098 //-----------------------------cast_to_exactness-------------------------------
4099 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4100 if( klass_is_exact == _klass_is_exact ) return this;
4101 if (!_klass->is_loaded()) return this;
4102 ciInstanceKlass* ik = _klass->as_instance_klass();
4103 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4104 assert(!ik->is_interface(), "no interface here");
4105 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4106 }
4107
4108 //-----------------------------cast_to_instance_id----------------------------
4109 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4110 if( instance_id == _instance_id ) return this;
4111 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4112 }
4113
4114 //------------------------------xmeet_unloaded---------------------------------
4115 // Compute the MEET of two InstPtrs when at least one is unloaded.
4116 // Assume classes are different since called after check for same name/class-loader
4117 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4118 int off = meet_offset(tinst->offset());
4119 PTR ptr = meet_ptr(tinst->ptr());
4120 int instance_id = meet_instance_id(tinst->instance_id());
4121 const TypePtr* speculative = xmeet_speculative(tinst);
4122 int depth = meet_inline_depth(tinst->inline_depth());
4123
4124 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4125 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4126 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4127 //
4128 // Meet unloaded class with java/lang/Object
4129 //
4130 // Meet
4131 // | Unloaded Class
4132 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4133 // ===================================================================
4134 // TOP | ..........................Unloaded......................|
4135 // AnyNull | U-AN |................Unloaded......................|
4136 // Constant | ... O-NN .................................. | O-BOT |
4137 // NotNull | ... O-NN .................................. | O-BOT |
4138 // BOTTOM | ........................Object-BOTTOM ..................|
4139 //
4140 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4141 //
4142 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4143 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4144 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4145 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4146 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4147 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4148 }
4149 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4150
4151 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4152 }
4153
4154 // Both are unloaded, not the same class, not Object
4155 // Or meet unloaded with a different loaded class, not java/lang/Object
4156 if (ptr != TypePtr::BotPTR) {
4157 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4158 }
4159 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4160 }
4161
4162
4163 //------------------------------meet-------------------------------------------
4187 case Top:
4188 return this;
4189
4190 default: // All else is a mistake
4191 typerr(t);
4192
4193 case MetadataPtr:
4194 case KlassPtr:
4195 case InstKlassPtr:
4196 case AryKlassPtr:
4197 case RawPtr: return TypePtr::BOTTOM;
4198
4199 case AryPtr: { // All arrays inherit from Object class
4200 // Call in reverse direction to avoid duplication
4201 return t->is_aryptr()->xmeet_helper(this);
4202 }
4203
4204 case OopPtr: { // Meeting to OopPtrs
4205 // Found a OopPtr type vs self-InstPtr type
4206 const TypeOopPtr *tp = t->is_oopptr();
4207 int offset = meet_offset(tp->offset());
4208 PTR ptr = meet_ptr(tp->ptr());
4209 switch (tp->ptr()) {
4210 case TopPTR:
4211 case AnyNull: {
4212 int instance_id = meet_instance_id(InstanceTop);
4213 const TypePtr* speculative = xmeet_speculative(tp);
4214 int depth = meet_inline_depth(tp->inline_depth());
4215 return make(ptr, klass(), _interfaces, klass_is_exact(),
4216 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4217 }
4218 case NotNull:
4219 case BotPTR: {
4220 int instance_id = meet_instance_id(tp->instance_id());
4221 const TypePtr* speculative = xmeet_speculative(tp);
4222 int depth = meet_inline_depth(tp->inline_depth());
4223 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4224 }
4225 default: typerr(t);
4226 }
4227 }
4228
4229 case AnyPtr: { // Meeting to AnyPtrs
4230 // Found an AnyPtr type vs self-InstPtr type
4231 const TypePtr *tp = t->is_ptr();
4232 int offset = meet_offset(tp->offset());
4233 PTR ptr = meet_ptr(tp->ptr());
4234 int instance_id = meet_instance_id(InstanceTop);
4235 const TypePtr* speculative = xmeet_speculative(tp);
4236 int depth = meet_inline_depth(tp->inline_depth());
4237 switch (tp->ptr()) {
4238 case Null:
4239 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4240 // else fall through to AnyNull
4241 case TopPTR:
4242 case AnyNull: {
4243 return make(ptr, klass(), _interfaces, klass_is_exact(),
4244 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4245 }
4246 case NotNull:
4247 case BotPTR:
4248 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4249 default: typerr(t);
4250 }
4251 }
4252
4253 /*
4254 A-top }
4255 / | \ } Tops
4256 B-top A-any C-top }
4257 | / | \ | } Any-nulls
4258 B-any | C-any }
4259 | | |
4260 B-con A-con C-con } constants; not comparable across classes
4261 | | |
4262 B-not | C-not }
4263 | \ | / | } not-nulls
4264 B-bot A-not C-bot }
4265 \ | / } Bottoms
4266 A-bot }
4267 */
4268
4269 case InstPtr: { // Meeting 2 Oops?
4270 // Found an InstPtr sub-type vs self-InstPtr type
4271 const TypeInstPtr *tinst = t->is_instptr();
4272 int off = meet_offset(tinst->offset());
4273 PTR ptr = meet_ptr(tinst->ptr());
4274 int instance_id = meet_instance_id(tinst->instance_id());
4275 const TypePtr* speculative = xmeet_speculative(tinst);
4276 int depth = meet_inline_depth(tinst->inline_depth());
4277 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4278
4279 ciKlass* tinst_klass = tinst->klass();
4280 ciKlass* this_klass = klass();
4281
4282 ciKlass* res_klass = nullptr;
4283 bool res_xk = false;
4284 const Type* res;
4285 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4286
4287 if (kind == UNLOADED) {
4288 // One of these classes has not been loaded
4289 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4290 #ifndef PRODUCT
4291 if (PrintOpto && Verbose) {
4292 tty->print("meet of unloaded classes resulted in: ");
4293 unloaded_meet->dump();
4294 tty->cr();
4295 tty->print(" this == ");
4296 dump();
4297 tty->cr();
4298 tty->print(" tinst == ");
4299 tinst->dump();
4300 tty->cr();
4301 }
4302 #endif
4303 res = unloaded_meet;
4304 } else {
4305 if (kind == NOT_SUBTYPE && instance_id > 0) {
4306 instance_id = InstanceBot;
4307 } else if (kind == LCA) {
4308 instance_id = InstanceBot;
4309 }
4310 ciObject* o = nullptr; // Assume not constant when done
4311 ciObject* this_oop = const_oop();
4312 ciObject* tinst_oop = tinst->const_oop();
4313 if (ptr == Constant) {
4314 if (this_oop != nullptr && tinst_oop != nullptr &&
4315 this_oop->equals(tinst_oop))
4316 o = this_oop;
4317 else if (above_centerline(_ptr)) {
4318 assert(!tinst_klass->is_interface(), "");
4319 o = tinst_oop;
4320 } else if (above_centerline(tinst->_ptr)) {
4321 assert(!this_klass->is_interface(), "");
4322 o = this_oop;
4323 } else
4324 ptr = NotNull;
4325 }
4326 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4327 }
4328
4329 return res;
4330
4331 } // End of case InstPtr
4332
4333 } // End of switch
4334 return this; // Return the double constant
4335 }
4336
4337 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4338 ciKlass*& res_klass, bool& res_xk) {
4339 ciKlass* this_klass = this_type->klass();
4340 ciKlass* other_klass = other_type->klass();
4341 bool this_xk = this_type->klass_is_exact();
4342 bool other_xk = other_type->klass_is_exact();
4343 PTR this_ptr = this_type->ptr();
4344 PTR other_ptr = other_type->ptr();
4345 const TypeInterfaces* this_interfaces = this_type->interfaces();
4346 const TypeInterfaces* other_interfaces = other_type->interfaces();
4347 // Check for easy case; klasses are equal (and perhaps not loaded!)
4348 // If we have constants, then we created oops so classes are loaded
4349 // and we can handle the constants further down. This case handles
4350 // both-not-loaded or both-loaded classes
4351 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4352 res_klass = this_klass;
4353 res_xk = this_xk;
4354 return QUICK;
4355 }
4356
4357 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4358 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4359 return UNLOADED;
4360 }
4366 // If both are up and they do NOT subtype, "fall hard".
4367 // If both are down and they subtype, take the supertype class.
4368 // If both are down and they do NOT subtype, "fall hard".
4369 // Constants treated as down.
4370
4371 // Now, reorder the above list; observe that both-down+subtype is also
4372 // "fall hard"; "fall hard" becomes the default case:
4373 // If we split one up & one down AND they subtype, take the down man.
4374 // If both are up and they subtype, take the subtype class.
4375
4376 // If both are down and they subtype, "fall hard".
4377 // If both are down and they do NOT subtype, "fall hard".
4378 // If both are up and they do NOT subtype, "fall hard".
4379 // If we split one up & one down AND they do NOT subtype, "fall hard".
4380
4381 // If a proper subtype is exact, and we return it, we return it exactly.
4382 // If a proper supertype is exact, there can be no subtyping relationship!
4383 // If both types are equal to the subtype, exactness is and-ed below the
4384 // centerline and or-ed above it. (N.B. Constants are always exact.)
4385
4386 // Check for subtyping:
4387 const T* subtype = nullptr;
4388 bool subtype_exact = false;
4389 if (this_type->is_same_java_type_as(other_type)) {
4390 subtype = this_type;
4391 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4392 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4393 subtype = this_type; // Pick subtyping class
4394 subtype_exact = this_xk;
4395 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4396 subtype = other_type; // Pick subtyping class
4397 subtype_exact = other_xk;
4398 }
4399
4400 if (subtype) {
4401 if (above_centerline(ptr)) { // both are up?
4402 this_type = other_type = subtype;
4403 this_xk = other_xk = subtype_exact;
4404 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4405 this_type = other_type; // tinst is down; keep down man
4406 this_xk = other_xk;
4407 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4408 other_type = this_type; // this is down; keep down man
4409 other_xk = this_xk;
4410 } else {
4411 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4412 }
4413 }
4414
4415 // Check for classes now being equal
4416 if (this_type->is_same_java_type_as(other_type)) {
4417 // If the klasses are equal, the constants may still differ. Fall to
4418 // NotNull if they do (neither constant is null; that is a special case
4419 // handled elsewhere).
4420 res_klass = this_type->klass();
4421 res_xk = this_xk;
4422 return SUBTYPE;
4423 } // Else classes are not equal
4424
4425 // Since klasses are different, we require a LCA in the Java
4426 // class hierarchy - which means we have to fall to at least NotNull.
4427 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4428 ptr = NotNull;
4429 }
4430
4431 interfaces = this_interfaces->intersection_with(other_interfaces);
4432
4433 // Now we find the LCA of Java classes
4434 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4435
4436 res_klass = k;
4437 res_xk = false;
4438
4439 return LCA;
4440 }
4441
4442 //------------------------java_mirror_type--------------------------------------
4443 ciType* TypeInstPtr::java_mirror_type() const {
4444 // must be a singleton type
4445 if( const_oop() == nullptr ) return nullptr;
4446
4447 // must be of type java.lang.Class
4448 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4449
4450 return const_oop()->as_instance()->java_mirror_type();
4451 }
4452
4453
4454 //------------------------------xdual------------------------------------------
4455 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4456 // inheritance mechanism.
4457 const Type *TypeInstPtr::xdual() const {
4458 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4459 }
4460
4461 //------------------------------eq---------------------------------------------
4462 // Structural equality check for Type representations
4463 bool TypeInstPtr::eq( const Type *t ) const {
4464 const TypeInstPtr *p = t->is_instptr();
4465 return
4466 klass()->equals(p->klass()) &&
4467 _interfaces->eq(p->_interfaces) &&
4468 TypeOopPtr::eq(p); // Check sub-type stuff
4469 }
4470
4471 //------------------------------hash-------------------------------------------
4472 // Type-specific hashing function.
4473 uint TypeInstPtr::hash(void) const {
4474 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4475 }
4476
4477 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4478 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4479 }
4480
4481
4482 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4483 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4484 }
4485
4486 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4487 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4488 }
4489
4490
4491 //------------------------------dump2------------------------------------------
4492 // Dump oop Type
4493 #ifndef PRODUCT
4494 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4498 _interfaces->dump(st);
4499
4500 if (_ptr == Constant && (WizardMode || Verbose)) {
4501 ResourceMark rm;
4502 stringStream ss;
4503
4504 st->print(" ");
4505 const_oop()->print_oop(&ss);
4506 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4507 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4508 char* buf = ss.as_string(/* c_heap= */false);
4509 StringUtils::replace_no_expand(buf, "\n", "");
4510 st->print_raw(buf);
4511 }
4512
4513 st->print(":%s", ptr_msg[_ptr]);
4514 if (_klass_is_exact) {
4515 st->print(":exact");
4516 }
4517
4518 dump_offset(st);
4519 dump_instance_id(st);
4520 dump_inline_depth(st);
4521 dump_speculative(st);
4522 }
4523 #endif
4524
4525 //------------------------------add_offset-------------------------------------
4526 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4527 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4528 _instance_id, add_offset_speculative(offset), _inline_depth);
4529 }
4530
4531 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4532 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4533 _instance_id, with_offset_speculative(offset), _inline_depth);
4534 }
4535
4536 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4537 if (_speculative == nullptr) {
4538 return this;
4539 }
4540 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4541 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4542 _instance_id, nullptr, _inline_depth);
4543 }
4544
4545 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4546 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4547 }
4548
4549 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4550 if (!UseInlineDepthForSpeculativeTypes) {
4551 return this;
4552 }
4553 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4554 }
4555
4556 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4557 assert(is_known_instance(), "should be known");
4558 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4559 }
4560
4561 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4562 bool xk = klass_is_exact();
4563 ciInstanceKlass* ik = klass()->as_instance_klass();
4564 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4565 if (_interfaces->eq(ik)) {
4566 Compile* C = Compile::current();
4567 Dependencies* deps = C->dependencies();
4568 deps->assert_leaf_type(ik);
4569 xk = true;
4570 }
4571 }
4572 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4573 }
4574
4575 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) {
4576 static_assert(std::is_base_of<T2, T1>::value, "");
4577
4578 if (!this_one->is_instance_type(other)) {
4579 return false;
4580 }
4581
4582 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4583 return true;
4584 }
4585
4586 return this_one->klass()->is_subtype_of(other->klass()) &&
4587 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4588 }
4589
4590
4591 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4592 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4597 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4598 return true;
4599 }
4600
4601 if (this_one->is_instance_type(other)) {
4602 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4603 }
4604
4605 int dummy;
4606 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4607 if (this_top_or_bottom) {
4608 return false;
4609 }
4610
4611 const T1* other_ary = this_one->is_array_type(other);
4612 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4613 const TypePtr* this_elem = this_one->elem()->make_ptr();
4614 if (other_elem != nullptr && this_elem != nullptr) {
4615 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4616 }
4617
4618 if (other_elem == nullptr && this_elem == nullptr) {
4619 return this_one->klass()->is_subtype_of(other->klass());
4620 }
4621
4622 return false;
4623 }
4624
4625 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4626 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4627 }
4628
4629 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4630 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4631 }
4632
4633 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4634 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4635 }
4636
4637 //=============================================================================
4638 // Convenience common pre-built types.
4639 const TypeAryPtr* TypeAryPtr::BOTTOM;
4640 const TypeAryPtr* TypeAryPtr::RANGE;
4641 const TypeAryPtr* TypeAryPtr::OOPS;
4642 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4643 const TypeAryPtr* TypeAryPtr::BYTES;
4644 const TypeAryPtr* TypeAryPtr::SHORTS;
4645 const TypeAryPtr* TypeAryPtr::CHARS;
4646 const TypeAryPtr* TypeAryPtr::INTS;
4647 const TypeAryPtr* TypeAryPtr::LONGS;
4648 const TypeAryPtr* TypeAryPtr::FLOATS;
4649 const TypeAryPtr* TypeAryPtr::DOUBLES;
4650
4651 //------------------------------make-------------------------------------------
4652 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4653 int instance_id, const TypePtr* speculative, int inline_depth) {
4654 assert(!(k == nullptr && ary->_elem->isa_int()),
4655 "integral arrays must be pre-equipped with a class");
4656 if (!xk) xk = ary->ary_must_be_exact();
4657 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4658 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4659 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4660 k = nullptr;
4661 }
4662 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4663 }
4664
4665 //------------------------------make-------------------------------------------
4666 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4667 int instance_id, const TypePtr* speculative, int inline_depth,
4668 bool is_autobox_cache) {
4669 assert(!(k == nullptr && ary->_elem->isa_int()),
4670 "integral arrays must be pre-equipped with a class");
4671 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4672 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4673 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4674 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4675 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4676 k = nullptr;
4677 }
4678 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4679 }
4680
4681 //------------------------------cast_to_ptr_type-------------------------------
4682 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4683 if( ptr == _ptr ) return this;
4684 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4685 }
4686
4687
4688 //-----------------------------cast_to_exactness-------------------------------
4689 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4690 if( klass_is_exact == _klass_is_exact ) return this;
4691 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4692 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4693 }
4694
4695 //-----------------------------cast_to_instance_id----------------------------
4696 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4697 if( instance_id == _instance_id ) return this;
4698 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4699 }
4700
4701
4702 //-----------------------------max_array_length-------------------------------
4703 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4704 jint TypeAryPtr::max_array_length(BasicType etype) {
4705 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4706 if (etype == T_NARROWOOP) {
4707 etype = T_OBJECT;
4708 } else if (etype == T_ILLEGAL) { // bottom[]
4709 etype = T_BYTE; // will produce conservatively high value
4710 } else {
4711 fatal("not an element type: %s", type2name(etype));
4712 }
4713 }
4714 return arrayOopDesc::max_array_length(etype);
4715 }
4716
4717 //-----------------------------narrow_size_type-------------------------------
4718 // Narrow the given size type to the index range for the given array base type.
4736 if (size->is_con()) {
4737 lo = hi;
4738 }
4739 chg = true;
4740 }
4741 // Negative length arrays will produce weird intermediate dead fast-path code
4742 if (lo > hi) {
4743 return TypeInt::ZERO;
4744 }
4745 if (!chg) {
4746 return size;
4747 }
4748 return TypeInt::make(lo, hi, Type::WidenMin);
4749 }
4750
4751 //-------------------------------cast_to_size----------------------------------
4752 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4753 assert(new_size != nullptr, "");
4754 new_size = narrow_size_type(new_size);
4755 if (new_size == size()) return this;
4756 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4757 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4758 }
4759
4760 //------------------------------cast_to_stable---------------------------------
4761 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4762 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4763 return this;
4764
4765 const Type* elem = this->elem();
4766 const TypePtr* elem_ptr = elem->make_ptr();
4767
4768 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4769 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4770 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4771 }
4772
4773 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4774
4775 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4776 }
4777
4778 //-----------------------------stable_dimension--------------------------------
4779 int TypeAryPtr::stable_dimension() const {
4780 if (!is_stable()) return 0;
4781 int dim = 1;
4782 const TypePtr* elem_ptr = elem()->make_ptr();
4783 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4784 dim += elem_ptr->is_aryptr()->stable_dimension();
4785 return dim;
4786 }
4787
4788 //----------------------cast_to_autobox_cache-----------------------------------
4789 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4790 if (is_autobox_cache()) return this;
4791 const TypeOopPtr* etype = elem()->make_oopptr();
4792 if (etype == nullptr) return this;
4793 // The pointers in the autobox arrays are always non-null.
4794 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4795 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4796 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4797 }
4798
4799 //------------------------------eq---------------------------------------------
4800 // Structural equality check for Type representations
4801 bool TypeAryPtr::eq( const Type *t ) const {
4802 const TypeAryPtr *p = t->is_aryptr();
4803 return
4804 _ary == p->_ary && // Check array
4805 TypeOopPtr::eq(p); // Check sub-parts
4806 }
4807
4808 //------------------------------hash-------------------------------------------
4809 // Type-specific hashing function.
4810 uint TypeAryPtr::hash(void) const {
4811 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4812 }
4813
4814 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4815 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4816 }
4817
4818 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4819 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4820 }
4821
4822 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4823 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4824 }
4825 //------------------------------meet-------------------------------------------
4826 // Compute the MEET of two types. It returns a new Type object.
4827 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4828 // Perform a fast test for common case; meeting the same types together.
4829 if( this == t ) return this; // Meeting same type-rep?
4830 // Current "this->_base" is Pointer
4831 switch (t->base()) { // switch on original type
4838 case HalfFloatBot:
4839 case FloatTop:
4840 case FloatCon:
4841 case FloatBot:
4842 case DoubleTop:
4843 case DoubleCon:
4844 case DoubleBot:
4845 case NarrowOop:
4846 case NarrowKlass:
4847 case Bottom: // Ye Olde Default
4848 return Type::BOTTOM;
4849 case Top:
4850 return this;
4851
4852 default: // All else is a mistake
4853 typerr(t);
4854
4855 case OopPtr: { // Meeting to OopPtrs
4856 // Found a OopPtr type vs self-AryPtr type
4857 const TypeOopPtr *tp = t->is_oopptr();
4858 int offset = meet_offset(tp->offset());
4859 PTR ptr = meet_ptr(tp->ptr());
4860 int depth = meet_inline_depth(tp->inline_depth());
4861 const TypePtr* speculative = xmeet_speculative(tp);
4862 switch (tp->ptr()) {
4863 case TopPTR:
4864 case AnyNull: {
4865 int instance_id = meet_instance_id(InstanceTop);
4866 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4867 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4868 }
4869 case BotPTR:
4870 case NotNull: {
4871 int instance_id = meet_instance_id(tp->instance_id());
4872 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4873 }
4874 default: ShouldNotReachHere();
4875 }
4876 }
4877
4878 case AnyPtr: { // Meeting two AnyPtrs
4879 // Found an AnyPtr type vs self-AryPtr type
4880 const TypePtr *tp = t->is_ptr();
4881 int offset = meet_offset(tp->offset());
4882 PTR ptr = meet_ptr(tp->ptr());
4883 const TypePtr* speculative = xmeet_speculative(tp);
4884 int depth = meet_inline_depth(tp->inline_depth());
4885 switch (tp->ptr()) {
4886 case TopPTR:
4887 return this;
4888 case BotPTR:
4889 case NotNull:
4890 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4891 case Null:
4892 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4893 // else fall through to AnyNull
4894 case AnyNull: {
4895 int instance_id = meet_instance_id(InstanceTop);
4896 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4897 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4898 }
4899 default: ShouldNotReachHere();
4900 }
4901 }
4902
4903 case MetadataPtr:
4904 case KlassPtr:
4905 case InstKlassPtr:
4906 case AryKlassPtr:
4907 case RawPtr: return TypePtr::BOTTOM;
4908
4909 case AryPtr: { // Meeting 2 references?
4910 const TypeAryPtr *tap = t->is_aryptr();
4911 int off = meet_offset(tap->offset());
4912 const Type* tm = _ary->meet_speculative(tap->_ary);
4913 const TypeAry* tary = tm->isa_ary();
4914 if (tary == nullptr) {
4915 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
4916 return tm;
4917 }
4918 PTR ptr = meet_ptr(tap->ptr());
4919 int instance_id = meet_instance_id(tap->instance_id());
4920 const TypePtr* speculative = xmeet_speculative(tap);
4921 int depth = meet_inline_depth(tap->inline_depth());
4922
4923 ciKlass* res_klass = nullptr;
4924 bool res_xk = false;
4925 const Type* elem = tary->_elem;
4926 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4927 instance_id = InstanceBot;
4928 }
4929
4930 ciObject* o = nullptr; // Assume not constant when done
4931 ciObject* this_oop = const_oop();
4932 ciObject* tap_oop = tap->const_oop();
4933 if (ptr == Constant) {
4934 if (this_oop != nullptr && tap_oop != nullptr &&
4935 this_oop->equals(tap_oop)) {
4936 o = tap_oop;
4937 } else if (above_centerline(_ptr)) {
4938 o = tap_oop;
4939 } else if (above_centerline(tap->_ptr)) {
4940 o = this_oop;
4941 } else {
4942 ptr = NotNull;
4943 }
4944 }
4945 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4946 }
4947
4948 // All arrays inherit from Object class
4949 case InstPtr: {
4950 const TypeInstPtr *tp = t->is_instptr();
4951 int offset = meet_offset(tp->offset());
4952 PTR ptr = meet_ptr(tp->ptr());
4953 int instance_id = meet_instance_id(tp->instance_id());
4954 const TypePtr* speculative = xmeet_speculative(tp);
4955 int depth = meet_inline_depth(tp->inline_depth());
4956 const TypeInterfaces* interfaces = meet_interfaces(tp);
4957 const TypeInterfaces* tp_interfaces = tp->_interfaces;
4958 const TypeInterfaces* this_interfaces = _interfaces;
4959
4960 switch (ptr) {
4961 case TopPTR:
4962 case AnyNull: // Fall 'down' to dual of object klass
4963 // For instances when a subclass meets a superclass we fall
4964 // below the centerline when the superclass is exact. We need to
4965 // do the same here.
4966 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4967 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4968 } else {
4969 // cannot subclass, so the meet has to fall badly below the centerline
4970 ptr = NotNull;
4971 instance_id = InstanceBot;
4972 interfaces = this_interfaces->intersection_with(tp_interfaces);
4973 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
4974 }
4975 case Constant:
4976 case NotNull:
4977 case BotPTR: // Fall down to object klass
4978 // LCA is object_klass, but if we subclass from the top we can do better
4979 if (above_centerline(tp->ptr())) {
4980 // If 'tp' is above the centerline and it is Object class
4981 // then we can subclass in the Java class hierarchy.
4982 // For instances when a subclass meets a superclass we fall
4983 // below the centerline when the superclass is exact. We need
4984 // to do the same here.
4985 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4986 // that is, my array type is a subtype of 'tp' klass
4987 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4988 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4989 }
4990 }
4991 // The other case cannot happen, since t cannot be a subtype of an array.
4992 // The meet falls down to Object class below centerline.
4993 if (ptr == Constant) {
4994 ptr = NotNull;
4995 }
4996 if (instance_id > 0) {
4997 instance_id = InstanceBot;
4998 }
4999 interfaces = this_interfaces->intersection_with(tp_interfaces);
5000 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5001 default: typerr(t);
5002 }
5003 }
5004 }
5005 return this; // Lint noise
5006 }
5007
5008
5009 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5010 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5011 int dummy;
5012 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5013 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5014 ciKlass* this_klass = this_ary->klass();
5015 ciKlass* other_klass = other_ary->klass();
5016 bool this_xk = this_ary->klass_is_exact();
5017 bool other_xk = other_ary->klass_is_exact();
5018 PTR this_ptr = this_ary->ptr();
5019 PTR other_ptr = other_ary->ptr();
5020 res_klass = nullptr;
5021 MeetResult result = SUBTYPE;
5022 if (elem->isa_int()) {
5023 // Integral array element types have irrelevant lattice relations.
5024 // It is the klass that determines array layout, not the element type.
5025 if (this_top_or_bottom)
5026 res_klass = other_klass;
5027 else if (other_top_or_bottom || other_klass == this_klass) {
5028 res_klass = this_klass;
5029 } else {
5030 // Something like byte[int+] meets char[int+].
5031 // This must fall to bottom, not (int[-128..65535])[int+].
5032 // instance_id = InstanceBot;
5033 elem = Type::BOTTOM;
5034 result = NOT_SUBTYPE;
5035 if (above_centerline(ptr) || ptr == Constant) {
5036 ptr = NotNull;
5037 res_xk = false;
5038 return NOT_SUBTYPE;
5039 }
5040 }
5041 } else {// Non integral arrays.
5042 // Must fall to bottom if exact klasses in upper lattice
5043 // are not equal or super klass is exact.
5044 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5045 // meet with top[] and bottom[] are processed further down:
5046 !this_top_or_bottom && !other_top_or_bottom &&
5047 // both are exact and not equal:
5049 // 'tap' is exact and super or unrelated:
5050 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5051 // 'this' is exact and super or unrelated:
5052 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5053 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5054 elem = Type::BOTTOM;
5055 }
5056 ptr = NotNull;
5057 res_xk = false;
5058 return NOT_SUBTYPE;
5059 }
5060 }
5061
5062 res_xk = false;
5063 switch (other_ptr) {
5064 case AnyNull:
5065 case TopPTR:
5066 // Compute new klass on demand, do not use tap->_klass
5067 if (below_centerline(this_ptr)) {
5068 res_xk = this_xk;
5069 } else {
5070 res_xk = (other_xk || this_xk);
5071 }
5072 return result;
5073 case Constant: {
5074 if (this_ptr == Constant) {
5075 res_xk = true;
5076 } else if(above_centerline(this_ptr)) {
5077 res_xk = true;
5078 } else {
5079 // Only precise for identical arrays
5080 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5081 }
5082 return result;
5083 }
5084 case NotNull:
5085 case BotPTR:
5086 // Compute new klass on demand, do not use tap->_klass
5087 if (above_centerline(this_ptr)) {
5088 res_xk = other_xk;
5089 } else {
5090 res_xk = (other_xk && this_xk) &&
5091 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5092 }
5093 return result;
5094 default: {
5095 ShouldNotReachHere();
5096 return result;
5097 }
5098 }
5099 return result;
5100 }
5101
5102
5103 //------------------------------xdual------------------------------------------
5104 // Dual: compute field-by-field dual
5105 const Type *TypeAryPtr::xdual() const {
5106 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());
5107 }
5108
5109 //------------------------------dump2------------------------------------------
5110 #ifndef PRODUCT
5111 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5112 st->print("aryptr:");
5113 _ary->dump2(d, depth, st);
5114 _interfaces->dump(st);
5115
5116 if (_ptr == Constant) {
5117 const_oop()->print(st);
5118 }
5119
5120 st->print(":%s", ptr_msg[_ptr]);
5121 if (_klass_is_exact) {
5122 st->print(":exact");
5123 }
5124
5125 if( _offset != 0 ) {
5126 BasicType basic_elem_type = elem()->basic_type();
5127 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5128 if( _offset == OffsetTop ) st->print("+undefined");
5129 else if( _offset == OffsetBot ) st->print("+any");
5130 else if( _offset < header_size ) st->print("+%d", _offset);
5131 else {
5132 if (basic_elem_type == T_ILLEGAL) {
5133 st->print("+any");
5134 } else {
5135 int elem_size = type2aelembytes(basic_elem_type);
5136 st->print("[%d]", (_offset - header_size)/elem_size);
5137 }
5138 }
5139 }
5140
5141 dump_instance_id(st);
5142 dump_inline_depth(st);
5143 dump_speculative(st);
5144 }
5145 #endif
5146
5147 bool TypeAryPtr::empty(void) const {
5148 if (_ary->empty()) return true;
5149 return TypeOopPtr::empty();
5150 }
5151
5152 //------------------------------add_offset-------------------------------------
5153 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5154 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5155 }
5156
5157 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5158 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5159 }
5160
5161 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5162 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5163 }
5164
5165 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5166 if (_speculative == nullptr) {
5167 return this;
5168 }
5169 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5170 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5171 }
5172
5173 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5174 if (!UseInlineDepthForSpeculativeTypes) {
5175 return this;
5176 }
5177 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5178 }
5179
5180 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5181 assert(is_known_instance(), "should be known");
5182 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5183 }
5184
5185 //=============================================================================
5186
5187 //------------------------------hash-------------------------------------------
5188 // Type-specific hashing function.
5189 uint TypeNarrowPtr::hash(void) const {
5190 return _ptrtype->hash() + 7;
5191 }
5192
5193 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5194 return _ptrtype->singleton();
5195 }
5196
5197 bool TypeNarrowPtr::empty(void) const {
5198 return _ptrtype->empty();
5199 }
5200
5201 intptr_t TypeNarrowPtr::get_con() const {
5202 return _ptrtype->get_con();
5203 }
5204
5205 bool TypeNarrowPtr::eq( const Type *t ) const {
5206 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5260 case HalfFloatTop:
5261 case HalfFloatCon:
5262 case HalfFloatBot:
5263 case FloatTop:
5264 case FloatCon:
5265 case FloatBot:
5266 case DoubleTop:
5267 case DoubleCon:
5268 case DoubleBot:
5269 case AnyPtr:
5270 case RawPtr:
5271 case OopPtr:
5272 case InstPtr:
5273 case AryPtr:
5274 case MetadataPtr:
5275 case KlassPtr:
5276 case InstKlassPtr:
5277 case AryKlassPtr:
5278 case NarrowOop:
5279 case NarrowKlass:
5280
5281 case Bottom: // Ye Olde Default
5282 return Type::BOTTOM;
5283 case Top:
5284 return this;
5285
5286 default: // All else is a mistake
5287 typerr(t);
5288
5289 } // End of switch
5290
5291 return this;
5292 }
5293
5294 #ifndef PRODUCT
5295 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5296 _ptrtype->dump2(d, depth, st);
5297 }
5298 #endif
5299
5300 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5344 return (one == two) && TypePtr::eq(t);
5345 } else {
5346 return one->equals(two) && TypePtr::eq(t);
5347 }
5348 }
5349
5350 //------------------------------hash-------------------------------------------
5351 // Type-specific hashing function.
5352 uint TypeMetadataPtr::hash(void) const {
5353 return
5354 (metadata() ? metadata()->hash() : 0) +
5355 TypePtr::hash();
5356 }
5357
5358 //------------------------------singleton--------------------------------------
5359 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5360 // constants
5361 bool TypeMetadataPtr::singleton(void) const {
5362 // detune optimizer to not generate constant metadata + constant offset as a constant!
5363 // TopPTR, Null, AnyNull, Constant are all singletons
5364 return (_offset == 0) && !below_centerline(_ptr);
5365 }
5366
5367 //------------------------------add_offset-------------------------------------
5368 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5369 return make( _ptr, _metadata, xadd_offset(offset));
5370 }
5371
5372 //-----------------------------filter------------------------------------------
5373 // Do not allow interface-vs.-noninterface joins to collapse to top.
5374 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5375 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5376 if (ft == nullptr || ft->empty())
5377 return Type::TOP; // Canonical empty value
5378 return ft;
5379 }
5380
5381 //------------------------------get_con----------------------------------------
5382 intptr_t TypeMetadataPtr::get_con() const {
5383 assert( _ptr == Null || _ptr == Constant, "" );
5384 assert( _offset >= 0, "" );
5385
5386 if (_offset != 0) {
5387 // After being ported to the compiler interface, the compiler no longer
5388 // directly manipulates the addresses of oops. Rather, it only has a pointer
5389 // to a handle at compile time. This handle is embedded in the generated
5390 // code and dereferenced at the time the nmethod is made. Until that time,
5391 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5392 // have access to the addresses!). This does not seem to currently happen,
5393 // but this assertion here is to help prevent its occurrence.
5394 tty->print_cr("Found oop constant with non-zero offset");
5395 ShouldNotReachHere();
5396 }
5397
5398 return (intptr_t)metadata()->constant_encoding();
5399 }
5400
5401 //------------------------------cast_to_ptr_type-------------------------------
5402 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5403 if( ptr == _ptr ) return this;
5404 return make(ptr, metadata(), _offset);
5405 }
5406
5420 case HalfFloatBot:
5421 case FloatTop:
5422 case FloatCon:
5423 case FloatBot:
5424 case DoubleTop:
5425 case DoubleCon:
5426 case DoubleBot:
5427 case NarrowOop:
5428 case NarrowKlass:
5429 case Bottom: // Ye Olde Default
5430 return Type::BOTTOM;
5431 case Top:
5432 return this;
5433
5434 default: // All else is a mistake
5435 typerr(t);
5436
5437 case AnyPtr: {
5438 // Found an AnyPtr type vs self-OopPtr type
5439 const TypePtr *tp = t->is_ptr();
5440 int offset = meet_offset(tp->offset());
5441 PTR ptr = meet_ptr(tp->ptr());
5442 switch (tp->ptr()) {
5443 case Null:
5444 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5445 // else fall through:
5446 case TopPTR:
5447 case AnyNull: {
5448 return make(ptr, _metadata, offset);
5449 }
5450 case BotPTR:
5451 case NotNull:
5452 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5453 default: typerr(t);
5454 }
5455 }
5456
5457 case RawPtr:
5458 case KlassPtr:
5459 case InstKlassPtr:
5460 case AryKlassPtr:
5461 case OopPtr:
5462 case InstPtr:
5463 case AryPtr:
5464 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5465
5466 case MetadataPtr: {
5467 const TypeMetadataPtr *tp = t->is_metadataptr();
5468 int offset = meet_offset(tp->offset());
5469 PTR tptr = tp->ptr();
5470 PTR ptr = meet_ptr(tptr);
5471 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5472 if (tptr == TopPTR || _ptr == TopPTR ||
5473 metadata()->equals(tp->metadata())) {
5474 return make(ptr, md, offset);
5475 }
5476 // metadata is different
5477 if( ptr == Constant ) { // Cannot be equal constants, so...
5478 if( tptr == Constant && _ptr != Constant) return t;
5479 if( _ptr == Constant && tptr != Constant) return this;
5480 ptr = NotNull; // Fall down in lattice
5481 }
5482 return make(ptr, nullptr, offset);
5483 break;
5484 }
5485 } // End of switch
5486 return this; // Return the double constant
5487 }
5488
5492 const Type *TypeMetadataPtr::xdual() const {
5493 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5494 }
5495
5496 //------------------------------dump2------------------------------------------
5497 #ifndef PRODUCT
5498 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5499 st->print("metadataptr:%s", ptr_msg[_ptr]);
5500 if (metadata() != nullptr) {
5501 st->print(":" INTPTR_FORMAT, p2i(metadata()));
5502 }
5503 dump_offset(st);
5504 }
5505 #endif
5506
5507
5508 //=============================================================================
5509 // Convenience common pre-built type.
5510 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5511
5512 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5513 TypePtr(MetadataPtr, ptr, offset, relocInfo::metadata_type), _metadata(metadata) {
5514 }
5515
5516 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5517 return make(Constant, m, 0);
5518 }
5519 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5520 return make(Constant, m, 0);
5521 }
5522
5523 //------------------------------make-------------------------------------------
5524 // Create a meta data constant
5525 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5526 assert(m == nullptr || !m->is_klass(), "wrong type");
5527 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5528 }
5529
5530
5531 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5532 const Type* elem = _ary->_elem;
5533 bool xk = klass_is_exact();
5534 if (elem->make_oopptr() != nullptr) {
5535 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5536 if (elem->is_klassptr()->klass_is_exact()) {
5537 xk = true;
5538 }
5539 }
5540 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5541 }
5542
5543 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5544 if (klass->is_instance_klass()) {
5545 return TypeInstKlassPtr::make(klass, interface_handling);
5546 }
5547 return TypeAryKlassPtr::make(klass, interface_handling);
5548 }
5549
5550 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5551 if (klass->is_instance_klass()) {
5552 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5553 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5554 }
5555 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5556 }
5557
5558
5559 //------------------------------TypeKlassPtr-----------------------------------
5560 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5561 : TypePtr(t, ptr, offset, relocInfo::metadata_type), _klass(klass), _interfaces(interfaces) {
5562 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5563 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5564 }
5565
5566 // Is there a single ciKlass* that can represent that type?
5567 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5568 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5569 if (_interfaces->empty()) {
5570 return _klass;
5571 }
5572 if (_klass != ciEnv::current()->Object_klass()) {
5573 if (_interfaces->eq(_klass->as_instance_klass())) {
5574 return _klass;
5575 }
5576 return nullptr;
5577 }
5578 return _interfaces->exact_klass();
5579 }
5580
5581 //------------------------------eq---------------------------------------------
5582 // Structural equality check for Type representations
5583 bool TypeKlassPtr::eq(const Type *t) const {
5584 const TypeKlassPtr *p = t->is_klassptr();
5585 return
5586 _interfaces->eq(p->_interfaces) &&
5587 TypePtr::eq(p);
5588 }
5589
5590 //------------------------------hash-------------------------------------------
5591 // Type-specific hashing function.
5592 uint TypeKlassPtr::hash(void) const {
5593 return TypePtr::hash() + _interfaces->hash();
5594 }
5595
5596 //------------------------------singleton--------------------------------------
5597 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5598 // constants
5599 bool TypeKlassPtr::singleton(void) const {
5600 // detune optimizer to not generate constant klass + constant offset as a constant!
5601 // TopPTR, Null, AnyNull, Constant are all singletons
5602 return (_offset == 0) && !below_centerline(_ptr);
5603 }
5604
5605 // Do not allow interface-vs.-noninterface joins to collapse to top.
5606 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5607 // logic here mirrors the one from TypeOopPtr::filter. See comments
5608 // there.
5609 const Type* ft = join_helper(kills, include_speculative);
5610
5611 if (ft->empty()) {
5612 return Type::TOP; // Canonical empty value
5613 }
5614
5615 return ft;
5616 }
5617
5618 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5619 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5620 return _interfaces->union_with(other->_interfaces);
5621 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5622 return other->_interfaces;
5623 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5624 return _interfaces;
5625 }
5626 return _interfaces->intersection_with(other->_interfaces);
5627 }
5628
5629 //------------------------------get_con----------------------------------------
5630 intptr_t TypeKlassPtr::get_con() const {
5631 assert( _ptr == Null || _ptr == Constant, "" );
5632 assert( _offset >= 0, "" );
5633
5634 if (_offset != 0) {
5635 // After being ported to the compiler interface, the compiler no longer
5636 // directly manipulates the addresses of oops. Rather, it only has a pointer
5637 // to a handle at compile time. This handle is embedded in the generated
5638 // code and dereferenced at the time the nmethod is made. Until that time,
5639 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5640 // have access to the addresses!). This does not seem to currently happen,
5641 // but this assertion here is to help prevent its occurrence.
5642 tty->print_cr("Found oop constant with non-zero offset");
5643 ShouldNotReachHere();
5644 }
5645
5646 ciKlass* k = exact_klass();
5647
5648 return (intptr_t)k->constant_encoding();
5649 }
5650
5651 //=============================================================================
5652 // Convenience common pre-built types.
5653
5654 // Not-null object klass or below
5655 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5656 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5657
5658 bool TypeInstKlassPtr::eq(const Type *t) const {
5659 const TypeKlassPtr *p = t->is_klassptr();
5660 return
5661 klass()->equals(p->klass()) &&
5662 TypeKlassPtr::eq(p);
5663 }
5664
5665 uint TypeInstKlassPtr::hash(void) const {
5666 return klass()->hash() + TypeKlassPtr::hash();
5667 }
5668
5669 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5670 TypeInstKlassPtr *r =
5671 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5672
5673 return r;
5674 }
5675
5676 //------------------------------add_offset-------------------------------------
5677 // Access internals of klass object
5678 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5679 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5680 }
5681
5682 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5683 return make(_ptr, klass(), _interfaces, offset);
5684 }
5685
5686 //------------------------------cast_to_ptr_type-------------------------------
5687 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5688 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5689 if( ptr == _ptr ) return this;
5690 return make(ptr, _klass, _interfaces, _offset);
5691 }
5692
5693
5694 bool TypeInstKlassPtr::must_be_exact() const {
5695 if (!_klass->is_loaded()) return false;
5696 ciInstanceKlass* ik = _klass->as_instance_klass();
5697 if (ik->is_final()) return true; // cannot clear xk
5698 return false;
5699 }
5700
5701 //-----------------------------cast_to_exactness-------------------------------
5702 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5703 if (klass_is_exact == (_ptr == Constant)) return this;
5704 if (must_be_exact()) return this;
5705 ciKlass* k = klass();
5706 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5707 }
5708
5709
5710 //-----------------------------as_instance_type--------------------------------
5711 // Corresponding type for an instance of the given class.
5712 // It will be NotNull, and exact if and only if the klass type is exact.
5713 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5714 ciKlass* k = klass();
5715 bool xk = klass_is_exact();
5716 Compile* C = Compile::current();
5717 Dependencies* deps = C->dependencies();
5718 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5719 // Element is an instance
5720 bool klass_is_exact = false;
5721 const TypeInterfaces* interfaces = _interfaces;
5722 if (k->is_loaded()) {
5723 // Try to set klass_is_exact.
5724 ciInstanceKlass* ik = k->as_instance_klass();
5725 klass_is_exact = ik->is_final();
5726 if (!klass_is_exact && klass_change
5727 && deps != nullptr && UseUniqueSubclasses) {
5728 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5729 if (sub != nullptr) {
5730 if (_interfaces->eq(sub)) {
5731 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5732 k = ik = sub;
5733 xk = sub->is_final();
5734 }
5735 }
5736 }
5737 }
5738 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5739 }
5740
5741 //------------------------------xmeet------------------------------------------
5742 // Compute the MEET of two types, return a new Type object.
5743 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5744 // Perform a fast test for common case; meeting the same types together.
5745 if( this == t ) return this; // Meeting same type-rep?
5746
5747 // Current "this->_base" is Pointer
5748 switch (t->base()) { // switch on original type
5749
5750 case Int: // Mixing ints & oops happens when javac
5751 case Long: // reuses local variables
5752 case HalfFloatTop:
5753 case HalfFloatCon:
5754 case HalfFloatBot:
5755 case FloatTop:
5756 case FloatCon:
5757 case FloatBot:
5758 case DoubleTop:
5759 case DoubleCon:
5760 case DoubleBot:
5761 case NarrowOop:
5762 case NarrowKlass:
5763 case Bottom: // Ye Olde Default
5764 return Type::BOTTOM;
5765 case Top:
5766 return this;
5767
5768 default: // All else is a mistake
5769 typerr(t);
5770
5771 case AnyPtr: { // Meeting to AnyPtrs
5772 // Found an AnyPtr type vs self-KlassPtr type
5773 const TypePtr *tp = t->is_ptr();
5774 int offset = meet_offset(tp->offset());
5775 PTR ptr = meet_ptr(tp->ptr());
5776 switch (tp->ptr()) {
5777 case TopPTR:
5778 return this;
5779 case Null:
5780 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5781 case AnyNull:
5782 return make( ptr, klass(), _interfaces, offset );
5783 case BotPTR:
5784 case NotNull:
5785 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5786 default: typerr(t);
5787 }
5788 }
5789
5790 case RawPtr:
5791 case MetadataPtr:
5792 case OopPtr:
5793 case AryPtr: // Meet with AryPtr
5794 case InstPtr: // Meet with InstPtr
5795 return TypePtr::BOTTOM;
5796
5797 //
5798 // A-top }
5799 // / | \ } Tops
5800 // B-top A-any C-top }
5801 // | / | \ | } Any-nulls
5802 // B-any | C-any }
5803 // | | |
5804 // B-con A-con C-con } constants; not comparable across classes
5805 // | | |
5806 // B-not | C-not }
5807 // | \ | / | } not-nulls
5808 // B-bot A-not C-bot }
5809 // \ | / } Bottoms
5810 // A-bot }
5811 //
5812
5813 case InstKlassPtr: { // Meet two KlassPtr types
5814 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5815 int off = meet_offset(tkls->offset());
5816 PTR ptr = meet_ptr(tkls->ptr());
5817 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5818
5819 ciKlass* res_klass = nullptr;
5820 bool res_xk = false;
5821 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5822 case UNLOADED:
5823 ShouldNotReachHere();
5824 case SUBTYPE:
5825 case NOT_SUBTYPE:
5826 case LCA:
5827 case QUICK: {
5828 assert(res_xk == (ptr == Constant), "");
5829 const Type* res = make(ptr, res_klass, interfaces, off);
5830 return res;
5831 }
5832 default:
5833 ShouldNotReachHere();
5834 }
5835 } // End of case KlassPtr
5836 case AryKlassPtr: { // All arrays inherit from Object class
5837 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5838 int offset = meet_offset(tp->offset());
5839 PTR ptr = meet_ptr(tp->ptr());
5840 const TypeInterfaces* interfaces = meet_interfaces(tp);
5841 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5842 const TypeInterfaces* this_interfaces = _interfaces;
5843
5844 switch (ptr) {
5845 case TopPTR:
5846 case AnyNull: // Fall 'down' to dual of object klass
5847 // For instances when a subclass meets a superclass we fall
5848 // below the centerline when the superclass is exact. We need to
5849 // do the same here.
5850 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5851 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5852 } else {
5853 // cannot subclass, so the meet has to fall badly below the centerline
5854 ptr = NotNull;
5855 interfaces = _interfaces->intersection_with(tp->_interfaces);
5856 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5857 }
5858 case Constant:
5859 case NotNull:
5860 case BotPTR: // Fall down to object klass
5861 // LCA is object_klass, but if we subclass from the top we can do better
5862 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5863 // If 'this' (InstPtr) is above the centerline and it is Object class
5864 // then we can subclass in the Java class hierarchy.
5865 // For instances when a subclass meets a superclass we fall
5866 // below the centerline when the superclass is exact. We need
5867 // to do the same here.
5868 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5869 // that is, tp's array type is a subtype of my klass
5870 return TypeAryKlassPtr::make(ptr,
5871 tp->elem(), tp->klass(), offset);
5872 }
5873 }
5874 // The other case cannot happen, since I cannot be a subtype of an array.
5875 // The meet falls down to Object class below centerline.
5876 if( ptr == Constant )
5877 ptr = NotNull;
5878 interfaces = this_interfaces->intersection_with(tp_interfaces);
5879 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5880 default: typerr(t);
5881 }
5882 }
5883
5884 } // End of switch
5885 return this; // Return the double constant
5886 }
5887
5888 //------------------------------xdual------------------------------------------
5889 // Dual: compute field-by-field dual
5890 const Type *TypeInstKlassPtr::xdual() const {
5891 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5892 }
5893
5894 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) {
5895 static_assert(std::is_base_of<T2, T1>::value, "");
5896 if (!this_one->is_loaded() || !other->is_loaded()) {
5897 return false;
5898 }
5899 if (!this_one->is_instance_type(other)) {
5900 return false;
5901 }
5902
5903 if (!other_exact) {
5904 return false;
5905 }
5906
5907 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5908 return true;
5909 }
5910
5911 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5967 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5968 }
5969
5970 return true;
5971 }
5972
5973 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5974 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5975 }
5976
5977 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
5978 if (!UseUniqueSubclasses) {
5979 return this;
5980 }
5981 ciKlass* k = klass();
5982 Compile* C = Compile::current();
5983 Dependencies* deps = C->dependencies();
5984 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5985 if (k->is_loaded()) {
5986 ciInstanceKlass* ik = k->as_instance_klass();
5987 bool klass_is_exact = ik->is_final();
5988 if (!klass_is_exact && deps != nullptr) {
5989 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5990 if (sub != nullptr && _interfaces->is_subset(sub)) {
5991 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5992 k = ik = sub;
5993 klass_is_exact = sub->is_final();
5994 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
5995 }
5996 }
5997 }
5998 return this;
5999 }
6000
6001 #ifndef PRODUCT
6002 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6003 st->print("instklassptr:");
6004 klass()->print_name_on(st);
6005 _interfaces->dump(st);
6006 st->print(":%s", ptr_msg[_ptr]);
6007 dump_offset(st);
6008 }
6009 #endif // PRODUCT
6010
6011 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6012 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6013 }
6014
6015 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6016 if (k->is_obj_array_klass()) {
6017 // Element is an object array. Recursively call ourself.
6018 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6019 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6020 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6021 } else if (k->is_type_array_klass()) {
6022 // Element is an typeArray
6023 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6024 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6025 } else {
6026 ShouldNotReachHere();
6027 return nullptr;
6028 }
6029 }
6030
6031 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6032 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6033 }
6034
6035 //------------------------------eq---------------------------------------------
6036 // Structural equality check for Type representations
6037 bool TypeAryKlassPtr::eq(const Type *t) const {
6038 const TypeAryKlassPtr *p = t->is_aryklassptr();
6039 return
6040 _elem == p->_elem && // Check array
6041 TypeKlassPtr::eq(p); // Check sub-parts
6042 }
6043
6044 //------------------------------hash-------------------------------------------
6045 // Type-specific hashing function.
6046 uint TypeAryKlassPtr::hash(void) const {
6047 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6048 }
6049
6050 //----------------------compute_klass------------------------------------------
6051 // Compute the defining klass for this class
6052 ciKlass* TypeAryPtr::compute_klass() const {
6053 // Compute _klass based on element type.
6054 ciKlass* k_ary = nullptr;
6055 const TypeInstPtr *tinst;
6056 const TypeAryPtr *tary;
6057 const Type* el = elem();
6058 if (el->isa_narrowoop()) {
6059 el = el->make_ptr();
6060 }
6061
6062 // Get element klass
6063 if ((tinst = el->isa_instptr()) != nullptr) {
6064 // Leave k_ary at null.
6065 } else if ((tary = el->isa_aryptr()) != nullptr) {
6066 // Leave k_ary at null.
6067 } else if ((el->base() == Type::Top) ||
6068 (el->base() == Type::Bottom)) {
6069 // element type of Bottom occurs from meet of basic type
6070 // and object; Top occurs when doing join on Bottom.
6071 // Leave k_ary at null.
6072 } else {
6073 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6074 // Compute array klass directly from basic type
6075 k_ary = ciTypeArrayKlass::make(el->basic_type());
6076 }
6077 return k_ary;
6078 }
6079
6080 //------------------------------klass------------------------------------------
6081 // Return the defining klass for this class
6082 ciKlass* TypeAryPtr::klass() const {
6083 if( _klass ) return _klass; // Return cached value, if possible
6084
6085 // Oops, need to compute _klass and cache it
6086 ciKlass* k_ary = compute_klass();
6094 // type TypeAryPtr::OOPS. This Type is shared between all
6095 // active compilations. However, the ciKlass which represents
6096 // this Type is *not* shared between compilations, so caching
6097 // this value would result in fetching a dangling pointer.
6098 //
6099 // Recomputing the underlying ciKlass for each request is
6100 // a bit less efficient than caching, but calls to
6101 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6102 ((TypeAryPtr*)this)->_klass = k_ary;
6103 }
6104 return k_ary;
6105 }
6106
6107 // Is there a single ciKlass* that can represent that type?
6108 ciKlass* TypeAryPtr::exact_klass_helper() const {
6109 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6110 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6111 if (k == nullptr) {
6112 return nullptr;
6113 }
6114 k = ciObjArrayKlass::make(k);
6115 return k;
6116 }
6117
6118 return klass();
6119 }
6120
6121 const Type* TypeAryPtr::base_element_type(int& dims) const {
6122 const Type* elem = this->elem();
6123 dims = 1;
6124 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6125 elem = elem->make_ptr()->is_aryptr()->elem();
6126 dims++;
6127 }
6128 return elem;
6129 }
6130
6131 //------------------------------add_offset-------------------------------------
6132 // Access internals of klass object
6133 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6134 return make(_ptr, elem(), klass(), xadd_offset(offset));
6135 }
6136
6137 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6138 return make(_ptr, elem(), klass(), offset);
6139 }
6140
6141 //------------------------------cast_to_ptr_type-------------------------------
6142 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6143 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6144 if (ptr == _ptr) return this;
6145 return make(ptr, elem(), _klass, _offset);
6146 }
6147
6148 bool TypeAryKlassPtr::must_be_exact() const {
6149 if (_elem == Type::BOTTOM) return false;
6150 if (_elem == Type::TOP ) return false;
6151 const TypeKlassPtr* tk = _elem->isa_klassptr();
6152 if (!tk) return true; // a primitive type, like int
6153 return tk->must_be_exact();
6154 }
6155
6156
6157 //-----------------------------cast_to_exactness-------------------------------
6158 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6159 if (must_be_exact()) return this; // cannot clear xk
6160 ciKlass* k = _klass;
6161 const Type* elem = this->elem();
6162 if (elem->isa_klassptr() && !klass_is_exact) {
6163 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6164 }
6165 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6166 }
6167
6168
6169 //-----------------------------as_instance_type--------------------------------
6170 // Corresponding type for an instance of the given class.
6171 // It will be NotNull, and exact if and only if the klass type is exact.
6172 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6173 ciKlass* k = klass();
6174 bool xk = klass_is_exact();
6175 const Type* el = nullptr;
6176 if (elem()->isa_klassptr()) {
6177 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6178 k = nullptr;
6179 } else {
6180 el = elem();
6181 }
6182 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6183 }
6184
6185
6186 //------------------------------xmeet------------------------------------------
6187 // Compute the MEET of two types, return a new Type object.
6188 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6189 // Perform a fast test for common case; meeting the same types together.
6190 if( this == t ) return this; // Meeting same type-rep?
6191
6192 // Current "this->_base" is Pointer
6193 switch (t->base()) { // switch on original type
6194
6195 case Int: // Mixing ints & oops happens when javac
6196 case Long: // reuses local variables
6197 case HalfFloatTop:
6198 case HalfFloatCon:
6199 case HalfFloatBot:
6200 case FloatTop:
6201 case FloatCon:
6202 case FloatBot:
6203 case DoubleTop:
6204 case DoubleCon:
6205 case DoubleBot:
6206 case NarrowOop:
6207 case NarrowKlass:
6208 case Bottom: // Ye Olde Default
6209 return Type::BOTTOM;
6210 case Top:
6211 return this;
6212
6213 default: // All else is a mistake
6214 typerr(t);
6215
6216 case AnyPtr: { // Meeting to AnyPtrs
6217 // Found an AnyPtr type vs self-KlassPtr type
6218 const TypePtr *tp = t->is_ptr();
6219 int offset = meet_offset(tp->offset());
6220 PTR ptr = meet_ptr(tp->ptr());
6221 switch (tp->ptr()) {
6222 case TopPTR:
6223 return this;
6224 case Null:
6225 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6226 case AnyNull:
6227 return make( ptr, _elem, klass(), offset );
6228 case BotPTR:
6229 case NotNull:
6230 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6231 default: typerr(t);
6232 }
6233 }
6234
6235 case RawPtr:
6236 case MetadataPtr:
6237 case OopPtr:
6238 case AryPtr: // Meet with AryPtr
6239 case InstPtr: // Meet with InstPtr
6240 return TypePtr::BOTTOM;
6241
6242 //
6243 // A-top }
6244 // / | \ } Tops
6245 // B-top A-any C-top }
6246 // | / | \ | } Any-nulls
6247 // B-any | C-any }
6248 // | | |
6249 // B-con A-con C-con } constants; not comparable across classes
6250 // | | |
6251 // B-not | C-not }
6252 // | \ | / | } not-nulls
6253 // B-bot A-not C-bot }
6254 // \ | / } Bottoms
6255 // A-bot }
6256 //
6257
6258 case AryKlassPtr: { // Meet two KlassPtr types
6259 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6260 int off = meet_offset(tap->offset());
6261 const Type* elem = _elem->meet(tap->_elem);
6262
6263 PTR ptr = meet_ptr(tap->ptr());
6264 ciKlass* res_klass = nullptr;
6265 bool res_xk = false;
6266 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6267 assert(res_xk == (ptr == Constant), "");
6268 return make(ptr, elem, res_klass, off);
6269 } // End of case KlassPtr
6270 case InstKlassPtr: {
6271 const TypeInstKlassPtr *tp = t->is_instklassptr();
6272 int offset = meet_offset(tp->offset());
6273 PTR ptr = meet_ptr(tp->ptr());
6274 const TypeInterfaces* interfaces = meet_interfaces(tp);
6275 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6276 const TypeInterfaces* this_interfaces = _interfaces;
6277
6278 switch (ptr) {
6279 case TopPTR:
6280 case AnyNull: // Fall 'down' to dual of object klass
6281 // For instances when a subclass meets a superclass we fall
6282 // below the centerline when the superclass is exact. We need to
6283 // do the same here.
6284 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6285 !tp->klass_is_exact()) {
6286 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6287 } else {
6288 // cannot subclass, so the meet has to fall badly below the centerline
6289 ptr = NotNull;
6290 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6291 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6292 }
6293 case Constant:
6294 case NotNull:
6295 case BotPTR: // Fall down to object klass
6296 // LCA is object_klass, but if we subclass from the top we can do better
6297 if (above_centerline(tp->ptr())) {
6298 // If 'tp' is above the centerline and it is Object class
6299 // then we can subclass in the Java class hierarchy.
6300 // For instances when a subclass meets a superclass we fall
6301 // below the centerline when the superclass is exact. We need
6302 // to do the same here.
6303 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6304 !tp->klass_is_exact()) {
6305 // that is, my array type is a subtype of 'tp' klass
6306 return make(ptr, _elem, _klass, offset);
6307 }
6308 }
6309 // The other case cannot happen, since t cannot be a subtype of an array.
6310 // The meet falls down to Object class below centerline.
6311 if (ptr == Constant)
6312 ptr = NotNull;
6313 interfaces = this_interfaces->intersection_with(tp_interfaces);
6314 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6315 default: typerr(t);
6316 }
6317 }
6318
6319 } // End of switch
6320 return this; // Return the double constant
6321 }
6322
6323 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) {
6324 static_assert(std::is_base_of<T2, T1>::value, "");
6325
6326 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6327 return true;
6328 }
6329
6330 int dummy;
6331 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6332
6333 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6334 return false;
6335 }
6336
6337 if (this_one->is_instance_type(other)) {
6338 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6339 other_exact;
6340 }
6341
6342 assert(this_one->is_array_type(other), "");
6343 const T1* other_ary = this_one->is_array_type(other);
6344 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6345 if (other_top_or_bottom) {
6346 return false;
6347 }
6348
6349 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6350 const TypePtr* this_elem = this_one->elem()->make_ptr();
6351 if (this_elem != nullptr && other_elem != nullptr) {
6352 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6353 }
6354 if (this_elem == nullptr && other_elem == nullptr) {
6355 return this_one->klass()->is_subtype_of(other->klass());
6356 }
6357 return false;
6358 }
6359
6360 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6361 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6362 }
6363
6364 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6365 static_assert(std::is_base_of<T2, T1>::value, "");
6366
6367 int dummy;
6368 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6369
6370 if (!this_one->is_array_type(other) ||
6371 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6424 }
6425
6426 const TypePtr* this_elem = this_one->elem()->make_ptr();
6427 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6428 if (other_elem != nullptr && this_elem != nullptr) {
6429 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6430 }
6431 if (other_elem == nullptr && this_elem == nullptr) {
6432 return this_one->klass()->is_subtype_of(other->klass());
6433 }
6434 return false;
6435 }
6436
6437 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6438 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6439 }
6440
6441 //------------------------------xdual------------------------------------------
6442 // Dual: compute field-by-field dual
6443 const Type *TypeAryKlassPtr::xdual() const {
6444 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6445 }
6446
6447 // Is there a single ciKlass* that can represent that type?
6448 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6449 if (elem()->isa_klassptr()) {
6450 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6451 if (k == nullptr) {
6452 return nullptr;
6453 }
6454 k = ciObjArrayKlass::make(k);
6455 return k;
6456 }
6457
6458 return klass();
6459 }
6460
6461 ciKlass* TypeAryKlassPtr::klass() const {
6462 if (_klass != nullptr) {
6463 return _klass;
6464 }
6465 ciKlass* k = nullptr;
6466 if (elem()->isa_klassptr()) {
6467 // leave null
6468 } else if ((elem()->base() == Type::Top) ||
6469 (elem()->base() == Type::Bottom)) {
6470 } else {
6471 k = ciTypeArrayKlass::make(elem()->basic_type());
6472 ((TypeAryKlassPtr*)this)->_klass = k;
6473 }
6474 return k;
6475 }
6476
6477 //------------------------------dump2------------------------------------------
6478 // Dump Klass Type
6479 #ifndef PRODUCT
6480 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6481 st->print("aryklassptr:[");
6482 _elem->dump2(d, depth, st);
6483 _interfaces->dump(st);
6484 st->print(":%s", ptr_msg[_ptr]);
6485 dump_offset(st);
6486 }
6487 #endif
6488
6489 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6490 const Type* elem = this->elem();
6491 dims = 1;
6492 while (elem->isa_aryklassptr()) {
6493 elem = elem->is_aryklassptr()->elem();
6494 dims++;
6495 }
6496 return elem;
6497 }
6498
6499 //=============================================================================
6500 // Convenience common pre-built types.
6501
6502 //------------------------------make-------------------------------------------
6503 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6504 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6505 }
6506
6507 //------------------------------make-------------------------------------------
6508 const TypeFunc *TypeFunc::make(ciMethod* method) {
6509 Compile* C = Compile::current();
6510 const TypeFunc* tf = C->last_tf(method); // check cache
6511 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6512 const TypeTuple *domain;
6513 if (method->is_static()) {
6514 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6515 } else {
6516 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6517 }
6518 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6519 tf = TypeFunc::make(domain, range);
6520 C->set_last_tf(method, tf); // fill cache
6521 return tf;
6522 }
6523
6524 //------------------------------meet-------------------------------------------
6525 // Compute the MEET of two types. It returns a new Type object.
6526 const Type *TypeFunc::xmeet( const Type *t ) const {
6527 // Perform a fast test for common case; meeting the same types together.
6528 if( this == t ) return this; // Meeting same type-rep?
6529
6530 // Current "this->_base" is Func
6531 switch (t->base()) { // switch on original type
6532
6533 case Bottom: // Ye Olde Default
6534 return t;
6535
6536 default: // All else is a mistake
6537 typerr(t);
6538
6539 case Top:
6540 break;
6541 }
6542 return this; // Return the double constant
6543 }
6544
6545 //------------------------------xdual------------------------------------------
6546 // Dual: compute field-by-field dual
6547 const Type *TypeFunc::xdual() const {
6548 return this;
6549 }
6550
6551 //------------------------------eq---------------------------------------------
6552 // Structural equality check for Type representations
6553 bool TypeFunc::eq( const Type *t ) const {
6554 const TypeFunc *a = (const TypeFunc*)t;
6555 return _domain == a->_domain &&
6556 _range == a->_range;
6557 }
6558
6559 //------------------------------hash-------------------------------------------
6560 // Type-specific hashing function.
6561 uint TypeFunc::hash(void) const {
6562 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6563 }
6564
6565 //------------------------------dump2------------------------------------------
6566 // Dump Function Type
6567 #ifndef PRODUCT
6568 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6569 if( _range->cnt() <= Parms )
6570 st->print("void");
6571 else {
6572 uint i;
6573 for (i = Parms; i < _range->cnt()-1; i++) {
6574 _range->field_at(i)->dump2(d,depth,st);
6575 st->print("/");
6576 }
6577 _range->field_at(i)->dump2(d,depth,st);
6578 }
6579 st->print(" ");
6580 st->print("( ");
6581 if( !depth || d[this] ) { // Check for recursive dump
6582 st->print("...)");
6583 return;
6584 }
6585 d.Insert((void*)this,(void*)this); // Stop recursion
6586 if (Parms < _domain->cnt())
6587 _domain->field_at(Parms)->dump2(d,depth-1,st);
6588 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6589 st->print(", ");
6590 _domain->field_at(i)->dump2(d,depth-1,st);
6591 }
6592 st->print(" )");
6593 }
6594 #endif
6595
6596 //------------------------------singleton--------------------------------------
6597 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6598 // constants (Ldi nodes). Singletons are integer, float or double constants
6599 // or a single symbol.
6600 bool TypeFunc::singleton(void) const {
6601 return false; // Never a singleton
6602 }
6603
6604 bool TypeFunc::empty(void) const {
6605 return false; // Never empty
6606 }
6607
6608
6609 BasicType TypeFunc::return_type() const{
6610 if (range()->cnt() == TypeFunc::Parms) {
6611 return T_VOID;
6612 }
6613 return range()->field_at(TypeFunc::Parms)->basic_type();
6614 }
|
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/ciFlatArray.hpp"
27 #include "ci/ciFlatArrayKlass.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciInstanceKlass.hpp"
30 #include "ci/ciMethodData.hpp"
31 #include "ci/ciObjArrayKlass.hpp"
32 #include "ci/ciTypeFlow.hpp"
33 #include "classfile/javaClasses.hpp"
34 #include "classfile/symbolTable.hpp"
35 #include "classfile/vmSymbols.hpp"
36 #include "compiler/compileLog.hpp"
37 #include "libadt/dict.hpp"
38 #include "memory/oopFactory.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "oops/instanceKlass.hpp"
41 #include "oops/instanceMirrorKlass.hpp"
42 #include "oops/objArrayKlass.hpp"
43 #include "oops/typeArrayKlass.hpp"
44 #include "opto/arraycopynode.hpp"
45 #include "opto/callnode.hpp"
46 #include "opto/matcher.hpp"
47 #include "opto/node.hpp"
48 #include "opto/opcodes.hpp"
49 #include "opto/rangeinference.hpp"
50 #include "opto/runtime.hpp"
51 #include "opto/type.hpp"
52 #include "runtime/globals.hpp"
53 #include "runtime/stubRoutines.hpp"
54 #include "utilities/checkedCast.hpp"
55 #include "utilities/debug.hpp"
56 #include "utilities/globalDefinitions.hpp"
57 #include "utilities/ostream.hpp"
58 #include "utilities/powerOfTwo.hpp"
59 #include "utilities/stringUtils.hpp"
60
61 // Portions of code courtesy of Clifford Click
62
63 // Optimization - Graph Style
64
65 // Dictionary of types shared among compilations.
66 Dict* Type::_shared_type_dict = nullptr;
67 const Type::Offset Type::Offset::top(Type::OffsetTop);
68 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
69
70 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
71 // Either is 'TOP' offset? Return the other offset!
72 if (_offset == OffsetTop) return other;
73 if (other._offset == OffsetTop) return *this;
74 // If either is different, return 'BOTTOM' offset
75 if (_offset != other._offset) return bottom;
76 return Offset(_offset);
77 }
78
79 const Type::Offset Type::Offset::dual() const {
80 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
81 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
82 return Offset(_offset); // Map everything else into self
83 }
84
85 const Type::Offset Type::Offset::add(intptr_t offset) const {
86 // Adding to 'TOP' offset? Return 'TOP'!
87 if (_offset == OffsetTop || offset == OffsetTop) return top;
88 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
89 if (_offset == OffsetBot || offset == OffsetBot) return bottom;
90 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
91 offset += (intptr_t)_offset;
92 if (offset != (int)offset || offset == OffsetTop) return bottom;
93
94 // assert( _offset >= 0 && _offset+offset >= 0, "" );
95 // It is possible to construct a negative offset during PhaseCCP
96
97 return Offset((int)offset); // Sum valid offsets
98 }
99
100 void Type::Offset::dump2(outputStream *st) const {
101 if (_offset == 0) {
102 return;
103 } else if (_offset == OffsetTop) {
104 st->print("+top");
105 } else if (_offset == OffsetBot) {
106 st->print("+bot");
107 } else {
108 st->print("+%d", _offset);
109 }
110 }
111
112 // Array which maps compiler types to Basic Types
113 const Type::TypeInfo Type::_type_info[Type::lastype] = {
114 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg}, // Bad
115 { Control, T_ILLEGAL, "control", false, 0 }, // Control
116 { Bottom, T_VOID, "top", false, 0 }, // Top
117 { Bad, T_INT, "int:", false, Op_RegI }, // Int
118 { Bad, T_LONG, "long:", false, Op_RegL }, // Long
119 { Half, T_VOID, "half", false, 0 }, // Half
120 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN }, // NarrowOop
121 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN }, // NarrowKlass
122 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg}, // Tuple
123 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg}, // Array
124 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg}, // Interfaces
125
126 #if defined(PPC64)
127 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask }, // VectorMask.
128 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA }, // VectorA.
129 { Bad, T_ILLEGAL, "vectors:", false, 0 }, // VectorS
130 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL }, // VectorD
269 case ciTypeFlow::StateVector::T_NULL:
270 assert(type == ciTypeFlow::StateVector::null_type(), "");
271 return TypePtr::NULL_PTR;
272
273 case ciTypeFlow::StateVector::T_LONG2:
274 // The ciTypeFlow pass pushes a long, then the half.
275 // We do the same.
276 assert(type == ciTypeFlow::StateVector::long2_type(), "");
277 return TypeInt::TOP;
278
279 case ciTypeFlow::StateVector::T_DOUBLE2:
280 // The ciTypeFlow pass pushes double, then the half.
281 // Our convention is the same.
282 assert(type == ciTypeFlow::StateVector::double2_type(), "");
283 return Type::TOP;
284
285 case T_ADDRESS:
286 assert(type->is_return_address(), "");
287 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci(), relocInfo::none);
288
289 case T_OBJECT:
290 return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
291
292 default:
293 // make sure we did not mix up the cases:
294 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
295 assert(type != ciTypeFlow::StateVector::top_type(), "");
296 assert(type != ciTypeFlow::StateVector::null_type(), "");
297 assert(type != ciTypeFlow::StateVector::long2_type(), "");
298 assert(type != ciTypeFlow::StateVector::double2_type(), "");
299 assert(!type->is_return_address(), "");
300
301 return Type::get_const_type(type);
302 }
303 }
304
305
306 //-----------------------make_from_constant------------------------------------
307 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
308 int stable_dimension, bool is_narrow_oop,
309 bool is_autobox_cache) {
310 switch (constant.basic_type()) {
311 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
361 case T_NARROWOOP: loadbt = T_OBJECT; break;
362 case T_ARRAY: loadbt = T_OBJECT; break;
363 case T_ADDRESS: loadbt = T_OBJECT; break;
364 default: break;
365 }
366 if (conbt == loadbt) {
367 if (is_unsigned && conbt == T_BYTE) {
368 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
369 return ciConstant(T_INT, con.as_int() & 0xFF);
370 } else {
371 return con;
372 }
373 }
374 if (conbt == T_SHORT && loadbt == T_CHAR) {
375 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
376 return ciConstant(T_INT, con.as_int() & 0xFFFF);
377 }
378 return ciConstant(); // T_ILLEGAL
379 }
380
381 static const Type* make_constant_from_non_flat_array_element(ciArray* array, int off, int stable_dimension,
382 BasicType loadbt, bool is_unsigned_load) {
383 // Decode the results of GraphKit::array_element_address.
384 ciConstant element_value = array->element_value_by_offset(off);
385 if (element_value.basic_type() == T_ILLEGAL) {
386 return nullptr; // wrong offset
387 }
388 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
389
390 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
391 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
392
393 if (con.is_valid() && // not a mismatched access
394 !con.is_null_or_zero()) { // not a default value
395 bool is_narrow_oop = (loadbt == T_NARROWOOP);
396 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
397 }
398 return nullptr;
399 }
400
401 static const Type* make_constant_from_flat_array_element(ciFlatArray* array, int off, int field_offset, int stable_dimension,
402 BasicType loadbt, bool is_unsigned_load) {
403 if (!array->is_null_free()) {
404 ciConstant nm_value = array->null_marker_of_element_by_offset(off);
405 if (!nm_value.is_valid() || !nm_value.as_boolean()) {
406 return nullptr;
407 }
408 }
409 ciConstant element_value = array->field_value_by_offset(off + field_offset);
410 if (element_value.basic_type() == T_ILLEGAL) {
411 return nullptr; // wrong offset
412 }
413 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
414
415 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
416 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
417
418 if (con.is_valid()) { // not a mismatched access
419 bool is_narrow_oop = (loadbt == T_NARROWOOP);
420 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
421 }
422 return nullptr;
423 }
424
425 // Try to constant-fold a stable array element.
426 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int field_offset, int stable_dimension,
427 BasicType loadbt, bool is_unsigned_load) {
428 if (array->is_flat()) {
429 return make_constant_from_flat_array_element(array->as_flat_array(), off, field_offset, stable_dimension, loadbt, is_unsigned_load);
430 }
431 return make_constant_from_non_flat_array_element(array, off, stable_dimension, loadbt, is_unsigned_load);
432 }
433
434 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
435 ciField* field;
436 ciType* type = holder->java_mirror_type();
437 if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
438 // Static field
439 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
440 } else {
441 // Instance field
442 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
443 }
444 if (field == nullptr) {
445 return nullptr; // Wrong offset
446 }
447 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
448 }
449
450 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
451 BasicType loadbt, bool is_unsigned_load) {
452 if (!field->is_constant()) {
453 return nullptr; // Non-constant field
626 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
627 ffalse[0] = Type::CONTROL;
628 ffalse[1] = Type::TOP;
629 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
630
631 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
632 fneither[0] = Type::TOP;
633 fneither[1] = Type::TOP;
634 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
635
636 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
637 ftrue[0] = Type::TOP;
638 ftrue[1] = Type::CONTROL;
639 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
640
641 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
642 floop[0] = Type::CONTROL;
643 floop[1] = TypeInt::INT;
644 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
645
646 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
647 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
648 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
649
650 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
651 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
652
653 const Type **fmembar = TypeTuple::fields(0);
654 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
655
656 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
657 fsc[0] = TypeInt::CC;
658 fsc[1] = Type::MEMORY;
659 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
660
661 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
662 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
663 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
664 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
665 false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
666 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
667 false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
668 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
669
670 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
671
672 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
673 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
674
675 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
676
677 mreg2type[Op_Node] = Type::BOTTOM;
678 mreg2type[Op_Set ] = nullptr;
679 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
680 mreg2type[Op_RegI] = TypeInt::INT;
681 mreg2type[Op_RegP] = TypePtr::BOTTOM;
682 mreg2type[Op_RegF] = Type::FLOAT;
683 mreg2type[Op_RegD] = Type::DOUBLE;
684 mreg2type[Op_RegL] = TypeLong::LONG;
685 mreg2type[Op_RegFlags] = TypeInt::CC;
686
687 GrowableArray<ciInstanceKlass*> array_interfaces;
688 array_interfaces.push(current->env()->Cloneable_klass());
689 array_interfaces.push(current->env()->Serializable_klass());
690 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
691 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
692
693 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr, false, Offset::bottom);
694 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
695
696 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
697
698 #ifdef _LP64
699 if (UseCompressedOops) {
700 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
701 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
702 } else
703 #endif
704 {
705 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
706 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
707 }
708 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom);
709 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom);
710 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom);
711 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_INT), true, Offset::bottom);
712 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom);
713 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom);
714 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom);
715 TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true, false, false, false), nullptr, false, Offset::bottom);
716
717 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
718 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
719 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
720 TypeAryPtr::_array_body_type[T_FLAT_ELEMENT] = TypeAryPtr::OOPS;
721 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
722 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
723 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
724 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
725 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
726 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
727 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
728 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
729 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
730
731 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
732 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
733
734 const Type **fi2c = TypeTuple::fields(2);
735 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
736 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
737 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
738
739 const Type **intpair = TypeTuple::fields(2);
740 intpair[0] = TypeInt::INT;
741 intpair[1] = TypeInt::INT;
742 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
743
744 const Type **longpair = TypeTuple::fields(2);
745 longpair[0] = TypeLong::LONG;
746 longpair[1] = TypeLong::LONG;
747 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
748
749 const Type **intccpair = TypeTuple::fields(2);
750 intccpair[0] = TypeInt::INT;
751 intccpair[1] = TypeInt::CC;
752 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
753
754 const Type **longccpair = TypeTuple::fields(2);
755 longccpair[0] = TypeLong::LONG;
756 longccpair[1] = TypeInt::CC;
757 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
758
759 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
760 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
761 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
762 _const_basic_type[T_CHAR] = TypeInt::CHAR;
763 _const_basic_type[T_BYTE] = TypeInt::BYTE;
764 _const_basic_type[T_SHORT] = TypeInt::SHORT;
765 _const_basic_type[T_INT] = TypeInt::INT;
766 _const_basic_type[T_LONG] = TypeLong::LONG;
767 _const_basic_type[T_FLOAT] = Type::FLOAT;
768 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
769 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
770 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
771 _const_basic_type[T_FLAT_ELEMENT] = TypeInstPtr::BOTTOM;
772 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
773 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
774 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
775
776 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
777 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
778 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
779 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
780 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
781 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
782 _zero_type[T_INT] = TypeInt::ZERO;
783 _zero_type[T_LONG] = TypeLong::ZERO;
784 _zero_type[T_FLOAT] = TypeF::ZERO;
785 _zero_type[T_DOUBLE] = TypeD::ZERO;
786 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
787 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
788 _zero_type[T_FLAT_ELEMENT] = TypePtr::NULL_PTR;
789 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
790 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
791
792 // get_zero_type() should not happen for T_CONFLICT
793 _zero_type[T_CONFLICT]= nullptr;
794
795 TypeVect::VECTMASK = (TypeVect*)(new TypePVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
796 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
797
798 if (Matcher::supports_scalable_vector()) {
799 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
800 }
801
802 // Vector predefined types, it needs initialized _const_basic_type[].
803 if (Matcher::vector_size_supported(T_BYTE, 4)) {
804 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
805 }
806 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
807 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
808 }
1044 ~VerifyMeet() {
1045 assert(_C->_type_verify->_depth != 0, "");
1046 _C->_type_verify->_depth--;
1047 if (_C->_type_verify->_depth == 0) {
1048 _C->_type_verify->_cache.trunc_to(0);
1049 }
1050 }
1051
1052 const Type* meet(const Type* t1, const Type* t2) const {
1053 return _C->_type_verify->meet(t1, t2);
1054 }
1055
1056 void add(const Type* t1, const Type* t2, const Type* res) const {
1057 _C->_type_verify->add(t1, t2, res);
1058 }
1059 };
1060
1061 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1062 Compile* C = Compile::current();
1063 const Type* mt2 = verify.meet(t, this);
1064
1065 // Verify that:
1066 // this meet t == t meet this
1067 if (mt != mt2) {
1068 tty->print_cr("=== Meet Not Commutative ===");
1069 tty->print("t = "); t->dump(); tty->cr();
1070 tty->print("this = "); dump(); tty->cr();
1071 tty->print("t meet this = "); mt2->dump(); tty->cr();
1072 tty->print("this meet t = "); mt->dump(); tty->cr();
1073 fatal("meet not commutative");
1074 }
1075 const Type* dual_join = mt->_dual;
1076 const Type* t2t = verify.meet(dual_join,t->_dual);
1077 const Type* t2this = verify.meet(dual_join,this->_dual);
1078
1079 // Interface meet Oop is Not Symmetric:
1080 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1081 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1082
1083 // Verify that:
1084 // 1) mt_dual meet t_dual == t_dual
1085 // which corresponds to
1086 // !(t meet this) meet !t ==
1087 // (!t join !this) meet !t == !t
1088 // 2) mt_dual meet this_dual == this_dual
1089 // which corresponds to
1090 // !(t meet this) meet !this ==
1091 // (!t join !this) meet !this == !this
1092 if (t2t != t->_dual || t2this != this->_dual) {
1093 tty->print_cr("=== Meet Not Symmetric ===");
1094 tty->print("t = "); t->dump(); tty->cr();
1095 tty->print("this= "); dump(); tty->cr();
1096 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
1097
1098 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
1099 tty->print("this_dual= "); _dual->dump(); tty->cr();
1100 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
1101
1102 // 1)
1103 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1104 // 2)
1105 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1106 tty->cr();
1107 tty->print_cr("Fail: ");
1108 if (t2t != t->_dual) {
1109 tty->print_cr("- mt_dual meet t_dual != t_dual");
1110 }
1111 if (t2this != this->_dual) {
1112 tty->print_cr("- mt_dual meet this_dual != this_dual");
1113 }
1114 tty->cr();
1115
1116 fatal("meet not symmetric");
1117 }
1118 }
1119 #endif
1120
1121 //------------------------------meet-------------------------------------------
1122 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1123 // commutative and the lattice is symmetric.
1124 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1125 if (isa_narrowoop() && t->isa_narrowoop()) {
1126 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1127 return result->make_narrowoop();
1128 }
1129 if (isa_narrowklass() && t->isa_narrowklass()) {
1130 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1131 return result->make_narrowklass();
1132 }
1133
1134 #ifdef ASSERT
1135 Compile* C = Compile::current();
1136 VerifyMeet verify(C);
1137 #endif
1138
1139 const Type *this_t = maybe_remove_speculative(include_speculative);
1140 t = t->maybe_remove_speculative(include_speculative);
1141
1142 const Type *mt = this_t->xmeet(t);
1143 #ifdef ASSERT
1144 verify.add(this_t, t, mt);
1145 if (isa_narrowoop() || t->isa_narrowoop()) {
1146 return mt;
1147 }
1148 if (isa_narrowklass() || t->isa_narrowklass()) {
1149 return mt;
1150 }
1151 // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1152 if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1153 (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1154 this_t->check_symmetrical(t, mt, verify);
1155 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1156 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1157 #endif
1158 return mt;
1159 }
1160
1161 //------------------------------xmeet------------------------------------------
1162 // Compute the MEET of two types. It returns a new Type object.
1163 const Type *Type::xmeet( const Type *t ) const {
1164 // Perform a fast test for common case; meeting the same types together.
1165 if( this == t ) return this; // Meeting same type-rep?
1166
1167 // Meeting TOP with anything?
1168 if( _base == Top ) return t;
1169
1170 // Meeting BOTTOM with anything?
1171 if( _base == Bottom ) return BOTTOM;
1172
1173 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2176 void TypeLong::dump_verbose() const {
2177 TypeIntHelper::int_type_dump(this, tty, true);
2178 }
2179 #endif
2180
2181 //=============================================================================
2182 // Convenience common pre-built types.
2183 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2184 const TypeTuple *TypeTuple::IFFALSE;
2185 const TypeTuple *TypeTuple::IFTRUE;
2186 const TypeTuple *TypeTuple::IFNEITHER;
2187 const TypeTuple *TypeTuple::LOOPBODY;
2188 const TypeTuple *TypeTuple::MEMBAR;
2189 const TypeTuple *TypeTuple::STORECONDITIONAL;
2190 const TypeTuple *TypeTuple::START_I2C;
2191 const TypeTuple *TypeTuple::INT_PAIR;
2192 const TypeTuple *TypeTuple::LONG_PAIR;
2193 const TypeTuple *TypeTuple::INT_CC_PAIR;
2194 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2195
2196 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2197 for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2198 ciField* field = vk->declared_nonstatic_field_at(i);
2199 if (field->is_flat()) {
2200 collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2201 if (!field->is_null_free()) {
2202 // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2203 // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2204 field_array[pos++] = Type::get_const_basic_type(T_INT);
2205 }
2206 } else {
2207 BasicType bt = field->type()->basic_type();
2208 const Type* ft = Type::get_const_type(field->type());
2209 field_array[pos++] = ft;
2210 if (type2size[bt] == 2) {
2211 field_array[pos++] = Type::HALF;
2212 }
2213 }
2214 }
2215 }
2216
2217 //------------------------------make-------------------------------------------
2218 // Make a TypeTuple from the range of a method signature
2219 const TypeTuple* TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields, bool is_call) {
2220 ciType* return_type = sig->return_type();
2221 uint arg_cnt = return_type->size();
2222 if (ret_vt_fields) {
2223 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2224 if (is_call) {
2225 // InlineTypeNode::NullMarker field returned by scalarized calls
2226 arg_cnt++;
2227 }
2228 }
2229 const Type **field_array = fields(arg_cnt);
2230 switch (return_type->basic_type()) {
2231 case T_LONG:
2232 field_array[TypeFunc::Parms] = TypeLong::LONG;
2233 field_array[TypeFunc::Parms+1] = Type::HALF;
2234 break;
2235 case T_DOUBLE:
2236 field_array[TypeFunc::Parms] = Type::DOUBLE;
2237 field_array[TypeFunc::Parms+1] = Type::HALF;
2238 break;
2239 case T_OBJECT:
2240 if (ret_vt_fields) {
2241 uint pos = TypeFunc::Parms;
2242 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2243 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2244 if (is_call) {
2245 // InlineTypeNode::NullMarker field returned by scalarized calls
2246 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2247 }
2248 assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2249 break;
2250 } else {
2251 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2252 }
2253 break;
2254 case T_ARRAY:
2255 case T_BOOLEAN:
2256 case T_CHAR:
2257 case T_FLOAT:
2258 case T_BYTE:
2259 case T_SHORT:
2260 case T_INT:
2261 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2262 break;
2263 case T_VOID:
2264 break;
2265 default:
2266 ShouldNotReachHere();
2267 }
2268 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2269 }
2270
2271 // Make a TypeTuple from the domain of a method signature
2272 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2273 ciSignature* sig = method->signature();
2274 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2275 if (vt_fields_as_args) {
2276 arg_cnt = 0;
2277 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2278 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2279 arg_cnt += type2size[(*sig_cc)._bt];
2280 }
2281 }
2282
2283 uint pos = TypeFunc::Parms;
2284 const Type** field_array = fields(arg_cnt);
2285 if (!method->is_static()) {
2286 ciInstanceKlass* recv = method->holder();
2287 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2288 field_array[pos++] = get_const_type(recv, interface_handling); // buffer argument
2289 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2290 } else {
2291 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2292 }
2293 }
2294
2295 int i = 0;
2296 while (pos < TypeFunc::Parms + arg_cnt) {
2297 ciType* type = sig->type_at(i);
2298 BasicType bt = type->basic_type();
2299
2300 switch (bt) {
2301 case T_LONG:
2302 field_array[pos++] = TypeLong::LONG;
2303 field_array[pos++] = Type::HALF;
2304 break;
2305 case T_DOUBLE:
2306 field_array[pos++] = Type::DOUBLE;
2307 field_array[pos++] = Type::HALF;
2308 break;
2309 case T_OBJECT:
2310 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2311 field_array[pos++] = get_const_type(type, interface_handling); // buffer argument
2312 // InlineTypeNode::NullMarker field used for null checking
2313 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2314 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2315 } else {
2316 field_array[pos++] = get_const_type(type, interface_handling);
2317 }
2318 break;
2319 case T_ARRAY:
2320 case T_FLOAT:
2321 case T_INT:
2322 field_array[pos++] = get_const_type(type, interface_handling);
2323 break;
2324 case T_BOOLEAN:
2325 case T_CHAR:
2326 case T_BYTE:
2327 case T_SHORT:
2328 field_array[pos++] = TypeInt::INT;
2329 break;
2330 default:
2331 ShouldNotReachHere();
2332 }
2333 i++;
2334 }
2335 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2336
2337 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2338 }
2339
2340 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2341 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2342 }
2343
2344 //------------------------------fields-----------------------------------------
2345 // Subroutine call type with space allocated for argument types
2346 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2347 const Type **TypeTuple::fields( uint arg_cnt ) {
2348 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2349 flds[TypeFunc::Control ] = Type::CONTROL;
2350 flds[TypeFunc::I_O ] = Type::ABIO;
2351 flds[TypeFunc::Memory ] = Type::MEMORY;
2352 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2353 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2354
2355 return flds;
2450 if (_fields[i]->empty()) return true;
2451 }
2452 return false;
2453 }
2454
2455 //=============================================================================
2456 // Convenience common pre-built types.
2457
2458 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2459 // Certain normalizations keep us sane when comparing types.
2460 // We do not want arrayOop variables to differ only by the wideness
2461 // of their index types. Pick minimum wideness, since that is the
2462 // forced wideness of small ranges anyway.
2463 if (size->_widen != Type::WidenMin)
2464 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2465 else
2466 return size;
2467 }
2468
2469 //------------------------------make-------------------------------------------
2470 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2471 bool flat, bool not_flat, bool not_null_free, bool atomic) {
2472 if (UseCompressedOops && elem->isa_oopptr()) {
2473 elem = elem->make_narrowoop();
2474 }
2475 size = normalize_array_size(size);
2476 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2477 }
2478
2479 //------------------------------meet-------------------------------------------
2480 // Compute the MEET of two types. It returns a new Type object.
2481 const Type *TypeAry::xmeet( const Type *t ) const {
2482 // Perform a fast test for common case; meeting the same types together.
2483 if( this == t ) return this; // Meeting same type-rep?
2484
2485 // Current "this->_base" is Ary
2486 switch (t->base()) { // switch on original type
2487
2488 case Bottom: // Ye Olde Default
2489 return t;
2490
2491 default: // All else is a mistake
2492 typerr(t);
2493
2494 case Array: { // Meeting 2 arrays?
2495 const TypeAry* a = t->is_ary();
2496 const Type* size = _size->xmeet(a->_size);
2497 const TypeInt* isize = size->isa_int();
2498 if (isize == nullptr) {
2499 assert(size == Type::TOP || size == Type::BOTTOM, "");
2500 return size;
2501 }
2502 return TypeAry::make(_elem->meet_speculative(a->_elem),
2503 isize, _stable && a->_stable,
2504 _flat && a->_flat,
2505 _not_flat && a->_not_flat,
2506 _not_null_free && a->_not_null_free,
2507 _atomic && a->_atomic);
2508 }
2509 case Top:
2510 break;
2511 }
2512 return this; // Return the double constant
2513 }
2514
2515 //------------------------------xdual------------------------------------------
2516 // Dual: compute field-by-field dual
2517 const Type *TypeAry::xdual() const {
2518 const TypeInt* size_dual = _size->dual()->is_int();
2519 size_dual = normalize_array_size(size_dual);
2520 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2521 }
2522
2523 //------------------------------eq---------------------------------------------
2524 // Structural equality check for Type representations
2525 bool TypeAry::eq( const Type *t ) const {
2526 const TypeAry *a = (const TypeAry*)t;
2527 return _elem == a->_elem &&
2528 _stable == a->_stable &&
2529 _size == a->_size &&
2530 _flat == a->_flat &&
2531 _not_flat == a->_not_flat &&
2532 _not_null_free == a->_not_null_free &&
2533 _atomic == a->_atomic;
2534
2535 }
2536
2537 //------------------------------hash-------------------------------------------
2538 // Type-specific hashing function.
2539 uint TypeAry::hash(void) const {
2540 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2541 (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2542 }
2543
2544 /**
2545 * Return same type without a speculative part in the element
2546 */
2547 const TypeAry* TypeAry::remove_speculative() const {
2548 return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2549 }
2550
2551 /**
2552 * Return same type with cleaned up speculative part of element
2553 */
2554 const Type* TypeAry::cleanup_speculative() const {
2555 return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2556 }
2557
2558 /**
2559 * Return same type but with a different inline depth (used for speculation)
2560 *
2561 * @param depth depth to meet with
2562 */
2563 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2564 if (!UseInlineDepthForSpeculativeTypes) {
2565 return this;
2566 }
2567 return make(AnyPtr, _ptr, _offset, _speculative, depth, _reloc);
2568 }
2569
2570 //------------------------------dump2------------------------------------------
2571 #ifndef PRODUCT
2572 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2573 if (_stable) st->print("stable:");
2574 if (_flat) st->print("flat:");
2575 if (Verbose) {
2576 if (_not_flat) st->print("not flat:");
2577 if (_not_null_free) st->print("not null free:");
2578 }
2579 if (_atomic) st->print("atomic:");
2580 _elem->dump2(d, depth, st);
2581 st->print("[");
2582 _size->dump2(d, depth, st);
2583 st->print("]");
2584 }
2585 #endif
2586
2587 //------------------------------singleton--------------------------------------
2588 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2589 // constants (Ldi nodes). Singletons are integer, float or double constants
2590 // or a single symbol.
2591 bool TypeAry::singleton(void) const {
2592 return false; // Never a singleton
2593 }
2594
2595 bool TypeAry::empty(void) const {
2596 assert(!_size->empty(), "TypeInt is never empty");
2597 // TODO 8385426 This should be simplified at construction time once we get rid of dual
2598 // Doing it with the dual-based join is annoying. TypeAry::empty tests whether the
2599 // element type is empty. When computing the dual of an array that can be flat or not,
2600 // we will get an element type that is empty, and doesn't need more. We even shouldn't
2601 // do more otherwise, we can't make the dual involutive. But if we compute the
2602 // intersection of a flat and a non-flat array, we could change the element type to an
2603 // empty type to reduce the abstract value. And we must be careful not to do that in
2604 // the dual world.
2605 return _elem->empty() || (_flat && _not_flat);
2606 }
2607
2608 //--------------------------ary_must_be_exact----------------------------------
2609 bool TypeAry::ary_must_be_exact() const {
2610 // This logic looks at the element type of an array, and returns true
2611 // if the element type is either a primitive or a final instance class.
2612 // In such cases, an array built on this ary must have no subclasses.
2613 if (_elem == BOTTOM) return false; // general array not exact
2614 if (_elem == TOP ) return false; // inverted general array not exact
2615 const TypeOopPtr* toop = nullptr;
2616 if (UseCompressedOops && _elem->isa_narrowoop()) {
2617 toop = _elem->make_ptr()->isa_oopptr();
2618 } else {
2619 toop = _elem->isa_oopptr();
2620 }
2621 if (!toop) return true; // a primitive type, like int
2622 if (!toop->is_loaded()) return false; // unloaded class
2623 const TypeInstPtr* tinst;
2624 if (_elem->isa_narrowoop())
2625 tinst = _elem->make_ptr()->isa_instptr();
2626 else
2627 tinst = _elem->isa_instptr();
2628 if (tinst) {
2629 if (tinst->instance_klass()->is_final()) {
2630 // Even though MyValue is final, [LMyValue is only exact if the array
2631 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2632 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2633 // If so, we should add '&& !_not_null_free'
2634 if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2635 return false;
2636 }
2637 return true;
2638 }
2639 return false;
2640 }
2641 const TypeAryPtr* tap;
2642 if (_elem->isa_narrowoop())
2643 tap = _elem->make_ptr()->isa_aryptr();
2644 else
2645 tap = _elem->isa_aryptr();
2646 if (tap)
2647 return tap->ary()->ary_must_be_exact();
2648 return false;
2649 }
2650
2651 //==============================TypeVect=======================================
2652 // Convenience common pre-built types.
2653 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2654 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2655 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2656 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2657 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2658 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2659 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2660
2801
2802 //=============================================================================
2803 // Convenience common pre-built types.
2804 const TypePtr *TypePtr::NULL_PTR;
2805 const TypePtr *TypePtr::NOTNULL;
2806 const TypePtr *TypePtr::BOTTOM;
2807
2808 //------------------------------meet-------------------------------------------
2809 // Meet over the PTR enum
2810 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2811 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2812 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2813 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2814 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2815 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2816 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2817 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2818 };
2819
2820 //------------------------------make-------------------------------------------
2821 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset,
2822 const TypePtr* speculative, int inline_depth,
2823 relocInfo::relocType reloc) {
2824 return (TypePtr*)(new TypePtr(t, ptr, offset, reloc, speculative, inline_depth))->hashcons();
2825 }
2826
2827 //------------------------------cast_to_ptr_type-------------------------------
2828 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2829 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2830 if( ptr == _ptr ) return this;
2831 return make(_base, ptr, _offset, _speculative, _inline_depth, _reloc);
2832 }
2833
2834 //------------------------------get_con----------------------------------------
2835 intptr_t TypePtr::get_con() const {
2836 assert( _ptr == Null, "" );
2837 return offset();
2838 }
2839
2840 //------------------------------meet-------------------------------------------
2841 // Compute the MEET of two types. It returns a new Type object.
2842 const Type *TypePtr::xmeet(const Type *t) const {
2843 const Type* res = xmeet_helper(t);
2844 if (res->isa_ptr() == nullptr) {
2845 return res;
2846 }
2847
2848 const TypePtr* res_ptr = res->is_ptr();
2849 if (res_ptr->speculative() != nullptr) {
2850 // type->speculative() is null means that speculation is no better
2851 // than type, i.e. type->speculative() == type. So there are 2
2852 // ways to represent the fact that we have no useful speculative
2853 // data and we should use a single one to be able to test for
2854 // equality between types. Check whether type->speculative() ==
2855 // type and set speculative to null if it is the case.
2856 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2857 return res_ptr->remove_speculative();
2891 int depth = meet_inline_depth(tp->inline_depth());
2892 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2893 }
2894 case RawPtr: // For these, flip the call around to cut down
2895 case OopPtr:
2896 case InstPtr: // on the cases I have to handle.
2897 case AryPtr:
2898 case MetadataPtr:
2899 case KlassPtr:
2900 case InstKlassPtr:
2901 case AryKlassPtr:
2902 return t->xmeet(this); // Call in reverse direction
2903 default: // All else is a mistake
2904 typerr(t);
2905
2906 }
2907 return this;
2908 }
2909
2910 //------------------------------meet_offset------------------------------------
2911 Type::Offset TypePtr::meet_offset(int offset) const {
2912 return _offset.meet(Offset(offset));
2913 }
2914
2915 //------------------------------dual_offset------------------------------------
2916 Type::Offset TypePtr::dual_offset() const {
2917 return _offset.dual();
2918 }
2919
2920 //------------------------------xdual------------------------------------------
2921 // Dual: compute field-by-field dual
2922 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2923 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2924 };
2925
2926 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2927 /* TopFlat -> */ MaybeFlat,
2928 /* Flat -> */ NotFlat,
2929 /* NotFlat -> */ Flat,
2930 /* MaybeFlat -> */ TopFlat
2931 };
2932
2933 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2934 "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2935 };
2936
2937 const Type *TypePtr::xdual() const {
2938 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), relocInfo::none, dual_speculative(), dual_inline_depth());
2939 }
2940
2941 //------------------------------xadd_offset------------------------------------
2942 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2943 return _offset.add(offset);
2944 }
2945
2946 //------------------------------add_offset-------------------------------------
2947 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2948 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth, _reloc);
2949 }
2950
2951 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2952 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth, _reloc);
2953 }
2954
2955 //------------------------------eq---------------------------------------------
2956 // Structural equality check for Type representations
2957 bool TypePtr::eq( const Type *t ) const {
2958 const TypePtr *a = (const TypePtr*)t;
2959 return _ptr == a->ptr() && offset() == a->offset() && _reloc == a->reloc() &&
2960 eq_speculative(a) && _inline_depth == a->_inline_depth;
2961 }
2962
2963 //------------------------------hash-------------------------------------------
2964 // Type-specific hashing function.
2965 uint TypePtr::hash(void) const {
2966 return (uint)_ptr + (uint)offset() + (uint)_reloc + (uint)hash_speculative() + (uint)_inline_depth;
2967 }
2968
2969 /**
2970 * Return same type without a speculative part
2971 */
2972 const TypePtr* TypePtr::remove_speculative() const {
2973 if (_speculative == nullptr) {
2974 return this;
2975 }
2976 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2977 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth, _reloc);
2978 }
2979
2980 /**
2981 * Return same type but drop speculative part if we know we won't use
2982 * it
2983 */
2984 const Type* TypePtr::cleanup_speculative() const {
2985 if (speculative() == nullptr) {
2986 return this;
3203 return false;
3204 }
3205 // We already know the speculative type cannot be null
3206 if (!speculative_maybe_null()) {
3207 return false;
3208 }
3209 // We already know this is always null
3210 if (this == TypePtr::NULL_PTR) {
3211 return false;
3212 }
3213 // We already know the speculative type is always null
3214 if (speculative_always_null()) {
3215 return false;
3216 }
3217 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3218 return false;
3219 }
3220 return true;
3221 }
3222
3223 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3224 if (!instance_klass->can_be_inline_klass(is_exact) || !UseArrayFlattening) {
3225 // Definitely not a value class, or flattening is not even enabled, and thus never flat in an array.
3226 return NotFlat;
3227 }
3228 if (instance_klass->is_inlinetype()) {
3229 if (instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3230 return Flat;
3231 }
3232 if (instance_klass->as_inline_klass()->maybe_flat_in_array()) {
3233 return MaybeFlat;
3234 }
3235 return NotFlat;
3236 }
3237 // It's not an inline class, but can still be, so we don't know.
3238 return MaybeFlat;
3239 }
3240
3241 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3242 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3243 FlatInArray old_flat_in_array) {
3244 // It is tempting to add verification code that "NotFlat == no value class" and "Flat == value class".
3245 // However, with type speculation, we could get contradicting flat in array properties that propagate through the
3246 // graph. We could try to stop the introduction of contradicting speculative types in terms of their flat in array
3247 // property. But this is hard because it is sometimes only recognized further down in the graph. Thus, we let an
3248 // inconsistent flat in array property propagating through the graph. This could lead to fold an actual live path
3249 // away. But in this case, the speculated type is wrong and we would trap earlier.
3250 if (old_flat_in_array == MaybeFlat) {
3251 return compute_flat_in_array(instance_klass, is_exact);
3252 }
3253 return old_flat_in_array;
3254 }
3255
3256 //------------------------------dump2------------------------------------------
3257 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3258 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3259 };
3260
3261 #ifndef PRODUCT
3262 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3263 st->print("ptr:%s", ptr_msg[_ptr]);
3264 dump_offset(st);
3265 dump_inline_depth(st);
3266 dump_speculative(st);
3267 }
3268
3269 void TypePtr::dump_offset(outputStream* st) const {
3270 _offset.dump2(st);
3271 }
3272
3273 /**
3274 *dump the speculative part of the type
3275 */
3276 void TypePtr::dump_speculative(outputStream *st) const {
3277 if (_speculative != nullptr) {
3278 st->print(" (speculative=");
3279 _speculative->dump_on(st);
3280 st->print(")");
3281 }
3282 }
3283
3284 /**
3285 *dump the inline depth of the type
3286 */
3287 void TypePtr::dump_inline_depth(outputStream *st) const {
3288 if (_inline_depth != InlineDepthBottom) {
3289 if (_inline_depth == InlineDepthTop) {
3290 st->print(" (inline_depth=InlineDepthTop)");
3291 } else {
3292 st->print(" (inline_depth=%d)", _inline_depth);
3293 }
3294 }
3295 }
3296
3297 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3298 switch (flat_in_array) {
3299 case MaybeFlat:
3300 case NotFlat:
3301 if (!Verbose) {
3302 break;
3303 }
3304 case TopFlat:
3305 case Flat:
3306 st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3307 break;
3308 default:
3309 ShouldNotReachHere();
3310 }
3311 }
3312 #endif
3313
3314 //------------------------------singleton--------------------------------------
3315 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3316 // constants
3317 bool TypePtr::singleton(void) const {
3318 // TopPTR, Null, AnyNull, Constant are all singletons
3319 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3320 }
3321
3322 bool TypePtr::empty(void) const {
3323 return (_offset == Offset::top) || above_centerline(_ptr);
3324 }
3325
3326 //=============================================================================
3327 // Convenience common pre-built types.
3328 const TypeRawPtr *TypeRawPtr::BOTTOM;
3329 const TypeRawPtr *TypeRawPtr::NOTNULL;
3330
3331 //------------------------------make-------------------------------------------
3332 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3333 assert( ptr != Constant, "what is the constant?" );
3334 assert( ptr != Null, "Use TypePtr for null" );
3335 return (TypeRawPtr*)(new TypeRawPtr(ptr, nullptr, relocInfo::none))->hashcons();
3336 }
3337
3338 const TypeRawPtr* TypeRawPtr::make(address bits, relocInfo::relocType reloc) {
3339 assert(bits != nullptr, "Use TypePtr for null");
3340 return (TypeRawPtr*)(new TypeRawPtr(Constant, bits, reloc))->hashcons();
3341 }
3342
3343 //------------------------------cast_to_ptr_type-------------------------------
3722 #endif
3723
3724 // Can't be implemented because there's no way to know if the type is above or below the center line.
3725 const Type* TypeInterfaces::xmeet(const Type* t) const {
3726 ShouldNotReachHere();
3727 return Type::xmeet(t);
3728 }
3729
3730 bool TypeInterfaces::singleton(void) const {
3731 ShouldNotReachHere();
3732 return Type::singleton();
3733 }
3734
3735 bool TypeInterfaces::has_non_array_interface() const {
3736 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3737
3738 return !TypeAryPtr::_array_interfaces->contains(this);
3739 }
3740
3741 //------------------------------TypeOopPtr-------------------------------------
3742 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3743 int instance_id, const TypePtr* speculative, int inline_depth)
3744 : TypePtr(t, ptr, offset, relocInfo::oop_type, speculative, inline_depth),
3745 _const_oop(o), _klass(k),
3746 _interfaces(interfaces),
3747 _klass_is_exact(xk),
3748 _is_ptr_to_narrowoop(false),
3749 _is_ptr_to_narrowklass(false),
3750 _is_ptr_to_boxed_value(false),
3751 _is_ptr_to_strict_final_field(false),
3752 _instance_id(instance_id) {
3753 #ifdef ASSERT
3754 if (klass() != nullptr && klass()->is_loaded()) {
3755 interfaces->verify_is_loaded();
3756 }
3757 #endif
3758 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3759 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3760 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3761 _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3762 }
3763
3764 if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3765 this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3766 ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3767 if (field != nullptr && field->is_strict() && field->is_final()) {
3768 _is_ptr_to_strict_final_field = true;
3769 }
3770 }
3771
3772 #ifdef _LP64
3773 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3774 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3775 _is_ptr_to_narrowklass = true;
3776 } else if (klass() == nullptr) {
3777 // Array with unknown body type
3778 assert(this->isa_aryptr(), "only arrays without klass");
3779 _is_ptr_to_narrowoop = UseCompressedOops;
3780 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3781 if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3782 // Check if the field of the inline type array element contains oops
3783 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3784 int foffset = field_offset.get() + vk->payload_offset();
3785 BasicType field_bt;
3786 ciField* field = vk->get_field_by_offset(foffset, false);
3787 if (field != nullptr) {
3788 field_bt = field->layout_type();
3789 } else {
3790 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);
3791 field_bt = T_BOOLEAN;
3792 }
3793 _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3794 } else if (klass()->is_obj_array_klass()) {
3795 _is_ptr_to_narrowoop = true;
3796 }
3797 } else if (klass()->is_instance_klass()) {
3798 if (this->isa_klassptr()) {
3799 // Perm objects don't use compressed references
3800 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3801 // unsafe access
3802 _is_ptr_to_narrowoop = UseCompressedOops;
3803 } else {
3804 assert(this->isa_instptr(), "must be an instance ptr.");
3805 if (klass() == ciEnv::current()->Class_klass() &&
3806 (this->offset() == java_lang_Class::klass_offset() ||
3807 this->offset() == java_lang_Class::array_klass_offset())) {
3808 // Special hidden fields from the Class.
3809 assert(this->isa_instptr(), "must be an instance ptr.");
3810 _is_ptr_to_narrowoop = false;
3811 } else if (klass() == ciEnv::current()->Class_klass() &&
3812 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3813 // Static fields
3814 BasicType basic_elem_type = T_ILLEGAL;
3815 if (const_oop() != nullptr) {
3816 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3817 basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3818 }
3819 if (basic_elem_type != T_ILLEGAL) {
3820 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3821 } else {
3822 // unsafe access
3823 _is_ptr_to_narrowoop = UseCompressedOops;
3824 }
3825 } else {
3826 // Instance fields which contains a compressed oop references.
3827 ciInstanceKlass* ik = klass()->as_instance_klass();
3828 BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3829 if (basic_elem_type != T_ILLEGAL) {
3830 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3831 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3832 // Compile::find_alias_type() cast exactness on all types to verify
3833 // that it does not affect alias type.
3834 _is_ptr_to_narrowoop = UseCompressedOops;
3835 } else {
3836 // Type for the copy start in LibraryCallKit::inline_native_clone().
3837 _is_ptr_to_narrowoop = UseCompressedOops;
3838 }
3839 }
3840 }
3841 }
3842 }
3843 #endif // _LP64
3844 }
3845
3846 //------------------------------make-------------------------------------------
3847 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3848 const TypePtr* speculative, int inline_depth) {
3849 assert(ptr != Constant, "no constant generic pointers");
3850 ciKlass* k = Compile::current()->env()->Object_klass();
3851 bool xk = false;
3852 ciObject* o = nullptr;
3853 const TypeInterfaces* interfaces = TypeInterfaces::make();
3854 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3855 }
3856
3857
3858 //------------------------------cast_to_ptr_type-------------------------------
3859 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3860 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3861 if( ptr == _ptr ) return this;
3862 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3863 }
3864
3865 //-----------------------------cast_to_instance_id----------------------------
3866 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3867 // There are no instances of a general oop.
3868 // Return self unchanged.
3869 return this;
3870 }
3871
3872 //-----------------------------cast_to_exactness-------------------------------
3873 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3874 // There is no such thing as an exact general oop.
3875 // Return self unchanged.
3876 return this;
3877 }
3878
3879 //------------------------------as_klass_type----------------------------------
3880 // Return the klass type corresponding to this instance or array type.
3881 // It is the type that is loaded from an object of this type.
3882 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3883 ShouldNotReachHere();
3884 return nullptr;
3885 }
3886
3887 //------------------------------meet-------------------------------------------
3888 // Compute the MEET of two types. It returns a new Type object.
3889 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3890 // Perform a fast test for common case; meeting the same types together.
3891 if( this == t ) return this; // Meeting same type-rep?
3892
3893 // Current "this->_base" is OopPtr
3894 switch (t->base()) { // switch on original type
3895
3896 case Int: // Mixing ints & oops happens when javac
3897 case Long: // reuses local variables
3898 case HalfFloatTop:
3907 case NarrowOop:
3908 case NarrowKlass:
3909 case Bottom: // Ye Olde Default
3910 return Type::BOTTOM;
3911 case Top:
3912 return this;
3913
3914 default: // All else is a mistake
3915 typerr(t);
3916
3917 case RawPtr:
3918 case MetadataPtr:
3919 case KlassPtr:
3920 case InstKlassPtr:
3921 case AryKlassPtr:
3922 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3923
3924 case AnyPtr: {
3925 // Found an AnyPtr type vs self-OopPtr type
3926 const TypePtr *tp = t->is_ptr();
3927 Offset offset = meet_offset(tp->offset());
3928 PTR ptr = meet_ptr(tp->ptr());
3929 const TypePtr* speculative = xmeet_speculative(tp);
3930 int depth = meet_inline_depth(tp->inline_depth());
3931 switch (tp->ptr()) {
3932 case Null:
3933 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3934 // else fall through:
3935 case TopPTR:
3936 case AnyNull: {
3937 int instance_id = meet_instance_id(InstanceTop);
3938 return make(ptr, offset, instance_id, speculative, depth);
3939 }
3940 case BotPTR:
3941 case NotNull:
3942 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3943 default: typerr(t);
3944 }
3945 }
3946
3947 case OopPtr: { // Meeting to other OopPtrs
3949 int instance_id = meet_instance_id(tp->instance_id());
3950 const TypePtr* speculative = xmeet_speculative(tp);
3951 int depth = meet_inline_depth(tp->inline_depth());
3952 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3953 }
3954
3955 case InstPtr: // For these, flip the call around to cut down
3956 case AryPtr:
3957 return t->xmeet(this); // Call in reverse direction
3958
3959 } // End of switch
3960 return this; // Return the double constant
3961 }
3962
3963
3964 //------------------------------xdual------------------------------------------
3965 // Dual of a pure heap pointer. No relevant klass or oop information.
3966 const Type *TypeOopPtr::xdual() const {
3967 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3968 assert(const_oop() == nullptr, "no constants here");
3969 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());
3970 }
3971
3972 //--------------------------make_from_klass_common-----------------------------
3973 // Computes the element-type given a klass.
3974 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3975 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3976 Compile* C = Compile::current();
3977 Dependencies* deps = C->dependencies();
3978 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3979 // Element is an instance
3980 bool klass_is_exact = false;
3981 ciInstanceKlass* ik = klass->as_instance_klass();
3982 if (klass->is_loaded()) {
3983 // Try to set klass_is_exact.
3984 klass_is_exact = ik->is_final();
3985 if (!klass_is_exact && klass_change
3986 && deps != nullptr && UseUniqueSubclasses) {
3987 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3988 if (sub != nullptr) {
3989 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3990 klass = ik = sub;
3991 klass_is_exact = sub->is_final();
3992 }
3993 }
3994 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3995 !ik->is_interface() && !ik->has_subklass()) {
3996 // Add a dependence; if concrete subclass added we need to recompile
3997 deps->assert_leaf_type(ik);
3998 klass_is_exact = true;
3999 }
4000 }
4001 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4002 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
4003 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
4004 } else if (klass->is_obj_array_klass()) {
4005 // Element is an object or inline type array. Recursively call ourself.
4006 ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
4007 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
4008 bool xk = array_klass->is_loaded() && array_klass->is_refined();
4009
4010 // Determine null-free/flat properties
4011 bool flat;
4012 bool not_flat;
4013 bool not_null_free;
4014 bool atomic;
4015 if (xk) {
4016 flat = array_klass->is_flat_array_klass();
4017 not_flat = !flat;
4018 bool is_null_free = array_klass->is_elem_null_free();
4019 not_null_free = !is_null_free;
4020 atomic = array_klass->is_elem_atomic();
4021
4022 if (is_null_free) {
4023 etype = etype->join_speculative(NOTNULL)->is_oopptr();
4024 }
4025 } else {
4026 const TypeOopPtr* exact_etype = etype;
4027 if (etype->can_be_inline_type()) {
4028 // Use exact type if element can be an inline type
4029 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
4030 }
4031
4032 flat = false;
4033 bool not_inline = !exact_etype->can_be_inline_type();
4034 not_null_free = not_inline;
4035 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4036 atomic = not_flat;
4037 }
4038
4039 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
4040 // We used to pass NotNull in here, asserting that the sub-arrays
4041 // are all not-null. This is not true in generally, as code can
4042 // slam nullptrs down in the subarrays.
4043 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4044 return arr;
4045 } else if (klass->is_type_array_klass()) {
4046 // Element is an typeArray
4047 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4048 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4049 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4050 // We used to pass NotNull in here, asserting that the array pointer
4051 // is not-null. That was not true in general.
4052 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4053 return arr;
4054 } else {
4055 ShouldNotReachHere();
4056 return nullptr;
4057 }
4058 }
4059
4060 //------------------------------make_from_constant-----------------------------
4061 // Make a java pointer from an oop constant
4062 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4063 assert(!o->is_null_object(), "null object not yet handled here.");
4064
4065 const bool make_constant = require_constant || o->should_be_constant();
4066
4067 ciKlass* klass = o->klass();
4068 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4069 // Element is an instance or inline type
4070 if (make_constant) {
4071 return TypeInstPtr::make(o);
4072 } else {
4073 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4074 }
4075 } else if (klass->is_obj_array_klass()) {
4076 // Element is an object array. Recursively call ourself.
4077 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4078 bool is_flat = o->as_array()->is_flat();
4079 bool is_null_free = o->as_array()->is_null_free();
4080 if (is_null_free) {
4081 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4082 }
4083 bool is_atomic = o->as_array()->is_atomic();
4084 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4085 /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4086 // We used to pass NotNull in here, asserting that the sub-arrays
4087 // are all not-null. This is not true in generally, as code can
4088 // slam nulls down in the subarrays.
4089 if (make_constant) {
4090 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4091 } else {
4092 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4093 }
4094 } else if (klass->is_type_array_klass()) {
4095 // Element is an typeArray
4096 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4097 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4098 /* not_flat= */ true, /* not_null_free= */ true, true);
4099 // We used to pass NotNull in here, asserting that the array pointer
4100 // is not-null. That was not true in general.
4101 if (make_constant) {
4102 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4103 } else {
4104 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4105 }
4106 }
4107
4108 fatal("unhandled object type");
4109 return nullptr;
4110 }
4111
4112 //------------------------------get_con----------------------------------------
4113 intptr_t TypeOopPtr::get_con() const {
4114 assert( _ptr == Null || _ptr == Constant, "" );
4115 assert(offset() >= 0, "");
4116
4117 if (offset() != 0) {
4118 // After being ported to the compiler interface, the compiler no longer
4119 // directly manipulates the addresses of oops. Rather, it only has a pointer
4120 // to a handle at compile time. This handle is embedded in the generated
4121 // code and dereferenced at the time the nmethod is made. Until that time,
4122 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4123 // have access to the addresses!). This does not seem to currently happen,
4124 // but this assertion here is to help prevent its occurrence.
4125 tty->print_cr("Found oop constant with non-zero offset");
4126 ShouldNotReachHere();
4127 }
4128
4129 return (intptr_t)const_oop()->constant_encoding();
4130 }
4131
4132
4133 //-----------------------------filter------------------------------------------
4134 // Do not allow interface-vs.-noninterface joins to collapse to top.
4135 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4136
4137 const Type* ft = join_helper(kills, include_speculative);
4183 dump_speculative(st);
4184 }
4185
4186 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4187 if (_instance_id == InstanceTop) {
4188 st->print(",iid=top");
4189 } else if (_instance_id == InstanceBot) {
4190 st->print(",iid=bot");
4191 } else {
4192 st->print(",iid=%d", _instance_id);
4193 }
4194 }
4195 #endif
4196
4197 //------------------------------singleton--------------------------------------
4198 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4199 // constants
4200 bool TypeOopPtr::singleton(void) const {
4201 // detune optimizer to not generate constant oop + constant offset as a constant!
4202 // TopPTR, Null, AnyNull, Constant are all singletons
4203 return (offset() == 0) && !below_centerline(_ptr);
4204 }
4205
4206 //------------------------------add_offset-------------------------------------
4207 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4208 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4209 }
4210
4211 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4212 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4213 }
4214
4215 /**
4216 * Return same type without a speculative part
4217 */
4218 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4219 if (_speculative == nullptr) {
4220 return this;
4221 }
4222 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4223 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4224 }
4225
4226 /**
4227 * Return same type but drop speculative part if we know we won't use
4228 * it
4229 */
4230 const Type* TypeOopPtr::cleanup_speculative() const {
4231 // If the klass is exact and the ptr is not null then there's
4232 // nothing that the speculative type can help us with
4305 const TypeInstPtr *TypeInstPtr::BOTTOM;
4306 const TypeInstPtr *TypeInstPtr::MIRROR;
4307 const TypeInstPtr *TypeInstPtr::MARK;
4308 const TypeInstPtr *TypeInstPtr::KLASS;
4309
4310 // Is there a single ciKlass* that can represent that type?
4311 ciKlass* TypeInstPtr::exact_klass_helper() const {
4312 if (_interfaces->empty()) {
4313 return _klass;
4314 }
4315 if (_klass != ciEnv::current()->Object_klass()) {
4316 if (_interfaces->eq(_klass->as_instance_klass())) {
4317 return _klass;
4318 }
4319 return nullptr;
4320 }
4321 return _interfaces->exact_klass();
4322 }
4323
4324 //------------------------------TypeInstPtr-------------------------------------
4325 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4326 FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4327 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4328 _flat_in_array(flat_in_array) {
4329
4330 assert(flat_in_array != Uninitialized, "must be set now");
4331 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4332 assert(k != nullptr &&
4333 (k->is_loaded() || o == nullptr),
4334 "cannot have constants with non-loaded klass");
4335 };
4336
4337 //------------------------------make-------------------------------------------
4338 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4339 ciKlass* k,
4340 const TypeInterfaces* interfaces,
4341 bool xk,
4342 ciObject* o,
4343 Offset offset,
4344 FlatInArray flat_in_array,
4345 int instance_id,
4346 const TypePtr* speculative,
4347 int inline_depth) {
4348 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4349 // Either const_oop() is null or else ptr is Constant
4350 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4351 "constant pointers must have a value supplied" );
4352 // Ptr is never Null
4353 assert( ptr != Null, "null pointers are not typed" );
4354
4355 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4356 ciInstanceKlass* ik = k->as_instance_klass();
4357 if (ptr == Constant) {
4358 // Note: This case includes meta-object constants, such as methods.
4359 xk = true;
4360 } else if (k->is_loaded()) {
4361 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4362 assert(!ik->is_interface(), "no interface here");
4363 if (xk && ik->is_interface()) xk = false; // no exact interface
4364 }
4365
4366 if (flat_in_array == Uninitialized) {
4367 flat_in_array = compute_flat_in_array(ik, xk);
4368 }
4369 // Now hash this baby
4370 TypeInstPtr *result =
4371 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4372
4373 return result;
4374 }
4375
4376 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4377 if (k->is_instance_klass()) {
4378 if (k->is_loaded()) {
4379 if (k->is_interface() && interface_handling == ignore_interfaces) {
4380 assert(interface, "no interface expected");
4381 k = ciEnv::current()->Object_klass();
4382 const TypeInterfaces* interfaces = TypeInterfaces::make();
4383 return interfaces;
4384 }
4385 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4386 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4387 if (k->is_interface()) {
4388 assert(interface, "no interface expected");
4389 k = ciEnv::current()->Object_klass();
4390 } else {
4391 assert(klass, "no instance klass expected");
4394 }
4395 const TypeInterfaces* interfaces = TypeInterfaces::make();
4396 return interfaces;
4397 }
4398 assert(array, "no array expected");
4399 assert(k->is_array_klass(), "Not an array?");
4400 ciType* e = k->as_array_klass()->base_element_type();
4401 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4402 if (interface_handling == ignore_interfaces) {
4403 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4404 }
4405 }
4406 return TypeAryPtr::_array_interfaces;
4407 }
4408
4409 //------------------------------cast_to_ptr_type-------------------------------
4410 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4411 if( ptr == _ptr ) return this;
4412 // Reconstruct _sig info here since not a problem with later lazy
4413 // construction, _sig will show up on demand.
4414 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4415 }
4416
4417
4418 //-----------------------------cast_to_exactness-------------------------------
4419 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4420 if( klass_is_exact == _klass_is_exact ) return this;
4421 if (!_klass->is_loaded()) return this;
4422 ciInstanceKlass* ik = _klass->as_instance_klass();
4423 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4424 assert(!ik->is_interface(), "no interface here");
4425 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4426 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4427 }
4428
4429 //-----------------------------cast_to_instance_id----------------------------
4430 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4431 if( instance_id == _instance_id ) return this;
4432 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4433 }
4434
4435 //------------------------------xmeet_unloaded---------------------------------
4436 // Compute the MEET of two InstPtrs when at least one is unloaded.
4437 // Assume classes are different since called after check for same name/class-loader
4438 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4439 Offset off = meet_offset(tinst->offset());
4440 PTR ptr = meet_ptr(tinst->ptr());
4441 int instance_id = meet_instance_id(tinst->instance_id());
4442 const TypePtr* speculative = xmeet_speculative(tinst);
4443 int depth = meet_inline_depth(tinst->inline_depth());
4444
4445 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4446 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4447 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4448 //
4449 // Meet unloaded class with java/lang/Object
4450 //
4451 // Meet
4452 // | Unloaded Class
4453 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4454 // ===================================================================
4455 // TOP | ..........................Unloaded......................|
4456 // AnyNull | U-AN |................Unloaded......................|
4457 // Constant | ... O-NN .................................. | O-BOT |
4458 // NotNull | ... O-NN .................................. | O-BOT |
4459 // BOTTOM | ........................Object-BOTTOM ..................|
4460 //
4461 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4462 //
4463 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4464 else if (loaded->ptr() == TypePtr::AnyNull) {
4465 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4466 return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4467 speculative, depth);
4468 }
4469 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4470 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4471 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4472 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4473 }
4474 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4475
4476 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4477 }
4478
4479 // Both are unloaded, not the same class, not Object
4480 // Or meet unloaded with a different loaded class, not java/lang/Object
4481 if (ptr != TypePtr::BotPTR) {
4482 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4483 }
4484 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4485 }
4486
4487
4488 //------------------------------meet-------------------------------------------
4512 case Top:
4513 return this;
4514
4515 default: // All else is a mistake
4516 typerr(t);
4517
4518 case MetadataPtr:
4519 case KlassPtr:
4520 case InstKlassPtr:
4521 case AryKlassPtr:
4522 case RawPtr: return TypePtr::BOTTOM;
4523
4524 case AryPtr: { // All arrays inherit from Object class
4525 // Call in reverse direction to avoid duplication
4526 return t->is_aryptr()->xmeet_helper(this);
4527 }
4528
4529 case OopPtr: { // Meeting to OopPtrs
4530 // Found a OopPtr type vs self-InstPtr type
4531 const TypeOopPtr *tp = t->is_oopptr();
4532 Offset offset = meet_offset(tp->offset());
4533 PTR ptr = meet_ptr(tp->ptr());
4534 switch (tp->ptr()) {
4535 case TopPTR:
4536 case AnyNull: {
4537 int instance_id = meet_instance_id(InstanceTop);
4538 const TypePtr* speculative = xmeet_speculative(tp);
4539 int depth = meet_inline_depth(tp->inline_depth());
4540 return make(ptr, klass(), _interfaces, klass_is_exact(),
4541 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4542 }
4543 case NotNull:
4544 case BotPTR: {
4545 int instance_id = meet_instance_id(tp->instance_id());
4546 const TypePtr* speculative = xmeet_speculative(tp);
4547 int depth = meet_inline_depth(tp->inline_depth());
4548 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4549 }
4550 default: typerr(t);
4551 }
4552 }
4553
4554 case AnyPtr: { // Meeting to AnyPtrs
4555 // Found an AnyPtr type vs self-InstPtr type
4556 const TypePtr *tp = t->is_ptr();
4557 Offset offset = meet_offset(tp->offset());
4558 PTR ptr = meet_ptr(tp->ptr());
4559 int instance_id = meet_instance_id(InstanceTop);
4560 const TypePtr* speculative = xmeet_speculative(tp);
4561 int depth = meet_inline_depth(tp->inline_depth());
4562 switch (tp->ptr()) {
4563 case Null:
4564 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4565 // else fall through to AnyNull
4566 case TopPTR:
4567 case AnyNull: {
4568 return make(ptr, klass(), _interfaces, klass_is_exact(),
4569 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4570 }
4571 case NotNull:
4572 case BotPTR:
4573 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4574 default: typerr(t);
4575 }
4576 }
4577
4578 /*
4579 A-top }
4580 / | \ } Tops
4581 B-top A-any C-top }
4582 | / | \ | } Any-nulls
4583 B-any | C-any }
4584 | | |
4585 B-con A-con C-con } constants; not comparable across classes
4586 | | |
4587 B-not | C-not }
4588 | \ | / | } not-nulls
4589 B-bot A-not C-bot }
4590 \ | / } Bottoms
4591 A-bot }
4592 */
4593
4594 case InstPtr: { // Meeting 2 Oops?
4595 // Found an InstPtr sub-type vs self-InstPtr type
4596 const TypeInstPtr *tinst = t->is_instptr();
4597 Offset off = meet_offset(tinst->offset());
4598 PTR ptr = meet_ptr(tinst->ptr());
4599 int instance_id = meet_instance_id(tinst->instance_id());
4600 const TypePtr* speculative = xmeet_speculative(tinst);
4601 int depth = meet_inline_depth(tinst->inline_depth());
4602 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4603
4604 ciKlass* tinst_klass = tinst->klass();
4605 ciKlass* this_klass = klass();
4606
4607 ciKlass* res_klass = nullptr;
4608 bool res_xk = false;
4609 const Type* res;
4610 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4611
4612 if (kind == UNLOADED) {
4613 // One of these classes has not been loaded
4614 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4615 #ifndef PRODUCT
4616 if (PrintOpto && Verbose) {
4617 tty->print("meet of unloaded classes resulted in: ");
4618 unloaded_meet->dump();
4619 tty->cr();
4620 tty->print(" this == ");
4621 dump();
4622 tty->cr();
4623 tty->print(" tinst == ");
4624 tinst->dump();
4625 tty->cr();
4626 }
4627 #endif
4628 res = unloaded_meet;
4629 } else {
4630 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4631 if (kind == NOT_SUBTYPE && instance_id > 0) {
4632 instance_id = InstanceBot;
4633 } else if (kind == LCA) {
4634 instance_id = InstanceBot;
4635 }
4636 ciObject* o = nullptr; // Assume not constant when done
4637 ciObject* this_oop = const_oop();
4638 ciObject* tinst_oop = tinst->const_oop();
4639 if (ptr == Constant) {
4640 if (this_oop != nullptr && tinst_oop != nullptr &&
4641 this_oop->equals(tinst_oop))
4642 o = this_oop;
4643 else if (above_centerline(_ptr)) {
4644 assert(!tinst_klass->is_interface(), "");
4645 o = tinst_oop;
4646 } else if (above_centerline(tinst->_ptr)) {
4647 assert(!this_klass->is_interface(), "");
4648 o = this_oop;
4649 } else
4650 ptr = NotNull;
4651 }
4652 res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4653 }
4654
4655 return res;
4656
4657 } // End of case InstPtr
4658
4659 } // End of switch
4660 return this; // Return the double constant
4661 }
4662
4663 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4664 ciKlass*& res_klass, bool& res_xk) {
4665 ciKlass* this_klass = this_type->klass();
4666 ciKlass* other_klass = other_type->klass();
4667
4668 bool this_xk = this_type->klass_is_exact();
4669 bool other_xk = other_type->klass_is_exact();
4670 PTR this_ptr = this_type->ptr();
4671 PTR other_ptr = other_type->ptr();
4672 const TypeInterfaces* this_interfaces = this_type->interfaces();
4673 const TypeInterfaces* other_interfaces = other_type->interfaces();
4674 // Check for easy case; klasses are equal (and perhaps not loaded!)
4675 // If we have constants, then we created oops so classes are loaded
4676 // and we can handle the constants further down. This case handles
4677 // both-not-loaded or both-loaded classes
4678 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4679 res_klass = this_klass;
4680 res_xk = this_xk;
4681 return QUICK;
4682 }
4683
4684 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4685 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4686 return UNLOADED;
4687 }
4693 // If both are up and they do NOT subtype, "fall hard".
4694 // If both are down and they subtype, take the supertype class.
4695 // If both are down and they do NOT subtype, "fall hard".
4696 // Constants treated as down.
4697
4698 // Now, reorder the above list; observe that both-down+subtype is also
4699 // "fall hard"; "fall hard" becomes the default case:
4700 // If we split one up & one down AND they subtype, take the down man.
4701 // If both are up and they subtype, take the subtype class.
4702
4703 // If both are down and they subtype, "fall hard".
4704 // If both are down and they do NOT subtype, "fall hard".
4705 // If both are up and they do NOT subtype, "fall hard".
4706 // If we split one up & one down AND they do NOT subtype, "fall hard".
4707
4708 // If a proper subtype is exact, and we return it, we return it exactly.
4709 // If a proper supertype is exact, there can be no subtyping relationship!
4710 // If both types are equal to the subtype, exactness is and-ed below the
4711 // centerline and or-ed above it. (N.B. Constants are always exact.)
4712
4713 const T* subtype = nullptr;
4714 bool subtype_exact = false;
4715 if (this_type->is_same_java_type_as(other_type)) {
4716 // Same klass
4717 subtype = this_type;
4718 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4719 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4720 subtype = this_type; // Pick subtyping class
4721 subtype_exact = this_xk;
4722 } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4723 subtype = other_type; // Pick subtyping class
4724 subtype_exact = other_xk;
4725 }
4726
4727 if (subtype != nullptr) {
4728 if (above_centerline(ptr)) {
4729 // Both types are empty.
4730 this_type = other_type = subtype;
4731 this_xk = other_xk = subtype_exact;
4732 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4733 // this_type is empty while other_type is not. Take other_type.
4734 this_type = other_type;
4735 this_xk = other_xk;
4736 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4737 // other_type is empty while this_type is not. Take this_type.
4738 other_type = this_type; // this is down; keep down man
4739 } else {
4740 // this_type and other_type are both non-empty.
4741 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4742 }
4743 }
4744
4745 // Check for classes now being equal
4746 if (this_type->is_same_java_type_as(other_type)) {
4747 // If the klasses are equal, the constants may still differ. Fall to
4748 // NotNull if they do (neither constant is null; that is a special case
4749 // handled elsewhere).
4750 res_klass = this_type->klass();
4751 res_xk = this_xk;
4752 return SUBTYPE;
4753 } // Else classes are not equal
4754
4755 // Since klasses are different, we require a LCA in the Java
4756 // class hierarchy - which means we have to fall to at least NotNull.
4757 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4758 ptr = NotNull;
4759 }
4760
4761 interfaces = this_interfaces->intersection_with(other_interfaces);
4762
4763 // Now we find the LCA of Java classes
4764 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4765
4766 res_klass = k;
4767 res_xk = false;
4768 return LCA;
4769 }
4770
4771 // Top-Flat Flat Not-Flat Maybe-Flat
4772 // -------------------------------------------------------------
4773 // Top-Flat Top-Flat Flat Not-Flat Maybe-Flat
4774 // Flat Flat Flat Maybe-Flat Maybe-Flat
4775 // Not-Flat Not-Flat Maybe-Flat Not-Flat Maybe-Flat
4776 // Maybe-Flat Maybe-Flat Maybe-Flat Maybe-Flat Maybe-flat
4777 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4778 if (left == TopFlat) {
4779 return right;
4780 }
4781 if (right == TopFlat) {
4782 return left;
4783 }
4784 if (left == MaybeFlat || right == MaybeFlat) {
4785 return MaybeFlat;
4786 }
4787
4788 switch (left) {
4789 case Flat:
4790 if (right == Flat) {
4791 return Flat;
4792 }
4793 return MaybeFlat;
4794 case NotFlat:
4795 if (right == NotFlat) {
4796 return NotFlat;
4797 }
4798 return MaybeFlat;
4799 default:
4800 ShouldNotReachHere();
4801 return Uninitialized;
4802 }
4803 }
4804
4805 //------------------------java_mirror_type--------------------------------------
4806 ciType* TypeInstPtr::java_mirror_type() const {
4807 // must be a singleton type
4808 if( const_oop() == nullptr ) return nullptr;
4809
4810 // must be of type java.lang.Class
4811 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4812 return const_oop()->as_instance()->java_mirror_type();
4813 }
4814
4815
4816 //------------------------------xdual------------------------------------------
4817 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4818 // inheritance mechanism.
4819 const Type* TypeInstPtr::xdual() const {
4820 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4821 dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4822 }
4823
4824 //------------------------------eq---------------------------------------------
4825 // Structural equality check for Type representations
4826 bool TypeInstPtr::eq( const Type *t ) const {
4827 const TypeInstPtr *p = t->is_instptr();
4828 return
4829 klass()->equals(p->klass()) &&
4830 _flat_in_array == p->_flat_in_array &&
4831 _interfaces->eq(p->_interfaces) &&
4832 TypeOopPtr::eq(p); // Check sub-type stuff
4833 }
4834
4835 //------------------------------hash-------------------------------------------
4836 // Type-specific hashing function.
4837 uint TypeInstPtr::hash() const {
4838 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4839 }
4840
4841 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4842 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4843 }
4844
4845
4846 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4847 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4848 }
4849
4850 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4851 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4852 }
4853
4854
4855 //------------------------------dump2------------------------------------------
4856 // Dump oop Type
4857 #ifndef PRODUCT
4858 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4862 _interfaces->dump(st);
4863
4864 if (_ptr == Constant && (WizardMode || Verbose)) {
4865 ResourceMark rm;
4866 stringStream ss;
4867
4868 st->print(" ");
4869 const_oop()->print_oop(&ss);
4870 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4871 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4872 char* buf = ss.as_string(/* c_heap= */false);
4873 StringUtils::replace_no_expand(buf, "\n", "");
4874 st->print_raw(buf);
4875 }
4876
4877 st->print(":%s", ptr_msg[_ptr]);
4878 if (_klass_is_exact) {
4879 st->print(":exact");
4880 }
4881
4882 st->print(" *");
4883
4884 dump_offset(st);
4885 dump_instance_id(st);
4886 dump_inline_depth(st);
4887 dump_speculative(st);
4888 dump_flat_in_array(_flat_in_array, st);
4889 }
4890 #endif
4891
4892 bool TypeInstPtr::empty() const {
4893 if (_flat_in_array == TopFlat) {
4894 return true;
4895 }
4896 return TypeOopPtr::empty();
4897 }
4898
4899 //------------------------------add_offset-------------------------------------
4900 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4901 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4902 _instance_id, add_offset_speculative(offset), _inline_depth);
4903 }
4904
4905 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4906 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4907 _instance_id, with_offset_speculative(offset), _inline_depth);
4908 }
4909
4910 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4911 if (_speculative == nullptr) {
4912 return this;
4913 }
4914 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4915 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4916 _instance_id, nullptr, _inline_depth);
4917 }
4918
4919 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4920 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4921 }
4922
4923 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4924 if (!UseInlineDepthForSpeculativeTypes) {
4925 return this;
4926 }
4927 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4928 }
4929
4930 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4931 assert(is_known_instance(), "should be known");
4932 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4933 }
4934
4935 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4936 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4937 }
4938
4939 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4940 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4941 }
4942
4943 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4944 bool xk = klass_is_exact();
4945 ciInstanceKlass* ik = klass()->as_instance_klass();
4946 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4947 if (_interfaces->eq(ik)) {
4948 Compile* C = Compile::current();
4949 Dependencies* deps = C->dependencies();
4950 deps->assert_leaf_type(ik);
4951 xk = true;
4952 }
4953 }
4954 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4955 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4956 }
4957
4958 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) {
4959 static_assert(std::is_base_of<T2, T1>::value, "");
4960
4961 if (!this_one->is_instance_type(other)) {
4962 return false;
4963 }
4964
4965 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4966 return true;
4967 }
4968
4969 return this_one->klass()->is_subtype_of(other->klass()) &&
4970 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4971 }
4972
4973
4974 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4975 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4980 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4981 return true;
4982 }
4983
4984 if (this_one->is_instance_type(other)) {
4985 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4986 }
4987
4988 int dummy;
4989 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4990 if (this_top_or_bottom) {
4991 return false;
4992 }
4993
4994 const T1* other_ary = this_one->is_array_type(other);
4995 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4996 const TypePtr* this_elem = this_one->elem()->make_ptr();
4997 if (other_elem != nullptr && this_elem != nullptr) {
4998 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4999 }
5000 if (other_elem == nullptr && this_elem == nullptr) {
5001 return this_one->klass()->is_subtype_of(other->klass());
5002 }
5003
5004 return false;
5005 }
5006
5007 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5008 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5009 }
5010
5011 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5012 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5013 }
5014
5015 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5016 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5017 }
5018
5019 //=============================================================================
5020 // Convenience common pre-built types.
5021 const TypeAryPtr* TypeAryPtr::BOTTOM;
5022 const TypeAryPtr *TypeAryPtr::RANGE;
5023 const TypeAryPtr *TypeAryPtr::OOPS;
5024 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5025 const TypeAryPtr *TypeAryPtr::BYTES;
5026 const TypeAryPtr *TypeAryPtr::SHORTS;
5027 const TypeAryPtr *TypeAryPtr::CHARS;
5028 const TypeAryPtr *TypeAryPtr::INTS;
5029 const TypeAryPtr *TypeAryPtr::LONGS;
5030 const TypeAryPtr *TypeAryPtr::FLOATS;
5031 const TypeAryPtr *TypeAryPtr::DOUBLES;
5032 const TypeAryPtr *TypeAryPtr::INLINES;
5033
5034 //------------------------------make-------------------------------------------
5035 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5036 int instance_id, const TypePtr* speculative, int inline_depth) {
5037 assert(!(k == nullptr && ary->_elem->isa_int()),
5038 "integral arrays must be pre-equipped with a class");
5039 if (!xk) xk = ary->ary_must_be_exact();
5040 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5041 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5042 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5043 k = nullptr;
5044 }
5045 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5046 }
5047
5048 //------------------------------make-------------------------------------------
5049 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5050 int instance_id, const TypePtr* speculative, int inline_depth,
5051 bool is_autobox_cache) {
5052 assert(!(k == nullptr && ary->_elem->isa_int()),
5053 "integral arrays must be pre-equipped with a class");
5054 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5055 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
5056 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5057 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5058 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5059 k = nullptr;
5060 }
5061 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5062 }
5063
5064 //------------------------------cast_to_ptr_type-------------------------------
5065 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5066 if( ptr == _ptr ) return this;
5067 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5068 }
5069
5070
5071 //-----------------------------cast_to_exactness-------------------------------
5072 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5073 if( klass_is_exact == _klass_is_exact ) return this;
5074 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
5075 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5076 }
5077
5078 //-----------------------------cast_to_instance_id----------------------------
5079 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5080 if( instance_id == _instance_id ) return this;
5081 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5082 }
5083
5084
5085 //-----------------------------max_array_length-------------------------------
5086 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5087 jint TypeAryPtr::max_array_length(BasicType etype) {
5088 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5089 if (etype == T_NARROWOOP) {
5090 etype = T_OBJECT;
5091 } else if (etype == T_ILLEGAL) { // bottom[]
5092 etype = T_BYTE; // will produce conservatively high value
5093 } else {
5094 fatal("not an element type: %s", type2name(etype));
5095 }
5096 }
5097 return arrayOopDesc::max_array_length(etype);
5098 }
5099
5100 //-----------------------------narrow_size_type-------------------------------
5101 // Narrow the given size type to the index range for the given array base type.
5119 if (size->is_con()) {
5120 lo = hi;
5121 }
5122 chg = true;
5123 }
5124 // Negative length arrays will produce weird intermediate dead fast-path code
5125 if (lo > hi) {
5126 return TypeInt::ZERO;
5127 }
5128 if (!chg) {
5129 return size;
5130 }
5131 return TypeInt::make(lo, hi, Type::WidenMin);
5132 }
5133
5134 //-------------------------------cast_to_size----------------------------------
5135 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5136 assert(new_size != nullptr, "");
5137 new_size = narrow_size_type(new_size);
5138 if (new_size == size()) return this;
5139 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5140 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5141 }
5142
5143 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5144 if (flat == is_flat()) {
5145 return this;
5146 }
5147 assert(!flat || !is_not_flat(), "inconsistency");
5148 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5149 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5150 if (res->speculative() == res->remove_speculative()) {
5151 return res->remove_speculative();
5152 }
5153 return res;
5154 }
5155
5156 //-------------------------------cast_to_not_flat------------------------------
5157 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5158 if (not_flat == is_not_flat()) {
5159 return this;
5160 }
5161 assert(!not_flat || !is_flat(), "inconsistency");
5162 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5163 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5164 // We keep the speculative part if it contains information about flat-/nullability.
5165 // Make sure it's removed if it's not better than the non-speculative type anymore.
5166 if (res->speculative() == res->remove_speculative()) {
5167 return res->remove_speculative();
5168 }
5169 return res;
5170 }
5171
5172 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5173 if (null_free == is_null_free()) {
5174 return this;
5175 }
5176 assert(!null_free || !is_not_null_free(), "inconsistency");
5177 const Type* elem = this->elem();
5178 const Type* new_elem = elem->make_ptr();
5179 if (null_free) {
5180 new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5181 } else {
5182 new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5183 }
5184 new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5185 const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5186 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5187 if (res->speculative() == res->remove_speculative()) {
5188 return res->remove_speculative();
5189 }
5190 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5191 "speculative type must not be narrower than non-speculative type");
5192 return res;
5193 }
5194
5195 //-------------------------------cast_to_not_null_free-------------------------
5196 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5197 if (not_null_free == is_not_null_free()) {
5198 return this;
5199 }
5200 assert(!not_null_free || !is_null_free(), "inconsistency");
5201 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5202 const TypePtr* new_spec = _speculative;
5203 if (new_spec != nullptr) {
5204 // Could be 'null free' from profiling, which would contradict the cast.
5205 new_spec = new_spec->is_aryptr()->cast_to_null_free(false)->cast_to_not_null_free();
5206 }
5207 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5208 _instance_id, new_spec, _inline_depth, _is_autobox_cache);
5209 // We keep the speculative part if it contains information about flat-/nullability.
5210 // Make sure it's removed if it's not better than the non-speculative type anymore.
5211 if (res->speculative() == res->remove_speculative()) {
5212 return res->remove_speculative();
5213 }
5214 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5215 "speculative type must not be narrower than non-speculative type");
5216 return res;
5217 }
5218
5219 //---------------------------------update_properties---------------------------
5220 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5221 if ((from->is_flat() && is_not_flat()) ||
5222 (from->is_not_flat() && is_flat()) ||
5223 (from->is_null_free() && is_not_null_free()) ||
5224 (from->is_not_null_free() && is_null_free())) {
5225 return nullptr; // Inconsistent properties
5226 }
5227 const TypeAryPtr* res = this;
5228 if (from->is_not_null_free()) {
5229 res = res->cast_to_not_null_free();
5230 }
5231 if (from->is_not_flat()) {
5232 res = res->cast_to_not_flat();
5233 }
5234 return res;
5235 }
5236
5237 jint TypeAryPtr::flat_layout_helper() const {
5238 return exact_klass()->as_flat_array_klass()->layout_helper();
5239 }
5240
5241 int TypeAryPtr::flat_elem_size() const {
5242 return exact_klass()->as_flat_array_klass()->element_byte_size();
5243 }
5244
5245 int TypeAryPtr::flat_log_elem_size() const {
5246 return exact_klass()->as_flat_array_klass()->log2_element_size();
5247 }
5248
5249 jint TypeAryPtr::max_flat_elements() const {
5250 return exact_klass()->as_flat_array_klass()->max_elements();
5251 }
5252
5253 //------------------------------cast_to_stable---------------------------------
5254 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5255 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5256 return this;
5257
5258 const Type* elem = this->elem();
5259 const TypePtr* elem_ptr = elem->make_ptr();
5260
5261 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5262 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5263 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5264 }
5265
5266 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5267
5268 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5269 }
5270
5271 //-----------------------------stable_dimension--------------------------------
5272 int TypeAryPtr::stable_dimension() const {
5273 if (!is_stable()) return 0;
5274 int dim = 1;
5275 const TypePtr* elem_ptr = elem()->make_ptr();
5276 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5277 dim += elem_ptr->is_aryptr()->stable_dimension();
5278 return dim;
5279 }
5280
5281 //----------------------cast_to_autobox_cache-----------------------------------
5282 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5283 if (is_autobox_cache()) return this;
5284 const TypeOopPtr* etype = elem()->make_oopptr();
5285 if (etype == nullptr) return this;
5286 // The pointers in the autobox arrays are always non-null.
5287 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5288 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5289 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5290 }
5291
5292 //------------------------------eq---------------------------------------------
5293 // Structural equality check for Type representations
5294 bool TypeAryPtr::eq( const Type *t ) const {
5295 const TypeAryPtr *p = t->is_aryptr();
5296 return
5297 _ary == p->_ary && // Check array
5298 TypeOopPtr::eq(p) &&// Check sub-parts
5299 _field_offset == p->_field_offset;
5300 }
5301
5302 //------------------------------hash-------------------------------------------
5303 // Type-specific hashing function.
5304 uint TypeAryPtr::hash(void) const {
5305 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5306 }
5307
5308 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5309 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5310 }
5311
5312 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5313 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5314 }
5315
5316 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5317 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5318 }
5319 //------------------------------meet-------------------------------------------
5320 // Compute the MEET of two types. It returns a new Type object.
5321 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5322 // Perform a fast test for common case; meeting the same types together.
5323 if( this == t ) return this; // Meeting same type-rep?
5324 // Current "this->_base" is Pointer
5325 switch (t->base()) { // switch on original type
5332 case HalfFloatBot:
5333 case FloatTop:
5334 case FloatCon:
5335 case FloatBot:
5336 case DoubleTop:
5337 case DoubleCon:
5338 case DoubleBot:
5339 case NarrowOop:
5340 case NarrowKlass:
5341 case Bottom: // Ye Olde Default
5342 return Type::BOTTOM;
5343 case Top:
5344 return this;
5345
5346 default: // All else is a mistake
5347 typerr(t);
5348
5349 case OopPtr: { // Meeting to OopPtrs
5350 // Found a OopPtr type vs self-AryPtr type
5351 const TypeOopPtr *tp = t->is_oopptr();
5352 Offset offset = meet_offset(tp->offset());
5353 PTR ptr = meet_ptr(tp->ptr());
5354 int depth = meet_inline_depth(tp->inline_depth());
5355 const TypePtr* speculative = xmeet_speculative(tp);
5356 switch (tp->ptr()) {
5357 case TopPTR:
5358 case AnyNull: {
5359 int instance_id = meet_instance_id(InstanceTop);
5360 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5361 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5362 }
5363 case BotPTR:
5364 case NotNull: {
5365 int instance_id = meet_instance_id(tp->instance_id());
5366 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5367 }
5368 default: ShouldNotReachHere();
5369 }
5370 }
5371
5372 case AnyPtr: { // Meeting two AnyPtrs
5373 // Found an AnyPtr type vs self-AryPtr type
5374 const TypePtr *tp = t->is_ptr();
5375 Offset offset = meet_offset(tp->offset());
5376 PTR ptr = meet_ptr(tp->ptr());
5377 const TypePtr* speculative = xmeet_speculative(tp);
5378 int depth = meet_inline_depth(tp->inline_depth());
5379 switch (tp->ptr()) {
5380 case TopPTR:
5381 return this;
5382 case BotPTR:
5383 case NotNull:
5384 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5385 case Null:
5386 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5387 // else fall through to AnyNull
5388 case AnyNull: {
5389 int instance_id = meet_instance_id(InstanceTop);
5390 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5391 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5392 }
5393 default: ShouldNotReachHere();
5394 }
5395 }
5396
5397 case MetadataPtr:
5398 case KlassPtr:
5399 case InstKlassPtr:
5400 case AryKlassPtr:
5401 case RawPtr: return TypePtr::BOTTOM;
5402
5403 case AryPtr: { // Meeting 2 references?
5404 const TypeAryPtr *tap = t->is_aryptr();
5405 Offset off = meet_offset(tap->offset());
5406 Offset field_off = meet_field_offset(tap->field_offset());
5407 const Type* tm = _ary->meet_speculative(tap->_ary);
5408 const TypeAry* tary = tm->isa_ary();
5409 if (tary == nullptr) {
5410 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5411 return tm;
5412 }
5413 PTR ptr = meet_ptr(tap->ptr());
5414 int instance_id = meet_instance_id(tap->instance_id());
5415 const TypePtr* speculative = xmeet_speculative(tap);
5416 int depth = meet_inline_depth(tap->inline_depth());
5417
5418 ciKlass* res_klass = nullptr;
5419 bool res_xk = false;
5420 bool res_flat = false;
5421 bool res_not_flat = false;
5422 bool res_not_null_free = false;
5423 bool res_atomic = false;
5424 const Type* elem = tary->_elem;
5425 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5426 instance_id = InstanceBot;
5427 } else if (this->is_flat() != tap->is_flat()) {
5428 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5429 if (tary->_flat) {
5430 // Result is in a flat representation
5431 off = Offset(is_flat() ? offset() : tap->offset());
5432 field_off = is_flat() ? field_offset() : tap->field_offset();
5433 } else if (below_centerline(ptr)) {
5434 // Result is in a non-flat representation
5435 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5436 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5437 } else if (flat_offset() == tap->flat_offset()) {
5438 off = Offset(!is_flat() ? offset() : tap->offset());
5439 field_off = !is_flat() ? field_offset() : tap->field_offset();
5440 }
5441 }
5442
5443 ciObject* o = nullptr; // Assume not constant when done
5444 ciObject* this_oop = const_oop();
5445 ciObject* tap_oop = tap->const_oop();
5446 if (ptr == Constant) {
5447 if (this_oop != nullptr && tap_oop != nullptr &&
5448 this_oop->equals(tap_oop)) {
5449 o = tap_oop;
5450 } else if (above_centerline(_ptr)) {
5451 o = tap_oop;
5452 } else if (above_centerline(tap->_ptr)) {
5453 o = this_oop;
5454 } else {
5455 ptr = NotNull;
5456 }
5457 }
5458 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);
5459 }
5460
5461 // All arrays inherit from Object class
5462 case InstPtr: {
5463 const TypeInstPtr *tp = t->is_instptr();
5464 Offset offset = meet_offset(tp->offset());
5465 PTR ptr = meet_ptr(tp->ptr());
5466 int instance_id = meet_instance_id(tp->instance_id());
5467 const TypePtr* speculative = xmeet_speculative(tp);
5468 int depth = meet_inline_depth(tp->inline_depth());
5469 const TypeInterfaces* interfaces = meet_interfaces(tp);
5470 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5471 const TypeInterfaces* this_interfaces = _interfaces;
5472
5473 switch (ptr) {
5474 case TopPTR:
5475 case AnyNull: // Fall 'down' to dual of object klass
5476 // For instances when a subclass meets a superclass we fall
5477 // below the centerline when the superclass is exact. We need to
5478 // do the same here.
5479 //
5480 // Flat in array:
5481 // We do
5482 // dual(TypeAryPtr) MEET dual(TypeInstPtr)
5483 // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5484 // instances or arrays).
5485 // If TypeInstPtr is an Object and either
5486 // - exact
5487 // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5488 // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5489 // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5490 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5491 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5492 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5493 } else {
5494 // cannot subclass, so the meet has to fall badly below the centerline
5495 ptr = NotNull;
5496 instance_id = InstanceBot;
5497 interfaces = this_interfaces->intersection_with(tp_interfaces);
5498 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5499 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5500 }
5501 case Constant:
5502 case NotNull:
5503 case BotPTR: { // Fall down to object klass
5504 // LCA is object_klass, but if we subclass from the top we can do better
5505 if (above_centerline(tp->ptr())) {
5506 // If 'tp' is above the centerline and it is Object class
5507 // then we can subclass in the Java class hierarchy.
5508 // For instances when a subclass meets a superclass we fall
5509 // below the centerline when the superclass is exact. We need
5510 // to do the same here.
5511
5512 // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5513 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5514 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5515 // that is, my array type is a subtype of 'tp' klass
5516 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5517 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5518 }
5519 }
5520 // The other case cannot happen, since t cannot be a subtype of an array.
5521 // The meet falls down to Object class below centerline.
5522 if (ptr == Constant) {
5523 ptr = NotNull;
5524 }
5525 if (instance_id > 0) {
5526 instance_id = InstanceBot;
5527 }
5528
5529 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5530 interfaces = this_interfaces->intersection_with(tp_interfaces);
5531 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5532 flat_in_array, instance_id, speculative, depth);
5533 }
5534 default: typerr(t);
5535 }
5536 }
5537 }
5538 return this; // Lint noise
5539 }
5540
5541
5542 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5543 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5544 int dummy;
5545 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5546 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5547 ciKlass* this_klass = this_ary->klass();
5548 ciKlass* other_klass = other_ary->klass();
5549 bool this_xk = this_ary->klass_is_exact();
5550 bool other_xk = other_ary->klass_is_exact();
5551 PTR this_ptr = this_ary->ptr();
5552 PTR other_ptr = other_ary->ptr();
5553 bool this_flat = this_ary->is_flat();
5554 bool this_not_flat = this_ary->is_not_flat();
5555 bool other_flat = other_ary->is_flat();
5556 bool other_not_flat = other_ary->is_not_flat();
5557 bool this_not_null_free = this_ary->is_not_null_free();
5558 bool other_not_null_free = other_ary->is_not_null_free();
5559 bool this_atomic = this_ary->is_atomic();
5560 bool other_atomic = other_ary->is_atomic();
5561 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5562 res_klass = nullptr;
5563 MeetResult result = SUBTYPE;
5564 res_flat = this_flat && other_flat;
5565 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5566 res_not_flat = this_not_flat && other_not_flat;
5567 res_not_null_free = this_not_null_free && other_not_null_free;
5568 res_atomic = this_atomic && other_atomic;
5569
5570 if (elem->isa_int()) {
5571 // Integral array element types have irrelevant lattice relations.
5572 // It is the klass that determines array layout, not the element type.
5573 if (this_top_or_bottom) {
5574 res_klass = other_klass;
5575 } else if (other_top_or_bottom || other_klass == this_klass) {
5576 res_klass = this_klass;
5577 } else {
5578 // Something like byte[int+] meets char[int+].
5579 // This must fall to bottom, not (int[-128..65535])[int+].
5580 // instance_id = InstanceBot;
5581 elem = Type::BOTTOM;
5582 result = NOT_SUBTYPE;
5583 if (above_centerline(ptr) || ptr == Constant) {
5584 ptr = NotNull;
5585 res_xk = false;
5586 return NOT_SUBTYPE;
5587 }
5588 }
5589 } else {// Non integral arrays.
5590 // Must fall to bottom if exact klasses in upper lattice
5591 // are not equal or super klass is exact.
5592 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5593 // meet with top[] and bottom[] are processed further down:
5594 !this_top_or_bottom && !other_top_or_bottom &&
5595 // both are exact and not equal:
5597 // 'tap' is exact and super or unrelated:
5598 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5599 // 'this' is exact and super or unrelated:
5600 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5601 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5602 elem = Type::BOTTOM;
5603 }
5604 ptr = NotNull;
5605 res_xk = false;
5606 return NOT_SUBTYPE;
5607 }
5608 }
5609
5610 res_xk = false;
5611 switch (other_ptr) {
5612 case AnyNull:
5613 case TopPTR:
5614 // Compute new klass on demand, do not use tap->_klass
5615 if (below_centerline(this_ptr)) {
5616 res_xk = this_xk;
5617 if (this_ary->is_flat()) {
5618 elem = this_ary->elem();
5619 }
5620 } else {
5621 res_xk = (other_xk || this_xk);
5622 }
5623 break;
5624 case Constant: {
5625 if (this_ptr == Constant && same_nullness) {
5626 // Only exact if same nullness since:
5627 // null-free [LMyValue <: nullable [LMyValue.
5628 res_xk = true;
5629 } else if (above_centerline(this_ptr)) {
5630 res_xk = true;
5631 } else {
5632 // Only precise for identical arrays
5633 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5634 // Even though MyValue is final, [LMyValue is only exact if the array
5635 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5636 if (res_xk && !res_null_free && !res_not_null_free) {
5637 ptr = NotNull;
5638 res_xk = false;
5639 }
5640 }
5641 break;
5642 }
5643 case NotNull:
5644 case BotPTR:
5645 // Compute new klass on demand, do not use tap->_klass
5646 if (above_centerline(this_ptr)) {
5647 res_xk = other_xk;
5648 if (other_ary->is_flat()) {
5649 elem = other_ary->elem();
5650 }
5651 } else {
5652 res_xk = (other_xk && this_xk) &&
5653 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5654 // Even though MyValue is final, [LMyValue is only exact if the array
5655 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5656 if (res_xk && !res_null_free && !res_not_null_free) {
5657 res_xk = false;
5658 }
5659 }
5660 break;
5661 default: {
5662 ShouldNotReachHere();
5663 return result;
5664 }
5665 }
5666 return result;
5667 }
5668
5669
5670 //------------------------------xdual------------------------------------------
5671 // Dual: compute field-by-field dual
5672 const Type *TypeAryPtr::xdual() const {
5673 bool xk = _klass_is_exact;
5674 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());
5675 }
5676
5677 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5678 return _field_offset.meet(offset);
5679 }
5680
5681 //------------------------------dual_offset------------------------------------
5682 Type::Offset TypeAryPtr::dual_field_offset() const {
5683 return _field_offset.dual();
5684 }
5685
5686 //------------------------------dump2------------------------------------------
5687 #ifndef PRODUCT
5688 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5689 st->print("aryptr:");
5690 _ary->dump2(d, depth, st);
5691 _interfaces->dump(st);
5692
5693 if (_ptr == Constant) {
5694 const_oop()->print(st);
5695 }
5696
5697 st->print(":%s", ptr_msg[_ptr]);
5698 if (_klass_is_exact) {
5699 st->print(":exact");
5700 }
5701
5702 if (is_flat()) {
5703 st->print(":flat");
5704 st->print("(");
5705 _field_offset.dump2(st);
5706 st->print(")");
5707 } else if (is_not_flat()) {
5708 st->print(":not_flat");
5709 }
5710 if (is_null_free()) {
5711 st->print(":null free");
5712 }
5713 if (is_atomic()) {
5714 st->print(":atomic");
5715 }
5716 if (Verbose) {
5717 if (is_not_flat()) {
5718 st->print(":not flat");
5719 }
5720 if (is_not_null_free()) {
5721 st->print(":nullable");
5722 }
5723 }
5724 if (offset() != 0) {
5725 BasicType basic_elem_type = elem()->basic_type();
5726 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5727 if( _offset == Offset::top ) st->print("+undefined");
5728 else if( _offset == Offset::bottom ) st->print("+any");
5729 else if( offset() < header_size ) st->print("+%d", offset());
5730 else {
5731 if (basic_elem_type == T_ILLEGAL) {
5732 st->print("+any");
5733 } else {
5734 int elem_size = type2aelembytes(basic_elem_type);
5735 st->print("[%d]", (offset() - header_size)/elem_size);
5736 }
5737 }
5738 }
5739
5740 dump_instance_id(st);
5741 dump_inline_depth(st);
5742 dump_speculative(st);
5743 }
5744 #endif
5745
5746 bool TypeAryPtr::empty(void) const {
5747 if (_ary->empty()) {
5748 return true;
5749 }
5750
5751 // Reference array is always possible. Only flat array with non-flattenable content can be an issue.
5752 if (const TypeOopPtr* elem_ptr = elem()->make_oopptr(); _ary->_flat && elem_ptr != nullptr && elem_ptr->is_inlinetypeptr()) {
5753 auto impossible_layout_with_null_freeness = [this](bool null_free, bool atomic) -> bool {
5754 ArrayDescription description = elem()->inline_klass()->array_description_of_array_properties(ArrayProperties::Default().with_null_restricted(null_free).with_non_atomic(!atomic));
5755 return !LayoutKindHelper::is_flat(description._layout_kind); // We get a contradiction between _ary->_flat and array_layout_selection
5756 };
5757 auto impossible_layout = [&](bool atomic) -> bool {
5758 if (is_null_free()) {
5759 // Surely null-free
5760 if (impossible_layout_with_null_freeness(true, atomic)) {
5761 return true;
5762 }
5763 } else if (is_not_null_free()) {
5764 // Surely nullable
5765 if (impossible_layout_with_null_freeness(false, atomic)) {
5766 return true;
5767 }
5768 } else {
5769 // Not sure...
5770 if (impossible_layout_with_null_freeness(false, atomic) && impossible_layout_with_null_freeness(true, atomic)) {
5771 return true;
5772 }
5773 }
5774 return false;
5775 };
5776 if (_ary->_atomic) {
5777 // Surely atomic
5778 if (impossible_layout(true)) {
5779 return true;
5780 }
5781 } else if (klass_is_exact()) {
5782 // Surely non-atomic
5783 if (impossible_layout(false)) {
5784 return true;
5785 }
5786 } else {
5787 // Not sure...
5788 if (impossible_layout(true) && impossible_layout(false)) {
5789 return true;
5790 }
5791 }
5792 }
5793
5794 return TypeOopPtr::empty();
5795 }
5796
5797 //------------------------------add_offset-------------------------------------
5798 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5799 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);
5800 }
5801
5802 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5803 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);
5804 }
5805
5806 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5807 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5808 }
5809
5810 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5811 if (_speculative == nullptr) {
5812 return this;
5813 }
5814 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5815 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);
5816 }
5817
5818 const Type* TypeAryPtr::cleanup_speculative() const {
5819 if (speculative() == nullptr) {
5820 return this;
5821 }
5822 // Keep speculative part if it contains information about flat-/nullability
5823 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5824 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5825 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5826 return this;
5827 }
5828 return TypeOopPtr::cleanup_speculative();
5829 }
5830
5831 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5832 if (!UseInlineDepthForSpeculativeTypes) {
5833 return this;
5834 }
5835 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5836 }
5837
5838 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5839 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);
5840 }
5841
5842 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5843 if (!is_flat() || !klass_is_exact() || offset == OffsetBot || offset == OffsetTop) {
5844 return add_offset(offset);
5845 }
5846
5847 // Handle flat concrete value class array with known 'offset' which could refer to an actual field in the flat storage.
5848 int adj = 0;
5849 if (_offset != Offset::bottom && _offset != Offset::top) {
5850 adj = _offset.get();
5851 offset += _offset.get();
5852 }
5853 uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5854 if (_field_offset != Offset::bottom && _field_offset != Offset::top) {
5855 offset += _field_offset.get();
5856 if (_offset == Offset::bottom || _offset == Offset::top) {
5857 offset += header;
5858 }
5859 }
5860 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5861 // Try to get the field of the inline type array element we are pointing to
5862 ciInlineKlass* vk = elem()->inline_klass();
5863 int shift = flat_log_elem_size();
5864 int mask = (1 << shift) - 1;
5865 int field_offset = static_cast<int>((offset - header) & mask);
5866 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5867 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5868 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5869 }
5870 }
5871 return add_offset(offset - adj);
5872 }
5873
5874 // Return offset incremented by field_offset for flat inline type arrays
5875 int TypeAryPtr::flat_offset() const {
5876 int offset = _offset.get();
5877 if (offset != OffsetBot && offset != OffsetTop &&
5878 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5879 offset += _field_offset.get();
5880 }
5881 return offset;
5882 }
5883
5884 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5885 assert(is_known_instance(), "should be known");
5886 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5887 }
5888
5889 //=============================================================================
5890
5891
5892 //------------------------------hash-------------------------------------------
5893 // Type-specific hashing function.
5894 uint TypeNarrowPtr::hash(void) const {
5895 return _ptrtype->hash() + 7;
5896 }
5897
5898 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5899 return _ptrtype->singleton();
5900 }
5901
5902 bool TypeNarrowPtr::empty(void) const {
5903 return _ptrtype->empty();
5904 }
5905
5906 intptr_t TypeNarrowPtr::get_con() const {
5907 return _ptrtype->get_con();
5908 }
5909
5910 bool TypeNarrowPtr::eq( const Type *t ) const {
5911 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5965 case HalfFloatTop:
5966 case HalfFloatCon:
5967 case HalfFloatBot:
5968 case FloatTop:
5969 case FloatCon:
5970 case FloatBot:
5971 case DoubleTop:
5972 case DoubleCon:
5973 case DoubleBot:
5974 case AnyPtr:
5975 case RawPtr:
5976 case OopPtr:
5977 case InstPtr:
5978 case AryPtr:
5979 case MetadataPtr:
5980 case KlassPtr:
5981 case InstKlassPtr:
5982 case AryKlassPtr:
5983 case NarrowOop:
5984 case NarrowKlass:
5985 case Bottom: // Ye Olde Default
5986 return Type::BOTTOM;
5987 case Top:
5988 return this;
5989
5990 default: // All else is a mistake
5991 typerr(t);
5992
5993 } // End of switch
5994
5995 return this;
5996 }
5997
5998 #ifndef PRODUCT
5999 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6000 _ptrtype->dump2(d, depth, st);
6001 }
6002 #endif
6003
6004 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
6048 return (one == two) && TypePtr::eq(t);
6049 } else {
6050 return one->equals(two) && TypePtr::eq(t);
6051 }
6052 }
6053
6054 //------------------------------hash-------------------------------------------
6055 // Type-specific hashing function.
6056 uint TypeMetadataPtr::hash(void) const {
6057 return
6058 (metadata() ? metadata()->hash() : 0) +
6059 TypePtr::hash();
6060 }
6061
6062 //------------------------------singleton--------------------------------------
6063 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6064 // constants
6065 bool TypeMetadataPtr::singleton(void) const {
6066 // detune optimizer to not generate constant metadata + constant offset as a constant!
6067 // TopPTR, Null, AnyNull, Constant are all singletons
6068 return (offset() == 0) && !below_centerline(_ptr);
6069 }
6070
6071 //------------------------------add_offset-------------------------------------
6072 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6073 return make( _ptr, _metadata, xadd_offset(offset));
6074 }
6075
6076 //-----------------------------filter------------------------------------------
6077 // Do not allow interface-vs.-noninterface joins to collapse to top.
6078 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6079 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6080 if (ft == nullptr || ft->empty())
6081 return Type::TOP; // Canonical empty value
6082 return ft;
6083 }
6084
6085 //------------------------------get_con----------------------------------------
6086 intptr_t TypeMetadataPtr::get_con() const {
6087 assert( _ptr == Null || _ptr == Constant, "" );
6088 assert(offset() >= 0, "");
6089
6090 if (offset() != 0) {
6091 // After being ported to the compiler interface, the compiler no longer
6092 // directly manipulates the addresses of oops. Rather, it only has a pointer
6093 // to a handle at compile time. This handle is embedded in the generated
6094 // code and dereferenced at the time the nmethod is made. Until that time,
6095 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6096 // have access to the addresses!). This does not seem to currently happen,
6097 // but this assertion here is to help prevent its occurrence.
6098 tty->print_cr("Found oop constant with non-zero offset");
6099 ShouldNotReachHere();
6100 }
6101
6102 return (intptr_t)metadata()->constant_encoding();
6103 }
6104
6105 //------------------------------cast_to_ptr_type-------------------------------
6106 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6107 if( ptr == _ptr ) return this;
6108 return make(ptr, metadata(), _offset);
6109 }
6110
6124 case HalfFloatBot:
6125 case FloatTop:
6126 case FloatCon:
6127 case FloatBot:
6128 case DoubleTop:
6129 case DoubleCon:
6130 case DoubleBot:
6131 case NarrowOop:
6132 case NarrowKlass:
6133 case Bottom: // Ye Olde Default
6134 return Type::BOTTOM;
6135 case Top:
6136 return this;
6137
6138 default: // All else is a mistake
6139 typerr(t);
6140
6141 case AnyPtr: {
6142 // Found an AnyPtr type vs self-OopPtr type
6143 const TypePtr *tp = t->is_ptr();
6144 Offset offset = meet_offset(tp->offset());
6145 PTR ptr = meet_ptr(tp->ptr());
6146 switch (tp->ptr()) {
6147 case Null:
6148 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6149 // else fall through:
6150 case TopPTR:
6151 case AnyNull: {
6152 return make(ptr, _metadata, offset);
6153 }
6154 case BotPTR:
6155 case NotNull:
6156 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6157 default: typerr(t);
6158 }
6159 }
6160
6161 case RawPtr:
6162 case KlassPtr:
6163 case InstKlassPtr:
6164 case AryKlassPtr:
6165 case OopPtr:
6166 case InstPtr:
6167 case AryPtr:
6168 return TypePtr::BOTTOM; // Oop meet raw is not well defined
6169
6170 case MetadataPtr: {
6171 const TypeMetadataPtr *tp = t->is_metadataptr();
6172 Offset offset = meet_offset(tp->offset());
6173 PTR tptr = tp->ptr();
6174 PTR ptr = meet_ptr(tptr);
6175 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6176 if (tptr == TopPTR || _ptr == TopPTR ||
6177 metadata()->equals(tp->metadata())) {
6178 return make(ptr, md, offset);
6179 }
6180 // metadata is different
6181 if( ptr == Constant ) { // Cannot be equal constants, so...
6182 if( tptr == Constant && _ptr != Constant) return t;
6183 if( _ptr == Constant && tptr != Constant) return this;
6184 ptr = NotNull; // Fall down in lattice
6185 }
6186 return make(ptr, nullptr, offset);
6187 break;
6188 }
6189 } // End of switch
6190 return this; // Return the double constant
6191 }
6192
6196 const Type *TypeMetadataPtr::xdual() const {
6197 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6198 }
6199
6200 //------------------------------dump2------------------------------------------
6201 #ifndef PRODUCT
6202 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6203 st->print("metadataptr:%s", ptr_msg[_ptr]);
6204 if (metadata() != nullptr) {
6205 st->print(":" INTPTR_FORMAT, p2i(metadata()));
6206 }
6207 dump_offset(st);
6208 }
6209 #endif
6210
6211
6212 //=============================================================================
6213 // Convenience common pre-built type.
6214 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6215
6216 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6217 TypePtr(MetadataPtr, ptr, offset, relocInfo::metadata_type), _metadata(metadata) {
6218 }
6219
6220 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6221 return make(Constant, m, Offset(0));
6222 }
6223 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6224 return make(Constant, m, Offset(0));
6225 }
6226
6227 //------------------------------make-------------------------------------------
6228 // Create a meta data constant
6229 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6230 assert(m == nullptr || !m->is_klass(), "wrong type");
6231 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6232 }
6233
6234
6235 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6236 const Type* elem = _ary->_elem;
6237 bool xk = klass_is_exact();
6238 bool is_refined = false;
6239 if (elem->make_oopptr() != nullptr) {
6240 is_refined = true;
6241 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6242 if (elem->isa_aryklassptr()) {
6243 const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6244 if (elem_klass->is_refined_type()) {
6245 elem = elem_klass->cast_to_non_refined();
6246 }
6247 } else {
6248 const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6249 if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6250 !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6251 xk = true;
6252 }
6253 }
6254 }
6255 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined);
6256 }
6257
6258 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6259 if (klass->is_instance_klass()) {
6260 return TypeInstKlassPtr::make(klass, interface_handling);
6261 }
6262 return TypeAryKlassPtr::make(klass, interface_handling);
6263 }
6264
6265 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6266 : TypePtr(t, ptr, offset, relocInfo::metadata_type), _klass(klass), _interfaces(interfaces) {
6267 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6268 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6269 }
6270
6271 // Is there a single ciKlass* that can represent that type?
6272 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6273 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6274 if (_interfaces->empty()) {
6275 return _klass;
6276 }
6277 if (_klass != ciEnv::current()->Object_klass()) {
6278 if (_interfaces->eq(_klass->as_instance_klass())) {
6279 return _klass;
6280 }
6281 return nullptr;
6282 }
6283 return _interfaces->exact_klass();
6284 }
6285
6286 //------------------------------eq---------------------------------------------
6287 // Structural equality check for Type representations
6288 bool TypeKlassPtr::eq(const Type *t) const {
6289 const TypeKlassPtr *p = t->is_klassptr();
6290 return
6291 _interfaces->eq(p->_interfaces) &&
6292 TypePtr::eq(p);
6293 }
6294
6295 //------------------------------hash-------------------------------------------
6296 // Type-specific hashing function.
6297 uint TypeKlassPtr::hash(void) const {
6298 return TypePtr::hash() + _interfaces->hash();
6299 }
6300
6301 //------------------------------singleton--------------------------------------
6302 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6303 // constants
6304 bool TypeKlassPtr::singleton(void) const {
6305 // detune optimizer to not generate constant klass + constant offset as a constant!
6306 // TopPTR, Null, AnyNull, Constant are all singletons
6307 return (offset() == 0) && !below_centerline(_ptr);
6308 }
6309
6310 // Do not allow interface-vs.-noninterface joins to collapse to top.
6311 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6312 // logic here mirrors the one from TypeOopPtr::filter. See comments
6313 // there.
6314 const Type* ft = join_helper(kills, include_speculative);
6315
6316 if (ft->empty()) {
6317 return Type::TOP; // Canonical empty value
6318 }
6319
6320 return ft;
6321 }
6322
6323 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6324 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6325 return _interfaces->union_with(other->_interfaces);
6326 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6327 return other->_interfaces;
6328 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6329 return _interfaces;
6330 }
6331 return _interfaces->intersection_with(other->_interfaces);
6332 }
6333
6334 //------------------------------get_con----------------------------------------
6335 intptr_t TypeKlassPtr::get_con() const {
6336 assert( _ptr == Null || _ptr == Constant, "" );
6337 assert( offset() >= 0, "" );
6338
6339 if (offset() != 0) {
6340 // After being ported to the compiler interface, the compiler no longer
6341 // directly manipulates the addresses of oops. Rather, it only has a pointer
6342 // to a handle at compile time. This handle is embedded in the generated
6343 // code and dereferenced at the time the nmethod is made. Until that time,
6344 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6345 // have access to the addresses!). This does not seem to currently happen,
6346 // but this assertion here is to help prevent its occurrence.
6347 tty->print_cr("Found oop constant with non-zero offset");
6348 ShouldNotReachHere();
6349 }
6350
6351 ciKlass* k = exact_klass();
6352
6353 return (intptr_t)k->constant_encoding();
6354 }
6355
6356 //=============================================================================
6357 // Convenience common pre-built types.
6358
6359 // Not-null object klass or below
6360 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6361 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6362
6363 bool TypeInstKlassPtr::eq(const Type *t) const {
6364 const TypeInstKlassPtr* p = t->is_instklassptr();
6365 return
6366 klass()->equals(p->klass()) &&
6367 _flat_in_array == p->_flat_in_array &&
6368 TypeKlassPtr::eq(p);
6369 }
6370
6371 uint TypeInstKlassPtr::hash() const {
6372 return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6373 }
6374
6375 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6376 if (flat_in_array == Uninitialized) {
6377 flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6378 }
6379 TypeInstKlassPtr *r =
6380 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6381
6382 return r;
6383 }
6384
6385 bool TypeInstKlassPtr::empty() const {
6386 if (_flat_in_array == TopFlat) {
6387 return true;
6388 }
6389 return TypeKlassPtr::empty();
6390 }
6391
6392 //------------------------------add_offset-------------------------------------
6393 // Access internals of klass object
6394 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6395 return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6396 }
6397
6398 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6399 return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6400 }
6401
6402 //------------------------------cast_to_ptr_type-------------------------------
6403 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6404 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6405 if( ptr == _ptr ) return this;
6406 return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6407 }
6408
6409
6410 bool TypeInstKlassPtr::must_be_exact() const {
6411 if (!_klass->is_loaded()) return false;
6412 ciInstanceKlass* ik = _klass->as_instance_klass();
6413 if (ik->is_final()) return true; // cannot clear xk
6414 return false;
6415 }
6416
6417 //-----------------------------cast_to_exactness-------------------------------
6418 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6419 if (klass_is_exact == (_ptr == Constant)) return this;
6420 if (must_be_exact()) return this;
6421 ciKlass* k = klass();
6422 FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6423 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6424 }
6425
6426
6427 //-----------------------------as_instance_type--------------------------------
6428 // Corresponding type for an instance of the given class.
6429 // It will be NotNull, and exact if and only if the klass type is exact.
6430 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6431 ciKlass* k = klass();
6432 bool xk = klass_is_exact();
6433 Compile* C = Compile::current();
6434 Dependencies* deps = C->dependencies();
6435 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6436 // Element is an instance
6437 bool klass_is_exact = false;
6438 const TypeInterfaces* interfaces = _interfaces;
6439 ciInstanceKlass* ik = k->as_instance_klass();
6440 if (k->is_loaded()) {
6441 // Try to set klass_is_exact.
6442 klass_is_exact = ik->is_final();
6443 if (!klass_is_exact && klass_change
6444 && deps != nullptr && UseUniqueSubclasses) {
6445 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6446 if (sub != nullptr) {
6447 if (_interfaces->eq(sub)) {
6448 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6449 k = ik = sub;
6450 xk = sub->is_final();
6451 }
6452 }
6453 }
6454 }
6455
6456 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6457 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6458 }
6459
6460 //------------------------------xmeet------------------------------------------
6461 // Compute the MEET of two types, return a new Type object.
6462 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6463 // Perform a fast test for common case; meeting the same types together.
6464 if( this == t ) return this; // Meeting same type-rep?
6465
6466 // Current "this->_base" is Pointer
6467 switch (t->base()) { // switch on original type
6468
6469 case Int: // Mixing ints & oops happens when javac
6470 case Long: // reuses local variables
6471 case HalfFloatTop:
6472 case HalfFloatCon:
6473 case HalfFloatBot:
6474 case FloatTop:
6475 case FloatCon:
6476 case FloatBot:
6477 case DoubleTop:
6478 case DoubleCon:
6479 case DoubleBot:
6480 case NarrowOop:
6481 case NarrowKlass:
6482 case Bottom: // Ye Olde Default
6483 return Type::BOTTOM;
6484 case Top:
6485 return this;
6486
6487 default: // All else is a mistake
6488 typerr(t);
6489
6490 case AnyPtr: { // Meeting to AnyPtrs
6491 // Found an AnyPtr type vs self-KlassPtr type
6492 const TypePtr *tp = t->is_ptr();
6493 Offset offset = meet_offset(tp->offset());
6494 PTR ptr = meet_ptr(tp->ptr());
6495 switch (tp->ptr()) {
6496 case TopPTR:
6497 return this;
6498 case Null:
6499 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6500 case AnyNull:
6501 return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6502 case BotPTR:
6503 case NotNull:
6504 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6505 default: typerr(t);
6506 }
6507 }
6508
6509 case RawPtr:
6510 case MetadataPtr:
6511 case OopPtr:
6512 case AryPtr: // Meet with AryPtr
6513 case InstPtr: // Meet with InstPtr
6514 return TypePtr::BOTTOM;
6515
6516 //
6517 // A-top }
6518 // / | \ } Tops
6519 // B-top A-any C-top }
6520 // | / | \ | } Any-nulls
6521 // B-any | C-any }
6522 // | | |
6523 // B-con A-con C-con } constants; not comparable across classes
6524 // | | |
6525 // B-not | C-not }
6526 // | \ | / | } not-nulls
6527 // B-bot A-not C-bot }
6528 // \ | / } Bottoms
6529 // A-bot }
6530 //
6531
6532 case InstKlassPtr: { // Meet two KlassPtr types
6533 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6534 Offset off = meet_offset(tkls->offset());
6535 PTR ptr = meet_ptr(tkls->ptr());
6536 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6537
6538 ciKlass* res_klass = nullptr;
6539 bool res_xk = false;
6540 const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6541 switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6542 case UNLOADED:
6543 ShouldNotReachHere();
6544 case SUBTYPE:
6545 case NOT_SUBTYPE:
6546 case LCA:
6547 case QUICK: {
6548 assert(res_xk == (ptr == Constant), "");
6549 const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6550 return res;
6551 }
6552 default:
6553 ShouldNotReachHere();
6554 }
6555 } // End of case KlassPtr
6556 case AryKlassPtr: { // All arrays inherit from Object class
6557 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6558 Offset offset = meet_offset(tp->offset());
6559 PTR ptr = meet_ptr(tp->ptr());
6560 const TypeInterfaces* interfaces = meet_interfaces(tp);
6561 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6562 const TypeInterfaces* this_interfaces = _interfaces;
6563
6564 switch (ptr) {
6565 case TopPTR:
6566 case AnyNull: // Fall 'down' to dual of object klass
6567 // For instances when a subclass meets a superclass we fall
6568 // below the centerline when the superclass is exact. We need to
6569 // do the same here.
6570 //
6571 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6572 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6573 !klass_is_exact() && !is_not_flat_in_array()) {
6574 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6575 } else {
6576 // cannot subclass, so the meet has to fall badly below the centerline
6577 ptr = NotNull;
6578 interfaces = _interfaces->intersection_with(tp->_interfaces);
6579 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6580 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6581 }
6582 case Constant:
6583 case NotNull:
6584 case BotPTR: { // Fall down to object klass
6585 // LCA is object_klass, but if we subclass from the top we can do better
6586 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6587 // If 'this' (InstPtr) is above the centerline and it is Object class
6588 // then we can subclass in the Java class hierarchy.
6589 // For instances when a subclass meets a superclass we fall
6590 // below the centerline when the superclass is exact. We need
6591 // to do the same here.
6592 //
6593 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6594 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6595 !klass_is_exact() && !is_not_flat_in_array()) {
6596 // that is, tp's array type is a subtype of my klass
6597 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6598 }
6599 }
6600 // The other case cannot happen, since I cannot be a subtype of an array.
6601 // The meet falls down to Object class below centerline.
6602 if( ptr == Constant )
6603 ptr = NotNull;
6604 interfaces = this_interfaces->intersection_with(tp_interfaces);
6605 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6606 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6607 }
6608 default: typerr(t);
6609 }
6610 }
6611
6612 } // End of switch
6613 return this; // Return the double constant
6614 }
6615
6616 //------------------------------xdual------------------------------------------
6617 // Dual: compute field-by-field dual
6618 const Type* TypeInstKlassPtr::xdual() const {
6619 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6620 }
6621
6622 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) {
6623 static_assert(std::is_base_of<T2, T1>::value, "");
6624 if (!this_one->is_loaded() || !other->is_loaded()) {
6625 return false;
6626 }
6627 if (!this_one->is_instance_type(other)) {
6628 return false;
6629 }
6630
6631 if (!other_exact) {
6632 return false;
6633 }
6634
6635 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6636 return true;
6637 }
6638
6639 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6695 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6696 }
6697
6698 return true;
6699 }
6700
6701 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6702 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6703 }
6704
6705 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6706 if (!UseUniqueSubclasses) {
6707 return this;
6708 }
6709 ciKlass* k = klass();
6710 Compile* C = Compile::current();
6711 Dependencies* deps = C->dependencies();
6712 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6713 if (k->is_loaded()) {
6714 ciInstanceKlass* ik = k->as_instance_klass();
6715 if (deps != nullptr) {
6716 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6717 if (sub != nullptr) {
6718 bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6719 const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6720 if (_interfaces->is_subset(sub)) {
6721 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6722 return improved;
6723 }
6724 }
6725 }
6726 }
6727 return this;
6728 }
6729
6730 bool TypeInstKlassPtr::can_be_inline_array() const {
6731 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6732 }
6733
6734 #ifndef PRODUCT
6735 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6736 st->print("instklassptr:");
6737 klass()->print_name_on(st);
6738 _interfaces->dump(st);
6739 st->print(":%s", ptr_msg[_ptr]);
6740 dump_offset(st);
6741 dump_flat_in_array(_flat_in_array, st);
6742 }
6743 #endif // PRODUCT
6744
6745 bool TypeAryKlassPtr::can_be_inline_array() const {
6746 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6747 }
6748
6749 bool TypeInstPtr::can_be_inline_array() const {
6750 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6751 }
6752
6753 bool TypeAryPtr::can_be_inline_array() const {
6754 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6755 }
6756
6757 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6758 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6759 }
6760
6761 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type) {
6762 const Type* etype;
6763 if (k->is_obj_array_klass()) {
6764 // Element is an object array. Recursively call ourself.
6765 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6766 etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6767 k = nullptr;
6768 } else if (k->is_type_array_klass()) {
6769 // Element is an typeArray
6770 etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6771 } else {
6772 ShouldNotReachHere();
6773 }
6774
6775 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6776 }
6777
6778 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6779 ciArrayKlass* k = klass->as_array_klass();
6780 if (k->is_refined()) {
6781 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6782 k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6783 } else {
6784 // Use the default combination to canonicalize all non-refined klass pointers
6785 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6786 }
6787 }
6788
6789 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6790 assert(is_refined_type(), "must be a refined type");
6791 PTR ptr = _ptr;
6792 // There can be multiple refined array types corresponding to a single unrefined type
6793 if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6794 ptr = Constant;
6795 }
6796 return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6797 }
6798
6799 // Get the (non-)refined array klass ptr
6800 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6801 if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6802 return this;
6803 }
6804 ciArrayKlass* k = exact_klass()->as_array_klass();
6805 k = ciObjArrayKlass::make(k->element_klass(), refined);
6806 return make(k, trust_interfaces);
6807 }
6808
6809 //------------------------------eq---------------------------------------------
6810 // Structural equality check for Type representations
6811 bool TypeAryKlassPtr::eq(const Type *t) const {
6812 const TypeAryKlassPtr *p = t->is_aryklassptr();
6813 return
6814 _elem == p->_elem && // Check array
6815 _flat == p->_flat &&
6816 _not_flat == p->_not_flat &&
6817 _null_free == p->_null_free &&
6818 _not_null_free == p->_not_null_free &&
6819 _atomic == p->_atomic &&
6820 _refined_type == p->_refined_type &&
6821 TypeKlassPtr::eq(p); // Check sub-parts
6822 }
6823
6824 //------------------------------hash-------------------------------------------
6825 // Type-specific hashing function.
6826 uint TypeAryKlassPtr::hash(void) const {
6827 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6828 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6829 }
6830
6831 //----------------------compute_klass------------------------------------------
6832 // Compute the defining klass for this class
6833 ciKlass* TypeAryPtr::compute_klass() const {
6834 // Compute _klass based on element type.
6835 ciKlass* k_ary = nullptr;
6836 const TypeInstPtr *tinst;
6837 const TypeAryPtr *tary;
6838 const Type* el = elem();
6839 if (el->isa_narrowoop()) {
6840 el = el->make_ptr();
6841 }
6842
6843 // Get element klass
6844 if ((tinst = el->isa_instptr()) != nullptr) {
6845 // Leave k_ary at nullptr.
6846 } else if ((tary = el->isa_aryptr()) != nullptr) {
6847 // Leave k_ary at nullptr.
6848 } else if ((el->base() == Type::Top) ||
6849 (el->base() == Type::Bottom)) {
6850 // element type of Bottom occurs from meet of basic type
6851 // and object; Top occurs when doing join on Bottom.
6852 // Leave k_ary at null.
6853 } else {
6854 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6855 // Compute array klass directly from basic type
6856 k_ary = ciTypeArrayKlass::make(el->basic_type());
6857 }
6858 return k_ary;
6859 }
6860
6861 //------------------------------klass------------------------------------------
6862 // Return the defining klass for this class
6863 ciKlass* TypeAryPtr::klass() const {
6864 if( _klass ) return _klass; // Return cached value, if possible
6865
6866 // Oops, need to compute _klass and cache it
6867 ciKlass* k_ary = compute_klass();
6875 // type TypeAryPtr::OOPS. This Type is shared between all
6876 // active compilations. However, the ciKlass which represents
6877 // this Type is *not* shared between compilations, so caching
6878 // this value would result in fetching a dangling pointer.
6879 //
6880 // Recomputing the underlying ciKlass for each request is
6881 // a bit less efficient than caching, but calls to
6882 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6883 ((TypeAryPtr*)this)->_klass = k_ary;
6884 }
6885 return k_ary;
6886 }
6887
6888 // Is there a single ciKlass* that can represent that type?
6889 ciKlass* TypeAryPtr::exact_klass_helper() const {
6890 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6891 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6892 if (k == nullptr) {
6893 return nullptr;
6894 }
6895 if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6896 // We have no mechanism to create an array of refined arrays
6897 k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6898 }
6899 if (klass_is_exact()) {
6900 return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6901 } else {
6902 // We may reach here if called recursively, must be an unrefined type then
6903 return ciObjArrayKlass::make(k, false);
6904 }
6905 }
6906
6907 return klass();
6908 }
6909
6910 const Type* TypeAryPtr::base_element_type(int& dims) const {
6911 const Type* elem = this->elem();
6912 dims = 1;
6913 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6914 elem = elem->make_ptr()->is_aryptr()->elem();
6915 dims++;
6916 }
6917 return elem;
6918 }
6919
6920 //------------------------------add_offset-------------------------------------
6921 // Access internals of klass object
6922 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6923 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6924 }
6925
6926 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6927 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6928 }
6929
6930 //------------------------------cast_to_ptr_type-------------------------------
6931 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6932 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6933 if (ptr == _ptr) return this;
6934 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6935 }
6936
6937 bool TypeAryKlassPtr::must_be_exact() const {
6938 assert(klass_is_exact(), "precondition");
6939 if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6940 return false;
6941 }
6942 const TypeKlassPtr* elem = _elem->isa_klassptr();
6943 if (elem == nullptr) {
6944 // primitive arrays
6945 return true;
6946 }
6947
6948 // refined types are final
6949 return _refined_type;
6950 }
6951
6952 //-----------------------------cast_to_exactness-------------------------------
6953 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6954 if (klass_is_exact == this->klass_is_exact()) {
6955 return this;
6956 }
6957 if (!klass_is_exact && must_be_exact()) {
6958 return this;
6959 }
6960 const Type* elem = this->elem();
6961 if (elem->isa_klassptr() && !klass_is_exact) {
6962 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6963 }
6964
6965 if (klass_is_exact) {
6966 // cast_to_exactness(true) really means get the LCA of all values represented by this
6967 // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6968 return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6969 } else {
6970 // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6971 // this value
6972 bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6973 bool not_flat = !UseArrayFlattening || not_inline ||
6974 (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6975 bool not_null_free = not_inline;
6976 bool atomic = not_flat;
6977 return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6978 }
6979 }
6980
6981 //-----------------------------as_instance_type--------------------------------
6982 // Corresponding type for an instance of the given class.
6983 // It will be NotNull, and exact if and only if the klass type is exact.
6984 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6985 ciKlass* k = klass();
6986 bool xk = klass_is_exact();
6987 const Type* el = nullptr;
6988 if (elem()->isa_klassptr()) {
6989 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6990 k = nullptr;
6991 } else {
6992 el = elem();
6993 }
6994 bool flat, not_flat, not_null_free, atomic;
6995 if (_refined_type) {
6996 if (_null_free && el->isa_ptr()) {
6997 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6998 }
6999 flat = is_flat();
7000 not_flat = is_not_flat();
7001 not_null_free = is_not_null_free();
7002 atomic = is_atomic();
7003 } else { // Unrefined types aren't trustworthy! Let's not mistake their ignorance for information.
7004 // We can always have arrays of references. Flatness is not guaranteed.
7005 flat = false;
7006 // There are asserts that expect us to not be entirely naive about properties.
7007 // Only arrays of value classes can be null free. Otherwise, not_null_free == true. That is if the element type
7008 // is not an instance class, or this instance class cannot be an inline type, it's surely not null-restricted.
7009 not_null_free = !elem()->isa_instklassptr() || !elem()->is_instklassptr()->can_be_inline_type();
7010 bool array_can_be_flat;
7011 if (elem()->isa_instklassptr()) {
7012 FlatInArray elem_flat_in_array = elem()->is_instklassptr()->flat_in_array();
7013 array_can_be_flat = elem_flat_in_array == MaybeFlat || elem_flat_in_array == Flat;
7014 } else {
7015 array_can_be_flat = false;
7016 }
7017 not_flat = !array_can_be_flat;
7018 atomic = !array_can_be_flat;
7019 }
7020 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, flat, not_flat, not_null_free, atomic), k, xk, Offset(0));
7021 }
7022
7023
7024 //------------------------------xmeet------------------------------------------
7025 // Compute the MEET of two types, return a new Type object.
7026 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
7027 // Perform a fast test for common case; meeting the same types together.
7028 if( this == t ) return this; // Meeting same type-rep?
7029
7030 // Current "this->_base" is Pointer
7031 switch (t->base()) { // switch on original type
7032
7033 case Int: // Mixing ints & oops happens when javac
7034 case Long: // reuses local variables
7035 case HalfFloatTop:
7036 case HalfFloatCon:
7037 case HalfFloatBot:
7038 case FloatTop:
7039 case FloatCon:
7040 case FloatBot:
7041 case DoubleTop:
7042 case DoubleCon:
7043 case DoubleBot:
7044 case NarrowOop:
7045 case NarrowKlass:
7046 case Bottom: // Ye Olde Default
7047 return Type::BOTTOM;
7048 case Top:
7049 return this;
7050
7051 default: // All else is a mistake
7052 typerr(t);
7053
7054 case AnyPtr: { // Meeting to AnyPtrs
7055 // Found an AnyPtr type vs self-KlassPtr type
7056 const TypePtr *tp = t->is_ptr();
7057 Offset offset = meet_offset(tp->offset());
7058 PTR ptr = meet_ptr(tp->ptr());
7059 switch (tp->ptr()) {
7060 case TopPTR:
7061 return this;
7062 case Null:
7063 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7064 case AnyNull:
7065 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7066 case BotPTR:
7067 case NotNull:
7068 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7069 default: typerr(t);
7070 }
7071 }
7072
7073 case RawPtr:
7074 case MetadataPtr:
7075 case OopPtr:
7076 case AryPtr: // Meet with AryPtr
7077 case InstPtr: // Meet with InstPtr
7078 return TypePtr::BOTTOM;
7079
7080 //
7081 // A-top }
7082 // / | \ } Tops
7083 // B-top A-any C-top }
7084 // | / | \ | } Any-nulls
7085 // B-any | C-any }
7086 // | | |
7087 // B-con A-con C-con } constants; not comparable across classes
7088 // | | |
7089 // B-not | C-not }
7090 // | \ | / | } not-nulls
7091 // B-bot A-not C-bot }
7092 // \ | / } Bottoms
7093 // A-bot }
7094 //
7095
7096 case AryKlassPtr: { // Meet two KlassPtr types
7097 const TypeAryKlassPtr *tap = t->is_aryklassptr();
7098 Offset off = meet_offset(tap->offset());
7099 const Type* elem = _elem->meet(tap->_elem);
7100 PTR ptr = meet_ptr(tap->ptr());
7101 ciKlass* res_klass = nullptr;
7102 bool res_xk = false;
7103 bool res_flat = false;
7104 bool res_not_flat = false;
7105 bool res_not_null_free = false;
7106 bool res_atomic = false;
7107 MeetResult res = meet_aryptr(ptr, elem, this, tap,
7108 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
7109 assert(res_xk == (ptr == Constant), "");
7110 bool flat = meet_flat(tap->_flat);
7111 bool null_free = meet_null_free(tap->_null_free);
7112 bool atomic = meet_atomic(tap->_atomic);
7113 bool refined_type = _refined_type && tap->_refined_type;
7114 if (res == NOT_SUBTYPE) {
7115 flat = false;
7116 null_free = false;
7117 atomic = false;
7118 refined_type = false;
7119 } else if (res == SUBTYPE) {
7120 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7121 flat = _flat;
7122 null_free = _null_free;
7123 atomic = _atomic;
7124 refined_type = _refined_type;
7125 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7126 flat = tap->_flat;
7127 null_free = tap->_null_free;
7128 atomic = tap->_atomic;
7129 refined_type = tap->_refined_type;
7130 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7131 flat = _flat || tap->_flat;
7132 null_free = _null_free || tap->_null_free;
7133 atomic = _atomic || tap->_atomic;
7134 refined_type = _refined_type || tap->_refined_type;
7135 } else if (res_xk && _refined_type != tap->_refined_type) {
7136 // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7137 // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7138 // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7139 ptr = PTR::NotNull;
7140 }
7141 }
7142 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7143 } // End of case KlassPtr
7144 case InstKlassPtr: {
7145 const TypeInstKlassPtr *tp = t->is_instklassptr();
7146 Offset offset = meet_offset(tp->offset());
7147 PTR ptr = meet_ptr(tp->ptr());
7148 const TypeInterfaces* interfaces = meet_interfaces(tp);
7149 const TypeInterfaces* tp_interfaces = tp->_interfaces;
7150 const TypeInterfaces* this_interfaces = _interfaces;
7151
7152 switch (ptr) {
7153 case TopPTR:
7154 case AnyNull: // Fall 'down' to dual of object klass
7155 // For instances when a subclass meets a superclass we fall
7156 // below the centerline when the superclass is exact. We need to
7157 // do the same here.
7158 //
7159 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7160 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7161 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7162 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7163 } else {
7164 // cannot subclass, so the meet has to fall badly below the centerline
7165 ptr = NotNull;
7166 interfaces = this_interfaces->intersection_with(tp->_interfaces);
7167 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7168 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7169 }
7170 case Constant:
7171 case NotNull:
7172 case BotPTR: { // Fall down to object klass
7173 // LCA is object_klass, but if we subclass from the top we can do better
7174 if (above_centerline(tp->ptr())) {
7175 // If 'tp' is above the centerline and it is Object class
7176 // then we can subclass in the Java class hierarchy.
7177 // For instances when a subclass meets a superclass we fall
7178 // below the centerline when the superclass is exact. We need
7179 // to do the same here.
7180 //
7181 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7182 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7183 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7184 // that is, my array type is a subtype of 'tp' klass
7185 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7186 }
7187 }
7188 // The other case cannot happen, since t cannot be a subtype of an array.
7189 // The meet falls down to Object class below centerline.
7190 if (ptr == Constant)
7191 ptr = NotNull;
7192 interfaces = this_interfaces->intersection_with(tp_interfaces);
7193 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7194 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7195 }
7196 default: typerr(t);
7197 }
7198 }
7199
7200 } // End of switch
7201 return this; // Return the double constant
7202 }
7203
7204 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) {
7205 static_assert(std::is_base_of<T2, T1>::value, "");
7206
7207 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7208 return true;
7209 }
7210
7211 int dummy;
7212 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7213
7214 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7215 return false;
7216 }
7217
7218 if (this_one->is_instance_type(other)) {
7219 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7220 other_exact;
7221 }
7222
7223 assert(this_one->is_array_type(other), "");
7224 const T1* other_ary = this_one->is_array_type(other);
7225 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7226 if (other_top_or_bottom) {
7227 return false;
7228 }
7229
7230 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7231 const TypePtr* this_elem = this_one->elem()->make_ptr();
7232 if (this_elem != nullptr && other_elem != nullptr) {
7233 if (other->is_null_free() && !this_one->is_null_free()) {
7234 return false; // A nullable array can't be a subtype of a null-free array
7235 }
7236 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7237 }
7238 if (this_elem == nullptr && other_elem == nullptr) {
7239 return this_one->klass()->is_subtype_of(other->klass());
7240 }
7241 return false;
7242 }
7243
7244 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7245 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7246 }
7247
7248 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7249 static_assert(std::is_base_of<T2, T1>::value, "");
7250
7251 int dummy;
7252 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7253
7254 if (!this_one->is_array_type(other) ||
7255 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7308 }
7309
7310 const TypePtr* this_elem = this_one->elem()->make_ptr();
7311 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7312 if (other_elem != nullptr && this_elem != nullptr) {
7313 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7314 }
7315 if (other_elem == nullptr && this_elem == nullptr) {
7316 return this_one->klass()->is_subtype_of(other->klass());
7317 }
7318 return false;
7319 }
7320
7321 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7322 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7323 }
7324
7325 //------------------------------xdual------------------------------------------
7326 // Dual: compute field-by-field dual
7327 const Type *TypeAryKlassPtr::xdual() const {
7328 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _refined_type);
7329 }
7330
7331 // Is there a single ciKlass* that can represent that type?
7332 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7333 if (elem()->isa_klassptr()) {
7334 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7335 if (k == nullptr) {
7336 return nullptr;
7337 }
7338 assert(!k->is_array_klass() || !k->as_array_klass()->is_refined(), "no mechanism to create an array of refined arrays %s", k->name()->as_utf8());
7339 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7340 return k;
7341 }
7342
7343 return klass();
7344 }
7345
7346 ciKlass* TypeAryKlassPtr::klass() const {
7347 if (_klass != nullptr) {
7348 return _klass;
7349 }
7350 ciKlass* k = nullptr;
7351 if (elem()->isa_klassptr()) {
7352 // leave null
7353 } else if ((elem()->base() == Type::Top) ||
7354 (elem()->base() == Type::Bottom)) {
7355 } else {
7356 k = ciTypeArrayKlass::make(elem()->basic_type());
7357 ((TypeAryKlassPtr*)this)->_klass = k;
7358 }
7359 return k;
7360 }
7361
7362 //------------------------------dump2------------------------------------------
7363 // Dump Klass Type
7364 #ifndef PRODUCT
7365 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7366 st->print("aryklassptr:[");
7367 _elem->dump2(d, depth, st);
7368 _interfaces->dump(st);
7369 st->print(":%s", ptr_msg[_ptr]);
7370 if (_flat) st->print(":flat");
7371 if (_null_free) st->print(":null free");
7372 if (_atomic) st->print(":atomic");
7373 if (_refined_type) st->print(":refined_type");
7374 if (Verbose) {
7375 if (_not_flat) st->print(":not flat");
7376 if (_not_null_free) st->print(":nullable");
7377 }
7378 dump_offset(st);
7379 }
7380 #endif
7381
7382 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7383 const Type* elem = this->elem();
7384 dims = 1;
7385 while (elem->isa_aryklassptr()) {
7386 elem = elem->is_aryklassptr()->elem();
7387 dims++;
7388 }
7389 return elem;
7390 }
7391
7392 //=============================================================================
7393 // Convenience common pre-built types.
7394
7395 //------------------------------make-------------------------------------------
7396 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7397 const TypeTuple* range_sig, const TypeTuple* range_cc,
7398 bool scalarized_return) {
7399 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc, scalarized_return))->hashcons();
7400 }
7401
7402 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7403 return make(domain, domain, range, range);
7404 }
7405
7406 //------------------------------osr_domain-----------------------------
7407 const TypeTuple* osr_domain() {
7408 const Type **fields = TypeTuple::fields(2);
7409 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7410 return TypeTuple::make(TypeFunc::Parms+1, fields);
7411 }
7412
7413 // Build a TypeFunc with both the Java-signature view ('sig') and the actual calling-
7414 // convention view ('cc') of inline types. In the signature, an inline type is a single
7415 // oop slot. In the scalarized calling convention, it is expanded to its field
7416 // values (plus null marker and optional oop to the heap buffer).
7417 // The 'is_call' argument distinguishes between the return signature of a method at calls
7418 // vs. at compilation of that method because at calls we return an additional null marker field.
7419 // For OSR and mismatching calls, we fall back to the non-scalarized argument view.
7420 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_call, bool is_osr_compilation) {
7421 Compile* C = Compile::current();
7422 const TypeFunc* tf = nullptr;
7423 // Inline types are not passed/returned by reference, instead each field of
7424 // the inline type is passed/returned as an argument. We maintain two views of
7425 // the argument/return list here: one based on the signature (with an inline
7426 // type argument/return as a single slot), one based on the actual calling
7427 // convention (with an inline type argument/return as a list of its fields).
7428 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7429 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7430 if (is_call && method->mismatch()) {
7431 has_scalar_args = false;
7432 }
7433 ciSignature* sig = method->signature();
7434 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7435 // Don't cache on scalarized return because the range depends on 'is_call'
7436 if (!is_osr_compilation && !has_scalar_ret) {
7437 tf = C->last_tf(method); // check cache
7438 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7439 }
7440 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7441 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7442 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces);
7443 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true, is_call) : range_sig;
7444 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc, has_scalar_ret);
7445 if (!is_osr_compilation && !has_scalar_ret) {
7446 C->set_last_tf(method, tf); // fill cache
7447 }
7448 return tf;
7449 }
7450
7451 //------------------------------meet-------------------------------------------
7452 // Compute the MEET of two types. It returns a new Type object.
7453 const Type *TypeFunc::xmeet( const Type *t ) const {
7454 // Perform a fast test for common case; meeting the same types together.
7455 if( this == t ) return this; // Meeting same type-rep?
7456
7457 // Current "this->_base" is Func
7458 switch (t->base()) { // switch on original type
7459
7460 case Bottom: // Ye Olde Default
7461 return t;
7462
7463 default: // All else is a mistake
7464 typerr(t);
7465
7466 case Top:
7467 break;
7468 }
7469 return this; // Return the double constant
7470 }
7471
7472 //------------------------------xdual------------------------------------------
7473 // Dual: compute field-by-field dual
7474 const Type *TypeFunc::xdual() const {
7475 return this;
7476 }
7477
7478 //------------------------------eq---------------------------------------------
7479 // Structural equality check for Type representations
7480 bool TypeFunc::eq( const Type *t ) const {
7481 const TypeFunc *a = (const TypeFunc*)t;
7482 return _domain_sig == a->_domain_sig &&
7483 _domain_cc == a->_domain_cc &&
7484 _range_sig == a->_range_sig &&
7485 _range_cc == a->_range_cc &&
7486 _scalarized_return == a->_scalarized_return;
7487 }
7488
7489 //------------------------------hash-------------------------------------------
7490 // Type-specific hashing function.
7491 uint TypeFunc::hash(void) const {
7492 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc + (uint)(intptr_t)_scalarized_return;
7493 }
7494
7495 //------------------------------dump2------------------------------------------
7496 // Dump Function Type
7497 #ifndef PRODUCT
7498 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7499 if( _range_sig->cnt() <= Parms )
7500 st->print("void");
7501 else {
7502 uint i;
7503 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7504 _range_sig->field_at(i)->dump2(d,depth,st);
7505 st->print("/");
7506 }
7507 _range_sig->field_at(i)->dump2(d,depth,st);
7508 }
7509 st->print(" ");
7510 st->print("( ");
7511 if( !depth || d[this] ) { // Check for recursive dump
7512 st->print("...)");
7513 return;
7514 }
7515 d.Insert((void*)this,(void*)this); // Stop recursion
7516 if (Parms < _domain_sig->cnt())
7517 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7518 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7519 st->print(", ");
7520 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7521 }
7522 st->print(" )");
7523 }
7524 #endif
7525
7526 //------------------------------singleton--------------------------------------
7527 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7528 // constants (Ldi nodes). Singletons are integer, float or double constants
7529 // or a single symbol.
7530 bool TypeFunc::singleton(void) const {
7531 return false; // Never a singleton
7532 }
7533
7534 bool TypeFunc::empty(void) const {
7535 return false; // Never empty
7536 }
7537
7538
7539 BasicType TypeFunc::return_type() const{
7540 if (range_sig()->cnt() == TypeFunc::Parms) {
7541 return T_VOID;
7542 }
7543 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7544 }
|