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