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 8387653 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 8387653 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()->maybe_flat_in_array()) {
3230 return MaybeFlat;
3231 }
3232 return NotFlat;
3233 }
3234 // It's not an inline class, but can still be, so we don't know.
3235 return MaybeFlat;
3236 }
3237
3238 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3239 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3240 FlatInArray old_flat_in_array) {
3241 // It is tempting to add verification code that "NotFlat == no value class" and "Flat == value class".
3242 // However, with type speculation, we could get contradicting flat in array properties that propagate through the
3243 // graph. We could try to stop the introduction of contradicting speculative types in terms of their flat in array
3244 // property. But this is hard because it is sometimes only recognized further down in the graph. Thus, we let an
3245 // inconsistent flat in array property propagating through the graph. This could lead to fold an actual live path
3246 // away. But in this case, the speculated type is wrong and we would trap earlier.
3247 if (old_flat_in_array == MaybeFlat) {
3248 return compute_flat_in_array(instance_klass, is_exact);
3249 }
3250 return old_flat_in_array;
3251 }
3252
3253 //------------------------------dump2------------------------------------------
3254 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3255 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3256 };
3257
3258 #ifndef PRODUCT
3259 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3260 st->print("ptr:%s", ptr_msg[_ptr]);
3261 dump_offset(st);
3262 dump_inline_depth(st);
3263 dump_speculative(st);
3264 }
3265
3266 void TypePtr::dump_offset(outputStream* st) const {
3267 _offset.dump2(st);
3268 }
3269
3270 /**
3271 *dump the speculative part of the type
3272 */
3273 void TypePtr::dump_speculative(outputStream *st) const {
3274 if (_speculative != nullptr) {
3275 st->print(" (speculative=");
3276 _speculative->dump_on(st);
3277 st->print(")");
3278 }
3279 }
3280
3281 /**
3282 *dump the inline depth of the type
3283 */
3284 void TypePtr::dump_inline_depth(outputStream *st) const {
3285 if (_inline_depth != InlineDepthBottom) {
3286 if (_inline_depth == InlineDepthTop) {
3287 st->print(" (inline_depth=InlineDepthTop)");
3288 } else {
3289 st->print(" (inline_depth=%d)", _inline_depth);
3290 }
3291 }
3292 }
3293
3294 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3295 switch (flat_in_array) {
3296 case MaybeFlat:
3297 case NotFlat:
3298 if (!Verbose) {
3299 break;
3300 }
3301 case TopFlat:
3302 case Flat:
3303 st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3304 break;
3305 default:
3306 ShouldNotReachHere();
3307 }
3308 }
3309 #endif
3310
3311 //------------------------------singleton--------------------------------------
3312 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3313 // constants
3314 bool TypePtr::singleton(void) const {
3315 // TopPTR, Null, AnyNull, Constant are all singletons
3316 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3317 }
3318
3319 bool TypePtr::empty(void) const {
3320 return (_offset == Offset::top) || above_centerline(_ptr);
3321 }
3322
3323 //=============================================================================
3324 // Convenience common pre-built types.
3325 const TypeRawPtr *TypeRawPtr::BOTTOM;
3326 const TypeRawPtr *TypeRawPtr::NOTNULL;
3327
3328 //------------------------------make-------------------------------------------
3329 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3330 assert( ptr != Constant, "what is the constant?" );
3331 assert( ptr != Null, "Use TypePtr for null" );
3332 return (TypeRawPtr*)(new TypeRawPtr(ptr, nullptr, relocInfo::none))->hashcons();
3333 }
3334
3335 const TypeRawPtr* TypeRawPtr::make(address bits, relocInfo::relocType reloc) {
3336 assert(bits != nullptr, "Use TypePtr for null");
3337 return (TypeRawPtr*)(new TypeRawPtr(Constant, bits, reloc))->hashcons();
3338 }
3339
3340 //------------------------------cast_to_ptr_type-------------------------------
3719 #endif
3720
3721 // Can't be implemented because there's no way to know if the type is above or below the center line.
3722 const Type* TypeInterfaces::xmeet(const Type* t) const {
3723 ShouldNotReachHere();
3724 return Type::xmeet(t);
3725 }
3726
3727 bool TypeInterfaces::singleton(void) const {
3728 ShouldNotReachHere();
3729 return Type::singleton();
3730 }
3731
3732 bool TypeInterfaces::has_non_array_interface() const {
3733 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3734
3735 return !TypeAryPtr::_array_interfaces->contains(this);
3736 }
3737
3738 //------------------------------TypeOopPtr-------------------------------------
3739 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3740 int instance_id, const TypePtr* speculative, int inline_depth)
3741 : TypePtr(t, ptr, offset, relocInfo::oop_type, speculative, inline_depth),
3742 _const_oop(o), _klass(k),
3743 _interfaces(interfaces),
3744 _klass_is_exact(xk),
3745 _is_ptr_to_narrowoop(false),
3746 _is_ptr_to_narrowklass(false),
3747 _is_ptr_to_boxed_value(false),
3748 _is_ptr_to_strict_final_field(false),
3749 _instance_id(instance_id) {
3750 #ifdef ASSERT
3751 if (klass() != nullptr && klass()->is_loaded()) {
3752 interfaces->verify_is_loaded();
3753 }
3754 #endif
3755 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3756 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3757 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3758 _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3759 }
3760
3761 if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3762 this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3763 ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3764 if (field != nullptr && field->is_strict() && field->is_final()) {
3765 _is_ptr_to_strict_final_field = true;
3766 }
3767 }
3768
3769 #ifdef _LP64
3770 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3771 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3772 _is_ptr_to_narrowklass = true;
3773 } else if (klass() == nullptr) {
3774 // Array with unknown body type
3775 assert(this->isa_aryptr(), "only arrays without klass");
3776 _is_ptr_to_narrowoop = UseCompressedOops;
3777 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3778 if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3779 // Check if the field of the inline type array element contains oops
3780 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3781 int foffset = field_offset.get() + vk->payload_offset();
3782 BasicType field_bt;
3783 ciField* field = vk->get_field_by_offset(foffset, false);
3784 if (field != nullptr) {
3785 field_bt = field->layout_type();
3786 } else {
3787 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);
3788 field_bt = T_BOOLEAN;
3789 }
3790 _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3791 } else if (klass()->is_obj_array_klass()) {
3792 _is_ptr_to_narrowoop = true;
3793 }
3794 } else if (klass()->is_instance_klass()) {
3795 if (this->isa_klassptr()) {
3796 // Perm objects don't use compressed references
3797 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3798 // unsafe access
3799 _is_ptr_to_narrowoop = UseCompressedOops;
3800 } else {
3801 assert(this->isa_instptr(), "must be an instance ptr.");
3802 if (klass() == ciEnv::current()->Class_klass() &&
3803 (this->offset() == java_lang_Class::klass_offset() ||
3804 this->offset() == java_lang_Class::array_klass_offset())) {
3805 // Special hidden fields from the Class.
3806 assert(this->isa_instptr(), "must be an instance ptr.");
3807 _is_ptr_to_narrowoop = false;
3808 } else if (klass() == ciEnv::current()->Class_klass() &&
3809 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3810 // Static fields
3811 BasicType basic_elem_type = T_ILLEGAL;
3812 if (const_oop() != nullptr) {
3813 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3814 basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3815 }
3816 if (basic_elem_type != T_ILLEGAL) {
3817 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3818 } else {
3819 // unsafe access
3820 _is_ptr_to_narrowoop = UseCompressedOops;
3821 }
3822 } else {
3823 // Instance fields which contains a compressed oop references.
3824 ciInstanceKlass* ik = klass()->as_instance_klass();
3825 BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3826 if (basic_elem_type != T_ILLEGAL) {
3827 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3828 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3829 // Compile::find_alias_type() cast exactness on all types to verify
3830 // that it does not affect alias type.
3831 _is_ptr_to_narrowoop = UseCompressedOops;
3832 } else {
3833 // Type for the copy start in LibraryCallKit::inline_native_clone().
3834 _is_ptr_to_narrowoop = UseCompressedOops;
3835 }
3836 }
3837 }
3838 }
3839 }
3840 #endif // _LP64
3841 }
3842
3843 //------------------------------make-------------------------------------------
3844 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3845 const TypePtr* speculative, int inline_depth) {
3846 assert(ptr != Constant, "no constant generic pointers");
3847 ciKlass* k = Compile::current()->env()->Object_klass();
3848 bool xk = false;
3849 ciObject* o = nullptr;
3850 const TypeInterfaces* interfaces = TypeInterfaces::make();
3851 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3852 }
3853
3854
3855 //------------------------------cast_to_ptr_type-------------------------------
3856 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3857 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3858 if( ptr == _ptr ) return this;
3859 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3860 }
3861
3862 //-----------------------------cast_to_instance_id----------------------------
3863 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3864 // There are no instances of a general oop.
3865 // Return self unchanged.
3866 return this;
3867 }
3868
3869 //-----------------------------cast_to_exactness-------------------------------
3870 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3871 // There is no such thing as an exact general oop.
3872 // Return self unchanged.
3873 return this;
3874 }
3875
3876 //------------------------------as_klass_type----------------------------------
3877 // Return the klass type corresponding to this instance or array type.
3878 // It is the type that is loaded from an object of this type.
3879 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3880 ShouldNotReachHere();
3881 return nullptr;
3882 }
3883
3884 //------------------------------meet-------------------------------------------
3885 // Compute the MEET of two types. It returns a new Type object.
3886 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3887 // Perform a fast test for common case; meeting the same types together.
3888 if( this == t ) return this; // Meeting same type-rep?
3889
3890 // Current "this->_base" is OopPtr
3891 switch (t->base()) { // switch on original type
3892
3893 case Int: // Mixing ints & oops happens when javac
3894 case Long: // reuses local variables
3895 case HalfFloatTop:
3904 case NarrowOop:
3905 case NarrowKlass:
3906 case Bottom: // Ye Olde Default
3907 return Type::BOTTOM;
3908 case Top:
3909 return this;
3910
3911 default: // All else is a mistake
3912 typerr(t);
3913
3914 case RawPtr:
3915 case MetadataPtr:
3916 case KlassPtr:
3917 case InstKlassPtr:
3918 case AryKlassPtr:
3919 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3920
3921 case AnyPtr: {
3922 // Found an AnyPtr type vs self-OopPtr type
3923 const TypePtr *tp = t->is_ptr();
3924 Offset offset = meet_offset(tp->offset());
3925 PTR ptr = meet_ptr(tp->ptr());
3926 const TypePtr* speculative = xmeet_speculative(tp);
3927 int depth = meet_inline_depth(tp->inline_depth());
3928 switch (tp->ptr()) {
3929 case Null:
3930 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3931 // else fall through:
3932 case TopPTR:
3933 case AnyNull: {
3934 int instance_id = meet_instance_id(InstanceTop);
3935 return make(ptr, offset, instance_id, speculative, depth);
3936 }
3937 case BotPTR:
3938 case NotNull:
3939 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3940 default: typerr(t);
3941 }
3942 }
3943
3944 case OopPtr: { // Meeting to other OopPtrs
3946 int instance_id = meet_instance_id(tp->instance_id());
3947 const TypePtr* speculative = xmeet_speculative(tp);
3948 int depth = meet_inline_depth(tp->inline_depth());
3949 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3950 }
3951
3952 case InstPtr: // For these, flip the call around to cut down
3953 case AryPtr:
3954 return t->xmeet(this); // Call in reverse direction
3955
3956 } // End of switch
3957 return this; // Return the double constant
3958 }
3959
3960
3961 //------------------------------xdual------------------------------------------
3962 // Dual of a pure heap pointer. No relevant klass or oop information.
3963 const Type *TypeOopPtr::xdual() const {
3964 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3965 assert(const_oop() == nullptr, "no constants here");
3966 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());
3967 }
3968
3969 //--------------------------make_from_klass_common-----------------------------
3970 // Computes the element-type given a klass.
3971 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3972 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3973 Compile* C = Compile::current();
3974 Dependencies* deps = C->dependencies();
3975 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3976 // Element is an instance
3977 bool klass_is_exact = false;
3978 ciInstanceKlass* ik = klass->as_instance_klass();
3979 if (klass->is_loaded()) {
3980 // Try to set klass_is_exact.
3981 klass_is_exact = ik->is_final();
3982 if (!klass_is_exact && klass_change
3983 && deps != nullptr && UseUniqueSubclasses) {
3984 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3985 if (sub != nullptr) {
3986 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3987 klass = ik = sub;
3988 klass_is_exact = sub->is_final();
3989 }
3990 }
3991 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3992 !ik->is_interface() && !ik->has_subklass()) {
3993 // Add a dependence; if concrete subclass added we need to recompile
3994 deps->assert_leaf_type(ik);
3995 klass_is_exact = true;
3996 }
3997 }
3998 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3999 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
4000 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
4001 } else if (klass->is_obj_array_klass()) {
4002 // Element is an object or inline type array. Recursively call ourself.
4003 ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
4004 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
4005 bool xk = array_klass->is_loaded() && array_klass->is_refined();
4006
4007 // Determine null-free/flat properties
4008 bool flat;
4009 bool not_flat;
4010 bool not_null_free;
4011 bool atomic;
4012 if (xk) {
4013 flat = array_klass->is_flat_array_klass();
4014 not_flat = !flat;
4015 bool is_null_free = array_klass->is_elem_null_free();
4016 not_null_free = !is_null_free;
4017 atomic = array_klass->is_elem_atomic();
4018
4019 if (is_null_free) {
4020 etype = etype->join_speculative(NOTNULL)->is_oopptr();
4021 }
4022 } else {
4023 const TypeOopPtr* exact_etype = etype;
4024 if (etype->can_be_inline_type()) {
4025 // Use exact type if element can be an inline type
4026 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
4027 }
4028
4029 flat = false;
4030 bool not_inline = !exact_etype->can_be_inline_type();
4031 not_null_free = not_inline;
4032 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4033 atomic = not_flat;
4034 }
4035
4036 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
4037 // We used to pass NotNull in here, asserting that the sub-arrays
4038 // are all not-null. This is not true in generally, as code can
4039 // slam nullptrs down in the subarrays.
4040 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4041 return arr;
4042 } else if (klass->is_type_array_klass()) {
4043 // Element is an typeArray
4044 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4045 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4046 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4047 // We used to pass NotNull in here, asserting that the array pointer
4048 // is not-null. That was not true in general.
4049 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4050 return arr;
4051 } else {
4052 ShouldNotReachHere();
4053 return nullptr;
4054 }
4055 }
4056
4057 //------------------------------make_from_constant-----------------------------
4058 // Make a java pointer from an oop constant
4059 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4060 assert(!o->is_null_object(), "null object not yet handled here.");
4061
4062 const bool make_constant = require_constant || o->should_be_constant();
4063
4064 ciKlass* klass = o->klass();
4065 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4066 // Element is an instance or inline type
4067 if (make_constant) {
4068 return TypeInstPtr::make(o);
4069 } else {
4070 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4071 }
4072 } else if (klass->is_obj_array_klass()) {
4073 // Element is an object array. Recursively call ourself.
4074 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4075 bool is_flat = o->as_array()->is_flat();
4076 bool is_null_free = o->as_array()->is_null_free();
4077 if (is_null_free) {
4078 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4079 }
4080 bool is_atomic = o->as_array()->is_atomic();
4081 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4082 /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4083 // We used to pass NotNull in here, asserting that the sub-arrays
4084 // are all not-null. This is not true in generally, as code can
4085 // slam nulls down in the subarrays.
4086 if (make_constant) {
4087 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4088 } else {
4089 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4090 }
4091 } else if (klass->is_type_array_klass()) {
4092 // Element is an typeArray
4093 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4094 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4095 /* not_flat= */ true, /* not_null_free= */ true, true);
4096 // We used to pass NotNull in here, asserting that the array pointer
4097 // is not-null. That was not true in general.
4098 if (make_constant) {
4099 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4100 } else {
4101 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4102 }
4103 }
4104
4105 fatal("unhandled object type");
4106 return nullptr;
4107 }
4108
4109 //------------------------------get_con----------------------------------------
4110 intptr_t TypeOopPtr::get_con() const {
4111 assert( _ptr == Null || _ptr == Constant, "" );
4112 assert(offset() >= 0, "");
4113
4114 if (offset() != 0) {
4115 // After being ported to the compiler interface, the compiler no longer
4116 // directly manipulates the addresses of oops. Rather, it only has a pointer
4117 // to a handle at compile time. This handle is embedded in the generated
4118 // code and dereferenced at the time the nmethod is made. Until that time,
4119 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4120 // have access to the addresses!). This does not seem to currently happen,
4121 // but this assertion here is to help prevent its occurrence.
4122 tty->print_cr("Found oop constant with non-zero offset");
4123 ShouldNotReachHere();
4124 }
4125
4126 return (intptr_t)const_oop()->constant_encoding();
4127 }
4128
4129
4130 //-----------------------------filter------------------------------------------
4131 // Do not allow interface-vs.-noninterface joins to collapse to top.
4132 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4133
4134 const Type* ft = join_helper(kills, include_speculative);
4180 dump_speculative(st);
4181 }
4182
4183 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4184 if (_instance_id == InstanceTop) {
4185 st->print(",iid=top");
4186 } else if (_instance_id == InstanceBot) {
4187 st->print(",iid=bot");
4188 } else {
4189 st->print(",iid=%d", _instance_id);
4190 }
4191 }
4192 #endif
4193
4194 //------------------------------singleton--------------------------------------
4195 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4196 // constants
4197 bool TypeOopPtr::singleton(void) const {
4198 // detune optimizer to not generate constant oop + constant offset as a constant!
4199 // TopPTR, Null, AnyNull, Constant are all singletons
4200 return (offset() == 0) && !below_centerline(_ptr);
4201 }
4202
4203 //------------------------------add_offset-------------------------------------
4204 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4205 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4206 }
4207
4208 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4209 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4210 }
4211
4212 /**
4213 * Return same type without a speculative part
4214 */
4215 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4216 if (_speculative == nullptr) {
4217 return this;
4218 }
4219 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4220 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4221 }
4222
4223 /**
4224 * Return same type but drop speculative part if we know we won't use
4225 * it
4226 */
4227 const Type* TypeOopPtr::cleanup_speculative() const {
4228 // If the klass is exact and the ptr is not null then there's
4229 // nothing that the speculative type can help us with
4302 const TypeInstPtr *TypeInstPtr::BOTTOM;
4303 const TypeInstPtr *TypeInstPtr::MIRROR;
4304 const TypeInstPtr *TypeInstPtr::MARK;
4305 const TypeInstPtr *TypeInstPtr::KLASS;
4306
4307 // Is there a single ciKlass* that can represent that type?
4308 ciKlass* TypeInstPtr::exact_klass_helper() const {
4309 if (_interfaces->empty()) {
4310 return _klass;
4311 }
4312 if (_klass != ciEnv::current()->Object_klass()) {
4313 if (_interfaces->eq(_klass->as_instance_klass())) {
4314 return _klass;
4315 }
4316 return nullptr;
4317 }
4318 return _interfaces->exact_klass();
4319 }
4320
4321 //------------------------------TypeInstPtr-------------------------------------
4322 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4323 FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4324 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4325 _flat_in_array(flat_in_array) {
4326
4327 assert(flat_in_array != Uninitialized, "must be set now");
4328 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4329 assert(k != nullptr &&
4330 (k->is_loaded() || o == nullptr),
4331 "cannot have constants with non-loaded klass");
4332 };
4333
4334 //------------------------------make-------------------------------------------
4335 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4336 ciKlass* k,
4337 const TypeInterfaces* interfaces,
4338 bool xk,
4339 ciObject* o,
4340 Offset offset,
4341 FlatInArray flat_in_array,
4342 int instance_id,
4343 const TypePtr* speculative,
4344 int inline_depth) {
4345 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4346 // Either const_oop() is null or else ptr is Constant
4347 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4348 "constant pointers must have a value supplied" );
4349 // Ptr is never Null
4350 assert( ptr != Null, "null pointers are not typed" );
4351
4352 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4353 ciInstanceKlass* ik = k->as_instance_klass();
4354 if (ptr == Constant) {
4355 // Note: This case includes meta-object constants, such as methods.
4356 xk = true;
4357 } else if (k->is_loaded()) {
4358 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4359 assert(!ik->is_interface(), "no interface here");
4360 if (xk && ik->is_interface()) xk = false; // no exact interface
4361 }
4362
4363 if (flat_in_array == Uninitialized) {
4364 flat_in_array = compute_flat_in_array(ik, xk);
4365 }
4366 // Now hash this baby
4367 TypeInstPtr *result =
4368 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4369
4370 return result;
4371 }
4372
4373 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4374 if (k->is_instance_klass()) {
4375 if (k->is_loaded()) {
4376 if (k->is_interface() && interface_handling == ignore_interfaces) {
4377 assert(interface, "no interface expected");
4378 k = ciEnv::current()->Object_klass();
4379 const TypeInterfaces* interfaces = TypeInterfaces::make();
4380 return interfaces;
4381 }
4382 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4383 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4384 if (k->is_interface()) {
4385 assert(interface, "no interface expected");
4386 k = ciEnv::current()->Object_klass();
4387 } else {
4388 assert(klass, "no instance klass expected");
4391 }
4392 const TypeInterfaces* interfaces = TypeInterfaces::make();
4393 return interfaces;
4394 }
4395 assert(array, "no array expected");
4396 assert(k->is_array_klass(), "Not an array?");
4397 ciType* e = k->as_array_klass()->base_element_type();
4398 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4399 if (interface_handling == ignore_interfaces) {
4400 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4401 }
4402 }
4403 return TypeAryPtr::_array_interfaces;
4404 }
4405
4406 //------------------------------cast_to_ptr_type-------------------------------
4407 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4408 if( ptr == _ptr ) return this;
4409 // Reconstruct _sig info here since not a problem with later lazy
4410 // construction, _sig will show up on demand.
4411 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4412 }
4413
4414
4415 //-----------------------------cast_to_exactness-------------------------------
4416 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4417 if( klass_is_exact == _klass_is_exact ) return this;
4418 if (!_klass->is_loaded()) return this;
4419 ciInstanceKlass* ik = _klass->as_instance_klass();
4420 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4421 assert(!ik->is_interface(), "no interface here");
4422 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4423 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4424 }
4425
4426 //-----------------------------cast_to_instance_id----------------------------
4427 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4428 if( instance_id == _instance_id ) return this;
4429 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4430 }
4431
4432 //------------------------------xmeet_unloaded---------------------------------
4433 // Compute the MEET of two InstPtrs when at least one is unloaded.
4434 // Assume classes are different since called after check for same name/class-loader
4435 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4436 Offset off = meet_offset(tinst->offset());
4437 PTR ptr = meet_ptr(tinst->ptr());
4438 int instance_id = meet_instance_id(tinst->instance_id());
4439 const TypePtr* speculative = xmeet_speculative(tinst);
4440 int depth = meet_inline_depth(tinst->inline_depth());
4441
4442 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4443 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4444 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4445 //
4446 // Meet unloaded class with java/lang/Object
4447 //
4448 // Meet
4449 // | Unloaded Class
4450 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4451 // ===================================================================
4452 // TOP | ..........................Unloaded......................|
4453 // AnyNull | U-AN |................Unloaded......................|
4454 // Constant | ... O-NN .................................. | O-BOT |
4455 // NotNull | ... O-NN .................................. | O-BOT |
4456 // BOTTOM | ........................Object-BOTTOM ..................|
4457 //
4458 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4459 //
4460 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4461 else if (loaded->ptr() == TypePtr::AnyNull) {
4462 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4463 return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4464 speculative, depth);
4465 }
4466 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4467 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4468 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4469 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4470 }
4471 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4472
4473 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4474 }
4475
4476 // Both are unloaded, not the same class, not Object
4477 // Or meet unloaded with a different loaded class, not java/lang/Object
4478 if (ptr != TypePtr::BotPTR) {
4479 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4480 }
4481 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4482 }
4483
4484
4485 //------------------------------meet-------------------------------------------
4509 case Top:
4510 return this;
4511
4512 default: // All else is a mistake
4513 typerr(t);
4514
4515 case MetadataPtr:
4516 case KlassPtr:
4517 case InstKlassPtr:
4518 case AryKlassPtr:
4519 case RawPtr: return TypePtr::BOTTOM;
4520
4521 case AryPtr: { // All arrays inherit from Object class
4522 // Call in reverse direction to avoid duplication
4523 return t->is_aryptr()->xmeet_helper(this);
4524 }
4525
4526 case OopPtr: { // Meeting to OopPtrs
4527 // Found a OopPtr type vs self-InstPtr type
4528 const TypeOopPtr *tp = t->is_oopptr();
4529 Offset offset = meet_offset(tp->offset());
4530 PTR ptr = meet_ptr(tp->ptr());
4531 switch (tp->ptr()) {
4532 case TopPTR:
4533 case AnyNull: {
4534 int instance_id = meet_instance_id(InstanceTop);
4535 const TypePtr* speculative = xmeet_speculative(tp);
4536 int depth = meet_inline_depth(tp->inline_depth());
4537 return make(ptr, klass(), _interfaces, klass_is_exact(),
4538 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4539 }
4540 case NotNull:
4541 case BotPTR: {
4542 int instance_id = meet_instance_id(tp->instance_id());
4543 const TypePtr* speculative = xmeet_speculative(tp);
4544 int depth = meet_inline_depth(tp->inline_depth());
4545 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4546 }
4547 default: typerr(t);
4548 }
4549 }
4550
4551 case AnyPtr: { // Meeting to AnyPtrs
4552 // Found an AnyPtr type vs self-InstPtr type
4553 const TypePtr *tp = t->is_ptr();
4554 Offset offset = meet_offset(tp->offset());
4555 PTR ptr = meet_ptr(tp->ptr());
4556 int instance_id = meet_instance_id(InstanceTop);
4557 const TypePtr* speculative = xmeet_speculative(tp);
4558 int depth = meet_inline_depth(tp->inline_depth());
4559 switch (tp->ptr()) {
4560 case Null:
4561 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4562 // else fall through to AnyNull
4563 case TopPTR:
4564 case AnyNull: {
4565 return make(ptr, klass(), _interfaces, klass_is_exact(),
4566 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4567 }
4568 case NotNull:
4569 case BotPTR:
4570 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4571 default: typerr(t);
4572 }
4573 }
4574
4575 /*
4576 A-top }
4577 / | \ } Tops
4578 B-top A-any C-top }
4579 | / | \ | } Any-nulls
4580 B-any | C-any }
4581 | | |
4582 B-con A-con C-con } constants; not comparable across classes
4583 | | |
4584 B-not | C-not }
4585 | \ | / | } not-nulls
4586 B-bot A-not C-bot }
4587 \ | / } Bottoms
4588 A-bot }
4589 */
4590
4591 case InstPtr: { // Meeting 2 Oops?
4592 // Found an InstPtr sub-type vs self-InstPtr type
4593 const TypeInstPtr *tinst = t->is_instptr();
4594 Offset off = meet_offset(tinst->offset());
4595 PTR ptr = meet_ptr(tinst->ptr());
4596 int instance_id = meet_instance_id(tinst->instance_id());
4597 const TypePtr* speculative = xmeet_speculative(tinst);
4598 int depth = meet_inline_depth(tinst->inline_depth());
4599 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4600
4601 ciKlass* tinst_klass = tinst->klass();
4602 ciKlass* this_klass = klass();
4603
4604 ciKlass* res_klass = nullptr;
4605 bool res_xk = false;
4606 const Type* res;
4607 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4608
4609 if (kind == UNLOADED) {
4610 // One of these classes has not been loaded
4611 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4612 #ifndef PRODUCT
4613 if (PrintOpto && Verbose) {
4614 tty->print("meet of unloaded classes resulted in: ");
4615 unloaded_meet->dump();
4616 tty->cr();
4617 tty->print(" this == ");
4618 dump();
4619 tty->cr();
4620 tty->print(" tinst == ");
4621 tinst->dump();
4622 tty->cr();
4623 }
4624 #endif
4625 res = unloaded_meet;
4626 } else {
4627 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4628 if (kind == NOT_SUBTYPE && instance_id > 0) {
4629 instance_id = InstanceBot;
4630 } else if (kind == LCA) {
4631 instance_id = InstanceBot;
4632 }
4633 ciObject* o = nullptr; // Assume not constant when done
4634 ciObject* this_oop = const_oop();
4635 ciObject* tinst_oop = tinst->const_oop();
4636 if (ptr == Constant) {
4637 if (this_oop != nullptr && tinst_oop != nullptr &&
4638 this_oop->equals(tinst_oop))
4639 o = this_oop;
4640 else if (above_centerline(_ptr)) {
4641 assert(!tinst_klass->is_interface(), "");
4642 o = tinst_oop;
4643 } else if (above_centerline(tinst->_ptr)) {
4644 assert(!this_klass->is_interface(), "");
4645 o = this_oop;
4646 } else
4647 ptr = NotNull;
4648 }
4649 res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4650 }
4651
4652 return res;
4653
4654 } // End of case InstPtr
4655
4656 } // End of switch
4657 return this; // Return the double constant
4658 }
4659
4660 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4661 ciKlass*& res_klass, bool& res_xk) {
4662 ciKlass* this_klass = this_type->klass();
4663 ciKlass* other_klass = other_type->klass();
4664
4665 bool this_xk = this_type->klass_is_exact();
4666 bool other_xk = other_type->klass_is_exact();
4667 PTR this_ptr = this_type->ptr();
4668 PTR other_ptr = other_type->ptr();
4669 const TypeInterfaces* this_interfaces = this_type->interfaces();
4670 const TypeInterfaces* other_interfaces = other_type->interfaces();
4671 // Check for easy case; klasses are equal (and perhaps not loaded!)
4672 // If we have constants, then we created oops so classes are loaded
4673 // and we can handle the constants further down. This case handles
4674 // both-not-loaded or both-loaded classes
4675 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4676 res_klass = this_klass;
4677 res_xk = this_xk;
4678 return QUICK;
4679 }
4680
4681 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4682 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4683 return UNLOADED;
4684 }
4690 // If both are up and they do NOT subtype, "fall hard".
4691 // If both are down and they subtype, take the supertype class.
4692 // If both are down and they do NOT subtype, "fall hard".
4693 // Constants treated as down.
4694
4695 // Now, reorder the above list; observe that both-down+subtype is also
4696 // "fall hard"; "fall hard" becomes the default case:
4697 // If we split one up & one down AND they subtype, take the down man.
4698 // If both are up and they subtype, take the subtype class.
4699
4700 // If both are down and they subtype, "fall hard".
4701 // If both are down and they do NOT subtype, "fall hard".
4702 // If both are up and they do NOT subtype, "fall hard".
4703 // If we split one up & one down AND they do NOT subtype, "fall hard".
4704
4705 // If a proper subtype is exact, and we return it, we return it exactly.
4706 // If a proper supertype is exact, there can be no subtyping relationship!
4707 // If both types are equal to the subtype, exactness is and-ed below the
4708 // centerline and or-ed above it. (N.B. Constants are always exact.)
4709
4710 const T* subtype = nullptr;
4711 bool subtype_exact = false;
4712 if (this_type->is_same_java_type_as(other_type)) {
4713 // Same klass
4714 subtype = this_type;
4715 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4716 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4717 subtype = this_type; // Pick subtyping class
4718 subtype_exact = this_xk;
4719 } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4720 subtype = other_type; // Pick subtyping class
4721 subtype_exact = other_xk;
4722 }
4723
4724 if (subtype != nullptr) {
4725 if (above_centerline(ptr)) {
4726 // Both types are empty.
4727 this_type = other_type = subtype;
4728 this_xk = other_xk = subtype_exact;
4729 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4730 // this_type is empty while other_type is not. Take other_type.
4731 this_type = other_type;
4732 this_xk = other_xk;
4733 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4734 // other_type is empty while this_type is not. Take this_type.
4735 other_type = this_type; // this is down; keep down man
4736 } else {
4737 // this_type and other_type are both non-empty.
4738 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4739 }
4740 }
4741
4742 // Check for classes now being equal
4743 if (this_type->is_same_java_type_as(other_type)) {
4744 // If the klasses are equal, the constants may still differ. Fall to
4745 // NotNull if they do (neither constant is null; that is a special case
4746 // handled elsewhere).
4747 res_klass = this_type->klass();
4748 res_xk = this_xk;
4749 return SUBTYPE;
4750 } // Else classes are not equal
4751
4752 // Since klasses are different, we require a LCA in the Java
4753 // class hierarchy - which means we have to fall to at least NotNull.
4754 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4755 ptr = NotNull;
4756 }
4757
4758 interfaces = this_interfaces->intersection_with(other_interfaces);
4759
4760 // Now we find the LCA of Java classes
4761 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4762
4763 res_klass = k;
4764 res_xk = false;
4765 return LCA;
4766 }
4767
4768 // Top-Flat Flat Not-Flat Maybe-Flat
4769 // -------------------------------------------------------------
4770 // Top-Flat Top-Flat Flat Not-Flat Maybe-Flat
4771 // Flat Flat Flat Maybe-Flat Maybe-Flat
4772 // Not-Flat Not-Flat Maybe-Flat Not-Flat Maybe-Flat
4773 // Maybe-Flat Maybe-Flat Maybe-Flat Maybe-Flat Maybe-flat
4774 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4775 if (left == TopFlat) {
4776 return right;
4777 }
4778 if (right == TopFlat) {
4779 return left;
4780 }
4781 if (left == MaybeFlat || right == MaybeFlat) {
4782 return MaybeFlat;
4783 }
4784
4785 switch (left) {
4786 case Flat:
4787 if (right == Flat) {
4788 return Flat;
4789 }
4790 return MaybeFlat;
4791 case NotFlat:
4792 if (right == NotFlat) {
4793 return NotFlat;
4794 }
4795 return MaybeFlat;
4796 default:
4797 ShouldNotReachHere();
4798 return Uninitialized;
4799 }
4800 }
4801
4802 //------------------------java_mirror_type--------------------------------------
4803 ciType* TypeInstPtr::java_mirror_type() const {
4804 // must be a singleton type
4805 if( const_oop() == nullptr ) return nullptr;
4806
4807 // must be of type java.lang.Class
4808 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4809 return const_oop()->as_instance()->java_mirror_type();
4810 }
4811
4812
4813 //------------------------------xdual------------------------------------------
4814 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4815 // inheritance mechanism.
4816 const Type* TypeInstPtr::xdual() const {
4817 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4818 dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4819 }
4820
4821 //------------------------------eq---------------------------------------------
4822 // Structural equality check for Type representations
4823 bool TypeInstPtr::eq( const Type *t ) const {
4824 const TypeInstPtr *p = t->is_instptr();
4825 return
4826 klass()->equals(p->klass()) &&
4827 _flat_in_array == p->_flat_in_array &&
4828 _interfaces->eq(p->_interfaces) &&
4829 TypeOopPtr::eq(p); // Check sub-type stuff
4830 }
4831
4832 //------------------------------hash-------------------------------------------
4833 // Type-specific hashing function.
4834 uint TypeInstPtr::hash() const {
4835 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4836 }
4837
4838 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4839 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4840 }
4841
4842
4843 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4844 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4845 }
4846
4847 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4848 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4849 }
4850
4851
4852 //------------------------------dump2------------------------------------------
4853 // Dump oop Type
4854 #ifndef PRODUCT
4855 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4859 _interfaces->dump(st);
4860
4861 if (_ptr == Constant && (WizardMode || Verbose)) {
4862 ResourceMark rm;
4863 stringStream ss;
4864
4865 st->print(" ");
4866 const_oop()->print_oop(&ss);
4867 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4868 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4869 char* buf = ss.as_string(/* c_heap= */false);
4870 StringUtils::replace_no_expand(buf, "\n", "");
4871 st->print_raw(buf);
4872 }
4873
4874 st->print(":%s", ptr_msg[_ptr]);
4875 if (_klass_is_exact) {
4876 st->print(":exact");
4877 }
4878
4879 st->print(" *");
4880
4881 dump_offset(st);
4882 dump_instance_id(st);
4883 dump_inline_depth(st);
4884 dump_speculative(st);
4885 dump_flat_in_array(_flat_in_array, st);
4886 }
4887 #endif
4888
4889 bool TypeInstPtr::empty() const {
4890 if (_flat_in_array == TopFlat) {
4891 return true;
4892 }
4893 return TypeOopPtr::empty();
4894 }
4895
4896 //------------------------------add_offset-------------------------------------
4897 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4898 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4899 _instance_id, add_offset_speculative(offset), _inline_depth);
4900 }
4901
4902 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4903 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4904 _instance_id, with_offset_speculative(offset), _inline_depth);
4905 }
4906
4907 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4908 if (_speculative == nullptr) {
4909 return this;
4910 }
4911 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4912 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4913 _instance_id, nullptr, _inline_depth);
4914 }
4915
4916 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4917 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4918 }
4919
4920 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4921 if (!UseInlineDepthForSpeculativeTypes) {
4922 return this;
4923 }
4924 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4925 }
4926
4927 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4928 assert(is_known_instance(), "should be known");
4929 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4930 }
4931
4932 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4933 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4934 }
4935
4936 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4937 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4938 }
4939
4940 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4941 bool xk = klass_is_exact();
4942 ciInstanceKlass* ik = klass()->as_instance_klass();
4943 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4944 if (_interfaces->eq(ik)) {
4945 Compile* C = Compile::current();
4946 Dependencies* deps = C->dependencies();
4947 deps->assert_leaf_type(ik);
4948 xk = true;
4949 }
4950 }
4951 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4952 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4953 }
4954
4955 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) {
4956 static_assert(std::is_base_of<T2, T1>::value, "");
4957
4958 if (!this_one->is_instance_type(other)) {
4959 return false;
4960 }
4961
4962 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4963 return true;
4964 }
4965
4966 return this_one->klass()->is_subtype_of(other->klass()) &&
4967 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4968 }
4969
4970
4971 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4972 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4977 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4978 return true;
4979 }
4980
4981 if (this_one->is_instance_type(other)) {
4982 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4983 }
4984
4985 int dummy;
4986 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4987 if (this_top_or_bottom) {
4988 return false;
4989 }
4990
4991 const T1* other_ary = this_one->is_array_type(other);
4992 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4993 const TypePtr* this_elem = this_one->elem()->make_ptr();
4994 if (other_elem != nullptr && this_elem != nullptr) {
4995 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4996 }
4997 if (other_elem == nullptr && this_elem == nullptr) {
4998 return this_one->klass()->is_subtype_of(other->klass());
4999 }
5000
5001 return false;
5002 }
5003
5004 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5005 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5006 }
5007
5008 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5009 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5010 }
5011
5012 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5013 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5014 }
5015
5016 //=============================================================================
5017 // Convenience common pre-built types.
5018 const TypeAryPtr* TypeAryPtr::BOTTOM;
5019 const TypeAryPtr *TypeAryPtr::RANGE;
5020 const TypeAryPtr *TypeAryPtr::OOPS;
5021 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5022 const TypeAryPtr *TypeAryPtr::BYTES;
5023 const TypeAryPtr *TypeAryPtr::SHORTS;
5024 const TypeAryPtr *TypeAryPtr::CHARS;
5025 const TypeAryPtr *TypeAryPtr::INTS;
5026 const TypeAryPtr *TypeAryPtr::LONGS;
5027 const TypeAryPtr *TypeAryPtr::FLOATS;
5028 const TypeAryPtr *TypeAryPtr::DOUBLES;
5029 const TypeAryPtr *TypeAryPtr::INLINES;
5030
5031 //------------------------------make-------------------------------------------
5032 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5033 int instance_id, const TypePtr* speculative, int inline_depth) {
5034 assert(!(k == nullptr && ary->_elem->isa_int()),
5035 "integral arrays must be pre-equipped with a class");
5036 if (!xk) xk = ary->ary_must_be_exact();
5037 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5038 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5039 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5040 k = nullptr;
5041 }
5042 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5043 }
5044
5045 //------------------------------make-------------------------------------------
5046 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5047 int instance_id, const TypePtr* speculative, int inline_depth,
5048 bool is_autobox_cache) {
5049 assert(!(k == nullptr && ary->_elem->isa_int()),
5050 "integral arrays must be pre-equipped with a class");
5051 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5052 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
5053 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5054 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5055 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5056 k = nullptr;
5057 }
5058 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5059 }
5060
5061 //------------------------------cast_to_ptr_type-------------------------------
5062 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5063 if( ptr == _ptr ) return this;
5064 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5065 }
5066
5067
5068 //-----------------------------cast_to_exactness-------------------------------
5069 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5070 if( klass_is_exact == _klass_is_exact ) return this;
5071 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
5072 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5073 }
5074
5075 //-----------------------------cast_to_instance_id----------------------------
5076 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5077 if( instance_id == _instance_id ) return this;
5078 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5079 }
5080
5081
5082 //-----------------------------max_array_length-------------------------------
5083 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5084 jint TypeAryPtr::max_array_length(BasicType etype) {
5085 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5086 if (etype == T_NARROWOOP) {
5087 etype = T_OBJECT;
5088 } else if (etype == T_ILLEGAL) { // bottom[]
5089 etype = T_BYTE; // will produce conservatively high value
5090 } else {
5091 fatal("not an element type: %s", type2name(etype));
5092 }
5093 }
5094 return arrayOopDesc::max_array_length(etype);
5095 }
5096
5097 //-----------------------------narrow_size_type-------------------------------
5098 // Narrow the given size type to the index range for the given array base type.
5116 if (size->is_con()) {
5117 lo = hi;
5118 }
5119 chg = true;
5120 }
5121 // Negative length arrays will produce weird intermediate dead fast-path code
5122 if (lo > hi) {
5123 return TypeInt::ZERO;
5124 }
5125 if (!chg) {
5126 return size;
5127 }
5128 return TypeInt::make(lo, hi, Type::WidenMin);
5129 }
5130
5131 //-------------------------------cast_to_size----------------------------------
5132 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5133 assert(new_size != nullptr, "");
5134 new_size = narrow_size_type(new_size);
5135 if (new_size == size()) return this;
5136 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5137 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5138 }
5139
5140 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5141 if (flat == is_flat()) {
5142 return this;
5143 }
5144 assert(!flat || !is_not_flat(), "inconsistency");
5145 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5146 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5147 if (res->speculative() == res->remove_speculative()) {
5148 return res->remove_speculative();
5149 }
5150 return res;
5151 }
5152
5153 //-------------------------------cast_to_not_flat------------------------------
5154 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5155 if (not_flat == is_not_flat()) {
5156 return this;
5157 }
5158 assert(!not_flat || !is_flat(), "inconsistency");
5159 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5160 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5161 // We keep the speculative part if it contains information about flat-/nullability.
5162 // Make sure it's removed if it's not better than the non-speculative type anymore.
5163 if (res->speculative() == res->remove_speculative()) {
5164 return res->remove_speculative();
5165 }
5166 return res;
5167 }
5168
5169 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5170 if (null_free == is_null_free()) {
5171 return this;
5172 }
5173 assert(!null_free || !is_not_null_free(), "inconsistency");
5174 const Type* elem = this->elem();
5175 const Type* new_elem = elem->make_ptr();
5176 if (null_free) {
5177 new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5178 } else {
5179 new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5180 }
5181 new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5182 const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5183 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5184 if (res->speculative() == res->remove_speculative()) {
5185 return res->remove_speculative();
5186 }
5187 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5188 "speculative type must not be narrower than non-speculative type");
5189 return res;
5190 }
5191
5192 //-------------------------------cast_to_not_null_free-------------------------
5193 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5194 if (not_null_free == is_not_null_free()) {
5195 return this;
5196 }
5197 assert(!not_null_free || !is_null_free(), "inconsistency");
5198 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5199 const TypePtr* new_spec = _speculative;
5200 if (new_spec != nullptr) {
5201 // Could be 'null free' from profiling, which would contradict the cast.
5202 new_spec = new_spec->is_aryptr()->cast_to_null_free(false)->cast_to_not_null_free();
5203 }
5204 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5205 _instance_id, new_spec, _inline_depth, _is_autobox_cache);
5206 // We keep the speculative part if it contains information about flat-/nullability.
5207 // Make sure it's removed if it's not better than the non-speculative type anymore.
5208 if (res->speculative() == res->remove_speculative()) {
5209 return res->remove_speculative();
5210 }
5211 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5212 "speculative type must not be narrower than non-speculative type");
5213 return res;
5214 }
5215
5216 //---------------------------------update_properties---------------------------
5217 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5218 if ((from->is_flat() && is_not_flat()) ||
5219 (from->is_not_flat() && is_flat()) ||
5220 (from->is_null_free() && is_not_null_free()) ||
5221 (from->is_not_null_free() && is_null_free())) {
5222 return nullptr; // Inconsistent properties
5223 }
5224 const TypeAryPtr* res = this;
5225 if (from->is_not_null_free()) {
5226 res = res->cast_to_not_null_free();
5227 }
5228 if (from->is_not_flat()) {
5229 res = res->cast_to_not_flat();
5230 }
5231 return res;
5232 }
5233
5234 jint TypeAryPtr::flat_layout_helper() const {
5235 return exact_klass()->as_flat_array_klass()->layout_helper();
5236 }
5237
5238 int TypeAryPtr::flat_elem_size() const {
5239 return exact_klass()->as_flat_array_klass()->element_byte_size();
5240 }
5241
5242 int TypeAryPtr::flat_log_elem_size() const {
5243 return exact_klass()->as_flat_array_klass()->log2_element_size();
5244 }
5245
5246 jint TypeAryPtr::max_flat_elements() const {
5247 return exact_klass()->as_flat_array_klass()->max_elements();
5248 }
5249
5250 //------------------------------cast_to_stable---------------------------------
5251 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5252 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5253 return this;
5254
5255 const Type* elem = this->elem();
5256 const TypePtr* elem_ptr = elem->make_ptr();
5257
5258 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5259 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5260 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5261 }
5262
5263 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5264
5265 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5266 }
5267
5268 //-----------------------------stable_dimension--------------------------------
5269 int TypeAryPtr::stable_dimension() const {
5270 if (!is_stable()) return 0;
5271 int dim = 1;
5272 const TypePtr* elem_ptr = elem()->make_ptr();
5273 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5274 dim += elem_ptr->is_aryptr()->stable_dimension();
5275 return dim;
5276 }
5277
5278 //----------------------cast_to_autobox_cache-----------------------------------
5279 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5280 if (is_autobox_cache()) return this;
5281 const TypeOopPtr* etype = elem()->make_oopptr();
5282 if (etype == nullptr) return this;
5283 // The pointers in the autobox arrays are always non-null.
5284 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5285 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5286 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5287 }
5288
5289 //------------------------------eq---------------------------------------------
5290 // Structural equality check for Type representations
5291 bool TypeAryPtr::eq( const Type *t ) const {
5292 const TypeAryPtr *p = t->is_aryptr();
5293 return
5294 _ary == p->_ary && // Check array
5295 TypeOopPtr::eq(p) &&// Check sub-parts
5296 _field_offset == p->_field_offset;
5297 }
5298
5299 //------------------------------hash-------------------------------------------
5300 // Type-specific hashing function.
5301 uint TypeAryPtr::hash(void) const {
5302 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5303 }
5304
5305 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5306 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5307 }
5308
5309 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5310 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5311 }
5312
5313 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5314 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5315 }
5316 //------------------------------meet-------------------------------------------
5317 // Compute the MEET of two types. It returns a new Type object.
5318 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5319 // Perform a fast test for common case; meeting the same types together.
5320 if( this == t ) return this; // Meeting same type-rep?
5321 // Current "this->_base" is Pointer
5322 switch (t->base()) { // switch on original type
5329 case HalfFloatBot:
5330 case FloatTop:
5331 case FloatCon:
5332 case FloatBot:
5333 case DoubleTop:
5334 case DoubleCon:
5335 case DoubleBot:
5336 case NarrowOop:
5337 case NarrowKlass:
5338 case Bottom: // Ye Olde Default
5339 return Type::BOTTOM;
5340 case Top:
5341 return this;
5342
5343 default: // All else is a mistake
5344 typerr(t);
5345
5346 case OopPtr: { // Meeting to OopPtrs
5347 // Found a OopPtr type vs self-AryPtr type
5348 const TypeOopPtr *tp = t->is_oopptr();
5349 Offset offset = meet_offset(tp->offset());
5350 PTR ptr = meet_ptr(tp->ptr());
5351 int depth = meet_inline_depth(tp->inline_depth());
5352 const TypePtr* speculative = xmeet_speculative(tp);
5353 switch (tp->ptr()) {
5354 case TopPTR:
5355 case AnyNull: {
5356 int instance_id = meet_instance_id(InstanceTop);
5357 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5358 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5359 }
5360 case BotPTR:
5361 case NotNull: {
5362 int instance_id = meet_instance_id(tp->instance_id());
5363 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5364 }
5365 default: ShouldNotReachHere();
5366 }
5367 }
5368
5369 case AnyPtr: { // Meeting two AnyPtrs
5370 // Found an AnyPtr type vs self-AryPtr type
5371 const TypePtr *tp = t->is_ptr();
5372 Offset offset = meet_offset(tp->offset());
5373 PTR ptr = meet_ptr(tp->ptr());
5374 const TypePtr* speculative = xmeet_speculative(tp);
5375 int depth = meet_inline_depth(tp->inline_depth());
5376 switch (tp->ptr()) {
5377 case TopPTR:
5378 return this;
5379 case BotPTR:
5380 case NotNull:
5381 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5382 case Null:
5383 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5384 // else fall through to AnyNull
5385 case AnyNull: {
5386 int instance_id = meet_instance_id(InstanceTop);
5387 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5388 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5389 }
5390 default: ShouldNotReachHere();
5391 }
5392 }
5393
5394 case MetadataPtr:
5395 case KlassPtr:
5396 case InstKlassPtr:
5397 case AryKlassPtr:
5398 case RawPtr: return TypePtr::BOTTOM;
5399
5400 case AryPtr: { // Meeting 2 references?
5401 const TypeAryPtr *tap = t->is_aryptr();
5402 Offset off = meet_offset(tap->offset());
5403 Offset field_off = meet_field_offset(tap->field_offset());
5404 const Type* tm = _ary->meet_speculative(tap->_ary);
5405 const TypeAry* tary = tm->isa_ary();
5406 if (tary == nullptr) {
5407 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5408 return tm;
5409 }
5410 PTR ptr = meet_ptr(tap->ptr());
5411 int instance_id = meet_instance_id(tap->instance_id());
5412 const TypePtr* speculative = xmeet_speculative(tap);
5413 int depth = meet_inline_depth(tap->inline_depth());
5414
5415 ciKlass* res_klass = nullptr;
5416 bool res_xk = false;
5417 bool res_flat = false;
5418 bool res_not_flat = false;
5419 bool res_not_null_free = false;
5420 bool res_atomic = false;
5421 const Type* elem = tary->_elem;
5422 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5423 instance_id = InstanceBot;
5424 } else if (this->is_flat() != tap->is_flat()) {
5425 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5426 if (tary->_flat) {
5427 // Result is in a flat representation
5428 off = Offset(is_flat() ? offset() : tap->offset());
5429 field_off = is_flat() ? field_offset() : tap->field_offset();
5430 } else if (below_centerline(ptr)) {
5431 // Result is in a non-flat representation
5432 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5433 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5434 } else if (flat_offset() == tap->flat_offset()) {
5435 off = Offset(!is_flat() ? offset() : tap->offset());
5436 field_off = !is_flat() ? field_offset() : tap->field_offset();
5437 }
5438 }
5439
5440 ciObject* o = nullptr; // Assume not constant when done
5441 ciObject* this_oop = const_oop();
5442 ciObject* tap_oop = tap->const_oop();
5443 if (ptr == Constant) {
5444 if (this_oop != nullptr && tap_oop != nullptr &&
5445 this_oop->equals(tap_oop)) {
5446 o = tap_oop;
5447 } else if (above_centerline(_ptr)) {
5448 o = tap_oop;
5449 } else if (above_centerline(tap->_ptr)) {
5450 o = this_oop;
5451 } else {
5452 ptr = NotNull;
5453 }
5454 }
5455 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);
5456 }
5457
5458 // All arrays inherit from Object class
5459 case InstPtr: {
5460 const TypeInstPtr *tp = t->is_instptr();
5461 Offset offset = meet_offset(tp->offset());
5462 PTR ptr = meet_ptr(tp->ptr());
5463 int instance_id = meet_instance_id(tp->instance_id());
5464 const TypePtr* speculative = xmeet_speculative(tp);
5465 int depth = meet_inline_depth(tp->inline_depth());
5466 const TypeInterfaces* interfaces = meet_interfaces(tp);
5467 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5468 const TypeInterfaces* this_interfaces = _interfaces;
5469
5470 switch (ptr) {
5471 case TopPTR:
5472 case AnyNull: // Fall 'down' to dual of object klass
5473 // For instances when a subclass meets a superclass we fall
5474 // below the centerline when the superclass is exact. We need to
5475 // do the same here.
5476 //
5477 // Flat in array:
5478 // We do
5479 // dual(TypeAryPtr) MEET dual(TypeInstPtr)
5480 // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5481 // instances or arrays).
5482 // If TypeInstPtr is an Object and either
5483 // - exact
5484 // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5485 // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5486 // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5487 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5488 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5489 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5490 } else {
5491 // cannot subclass, so the meet has to fall badly below the centerline
5492 ptr = NotNull;
5493 instance_id = InstanceBot;
5494 interfaces = this_interfaces->intersection_with(tp_interfaces);
5495 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5496 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5497 }
5498 case Constant:
5499 case NotNull:
5500 case BotPTR: { // Fall down to object klass
5501 // LCA is object_klass, but if we subclass from the top we can do better
5502 if (above_centerline(tp->ptr())) {
5503 // If 'tp' is above the centerline and it is Object class
5504 // then we can subclass in the Java class hierarchy.
5505 // For instances when a subclass meets a superclass we fall
5506 // below the centerline when the superclass is exact. We need
5507 // to do the same here.
5508
5509 // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5510 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5511 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5512 // that is, my array type is a subtype of 'tp' klass
5513 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5514 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5515 }
5516 }
5517 // The other case cannot happen, since t cannot be a subtype of an array.
5518 // The meet falls down to Object class below centerline.
5519 if (ptr == Constant) {
5520 ptr = NotNull;
5521 }
5522 if (instance_id > 0) {
5523 instance_id = InstanceBot;
5524 }
5525
5526 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5527 interfaces = this_interfaces->intersection_with(tp_interfaces);
5528 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5529 flat_in_array, instance_id, speculative, depth);
5530 }
5531 default: typerr(t);
5532 }
5533 }
5534 }
5535 return this; // Lint noise
5536 }
5537
5538
5539 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5540 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5541 int dummy;
5542 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5543 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5544 ciKlass* this_klass = this_ary->klass();
5545 ciKlass* other_klass = other_ary->klass();
5546 bool this_xk = this_ary->klass_is_exact();
5547 bool other_xk = other_ary->klass_is_exact();
5548 PTR this_ptr = this_ary->ptr();
5549 PTR other_ptr = other_ary->ptr();
5550 bool this_flat = this_ary->is_flat();
5551 bool this_not_flat = this_ary->is_not_flat();
5552 bool other_flat = other_ary->is_flat();
5553 bool other_not_flat = other_ary->is_not_flat();
5554 bool this_not_null_free = this_ary->is_not_null_free();
5555 bool other_not_null_free = other_ary->is_not_null_free();
5556 bool this_atomic = this_ary->is_atomic();
5557 bool other_atomic = other_ary->is_atomic();
5558 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5559 res_klass = nullptr;
5560 MeetResult result = SUBTYPE;
5561 res_flat = this_flat && other_flat;
5562 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5563 res_not_flat = this_not_flat && other_not_flat;
5564 res_not_null_free = this_not_null_free && other_not_null_free;
5565 res_atomic = this_atomic && other_atomic;
5566
5567 if (elem->isa_int()) {
5568 // Integral array element types have irrelevant lattice relations.
5569 // It is the klass that determines array layout, not the element type.
5570 if (this_top_or_bottom) {
5571 res_klass = other_klass;
5572 } else if (other_top_or_bottom || other_klass == this_klass) {
5573 res_klass = this_klass;
5574 } else {
5575 // Something like byte[int+] meets char[int+].
5576 // This must fall to bottom, not (int[-128..65535])[int+].
5577 // instance_id = InstanceBot;
5578 elem = Type::BOTTOM;
5579 result = NOT_SUBTYPE;
5580 if (above_centerline(ptr) || ptr == Constant) {
5581 ptr = NotNull;
5582 res_xk = false;
5583 return NOT_SUBTYPE;
5584 }
5585 }
5586 } else {// Non integral arrays.
5587 // Must fall to bottom if exact klasses in upper lattice
5588 // are not equal or super klass is exact.
5589 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5590 // meet with top[] and bottom[] are processed further down:
5591 !this_top_or_bottom && !other_top_or_bottom &&
5592 // both are exact and not equal:
5594 // 'tap' is exact and super or unrelated:
5595 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5596 // 'this' is exact and super or unrelated:
5597 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5598 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5599 elem = Type::BOTTOM;
5600 }
5601 ptr = NotNull;
5602 res_xk = false;
5603 return NOT_SUBTYPE;
5604 }
5605 }
5606
5607 res_xk = false;
5608 switch (other_ptr) {
5609 case AnyNull:
5610 case TopPTR:
5611 // Compute new klass on demand, do not use tap->_klass
5612 if (below_centerline(this_ptr)) {
5613 res_xk = this_xk;
5614 if (this_ary->is_flat()) {
5615 elem = this_ary->elem();
5616 }
5617 } else {
5618 res_xk = (other_xk || this_xk);
5619 }
5620 break;
5621 case Constant: {
5622 if (this_ptr == Constant && same_nullness) {
5623 // Only exact if same nullness since:
5624 // null-free [LMyValue <: nullable [LMyValue.
5625 res_xk = true;
5626 } else if (above_centerline(this_ptr)) {
5627 res_xk = true;
5628 } else {
5629 // Only precise for identical arrays
5630 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5631 // Even though MyValue is final, [LMyValue is only exact if the array
5632 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5633 if (res_xk && !res_null_free && !res_not_null_free) {
5634 ptr = NotNull;
5635 res_xk = false;
5636 }
5637 }
5638 break;
5639 }
5640 case NotNull:
5641 case BotPTR:
5642 // Compute new klass on demand, do not use tap->_klass
5643 if (above_centerline(this_ptr)) {
5644 res_xk = other_xk;
5645 if (other_ary->is_flat()) {
5646 elem = other_ary->elem();
5647 }
5648 } else {
5649 res_xk = (other_xk && this_xk) &&
5650 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5651 // Even though MyValue is final, [LMyValue is only exact if the array
5652 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5653 if (res_xk && !res_null_free && !res_not_null_free) {
5654 res_xk = false;
5655 }
5656 }
5657 break;
5658 default: {
5659 ShouldNotReachHere();
5660 return result;
5661 }
5662 }
5663 return result;
5664 }
5665
5666
5667 //------------------------------xdual------------------------------------------
5668 // Dual: compute field-by-field dual
5669 const Type *TypeAryPtr::xdual() const {
5670 bool xk = _klass_is_exact;
5671 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());
5672 }
5673
5674 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5675 return _field_offset.meet(offset);
5676 }
5677
5678 //------------------------------dual_offset------------------------------------
5679 Type::Offset TypeAryPtr::dual_field_offset() const {
5680 return _field_offset.dual();
5681 }
5682
5683 //------------------------------dump2------------------------------------------
5684 #ifndef PRODUCT
5685 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5686 st->print("aryptr:");
5687 _ary->dump2(d, depth, st);
5688 _interfaces->dump(st);
5689
5690 if (_ptr == Constant) {
5691 const_oop()->print(st);
5692 }
5693
5694 st->print(":%s", ptr_msg[_ptr]);
5695 if (_klass_is_exact) {
5696 st->print(":exact");
5697 }
5698
5699 if (is_flat()) {
5700 st->print(":flat");
5701 st->print("(");
5702 _field_offset.dump2(st);
5703 st->print(")");
5704 } else if (is_not_flat()) {
5705 st->print(":not_flat");
5706 }
5707 if (is_null_free()) {
5708 st->print(":null free");
5709 }
5710 if (is_atomic()) {
5711 st->print(":atomic");
5712 }
5713 if (Verbose) {
5714 if (is_not_flat()) {
5715 st->print(":not flat");
5716 }
5717 if (is_not_null_free()) {
5718 st->print(":nullable");
5719 }
5720 }
5721 if (offset() != 0) {
5722 BasicType basic_elem_type = elem()->basic_type();
5723 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5724 if( _offset == Offset::top ) st->print("+undefined");
5725 else if( _offset == Offset::bottom ) st->print("+any");
5726 else if( offset() < header_size ) st->print("+%d", offset());
5727 else {
5728 if (basic_elem_type == T_ILLEGAL) {
5729 st->print("+any");
5730 } else {
5731 int elem_size = type2aelembytes(basic_elem_type);
5732 st->print("[%d]", (offset() - header_size)/elem_size);
5733 }
5734 }
5735 }
5736
5737 dump_instance_id(st);
5738 dump_inline_depth(st);
5739 dump_speculative(st);
5740 }
5741 #endif
5742
5743 bool TypeAryPtr::empty(void) const {
5744 if (_ary->empty()) {
5745 return true;
5746 }
5747
5748 // Reference array is always possible. Only flat array with non-flattenable content can be an issue.
5749 if (const TypeOopPtr* elem_ptr = elem()->make_oopptr(); _ary->_flat && elem_ptr != nullptr && elem_ptr->is_inlinetypeptr()) {
5750 auto impossible_layout_with_null_freeness = [this](bool null_free, bool atomic) -> bool {
5751 ArrayDescription description = elem()->inline_klass()->array_description_of_array_properties(ArrayProperties::Default().with_null_restricted(null_free).with_non_atomic(!atomic));
5752 return !LayoutKindHelper::is_flat(description._layout_kind); // We get a contradiction between _ary->_flat and array_layout_selection
5753 };
5754 auto impossible_layout = [&](bool atomic) -> bool {
5755 if (is_null_free()) {
5756 // Surely null-free
5757 if (impossible_layout_with_null_freeness(true, atomic)) {
5758 return true;
5759 }
5760 } else if (is_not_null_free()) {
5761 // Surely nullable
5762 if (impossible_layout_with_null_freeness(false, atomic)) {
5763 return true;
5764 }
5765 } else {
5766 // Not sure...
5767 if (impossible_layout_with_null_freeness(false, atomic) && impossible_layout_with_null_freeness(true, atomic)) {
5768 return true;
5769 }
5770 }
5771 return false;
5772 };
5773 if (_ary->_atomic) {
5774 // Surely atomic
5775 if (impossible_layout(true)) {
5776 return true;
5777 }
5778 } else if (klass_is_exact()) {
5779 // Surely non-atomic
5780 if (impossible_layout(false)) {
5781 return true;
5782 }
5783 } else {
5784 // Not sure...
5785 if (impossible_layout(true) && impossible_layout(false)) {
5786 return true;
5787 }
5788 }
5789 }
5790
5791 return TypeOopPtr::empty();
5792 }
5793
5794 //------------------------------add_offset-------------------------------------
5795 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5796 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);
5797 }
5798
5799 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5800 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);
5801 }
5802
5803 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5804 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5805 }
5806
5807 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5808 if (_speculative == nullptr) {
5809 return this;
5810 }
5811 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5812 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);
5813 }
5814
5815 const Type* TypeAryPtr::cleanup_speculative() const {
5816 if (speculative() == nullptr) {
5817 return this;
5818 }
5819 // Keep speculative part if it contains information about flat-/nullability
5820 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5821 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5822 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5823 return this;
5824 }
5825 return TypeOopPtr::cleanup_speculative();
5826 }
5827
5828 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5829 if (!UseInlineDepthForSpeculativeTypes) {
5830 return this;
5831 }
5832 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5833 }
5834
5835 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5836 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);
5837 }
5838
5839 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5840 if (!is_flat() || !klass_is_exact() || offset == OffsetBot || offset == OffsetTop) {
5841 return add_offset(offset);
5842 }
5843
5844 // Handle flat concrete value class array with known 'offset' which could refer to an actual field in the flat storage.
5845 int adj = 0;
5846 if (_offset != Offset::bottom && _offset != Offset::top) {
5847 adj = _offset.get();
5848 offset += _offset.get();
5849 }
5850 uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5851 if (_field_offset != Offset::bottom && _field_offset != Offset::top) {
5852 offset += _field_offset.get();
5853 if (_offset == Offset::bottom || _offset == Offset::top) {
5854 offset += header;
5855 }
5856 }
5857 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5858 // Try to get the field of the inline type array element we are pointing to
5859 ciInlineKlass* vk = elem()->inline_klass();
5860 int shift = flat_log_elem_size();
5861 int mask = (1 << shift) - 1;
5862 int field_offset = static_cast<int>((offset - header) & mask);
5863 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5864 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5865 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5866 }
5867 }
5868 return add_offset(offset - adj);
5869 }
5870
5871 // Return offset incremented by field_offset for flat inline type arrays
5872 int TypeAryPtr::flat_offset() const {
5873 int offset = _offset.get();
5874 if (offset != OffsetBot && offset != OffsetTop &&
5875 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5876 offset += _field_offset.get();
5877 }
5878 return offset;
5879 }
5880
5881 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5882 assert(is_known_instance(), "should be known");
5883 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5884 }
5885
5886 //=============================================================================
5887
5888
5889 //------------------------------hash-------------------------------------------
5890 // Type-specific hashing function.
5891 uint TypeNarrowPtr::hash(void) const {
5892 return _ptrtype->hash() + 7;
5893 }
5894
5895 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5896 return _ptrtype->singleton();
5897 }
5898
5899 bool TypeNarrowPtr::empty(void) const {
5900 return _ptrtype->empty();
5901 }
5902
5903 intptr_t TypeNarrowPtr::get_con() const {
5904 return _ptrtype->get_con();
5905 }
5906
5907 bool TypeNarrowPtr::eq( const Type *t ) const {
5908 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5962 case HalfFloatTop:
5963 case HalfFloatCon:
5964 case HalfFloatBot:
5965 case FloatTop:
5966 case FloatCon:
5967 case FloatBot:
5968 case DoubleTop:
5969 case DoubleCon:
5970 case DoubleBot:
5971 case AnyPtr:
5972 case RawPtr:
5973 case OopPtr:
5974 case InstPtr:
5975 case AryPtr:
5976 case MetadataPtr:
5977 case KlassPtr:
5978 case InstKlassPtr:
5979 case AryKlassPtr:
5980 case NarrowOop:
5981 case NarrowKlass:
5982 case Bottom: // Ye Olde Default
5983 return Type::BOTTOM;
5984 case Top:
5985 return this;
5986
5987 default: // All else is a mistake
5988 typerr(t);
5989
5990 } // End of switch
5991
5992 return this;
5993 }
5994
5995 #ifndef PRODUCT
5996 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5997 _ptrtype->dump2(d, depth, st);
5998 }
5999 #endif
6000
6001 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
6045 return (one == two) && TypePtr::eq(t);
6046 } else {
6047 return one->equals(two) && TypePtr::eq(t);
6048 }
6049 }
6050
6051 //------------------------------hash-------------------------------------------
6052 // Type-specific hashing function.
6053 uint TypeMetadataPtr::hash(void) const {
6054 return
6055 (metadata() ? metadata()->hash() : 0) +
6056 TypePtr::hash();
6057 }
6058
6059 //------------------------------singleton--------------------------------------
6060 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6061 // constants
6062 bool TypeMetadataPtr::singleton(void) const {
6063 // detune optimizer to not generate constant metadata + constant offset as a constant!
6064 // TopPTR, Null, AnyNull, Constant are all singletons
6065 return (offset() == 0) && !below_centerline(_ptr);
6066 }
6067
6068 //------------------------------add_offset-------------------------------------
6069 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6070 return make( _ptr, _metadata, xadd_offset(offset));
6071 }
6072
6073 //-----------------------------filter------------------------------------------
6074 // Do not allow interface-vs.-noninterface joins to collapse to top.
6075 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6076 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6077 if (ft == nullptr || ft->empty())
6078 return Type::TOP; // Canonical empty value
6079 return ft;
6080 }
6081
6082 //------------------------------get_con----------------------------------------
6083 intptr_t TypeMetadataPtr::get_con() const {
6084 assert( _ptr == Null || _ptr == Constant, "" );
6085 assert(offset() >= 0, "");
6086
6087 if (offset() != 0) {
6088 // After being ported to the compiler interface, the compiler no longer
6089 // directly manipulates the addresses of oops. Rather, it only has a pointer
6090 // to a handle at compile time. This handle is embedded in the generated
6091 // code and dereferenced at the time the nmethod is made. Until that time,
6092 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6093 // have access to the addresses!). This does not seem to currently happen,
6094 // but this assertion here is to help prevent its occurrence.
6095 tty->print_cr("Found oop constant with non-zero offset");
6096 ShouldNotReachHere();
6097 }
6098
6099 return (intptr_t)metadata()->constant_encoding();
6100 }
6101
6102 //------------------------------cast_to_ptr_type-------------------------------
6103 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6104 if( ptr == _ptr ) return this;
6105 return make(ptr, metadata(), _offset);
6106 }
6107
6121 case HalfFloatBot:
6122 case FloatTop:
6123 case FloatCon:
6124 case FloatBot:
6125 case DoubleTop:
6126 case DoubleCon:
6127 case DoubleBot:
6128 case NarrowOop:
6129 case NarrowKlass:
6130 case Bottom: // Ye Olde Default
6131 return Type::BOTTOM;
6132 case Top:
6133 return this;
6134
6135 default: // All else is a mistake
6136 typerr(t);
6137
6138 case AnyPtr: {
6139 // Found an AnyPtr type vs self-OopPtr type
6140 const TypePtr *tp = t->is_ptr();
6141 Offset offset = meet_offset(tp->offset());
6142 PTR ptr = meet_ptr(tp->ptr());
6143 switch (tp->ptr()) {
6144 case Null:
6145 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6146 // else fall through:
6147 case TopPTR:
6148 case AnyNull: {
6149 return make(ptr, _metadata, offset);
6150 }
6151 case BotPTR:
6152 case NotNull:
6153 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6154 default: typerr(t);
6155 }
6156 }
6157
6158 case RawPtr:
6159 case KlassPtr:
6160 case InstKlassPtr:
6161 case AryKlassPtr:
6162 case OopPtr:
6163 case InstPtr:
6164 case AryPtr:
6165 return TypePtr::BOTTOM; // Oop meet raw is not well defined
6166
6167 case MetadataPtr: {
6168 const TypeMetadataPtr *tp = t->is_metadataptr();
6169 Offset offset = meet_offset(tp->offset());
6170 PTR tptr = tp->ptr();
6171 PTR ptr = meet_ptr(tptr);
6172 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6173 if (tptr == TopPTR || _ptr == TopPTR ||
6174 metadata()->equals(tp->metadata())) {
6175 return make(ptr, md, offset);
6176 }
6177 // metadata is different
6178 if( ptr == Constant ) { // Cannot be equal constants, so...
6179 if( tptr == Constant && _ptr != Constant) return t;
6180 if( _ptr == Constant && tptr != Constant) return this;
6181 ptr = NotNull; // Fall down in lattice
6182 }
6183 return make(ptr, nullptr, offset);
6184 break;
6185 }
6186 } // End of switch
6187 return this; // Return the double constant
6188 }
6189
6193 const Type *TypeMetadataPtr::xdual() const {
6194 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6195 }
6196
6197 //------------------------------dump2------------------------------------------
6198 #ifndef PRODUCT
6199 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6200 st->print("metadataptr:%s", ptr_msg[_ptr]);
6201 if (metadata() != nullptr) {
6202 st->print(":" INTPTR_FORMAT, p2i(metadata()));
6203 }
6204 dump_offset(st);
6205 }
6206 #endif
6207
6208
6209 //=============================================================================
6210 // Convenience common pre-built type.
6211 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6212
6213 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6214 TypePtr(MetadataPtr, ptr, offset, relocInfo::metadata_type), _metadata(metadata) {
6215 }
6216
6217 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6218 return make(Constant, m, Offset(0));
6219 }
6220 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6221 return make(Constant, m, Offset(0));
6222 }
6223
6224 //------------------------------make-------------------------------------------
6225 // Create a meta data constant
6226 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6227 assert(m == nullptr || !m->is_klass(), "wrong type");
6228 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6229 }
6230
6231
6232 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6233 const Type* elem = _ary->_elem;
6234 bool xk = klass_is_exact();
6235 bool is_refined = false;
6236 if (elem->make_oopptr() != nullptr) {
6237 is_refined = true;
6238 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6239 if (elem->isa_aryklassptr()) {
6240 const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6241 if (elem_klass->is_refined_type()) {
6242 elem = elem_klass->cast_to_non_refined();
6243 }
6244 } else {
6245 const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6246 if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6247 !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6248 xk = true;
6249 }
6250 }
6251 }
6252 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);
6253 }
6254
6255 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6256 if (klass->is_instance_klass()) {
6257 return TypeInstKlassPtr::make(klass, interface_handling);
6258 }
6259 return TypeAryKlassPtr::make(klass, interface_handling);
6260 }
6261
6262 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6263 : TypePtr(t, ptr, offset, relocInfo::metadata_type), _klass(klass), _interfaces(interfaces) {
6264 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6265 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6266 }
6267
6268 // Is there a single ciKlass* that can represent that type?
6269 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6270 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6271 if (_interfaces->empty()) {
6272 return _klass;
6273 }
6274 if (_klass != ciEnv::current()->Object_klass()) {
6275 if (_interfaces->eq(_klass->as_instance_klass())) {
6276 return _klass;
6277 }
6278 return nullptr;
6279 }
6280 return _interfaces->exact_klass();
6281 }
6282
6283 //------------------------------eq---------------------------------------------
6284 // Structural equality check for Type representations
6285 bool TypeKlassPtr::eq(const Type *t) const {
6286 const TypeKlassPtr *p = t->is_klassptr();
6287 return
6288 _interfaces->eq(p->_interfaces) &&
6289 TypePtr::eq(p);
6290 }
6291
6292 //------------------------------hash-------------------------------------------
6293 // Type-specific hashing function.
6294 uint TypeKlassPtr::hash(void) const {
6295 return TypePtr::hash() + _interfaces->hash();
6296 }
6297
6298 //------------------------------singleton--------------------------------------
6299 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6300 // constants
6301 bool TypeKlassPtr::singleton(void) const {
6302 // detune optimizer to not generate constant klass + constant offset as a constant!
6303 // TopPTR, Null, AnyNull, Constant are all singletons
6304 return (offset() == 0) && !below_centerline(_ptr);
6305 }
6306
6307 // Do not allow interface-vs.-noninterface joins to collapse to top.
6308 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6309 // logic here mirrors the one from TypeOopPtr::filter. See comments
6310 // there.
6311 const Type* ft = join_helper(kills, include_speculative);
6312
6313 if (ft->empty()) {
6314 return Type::TOP; // Canonical empty value
6315 }
6316
6317 return ft;
6318 }
6319
6320 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6321 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6322 return _interfaces->union_with(other->_interfaces);
6323 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6324 return other->_interfaces;
6325 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6326 return _interfaces;
6327 }
6328 return _interfaces->intersection_with(other->_interfaces);
6329 }
6330
6331 //------------------------------get_con----------------------------------------
6332 intptr_t TypeKlassPtr::get_con() const {
6333 assert( _ptr == Null || _ptr == Constant, "" );
6334 assert( offset() >= 0, "" );
6335
6336 if (offset() != 0) {
6337 // After being ported to the compiler interface, the compiler no longer
6338 // directly manipulates the addresses of oops. Rather, it only has a pointer
6339 // to a handle at compile time. This handle is embedded in the generated
6340 // code and dereferenced at the time the nmethod is made. Until that time,
6341 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6342 // have access to the addresses!). This does not seem to currently happen,
6343 // but this assertion here is to help prevent its occurrence.
6344 tty->print_cr("Found oop constant with non-zero offset");
6345 ShouldNotReachHere();
6346 }
6347
6348 ciKlass* k = exact_klass();
6349
6350 return (intptr_t)k->constant_encoding();
6351 }
6352
6353 //=============================================================================
6354 // Convenience common pre-built types.
6355
6356 // Not-null object klass or below
6357 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6358 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6359
6360 bool TypeInstKlassPtr::eq(const Type *t) const {
6361 const TypeInstKlassPtr* p = t->is_instklassptr();
6362 return
6363 klass()->equals(p->klass()) &&
6364 _flat_in_array == p->_flat_in_array &&
6365 TypeKlassPtr::eq(p);
6366 }
6367
6368 uint TypeInstKlassPtr::hash() const {
6369 return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6370 }
6371
6372 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6373 if (flat_in_array == Uninitialized) {
6374 flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6375 }
6376 TypeInstKlassPtr *r =
6377 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6378
6379 return r;
6380 }
6381
6382 bool TypeInstKlassPtr::empty() const {
6383 if (_flat_in_array == TopFlat) {
6384 return true;
6385 }
6386 return TypeKlassPtr::empty();
6387 }
6388
6389 //------------------------------add_offset-------------------------------------
6390 // Access internals of klass object
6391 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6392 return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6393 }
6394
6395 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6396 return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6397 }
6398
6399 //------------------------------cast_to_ptr_type-------------------------------
6400 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6401 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6402 if( ptr == _ptr ) return this;
6403 return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6404 }
6405
6406
6407 bool TypeInstKlassPtr::must_be_exact() const {
6408 if (!_klass->is_loaded()) return false;
6409 ciInstanceKlass* ik = _klass->as_instance_klass();
6410 if (ik->is_final()) return true; // cannot clear xk
6411 return false;
6412 }
6413
6414 //-----------------------------cast_to_exactness-------------------------------
6415 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6416 if (klass_is_exact == (_ptr == Constant)) return this;
6417 if (must_be_exact()) return this;
6418 ciKlass* k = klass();
6419 FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6420 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6421 }
6422
6423
6424 //-----------------------------as_instance_type--------------------------------
6425 // Corresponding type for an instance of the given class.
6426 // It will be NotNull, and exact if and only if the klass type is exact.
6427 const TypeInstPtr* TypeInstKlassPtr::as_exact_instance_type(bool klass_change) const {
6428 ciKlass* k = klass();
6429 bool xk = klass_is_exact();
6430 Compile* C = Compile::current();
6431 Dependencies* deps = C->dependencies();
6432 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6433 // Element is an instance
6434 bool klass_is_exact = false;
6435 const TypeInterfaces* interfaces = _interfaces;
6436 ciInstanceKlass* ik = k->as_instance_klass();
6437 if (k->is_loaded()) {
6438 // Try to set klass_is_exact.
6439 klass_is_exact = ik->is_final();
6440 if (!klass_is_exact && klass_change
6441 && deps != nullptr && UseUniqueSubclasses) {
6442 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6443 if (sub != nullptr) {
6444 if (_interfaces->eq(sub)) {
6445 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6446 k = ik = sub;
6447 xk = sub->is_final();
6448 }
6449 }
6450 }
6451 }
6452
6453 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6454 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6455 }
6456
6457 const TypeInstPtr* TypeInstKlassPtr::as_subtype_instance_type(bool klass_change) const {
6458 return cast_to_exactness(false)->as_exact_instance_type(klass_change);
6459 }
6460
6461 //------------------------------xmeet------------------------------------------
6462 // Compute the MEET of two types, return a new Type object.
6463 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6464 // Perform a fast test for common case; meeting the same types together.
6465 if( this == t ) return this; // Meeting same type-rep?
6466
6467 // Current "this->_base" is Pointer
6468 switch (t->base()) { // switch on original type
6469
6470 case Int: // Mixing ints & oops happens when javac
6471 case Long: // reuses local variables
6472 case HalfFloatTop:
6473 case HalfFloatCon:
6474 case HalfFloatBot:
6475 case FloatTop:
6476 case FloatCon:
6477 case FloatBot:
6478 case DoubleTop:
6479 case DoubleCon:
6480 case DoubleBot:
6481 case NarrowOop:
6482 case NarrowKlass:
6483 case Bottom: // Ye Olde Default
6484 return Type::BOTTOM;
6485 case Top:
6486 return this;
6487
6488 default: // All else is a mistake
6489 typerr(t);
6490
6491 case AnyPtr: { // Meeting to AnyPtrs
6492 // Found an AnyPtr type vs self-KlassPtr type
6493 const TypePtr *tp = t->is_ptr();
6494 Offset offset = meet_offset(tp->offset());
6495 PTR ptr = meet_ptr(tp->ptr());
6496 switch (tp->ptr()) {
6497 case TopPTR:
6498 return this;
6499 case Null:
6500 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6501 case AnyNull:
6502 return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6503 case BotPTR:
6504 case NotNull:
6505 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6506 default: typerr(t);
6507 }
6508 }
6509
6510 case RawPtr:
6511 case MetadataPtr:
6512 case OopPtr:
6513 case AryPtr: // Meet with AryPtr
6514 case InstPtr: // Meet with InstPtr
6515 return TypePtr::BOTTOM;
6516
6517 //
6518 // A-top }
6519 // / | \ } Tops
6520 // B-top A-any C-top }
6521 // | / | \ | } Any-nulls
6522 // B-any | C-any }
6523 // | | |
6524 // B-con A-con C-con } constants; not comparable across classes
6525 // | | |
6526 // B-not | C-not }
6527 // | \ | / | } not-nulls
6528 // B-bot A-not C-bot }
6529 // \ | / } Bottoms
6530 // A-bot }
6531 //
6532
6533 case InstKlassPtr: { // Meet two KlassPtr types
6534 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6535 Offset off = meet_offset(tkls->offset());
6536 PTR ptr = meet_ptr(tkls->ptr());
6537 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6538
6539 ciKlass* res_klass = nullptr;
6540 bool res_xk = false;
6541 const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6542 switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6543 case UNLOADED:
6544 ShouldNotReachHere();
6545 case SUBTYPE:
6546 case NOT_SUBTYPE:
6547 case LCA:
6548 case QUICK: {
6549 assert(res_xk == (ptr == Constant), "");
6550 const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6551 return res;
6552 }
6553 default:
6554 ShouldNotReachHere();
6555 }
6556 } // End of case KlassPtr
6557 case AryKlassPtr: { // All arrays inherit from Object class
6558 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6559 Offset offset = meet_offset(tp->offset());
6560 PTR ptr = meet_ptr(tp->ptr());
6561 const TypeInterfaces* interfaces = meet_interfaces(tp);
6562 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6563 const TypeInterfaces* this_interfaces = _interfaces;
6564
6565 switch (ptr) {
6566 case TopPTR:
6567 case AnyNull: // Fall 'down' to dual of object klass
6568 // For instances when a subclass meets a superclass we fall
6569 // below the centerline when the superclass is exact. We need to
6570 // do the same here.
6571 //
6572 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6573 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6574 !klass_is_exact() && !is_not_flat_in_array()) {
6575 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());
6576 } else {
6577 // cannot subclass, so the meet has to fall badly below the centerline
6578 ptr = NotNull;
6579 interfaces = _interfaces->intersection_with(tp->_interfaces);
6580 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6581 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6582 }
6583 case Constant:
6584 case NotNull:
6585 case BotPTR: { // Fall down to object klass
6586 // LCA is object_klass, but if we subclass from the top we can do better
6587 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6588 // If 'this' (InstPtr) is above the centerline and it is Object class
6589 // then we can subclass in the Java class hierarchy.
6590 // For instances when a subclass meets a superclass we fall
6591 // below the centerline when the superclass is exact. We need
6592 // to do the same here.
6593 //
6594 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6595 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6596 !klass_is_exact() && !is_not_flat_in_array()) {
6597 // that is, tp's array type is a subtype of my klass
6598 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());
6599 }
6600 }
6601 // The other case cannot happen, since I cannot be a subtype of an array.
6602 // The meet falls down to Object class below centerline.
6603 if( ptr == Constant )
6604 ptr = NotNull;
6605 interfaces = this_interfaces->intersection_with(tp_interfaces);
6606 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6607 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6608 }
6609 default: typerr(t);
6610 }
6611 }
6612
6613 } // End of switch
6614 return this; // Return the double constant
6615 }
6616
6617 //------------------------------xdual------------------------------------------
6618 // Dual: compute field-by-field dual
6619 const Type* TypeInstKlassPtr::xdual() const {
6620 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6621 }
6622
6623 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) {
6624 static_assert(std::is_base_of<T2, T1>::value, "");
6625 if (!this_one->is_loaded() || !other->is_loaded()) {
6626 return false;
6627 }
6628 if (!this_one->is_instance_type(other)) {
6629 return false;
6630 }
6631
6632 if (!other_exact) {
6633 return false;
6634 }
6635
6636 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6637 return true;
6638 }
6639
6640 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6696 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6697 }
6698
6699 return true;
6700 }
6701
6702 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6703 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6704 }
6705
6706 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6707 if (!UseUniqueSubclasses) {
6708 return this;
6709 }
6710 ciKlass* k = klass();
6711 Compile* C = Compile::current();
6712 Dependencies* deps = C->dependencies();
6713 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6714 if (k->is_loaded()) {
6715 ciInstanceKlass* ik = k->as_instance_klass();
6716 if (deps != nullptr) {
6717 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6718 if (sub != nullptr) {
6719 bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6720 const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6721 if (_interfaces->is_subset(sub)) {
6722 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6723 return improved;
6724 }
6725 }
6726 }
6727 }
6728 return this;
6729 }
6730
6731 bool TypeInstKlassPtr::can_be_inline_array() const {
6732 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6733 }
6734
6735 #ifndef PRODUCT
6736 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6737 st->print("instklassptr:");
6738 klass()->print_name_on(st);
6739 _interfaces->dump(st);
6740 st->print(":%s", ptr_msg[_ptr]);
6741 dump_offset(st);
6742 dump_flat_in_array(_flat_in_array, st);
6743 }
6744 #endif // PRODUCT
6745
6746 bool TypeAryKlassPtr::can_be_inline_array() const {
6747 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6748 }
6749
6750 bool TypeInstPtr::can_be_inline_array() const {
6751 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6752 }
6753
6754 bool TypeAryPtr::can_be_inline_array() const {
6755 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6756 }
6757
6758 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) {
6759 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6760 }
6761
6762 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) {
6763 const Type* etype;
6764 if (k->is_obj_array_klass()) {
6765 // Element is an object array. Recursively call ourself.
6766 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6767 etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6768 k = nullptr;
6769 } else if (k->is_type_array_klass()) {
6770 // Element is an typeArray
6771 etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6772 } else {
6773 ShouldNotReachHere();
6774 }
6775
6776 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6777 }
6778
6779 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6780 ciArrayKlass* k = klass->as_array_klass();
6781 if (k->is_refined()) {
6782 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6783 k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6784 } else {
6785 // Use the default combination to canonicalize all non-refined klass pointers
6786 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6787 }
6788 }
6789
6790 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6791 assert(is_refined_type(), "must be a refined type");
6792 PTR ptr = _ptr;
6793 // There can be multiple refined array types corresponding to a single unrefined type
6794 if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6795 ptr = Constant;
6796 }
6797 return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6798 }
6799
6800 // Get the (non-)refined array klass ptr
6801 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6802 if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6803 return this;
6804 }
6805 ciArrayKlass* k = exact_klass()->as_array_klass();
6806 k = ciObjArrayKlass::make(k->element_klass(), refined);
6807 return make(k, trust_interfaces);
6808 }
6809
6810 //------------------------------eq---------------------------------------------
6811 // Structural equality check for Type representations
6812 bool TypeAryKlassPtr::eq(const Type *t) const {
6813 const TypeAryKlassPtr *p = t->is_aryklassptr();
6814 return
6815 _elem == p->_elem && // Check array
6816 _flat == p->_flat &&
6817 _not_flat == p->_not_flat &&
6818 _null_free == p->_null_free &&
6819 _not_null_free == p->_not_null_free &&
6820 _atomic == p->_atomic &&
6821 _refined_type == p->_refined_type &&
6822 TypeKlassPtr::eq(p); // Check sub-parts
6823 }
6824
6825 //------------------------------hash-------------------------------------------
6826 // Type-specific hashing function.
6827 uint TypeAryKlassPtr::hash(void) const {
6828 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6829 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6830 }
6831
6832 //----------------------compute_klass------------------------------------------
6833 // Compute the defining klass for this class
6834 ciKlass* TypeAryPtr::compute_klass() const {
6835 // Compute _klass based on element type.
6836 ciKlass* k_ary = nullptr;
6837 const TypeInstPtr *tinst;
6838 const TypeAryPtr *tary;
6839 const Type* el = elem();
6840 if (el->isa_narrowoop()) {
6841 el = el->make_ptr();
6842 }
6843
6844 // Get element klass
6845 if ((tinst = el->isa_instptr()) != nullptr) {
6846 // Leave k_ary at nullptr.
6847 } else if ((tary = el->isa_aryptr()) != nullptr) {
6848 // Leave k_ary at nullptr.
6849 } else if ((el->base() == Type::Top) ||
6850 (el->base() == Type::Bottom)) {
6851 // element type of Bottom occurs from meet of basic type
6852 // and object; Top occurs when doing join on Bottom.
6853 // Leave k_ary at null.
6854 } else {
6855 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6856 // Compute array klass directly from basic type
6857 k_ary = ciTypeArrayKlass::make(el->basic_type());
6858 }
6859 return k_ary;
6860 }
6861
6862 //------------------------------klass------------------------------------------
6863 // Return the defining klass for this class
6864 ciKlass* TypeAryPtr::klass() const {
6865 if( _klass ) return _klass; // Return cached value, if possible
6866
6867 // Oops, need to compute _klass and cache it
6868 ciKlass* k_ary = compute_klass();
6876 // type TypeAryPtr::OOPS. This Type is shared between all
6877 // active compilations. However, the ciKlass which represents
6878 // this Type is *not* shared between compilations, so caching
6879 // this value would result in fetching a dangling pointer.
6880 //
6881 // Recomputing the underlying ciKlass for each request is
6882 // a bit less efficient than caching, but calls to
6883 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6884 ((TypeAryPtr*)this)->_klass = k_ary;
6885 }
6886 return k_ary;
6887 }
6888
6889 // Is there a single ciKlass* that can represent that type?
6890 ciKlass* TypeAryPtr::exact_klass_helper() const {
6891 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6892 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6893 if (k == nullptr) {
6894 return nullptr;
6895 }
6896 if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6897 // We have no mechanism to create an array of refined arrays
6898 k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6899 }
6900 if (klass_is_exact()) {
6901 return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6902 } else {
6903 // We may reach here if called recursively, must be an unrefined type then
6904 return ciObjArrayKlass::make(k, false);
6905 }
6906 }
6907
6908 return klass();
6909 }
6910
6911 const Type* TypeAryPtr::base_element_type(int& dims) const {
6912 const Type* elem = this->elem();
6913 dims = 1;
6914 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6915 elem = elem->make_ptr()->is_aryptr()->elem();
6916 dims++;
6917 }
6918 return elem;
6919 }
6920
6921 //------------------------------add_offset-------------------------------------
6922 // Access internals of klass object
6923 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6924 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6925 }
6926
6927 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6928 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6929 }
6930
6931 //------------------------------cast_to_ptr_type-------------------------------
6932 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6933 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6934 if (ptr == _ptr) return this;
6935 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6936 }
6937
6938 bool TypeAryKlassPtr::must_be_exact() const {
6939 assert(klass_is_exact(), "precondition");
6940 if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6941 return false;
6942 }
6943 const TypeKlassPtr* elem = _elem->isa_klassptr();
6944 if (elem == nullptr) {
6945 // primitive arrays
6946 return true;
6947 }
6948
6949 // refined types are final
6950 return _refined_type;
6951 }
6952
6953 //-----------------------------cast_to_exactness-------------------------------
6954 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6955 if (klass_is_exact == this->klass_is_exact()) {
6956 return this;
6957 }
6958 if (!klass_is_exact && must_be_exact()) {
6959 return this;
6960 }
6961 const Type* elem = this->elem();
6962 if (elem->isa_klassptr() && !klass_is_exact) {
6963 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6964 }
6965
6966 if (klass_is_exact) {
6967 // cast_to_exactness(true) really means get the LCA of all values represented by this
6968 // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6969 return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6970 } else {
6971 // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6972 // this value
6973 bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6974 bool not_flat = !UseArrayFlattening || not_inline ||
6975 (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6976 bool not_null_free = not_inline;
6977 bool atomic = not_flat;
6978 return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6979 }
6980 }
6981
6982 //-----------------------------as_instance_type--------------------------------
6983 // Corresponding type for an instance of the given class.
6984 // It will be NotNull, and exact if and only if the klass type is exact.
6985 const TypeAryPtr* TypeAryKlassPtr::as_exact_instance_type(bool klass_change) const {
6986 ciKlass* k = klass();
6987 bool xk = klass_is_exact();
6988 const Type* el = nullptr;
6989 if (elem()->isa_klassptr()) {
6990 el = elem()->is_klassptr()->as_subtype_instance_type(false);
6991 k = nullptr;
6992 } else {
6993 el = elem();
6994 }
6995 bool flat, not_flat, not_null_free, atomic;
6996 if (_refined_type) {
6997 if (_null_free && el->isa_ptr()) {
6998 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6999 }
7000 flat = is_flat();
7001 not_flat = is_not_flat();
7002 not_null_free = is_not_null_free();
7003 atomic = is_atomic();
7004 } else { // Unrefined types aren't trustworthy! Let's not mistake their ignorance for information.
7005 // We can always have arrays of references. Flatness is not guaranteed.
7006 flat = false;
7007 // There are asserts that expect us to not be entirely naive about properties.
7008 // Only arrays of value classes can be null free. Otherwise, not_null_free == true. That is if the element type
7009 // is not an instance class, or this instance class cannot be an inline type, it's surely not null-restricted.
7010 not_null_free = !elem()->isa_instklassptr() || !elem()->is_instklassptr()->can_be_inline_type();
7011 bool array_can_be_flat;
7012 if (elem()->isa_instklassptr()) {
7013 FlatInArray elem_flat_in_array = elem()->is_instklassptr()->flat_in_array();
7014 array_can_be_flat = elem_flat_in_array == MaybeFlat || elem_flat_in_array == Flat;
7015 } else {
7016 array_can_be_flat = false;
7017 }
7018 not_flat = !array_can_be_flat;
7019 atomic = !array_can_be_flat;
7020 }
7021 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, flat, not_flat, not_null_free, atomic), k, xk, Offset(0));
7022 }
7023
7024 // Corresponding type for instances that subtype the given class
7025 const TypeAryPtr* TypeAryKlassPtr::as_subtype_instance_type(bool klass_change) const {
7026 return cast_to_exactness(false)->as_exact_instance_type(klass_change);
7027 }
7028
7029 //------------------------------xmeet------------------------------------------
7030 // Compute the MEET of two types, return a new Type object.
7031 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
7032 // Perform a fast test for common case; meeting the same types together.
7033 if( this == t ) return this; // Meeting same type-rep?
7034
7035 // Current "this->_base" is Pointer
7036 switch (t->base()) { // switch on original type
7037
7038 case Int: // Mixing ints & oops happens when javac
7039 case Long: // reuses local variables
7040 case HalfFloatTop:
7041 case HalfFloatCon:
7042 case HalfFloatBot:
7043 case FloatTop:
7044 case FloatCon:
7045 case FloatBot:
7046 case DoubleTop:
7047 case DoubleCon:
7048 case DoubleBot:
7049 case NarrowOop:
7050 case NarrowKlass:
7051 case Bottom: // Ye Olde Default
7052 return Type::BOTTOM;
7053 case Top:
7054 return this;
7055
7056 default: // All else is a mistake
7057 typerr(t);
7058
7059 case AnyPtr: { // Meeting to AnyPtrs
7060 // Found an AnyPtr type vs self-KlassPtr type
7061 const TypePtr *tp = t->is_ptr();
7062 Offset offset = meet_offset(tp->offset());
7063 PTR ptr = meet_ptr(tp->ptr());
7064 switch (tp->ptr()) {
7065 case TopPTR:
7066 return this;
7067 case Null:
7068 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7069 case AnyNull:
7070 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7071 case BotPTR:
7072 case NotNull:
7073 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7074 default: typerr(t);
7075 }
7076 }
7077
7078 case RawPtr:
7079 case MetadataPtr:
7080 case OopPtr:
7081 case AryPtr: // Meet with AryPtr
7082 case InstPtr: // Meet with InstPtr
7083 return TypePtr::BOTTOM;
7084
7085 //
7086 // A-top }
7087 // / | \ } Tops
7088 // B-top A-any C-top }
7089 // | / | \ | } Any-nulls
7090 // B-any | C-any }
7091 // | | |
7092 // B-con A-con C-con } constants; not comparable across classes
7093 // | | |
7094 // B-not | C-not }
7095 // | \ | / | } not-nulls
7096 // B-bot A-not C-bot }
7097 // \ | / } Bottoms
7098 // A-bot }
7099 //
7100
7101 case AryKlassPtr: { // Meet two KlassPtr types
7102 const TypeAryKlassPtr *tap = t->is_aryklassptr();
7103 Offset off = meet_offset(tap->offset());
7104 const Type* elem = _elem->meet(tap->_elem);
7105 PTR ptr = meet_ptr(tap->ptr());
7106 ciKlass* res_klass = nullptr;
7107 bool res_xk = false;
7108 bool res_flat = false;
7109 bool res_not_flat = false;
7110 bool res_not_null_free = false;
7111 bool res_atomic = false;
7112 MeetResult res = meet_aryptr(ptr, elem, this, tap,
7113 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
7114 assert(res_xk == (ptr == Constant), "");
7115 bool flat = meet_flat(tap->_flat);
7116 bool null_free = meet_null_free(tap->_null_free);
7117 bool atomic = meet_atomic(tap->_atomic);
7118 bool refined_type = _refined_type && tap->_refined_type;
7119 if (res == NOT_SUBTYPE) {
7120 flat = false;
7121 null_free = false;
7122 atomic = false;
7123 refined_type = false;
7124 } else if (res == SUBTYPE) {
7125 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7126 flat = _flat;
7127 null_free = _null_free;
7128 atomic = _atomic;
7129 refined_type = _refined_type;
7130 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7131 flat = tap->_flat;
7132 null_free = tap->_null_free;
7133 atomic = tap->_atomic;
7134 refined_type = tap->_refined_type;
7135 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7136 flat = _flat || tap->_flat;
7137 null_free = _null_free || tap->_null_free;
7138 atomic = _atomic || tap->_atomic;
7139 refined_type = _refined_type || tap->_refined_type;
7140 } else if (res_xk && _refined_type != tap->_refined_type) {
7141 // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7142 // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7143 // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7144 ptr = PTR::NotNull;
7145 }
7146 }
7147 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7148 } // End of case KlassPtr
7149 case InstKlassPtr: {
7150 const TypeInstKlassPtr *tp = t->is_instklassptr();
7151 Offset offset = meet_offset(tp->offset());
7152 PTR ptr = meet_ptr(tp->ptr());
7153 const TypeInterfaces* interfaces = meet_interfaces(tp);
7154 const TypeInterfaces* tp_interfaces = tp->_interfaces;
7155 const TypeInterfaces* this_interfaces = _interfaces;
7156
7157 switch (ptr) {
7158 case TopPTR:
7159 case AnyNull: // Fall 'down' to dual of object klass
7160 // For instances when a subclass meets a superclass we fall
7161 // below the centerline when the superclass is exact. We need to
7162 // do the same here.
7163 //
7164 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7165 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7166 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7167 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7168 } else {
7169 // cannot subclass, so the meet has to fall badly below the centerline
7170 ptr = NotNull;
7171 interfaces = this_interfaces->intersection_with(tp->_interfaces);
7172 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7173 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7174 }
7175 case Constant:
7176 case NotNull:
7177 case BotPTR: { // Fall down to object klass
7178 // LCA is object_klass, but if we subclass from the top we can do better
7179 if (above_centerline(tp->ptr())) {
7180 // If 'tp' is above the centerline and it is Object class
7181 // then we can subclass in the Java class hierarchy.
7182 // For instances when a subclass meets a superclass we fall
7183 // below the centerline when the superclass is exact. We need
7184 // to do the same here.
7185 //
7186 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7187 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7188 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7189 // that is, my array type is a subtype of 'tp' klass
7190 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7191 }
7192 }
7193 // The other case cannot happen, since t cannot be a subtype of an array.
7194 // The meet falls down to Object class below centerline.
7195 if (ptr == Constant)
7196 ptr = NotNull;
7197 interfaces = this_interfaces->intersection_with(tp_interfaces);
7198 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7199 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7200 }
7201 default: typerr(t);
7202 }
7203 }
7204
7205 } // End of switch
7206 return this; // Return the double constant
7207 }
7208
7209 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) {
7210 static_assert(std::is_base_of<T2, T1>::value, "");
7211
7212 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7213 return true;
7214 }
7215
7216 int dummy;
7217 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7218
7219 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7220 return false;
7221 }
7222
7223 if (this_one->is_instance_type(other)) {
7224 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7225 other_exact;
7226 }
7227
7228 assert(this_one->is_array_type(other), "");
7229 const T1* other_ary = this_one->is_array_type(other);
7230 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7231 if (other_top_or_bottom) {
7232 return false;
7233 }
7234
7235 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7236 const TypePtr* this_elem = this_one->elem()->make_ptr();
7237 if (this_elem != nullptr && other_elem != nullptr) {
7238 if (other->is_null_free() && !this_one->is_null_free()) {
7239 return false; // A nullable array can't be a subtype of a null-free array
7240 }
7241 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7242 }
7243 if (this_elem == nullptr && other_elem == nullptr) {
7244 return this_one->klass()->is_subtype_of(other->klass());
7245 }
7246 return false;
7247 }
7248
7249 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7250 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7251 }
7252
7253 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7254 static_assert(std::is_base_of<T2, T1>::value, "");
7255
7256 int dummy;
7257 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7258
7259 if (!this_one->is_array_type(other) ||
7260 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7313 }
7314
7315 const TypePtr* this_elem = this_one->elem()->make_ptr();
7316 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7317 if (other_elem != nullptr && this_elem != nullptr) {
7318 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7319 }
7320 if (other_elem == nullptr && this_elem == nullptr) {
7321 return this_one->klass()->is_subtype_of(other->klass());
7322 }
7323 return false;
7324 }
7325
7326 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7327 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7328 }
7329
7330 //------------------------------xdual------------------------------------------
7331 // Dual: compute field-by-field dual
7332 const Type *TypeAryKlassPtr::xdual() const {
7333 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);
7334 }
7335
7336 // Is there a single ciKlass* that can represent that type?
7337 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7338 if (elem()->isa_klassptr()) {
7339 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7340 if (k == nullptr) {
7341 return nullptr;
7342 }
7343 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());
7344 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7345 return k;
7346 }
7347
7348 return klass();
7349 }
7350
7351 ciKlass* TypeAryKlassPtr::klass() const {
7352 if (_klass != nullptr) {
7353 return _klass;
7354 }
7355 ciKlass* k = nullptr;
7356 if (elem()->isa_klassptr()) {
7357 // leave null
7358 } else if ((elem()->base() == Type::Top) ||
7359 (elem()->base() == Type::Bottom)) {
7360 } else {
7361 k = ciTypeArrayKlass::make(elem()->basic_type());
7362 ((TypeAryKlassPtr*)this)->_klass = k;
7363 }
7364 return k;
7365 }
7366
7367 //------------------------------dump2------------------------------------------
7368 // Dump Klass Type
7369 #ifndef PRODUCT
7370 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7371 st->print("aryklassptr:[");
7372 _elem->dump2(d, depth, st);
7373 _interfaces->dump(st);
7374 st->print(":%s", ptr_msg[_ptr]);
7375 if (_flat) st->print(":flat");
7376 if (_null_free) st->print(":null free");
7377 if (_atomic) st->print(":atomic");
7378 if (_refined_type) st->print(":refined_type");
7379 if (Verbose) {
7380 if (_not_flat) st->print(":not flat");
7381 if (_not_null_free) st->print(":nullable");
7382 }
7383 dump_offset(st);
7384 }
7385 #endif
7386
7387 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7388 const Type* elem = this->elem();
7389 dims = 1;
7390 while (elem->isa_aryklassptr()) {
7391 elem = elem->is_aryklassptr()->elem();
7392 dims++;
7393 }
7394 return elem;
7395 }
7396
7397 //=============================================================================
7398 // Convenience common pre-built types.
7399
7400 //------------------------------make-------------------------------------------
7401 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7402 const TypeTuple* range_sig, const TypeTuple* range_cc,
7403 bool scalarized_return) {
7404 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc, scalarized_return))->hashcons();
7405 }
7406
7407 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7408 return make(domain, domain, range, range);
7409 }
7410
7411 //------------------------------osr_domain-----------------------------
7412 const TypeTuple* osr_domain() {
7413 const Type **fields = TypeTuple::fields(2);
7414 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7415 return TypeTuple::make(TypeFunc::Parms+1, fields);
7416 }
7417
7418 // Build a TypeFunc with both the Java-signature view ('sig') and the actual calling-
7419 // convention view ('cc') of inline types. In the signature, an inline type is a single
7420 // oop slot. In the scalarized calling convention, it is expanded to its field
7421 // values (plus null marker and optional oop to the heap buffer).
7422 // The 'is_call' argument distinguishes between the return signature of a method at calls
7423 // vs. at compilation of that method because at calls we return an additional null marker field.
7424 // For OSR and mismatching calls, we fall back to the non-scalarized argument view.
7425 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_call, bool is_osr_compilation) {
7426 Compile* C = Compile::current();
7427 const TypeFunc* tf = nullptr;
7428 // Inline types are not passed/returned by reference, instead each field of
7429 // the inline type is passed/returned as an argument. We maintain two views of
7430 // the argument/return list here: one based on the signature (with an inline
7431 // type argument/return as a single slot), one based on the actual calling
7432 // convention (with an inline type argument/return as a list of its fields).
7433 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7434 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7435 if (is_call && method->mismatch()) {
7436 has_scalar_args = false;
7437 }
7438 ciSignature* sig = method->signature();
7439 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7440 // Don't cache on scalarized return because the range depends on 'is_call'
7441 if (!is_osr_compilation && !has_scalar_ret) {
7442 tf = C->last_tf(method); // check cache
7443 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7444 }
7445 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7446 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7447 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces);
7448 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true, is_call) : range_sig;
7449 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc, has_scalar_ret);
7450 if (!is_osr_compilation && !has_scalar_ret) {
7451 C->set_last_tf(method, tf); // fill cache
7452 }
7453 return tf;
7454 }
7455
7456 //------------------------------meet-------------------------------------------
7457 // Compute the MEET of two types. It returns a new Type object.
7458 const Type *TypeFunc::xmeet( const Type *t ) const {
7459 // Perform a fast test for common case; meeting the same types together.
7460 if( this == t ) return this; // Meeting same type-rep?
7461
7462 // Current "this->_base" is Func
7463 switch (t->base()) { // switch on original type
7464
7465 case Bottom: // Ye Olde Default
7466 return t;
7467
7468 default: // All else is a mistake
7469 typerr(t);
7470
7471 case Top:
7472 break;
7473 }
7474 return this; // Return the double constant
7475 }
7476
7477 //------------------------------xdual------------------------------------------
7478 // Dual: compute field-by-field dual
7479 const Type *TypeFunc::xdual() const {
7480 return this;
7481 }
7482
7483 //------------------------------eq---------------------------------------------
7484 // Structural equality check for Type representations
7485 bool TypeFunc::eq( const Type *t ) const {
7486 const TypeFunc *a = (const TypeFunc*)t;
7487 return _domain_sig == a->_domain_sig &&
7488 _domain_cc == a->_domain_cc &&
7489 _range_sig == a->_range_sig &&
7490 _range_cc == a->_range_cc &&
7491 _scalarized_return == a->_scalarized_return;
7492 }
7493
7494 //------------------------------hash-------------------------------------------
7495 // Type-specific hashing function.
7496 uint TypeFunc::hash(void) const {
7497 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;
7498 }
7499
7500 //------------------------------dump2------------------------------------------
7501 // Dump Function Type
7502 #ifndef PRODUCT
7503 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7504 if( _range_sig->cnt() <= Parms )
7505 st->print("void");
7506 else {
7507 uint i;
7508 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7509 _range_sig->field_at(i)->dump2(d,depth,st);
7510 st->print("/");
7511 }
7512 _range_sig->field_at(i)->dump2(d,depth,st);
7513 }
7514 st->print(" ");
7515 st->print("( ");
7516 if( !depth || d[this] ) { // Check for recursive dump
7517 st->print("...)");
7518 return;
7519 }
7520 d.Insert((void*)this,(void*)this); // Stop recursion
7521 if (Parms < _domain_sig->cnt())
7522 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7523 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7524 st->print(", ");
7525 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7526 }
7527 st->print(" )");
7528 }
7529 #endif
7530
7531 //------------------------------singleton--------------------------------------
7532 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7533 // constants (Ldi nodes). Singletons are integer, float or double constants
7534 // or a single symbol.
7535 bool TypeFunc::singleton(void) const {
7536 return false; // Never a singleton
7537 }
7538
7539 bool TypeFunc::empty(void) const {
7540 return false; // Never empty
7541 }
7542
7543
7544 BasicType TypeFunc::return_type() const{
7545 if (range_sig()->cnt() == TypeFunc::Parms) {
7546 return T_VOID;
7547 }
7548 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7549 }
|