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